@@ -129,41 +129,19 @@ static std::shared_ptr<sdbusplus::asio::dbus_interface>
129
129
// calls the mapper to find all exposed objects of an interface type
130
130
// and creates a vector<flat_map> that contains all the key value pairs
131
131
// getManagedObjects
132
- void findDbusObjects (std::shared_ptr<PerformProbe> probe ,
132
+ void findDbusObjects (std::vector<std:: shared_ptr<PerformProbe>>& probeVector ,
133
133
std::shared_ptr<sdbusplus::asio::connection> connection,
134
- std::string& interface )
134
+ boost::container::flat_set< std::string>& interfaces )
135
135
{
136
136
137
- // store reference to pending callbacks so we don't overwhelm services
138
- static boost::container::flat_map<
139
- std::string, std::vector<std::shared_ptr<PerformProbe>>>
140
- pendingProbes;
141
-
142
- if (DBUS_PROBE_OBJECTS[interface].size ())
143
- {
144
- return ;
145
- }
146
-
147
- // add shared_ptr to vector of Probes waiting for callback from a specific
148
- // interface to keep alive while waiting for response
149
- std::array<const char *, 1 > objects = {interface.c_str ()};
150
- std::vector<std::shared_ptr<PerformProbe>>& pending =
151
- pendingProbes[interface];
152
- auto iter = pending.emplace (pending.end (), probe);
153
- // only allow first call to run to not overwhelm processes
154
- if (iter != pending.begin ())
155
- {
156
- return ;
157
- }
158
-
159
137
// find all connections in the mapper that expose a specific type
160
138
connection->async_method_call (
161
- [connection, interface, probe](boost::system ::error_code& ec,
162
- const GetSubTreeType& interfaceSubtree) {
139
+ [connection, interfaces,
140
+ probeVector](boost::system ::error_code& ec,
141
+ const GetSubTreeType& interfaceSubtree) {
163
142
boost::container::flat_set<std::string> interfaceConnections;
164
143
if (ec)
165
144
{
166
- pendingProbes[interface].clear ();
167
145
if (ec.value () == ENOENT)
168
146
{
169
147
return ; // wasn't found by mapper
@@ -173,59 +151,57 @@ void findDbusObjects(std::shared_ptr<PerformProbe> probe,
173
151
// if we can't communicate to the mapper something is very wrong
174
152
std::exit (EXIT_FAILURE);
175
153
}
176
- else
154
+
155
+ for (auto & object : interfaceSubtree)
177
156
{
178
- for (auto & object : interfaceSubtree )
157
+ for (auto & connPair : object. second )
179
158
{
180
- for (auto & connPair : object.second )
181
- {
182
- interfaceConnections.insert (connPair.first );
183
- }
159
+ interfaceConnections.insert (connPair.first );
184
160
}
185
161
}
162
+
186
163
if (interfaceConnections.empty ())
187
164
{
188
- pendingProbes[interface].clear ();
189
165
return ;
190
166
}
191
167
// get managed objects for all interfaces
192
168
for (const auto & conn : interfaceConnections)
193
169
{
194
170
connection->async_method_call (
195
- [conn,
196
- interface ](boost::system ::error_code& errc,
197
- const ManagedObjectType& managedInterface) {
171
+ [conn, interfaces,
172
+ probeVector ](boost::system ::error_code& errc,
173
+ const ManagedObjectType& managedInterface) {
198
174
if (errc)
199
175
{
200
176
std::cerr
201
177
<< " error getting managed object for device "
202
178
<< conn << " \n " ;
203
- pendingProbes[interface].clear ();
204
179
return ;
205
180
}
206
181
for (auto & interfaceManagedObj : managedInterface)
207
182
{
208
- auto ifaceObjFind =
209
- interfaceManagedObj.second .find (interface);
210
- if (ifaceObjFind !=
211
- interfaceManagedObj.second .end ())
183
+ // we could match multiple interfaces with one owner
184
+ for (auto & [interface, object] :
185
+ interfaceManagedObj.second )
212
186
{
213
- std::vector<boost::container::flat_map<
214
- std::string, BasicVariantType>>&
215
- dbusObject = DBUS_PROBE_OBJECTS[interface];
216
- dbusObject.emplace_back (ifaceObjFind->second );
187
+ auto ifaceObjFind = interfaces.find (interface);
188
+
189
+ if (ifaceObjFind != interfaces.end ())
190
+ {
191
+ DBUS_PROBE_OBJECTS[interface].emplace_back (
192
+ object);
193
+ }
217
194
}
218
195
}
219
- pendingProbes[interface].clear ();
220
196
},
221
- conn. c_str () , " /" , " org.freedesktop.DBus.ObjectManager" ,
197
+ conn, " /" , " org.freedesktop.DBus.ObjectManager" ,
222
198
" GetManagedObjects" );
223
199
}
224
200
},
225
201
" xyz.openbmc_project.ObjectMapper" ,
226
202
" /xyz/openbmc_project/object_mapper" ,
227
203
" xyz.openbmc_project.ObjectMapper" , " GetSubTree" , " /" , MAX_MAPPER_DEPTH,
228
- objects );
204
+ interfaces );
229
205
}
230
206
// probes dbus interface dictionary for a key with a value that matches a regex
231
207
bool probeDbus (const std::string& interface,
@@ -489,35 +465,6 @@ struct PerformProbe : std::enable_shared_from_this<PerformProbe>
489
465
_callback (foundDevs);
490
466
}
491
467
}
492
- void run ()
493
- {
494
- // parse out dbus probes by discarding other probe types
495
-
496
- for (std::string& probe : _probeCommand)
497
- {
498
- bool found = false ;
499
- boost::container::flat_map<const char *, probe_type_codes,
500
- cmp_str>::const_iterator probeType;
501
- for (probeType = PROBE_TYPES.begin ();
502
- probeType != PROBE_TYPES.end (); ++probeType)
503
- {
504
- if (probe.find (probeType->first ) != std::string::npos)
505
- {
506
- found = true ;
507
- break ;
508
- }
509
- }
510
- if (found)
511
- {
512
- continue ;
513
- }
514
- // syntax requires probe before first open brace
515
- auto findStart = probe.find (" (" );
516
- std::string interface = probe.substr (0 , findStart);
517
-
518
- findDbusObjects (shared_from_this (), SYSTEM_BUS, interface);
519
- }
520
- }
521
468
std::vector<std::string> _probeCommand;
522
469
std::function<void (FoundDeviceT&)> _callback;
523
470
};
@@ -1228,6 +1175,9 @@ struct PerformScan : std::enable_shared_from_this<PerformScan>
1228
1175
}
1229
1176
void run ()
1230
1177
{
1178
+ boost::container::flat_set<std::string> dbusProbeInterfaces;
1179
+ std::vector<std::shared_ptr<PerformProbe>> dbusProbePointers;
1180
+
1231
1181
for (auto it = _configurations.begin (); it != _configurations.end ();)
1232
1182
{
1233
1183
auto findProbe = it->find (" Probe" );
@@ -1272,7 +1222,7 @@ struct PerformScan : std::enable_shared_from_this<PerformScan>
1272
1222
// store reference to this to children to makes sure we don't get
1273
1223
// destroyed too early
1274
1224
auto thisRef = shared_from_this ();
1275
- auto p = std::make_shared<
1225
+ auto probePointer = std::make_shared<
1276
1226
PerformProbe>(probeCommand, [&, recordPtr, probeName, thisRef](
1277
1227
FoundDeviceT& foundDevices) {
1278
1228
_passed = true ;
@@ -1421,9 +1371,39 @@ struct PerformScan : std::enable_shared_from_this<PerformScan>
1421
1371
foundDeviceIdx++;
1422
1372
}
1423
1373
});
1424
- p->run ();
1374
+
1375
+ // parse out dbus probes by discarding other probe types, store in a
1376
+ // map
1377
+ for (const std::string& probe : probeCommand)
1378
+ {
1379
+ bool found = false ;
1380
+ boost::container::flat_map<const char *, probe_type_codes,
1381
+ cmp_str>::const_iterator probeType;
1382
+ for (probeType = PROBE_TYPES.begin ();
1383
+ probeType != PROBE_TYPES.end (); ++probeType)
1384
+ {
1385
+ if (probe.find (probeType->first ) != std::string::npos)
1386
+ {
1387
+ found = true ;
1388
+ break ;
1389
+ }
1390
+ }
1391
+ if (found)
1392
+ {
1393
+ continue ;
1394
+ }
1395
+ // syntax requires probe before first open brace
1396
+ auto findStart = probe.find (" (" );
1397
+ std::string interface = probe.substr (0 , findStart);
1398
+ dbusProbeInterfaces.emplace (interface);
1399
+ dbusProbePointers.emplace_back (probePointer);
1400
+ }
1425
1401
it++;
1426
1402
}
1403
+
1404
+ // probe vector stores a shared_ptr to each PerformProbe that cares
1405
+ // about a dbus interface
1406
+ findDbusObjects (dbusProbePointers, SYSTEM_BUS, dbusProbeInterfaces);
1427
1407
}
1428
1408
1429
1409
~PerformScan ()
@@ -1444,7 +1424,6 @@ struct PerformScan : std::enable_shared_from_this<PerformScan>
1444
1424
nlohmann::json& _missingConfigurations;
1445
1425
std::list<nlohmann::json> _configurations;
1446
1426
std::function<void (void )> _callback;
1447
- std::vector<std::shared_ptr<PerformProbe>> _probes;
1448
1427
bool _passed = false ;
1449
1428
bool powerWasOn = isPowerOn();
1450
1429
};
@@ -1655,8 +1634,8 @@ void registerCallbacks(boost::asio::io_service& io,
1655
1634
1656
1635
for (const auto & objectMap : DBUS_PROBE_OBJECTS)
1657
1636
{
1658
- auto findObject = watchedObjects.find (objectMap.first );
1659
- if (findObject != watchedObjects. end () )
1637
+ auto [_, inserted] = watchedObjects.insert (objectMap.first );
1638
+ if (!inserted )
1660
1639
{
1661
1640
continue ;
1662
1641
}
0 commit comments