blob: 1ca04657dc3571e7b8371111905d3fecdb2c179f [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
William A. Kennington III122b8432018-10-30 18:39:21 -0700335 auto timerConf = std::get<timerConfPos>(event);
336 if (std::get<intervalPos>(timerConf) != seconds(0))
Matthew Barth90149802017-08-15 10:51:37 -0500337 {
William A. Kennington III94fe1a02018-10-30 19:00:27 -0700338 addTimer(std::get<groupPos>(event),
339 std::get<actionsPos>(event),
340 timerConf);
Matthew Barth90149802017-08-15 10:51:37 -0500341 }
Matthew Barthf9201ab2017-09-11 16:07:58 -0500342 // Run action functions for initial event state
343 std::for_each(
344 std::get<actionsPos>(event).begin(),
345 std::get<actionsPos>(event).end(),
346 [this, &event](auto const& action)
347 {
348 action(*this,
349 std::get<groupPos>(event));
350 });
Matthew Barth1bf0ce42017-06-23 16:16:30 -0500351}
352
Matthew Barthf6b76d82017-08-04 12:58:02 -0500353void Zone::removeEvent(const SetSpeedEvent& event)
354{
355 // Find the signal event to be removed
356 auto it = std::find_if(
357 _signalEvents.begin(),
358 _signalEvents.end(),
359 [&event](auto const& se)
360 {
361 auto seEventData = *std::get<signalEventDataPos>(se);
Matthew Barthf9201ab2017-09-11 16:07:58 -0500362 if (std::get<eventActionsPos>(seEventData).size() !=
363 std::get<actionsPos>(event).size())
364 {
365 return false;
366 }
367 else
368 {
369 // TODO openbmc/openbmc#2328 - Use the action function target
370 // for comparison
371 auto actsEqual = [](auto const& a1,
372 auto const& a2)
373 {
374 return a1.target_type().name() ==
375 a2.target_type().name();
376 };
377 return
378 (
379 std::get<eventGroupPos>(seEventData) ==
380 std::get<groupPos>(event) &&
381 std::equal(std::get<actionsPos>(event).begin(),
382 std::get<actionsPos>(event).end(),
383 std::get<eventActionsPos>(seEventData).begin(),
384 actsEqual)
385 );
386 }
Matthew Barthf6b76d82017-08-04 12:58:02 -0500387 });
388 if (it != std::end(_signalEvents))
389 {
390 std::get<signalEventDataPos>(*it).reset();
Matthew Barth336f18a2017-09-26 09:15:56 -0500391 if (std::get<signalMatchPos>(*it) != nullptr)
392 {
393 std::get<signalMatchPos>(*it).reset();
394 }
Matthew Barthf6b76d82017-08-04 12:58:02 -0500395 _signalEvents.erase(it);
396 }
397}
398
Matthew Barthbfb1a562017-10-05 17:03:40 -0500399std::vector<TimerEvent>::iterator Zone::findTimer(
400 const Group& eventGroup,
401 const std::vector<Action>& eventActions)
402{
403 for (auto it = _timerEvents.begin(); it != _timerEvents.end(); ++it)
404 {
405 auto teEventData = *std::get<timerEventDataPos>(*it);
406 if (std::get<eventActionsPos>(teEventData).size() ==
407 eventActions.size())
408 {
409 // TODO openbmc/openbmc#2328 - Use the action function target
410 // for comparison
411 auto actsEqual = [](auto const& a1,
412 auto const& a2)
413 {
414 return a1.target_type().name() ==
415 a2.target_type().name();
416 };
417 if (std::get<eventGroupPos>(teEventData) == eventGroup &&
418 std::equal(eventActions.begin(),
419 eventActions.end(),
420 std::get<eventActionsPos>(teEventData).begin(),
421 actsEqual))
422 {
423 return it;
424 }
425 }
426 }
427
428 return _timerEvents.end();
429}
430
William A. Kennington III94fe1a02018-10-30 19:00:27 -0700431void Zone::addTimer(const Group& group,
432 const std::vector<Action>& actions,
433 const TimerConf& tConf)
434{
435 // Associate event data with timer
436 auto data = std::make_unique<EventData>(
437 group,
438 "",
439 nullptr,
440 actions
441 );
442 auto timer = std::make_unique<util::Timer>(
443 _eventLoop,
William A. Kennington IIIc0c5f072018-10-30 19:11:01 -0700444 std::bind(&Zone::timerExpired,
445 this,
446 std::cref(std::get<Group>(*data)),
447 std::cref(std::get<std::vector<Action>>(*data)))
William A. Kennington III94fe1a02018-10-30 19:00:27 -0700448 );
449 if (!timer->running())
450 {
451 timer->start(std::get<intervalPos>(tConf),
452 std::get<typePos>(tConf));
453 }
454 _timerEvents.emplace_back(std::move(data), std::move(timer));
455}
456
William A. Kennington IIIc0c5f072018-10-30 19:11:01 -0700457void Zone::timerExpired(const Group& eventGroup,
458 const std::vector<Action>& eventActions)
Matthew Barth90149802017-08-15 10:51:37 -0500459{
Matthew Barthf9201ab2017-09-11 16:07:58 -0500460 // Perform the actions
461 std::for_each(eventActions.begin(),
462 eventActions.end(),
463 [this, &eventGroup](auto const& action)
464 {
465 action(*this, eventGroup);
466 });
Matthew Barth90149802017-08-15 10:51:37 -0500467}
468
Matthew Barth38a93a82017-05-11 14:12:27 -0500469void Zone::handleEvent(sdbusplus::message::message& msg,
Matthew Barth34f1bda2017-05-31 13:45:36 -0500470 const EventData* eventData)
Matthew Barth38a93a82017-05-11 14:12:27 -0500471{
472 // Handle the callback
Matthew Barth34f1bda2017-05-31 13:45:36 -0500473 std::get<eventHandlerPos>(*eventData)(_bus, msg, *this);
Matthew Barthf9201ab2017-09-11 16:07:58 -0500474 // Perform the actions
475 std::for_each(
476 std::get<eventActionsPos>(*eventData).begin(),
477 std::get<eventActionsPos>(*eventData).end(),
478 [this, &eventData](auto const& action)
479 {
480 action(*this,
481 std::get<eventGroupPos>(*eventData));
482 });
Matthew Barth38a93a82017-05-11 14:12:27 -0500483}
484
Matthew Bartha603ed02018-01-19 16:56:26 -0600485const std::string& Zone::getService(const std::string& path,
486 const std::string& intf)
487{
488 // Retrieve service from cache
489 auto srvIter = _servTree.find(path);
490 if (srvIter != _servTree.end())
491 {
492 for (auto& serv : srvIter->second)
493 {
494 auto it = std::find_if(
495 serv.second.begin(),
496 serv.second.end(),
497 [&intf](auto const& interface)
498 {
499 return intf == interface;
500 });
501 if (it != std::end(serv.second))
502 {
503 // Service found
504 return serv.first;
505 }
506 }
507 // Interface not found in cache, add and return
508 return addServices(path, intf, 0);
509 }
510 else
511 {
512 // Path not found in cache, add and return
513 return addServices(path, intf, 0);
514 }
515}
516
517const std::string& Zone::addServices(const std::string& path,
518 const std::string& intf,
519 int32_t depth)
520{
521 static const std::string empty = "";
522 auto it = _servTree.end();
523
524 // Get all subtree objects for the given interface
525 auto objects = util::SDBusPlus::getSubTree(_bus, "/", intf, depth);
526 // Add what's returned to the cache of path->services
527 for (auto& pIter : objects)
528 {
529 auto pathIter = _servTree.find(pIter.first);
530 if (pathIter != _servTree.end())
531 {
532 // Path found in cache
533 for (auto& sIter : pIter.second)
534 {
535 auto servIter = pathIter->second.find(sIter.first);
536 if (servIter != pathIter->second.end())
537 {
538 // Service found in cache
539 for (auto& iIter : sIter.second)
540 {
541 // Add interface to cache
542 servIter->second.emplace_back(iIter);
543 }
544 }
545 else
546 {
547 // Service not found in cache
548 pathIter->second.insert(sIter);
549 }
550 }
551 }
552 else
553 {
554 _servTree.insert(pIter);
555 }
556 // When the paths match, since a single interface constraint is given,
557 // that is the service to return
558 if (path == pIter.first)
559 {
560 it = _servTree.find(pIter.first);
561 }
562 }
563
564 if (it != _servTree.end())
565 {
566 return it->second.begin()->first;
567 }
568
569 return empty;
570}
571
Matt Spinler7f88fe62017-04-10 14:39:02 -0500572}
573}
574}