blob: 11246dbef2b4b8c25f9b1ab16cb0dd8637c03080 [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>
Dinesh Chinari618027a2017-06-26 23:26:50 -050017#include <phosphor-logging/log.hpp>
Matthew Barthdf3e8d62017-05-31 11:07:24 -050018#include <phosphor-logging/elog.hpp>
Dinesh Chinari618027a2017-06-26 23:26:50 -050019#include <phosphor-logging/elog-errors.hpp>
20#include <xyz/openbmc_project/Common/error.hpp>
Matt Spinler7f88fe62017-04-10 14:39:02 -050021#include "zone.hpp"
Matthew Barthdf3e8d62017-05-31 11:07:24 -050022#include "utility.hpp"
Matthew Barthd953bb22017-08-22 10:45:28 -050023#include "sdbusplus.hpp"
Matt Spinler7f88fe62017-04-10 14:39:02 -050024
25namespace phosphor
26{
27namespace fan
28{
29namespace control
30{
31
Matthew Barth8600d9a2017-06-23 14:38:05 -050032using namespace std::chrono;
Matthew Barth90149802017-08-15 10:51:37 -050033using namespace phosphor::fan;
Matthew Barthdf3e8d62017-05-31 11:07:24 -050034using namespace phosphor::logging;
Dinesh Chinari618027a2017-06-26 23:26:50 -050035using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
36 Error::InternalFailure;
Matt Spinler7f88fe62017-04-10 14:39:02 -050037
Matthew Barth14184132017-05-19 14:37:30 -050038Zone::Zone(Mode mode,
39 sdbusplus::bus::bus& bus,
William A. Kennington III1cfc2f12018-10-19 17:29:46 -070040 const sdeventplus::Event& event,
Matt Spinler7f88fe62017-04-10 14:39:02 -050041 const ZoneDefinition& def) :
42 _bus(bus),
43 _fullSpeed(std::get<fullSpeedPos>(def)),
Matthew Barth1de66622017-06-12 13:13:02 -050044 _zoneNum(std::get<zoneNumPos>(def)),
Matthew Barthe0ca13e2017-06-13 16:29:09 -050045 _defFloorSpeed(std::get<floorSpeedPos>(def)),
Matthew Barth8600d9a2017-06-23 14:38:05 -050046 _defCeilingSpeed(std::get<fullSpeedPos>(def)),
Matthew Bartha9561842017-06-29 11:43:45 -050047 _incDelay(std::get<incDelayPos>(def)),
48 _decInterval(std::get<decIntervalPos>(def)),
William A. Kennington III1cfc2f12018-10-19 17:29:46 -070049 _incTimer(event, [this](){ this->incTimerExpired(); }),
50 _decTimer(event, [this](){ this->decTimerExpired(); }),
51 _eventLoop(event)
Matt Spinler7f88fe62017-04-10 14:39:02 -050052{
53 auto& fanDefs = std::get<fanListPos>(def);
54
55 for (auto& def : fanDefs)
56 {
57 _fans.emplace_back(std::make_unique<Fan>(bus, def));
58 }
Matthew Barth38a93a82017-05-11 14:12:27 -050059
Matthew Barth14184132017-05-19 14:37:30 -050060 // Do not enable set speed events when in init mode
61 if (mode != Mode::init)
Matthew Barth17d1fe22017-05-11 15:00:36 -050062 {
Matthew Barth2b3db612017-10-25 10:56:51 -050063 // Update target speed to current zone target speed
64 if (!_fans.empty())
65 {
66 _targetSpeed = _fans.front()->getTargetSpeed();
67 }
Matthew Barthccc77702017-07-28 13:43:04 -050068 // Setup signal trigger for set speed events
69 for (auto& event : std::get<setSpeedEventsPos>(def))
70 {
71 initEvent(event);
72 }
Matthew Barth8600d9a2017-06-23 14:38:05 -050073 // Start timer for fan speed decreases
Matthew Bartha9561842017-06-29 11:43:45 -050074 if (!_decTimer.running() && _decInterval != seconds::zero())
Matthew Barth8600d9a2017-06-23 14:38:05 -050075 {
William A. Kennington III0ce353e2018-10-30 18:30:36 -070076 _decTimer.start(_decInterval, TimerType::repeating);
Matthew Barth8600d9a2017-06-23 14:38:05 -050077 }
Matthew Barth38a93a82017-05-11 14:12:27 -050078 }
Matt Spinler7f88fe62017-04-10 14:39:02 -050079}
80
Matt Spinler7f88fe62017-04-10 14:39:02 -050081void Zone::setSpeed(uint64_t speed)
82{
Matthew Barth60b00762017-08-15 13:39:06 -050083 if (_isActive)
Matt Spinler7f88fe62017-04-10 14:39:02 -050084 {
Matthew Barth60b00762017-08-15 13:39:06 -050085 _targetSpeed = speed;
86 for (auto& fan : _fans)
87 {
88 fan->setSpeed(_targetSpeed);
89 }
90 }
91}
92
93void Zone::setFullSpeed()
94{
95 if (_fullSpeed != 0)
96 {
97 _targetSpeed = _fullSpeed;
98 for (auto& fan : _fans)
99 {
100 fan->setSpeed(_targetSpeed);
101 }
Matt Spinler7f88fe62017-04-10 14:39:02 -0500102 }
103}
104
Matthew Barth861d77c2017-05-22 14:18:25 -0500105void Zone::setActiveAllow(const Group* group, bool isActiveAllow)
106{
Matthew Barth60b00762017-08-15 13:39:06 -0500107 _active[*(group)] = isActiveAllow;
Matthew Barth861d77c2017-05-22 14:18:25 -0500108 if (!isActiveAllow)
109 {
110 _isActive = false;
111 }
112 else
113 {
114 // Check all entries are set to allow control active
115 auto actPred = [](auto const& entry) {return entry.second;};
116 _isActive = std::all_of(_active.begin(),
117 _active.end(),
118 actPred);
119 }
120}
121
Matthew Barth55dea642017-11-06 13:34:32 -0600122void Zone::removeService(const Group* group,
123 const std::string& name)
124{
125 try
126 {
127 auto& sNames = _services.at(*group);
128 auto it = std::find_if(
129 sNames.begin(),
130 sNames.end(),
131 [&name](auto const& entry)
132 {
133 return name == std::get<namePos>(entry);
134 }
135 );
136 if (it != std::end(sNames))
137 {
138 // Remove service name from group
139 sNames.erase(it);
140 }
141 }
142 catch (const std::out_of_range& oore)
143 {
144 // No services for group found
145 }
146}
147
Matthew Barthe59fdf72017-09-27 09:33:42 -0500148void Zone::setServiceOwner(const Group* group,
149 const std::string& name,
150 const bool hasOwner)
151{
152 try
153 {
154 auto& sNames = _services.at(*group);
155 auto it = std::find_if(
156 sNames.begin(),
157 sNames.end(),
158 [&name](auto const& entry)
159 {
160 return name == std::get<namePos>(entry);
161 }
162 );
163 if (it != std::end(sNames))
164 {
165 std::get<hasOwnerPos>(*it) = hasOwner;
166 }
167 else
168 {
169 _services[*group].emplace_back(name, hasOwner);
170 }
171 }
172 catch (const std::out_of_range& oore)
173 {
174 _services[*group].emplace_back(name, hasOwner);
175 }
176}
177
Matthew Barth480787c2017-11-06 11:00:00 -0600178void Zone::setServices(const Group* group)
179{
Matthew Barth55dea642017-11-06 13:34:32 -0600180 // Remove the empty service name if exists
181 removeService(group, "");
Matthew Barth480787c2017-11-06 11:00:00 -0600182 for (auto it = group->begin(); it != group->end(); ++it)
183 {
184 std::string name;
185 bool hasOwner = false;
186 try
187 {
Matthew Barthc72b8912018-01-19 17:28:18 -0600188 name = getService(it->first,
189 std::get<intfPos>(it->second));
Matthew Barth480787c2017-11-06 11:00:00 -0600190 hasOwner = util::SDBusPlus::callMethodAndRead<bool>(
191 _bus,
192 "org.freedesktop.DBus",
193 "/org/freedesktop/DBus",
194 "org.freedesktop.DBus",
195 "NameHasOwner",
196 name);
197 }
Matt Spinlerba7b5fe2018-04-25 15:26:10 -0500198 catch (const util::DBusMethodError& e)
Matthew Barth480787c2017-11-06 11:00:00 -0600199 {
200 // Failed to get service name owner state
201 hasOwner = false;
202 }
203 setServiceOwner(group, name, hasOwner);
204 }
205}
206
Matthew Barthb4a7cb92017-06-28 15:29:50 -0500207void Zone::setFloor(uint64_t speed)
208{
Matthew Barth98726c42017-10-17 10:35:20 -0500209 // Check all entries are set to allow floor to be set
210 auto pred = [](auto const& entry) {return entry.second;};
211 auto setFloor = std::all_of(_floorChange.begin(),
212 _floorChange.end(),
213 pred);
214 if (setFloor)
Matthew Barthb4a7cb92017-06-28 15:29:50 -0500215 {
Matthew Barth98726c42017-10-17 10:35:20 -0500216 _floorSpeed = speed;
217 // Floor speed above target, update target to floor speed
218 if (_targetSpeed < _floorSpeed)
219 {
220 requestSpeedIncrease(_floorSpeed - _targetSpeed);
221 }
Matthew Barthb4a7cb92017-06-28 15:29:50 -0500222 }
223}
224
Matthew Barth240397b2017-06-22 11:23:30 -0500225void Zone::requestSpeedIncrease(uint64_t targetDelta)
226{
227 // Only increase speed when delta is higher than
228 // the current increase delta for the zone and currently under ceiling
229 if (targetDelta > _incSpeedDelta &&
230 _targetSpeed < _ceilingSpeed)
231 {
Matthew Barth4e728542017-09-14 16:47:55 -0500232 auto requestTarget = getRequestSpeedBase();
Matthew Barth60b00762017-08-15 13:39:06 -0500233 requestTarget = (targetDelta - _incSpeedDelta) + requestTarget;
Matthew Barth240397b2017-06-22 11:23:30 -0500234 _incSpeedDelta = targetDelta;
Matthew Barth240397b2017-06-22 11:23:30 -0500235 // Target speed can not go above a defined ceiling speed
Matthew Barth60b00762017-08-15 13:39:06 -0500236 if (requestTarget > _ceilingSpeed)
Matthew Barth240397b2017-06-22 11:23:30 -0500237 {
Matthew Barth60b00762017-08-15 13:39:06 -0500238 requestTarget = _ceilingSpeed;
Matthew Barth240397b2017-06-22 11:23:30 -0500239 }
Matthew Barth1ee48f22017-06-27 15:14:48 -0500240 // Cancel current timer countdown
241 if (_incTimer.running())
242 {
243 _incTimer.stop();
244 }
Matthew Barth60b00762017-08-15 13:39:06 -0500245 setSpeed(requestTarget);
Matthew Barth1ee48f22017-06-27 15:14:48 -0500246 // Start timer countdown for fan speed increase
William A. Kennington III0ce353e2018-10-30 18:30:36 -0700247 _incTimer.start(_incDelay, TimerType::oneshot);
Matthew Barth240397b2017-06-22 11:23:30 -0500248 }
Matthew Barth1ee48f22017-06-27 15:14:48 -0500249}
250
251void Zone::incTimerExpired()
252{
253 // Clear increase delta when timer expires allowing additional speed
254 // increase requests or speed decreases to occur
Matthew Barth240397b2017-06-22 11:23:30 -0500255 _incSpeedDelta = 0;
256}
257
Matthew Barth0ce99d82017-06-22 15:07:29 -0500258void Zone::requestSpeedDecrease(uint64_t targetDelta)
259{
260 // Only decrease the lowest target delta requested
261 if (_decSpeedDelta == 0 || targetDelta < _decSpeedDelta)
262 {
263 _decSpeedDelta = targetDelta;
264 }
Matthew Barth8600d9a2017-06-23 14:38:05 -0500265}
Matthew Barth0ce99d82017-06-22 15:07:29 -0500266
Matthew Barth8600d9a2017-06-23 14:38:05 -0500267void Zone::decTimerExpired()
268{
Matthew Barthe4338cd2017-12-14 11:14:30 -0600269 // Check all entries are set to allow a decrease
270 auto pred = [](auto const& entry) {return entry.second;};
271 auto decAllowed = std::all_of(_decAllowed.begin(),
272 _decAllowed.end(),
273 pred);
274
275 // Only decrease speeds when allowed,
276 // where no requested increases exist and
277 // the increase timer is not running
278 // (i.e. not in the middle of increasing)
279 if (decAllowed && _incSpeedDelta == 0 && !_incTimer.running())
Matthew Barth0ce99d82017-06-22 15:07:29 -0500280 {
Matthew Barth4e728542017-09-14 16:47:55 -0500281 auto requestTarget = getRequestSpeedBase();
Matthew Barthc63973a2017-12-08 15:31:35 -0600282 // Request target speed should not start above ceiling
283 if (requestTarget > _ceilingSpeed)
284 {
285 requestTarget = _ceilingSpeed;
286 }
Matthew Barth0ce99d82017-06-22 15:07:29 -0500287 // Target speed can not go below the defined floor speed
Matthew Barth60b00762017-08-15 13:39:06 -0500288 if ((requestTarget < _decSpeedDelta) ||
289 (requestTarget - _decSpeedDelta < _floorSpeed))
Matthew Barth0ce99d82017-06-22 15:07:29 -0500290 {
Matthew Barth60b00762017-08-15 13:39:06 -0500291 requestTarget = _floorSpeed;
Matthew Barth0ce99d82017-06-22 15:07:29 -0500292 }
293 else
294 {
Matthew Barth60b00762017-08-15 13:39:06 -0500295 requestTarget = requestTarget - _decSpeedDelta;
Matthew Barth0ce99d82017-06-22 15:07:29 -0500296 }
Matthew Barth60b00762017-08-15 13:39:06 -0500297 setSpeed(requestTarget);
Matthew Barth0ce99d82017-06-22 15:07:29 -0500298 }
299 // Clear decrease delta when timer expires
300 _decSpeedDelta = 0;
Matthew Barth8600d9a2017-06-23 14:38:05 -0500301 // Decrease timer is restarted since its repeating
Matthew Barth0ce99d82017-06-22 15:07:29 -0500302}
303
Matthew Barthccc77702017-07-28 13:43:04 -0500304void Zone::initEvent(const SetSpeedEvent& event)
Matthew Barth1bf0ce42017-06-23 16:16:30 -0500305{
Matthew Barth336f18a2017-09-26 09:15:56 -0500306 sdbusplus::message::message nullMsg{nullptr};
307
Matthew Barth67967f92017-09-22 12:43:57 -0500308 for (auto& sig : std::get<signalsPos>(event))
Matthew Barthccc77702017-07-28 13:43:04 -0500309 {
Matthew Barth336f18a2017-09-26 09:15:56 -0500310 // Initialize the event signal using handler
311 std::get<sigHandlerPos>(sig)(_bus, nullMsg, *this);
312 // Setup signal matches of the property for event
Matthew Barthf6b76d82017-08-04 12:58:02 -0500313 std::unique_ptr<EventData> eventData =
314 std::make_unique<EventData>(
Matthew Barthf6b76d82017-08-04 12:58:02 -0500315 std::get<groupPos>(event),
Matthew Barth336f18a2017-09-26 09:15:56 -0500316 std::get<sigMatchPos>(sig),
317 std::get<sigHandlerPos>(sig),
Matthew Barthf9201ab2017-09-11 16:07:58 -0500318 std::get<actionsPos>(event)
Matthew Barthf6b76d82017-08-04 12:58:02 -0500319 );
Matthew Barth336f18a2017-09-26 09:15:56 -0500320 std::unique_ptr<sdbusplus::server::match::match> match = nullptr;
321 if (!std::get<sigMatchPos>(sig).empty())
322 {
323 match = std::make_unique<sdbusplus::server::match::match>(
324 _bus,
325 std::get<sigMatchPos>(sig).c_str(),
326 std::bind(std::mem_fn(&Zone::handleEvent),
327 this,
328 std::placeholders::_1,
329 eventData.get())
330 );
331 }
Matthew Barthf6b76d82017-08-04 12:58:02 -0500332 _signalEvents.emplace_back(std::move(eventData), std::move(match));
Matthew Barthccc77702017-07-28 13:43:04 -0500333 }
Matthew Barth90149802017-08-15 10:51:37 -0500334 // Attach a timer to run the action of an event
335 auto eventTimer = std::get<timerPos>(event);
336 if (std::get<intervalPos>(eventTimer) != seconds(0))
337 {
Matthew Barthbfb1a562017-10-05 17:03:40 -0500338 // Associate event data with timer
339 std::unique_ptr<EventData> eventData =
340 std::make_unique<EventData>(
Matthew Barth34a389e2017-11-07 14:01:22 -0600341 std::get<groupPos>(event),
342 "",
343 nullptr,
344 std::get<actionsPos>(event)
Matthew Barthbfb1a562017-10-05 17:03:40 -0500345 );
Matthew Barth90149802017-08-15 10:51:37 -0500346 std::unique_ptr<util::Timer> timer =
347 std::make_unique<util::Timer>(
William A. Kennington III1cfc2f12018-10-19 17:29:46 -0700348 _eventLoop,
Matthew Barth90149802017-08-15 10:51:37 -0500349 [this,
Matthew Barthf9201ab2017-09-11 16:07:58 -0500350 action = &(std::get<actionsPos>(event)),
Matthew Barth90149802017-08-15 10:51:37 -0500351 group = &(std::get<groupPos>(event))]()
352 {
353 this->timerExpired(*group, *action);
354 });
355 if (!timer->running())
356 {
357 timer->start(std::get<intervalPos>(eventTimer),
Matthew Barth7b7ceb82017-10-04 12:59:50 -0500358 std::get<typePos>(eventTimer));
Matthew Barth90149802017-08-15 10:51:37 -0500359 }
Matthew Barthbfb1a562017-10-05 17:03:40 -0500360 addTimer(std::move(eventData), std::move(timer));
Matthew Barth90149802017-08-15 10:51:37 -0500361 }
Matthew Barthf9201ab2017-09-11 16:07:58 -0500362 // Run action functions for initial event state
363 std::for_each(
364 std::get<actionsPos>(event).begin(),
365 std::get<actionsPos>(event).end(),
366 [this, &event](auto const& action)
367 {
368 action(*this,
369 std::get<groupPos>(event));
370 });
Matthew Barth1bf0ce42017-06-23 16:16:30 -0500371}
372
Matthew Barthf6b76d82017-08-04 12:58:02 -0500373void Zone::removeEvent(const SetSpeedEvent& event)
374{
375 // Find the signal event to be removed
376 auto it = std::find_if(
377 _signalEvents.begin(),
378 _signalEvents.end(),
379 [&event](auto const& se)
380 {
381 auto seEventData = *std::get<signalEventDataPos>(se);
Matthew Barthf9201ab2017-09-11 16:07:58 -0500382 if (std::get<eventActionsPos>(seEventData).size() !=
383 std::get<actionsPos>(event).size())
384 {
385 return false;
386 }
387 else
388 {
389 // TODO openbmc/openbmc#2328 - Use the action function target
390 // for comparison
391 auto actsEqual = [](auto const& a1,
392 auto const& a2)
393 {
394 return a1.target_type().name() ==
395 a2.target_type().name();
396 };
397 return
398 (
399 std::get<eventGroupPos>(seEventData) ==
400 std::get<groupPos>(event) &&
401 std::equal(std::get<actionsPos>(event).begin(),
402 std::get<actionsPos>(event).end(),
403 std::get<eventActionsPos>(seEventData).begin(),
404 actsEqual)
405 );
406 }
Matthew Barthf6b76d82017-08-04 12:58:02 -0500407 });
408 if (it != std::end(_signalEvents))
409 {
410 std::get<signalEventDataPos>(*it).reset();
Matthew Barth336f18a2017-09-26 09:15:56 -0500411 if (std::get<signalMatchPos>(*it) != nullptr)
412 {
413 std::get<signalMatchPos>(*it).reset();
414 }
Matthew Barthf6b76d82017-08-04 12:58:02 -0500415 _signalEvents.erase(it);
416 }
417}
418
Matthew Barthbfb1a562017-10-05 17:03:40 -0500419std::vector<TimerEvent>::iterator Zone::findTimer(
420 const Group& eventGroup,
421 const std::vector<Action>& eventActions)
422{
423 for (auto it = _timerEvents.begin(); it != _timerEvents.end(); ++it)
424 {
425 auto teEventData = *std::get<timerEventDataPos>(*it);
426 if (std::get<eventActionsPos>(teEventData).size() ==
427 eventActions.size())
428 {
429 // TODO openbmc/openbmc#2328 - Use the action function target
430 // for comparison
431 auto actsEqual = [](auto const& a1,
432 auto const& a2)
433 {
434 return a1.target_type().name() ==
435 a2.target_type().name();
436 };
437 if (std::get<eventGroupPos>(teEventData) == eventGroup &&
438 std::equal(eventActions.begin(),
439 eventActions.end(),
440 std::get<eventActionsPos>(teEventData).begin(),
441 actsEqual))
442 {
443 return it;
444 }
445 }
446 }
447
448 return _timerEvents.end();
449}
450
Matthew Barthf9201ab2017-09-11 16:07:58 -0500451void Zone::timerExpired(Group eventGroup, std::vector<Action> eventActions)
Matthew Barth90149802017-08-15 10:51:37 -0500452{
Matthew Barthf9201ab2017-09-11 16:07:58 -0500453 // Perform the actions
454 std::for_each(eventActions.begin(),
455 eventActions.end(),
456 [this, &eventGroup](auto const& action)
457 {
458 action(*this, eventGroup);
459 });
Matthew Barth90149802017-08-15 10:51:37 -0500460}
461
Matthew Barth38a93a82017-05-11 14:12:27 -0500462void Zone::handleEvent(sdbusplus::message::message& msg,
Matthew Barth34f1bda2017-05-31 13:45:36 -0500463 const EventData* eventData)
Matthew Barth38a93a82017-05-11 14:12:27 -0500464{
465 // Handle the callback
Matthew Barth34f1bda2017-05-31 13:45:36 -0500466 std::get<eventHandlerPos>(*eventData)(_bus, msg, *this);
Matthew Barthf9201ab2017-09-11 16:07:58 -0500467 // Perform the actions
468 std::for_each(
469 std::get<eventActionsPos>(*eventData).begin(),
470 std::get<eventActionsPos>(*eventData).end(),
471 [this, &eventData](auto const& action)
472 {
473 action(*this,
474 std::get<eventGroupPos>(*eventData));
475 });
Matthew Barth38a93a82017-05-11 14:12:27 -0500476}
477
Matthew Bartha603ed02018-01-19 16:56:26 -0600478const std::string& Zone::getService(const std::string& path,
479 const std::string& intf)
480{
481 // Retrieve service from cache
482 auto srvIter = _servTree.find(path);
483 if (srvIter != _servTree.end())
484 {
485 for (auto& serv : srvIter->second)
486 {
487 auto it = std::find_if(
488 serv.second.begin(),
489 serv.second.end(),
490 [&intf](auto const& interface)
491 {
492 return intf == interface;
493 });
494 if (it != std::end(serv.second))
495 {
496 // Service found
497 return serv.first;
498 }
499 }
500 // Interface not found in cache, add and return
501 return addServices(path, intf, 0);
502 }
503 else
504 {
505 // Path not found in cache, add and return
506 return addServices(path, intf, 0);
507 }
508}
509
510const std::string& Zone::addServices(const std::string& path,
511 const std::string& intf,
512 int32_t depth)
513{
514 static const std::string empty = "";
515 auto it = _servTree.end();
516
517 // Get all subtree objects for the given interface
518 auto objects = util::SDBusPlus::getSubTree(_bus, "/", intf, depth);
519 // Add what's returned to the cache of path->services
520 for (auto& pIter : objects)
521 {
522 auto pathIter = _servTree.find(pIter.first);
523 if (pathIter != _servTree.end())
524 {
525 // Path found in cache
526 for (auto& sIter : pIter.second)
527 {
528 auto servIter = pathIter->second.find(sIter.first);
529 if (servIter != pathIter->second.end())
530 {
531 // Service found in cache
532 for (auto& iIter : sIter.second)
533 {
534 // Add interface to cache
535 servIter->second.emplace_back(iIter);
536 }
537 }
538 else
539 {
540 // Service not found in cache
541 pathIter->second.insert(sIter);
542 }
543 }
544 }
545 else
546 {
547 _servTree.insert(pIter);
548 }
549 // When the paths match, since a single interface constraint is given,
550 // that is the service to return
551 if (path == pIter.first)
552 {
553 it = _servTree.find(pIter.first);
554 }
555 }
556
557 if (it != _servTree.end())
558 {
559 return it->second.begin()->first;
560 }
561
562 return empty;
563}
564
Matt Spinler7f88fe62017-04-10 14:39:02 -0500565}
566}
567}