blob: 17ec5fceaa44f604a9315f21635777e1fde755b6 [file] [log] [blame]
Matt Spinler7f88fe62017-04-10 14:39:02 -05001/**
2 * Copyright © 2017 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matthew Barth8600d9a2017-06-23 14:38:05 -050016#include <chrono>
William A. Kennington III22c36ab2018-10-30 19:50:57 -070017#include <functional>
Dinesh Chinari618027a2017-06-26 23:26:50 -050018#include <phosphor-logging/log.hpp>
Matthew Barthdf3e8d62017-05-31 11:07:24 -050019#include <phosphor-logging/elog.hpp>
Dinesh Chinari618027a2017-06-26 23:26:50 -050020#include <phosphor-logging/elog-errors.hpp>
21#include <xyz/openbmc_project/Common/error.hpp>
Matt Spinler7f88fe62017-04-10 14:39:02 -050022#include "zone.hpp"
Matthew Barthdf3e8d62017-05-31 11:07:24 -050023#include "utility.hpp"
Matthew Barthd953bb22017-08-22 10:45:28 -050024#include "sdbusplus.hpp"
Matt Spinler7f88fe62017-04-10 14:39:02 -050025
26namespace phosphor
27{
28namespace fan
29{
30namespace control
31{
32
Matthew Barth8600d9a2017-06-23 14:38:05 -050033using namespace std::chrono;
Matthew Barth90149802017-08-15 10:51:37 -050034using namespace phosphor::fan;
Matthew Barthdf3e8d62017-05-31 11:07:24 -050035using namespace phosphor::logging;
Dinesh Chinari618027a2017-06-26 23:26:50 -050036using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
37 Error::InternalFailure;
Matt Spinler7f88fe62017-04-10 14:39:02 -050038
Matthew Barth14184132017-05-19 14:37:30 -050039Zone::Zone(Mode mode,
40 sdbusplus::bus::bus& bus,
William A. Kennington III1cfc2f12018-10-19 17:29:46 -070041 const sdeventplus::Event& event,
Matt Spinler7f88fe62017-04-10 14:39:02 -050042 const ZoneDefinition& def) :
43 _bus(bus),
44 _fullSpeed(std::get<fullSpeedPos>(def)),
Matthew Barth1de66622017-06-12 13:13:02 -050045 _zoneNum(std::get<zoneNumPos>(def)),
Matthew Barthe0ca13e2017-06-13 16:29:09 -050046 _defFloorSpeed(std::get<floorSpeedPos>(def)),
Matthew Barth8600d9a2017-06-23 14:38:05 -050047 _defCeilingSpeed(std::get<fullSpeedPos>(def)),
Matthew Bartha9561842017-06-29 11:43:45 -050048 _incDelay(std::get<incDelayPos>(def)),
49 _decInterval(std::get<decIntervalPos>(def)),
William A. Kennington III22c36ab2018-10-30 19:50:57 -070050 _incTimer(event, std::bind(&Zone::incTimerExpired, this)),
51 _decTimer(event, std::bind(&Zone::decTimerExpired, this)),
William A. Kennington III1cfc2f12018-10-19 17:29:46 -070052 _eventLoop(event)
Matt Spinler7f88fe62017-04-10 14:39:02 -050053{
54 auto& fanDefs = std::get<fanListPos>(def);
55
56 for (auto& def : fanDefs)
57 {
58 _fans.emplace_back(std::make_unique<Fan>(bus, def));
59 }
Matthew Barth38a93a82017-05-11 14:12:27 -050060
Matthew Barth14184132017-05-19 14:37:30 -050061 // Do not enable set speed events when in init mode
62 if (mode != Mode::init)
Matthew Barth17d1fe22017-05-11 15:00:36 -050063 {
Matthew Barth2b3db612017-10-25 10:56:51 -050064 // Update target speed to current zone target speed
65 if (!_fans.empty())
66 {
67 _targetSpeed = _fans.front()->getTargetSpeed();
68 }
Matthew Barthccc77702017-07-28 13:43:04 -050069 // Setup signal trigger for set speed events
70 for (auto& event : std::get<setSpeedEventsPos>(def))
71 {
72 initEvent(event);
73 }
Matthew Barth8600d9a2017-06-23 14:38:05 -050074 // Start timer for fan speed decreases
Matthew Bartha9561842017-06-29 11:43:45 -050075 if (!_decTimer.running() && _decInterval != seconds::zero())
Matthew Barth8600d9a2017-06-23 14:38:05 -050076 {
William A. Kennington III0ce353e2018-10-30 18:30:36 -070077 _decTimer.start(_decInterval, TimerType::repeating);
Matthew Barth8600d9a2017-06-23 14:38:05 -050078 }
Matthew Barth38a93a82017-05-11 14:12:27 -050079 }
Matt Spinler7f88fe62017-04-10 14:39:02 -050080}
81
Matt Spinler7f88fe62017-04-10 14:39:02 -050082void Zone::setSpeed(uint64_t speed)
83{
Matthew Barth60b00762017-08-15 13:39:06 -050084 if (_isActive)
Matt Spinler7f88fe62017-04-10 14:39:02 -050085 {
Matthew Barth60b00762017-08-15 13:39:06 -050086 _targetSpeed = speed;
87 for (auto& fan : _fans)
88 {
89 fan->setSpeed(_targetSpeed);
90 }
91 }
92}
93
94void Zone::setFullSpeed()
95{
96 if (_fullSpeed != 0)
97 {
98 _targetSpeed = _fullSpeed;
99 for (auto& fan : _fans)
100 {
101 fan->setSpeed(_targetSpeed);
102 }
Matt Spinler7f88fe62017-04-10 14:39:02 -0500103 }
104}
105
Matthew Barth861d77c2017-05-22 14:18:25 -0500106void Zone::setActiveAllow(const Group* group, bool isActiveAllow)
107{
Matthew Barth60b00762017-08-15 13:39:06 -0500108 _active[*(group)] = isActiveAllow;
Matthew Barth861d77c2017-05-22 14:18:25 -0500109 if (!isActiveAllow)
110 {
111 _isActive = false;
112 }
113 else
114 {
115 // Check all entries are set to allow control active
116 auto actPred = [](auto const& entry) {return entry.second;};
117 _isActive = std::all_of(_active.begin(),
118 _active.end(),
119 actPred);
120 }
121}
122
Matthew Barth55dea642017-11-06 13:34:32 -0600123void Zone::removeService(const Group* group,
124 const std::string& name)
125{
126 try
127 {
128 auto& sNames = _services.at(*group);
129 auto it = std::find_if(
130 sNames.begin(),
131 sNames.end(),
132 [&name](auto const& entry)
133 {
134 return name == std::get<namePos>(entry);
135 }
136 );
137 if (it != std::end(sNames))
138 {
139 // Remove service name from group
140 sNames.erase(it);
141 }
142 }
143 catch (const std::out_of_range& oore)
144 {
145 // No services for group found
146 }
147}
148
Matthew Barthe59fdf72017-09-27 09:33:42 -0500149void Zone::setServiceOwner(const Group* group,
150 const std::string& name,
151 const bool hasOwner)
152{
153 try
154 {
155 auto& sNames = _services.at(*group);
156 auto it = std::find_if(
157 sNames.begin(),
158 sNames.end(),
159 [&name](auto const& entry)
160 {
161 return name == std::get<namePos>(entry);
162 }
163 );
164 if (it != std::end(sNames))
165 {
166 std::get<hasOwnerPos>(*it) = hasOwner;
167 }
168 else
169 {
170 _services[*group].emplace_back(name, hasOwner);
171 }
172 }
173 catch (const std::out_of_range& oore)
174 {
175 _services[*group].emplace_back(name, hasOwner);
176 }
177}
178
Matthew Barth480787c2017-11-06 11:00:00 -0600179void Zone::setServices(const Group* group)
180{
Matthew Barth55dea642017-11-06 13:34:32 -0600181 // Remove the empty service name if exists
182 removeService(group, "");
Matthew Barth480787c2017-11-06 11:00:00 -0600183 for (auto it = group->begin(); it != group->end(); ++it)
184 {
185 std::string name;
186 bool hasOwner = false;
187 try
188 {
Matthew Barthc72b8912018-01-19 17:28:18 -0600189 name = getService(it->first,
190 std::get<intfPos>(it->second));
Matthew Barth480787c2017-11-06 11:00:00 -0600191 hasOwner = util::SDBusPlus::callMethodAndRead<bool>(
192 _bus,
193 "org.freedesktop.DBus",
194 "/org/freedesktop/DBus",
195 "org.freedesktop.DBus",
196 "NameHasOwner",
197 name);
198 }
Matt Spinlerba7b5fe2018-04-25 15:26:10 -0500199 catch (const util::DBusMethodError& e)
Matthew Barth480787c2017-11-06 11:00:00 -0600200 {
201 // Failed to get service name owner state
202 hasOwner = false;
203 }
204 setServiceOwner(group, name, hasOwner);
205 }
206}
207
Matthew Barthb4a7cb92017-06-28 15:29:50 -0500208void Zone::setFloor(uint64_t speed)
209{
Matthew Barth98726c42017-10-17 10:35:20 -0500210 // Check all entries are set to allow floor to be set
211 auto pred = [](auto const& entry) {return entry.second;};
212 auto setFloor = std::all_of(_floorChange.begin(),
213 _floorChange.end(),
214 pred);
215 if (setFloor)
Matthew Barthb4a7cb92017-06-28 15:29:50 -0500216 {
Matthew Barth98726c42017-10-17 10:35:20 -0500217 _floorSpeed = speed;
218 // Floor speed above target, update target to floor speed
219 if (_targetSpeed < _floorSpeed)
220 {
221 requestSpeedIncrease(_floorSpeed - _targetSpeed);
222 }
Matthew Barthb4a7cb92017-06-28 15:29:50 -0500223 }
224}
225
Matthew Barth240397b2017-06-22 11:23:30 -0500226void Zone::requestSpeedIncrease(uint64_t targetDelta)
227{
228 // Only increase speed when delta is higher than
229 // the current increase delta for the zone and currently under ceiling
230 if (targetDelta > _incSpeedDelta &&
231 _targetSpeed < _ceilingSpeed)
232 {
Matthew Barth4e728542017-09-14 16:47:55 -0500233 auto requestTarget = getRequestSpeedBase();
Matthew Barth60b00762017-08-15 13:39:06 -0500234 requestTarget = (targetDelta - _incSpeedDelta) + requestTarget;
Matthew Barth240397b2017-06-22 11:23:30 -0500235 _incSpeedDelta = targetDelta;
Matthew Barth240397b2017-06-22 11:23:30 -0500236 // Target speed can not go above a defined ceiling speed
Matthew Barth60b00762017-08-15 13:39:06 -0500237 if (requestTarget > _ceilingSpeed)
Matthew Barth240397b2017-06-22 11:23:30 -0500238 {
Matthew Barth60b00762017-08-15 13:39:06 -0500239 requestTarget = _ceilingSpeed;
Matthew Barth240397b2017-06-22 11:23:30 -0500240 }
Matthew Barth1ee48f22017-06-27 15:14:48 -0500241 // Cancel current timer countdown
242 if (_incTimer.running())
243 {
244 _incTimer.stop();
245 }
Matthew Barth60b00762017-08-15 13:39:06 -0500246 setSpeed(requestTarget);
Matthew Barth1ee48f22017-06-27 15:14:48 -0500247 // Start timer countdown for fan speed increase
William A. Kennington III0ce353e2018-10-30 18:30:36 -0700248 _incTimer.start(_incDelay, TimerType::oneshot);
Matthew Barth240397b2017-06-22 11:23:30 -0500249 }
Matthew Barth1ee48f22017-06-27 15:14:48 -0500250}
251
252void Zone::incTimerExpired()
253{
254 // Clear increase delta when timer expires allowing additional speed
255 // increase requests or speed decreases to occur
Matthew Barth240397b2017-06-22 11:23:30 -0500256 _incSpeedDelta = 0;
257}
258
Matthew Barth0ce99d82017-06-22 15:07:29 -0500259void Zone::requestSpeedDecrease(uint64_t targetDelta)
260{
261 // Only decrease the lowest target delta requested
262 if (_decSpeedDelta == 0 || targetDelta < _decSpeedDelta)
263 {
264 _decSpeedDelta = targetDelta;
265 }
Matthew Barth8600d9a2017-06-23 14:38:05 -0500266}
Matthew Barth0ce99d82017-06-22 15:07:29 -0500267
Matthew Barth8600d9a2017-06-23 14:38:05 -0500268void Zone::decTimerExpired()
269{
Matthew Barthe4338cd2017-12-14 11:14:30 -0600270 // Check all entries are set to allow a decrease
271 auto pred = [](auto const& entry) {return entry.second;};
272 auto decAllowed = std::all_of(_decAllowed.begin(),
273 _decAllowed.end(),
274 pred);
275
276 // Only decrease speeds when allowed,
277 // where no requested increases exist and
278 // the increase timer is not running
279 // (i.e. not in the middle of increasing)
280 if (decAllowed && _incSpeedDelta == 0 && !_incTimer.running())
Matthew Barth0ce99d82017-06-22 15:07:29 -0500281 {
Matthew Barth4e728542017-09-14 16:47:55 -0500282 auto requestTarget = getRequestSpeedBase();
Matthew Barthc63973a2017-12-08 15:31:35 -0600283 // Request target speed should not start above ceiling
284 if (requestTarget > _ceilingSpeed)
285 {
286 requestTarget = _ceilingSpeed;
287 }
Matthew Barth0ce99d82017-06-22 15:07:29 -0500288 // Target speed can not go below the defined floor speed
Matthew Barth60b00762017-08-15 13:39:06 -0500289 if ((requestTarget < _decSpeedDelta) ||
290 (requestTarget - _decSpeedDelta < _floorSpeed))
Matthew Barth0ce99d82017-06-22 15:07:29 -0500291 {
Matthew Barth60b00762017-08-15 13:39:06 -0500292 requestTarget = _floorSpeed;
Matthew Barth0ce99d82017-06-22 15:07:29 -0500293 }
294 else
295 {
Matthew Barth60b00762017-08-15 13:39:06 -0500296 requestTarget = requestTarget - _decSpeedDelta;
Matthew Barth0ce99d82017-06-22 15:07:29 -0500297 }
Matthew Barth60b00762017-08-15 13:39:06 -0500298 setSpeed(requestTarget);
Matthew Barth0ce99d82017-06-22 15:07:29 -0500299 }
300 // Clear decrease delta when timer expires
301 _decSpeedDelta = 0;
Matthew Barth8600d9a2017-06-23 14:38:05 -0500302 // Decrease timer is restarted since its repeating
Matthew Barth0ce99d82017-06-22 15:07:29 -0500303}
304
Matthew Barthccc77702017-07-28 13:43:04 -0500305void Zone::initEvent(const SetSpeedEvent& event)
Matthew Barth1bf0ce42017-06-23 16:16:30 -0500306{
Matthew Barth336f18a2017-09-26 09:15:56 -0500307 sdbusplus::message::message nullMsg{nullptr};
308
Matthew Barth67967f92017-09-22 12:43:57 -0500309 for (auto& sig : std::get<signalsPos>(event))
Matthew Barthccc77702017-07-28 13:43:04 -0500310 {
Matthew Barth336f18a2017-09-26 09:15:56 -0500311 // Initialize the event signal using handler
312 std::get<sigHandlerPos>(sig)(_bus, nullMsg, *this);
313 // Setup signal matches of the property for event
Matthew Barthf6b76d82017-08-04 12:58:02 -0500314 std::unique_ptr<EventData> eventData =
315 std::make_unique<EventData>(
Matthew Barthf6b76d82017-08-04 12:58:02 -0500316 std::get<groupPos>(event),
Matthew Barth336f18a2017-09-26 09:15:56 -0500317 std::get<sigMatchPos>(sig),
318 std::get<sigHandlerPos>(sig),
Matthew Barthf9201ab2017-09-11 16:07:58 -0500319 std::get<actionsPos>(event)
Matthew Barthf6b76d82017-08-04 12:58:02 -0500320 );
Matthew Barth336f18a2017-09-26 09:15:56 -0500321 std::unique_ptr<sdbusplus::server::match::match> match = nullptr;
322 if (!std::get<sigMatchPos>(sig).empty())
323 {
324 match = std::make_unique<sdbusplus::server::match::match>(
325 _bus,
326 std::get<sigMatchPos>(sig).c_str(),
327 std::bind(std::mem_fn(&Zone::handleEvent),
328 this,
329 std::placeholders::_1,
330 eventData.get())
331 );
332 }
Matthew Barthf6b76d82017-08-04 12:58:02 -0500333 _signalEvents.emplace_back(std::move(eventData), std::move(match));
Matthew Barthccc77702017-07-28 13:43:04 -0500334 }
Matthew Barth90149802017-08-15 10:51:37 -0500335 // Attach a timer to run the action of an event
William A. Kennington III122b8432018-10-30 18:39:21 -0700336 auto timerConf = std::get<timerConfPos>(event);
337 if (std::get<intervalPos>(timerConf) != seconds(0))
Matthew Barth90149802017-08-15 10:51:37 -0500338 {
William A. Kennington III94fe1a02018-10-30 19:00:27 -0700339 addTimer(std::get<groupPos>(event),
340 std::get<actionsPos>(event),
341 timerConf);
Matthew Barth90149802017-08-15 10:51:37 -0500342 }
Matthew Barthf9201ab2017-09-11 16:07:58 -0500343 // Run action functions for initial event state
344 std::for_each(
345 std::get<actionsPos>(event).begin(),
346 std::get<actionsPos>(event).end(),
347 [this, &event](auto const& action)
348 {
349 action(*this,
350 std::get<groupPos>(event));
351 });
Matthew Barth1bf0ce42017-06-23 16:16:30 -0500352}
353
Matthew Barthf6b76d82017-08-04 12:58:02 -0500354void Zone::removeEvent(const SetSpeedEvent& event)
355{
356 // Find the signal event to be removed
357 auto it = std::find_if(
358 _signalEvents.begin(),
359 _signalEvents.end(),
360 [&event](auto const& se)
361 {
362 auto seEventData = *std::get<signalEventDataPos>(se);
Matthew Barthf9201ab2017-09-11 16:07:58 -0500363 if (std::get<eventActionsPos>(seEventData).size() !=
364 std::get<actionsPos>(event).size())
365 {
366 return false;
367 }
368 else
369 {
370 // TODO openbmc/openbmc#2328 - Use the action function target
371 // for comparison
372 auto actsEqual = [](auto const& a1,
373 auto const& a2)
374 {
375 return a1.target_type().name() ==
376 a2.target_type().name();
377 };
378 return
379 (
380 std::get<eventGroupPos>(seEventData) ==
381 std::get<groupPos>(event) &&
382 std::equal(std::get<actionsPos>(event).begin(),
383 std::get<actionsPos>(event).end(),
384 std::get<eventActionsPos>(seEventData).begin(),
385 actsEqual)
386 );
387 }
Matthew Barthf6b76d82017-08-04 12:58:02 -0500388 });
389 if (it != std::end(_signalEvents))
390 {
391 std::get<signalEventDataPos>(*it).reset();
Matthew Barth336f18a2017-09-26 09:15:56 -0500392 if (std::get<signalMatchPos>(*it) != nullptr)
393 {
394 std::get<signalMatchPos>(*it).reset();
395 }
Matthew Barthf6b76d82017-08-04 12:58:02 -0500396 _signalEvents.erase(it);
397 }
398}
399
Matthew Barthbfb1a562017-10-05 17:03:40 -0500400std::vector<TimerEvent>::iterator Zone::findTimer(
401 const Group& eventGroup,
402 const std::vector<Action>& eventActions)
403{
404 for (auto it = _timerEvents.begin(); it != _timerEvents.end(); ++it)
405 {
406 auto teEventData = *std::get<timerEventDataPos>(*it);
407 if (std::get<eventActionsPos>(teEventData).size() ==
408 eventActions.size())
409 {
410 // TODO openbmc/openbmc#2328 - Use the action function target
411 // for comparison
412 auto actsEqual = [](auto const& a1,
413 auto const& a2)
414 {
415 return a1.target_type().name() ==
416 a2.target_type().name();
417 };
418 if (std::get<eventGroupPos>(teEventData) == eventGroup &&
419 std::equal(eventActions.begin(),
420 eventActions.end(),
421 std::get<eventActionsPos>(teEventData).begin(),
422 actsEqual))
423 {
424 return it;
425 }
426 }
427 }
428
429 return _timerEvents.end();
430}
431
William A. Kennington III94fe1a02018-10-30 19:00:27 -0700432void Zone::addTimer(const Group& group,
433 const std::vector<Action>& actions,
434 const TimerConf& tConf)
435{
436 // Associate event data with timer
437 auto data = std::make_unique<EventData>(
438 group,
439 "",
440 nullptr,
441 actions
442 );
443 auto timer = std::make_unique<util::Timer>(
444 _eventLoop,
William A. Kennington IIIc0c5f072018-10-30 19:11:01 -0700445 std::bind(&Zone::timerExpired,
446 this,
447 std::cref(std::get<Group>(*data)),
448 std::cref(std::get<std::vector<Action>>(*data)))
William A. Kennington III94fe1a02018-10-30 19:00:27 -0700449 );
450 if (!timer->running())
451 {
452 timer->start(std::get<intervalPos>(tConf),
453 std::get<typePos>(tConf));
454 }
455 _timerEvents.emplace_back(std::move(data), std::move(timer));
456}
457
William A. Kennington IIIc0c5f072018-10-30 19:11:01 -0700458void Zone::timerExpired(const Group& eventGroup,
459 const std::vector<Action>& eventActions)
Matthew Barth90149802017-08-15 10:51:37 -0500460{
Matthew Barthf9201ab2017-09-11 16:07:58 -0500461 // Perform the actions
462 std::for_each(eventActions.begin(),
463 eventActions.end(),
464 [this, &eventGroup](auto const& action)
465 {
466 action(*this, eventGroup);
467 });
Matthew Barth90149802017-08-15 10:51:37 -0500468}
469
Matthew Barth38a93a82017-05-11 14:12:27 -0500470void Zone::handleEvent(sdbusplus::message::message& msg,
Matthew Barth34f1bda2017-05-31 13:45:36 -0500471 const EventData* eventData)
Matthew Barth38a93a82017-05-11 14:12:27 -0500472{
473 // Handle the callback
Matthew Barth34f1bda2017-05-31 13:45:36 -0500474 std::get<eventHandlerPos>(*eventData)(_bus, msg, *this);
Matthew Barthf9201ab2017-09-11 16:07:58 -0500475 // Perform the actions
476 std::for_each(
477 std::get<eventActionsPos>(*eventData).begin(),
478 std::get<eventActionsPos>(*eventData).end(),
479 [this, &eventData](auto const& action)
480 {
481 action(*this,
482 std::get<eventGroupPos>(*eventData));
483 });
Matthew Barth38a93a82017-05-11 14:12:27 -0500484}
485
Matthew Bartha603ed02018-01-19 16:56:26 -0600486const std::string& Zone::getService(const std::string& path,
487 const std::string& intf)
488{
489 // Retrieve service from cache
490 auto srvIter = _servTree.find(path);
491 if (srvIter != _servTree.end())
492 {
493 for (auto& serv : srvIter->second)
494 {
495 auto it = std::find_if(
496 serv.second.begin(),
497 serv.second.end(),
498 [&intf](auto const& interface)
499 {
500 return intf == interface;
501 });
502 if (it != std::end(serv.second))
503 {
504 // Service found
505 return serv.first;
506 }
507 }
508 // Interface not found in cache, add and return
509 return addServices(path, intf, 0);
510 }
511 else
512 {
513 // Path not found in cache, add and return
514 return addServices(path, intf, 0);
515 }
516}
517
518const std::string& Zone::addServices(const std::string& path,
519 const std::string& intf,
520 int32_t depth)
521{
522 static const std::string empty = "";
523 auto it = _servTree.end();
524
525 // Get all subtree objects for the given interface
526 auto objects = util::SDBusPlus::getSubTree(_bus, "/", intf, depth);
527 // Add what's returned to the cache of path->services
528 for (auto& pIter : objects)
529 {
530 auto pathIter = _servTree.find(pIter.first);
531 if (pathIter != _servTree.end())
532 {
533 // Path found in cache
534 for (auto& sIter : pIter.second)
535 {
536 auto servIter = pathIter->second.find(sIter.first);
537 if (servIter != pathIter->second.end())
538 {
539 // Service found in cache
540 for (auto& iIter : sIter.second)
541 {
542 // Add interface to cache
543 servIter->second.emplace_back(iIter);
544 }
545 }
546 else
547 {
548 // Service not found in cache
549 pathIter->second.insert(sIter);
550 }
551 }
552 }
553 else
554 {
555 _servTree.insert(pIter);
556 }
557 // When the paths match, since a single interface constraint is given,
558 // that is the service to return
559 if (path == pIter.first)
560 {
561 it = _servTree.find(pIter.first);
562 }
563 }
564
565 if (it != _servTree.end())
566 {
567 return it->second.begin()->first;
568 }
569
570 return empty;
571}
572
Matt Spinler7f88fe62017-04-10 14:39:02 -0500573}
574}
575}