1 //-----------------------------------------------------------------------------
2 //
3 //	Manager.cpp
4 //
5 //	The main public interface to OpenZWave.
6 //
7 //	Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
8 //
9 //	SOFTWARE NOTICE AND LICENSE
10 //
11 //	This file is part of OpenZWave.
12 //
13 //	OpenZWave is free software: you can redistribute it and/or modify
14 //	it under the terms of the GNU Lesser General Public License as published
15 //	by the Free Software Foundation, either version 3 of the License,
16 //	or (at your option) any later version.
17 //
18 //	OpenZWave is distributed in the hope that it will be useful,
19 //	but WITHOUT ANY WARRANTY; without even the implied warranty of
20 //	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 //	GNU Lesser General Public License for more details.
22 //
23 //	You should have received a copy of the GNU Lesser General Public License
24 //	along with OpenZWave.  If not, see <http://www.gnu.org/licenses/>.
25 //
26 //-----------------------------------------------------------------------------
27 
28 #include <algorithm>
29 #include <string>
30 #include <sstream>
31 #include <iomanip>
32 
33 #include "Defs.h"
34 #include "CompatOptionManager.h"
35 #include "Manager.h"
36 #include "Driver.h"
37 #include "Localization.h"
38 #include "Node.h"
39 #include "Notification.h"
40 #include "NotificationCCTypes.h"
41 #include "Options.h"
42 #include "Scene.h"
43 #include "SensorMultiLevelCCTypes.h"
44 #include "Utils.h"
45 
46 #include "platform/Mutex.h"
47 #include "platform/Event.h"
48 #include "platform/Log.h"
49 
50 #include "command_classes/CommandClasses.h"
51 #include "command_classes/CommandClass.h"
52 #include "command_classes/WakeUp.h"
53 
54 #include "value_classes/ValueID.h"
55 #include "value_classes/ValueBool.h"
56 #include "value_classes/ValueButton.h"
57 #include "value_classes/ValueByte.h"
58 #include "value_classes/ValueDecimal.h"
59 #include "value_classes/ValueInt.h"
60 #include "value_classes/ValueList.h"
61 #include "value_classes/ValueRaw.h"
62 #include "value_classes/ValueSchedule.h"
63 #include "value_classes/ValueShort.h"
64 #include "value_classes/ValueString.h"
65 #include "value_classes/ValueBitSet.h"
66 
67 using namespace OpenZWave;
68 
69 Manager* Manager::s_instance = NULL;
70 extern uint16_t ozw_vers_major;
71 extern uint16_t ozw_vers_minor;
72 extern uint16_t ozw_vers_revision;
73 extern char ozw_version_string[];
74 
75 //-----------------------------------------------------------------------------
76 //	Construction
77 //-----------------------------------------------------------------------------
78 #include "platform/FileOps.h"
79 //-----------------------------------------------------------------------------
80 //	<Manager::Create>
81 //	Static creation of the singleton
82 //-----------------------------------------------------------------------------
Create()83 Manager* Manager::Create()
84 {
85 
86 	if (Options::Get() && Options::Get()->AreLocked())
87 	{
88 		if ( NULL == s_instance)
89 		{
90 			s_instance = new Manager();
91 		}
92 		return s_instance;
93 	}
94 
95 	// Options have not been created and locked.
96 	Log::Create("", false, true, LogLevel_Debug, LogLevel_Debug, LogLevel_None);
97 	Log::Write(LogLevel_Error, "Options have not been created and locked. Exiting...");
98 	OZW_FATAL_ERROR(OZWException::OZWEXCEPTION_OPTIONS, "Options Not Created and Locked");
99 	return NULL;
100 }
101 
102 //-----------------------------------------------------------------------------
103 //	<Manager::Destroy>
104 //	Static method to destroy the singleton.
105 //-----------------------------------------------------------------------------
Destroy()106 void Manager::Destroy()
107 {
108 	delete s_instance;
109 	s_instance = NULL;
110 }
111 
112 //-----------------------------------------------------------------------------
113 //	<Manager::getVersion>
114 //	Static method to get the Version of OZW as a string.
115 //-----------------------------------------------------------------------------
getVersionAsString()116 std::string Manager::getVersionAsString()
117 {
118 	std::ostringstream versionstream;
119 	versionstream << ozw_vers_major << "." << ozw_vers_minor << "." << ozw_vers_revision;
120 	return versionstream.str();
121 }
122 //-----------------------------------------------------------------------------
123 //      <Manager::getVersionLong>
124 //      Static method to get the long Version of OZW as a string.
125 //-----------------------------------------------------------------------------
getVersionLongAsString()126 std::string Manager::getVersionLongAsString()
127 {
128 	std::ostringstream versionstream;
129 	versionstream << ozw_version_string;
130 	return versionstream.str();
131 }
132 //-----------------------------------------------------------------------------
133 //	<Manager::getVersion>
134 //	Static method to get the Version of OZW.
135 //-----------------------------------------------------------------------------
getVersion()136 ozwversion Manager::getVersion()
137 {
138 	return version(ozw_vers_major, ozw_vers_minor);
139 }
140 
141 //-----------------------------------------------------------------------------
142 // <Manager::Manager>
143 // Constructor
144 //-----------------------------------------------------------------------------
Manager()145 Manager::Manager() :
146 		m_notificationMutex(new Internal::Platform::Mutex())
147 {
148 	// Ensure the singleton instance is set
149 	s_instance = this;
150 
151 	// Create the log file (if enabled)
152 	bool logging = false;
153 	Options::Get()->GetOptionAsBool("Logging", &logging);
154 
155 	string userPath = "";
156 	Options::Get()->GetOptionAsString("UserPath", &userPath);
157 
158 	string logFileNameBase = "OZW_Log.txt";
159 	Options::Get()->GetOptionAsString("LogFileName", &logFileNameBase);
160 
161 	bool bAppend = false;
162 	Options::Get()->GetOptionAsBool("AppendLogFile", &bAppend);
163 
164 	bool bConsoleOutput = true;
165 	Options::Get()->GetOptionAsBool("ConsoleOutput", &bConsoleOutput);
166 
167 	int nSaveLogLevel = (int) LogLevel_Detail;
168 
169 	Options::Get()->GetOptionAsInt("SaveLogLevel", &nSaveLogLevel);
170 	if ((nSaveLogLevel == 0) || (nSaveLogLevel > LogLevel_StreamDetail))
171 	{
172 		Log::Write(LogLevel_Warning, "Invalid LogLevel Specified for SaveLogLevel in Options.xml");
173 		nSaveLogLevel = (int) LogLevel_Detail;
174 	}
175 
176 	int nQueueLogLevel = (int) LogLevel_Debug;
177 	Options::Get()->GetOptionAsInt("QueueLogLevel", &nQueueLogLevel);
178 	if ((nQueueLogLevel == 0) || (nQueueLogLevel > LogLevel_StreamDetail))
179 	{
180 		Log::Write(LogLevel_Warning, "Invalid LogLevel Specified for QueueLogLevel in Options.xml");
181 		nQueueLogLevel = (int) LogLevel_Debug;
182 	}
183 
184 	int nDumpTrigger = (int) LogLevel_Warning;
185 	Options::Get()->GetOptionAsInt("DumpTriggerLevel", &nDumpTrigger);
186 
187 	string logFilename = userPath + logFileNameBase;
188 	Log::Create(logFilename, bAppend, bConsoleOutput, (LogLevel) nSaveLogLevel, (LogLevel) nQueueLogLevel, (LogLevel) nDumpTrigger);
189 	Log::SetLoggingState(logging);
190 
191 	Internal::CC::CommandClasses::RegisterCommandClasses();
192 	Internal::Scene::ReadScenes();
193 	// petergebruers replace getVersionAsString() with getVersionLongAsString() because
194 	// the latter prints more information, based on the status of the repository
195 	// when "make" was run. A Makefile gets this info from git describe --long --tags --dirty
196 	Log::Write(LogLevel_Always, "OpenZwave Version %s Starting Up", getVersionLongAsString().c_str());
197 	Log::Write(LogLevel_Always, "Using Language Localization %s", Internal::Localization::Get()->GetSelectedLang().c_str());
198 	if (!Internal::NotificationCCTypes::Create()) {
199 		Log::Write(LogLevel_Error, "mgr,     Cannot Create NotificationCCTypes!");
200 	}
201 	if (!Internal::SensorMultiLevelCCTypes::Create()) {
202 		Log::Write(LogLevel_Error, "mgr,     Cannot Create SensorMultiLevelCCTypes!");
203 	}
204 
205 }
206 
207 //-----------------------------------------------------------------------------
208 // <Manager::Manager>
209 // Destructor
210 //-----------------------------------------------------------------------------
~Manager()211 Manager::~Manager()
212 {
213 	// Clear the pending list
214 	while (!m_pendingDrivers.empty())
215 	{
216 		list<Driver*>::iterator it = m_pendingDrivers.begin();
217 		delete *it;
218 		m_pendingDrivers.erase(it);
219 	}
220 	m_pendingDrivers.clear();
221 
222 	// Clear the ready map
223 	while (!m_readyDrivers.empty())
224 	{
225 		map<uint32, Driver*>::iterator it = m_readyDrivers.begin();
226 		delete it->second;
227 		m_readyDrivers.erase(it);
228 	}
229 	m_readyDrivers.clear();
230 
231 	m_notificationMutex->Release();
232 
233 	// Clear the watchers list
234 	while (!m_watchers.empty())
235 	{
236 		list<Watcher*>::iterator it = m_watchers.begin();
237 		delete *it;
238 		m_watchers.erase(it);
239 	}
240 	m_watchers.clear();
241 
242 	// Clear the generic device class list
243 	while (!Node::s_genericDeviceClasses.empty())
244 	{
245 		map<uint8, Node::GenericDeviceClass*>::iterator git = Node::s_genericDeviceClasses.begin();
246 		delete git->second;
247 		Node::s_genericDeviceClasses.erase(git);
248 	}
249 	Node::s_genericDeviceClasses.clear();
250 
251 	while (!Node::s_basicDeviceClasses.empty())
252 	{
253 		map<uint8, string>::iterator git = Node::s_basicDeviceClasses.begin();
254 		Node::s_basicDeviceClasses.erase(git);
255 	}
256 	Node::s_basicDeviceClasses.clear();
257 
258 	while (!Node::s_roleDeviceClasses.empty())
259 	{
260 		map<uint8, Node::DeviceClass*>::iterator git = Node::s_roleDeviceClasses.begin();
261 		delete git->second;
262 		Node::s_roleDeviceClasses.erase(git);
263 	}
264 	Node::s_roleDeviceClasses.clear();
265 
266 	while (!Node::s_deviceTypeClasses.empty())
267 	{
268 		map<uint16, Node::DeviceClass*>::iterator git = Node::s_deviceTypeClasses.begin();
269 		delete git->second;
270 		Node::s_deviceTypeClasses.erase(git);
271 	}
272 	Node::s_deviceTypeClasses.clear();
273 
274 	while (!Node::s_nodeTypes.empty())
275 	{
276 		map<uint8, Node::DeviceClass*>::iterator git = Node::s_nodeTypes.begin();
277 		delete git->second;
278 		Node::s_nodeTypes.erase(git);
279 	}
280 	Node::s_nodeTypes.clear();
281 
282 	Node::s_deviceClassesLoaded = false;
283 
284 	Log::Destroy();
285 }
286 
287 //-----------------------------------------------------------------------------
288 // Configuration
289 //-----------------------------------------------------------------------------
290 
291 //-----------------------------------------------------------------------------
292 // <Manager::WriteConfig>
293 // Save the configuration of a driver to a file
294 //-----------------------------------------------------------------------------
WriteConfig(uint32 const _homeId)295 void Manager::WriteConfig(uint32 const _homeId)
296 {
297 	if (Driver* driver = GetDriver(_homeId))
298 	{
299 		driver->WriteCache();
300 		Log::Write(LogLevel_Info, "mgr,     Manager::WriteConfig completed for driver with home ID of 0x%.8x", _homeId);
301 	}
302 	else
303 	{
304 		Log::Write(LogLevel_Info, "mgr,     Manager::WriteConfig failed - _homeId %d not found", _homeId);
305 	}
306 	Internal::Scene::WriteXML("zwscene.xml");
307 }
308 
309 //-----------------------------------------------------------------------------
310 //	Drivers
311 //-----------------------------------------------------------------------------
312 
313 //-----------------------------------------------------------------------------
314 // <Manager::AddDriver>
315 // Add a new Z-Wave PC Interface
316 //-----------------------------------------------------------------------------
AddDriver(string const & _controllerPath,Driver::ControllerInterface const & _interface)317 bool Manager::AddDriver(string const& _controllerPath, Driver::ControllerInterface const& _interface)
318 {
319 	// Make sure we don't already have a driver for this controller
320 
321 	// Search the pending list
322 	for (list<Driver*>::iterator pit = m_pendingDrivers.begin(); pit != m_pendingDrivers.end(); ++pit)
323 	{
324 		if (_controllerPath == (*pit)->GetControllerPath())
325 		{
326 			Log::Write(LogLevel_Info, "mgr,     Cannot add driver for controller %s - driver already exists", _controllerPath.c_str());
327 			return false;
328 		}
329 	}
330 
331 	// Search the ready map
332 	for (map<uint32, Driver*>::iterator rit = m_readyDrivers.begin(); rit != m_readyDrivers.end(); ++rit)
333 	{
334 		if (_controllerPath == rit->second->GetControllerPath())
335 		{
336 			Log::Write(LogLevel_Info, "mgr,     Cannot add driver for controller %s - driver already exists", _controllerPath.c_str());
337 			return false;
338 		}
339 	}
340 
341 	Driver* driver = new Driver(_controllerPath, _interface);
342 	m_pendingDrivers.push_back(driver);
343 	driver->Start();
344 
345 	Log::Write(LogLevel_Info, "mgr,     Added driver for controller %s", _controllerPath.c_str());
346 	return true;
347 }
348 
349 //-----------------------------------------------------------------------------
350 // <Manager::RemoveDriver>
351 // Remove a Z-Wave PC Interface
352 //-----------------------------------------------------------------------------
RemoveDriver(string const & _controllerPath)353 bool Manager::RemoveDriver(string const& _controllerPath)
354 {
355 	// Search the pending list
356 	for (list<Driver*>::iterator pit = m_pendingDrivers.begin(); pit != m_pendingDrivers.end(); ++pit)
357 	{
358 		if (_controllerPath == (*pit)->GetControllerPath())
359 		{
360 			delete *pit;
361 			m_pendingDrivers.erase(pit);
362 			Log::Write(LogLevel_Info, "mgr,     Driver for controller %s removed", _controllerPath.c_str());
363 			return true;
364 		}
365 	}
366 
367 	// Search the ready map
368 	for (map<uint32, Driver*>::iterator rit = m_readyDrivers.begin(); rit != m_readyDrivers.end(); ++rit)
369 	{
370 		if (_controllerPath == rit->second->GetControllerPath())
371 		{
372 			/* data race right here:
373 			 * Before, we were deleting the Driver Class direct from the Map... this was causing a datarace:
374 			 * 1) Driver::~Driver destructor starts deleting everything....
375 			 * 2) This Triggers Notifications such as ValueDeleted etc
376 			 * 3) Notifications are delivered to applications, and applications start calling
377 			 *    Manager Functions which require the Driver (such as IsPolled(valueid))
378 			 * 4) Manager looks up the Driver in the m_readyDriver and returns a pointer to the Driver Class
379 			 *    which is currently being destructed.
380 			 * 5) All Hell Breaks loose and we crash and burn.
381 			 *
382 			 * But we can't change this, as the Driver Destructor triggers internal GetDriver calls... which
383 			 * will crash and burn if they can't get a valid Driver back...
384 			 */
385 			Log::Write(LogLevel_Info, "mgr,     Driver for controller %s pending removal", _controllerPath.c_str());
386 			delete rit->second;
387 			m_readyDrivers.erase(rit);
388 			Log::Write(LogLevel_Info, "mgr,     Driver for controller %s removed", _controllerPath.c_str());
389 			return true;
390 		}
391 	}
392 
393 	Log::Write(LogLevel_Info, "mgr,     Failed to remove driver for controller %s", _controllerPath.c_str());
394 	return false;
395 }
396 
397 //-----------------------------------------------------------------------------
398 // <Manager::GetDriver>
399 // Get a pointer to the driver for a Z-Wave PC Interface
400 //-----------------------------------------------------------------------------
GetDriver(uint32 const _homeId)401 Driver* Manager::GetDriver(uint32 const _homeId)
402 {
403 	map<uint32, Driver*>::iterator it = m_readyDrivers.find(_homeId);
404 	if (it != m_readyDrivers.end())
405 	{
406 		return it->second;
407 	}
408 
409 	Log::Write(LogLevel_Error, "mgr,     Manager::GetDriver failed - Home ID 0x%.8x is unknown", _homeId);
410 	OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_HOMEID, "Invalid HomeId passed to GetDriver");
411 	//assert(0); << Don't assert as this might be a valid condition when we call RemoveDriver. See comments above.
412 	return NULL;
413 }
414 
415 //-----------------------------------------------------------------------------
416 // <Manager::SetDriverReady>
417 // Move a driver from pending to ready, and notify any watchers
418 //-----------------------------------------------------------------------------
SetDriverReady(Driver * _driver,bool success)419 void Manager::SetDriverReady(Driver* _driver, bool success)
420 {
421 	// Search the pending list
422 	bool found = false;
423 	for (list<Driver*>::iterator it = m_pendingDrivers.begin(); it != m_pendingDrivers.end(); ++it)
424 	{
425 		if ((*it) == _driver)
426 		{
427 			// Remove the driver from the pending list
428 			m_pendingDrivers.erase(it);
429 			found = true;
430 			break;
431 		}
432 	}
433 
434 	if (found)
435 	{
436 		if (success)
437 		{
438 			Log::Write(LogLevel_Info, "mgr,     Driver with Home ID of 0x%.8x is now ready.", _driver->GetHomeId());
439 			Log::Write(LogLevel_Info, "");
440 
441 			// Add the driver to the ready map
442 			m_readyDrivers[_driver->GetHomeId()] = _driver;
443 
444 		}
445 
446 		// Notify the watchers
447 		Notification* notification = new Notification(success ? Notification::Type_DriverReady : Notification::Type_DriverFailed);
448 		notification->SetHomeAndNodeIds(_driver->GetHomeId(), _driver->GetControllerNodeId());
449 		if (!success)
450 			notification->SetComPort(_driver->GetControllerPath());
451 		_driver->QueueNotification(notification);
452 	}
453 }
454 
455 //-----------------------------------------------------------------------------
456 // <Manager::GetControllerNodeId>
457 //
458 //-----------------------------------------------------------------------------
GetControllerNodeId(uint32 const _homeId)459 uint8 Manager::GetControllerNodeId(uint32 const _homeId)
460 {
461 	if (Driver* driver = GetDriver(_homeId))
462 	{
463 		return driver->GetControllerNodeId();
464 	}
465 
466 	Log::Write(LogLevel_Info, "mgr,     GetControllerNodeId() failed - _homeId %d not found", _homeId);
467 	return 0xff;
468 }
469 
470 //-----------------------------------------------------------------------------
471 // <Manager::GetSUCNodeId>
472 //
473 //-----------------------------------------------------------------------------
GetSUCNodeId(uint32 const _homeId)474 uint8 Manager::GetSUCNodeId(uint32 const _homeId)
475 {
476 	if (Driver* driver = GetDriver(_homeId))
477 	{
478 		return driver->GetSUCNodeId();
479 	}
480 
481 	Log::Write(LogLevel_Info, "mgr,     GetSUCNodeId() failed - _homeId %d not found", _homeId);
482 	return 0xff;
483 }
484 
485 //-----------------------------------------------------------------------------
486 // <Manager::IsPrimaryController>
487 //
488 //-----------------------------------------------------------------------------
IsPrimaryController(uint32 const _homeId)489 bool Manager::IsPrimaryController(uint32 const _homeId)
490 {
491 	if (Driver* driver = GetDriver(_homeId))
492 	{
493 		return driver->IsPrimaryController();
494 	}
495 
496 	Log::Write(LogLevel_Info, "mgr,     IsPrimaryController() failed - _homeId %d not found", _homeId);
497 	return false;
498 }
499 
500 //-----------------------------------------------------------------------------
501 // <Manager::IsStaticUpdateController>
502 //
503 //-----------------------------------------------------------------------------
IsStaticUpdateController(uint32 const _homeId)504 bool Manager::IsStaticUpdateController(uint32 const _homeId)
505 {
506 	if (Driver* driver = GetDriver(_homeId))
507 	{
508 		return driver->IsStaticUpdateController();
509 	}
510 
511 	Log::Write(LogLevel_Info, "mgr,     IsStaticUpdateController() failed - _homeId %d not found", _homeId);
512 	return false;
513 }
514 
515 //-----------------------------------------------------------------------------
516 // <Manager::IsBridgeController>
517 //
518 //-----------------------------------------------------------------------------
IsBridgeController(uint32 const _homeId)519 bool Manager::IsBridgeController(uint32 const _homeId)
520 {
521 	if (Driver* driver = GetDriver(_homeId))
522 	{
523 		return driver->IsBridgeController();
524 	}
525 
526 	Log::Write(LogLevel_Info, "mgr,     IsBridgeController() failed - _homeId %d not found", _homeId);
527 	return false;
528 }
529 
530 //-----------------------------------------------------------------------------
531 // <Manager::HasExtendedTxStatus>
532 //
533 //-----------------------------------------------------------------------------
HasExtendedTxStatus(uint32 const _homeId)534 bool Manager::HasExtendedTxStatus(uint32 const _homeId)
535 {
536 	if (Driver* driver = GetDriver(_homeId))
537 	{
538 		return driver->HasExtendedTxStatus();
539 	}
540 
541 	Log::Write(LogLevel_Info, "mgr,     HasExtendedTxStatus() failed - _homeId %d not found", _homeId);
542 	return false;
543 }
544 
545 //-----------------------------------------------------------------------------
546 // <Manager::GetLibraryVersion>
547 //
548 //-----------------------------------------------------------------------------
GetLibraryVersion(uint32 const _homeId)549 string Manager::GetLibraryVersion(uint32 const _homeId)
550 {
551 	if (Driver* driver = GetDriver(_homeId))
552 	{
553 		return driver->GetLibraryVersion();
554 	}
555 
556 	Log::Write(LogLevel_Info, "mgr,     GetLibraryVersion() failed - _homeId %d not found", _homeId);
557 	return "";
558 }
559 
560 //-----------------------------------------------------------------------------
561 // <Manager::GetLibraryTypeName>
562 //
563 //-----------------------------------------------------------------------------
GetLibraryTypeName(uint32 const _homeId)564 string Manager::GetLibraryTypeName(uint32 const _homeId)
565 {
566 	if (Driver* driver = GetDriver(_homeId))
567 	{
568 		return driver->GetLibraryTypeName();
569 	}
570 
571 	Log::Write(LogLevel_Info, "mgr,     GetLibraryTypeName() failed - _homeId %d not found", _homeId);
572 	return "";
573 }
574 
575 //-----------------------------------------------------------------------------
576 // <Manager::GetSendQueueCount>
577 //
578 //-----------------------------------------------------------------------------
GetSendQueueCount(uint32 const _homeId)579 int32 Manager::GetSendQueueCount(uint32 const _homeId)
580 {
581 	if (Driver* driver = GetDriver(_homeId))
582 	{
583 		return driver->GetSendQueueCount();
584 	}
585 
586 	Log::Write(LogLevel_Info, "mgr,     GetSendQueueCount() failed - _homeId %d not found", _homeId);
587 	return -1;
588 }
589 
590 //-----------------------------------------------------------------------------
591 // <Manager::LogDriverStatistics>
592 // Send driver statistics to the log file
593 //-----------------------------------------------------------------------------
LogDriverStatistics(uint32 const _homeId)594 void Manager::LogDriverStatistics(uint32 const _homeId)
595 {
596 	if (Driver* driver = GetDriver(_homeId))
597 	{
598 		return driver->LogDriverStatistics();
599 	}
600 
601 	Log::Write(LogLevel_Warning, "mgr,     LogDriverStatistics() failed - _homeId %d not found", _homeId);
602 }
603 
604 //-----------------------------------------------------------------------------
605 // <Manager::GetControllerInterfaceType>
606 // Retrieve controller interface type
607 //-----------------------------------------------------------------------------
GetControllerInterfaceType(uint32 const _homeId)608 Driver::ControllerInterface Manager::GetControllerInterfaceType(uint32 const _homeId)
609 {
610 	Driver::ControllerInterface ifType = Driver::ControllerInterface_Unknown;
611 	if (Driver* driver = GetDriver(_homeId))
612 	{
613 		ifType = driver->GetControllerInterfaceType();
614 	}
615 	return ifType;
616 }
617 
618 //-----------------------------------------------------------------------------
619 // <Manager::GetControllerPath>
620 // Retrieve controller interface path
621 //-----------------------------------------------------------------------------
GetControllerPath(uint32 const _homeId)622 string Manager::GetControllerPath(uint32 const _homeId)
623 {
624 	string path = "";
625 	if (Driver* driver = GetDriver(_homeId))
626 	{
627 		path = driver->GetControllerPath();
628 	}
629 	return path;
630 }
631 //-----------------------------------------------------------------------------
632 //	Polling Z-Wave values
633 //-----------------------------------------------------------------------------
634 
635 //-----------------------------------------------------------------------------
636 // <Manager::GetPollInterval>
637 // Return the polling interval
638 //-----------------------------------------------------------------------------
GetPollInterval()639 int32 Manager::GetPollInterval()
640 {
641 	for (map<uint32, Driver*>::iterator rit = m_readyDrivers.begin(); rit != m_readyDrivers.end(); ++rit)
642 	{
643 		return rit->second->GetPollInterval();
644 	}
645 	for (list<Driver*>::iterator pit = m_pendingDrivers.begin(); pit != m_pendingDrivers.end(); ++pit)
646 	{
647 		return (*pit)->GetPollInterval();
648 	}
649 	return 0;
650 
651 }
652 
653 //-----------------------------------------------------------------------------
654 // <Manager::SetPollInterval>
655 // Set the polling interval on all drivers
656 //-----------------------------------------------------------------------------
SetPollInterval(int32 _milliseconds,bool _bIntervalBetweenPolls)657 void Manager::SetPollInterval(int32 _milliseconds, bool _bIntervalBetweenPolls)
658 {
659 	for (list<Driver*>::iterator pit = m_pendingDrivers.begin(); pit != m_pendingDrivers.end(); ++pit)
660 	{
661 		(*pit)->SetPollInterval(_milliseconds, _bIntervalBetweenPolls);
662 	}
663 
664 	for (map<uint32, Driver*>::iterator rit = m_readyDrivers.begin(); rit != m_readyDrivers.end(); ++rit)
665 	{
666 		rit->second->SetPollInterval(_milliseconds, _bIntervalBetweenPolls);
667 	}
668 }
669 
670 //-----------------------------------------------------------------------------
671 // <Manager::EnablePoll>
672 // Enable polling of a value
673 //-----------------------------------------------------------------------------
EnablePoll(ValueID const & _valueId,uint8 const _intensity)674 bool Manager::EnablePoll(ValueID const &_valueId, uint8 const _intensity)
675 {
676 	if (Driver* driver = GetDriver(_valueId.GetHomeId()))
677 	{
678 		return (driver->EnablePoll(_valueId, _intensity));
679 	}
680 
681 	Log::Write(LogLevel_Info, "mgr,     EnablePoll failed - Driver with Home ID 0x%.8x is not available", _valueId.GetHomeId());
682 	return false;
683 }
684 
685 //-----------------------------------------------------------------------------
686 // <Manager::DisablePoll>
687 // Disable polling of a value
688 //-----------------------------------------------------------------------------
DisablePoll(ValueID const & _valueId)689 bool Manager::DisablePoll(ValueID const &_valueId)
690 {
691 	if (Driver* driver = GetDriver(_valueId.GetHomeId()))
692 	{
693 		return (driver->DisablePoll(_valueId));
694 	}
695 
696 	Log::Write(LogLevel_Info, "mgr,     DisablePoll failed - Driver with Home ID 0x%.8x is not available", _valueId.GetHomeId());
697 	return false;
698 }
699 
700 //-----------------------------------------------------------------------------
701 // <Manager::isPolled>
702 // Check polling status of a value
703 //-----------------------------------------------------------------------------
isPolled(ValueID const & _valueId)704 bool Manager::isPolled(ValueID const &_valueId)
705 {
706 	if (Driver* driver = GetDriver(_valueId.GetHomeId()))
707 	{
708 		return (driver->isPolled(_valueId));
709 	}
710 
711 	Log::Write(LogLevel_Info, "mgr,     isPolled failed - Driver with Home ID 0x%.8x is not available", _valueId.GetHomeId());
712 	return false;
713 }
714 
715 //-----------------------------------------------------------------------------
716 // <Manager::SetPollIntensity>
717 // Change the intensity with which this value is polled
718 //-----------------------------------------------------------------------------
SetPollIntensity(ValueID const & _valueId,uint8 const _intensity)719 void Manager::SetPollIntensity(ValueID const &_valueId, uint8 const _intensity)
720 {
721 	if (Driver* driver = GetDriver(_valueId.GetHomeId()))
722 	{
723 		return (driver->SetPollIntensity(_valueId, _intensity));
724 	}
725 
726 	Log::Write(LogLevel_Error, "mgr,     SetPollIntensity failed - Driver with Home ID 0x%.8x is not available", _valueId.GetHomeId());
727 }
728 
729 //-----------------------------------------------------------------------------
730 // <Manager::GetPollIntensity>
731 // Change the intensity with which this value is polled
732 //-----------------------------------------------------------------------------
GetPollIntensity(ValueID const & _valueId)733 uint8 Manager::GetPollIntensity(ValueID const &_valueId)
734 {
735 	uint8 intensity = 0;
736 	if (Driver* driver = GetDriver(_valueId.GetHomeId()))
737 	{
738 		Internal::LockGuard LG(driver->m_nodeMutex);
739 		if (Internal::VC::Value* value = driver->GetValue(_valueId))
740 		{
741 			intensity = value->GetPollIntensity();
742 			value->Release();
743 		}
744 		else
745 		{
746 			OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetPollIntensity");
747 		}
748 	}
749 
750 	return intensity;
751 }
752 
753 //-----------------------------------------------------------------------------
754 //	Retrieving Node information
755 //-----------------------------------------------------------------------------
756 
757 //-----------------------------------------------------------------------------
758 // <Manager::RefreshNodeInfo>
759 // Fetch the data for a node from the Z-Wave network
760 //-----------------------------------------------------------------------------
RefreshNodeInfo(uint32 const _homeId,uint8 const _nodeId)761 bool Manager::RefreshNodeInfo(uint32 const _homeId, uint8 const _nodeId)
762 {
763 	if (Driver* driver = GetDriver(_homeId))
764 	{
765 		// Cause the node's data to be obtained from the Z-Wave network
766 		// in the same way as if it had just been added.
767 		Internal::LockGuard LG(driver->m_nodeMutex);
768 		driver->ReloadNode(_nodeId);
769 		return true;
770 	}
771 
772 	return false;
773 }
774 
775 //-----------------------------------------------------------------------------
776 // <Manager::RequestNodeState>
777 // Fetch the command class data for a node from the Z-Wave network
778 //-----------------------------------------------------------------------------
RequestNodeState(uint32 const _homeId,uint8 const _nodeId)779 bool Manager::RequestNodeState(uint32 const _homeId, uint8 const _nodeId)
780 {
781 	if (Driver* driver = GetDriver(_homeId))
782 	{
783 		Internal::LockGuard LG(driver->m_nodeMutex);
784 		// Retreive the Node's session and dynamic data
785 		Node* node = driver->GetNode(_nodeId);
786 		if (node)
787 		{
788 			node->SetQueryStage(Node::QueryStage_Associations);
789 			return true;
790 		}
791 	}
792 	return false;
793 }
794 
795 //-----------------------------------------------------------------------------
796 // <Manager::RequestNodeDynamic>
797 // Fetch only the dynamic command class data for a node from the Z-Wave network
798 //-----------------------------------------------------------------------------
RequestNodeDynamic(uint32 const _homeId,uint8 const _nodeId)799 bool Manager::RequestNodeDynamic(uint32 const _homeId, uint8 const _nodeId)
800 {
801 	if (Driver* driver = GetDriver(_homeId))
802 	{
803 		Internal::LockGuard LG(driver->m_nodeMutex);
804 		// Retreive the Node's dynamic data
805 		Node* node = driver->GetNode(_nodeId);
806 		if (node)
807 		{
808 			node->SetQueryStage(Node::QueryStage_Dynamic);
809 			return true;
810 		}
811 	}
812 	return false;
813 }
814 
815 //-----------------------------------------------------------------------------
816 // <Manager::IsNodeListeningDevice>
817 // Get whether the node is a listening device that does not go to sleep
818 //-----------------------------------------------------------------------------
IsNodeListeningDevice(uint32 const _homeId,uint8 const _nodeId)819 bool Manager::IsNodeListeningDevice(uint32 const _homeId, uint8 const _nodeId)
820 {
821 	bool res = false;
822 	if (Driver* driver = GetDriver(_homeId))
823 	{
824 		res = driver->IsNodeListeningDevice(_nodeId);
825 	}
826 
827 	return res;
828 }
829 
830 //-----------------------------------------------------------------------------
831 // <Manager::IsNodeFrequentListeningDevice>
832 // Get whether the node is a listening device that does not go to sleep
833 //-----------------------------------------------------------------------------
IsNodeFrequentListeningDevice(uint32 const _homeId,uint8 const _nodeId)834 bool Manager::IsNodeFrequentListeningDevice(uint32 const _homeId, uint8 const _nodeId)
835 {
836 	bool res = false;
837 	if (Driver* driver = GetDriver(_homeId))
838 	{
839 		res = driver->IsNodeFrequentListeningDevice(_nodeId);
840 	}
841 
842 	return res;
843 }
844 
845 //-----------------------------------------------------------------------------
846 // <Manager::IsNodeBeamingDevice>
847 // Get whether the node is a beam capable device.
848 //-----------------------------------------------------------------------------
IsNodeBeamingDevice(uint32 const _homeId,uint8 const _nodeId)849 bool Manager::IsNodeBeamingDevice(uint32 const _homeId, uint8 const _nodeId)
850 {
851 	bool res = false;
852 	if (Driver* driver = GetDriver(_homeId))
853 	{
854 		res = driver->IsNodeBeamingDevice(_nodeId);
855 	}
856 
857 	return res;
858 }
859 
860 //-----------------------------------------------------------------------------
861 // <Manager::IsNodeRoutingDevice>
862 // Get whether the node is a routing device that passes messages to other nodes
863 //-----------------------------------------------------------------------------
IsNodeRoutingDevice(uint32 const _homeId,uint8 const _nodeId)864 bool Manager::IsNodeRoutingDevice(uint32 const _homeId, uint8 const _nodeId)
865 {
866 	bool res = false;
867 	if (Driver* driver = GetDriver(_homeId))
868 	{
869 		res = driver->IsNodeRoutingDevice(_nodeId);
870 	}
871 
872 	return res;
873 }
874 
875 //-----------------------------------------------------------------------------
876 // <Manager::IsNodeSecurityDevice>
877 // Get the security attribute for a node.
878 //-----------------------------------------------------------------------------
IsNodeSecurityDevice(uint32 const _homeId,uint8 const _nodeId)879 bool Manager::IsNodeSecurityDevice(uint32 const _homeId, uint8 const _nodeId)
880 {
881 	bool security = 0;
882 	if (Driver* driver = GetDriver(_homeId))
883 	{
884 		security = driver->IsNodeSecurityDevice(_nodeId);
885 	}
886 
887 	return security;
888 }
889 
890 //-----------------------------------------------------------------------------
891 // <Manager::GetNodeMaxBaudRate>
892 // Get the maximum baud rate of a node's communications
893 //-----------------------------------------------------------------------------
GetNodeMaxBaudRate(uint32 const _homeId,uint8 const _nodeId)894 uint32 Manager::GetNodeMaxBaudRate(uint32 const _homeId, uint8 const _nodeId)
895 {
896 	uint32 baud = 0;
897 	if (Driver* driver = GetDriver(_homeId))
898 	{
899 		baud = driver->GetNodeMaxBaudRate(_nodeId);
900 	}
901 
902 	return baud;
903 }
904 
905 //-----------------------------------------------------------------------------
906 // <Manager::GetNodeVersion>
907 // Get the version number of a node
908 //-----------------------------------------------------------------------------
GetNodeVersion(uint32 const _homeId,uint8 const _nodeId)909 uint8 Manager::GetNodeVersion(uint32 const _homeId, uint8 const _nodeId)
910 {
911 	uint8 version = 0;
912 	if (Driver* driver = GetDriver(_homeId))
913 	{
914 		version = driver->GetNodeVersion(_nodeId);
915 	}
916 
917 	return version;
918 }
919 
920 //-----------------------------------------------------------------------------
921 // <Manager::GetNodeSecurity>
922 // Get the security byte of a node
923 //-----------------------------------------------------------------------------
GetNodeSecurity(uint32 const _homeId,uint8 const _nodeId)924 uint8 Manager::GetNodeSecurity(uint32 const _homeId, uint8 const _nodeId)
925 {
926 	uint8 version = 0;
927 	if (Driver* driver = GetDriver(_homeId))
928 	{
929 		version = driver->GetNodeSecurity(_nodeId);
930 	}
931 
932 	return version;
933 }
934 
935 //-----------------------------------------------------------------------------
936 // <Manager::IsNodeZWavePlus>
937 // Get if the Node is a ZWave Plus Supported Node
938 //-----------------------------------------------------------------------------
IsNodeZWavePlus(uint32 const _homeId,uint8 const _nodeId)939 bool Manager::IsNodeZWavePlus(uint32 const _homeId, uint8 const _nodeId)
940 {
941 	bool version = false;
942 	if (Driver* driver = GetDriver(_homeId))
943 	{
944 		version = driver->IsNodeZWavePlus(_nodeId);
945 	}
946 
947 	return version;
948 }
949 
950 //-----------------------------------------------------------------------------
951 // <Manager::GetNodeBasic>
952 // Get the basic type of a node
953 //-----------------------------------------------------------------------------
GetNodeBasic(uint32 const _homeId,uint8 const _nodeId)954 uint8 Manager::GetNodeBasic(uint32 const _homeId, uint8 const _nodeId)
955 {
956 	uint8 basic = 0;
957 	if (Driver* driver = GetDriver(_homeId))
958 	{
959 		basic = driver->GetNodeBasic(_nodeId);
960 	}
961 
962 	return basic;
963 }
964 
965 //-----------------------------------------------------------------------------
966 // <Manager::GetNodeBasic>
967 // Get the basic type of a node
968 //-----------------------------------------------------------------------------
GetNodeBasicString(uint32 const _homeId,uint8 const _nodeId)969 string Manager::GetNodeBasicString(uint32 const _homeId, uint8 const _nodeId)
970 {
971 	if (Driver* driver = GetDriver(_homeId))
972 	{
973 		return driver->GetNodeBasicString(_nodeId);
974 	}
975 
976 	return "Unknown";
977 }
978 
979 
980 //-----------------------------------------------------------------------------
981 // <Manager::GetNodeGeneric>
982 // Get the generic type of a node
983 //-----------------------------------------------------------------------------
GetNodeGeneric(uint32 const _homeId,uint8 const _nodeId,uint8 const _instance)984 uint8 Manager::GetNodeGeneric(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance)
985 {
986 	uint8 genericType = 0;
987 	if (Driver* driver = GetDriver(_homeId))
988 	{
989 		genericType = driver->GetNodeGeneric(_nodeId, _instance);
990 	}
991 
992 	return genericType;
993 }
994 //-----------------------------------------------------------------------------
995 // <Manager::GetNodeGeneric>
996 // Get the generic type of a node
997 //-----------------------------------------------------------------------------
998 
GetNodeGenericString(uint32 const _homeId,uint8 const _nodeId,uint8 const _instance)999 string Manager::GetNodeGenericString(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance)
1000 {
1001 	if (Driver *driver = GetDriver(_homeId))
1002 	{
1003 		return driver->GetNodeGenericString(_nodeId, _instance);
1004 	}
1005 	return "Unknown";
1006 }
1007 
1008 
1009 //-----------------------------------------------------------------------------
1010 // <Manager::GetNodeSpecific>
1011 // Get the specific type of a node
1012 //-----------------------------------------------------------------------------
GetNodeSpecific(uint32 const _homeId,uint8 const _nodeId,uint8 const _instance)1013 uint8 Manager::GetNodeSpecific(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance)
1014 {
1015 	uint8 specific = 0;
1016 	if (Driver* driver = GetDriver(_homeId))
1017 	{
1018 		specific = driver->GetNodeSpecific(_nodeId, _instance);
1019 	}
1020 
1021 	return specific;
1022 }
1023 
1024 //-----------------------------------------------------------------------------
1025 // <Manager::GetNodeSpecific>
1026 // Get the specific type of a node
1027 //-----------------------------------------------------------------------------
GetNodeSpecificString(uint32 const _homeId,uint8 const _nodeId,uint8 const _instance)1028 string Manager::GetNodeSpecificString(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance)
1029 {
1030 	if (Driver* driver = GetDriver(_homeId))
1031 	{
1032 		return driver->GetNodeSpecificString(_nodeId, _instance);
1033 	}
1034 
1035 	return "Unknown";
1036 }
1037 
1038 //-----------------------------------------------------------------------------
1039 // <Manager::GetNodeType>
1040 // Get a string describing the type of a node
1041 //-----------------------------------------------------------------------------
GetNodeType(uint32 const _homeId,uint8 const _nodeId)1042 string Manager::GetNodeType(uint32 const _homeId, uint8 const _nodeId)
1043 {
1044 	if (Driver* driver = GetDriver(_homeId))
1045 	{
1046 		if (driver->IsNodeZWavePlus(_nodeId))
1047 			return driver->GetNodeDeviceTypeString(_nodeId);
1048 		else
1049 			return driver->GetNodeType(_nodeId);
1050 	}
1051 
1052 	return "Unknown";
1053 }
1054 
1055 //-----------------------------------------------------------------------------
1056 // <Manager::GetNodeNeighbors>
1057 // Get the bitmap of this node's neighbors
1058 //-----------------------------------------------------------------------------
GetNodeNeighbors(uint32 const _homeId,uint8 const _nodeId,uint8 ** o_neighbors)1059 uint32 Manager::GetNodeNeighbors(uint32 const _homeId, uint8 const _nodeId, uint8** o_neighbors)
1060 {
1061 	if (Driver* driver = GetDriver(_homeId))
1062 	{
1063 		return driver->GetNodeNeighbors(_nodeId, o_neighbors);
1064 	}
1065 
1066 	return 0;
1067 }
1068 
1069 //-----------------------------------------------------------------------------
1070 // <Manager::SyncronizeNodeNeighbors>
1071 // Syncronise OZW's copy of the Neighbor List for a Node with the Controller
1072 //-----------------------------------------------------------------------------
SyncronizeNodeNeighbors(uint32 const _homeId,uint8 const _nodeId)1073 void Manager::SyncronizeNodeNeighbors(uint32 const _homeId, uint8 const _nodeId)
1074 {
1075 	if (Driver* driver = GetDriver(_homeId))
1076 	{
1077 		driver->RequestNodeNeighbors(_nodeId, 0);
1078 	}
1079 
1080 	return;
1081 }
1082 
1083 
1084 //-----------------------------------------------------------------------------
1085 // <Manager::GetNodeManufacturerName>
1086 // Get the manufacturer name of a node
1087 //-----------------------------------------------------------------------------
GetNodeManufacturerName(uint32 const _homeId,uint8 const _nodeId)1088 string Manager::GetNodeManufacturerName(uint32 const _homeId, uint8 const _nodeId)
1089 {
1090 	if (Driver* driver = GetDriver(_homeId))
1091 	{
1092 		return driver->GetNodeManufacturerName(_nodeId);
1093 	}
1094 
1095 	return "Unknown";
1096 }
1097 
1098 //-----------------------------------------------------------------------------
1099 // <Manager::GetNodeProductName>
1100 // Get the product name of a node
1101 //-----------------------------------------------------------------------------
GetNodeProductName(uint32 const _homeId,uint8 const _nodeId)1102 string Manager::GetNodeProductName(uint32 const _homeId, uint8 const _nodeId)
1103 {
1104 	if (Driver* driver = GetDriver(_homeId))
1105 	{
1106 		return driver->GetNodeProductName(_nodeId);
1107 	}
1108 
1109 	return "Unknown";
1110 }
1111 
1112 //-----------------------------------------------------------------------------
1113 // <Manager::GetNodeName>
1114 // Get the user-editable name of a node
1115 //-----------------------------------------------------------------------------
GetNodeName(uint32 const _homeId,uint8 const _nodeId)1116 string Manager::GetNodeName(uint32 const _homeId, uint8 const _nodeId)
1117 {
1118 	if (Driver* driver = GetDriver(_homeId))
1119 	{
1120 		return driver->GetNodeName(_nodeId);
1121 	}
1122 
1123 	return "Unknown";
1124 }
1125 
1126 //-----------------------------------------------------------------------------
1127 // <Manager::GetNodeLocation>
1128 // Get the location of a node
1129 //-----------------------------------------------------------------------------
GetNodeLocation(uint32 const _homeId,uint8 const _nodeId)1130 string Manager::GetNodeLocation(uint32 const _homeId, uint8 const _nodeId)
1131 {
1132 	if (Driver* driver = GetDriver(_homeId))
1133 	{
1134 		return driver->GetNodeLocation(_nodeId);
1135 	}
1136 
1137 	return "Unknown";
1138 }
1139 
1140 //-----------------------------------------------------------------------------
1141 // <Manager::SetNodeManufacturerName>
1142 // Set the manufacturer name a node
1143 //-----------------------------------------------------------------------------
SetNodeManufacturerName(uint32 const _homeId,uint8 const _nodeId,string const & _manufacturerName)1144 void Manager::SetNodeManufacturerName(uint32 const _homeId, uint8 const _nodeId, string const& _manufacturerName)
1145 {
1146 	if (Driver* driver = GetDriver(_homeId))
1147 	{
1148 		driver->SetNodeManufacturerName(_nodeId, _manufacturerName);
1149 	}
1150 }
1151 
1152 //-----------------------------------------------------------------------------
1153 // <Manager::SetNodeProductName>
1154 // Set the product name of a node
1155 //-----------------------------------------------------------------------------
SetNodeProductName(uint32 const _homeId,uint8 const _nodeId,string const & _productName)1156 void Manager::SetNodeProductName(uint32 const _homeId, uint8 const _nodeId, string const& _productName)
1157 {
1158 	if (Driver* driver = GetDriver(_homeId))
1159 	{
1160 		driver->SetNodeProductName(_nodeId, _productName);
1161 	}
1162 }
1163 
1164 //-----------------------------------------------------------------------------
1165 // <Manager::SetNodeName>
1166 // Set the node name value with the specified ID
1167 //-----------------------------------------------------------------------------
SetNodeName(uint32 const _homeId,uint8 const _nodeId,string const & _nodeName)1168 void Manager::SetNodeName(uint32 const _homeId, uint8 const _nodeId, string const& _nodeName)
1169 {
1170 	if (Driver* driver = GetDriver(_homeId))
1171 	{
1172 		driver->SetNodeName(_nodeId, _nodeName);
1173 	}
1174 }
1175 
1176 //-----------------------------------------------------------------------------
1177 // <Manager::SetNodeLocation>
1178 // Set a string describing the location of a node
1179 //-----------------------------------------------------------------------------
SetNodeLocation(uint32 const _homeId,uint8 const _nodeId,string const & _location)1180 void Manager::SetNodeLocation(uint32 const _homeId, uint8 const _nodeId, string const& _location
1181 
1182 )
1183 {
1184 	if (Driver* driver = GetDriver(_homeId))
1185 	{
1186 		driver->SetNodeLocation(_nodeId, _location);
1187 	}
1188 }
1189 
1190 //-----------------------------------------------------------------------------
1191 // <Manager::GetNodeManufacturerId>
1192 // Get the manufacturer ID value of a node
1193 //-----------------------------------------------------------------------------
GetNodeManufacturerId(uint32 const _homeId,uint8 const _nodeId)1194 string Manager::GetNodeManufacturerId(uint32 const _homeId, uint8 const _nodeId)
1195 {
1196 	if (Driver* driver = GetDriver(_homeId))
1197 	{
1198 		uint16 mid = driver->GetNodeManufacturerId(_nodeId);
1199 		std::stringstream ss;
1200 		ss << "0x" << std::hex << std::setw(4) << std::setfill('0') << mid;
1201 		return ss.str();
1202 	}
1203 
1204 	return "Unknown";
1205 }
1206 
1207 //-----------------------------------------------------------------------------
1208 // <Manager::GetNodeProductType>
1209 // Get the product type value of a node
1210 //-----------------------------------------------------------------------------
GetNodeProductType(uint32 const _homeId,uint8 const _nodeId)1211 string Manager::GetNodeProductType(uint32 const _homeId, uint8 const _nodeId)
1212 {
1213 	if (Driver* driver = GetDriver(_homeId))
1214 	{
1215 		uint16 mid = driver->GetNodeProductType(_nodeId);
1216 		std::stringstream ss;
1217 		ss << "0x" << std::hex << std::setw(4) << std::setfill('0') << mid;
1218 		return ss.str();
1219 	}
1220 
1221 	return "Unknown";
1222 }
1223 
1224 //-----------------------------------------------------------------------------
1225 // <Manager::GetNodeDeviceType>
1226 // Get the node device type as reported in the Z-Wave+ Info report.
1227 //-----------------------------------------------------------------------------
GetNodeDeviceType(uint32 const _homeId,uint8 const _nodeId)1228 uint16 Manager::GetNodeDeviceType(uint32 const _homeId, uint8 const _nodeId)
1229 {
1230 	if (Driver* driver = GetDriver(_homeId))
1231 	{
1232 		return driver->GetNodeDeviceType(_nodeId);
1233 	}
1234 
1235 	return 0x00; // unknown
1236 }
1237 
1238 //-----------------------------------------------------------------------------
1239 // <Manager::GetNodeDeviceType>
1240 // Get the node device type as reported in the Z-Wave+ Info report.
1241 //-----------------------------------------------------------------------------
GetNodeDeviceTypeString(uint32 const _homeId,uint8 const _nodeId)1242 string Manager::GetNodeDeviceTypeString(uint32 const _homeId, uint8 const _nodeId)
1243 {
1244 	if (Driver* driver = GetDriver(_homeId))
1245 	{
1246 		return driver->GetNodeDeviceTypeString(_nodeId);
1247 	}
1248 
1249 	return ""; // unknown
1250 }
1251 
1252 //-----------------------------------------------------------------------------
1253 // <Manager::GetNodeRole>
1254 // Get the node role as reported in the Z-Wave+ Info report.
1255 //-----------------------------------------------------------------------------
GetNodeRole(uint32 const _homeId,uint8 const _nodeId)1256 uint8 Manager::GetNodeRole(uint32 const _homeId, uint8 const _nodeId)
1257 {
1258 	if (Driver* driver = GetDriver(_homeId))
1259 	{
1260 		return driver->GetNodeRole(_nodeId);
1261 	}
1262 
1263 	return 0x00; // unknown
1264 }
1265 
1266 //-----------------------------------------------------------------------------
1267 // <Manager::GetNodeRole>
1268 // Get the node role as reported in the Z-Wave+ Info report.
1269 //-----------------------------------------------------------------------------
GetNodeRoleString(uint32 const _homeId,uint8 const _nodeId)1270 string Manager::GetNodeRoleString(uint32 const _homeId, uint8 const _nodeId)
1271 {
1272 	if (Driver* driver = GetDriver(_homeId))
1273 	{
1274 		return driver->GetNodeRoleString(_nodeId);
1275 	}
1276 
1277 	return ""; // unknown
1278 }
1279 
GetNodePlusType(uint32 const _homeId,uint8 const _nodeId)1280 uint8 Manager::GetNodePlusType(uint32 const _homeId, uint8 const _nodeId)
1281 {
1282 	if (Driver* driver = GetDriver(_homeId))
1283 	{
1284 		return driver->GetNodePlusType(_nodeId);
1285 	}
1286 
1287 	return 0x00; // unknown
1288 
1289 }
1290 
GetNodePlusTypeString(uint32 const _homeId,uint8 const _nodeId)1291 string Manager::GetNodePlusTypeString(uint32 const _homeId, uint8 const _nodeId)
1292 {
1293 	if (Driver* driver = GetDriver(_homeId))
1294 	{
1295 		return driver->GetNodePlusTypeString(_nodeId);
1296 	}
1297 
1298 	return ""; // unknown
1299 
1300 }
1301 
1302 //-----------------------------------------------------------------------------
1303 // <Manager::GetNodeProductId>
1304 // Get the product Id value with the specified ID
1305 //-----------------------------------------------------------------------------
GetNodeProductId(uint32 const _homeId,uint8 const _nodeId)1306 string Manager::GetNodeProductId(uint32 const _homeId, uint8 const _nodeId)
1307 {
1308 	if (Driver* driver = GetDriver(_homeId))
1309 	{
1310 		uint16 mid = driver->GetNodeProductId(_nodeId);
1311 		std::stringstream ss;
1312 		ss << "0x" << std::hex << std::setw(4) << std::setfill('0') << mid;
1313 		return ss.str();
1314 	}
1315 
1316 	return "Unknown";
1317 }
1318 
1319 //-----------------------------------------------------------------------------
1320 // <Manager::SetNodeOn>
1321 // Helper method to turn a node on
1322 //-----------------------------------------------------------------------------
SetNodeOn(uint32 const _homeId,uint8 const _nodeId)1323 void Manager::SetNodeOn(uint32 const _homeId, uint8 const _nodeId)
1324 {
1325 	if (Driver* driver = GetDriver(_homeId))
1326 	{
1327 		driver->SetNodeOn(_nodeId);
1328 	}
1329 }
1330 
1331 //-----------------------------------------------------------------------------
1332 // <Manager::SetNodeOff>
1333 // Helper method to turn a node off
1334 //-----------------------------------------------------------------------------
SetNodeOff(uint32 const _homeId,uint8 const _nodeId)1335 void Manager::SetNodeOff(uint32 const _homeId, uint8 const _nodeId)
1336 {
1337 	if (Driver* driver = GetDriver(_homeId))
1338 	{
1339 		driver->SetNodeOff(_nodeId);
1340 	}
1341 }
1342 
1343 //-----------------------------------------------------------------------------
1344 // <Manager::IsNodeInfoReceived>
1345 // Helper method to return whether a particular class is available in a node
1346 //-----------------------------------------------------------------------------
IsNodeInfoReceived(uint32 const _homeId,uint8 const _nodeId)1347 bool Manager::IsNodeInfoReceived(uint32 const _homeId, uint8 const _nodeId)
1348 {
1349 	bool result = false;
1350 
1351 	if (Driver* driver = GetDriver(_homeId))
1352 	{
1353 		Node *node;
1354 
1355 		// Need to lock and unlock nodes to check this information
1356 		Internal::LockGuard LG(driver->m_nodeMutex);
1357 
1358 		if ((node = driver->GetNode(_nodeId)) != NULL)
1359 		{
1360 			result = node->NodeInfoReceived();
1361 		}
1362 	}
1363 
1364 	return result;
1365 }
1366 
1367 //-----------------------------------------------------------------------------
1368 // <Manager::GetNodeClassAvailable>
1369 // Helper method to return whether a particular class is available in a node
1370 //-----------------------------------------------------------------------------
GetNodeClassInformation(uint32 const _homeId,uint8 const _nodeId,uint8 const _commandClassId,string * _className,uint8 * _classVersion)1371 bool Manager::GetNodeClassInformation(uint32 const _homeId, uint8 const _nodeId, uint8 const _commandClassId, string *_className, uint8 *_classVersion)
1372 {
1373 	bool result = false;
1374 
1375 	if (Driver* driver = GetDriver(_homeId))
1376 	{
1377 		Node *node;
1378 
1379 		// Need to lock and unlock nodes to check this information
1380 		Internal::LockGuard LG(driver->m_nodeMutex);
1381 
1382 		if ((node = driver->GetNode(_nodeId)) != NULL)
1383 		{
1384 			Internal::CC::CommandClass *cc;
1385 			if (node->NodeInfoReceived() && ((cc = node->GetCommandClass(_commandClassId)) != NULL))
1386 			{
1387 				if (_className)
1388 				{
1389 					*_className = cc->GetCommandClassName();
1390 				}
1391 				if (_classVersion)
1392 				{
1393 					*_classVersion = cc->GetVersion();
1394 				}
1395 				// Positive result
1396 				result = true;
1397 			}
1398 		}
1399 
1400 	}
1401 
1402 	return result;
1403 }
1404 
1405 //-----------------------------------------------------------------------------
1406 // <Manager::GetCommandClassName>
1407 // Get a String representing the Command Class Name
1408 //-----------------------------------------------------------------------------
GetCommandClassName(uint8 const _commandClassId)1409 string Manager::GetCommandClassName(uint8 const _commandClassId) {
1410 	return OpenZWave::Internal::CC::CommandClasses::GetName(_commandClassId);
1411 }
1412 
1413 //-----------------------------------------------------------------------------
1414 // <Manager::IsNodeAwake>
1415 // Helper method to return whether a node is awake or sleeping
1416 //-----------------------------------------------------------------------------
IsNodeAwake(uint32 const _homeId,uint8 const _nodeId)1417 bool Manager::IsNodeAwake(uint32 const _homeId, uint8 const _nodeId)
1418 {
1419 	if (IsNodeListeningDevice(_homeId, _nodeId))
1420 	{
1421 		return true;				// if listening then always awake
1422 	}
1423 	bool result = true;
1424 	if (Driver* driver = GetDriver(_homeId))
1425 	{
1426 		// Need to lock and unlock nodes to check this information
1427 		Internal::LockGuard LG(driver->m_nodeMutex);
1428 
1429 		if (Node* node = driver->GetNode(_nodeId))
1430 		{
1431 			if (Internal::CC::WakeUp* wcc = static_cast<Internal::CC::WakeUp*>(node->GetCommandClass(Internal::CC::WakeUp::StaticGetCommandClassId())))
1432 			{
1433 				result = wcc->IsAwake();
1434 			}
1435 		}
1436 	}
1437 	return result;
1438 }
1439 
1440 //-----------------------------------------------------------------------------
1441 // <Manager::IsNodeFailed>
1442 // Helper method to return whether a node is on the network or not
1443 //-----------------------------------------------------------------------------
IsNodeFailed(uint32 const _homeId,uint8 const _nodeId)1444 bool Manager::IsNodeFailed(uint32 const _homeId, uint8 const _nodeId)
1445 {
1446 	bool result = false;
1447 	if (Driver* driver = GetDriver(_homeId))
1448 	{
1449 		Internal::LockGuard LG(driver->m_nodeMutex);
1450 		if (Node* node = driver->GetNode(_nodeId))
1451 		{
1452 			result = !node->IsNodeAlive();
1453 		}
1454 	}
1455 	return result;
1456 }
1457 
1458 //-----------------------------------------------------------------------------
1459 // <Manager::GetNodeQueryStage>
1460 // Helper method to return whether a node's query stage
1461 //-----------------------------------------------------------------------------
GetNodeQueryStage(uint32 const _homeId,uint8 const _nodeId)1462 string Manager::GetNodeQueryStage(uint32 const _homeId, uint8 const _nodeId)
1463 {
1464 	string result = "Unknown";
1465 	if (Driver* driver = GetDriver(_homeId))
1466 	{
1467 		Internal::LockGuard LG(driver->m_nodeMutex);
1468 		if (Node* node = driver->GetNode(_nodeId))
1469 		{
1470 			result = node->GetQueryStageName(node->GetCurrentQueryStage());
1471 		}
1472 	}
1473 	return result;
1474 }
1475 
1476 //-----------------------------------------------------------------------------
1477 // <Manager::SetNodeLevel>
1478 // Helper method to set the basic level of a node
1479 //-----------------------------------------------------------------------------
SetNodeLevel(uint32 const _homeId,uint8 const _nodeId,uint8 const _level)1480 void Manager::SetNodeLevel(uint32 const _homeId, uint8 const _nodeId, uint8 const _level)
1481 {
1482 	if (Driver* driver = GetDriver(_homeId))
1483 	{
1484 		return driver->SetNodeLevel(_nodeId, _level);
1485 	}
1486 }
1487 
1488 //-----------------------------------------------------------------------------
1489 //	Instances
1490 //-----------------------------------------------------------------------------
1491 
1492 //-----------------------------------------------------------------------------
1493 // <Manager::GetInstanceLabel>
1494 // Gets the user-friendly Instance label for the valueID
1495 //-----------------------------------------------------------------------------
GetInstanceLabel(ValueID const & _id)1496 string Manager::GetInstanceLabel(ValueID const &_id)
1497 {
1498 	return GetInstanceLabel(_id.GetHomeId(), _id.GetNodeId(), _id.GetCommandClassId(), _id.GetInstance());
1499 }
1500 //-----------------------------------------------------------------------------
1501 // <Manager::GetInstanceLabel>
1502 // Gets the user-friendly Instance label for the cc and instance
1503 //-----------------------------------------------------------------------------
GetInstanceLabel(uint32 const _homeId,uint8 const _node,uint8 const _cc,uint8 const _instance)1504 string Manager::GetInstanceLabel(uint32 const _homeId, uint8 const _node, uint8 const _cc, uint8 const _instance)
1505 {
1506 	string label;
1507 	if (Driver* driver = GetDriver(_homeId))
1508 	{
1509 		Internal::LockGuard LG(driver->m_nodeMutex);
1510 		if (Node* node = driver->GetNode(_node))
1511 		{
1512 			label = node->GetInstanceLabel(_cc, _instance);
1513 			return label;
1514 		}
1515 		OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_NODEID, "Invalid Node passed to GetInstanceLabel");
1516 	}
1517 	else
1518 	{
1519 		OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_HOMEID, "Invalid HomeId passed to GetInstanceLabel");
1520 	}
1521 	return label;
1522 }
1523 
1524 //-----------------------------------------------------------------------------
1525 //	Values
1526 //-----------------------------------------------------------------------------
1527 
1528 //-----------------------------------------------------------------------------
1529 // <Manager::GetValueLabel>
1530 // Gets the user-friendly label for the value
1531 //-----------------------------------------------------------------------------
GetValueLabel(ValueID const & _id,int32 _pos)1532 string Manager::GetValueLabel(ValueID const& _id, int32 _pos)
1533 {
1534 	string label;
1535 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1536 	{
1537 		Internal::LockGuard LG(driver->m_nodeMutex);
1538 		if (_pos != -1)
1539 		{
1540 			if (_id.GetType() != ValueID::ValueType_BitSet)
1541 			{
1542 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "ValueID passed to GetValueLabel is not a BitSet but a position was requested");
1543 				return label;
1544 			}
1545 			Internal::VC::ValueBitSet *value = static_cast<Internal::VC::ValueBitSet *>(driver->GetValue(_id));
1546 			label = value->GetBitLabel(_pos);
1547 			value->Release();
1548 			return label;
1549 		}
1550 		else
1551 		{
1552 			bool useinstancelabels = true;
1553 			Options::Get()->GetOptionAsBool("IncludeInstanceLabel", &useinstancelabels);
1554 			Node* node = driver->GetNode(_id.GetNodeId());
1555 			if ((useinstancelabels) && (node))
1556 			{
1557 				if (node->GetNumInstances(_id.GetCommandClassId()) > 1)
1558 				{
1559 					label = GetInstanceLabel(_id).append(" ");
1560 				}
1561 			}
1562 			if (Internal::VC::Value* value = driver->GetValue(_id))
1563 			{
1564 
1565 				label.append(value->GetLabel());
1566 				value->Release();
1567 				return label;
1568 			}
1569 		}
1570 		OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueLabel");
1571 	}
1572 	return label;
1573 }
1574 
1575 //-----------------------------------------------------------------------------
1576 // <Manager::SetValueLabel>
1577 // Sets the user-friendly label for the value
1578 //-----------------------------------------------------------------------------
SetValueLabel(ValueID const & _id,string const & _value,int32 _pos)1579 void Manager::SetValueLabel(ValueID const& _id, string const& _value, int32 _pos)
1580 {
1581 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1582 	{
1583 		Internal::LockGuard LG(driver->m_nodeMutex);
1584 		if (_pos != -1)
1585 		{
1586 			if (_id.GetType() != ValueID::ValueType_BitSet)
1587 			{
1588 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "ValueID passed to SetValueLabel is not a BitSet but a position was requested");
1589 				return;
1590 			}
1591 			Internal::VC::ValueBitSet *value = static_cast<Internal::VC::ValueBitSet *>(driver->GetValue(_id));
1592 			value->SetBitLabel(_pos, _value);
1593 			value->Release();
1594 			return;
1595 		}
1596 		else
1597 		{
1598 			if (Internal::VC::Value* value = driver->GetValue(_id))
1599 			{
1600 				value->SetLabel(_value);
1601 				value->Release();
1602 				return;
1603 			}
1604 		}
1605 		OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValueLabel");
1606 	}
1607 }
1608 
1609 //-----------------------------------------------------------------------------
1610 // <Manager::GetValueUnits>
1611 // Gets the units that the value is measured in
1612 //-----------------------------------------------------------------------------
GetValueUnits(ValueID const & _id)1613 string Manager::GetValueUnits(ValueID const& _id)
1614 {
1615 	string units;
1616 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1617 	{
1618 		Internal::LockGuard LG(driver->m_nodeMutex);
1619 		if (Internal::VC::Value* value = driver->GetValue(_id))
1620 		{
1621 			units = value->GetUnits();
1622 			value->Release();
1623 		}
1624 		else
1625 		{
1626 			OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueUnits");
1627 		}
1628 	}
1629 
1630 	return units;
1631 }
1632 
1633 //-----------------------------------------------------------------------------
1634 // <Manager::SetValueUnits>
1635 // Sets the units that the value is measured in
1636 //-----------------------------------------------------------------------------
SetValueUnits(ValueID const & _id,string const & _value)1637 void Manager::SetValueUnits(ValueID const& _id, string const& _value)
1638 {
1639 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1640 	{
1641 		Internal::LockGuard LG(driver->m_nodeMutex);
1642 		if (Internal::VC::Value* value = driver->GetValue(_id))
1643 		{
1644 			value->SetUnits(_value);
1645 			value->Release();
1646 		}
1647 		else
1648 		{
1649 			OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValueUnits");
1650 		}
1651 	}
1652 }
1653 
1654 //-----------------------------------------------------------------------------
1655 // <Manager::GetValueHelp>
1656 // Gets a help string describing the value's purpose and usage
1657 //-----------------------------------------------------------------------------
GetValueHelp(ValueID const & _id,int32 _pos)1658 string Manager::GetValueHelp(ValueID const& _id, int32 _pos)
1659 {
1660 	string help;
1661 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1662 	{
1663 		Internal::LockGuard LG(driver->m_nodeMutex);
1664 		if (_pos != -1)
1665 		{
1666 			if (_id.GetType() != ValueID::ValueType_BitSet)
1667 			{
1668 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "ValueID passed to GetValueHelp is not a BitSet but a position was requested");
1669 				return help;
1670 			}
1671 			Internal::VC::ValueBitSet *value = static_cast<Internal::VC::ValueBitSet *>(driver->GetValue(_id));
1672 			help = value->GetBitHelp(_pos);
1673 			value->Release();
1674 			return help;
1675 		}
1676 		else
1677 		{
1678 			if (Internal::VC::Value* value = driver->GetValue(_id))
1679 			{
1680 				help = value->GetHelp();
1681 				value->Release();
1682 				return help;
1683 			}
1684 		}
1685 	}
1686 	OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueHelp");
1687 	return help;
1688 }
1689 
1690 //-----------------------------------------------------------------------------
1691 // <Manager::SetValueHelp>
1692 // Sets a help string describing the value's purpose and usage
1693 //-----------------------------------------------------------------------------
SetValueHelp(ValueID const & _id,string const & _value,int32 _pos)1694 void Manager::SetValueHelp(ValueID const& _id, string const& _value, int32 _pos)
1695 {
1696 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1697 	{
1698 		Internal::LockGuard LG(driver->m_nodeMutex);
1699 		if (_pos != -1)
1700 		{
1701 			if (_id.GetType() != ValueID::ValueType_BitSet)
1702 			{
1703 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "ValueID passed to SetValueHelp is not a BitSet but a position was requested");
1704 				return;
1705 			}
1706 			Internal::VC::ValueBitSet *value = static_cast<Internal::VC::ValueBitSet *>(driver->GetValue(_id));
1707 			value->SetBitHelp(_pos, _value);
1708 			value->Release();
1709 			return;
1710 		}
1711 		else
1712 		{
1713 			if (Internal::VC::Value* value = driver->GetValue(_id))
1714 			{
1715 				value->SetHelp(_value);
1716 				value->Release();
1717 				return;
1718 			}
1719 		}
1720 	}
1721 	OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValueHelp");
1722 }
1723 
1724 //-----------------------------------------------------------------------------
1725 // <Manager::GetValueMin>
1726 // Gets the minimum for a value
1727 //-----------------------------------------------------------------------------
GetValueMin(ValueID const & _id)1728 int32 Manager::GetValueMin(ValueID const& _id)
1729 {
1730 	int32 limit = 0;
1731 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1732 	{
1733 		Internal::LockGuard LG(driver->m_nodeMutex);
1734 		if (Internal::VC::Value* value = driver->GetValue(_id))
1735 		{
1736 			limit = value->GetMin();
1737 			value->Release();
1738 		}
1739 		else
1740 		{
1741 			OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueMin");
1742 		}
1743 	}
1744 
1745 	return limit;
1746 }
1747 
1748 //-----------------------------------------------------------------------------
1749 // <Manager::GetValueMax>
1750 // Gets the maximum for a value
1751 //-----------------------------------------------------------------------------
GetValueMax(ValueID const & _id)1752 int32 Manager::GetValueMax(ValueID const& _id)
1753 {
1754 	int32 limit = 0;
1755 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1756 	{
1757 		Internal::LockGuard LG(driver->m_nodeMutex);
1758 		if (Internal::VC::Value* value = driver->GetValue(_id))
1759 		{
1760 			limit = value->GetMax();
1761 			value->Release();
1762 		}
1763 		else
1764 		{
1765 			OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueMax");
1766 		}
1767 	}
1768 
1769 	return limit;
1770 }
1771 
1772 //-----------------------------------------------------------------------------
1773 // <Manager::IsValueReadOnly>
1774 // Test whether the value is read-only
1775 //-----------------------------------------------------------------------------
IsValueReadOnly(ValueID const & _id)1776 bool Manager::IsValueReadOnly(ValueID const& _id)
1777 {
1778 	bool res = false;
1779 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1780 	{
1781 		Internal::LockGuard LG(driver->m_nodeMutex);
1782 		if (Internal::VC::Value* value = driver->GetValue(_id))
1783 		{
1784 			res = value->IsReadOnly();
1785 			value->Release();
1786 		}
1787 		else
1788 		{
1789 			OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to IsValueReadOnly");
1790 		}
1791 	}
1792 
1793 	return res;
1794 }
1795 
1796 //-----------------------------------------------------------------------------
1797 // <Manager::IsValueWriteOnly>
1798 // Test whether the value is write-only
1799 //-----------------------------------------------------------------------------
IsValueWriteOnly(ValueID const & _id)1800 bool Manager::IsValueWriteOnly(ValueID const& _id)
1801 {
1802 	bool res = false;
1803 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1804 	{
1805 		Internal::LockGuard LG(driver->m_nodeMutex);
1806 		if (Internal::VC::Value* value = driver->GetValue(_id))
1807 		{
1808 			res = value->IsWriteOnly();
1809 			value->Release();
1810 		}
1811 		else
1812 		{
1813 			OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to IsValueWriteOnly");
1814 		}
1815 	}
1816 
1817 	return res;
1818 }
1819 
1820 //-----------------------------------------------------------------------------
1821 // <Manager::IsValueSet>
1822 // Test whether the value has been set by a status message from the device
1823 //-----------------------------------------------------------------------------
IsValueSet(ValueID const & _id)1824 bool Manager::IsValueSet(ValueID const& _id)
1825 {
1826 	bool res = false;
1827 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1828 	{
1829 		Internal::LockGuard LG(driver->m_nodeMutex);
1830 		if (Internal::VC::Value* value = driver->GetValue(_id))
1831 		{
1832 			res = value->IsSet();
1833 			value->Release();
1834 		}
1835 		else
1836 		{
1837 			OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to IsValueSet");
1838 		}
1839 	}
1840 
1841 	return res;
1842 }
1843 
1844 //-----------------------------------------------------------------------------
1845 // <Manager::IsValuePolled>
1846 // Test whether the value is currently being polled
1847 //-----------------------------------------------------------------------------
IsValuePolled(ValueID const & _id)1848 bool Manager::IsValuePolled(ValueID const& _id)
1849 {
1850 	bool res = false;
1851 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1852 	{
1853 		Internal::LockGuard LG(driver->m_nodeMutex);
1854 		if (Internal::VC::Value* value = driver->GetValue(_id))
1855 		{
1856 			res = value->IsPolled();
1857 			value->Release();
1858 		}
1859 		else
1860 		{
1861 			OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to IsValuePolled");
1862 		}
1863 	}
1864 
1865 	return res;
1866 }
1867 
1868 //-----------------------------------------------------------------------------
1869 // <Manager::IsValueValid>
1870 // Test whether the valueID is Valid
1871 //-----------------------------------------------------------------------------
IsValueValid(ValueID const & _id)1872 bool Manager::IsValueValid(ValueID const& _id)
1873 {
1874 	if (Driver* driver = GetDriver(_id.GetHomeId()))
1875 	{
1876 		Internal::LockGuard LG(driver->m_nodeMutex);
1877 		if (Internal::VC::Value* value = driver->GetValue(_id))
1878 		{
1879 			value->Release();
1880 			return true;
1881 		}
1882 	}
1883 	return false;
1884 }
1885 
1886 
1887 //-----------------------------------------------------------------------------
1888 // <Manager::GetValueAsBitSet>
1889 // Gets a bit from a BitSet as a bool
1890 //-----------------------------------------------------------------------------
GetValueAsBitSet(ValueID const & _id,uint8 _pos,bool * o_value)1891 bool Manager::GetValueAsBitSet(ValueID const& _id, uint8 _pos, bool* o_value)
1892 {
1893 
1894 	if (o_value)
1895 	{
1896 		if (ValueID::ValueType_BitSet == _id.GetType())
1897 		{
1898 			if (Driver* driver = GetDriver(_id.GetHomeId()))
1899 			{
1900 				Internal::LockGuard LG(driver->m_nodeMutex);
1901 				if (Internal::VC::ValueBitSet* value = static_cast<Internal::VC::ValueBitSet*>(driver->GetValue(_id)))
1902 				{
1903 					*o_value = value->GetBit(_pos);
1904 					value->Release();
1905 					return true;
1906 				}
1907 				else
1908 				{
1909 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsBitSet");
1910 				}
1911 			}
1912 		}
1913 		else
1914 		{
1915 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueAsBitSet is not a BitSet Value");
1916 		}
1917 	}
1918 	return false;
1919 }
1920 
1921 //-----------------------------------------------------------------------------
1922 // <Manager::GetValueAsBool>
1923 // Gets a value as a bool
1924 //-----------------------------------------------------------------------------
GetValueAsBool(ValueID const & _id,bool * o_value)1925 bool Manager::GetValueAsBool(ValueID const& _id, bool* o_value)
1926 {
1927 	bool res = false;
1928 
1929 	if (o_value)
1930 	{
1931 		if (ValueID::ValueType_Bool == _id.GetType())
1932 		{
1933 			if (Driver* driver = GetDriver(_id.GetHomeId()))
1934 			{
1935 				Internal::LockGuard LG(driver->m_nodeMutex);
1936 				if (Internal::VC::ValueBool* value = static_cast<Internal::VC::ValueBool*>(driver->GetValue(_id)))
1937 				{
1938 					*o_value = value->GetValue();
1939 					value->Release();
1940 					res = true;
1941 				}
1942 				else
1943 				{
1944 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsBool");
1945 				}
1946 			}
1947 		}
1948 		else if (ValueID::ValueType_Button == _id.GetType())
1949 		{
1950 			if (Driver* driver = GetDriver(_id.GetHomeId()))
1951 			{
1952 				Internal::LockGuard LG(driver->m_nodeMutex);
1953 				if (Internal::VC::ValueButton* value = static_cast<Internal::VC::ValueButton*>(driver->GetValue(_id)))
1954 				{
1955 					*o_value = value->IsPressed();
1956 					value->Release();
1957 					res = true;
1958 				}
1959 				else
1960 				{
1961 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsBool");
1962 				}
1963 			}
1964 		}
1965 		else
1966 		{
1967 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueAsBool is not a Bool or Button Value");
1968 		}
1969 	}
1970 
1971 	return res;
1972 }
1973 
1974 //-----------------------------------------------------------------------------
1975 // <Manager::GetValueAsByte>
1976 // Gets a value as an 8-bit unsigned integer
1977 //-----------------------------------------------------------------------------
GetValueAsByte(ValueID const & _id,uint8 * o_value)1978 bool Manager::GetValueAsByte(ValueID const& _id, uint8* o_value)
1979 {
1980 	bool res = false;
1981 
1982 	if (o_value)
1983 	{
1984 		if (ValueID::ValueType_Byte == _id.GetType())
1985 		{
1986 			if (Driver* driver = GetDriver(_id.GetHomeId()))
1987 			{
1988 				Internal::LockGuard LG(driver->m_nodeMutex);
1989 				if (Internal::VC::ValueByte* value = static_cast<Internal::VC::ValueByte*>(driver->GetValue(_id)))
1990 				{
1991 					*o_value = value->GetValue();
1992 					value->Release();
1993 					res = true;
1994 				}
1995 				else
1996 				{
1997 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsByte");
1998 				}
1999 			}
2000 		}
2001 		else
2002 		{
2003 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueAsByte is not a Byte Value");
2004 		}
2005 	}
2006 
2007 	return res;
2008 }
2009 
2010 //-----------------------------------------------------------------------------
2011 // <Manager::GetValueAsFloat>
2012 // Gets a value as a floating point number
2013 //-----------------------------------------------------------------------------
GetValueAsFloat(ValueID const & _id,float * o_value)2014 bool Manager::GetValueAsFloat(ValueID const& _id, float* o_value)
2015 {
2016 	bool res = false;
2017 
2018 	if (o_value)
2019 	{
2020 		if (ValueID::ValueType_Decimal == _id.GetType())
2021 		{
2022 			if (Driver* driver = GetDriver(_id.GetHomeId()))
2023 			{
2024 				Internal::LockGuard LG(driver->m_nodeMutex);
2025 				if (Internal::VC::ValueDecimal* value = static_cast<Internal::VC::ValueDecimal*>(driver->GetValue(_id)))
2026 				{
2027 					string str = value->GetValue();
2028 					*o_value = (float) atof(str.c_str());
2029 					value->Release();
2030 					res = true;
2031 				}
2032 				else
2033 				{
2034 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsFloat");
2035 				}
2036 			}
2037 		}
2038 		else
2039 		{
2040 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueAsFloat is not a Float Value");
2041 		}
2042 	}
2043 
2044 	return res;
2045 }
2046 
2047 //-----------------------------------------------------------------------------
2048 // <Manager::GetValueAsInt>
2049 // Gets a value as a 32-bit signed integer
2050 //-----------------------------------------------------------------------------
GetValueAsInt(ValueID const & _id,int32 * o_value)2051 bool Manager::GetValueAsInt(ValueID const& _id, int32* o_value)
2052 {
2053 	bool res = false;
2054 
2055 	if (o_value)
2056 	{
2057 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2058 		{
2059 			Internal::LockGuard LG(driver->m_nodeMutex);
2060 
2061 			if (ValueID::ValueType_Int == _id.GetType())
2062 			{
2063 				if (Internal::VC::ValueInt* value = static_cast<Internal::VC::ValueInt*>(driver->GetValue(_id)))
2064 				{
2065 					*o_value = value->GetValue();
2066 					value->Release();
2067 					res = true;
2068 				}
2069 				else
2070 				{
2071 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsInt");
2072 				}
2073 			}
2074 			else if (ValueID::ValueType_BitSet == _id.GetType())
2075 			{
2076 				if (Internal::VC::ValueBitSet* value = static_cast<Internal::VC::ValueBitSet*>(driver->GetValue(_id)))
2077 				{
2078 					*o_value = value->GetValue();
2079 					value->Release();
2080 					res = true;
2081 				}
2082 				else
2083 				{
2084 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsInt");
2085 				}
2086 			}
2087 			else
2088 			{
2089 				OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueAsInt is not a Int or BitSet Value");
2090 			}
2091 		}
2092 	}
2093 
2094 	return res;
2095 }
2096 
2097 //-----------------------------------------------------------------------------
2098 // <Manager::GetValueAsRaw>
2099 // Gets a value as a collection of bytes
2100 //-----------------------------------------------------------------------------
GetValueAsRaw(ValueID const & _id,uint8 ** o_value,uint8 * o_length)2101 bool Manager::GetValueAsRaw(ValueID const& _id, uint8** o_value, uint8* o_length)
2102 {
2103 	bool res = false;
2104 
2105 	if (o_value && o_length)
2106 	{
2107 		if (ValueID::ValueType_Raw == _id.GetType())
2108 		{
2109 			if (Driver* driver = GetDriver(_id.GetHomeId()))
2110 			{
2111 				Internal::LockGuard LG(driver->m_nodeMutex);
2112 				if (Internal::VC::ValueRaw* value = static_cast<Internal::VC::ValueRaw*>(driver->GetValue(_id)))
2113 				{
2114 					*o_length = value->GetLength();
2115 					*o_value = new uint8[*o_length];
2116 					memcpy(*o_value, value->GetValue(), *o_length);
2117 					value->Release();
2118 					res = true;
2119 				}
2120 				else
2121 				{
2122 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsRaw");
2123 				}
2124 			}
2125 		}
2126 		else
2127 		{
2128 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueAsRaw is not a Raw Value");
2129 		}
2130 	}
2131 
2132 	return res;
2133 }
2134 
2135 //-----------------------------------------------------------------------------
2136 // <Manager::GetValueAsShort>
2137 // Gets a value as a 16-bit signed integer
2138 //-----------------------------------------------------------------------------
GetValueAsShort(ValueID const & _id,int16 * o_value)2139 bool Manager::GetValueAsShort(ValueID const& _id, int16* o_value)
2140 {
2141 	bool res = false;
2142 
2143 	if (o_value)
2144 	{
2145 		if (ValueID::ValueType_Short == _id.GetType())
2146 		{
2147 			if (Driver* driver = GetDriver(_id.GetHomeId()))
2148 			{
2149 				Internal::LockGuard LG(driver->m_nodeMutex);
2150 				if (Internal::VC::ValueShort* value = static_cast<Internal::VC::ValueShort*>(driver->GetValue(_id)))
2151 				{
2152 					*o_value = value->GetValue();
2153 					value->Release();
2154 					res = true;
2155 				}
2156 				else
2157 				{
2158 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsShort");
2159 				}
2160 			}
2161 		}
2162 		else
2163 		{
2164 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueAsShort is not a Short Value");
2165 		}
2166 	}
2167 
2168 	return res;
2169 }
2170 
2171 //-----------------------------------------------------------------------------
2172 // <Manager::GetValueAsString>
2173 // Creates a string representation of the value, regardless of type
2174 //-----------------------------------------------------------------------------
GetValueAsString(ValueID const & _id,string * o_value)2175 bool Manager::GetValueAsString(ValueID const& _id, string* o_value)
2176 {
2177 	bool res = false;
2178 	char str[256] =
2179 	{ 0 };
2180 
2181 	if (o_value)
2182 	{
2183 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2184 		{
2185 			Internal::LockGuard LG(driver->m_nodeMutex);
2186 
2187 			switch (_id.GetType())
2188 			{
2189 				case ValueID::ValueType_BitSet:
2190 				{
2191 					if (Internal::VC::ValueBitSet* value = static_cast<Internal::VC::ValueBitSet*>(driver->GetValue(_id)))
2192 					{
2193 						*o_value = value->GetAsString();
2194 						value->Release();
2195 						res = true;
2196 					}
2197 					else
2198 					{
2199 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2200 					}
2201 					break;
2202 				}
2203 				case ValueID::ValueType_Bool:
2204 				{
2205 					if (Internal::VC::ValueBool* value = static_cast<Internal::VC::ValueBool*>(driver->GetValue(_id)))
2206 					{
2207 						*o_value = value->GetValue() ? "True" : "False";
2208 						value->Release();
2209 						res = true;
2210 					}
2211 					else
2212 					{
2213 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2214 					}
2215 					break;
2216 				}
2217 				case ValueID::ValueType_Byte:
2218 				{
2219 					if (Internal::VC::ValueByte* value = static_cast<Internal::VC::ValueByte*>(driver->GetValue(_id)))
2220 					{
2221 						snprintf(str, sizeof(str), "%u", value->GetValue());
2222 						*o_value = str;
2223 						value->Release();
2224 						res = true;
2225 					}
2226 					else
2227 					{
2228 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2229 					}
2230 					break;
2231 				}
2232 				case ValueID::ValueType_Decimal:
2233 				{
2234 					if (Internal::VC::ValueDecimal* value = static_cast<Internal::VC::ValueDecimal*>(driver->GetValue(_id)))
2235 					{
2236 						*o_value = value->GetValue();
2237 						value->Release();
2238 						res = true;
2239 					}
2240 					else
2241 					{
2242 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2243 					}
2244 					break;
2245 				}
2246 				case ValueID::ValueType_Int:
2247 				{
2248 					if (Internal::VC::ValueInt* value = static_cast<Internal::VC::ValueInt*>(driver->GetValue(_id)))
2249 					{
2250 						snprintf(str, sizeof(str), "%d", value->GetValue());
2251 						*o_value = str;
2252 						value->Release();
2253 						res = true;
2254 					}
2255 					else
2256 					{
2257 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2258 					}
2259 					break;
2260 				}
2261 				case ValueID::ValueType_List:
2262 				{
2263 					if (Internal::VC::ValueList* value = static_cast<Internal::VC::ValueList*>(driver->GetValue(_id)))
2264 					{
2265 						Internal::VC::ValueList::Item const *item = value->GetItem();
2266 						if (item == NULL)
2267 						{
2268 							o_value = NULL;
2269 							res = false;
2270 						}
2271 						else
2272 						{
2273 							*o_value = item->m_label;
2274 							res = true;
2275 						}
2276 						value->Release();
2277 
2278 					}
2279 					else
2280 					{
2281 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2282 					}
2283 					break;
2284 				}
2285 				case ValueID::ValueType_Raw:
2286 				{
2287 					if (Internal::VC::ValueRaw* value = static_cast<Internal::VC::ValueRaw*>(driver->GetValue(_id)))
2288 					{
2289 						*o_value = value->GetAsString();
2290 						value->Release();
2291 						res = true;
2292 					}
2293 					else
2294 					{
2295 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2296 					}
2297 					break;
2298 				}
2299 				case ValueID::ValueType_Short:
2300 				{
2301 					if (Internal::VC::ValueShort* value = static_cast<Internal::VC::ValueShort*>(driver->GetValue(_id)))
2302 					{
2303 						snprintf(str, sizeof(str), "%d", value->GetValue());
2304 						*o_value = str;
2305 						value->Release();
2306 						res = true;
2307 					}
2308 					else
2309 					{
2310 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2311 					}
2312 					break;
2313 				}
2314 				case ValueID::ValueType_String:
2315 				{
2316 					if (Internal::VC::ValueString* value = static_cast<Internal::VC::ValueString*>(driver->GetValue(_id)))
2317 					{
2318 						*o_value = value->GetValue();
2319 						value->Release();
2320 						res = true;
2321 					}
2322 					else
2323 					{
2324 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2325 					}
2326 					break;
2327 				}
2328 				case ValueID::ValueType_Button:
2329 				{
2330 					if (Internal::VC::ValueButton* value = static_cast<Internal::VC::ValueButton*>(driver->GetValue(_id)))
2331 					{
2332 						*o_value = value->IsPressed() ? "True" : "False";
2333 						value->Release();
2334 						res = true;
2335 					}
2336 					else
2337 					{
2338 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2339 					}
2340 					break;
2341 				}
2342 				case ValueID::ValueType_Schedule:
2343 				{
2344 					if (Internal::VC::ValueSchedule* value = static_cast<Internal::VC::ValueSchedule*>(driver->GetValue(_id)))
2345 					{
2346 						*o_value = value->GetAsString();
2347 						value->Release();
2348 						res = true;
2349 					}
2350 					else
2351 					{
2352 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueAsString");
2353 					}
2354 					break;
2355 				}
2356 			}
2357 
2358 		}
2359 	}
2360 
2361 	return res;
2362 }
2363 
2364 //-----------------------------------------------------------------------------
2365 // <Manager::GetValueListSelection>
2366 // Gets the selected item from a list value (returning a string)
2367 //-----------------------------------------------------------------------------
GetValueListSelection(ValueID const & _id,string * o_value)2368 bool Manager::GetValueListSelection(ValueID const& _id, string* o_value)
2369 {
2370 	bool res = false;
2371 
2372 	if (o_value)
2373 	{
2374 		if (ValueID::ValueType_List == _id.GetType())
2375 		{
2376 			if (Driver* driver = GetDriver(_id.GetHomeId()))
2377 			{
2378 				Internal::LockGuard LG(driver->m_nodeMutex);
2379 				if (Internal::VC::ValueList* value = static_cast<Internal::VC::ValueList*>(driver->GetValue(_id)))
2380 				{
2381 					Internal::VC::ValueList::Item const *item = value->GetItem();
2382 					if (item != NULL && item->m_label.length() > 0)
2383 					{
2384 						*o_value = item->m_label;
2385 						res = true;
2386 					}
2387 					else
2388 					{
2389 						o_value = NULL;
2390 						Log::Write(LogLevel_Warning, "ValueList returned a NULL value for GetValueListSelection: %s", value->GetLabel().c_str());
2391 					}
2392 					value->Release();
2393 				}
2394 				else
2395 				{
2396 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueListSelection");
2397 				}
2398 			}
2399 		}
2400 		else
2401 		{
2402 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueListSelection is not a List Value");
2403 		}
2404 	}
2405 
2406 	return res;
2407 }
2408 
2409 //-----------------------------------------------------------------------------
2410 // <Manager::GetValueListSelection>
2411 // Gets the selected item from a list value (returning the index)
2412 //-----------------------------------------------------------------------------
GetValueListSelection(ValueID const & _id,int32 * o_value)2413 bool Manager::GetValueListSelection(ValueID const& _id, int32* o_value)
2414 {
2415 	bool res = false;
2416 
2417 	if (o_value)
2418 	{
2419 		if (ValueID::ValueType_List == _id.GetType())
2420 		{
2421 			if (Driver* driver = GetDriver(_id.GetHomeId()))
2422 			{
2423 				Internal::LockGuard LG(driver->m_nodeMutex);
2424 				if (Internal::VC::ValueList* value = static_cast<Internal::VC::ValueList*>(driver->GetValue(_id)))
2425 				{
2426 					Internal::VC::ValueList::Item const *item = value->GetItem();
2427 					if (item == NULL)
2428 					{
2429 						res = false;
2430 					}
2431 					else
2432 					{
2433 						*o_value = item->m_value;
2434 						res = true;
2435 					}
2436 					value->Release();
2437 
2438 				}
2439 				else
2440 				{
2441 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueListSelection");
2442 				}
2443 			}
2444 		}
2445 		else
2446 		{
2447 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueListSelection is not a List Value");
2448 		}
2449 	}
2450 
2451 	return res;
2452 }
2453 
2454 //-----------------------------------------------------------------------------
2455 // <Manager::GetValueListItems>
2456 // Gets the list of items from a list value
2457 //-----------------------------------------------------------------------------
GetValueListItems(ValueID const & _id,vector<string> * o_value)2458 bool Manager::GetValueListItems(ValueID const& _id, vector<string>* o_value)
2459 {
2460 	bool res = false;
2461 
2462 	if (o_value)
2463 	{
2464 		if (ValueID::ValueType_List == _id.GetType())
2465 		{
2466 			if (Driver* driver = GetDriver(_id.GetHomeId()))
2467 			{
2468 				Internal::LockGuard LG(driver->m_nodeMutex);
2469 				if (Internal::VC::ValueList* value = static_cast<Internal::VC::ValueList*>(driver->GetValue(_id)))
2470 				{
2471 					o_value->clear();
2472 					res = value->GetItemLabels(o_value);
2473 					value->Release();
2474 				}
2475 				else
2476 				{
2477 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueListItems");
2478 				}
2479 			}
2480 		}
2481 		else
2482 		{
2483 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueListItems is not a List Value");
2484 		}
2485 	}
2486 
2487 	return res;
2488 }
2489 
2490 //-----------------------------------------------------------------------------
2491 // <Manager::GetValueListValues>
2492 // Gets the list of values from a list value
2493 //-----------------------------------------------------------------------------
GetValueListValues(ValueID const & _id,vector<int32> * o_value)2494 bool Manager::GetValueListValues(ValueID const& _id, vector<int32>* o_value)
2495 {
2496 	bool res = false;
2497 
2498 	if (o_value)
2499 	{
2500 		if (ValueID::ValueType_List == _id.GetType())
2501 		{
2502 			if (Driver* driver = GetDriver(_id.GetHomeId()))
2503 			{
2504 				Internal::LockGuard LG(driver->m_nodeMutex);
2505 				if (Internal::VC::ValueList* value = static_cast<Internal::VC::ValueList*>(driver->GetValue(_id)))
2506 				{
2507 					o_value->clear();
2508 					res = value->GetItemValues(o_value);
2509 					value->Release();
2510 				}
2511 				else
2512 				{
2513 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueListValues");
2514 				}
2515 			}
2516 		}
2517 		else
2518 		{
2519 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueListValues is not a List Value");
2520 		}
2521 	}
2522 
2523 	return res;
2524 }
2525 
2526 //-----------------------------------------------------------------------------
2527 // <Manager::GetValueFloatPrecision>
2528 // Gets a value's scale as a uint8
2529 //-----------------------------------------------------------------------------
GetValueFloatPrecision(ValueID const & _id,uint8 * o_value)2530 bool Manager::GetValueFloatPrecision(ValueID const& _id, uint8* o_value)
2531 {
2532 	bool res = false;
2533 
2534 	if (o_value)
2535 	{
2536 		if (ValueID::ValueType_Decimal == _id.GetType())
2537 		{
2538 			if (Driver* driver = GetDriver(_id.GetHomeId()))
2539 			{
2540 				Internal::LockGuard LG(driver->m_nodeMutex);
2541 				if (Internal::VC::ValueDecimal* value = static_cast<Internal::VC::ValueDecimal*>(driver->GetValue(_id)))
2542 				{
2543 					*o_value = value->GetPrecision();
2544 					value->Release();
2545 					res = true;
2546 				}
2547 				else
2548 				{
2549 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetValueFloatPrecision");
2550 				}
2551 			}
2552 		}
2553 		else
2554 		{
2555 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueFloatPrecision is not a Decimal Value");
2556 		}
2557 	}
2558 
2559 	return res;
2560 }
2561 
2562 //-----------------------------------------------------------------------------
2563 // <Manager::SetValue>
2564 // Sets a bit in a BitSet Value
2565 //-----------------------------------------------------------------------------
SetValue(ValueID const & _id,uint8 _pos,bool const _value)2566 bool Manager::SetValue(ValueID const& _id, uint8 _pos, bool const _value)
2567 {
2568 	bool res = false;
2569 
2570 	if (ValueID::ValueType_BitSet == _id.GetType())
2571 	{
2572 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2573 		{
2574 			if (_id.GetNodeId() != driver->GetControllerNodeId())
2575 			{
2576 				Internal::LockGuard LG(driver->m_nodeMutex);
2577 				if (Internal::VC::ValueBitSet* value = static_cast<Internal::VC::ValueBitSet*>(driver->GetValue(_id)))
2578 				{
2579 					if (_value)
2580 						res = value->SetBit(_pos);
2581 					else
2582 						res = value->ClearBit(_pos);
2583 					value->Release();
2584 				}
2585 				else
2586 				{
2587 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
2588 				}
2589 			}
2590 		}
2591 	}
2592 	else
2593 	{
2594 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to SetValue is not a BitSet Value");
2595 	}
2596 
2597 	return res;
2598 }
2599 
2600 //-----------------------------------------------------------------------------
2601 // <Manager::SetValue>
2602 // Sets the value from a bool
2603 //-----------------------------------------------------------------------------
SetValue(ValueID const & _id,bool const _value)2604 bool Manager::SetValue(ValueID const& _id, bool const _value)
2605 {
2606 	bool res = false;
2607 
2608 	if (ValueID::ValueType_Bool == _id.GetType())
2609 	{
2610 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2611 		{
2612 			if (_id.GetNodeId() != driver->GetControllerNodeId())
2613 			{
2614 				Internal::LockGuard LG(driver->m_nodeMutex);
2615 				if (Internal::VC::ValueBool* value = static_cast<Internal::VC::ValueBool*>(driver->GetValue(_id)))
2616 				{
2617 					res = value->Set(_value);
2618 					value->Release();
2619 				}
2620 				else
2621 				{
2622 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
2623 				}
2624 			}
2625 		}
2626 	}
2627 	else
2628 	{
2629 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to SetValue is not a bool Value");
2630 	}
2631 
2632 	return res;
2633 }
2634 
2635 //-----------------------------------------------------------------------------
2636 // <Manager::SetValue>
2637 // Sets the value from a byte
2638 //-----------------------------------------------------------------------------
SetValue(ValueID const & _id,uint8 const _value)2639 bool Manager::SetValue(ValueID const& _id, uint8 const _value)
2640 {
2641 	bool res = false;
2642 
2643 	if (ValueID::ValueType_Byte == _id.GetType())
2644 	{
2645 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2646 		{
2647 			if (_id.GetNodeId() != driver->GetControllerNodeId())
2648 			{
2649 				Internal::LockGuard LG(driver->m_nodeMutex);
2650 				if (Internal::VC::ValueByte* value = static_cast<Internal::VC::ValueByte*>(driver->GetValue(_id)))
2651 				{
2652 					res = value->Set(_value);
2653 					value->Release();
2654 				}
2655 				else
2656 				{
2657 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
2658 				}
2659 			}
2660 		}
2661 	}
2662 	else if (ValueID::ValueType_BitSet == _id.GetType())
2663 	{
2664 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2665 		{
2666 			if (_id.GetNodeId() != driver->GetControllerNodeId())
2667 			{
2668 				Internal::LockGuard LG(driver->m_nodeMutex);
2669 				if (Internal::VC::ValueBitSet* value = static_cast<Internal::VC::ValueBitSet*>(driver->GetValue(_id)))
2670 				{
2671 					if (value->GetSize() == 1)
2672 					{
2673 						res = value->Set(_value);
2674 						value->Release();
2675 					}
2676 					else
2677 					{
2678 						OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "BitSet ValueID is Not of Size 1 (SetValue uint8)");
2679 					}
2680 				}
2681 				else
2682 				{
2683 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
2684 				}
2685 			}
2686 		}
2687 	}
2688 	else
2689 	{
2690 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to SetValue is not a Byte Value");
2691 	}
2692 
2693 	return res;
2694 }
2695 
2696 //-----------------------------------------------------------------------------
2697 // <Manager::SetValue>
2698 // Sets the value from a floating point number
2699 //-----------------------------------------------------------------------------
SetValue(ValueID const & _id,float const _value)2700 bool Manager::SetValue(ValueID const& _id, float const _value)
2701 {
2702 	bool res = false;
2703 
2704 	if (ValueID::ValueType_Decimal == _id.GetType())
2705 	{
2706 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2707 		{
2708 			if (_id.GetNodeId() != driver->GetControllerNodeId())
2709 			{
2710 				Internal::LockGuard LG(driver->m_nodeMutex);
2711 				if (Internal::VC::ValueDecimal* value = static_cast<Internal::VC::ValueDecimal*>(driver->GetValue(_id)))
2712 				{
2713 					char str[256];
2714 					snprintf(str, sizeof(str), "%f", _value);
2715 
2716 					// remove trailing zeros (and the decimal point, if present)
2717 					// TODO: better way of figuring out which locale is being used ('.' or ',' to separate decimals)
2718 					size_t nLen;
2719 					if ((strchr(str, '.') != NULL) || (strchr(str, ',') != NULL))
2720 					{
2721 						for (nLen = strlen(str) - 1; nLen > 0; nLen--)
2722 						{
2723 							if (str[nLen] == '0')
2724 								str[nLen] = 0;
2725 							else
2726 								break;
2727 						}
2728 						if ((str[nLen] == '.') || (str[nLen] == ','))
2729 							str[nLen] = 0;
2730 					}
2731 
2732 					// now set the value
2733 					res = value->Set(str);
2734 					value->Release();
2735 				}
2736 				else
2737 				{
2738 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
2739 				}
2740 			}
2741 		}
2742 	}
2743 	else
2744 	{
2745 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to SetValue is not a Decimal Value");
2746 	}
2747 
2748 	return res;
2749 }
2750 
2751 //-----------------------------------------------------------------------------
2752 // <Manager::SetValue>
2753 // Sets the value from a 32-bit signed integer
2754 //-----------------------------------------------------------------------------
SetValue(ValueID const & _id,int32 const _value)2755 bool Manager::SetValue(ValueID const& _id, int32 const _value)
2756 {
2757 	bool res = false;
2758 
2759 	if (ValueID::ValueType_Int == _id.GetType())
2760 	{
2761 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2762 		{
2763 			if (_id.GetNodeId() != driver->GetControllerNodeId())
2764 			{
2765 				Internal::LockGuard LG(driver->m_nodeMutex);
2766 				if (Internal::VC::ValueInt* value = static_cast<Internal::VC::ValueInt*>(driver->GetValue(_id)))
2767 				{
2768 					res = value->Set(_value);
2769 					value->Release();
2770 				}
2771 				else
2772 				{
2773 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
2774 				}
2775 			}
2776 		}
2777 	}
2778 	else if (ValueID::ValueType_BitSet == _id.GetType())
2779 	{
2780 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2781 		{
2782 			if (_id.GetNodeId() != driver->GetControllerNodeId())
2783 			{
2784 				Internal::LockGuard LG(driver->m_nodeMutex);
2785 				if (Internal::VC::ValueBitSet* value = static_cast<Internal::VC::ValueBitSet*>(driver->GetValue(_id)))
2786 				{
2787 					if (value->GetSize() == 4)
2788 					{
2789 						res = value->Set(_value);
2790 						value->Release();
2791 					}
2792 					else
2793 					{
2794 						OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "BitSet ValueID is Not of Size 4 (SetValue uint32)");
2795 					}
2796 				}
2797 				else
2798 				{
2799 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
2800 				}
2801 			}
2802 		}
2803 	}
2804 	else
2805 	{
2806 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to SetValue is not a Int Value");
2807 	}
2808 
2809 	return res;
2810 }
2811 
2812 //-----------------------------------------------------------------------------
2813 // <Manager::SetValue>
2814 // Sets the value from a collection of bytes
2815 //-----------------------------------------------------------------------------
SetValue(ValueID const & _id,uint8 const * _value,uint8 const _length)2816 bool Manager::SetValue(ValueID const& _id, uint8 const* _value, uint8 const _length)
2817 {
2818 	bool res = false;
2819 
2820 	if (ValueID::ValueType_Raw == _id.GetType())
2821 	{
2822 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2823 		{
2824 			if (_id.GetNodeId() != driver->GetControllerNodeId())
2825 			{
2826 				Internal::LockGuard LG(driver->m_nodeMutex);
2827 				if (Internal::VC::ValueRaw* value = static_cast<Internal::VC::ValueRaw*>(driver->GetValue(_id)))
2828 				{
2829 					res = value->Set(_value, _length);
2830 					value->Release();
2831 				}
2832 				else
2833 				{
2834 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
2835 				}
2836 			}
2837 		}
2838 	}
2839 	else
2840 	{
2841 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to SetValue is not a Raw Value");
2842 	}
2843 
2844 	return res;
2845 }
2846 
2847 //-----------------------------------------------------------------------------
2848 // <Manager::SetValue>
2849 // Sets the value from a 16-bit signed integer
2850 //-----------------------------------------------------------------------------
SetValue(ValueID const & _id,int16 const _value)2851 bool Manager::SetValue(ValueID const& _id, int16 const _value)
2852 {
2853 	bool res = false;
2854 
2855 	if (ValueID::ValueType_Short == _id.GetType())
2856 	{
2857 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2858 		{
2859 			if (_id.GetNodeId() != driver->GetControllerNodeId())
2860 			{
2861 				Internal::LockGuard LG(driver->m_nodeMutex);
2862 				if (Internal::VC::ValueShort* value = static_cast<Internal::VC::ValueShort*>(driver->GetValue(_id)))
2863 				{
2864 					res = value->Set(_value);
2865 					value->Release();
2866 				}
2867 				else
2868 				{
2869 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
2870 				}
2871 			}
2872 		}
2873 	}
2874 	else if (ValueID::ValueType_BitSet == _id.GetType())
2875 	{
2876 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2877 		{
2878 			if (_id.GetNodeId() != driver->GetControllerNodeId())
2879 			{
2880 				Internal::LockGuard LG(driver->m_nodeMutex);
2881 				if (Internal::VC::ValueBitSet* value = static_cast<Internal::VC::ValueBitSet*>(driver->GetValue(_id)))
2882 				{
2883 					if (value->GetSize() == 2)
2884 					{
2885 						res = value->Set(_value);
2886 						value->Release();
2887 					}
2888 					else
2889 					{
2890 						OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "BitSet ValueID is Not of Size 2 (SetValue uint16)");
2891 					}
2892 				}
2893 				else
2894 				{
2895 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
2896 				}
2897 			}
2898 		}
2899 	}
2900 	else
2901 	{
2902 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to SetValue is not a Short Value");
2903 	}
2904 
2905 	return res;
2906 }
2907 
2908 //-----------------------------------------------------------------------------
2909 // <Manager::SetValueListSelection>
2910 // Sets the selected item in a list by value
2911 //-----------------------------------------------------------------------------
SetValueListSelection(ValueID const & _id,string const & _selectedItem)2912 bool Manager::SetValueListSelection(ValueID const& _id, string const& _selectedItem)
2913 {
2914 	bool res = false;
2915 
2916 	if (ValueID::ValueType_List == _id.GetType())
2917 	{
2918 		if (Driver* driver = GetDriver(_id.GetHomeId()))
2919 		{
2920 			if (_id.GetNodeId() != driver->GetControllerNodeId())
2921 			{
2922 				Internal::LockGuard LG(driver->m_nodeMutex);
2923 				if (Internal::VC::ValueList* value = static_cast<Internal::VC::ValueList*>(driver->GetValue(_id)))
2924 				{
2925 					res = value->SetByLabel(_selectedItem);
2926 					value->Release();
2927 				}
2928 				else
2929 				{
2930 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValueListSelection");
2931 				}
2932 			}
2933 
2934 		}
2935 	}
2936 	else
2937 	{
2938 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to SetValueListSelection is not a List Value");
2939 	}
2940 
2941 	return res;
2942 }
2943 
2944 //-----------------------------------------------------------------------------
2945 // <Manager::SetValue>
2946 // Sets the value from a string
2947 //-----------------------------------------------------------------------------
SetValue(ValueID const & _id,string const & _value)2948 bool Manager::SetValue(ValueID const& _id, string const& _value)
2949 {
2950 	bool res = false;
2951 
2952 	if (Driver* driver = GetDriver(_id.GetHomeId()))
2953 	{
2954 		if (_id.GetNodeId() != driver->GetControllerNodeId())
2955 		{
2956 			Internal::LockGuard LG(driver->m_nodeMutex);
2957 
2958 			switch (_id.GetType())
2959 			{
2960 				case ValueID::ValueType_BitSet:
2961 				{
2962 					if (Internal::VC::ValueBitSet* value = static_cast<Internal::VC::ValueBitSet*>(driver->GetValue(_id)))
2963 					{
2964 
2965 						res = value->SetFromString(_value);
2966 						value->Release();
2967 					}
2968 					else
2969 					{
2970 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
2971 					}
2972 					break;
2973 				}
2974 				case ValueID::ValueType_Bool:
2975 				{
2976 					if (Internal::VC::ValueBool* value = static_cast<Internal::VC::ValueBool*>(driver->GetValue(_id)))
2977 					{
2978 						if (!strcasecmp("true", _value.c_str()))
2979 						{
2980 							res = value->Set(true);
2981 						}
2982 						else if (!strcasecmp("false", _value.c_str()))
2983 						{
2984 							res = value->Set(false);
2985 						}
2986 						value->Release();
2987 					}
2988 					else
2989 					{
2990 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
2991 					}
2992 					break;
2993 				}
2994 				case ValueID::ValueType_Byte:
2995 				{
2996 					if (Internal::VC::ValueByte* value = static_cast<Internal::VC::ValueByte*>(driver->GetValue(_id)))
2997 					{
2998 						uint32 val = (uint32) atoi(_value.c_str());
2999 						if (val < 256)
3000 						{
3001 							res = value->Set((uint8) val);
3002 						}
3003 						value->Release();
3004 					}
3005 					else
3006 					{
3007 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
3008 					}
3009 					break;
3010 				}
3011 				case ValueID::ValueType_Decimal:
3012 				{
3013 					if (Internal::VC::ValueDecimal* value = static_cast<Internal::VC::ValueDecimal*>(driver->GetValue(_id)))
3014 					{
3015 						res = value->Set(_value);
3016 						value->Release();
3017 					}
3018 					else
3019 					{
3020 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
3021 					}
3022 					break;
3023 				}
3024 				case ValueID::ValueType_Int:
3025 				{
3026 					if (Internal::VC::ValueInt* value = static_cast<Internal::VC::ValueInt*>(driver->GetValue(_id)))
3027 					{
3028 						int32 val = atoi(_value.c_str());
3029 						res = value->Set(val);
3030 						value->Release();
3031 					}
3032 					else
3033 					{
3034 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
3035 					}
3036 					break;
3037 				}
3038 				case ValueID::ValueType_List:
3039 				{
3040 					if (Internal::VC::ValueList* value = static_cast<Internal::VC::ValueList*>(driver->GetValue(_id)))
3041 					{
3042 						res = value->SetByLabel(_value);
3043 						value->Release();
3044 					}
3045 					else
3046 					{
3047 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
3048 					}
3049 					break;
3050 				}
3051 				case ValueID::ValueType_Short:
3052 				{
3053 					if (Internal::VC::ValueShort* value = static_cast<Internal::VC::ValueShort*>(driver->GetValue(_id)))
3054 					{
3055 						int32 val = (uint32) atoi(_value.c_str());
3056 						if ((val < 32768) && (val >= -32768))
3057 						{
3058 							res = value->Set((int16) val);
3059 						}
3060 						value->Release();
3061 					}
3062 					else
3063 					{
3064 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
3065 					}
3066 					break;
3067 				}
3068 				case ValueID::ValueType_String:
3069 				{
3070 					if (Internal::VC::ValueString* value = static_cast<Internal::VC::ValueString*>(driver->GetValue(_id)))
3071 					{
3072 						res = value->Set(_value);
3073 						value->Release();
3074 					}
3075 					else
3076 					{
3077 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
3078 					}
3079 					break;
3080 				}
3081 				case ValueID::ValueType_Raw:
3082 				{
3083 					if (Internal::VC::ValueRaw* value = static_cast<Internal::VC::ValueRaw*>(driver->GetValue(_id)))
3084 					{
3085 						res = value->SetFromString(_value);
3086 						value->Release();
3087 					}
3088 					else
3089 					{
3090 						OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetValue");
3091 					}
3092 					break;
3093 				}
3094 				case ValueID::ValueType_Schedule:
3095 				case ValueID::ValueType_Button:
3096 				{
3097 					OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetValueFloatPrecision is not a Decimal Value");
3098 					break;
3099 				}
3100 			}
3101 		}
3102 	}
3103 	return res;
3104 }
3105 
3106 //-----------------------------------------------------------------------------
3107 // <Manager::RefreshValue>
3108 // Instruct the driver to refresh this value by sending a message to the device
3109 //-----------------------------------------------------------------------------
RefreshValue(ValueID const & _id)3110 bool Manager::RefreshValue(ValueID const& _id)
3111 {
3112 	bool bRet = false;	// return value
3113 
3114 	if (Driver* driver = GetDriver(_id.GetHomeId()))
3115 	{
3116 		Node *node;
3117 
3118 		// Need to lock and unlock nodes to check this information
3119 		Internal::LockGuard LG(driver->m_nodeMutex);
3120 
3121 		if ((node = driver->GetNode(_id.GetNodeId())) != NULL)
3122 		{
3123 			Internal::CC::CommandClass* cc = node->GetCommandClass(_id.GetCommandClassId());
3124 			if (cc)
3125 			{
3126 				uint16_t index = _id.GetIndex();
3127 				uint8 instance = _id.GetInstance();
3128 				Log::Write(LogLevel_Info, "mgr,     Refreshing node %d: %s index = %d instance = %d (to confirm a reported change)", node->m_nodeId, cc->GetCommandClassName().c_str(), index, instance);
3129 				cc->RequestValue(0, index, instance, Driver::MsgQueue_Send);
3130 				bRet = true;
3131 			}
3132 			else
3133 			{
3134 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to RefreshValue");
3135 				bRet = false;
3136 			}
3137 		}
3138 	}
3139 	return bRet;
3140 }
3141 
3142 //-----------------------------------------------------------------------------
3143 // <Manager::SetChangeVerified>
3144 // Set the verify changes flag for the specified value
3145 //-----------------------------------------------------------------------------
SetChangeVerified(ValueID const & _id,bool _verify)3146 void Manager::SetChangeVerified(ValueID const& _id, bool _verify)
3147 {
3148 	if (Driver* driver = GetDriver(_id.GetHomeId()))
3149 	{
3150 		Internal::LockGuard LG(driver->m_nodeMutex);
3151 		if (Internal::VC::Value* value = driver->GetValue(_id))
3152 		{
3153 			value->SetChangeVerified(_verify);
3154 			value->Release();
3155 		}
3156 		else
3157 		{
3158 			OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetChangeVerified");
3159 		}
3160 	}
3161 }
3162 
3163 //-----------------------------------------------------------------------------
3164 // <Manager::GetChangeVerified>
3165 // Get the verify changes flag for the specified value
3166 //-----------------------------------------------------------------------------
GetChangeVerified(ValueID const & _id)3167 bool Manager::GetChangeVerified(ValueID const& _id)
3168 {
3169 	bool res = false;
3170 	if (Driver* driver = GetDriver(_id.GetHomeId()))
3171 	{
3172 		Internal::LockGuard LG(driver->m_nodeMutex);
3173 		if (Internal::VC::Value* value = driver->GetValue(_id))
3174 		{
3175 			res = value->GetChangeVerified();
3176 			value->Release();
3177 		}
3178 		else
3179 		{
3180 			OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetChangeVerified");
3181 		}
3182 	}
3183 	return res;
3184 }
3185 
3186 //-----------------------------------------------------------------------------
3187 // <Manager::PressButton>
3188 // Starts an activity in a device.
3189 //-----------------------------------------------------------------------------
PressButton(ValueID const & _id)3190 bool Manager::PressButton(ValueID const& _id)
3191 {
3192 	bool res = false;
3193 
3194 	if (ValueID::ValueType_Button == _id.GetType())
3195 	{
3196 		if (Driver* driver = GetDriver(_id.GetHomeId()))
3197 		{
3198 			Internal::LockGuard LG(driver->m_nodeMutex);
3199 			if (Internal::VC::ValueButton* value = static_cast<Internal::VC::ValueButton*>(driver->GetValue(_id)))
3200 			{
3201 				res = value->PressButton();
3202 				value->Release();
3203 			}
3204 			else
3205 			{
3206 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to PressButton");
3207 			}
3208 		}
3209 	}
3210 	else
3211 	{
3212 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to PressButton is not a Button Value");
3213 	}
3214 
3215 	return res;
3216 }
3217 
3218 //-----------------------------------------------------------------------------
3219 // <Manager::ReleaseButton>
3220 // Stops an activity in a device.
3221 //-----------------------------------------------------------------------------
ReleaseButton(ValueID const & _id)3222 bool Manager::ReleaseButton(ValueID const& _id)
3223 {
3224 	bool res = false;
3225 
3226 	if (ValueID::ValueType_Button == _id.GetType())
3227 	{
3228 		if (Driver* driver = GetDriver(_id.GetHomeId()))
3229 		{
3230 			Internal::LockGuard LG(driver->m_nodeMutex);
3231 			if (Internal::VC::ValueButton* value = static_cast<Internal::VC::ValueButton*>(driver->GetValue(_id)))
3232 			{
3233 				res = value->ReleaseButton();
3234 				value->Release();
3235 			}
3236 			else
3237 			{
3238 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to ReleaseButton");
3239 			}
3240 		}
3241 	}
3242 	else
3243 	{
3244 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to ReleaseButton is not a Button Value");
3245 	}
3246 
3247 	return res;
3248 }
3249 
3250 //-----------------------------------------------------------------------------
3251 // <Manager::SetBitMask>
3252 // Sets a BitMask on a BitSet ValueID
3253 //-----------------------------------------------------------------------------
SetBitMask(ValueID const & _id,uint32 _mask)3254 bool Manager::SetBitMask(ValueID const& _id, uint32 _mask)
3255 {
3256 	bool res = false;
3257 
3258 	if (ValueID::ValueType_BitSet == _id.GetType())
3259 	{
3260 		if (Driver* driver = GetDriver(_id.GetHomeId()))
3261 		{
3262 			Internal::LockGuard LG(driver->m_nodeMutex);
3263 			if (Internal::VC::ValueBitSet* value = static_cast<Internal::VC::ValueBitSet*>(driver->GetValue(_id)))
3264 			{
3265 				res = value->SetBitMask(_mask);
3266 				value->Release();
3267 			}
3268 			else
3269 			{
3270 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetBitMask");
3271 			}
3272 		}
3273 	}
3274 	else
3275 	{
3276 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to SetBitMask is not a BitSet Value");
3277 	}
3278 
3279 	return res;
3280 
3281 }
3282 
3283 //-----------------------------------------------------------------------------
3284 // <Manager::GetBitMask>
3285 // Gets a BitMask on a BitSet ValueID
3286 //-----------------------------------------------------------------------------
GetBitMask(ValueID const & _id,int32 * o_mask)3287 bool Manager::GetBitMask(ValueID const& _id, int32* o_mask)
3288 {
3289 	bool res = false;
3290 
3291 	if (o_mask)
3292 	{
3293 		if (ValueID::ValueType_BitSet == _id.GetType())
3294 		{
3295 			if (Driver* driver = GetDriver(_id.GetHomeId()))
3296 			{
3297 				Internal::LockGuard LG(driver->m_nodeMutex);
3298 				if (Internal::VC::ValueBitSet* value = static_cast<Internal::VC::ValueBitSet*>(driver->GetValue(_id)))
3299 				{
3300 					*o_mask = value->GetBitMask();
3301 					value->Release();
3302 					res = true;
3303 				}
3304 				else
3305 				{
3306 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetBitMask");
3307 				}
3308 			}
3309 		}
3310 		else
3311 		{
3312 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetBitMask is not a BitSet Value");
3313 		}
3314 	}
3315 
3316 	return res;
3317 }
3318 
3319 //-----------------------------------------------------------------------------
3320 // <Manager::GetBitSetSize
3321 // Gets the size of a BitMask (1, 2 or 4)
3322 //-----------------------------------------------------------------------------
GetBitSetSize(ValueID const & _id,uint8 * o_size)3323 bool Manager::GetBitSetSize(ValueID const& _id, uint8* o_size)
3324 {
3325 	bool res = false;
3326 
3327 	if (o_size)
3328 	{
3329 		if (ValueID::ValueType_BitSet == _id.GetType())
3330 		{
3331 			if (Driver* driver = GetDriver(_id.GetHomeId()))
3332 			{
3333 				Internal::LockGuard LG(driver->m_nodeMutex);
3334 				if (Internal::VC::ValueBitSet* value = static_cast<Internal::VC::ValueBitSet*>(driver->GetValue(_id)))
3335 				{
3336 					*o_size = value->GetSize();
3337 					value->Release();
3338 					res = true;
3339 				}
3340 				else
3341 				{
3342 					OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetBitSetSize");
3343 				}
3344 			}
3345 		}
3346 		else
3347 		{
3348 			OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetBitSetSize is not a BitSet Value");
3349 		}
3350 	}
3351 
3352 	return res;
3353 }
3354 
3355 //-----------------------------------------------------------------------------
3356 // Climate Control Schedules
3357 //-----------------------------------------------------------------------------
3358 
3359 //-----------------------------------------------------------------------------
3360 // <Manager::GetNumSwitchPoints>
3361 // Get the number of switch points defined in a schedule
3362 //-----------------------------------------------------------------------------
GetNumSwitchPoints(ValueID const & _id)3363 uint8 Manager::GetNumSwitchPoints(ValueID const& _id)
3364 {
3365 	//	bool res = false;
3366 
3367 	uint8 numSwitchPoints = 0;
3368 	if (ValueID::ValueType_Schedule == _id.GetType())
3369 	{
3370 		if (Driver* driver = GetDriver(_id.GetHomeId()))
3371 		{
3372 			Internal::LockGuard LG(driver->m_nodeMutex);
3373 			if (Internal::VC::ValueSchedule* value = static_cast<Internal::VC::ValueSchedule*>(driver->GetValue(_id)))
3374 			{
3375 				numSwitchPoints = value->GetNumSwitchPoints();
3376 				value->Release();
3377 			}
3378 			else
3379 			{
3380 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetNumSwitchPoints");
3381 			}
3382 		}
3383 	}
3384 	else
3385 	{
3386 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetNumSwitchPoints is not a Schedule Value");
3387 	}
3388 
3389 	return numSwitchPoints;
3390 }
3391 
3392 //-----------------------------------------------------------------------------
3393 // <Manager::SetSwitchPoint>
3394 // Set a switch point in the schedule
3395 //-----------------------------------------------------------------------------
SetSwitchPoint(ValueID const & _id,uint8 const _hours,uint8 const _minutes,int8 const _setback)3396 bool Manager::SetSwitchPoint(ValueID const& _id, uint8 const _hours, uint8 const _minutes, int8 const _setback)
3397 {
3398 	bool res = false;
3399 
3400 	if (ValueID::ValueType_Schedule == _id.GetType())
3401 	{
3402 		if (Driver* driver = GetDriver(_id.GetHomeId()))
3403 		{
3404 			Internal::LockGuard LG(driver->m_nodeMutex);
3405 			if (Internal::VC::ValueSchedule* value = static_cast<Internal::VC::ValueSchedule*>(driver->GetValue(_id)))
3406 			{
3407 				res = value->SetSwitchPoint(_hours, _minutes, _setback);
3408 				value->Release();
3409 			}
3410 			else
3411 			{
3412 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to SetSwitchPoint");
3413 			}
3414 		}
3415 	}
3416 	else
3417 	{
3418 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to SetSwitchPoint is not a Schedule Value");
3419 	}
3420 
3421 	return res;
3422 }
3423 
3424 //-----------------------------------------------------------------------------
3425 // <Manager::RemoveSwitchPoint>
3426 // Remove a switch point from the schedule
3427 //-----------------------------------------------------------------------------
RemoveSwitchPoint(ValueID const & _id,uint8 const _hours,uint8 const _minutes)3428 bool Manager::RemoveSwitchPoint(ValueID const& _id, uint8 const _hours, uint8 const _minutes)
3429 {
3430 	bool res = false;
3431 
3432 	if (ValueID::ValueType_Schedule == _id.GetType())
3433 	{
3434 		if (Driver* driver = GetDriver(_id.GetHomeId()))
3435 		{
3436 			Internal::LockGuard LG(driver->m_nodeMutex);
3437 			if (Internal::VC::ValueSchedule* value = static_cast<Internal::VC::ValueSchedule*>(driver->GetValue(_id)))
3438 			{
3439 				uint8 idx;
3440 				res = value->FindSwitchPoint(_hours, _minutes, &idx);
3441 
3442 				if (res)
3443 				{
3444 					res = value->RemoveSwitchPoint(idx);
3445 				}
3446 				value->Release();
3447 			}
3448 			else
3449 			{
3450 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to RemoveSwitchPoint");
3451 			}
3452 		}
3453 	}
3454 	else
3455 	{
3456 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to RemoveSwitchPoint is not a Schedule Value");
3457 	}
3458 
3459 	return res;
3460 }
3461 
3462 //-----------------------------------------------------------------------------
3463 // <Manager::ClearSwitchPoints>
3464 // Clears all switch points from the schedule
3465 //-----------------------------------------------------------------------------
ClearSwitchPoints(ValueID const & _id)3466 void Manager::ClearSwitchPoints(ValueID const& _id)
3467 {
3468 	if (ValueID::ValueType_Schedule == _id.GetType())
3469 	{
3470 		if (Driver* driver = GetDriver(_id.GetHomeId()))
3471 		{
3472 			Internal::LockGuard LG(driver->m_nodeMutex);
3473 			if (Internal::VC::ValueSchedule* value = static_cast<Internal::VC::ValueSchedule*>(driver->GetValue(_id)))
3474 			{
3475 				value->ClearSwitchPoints();
3476 				value->Release();
3477 			}
3478 			else
3479 			{
3480 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to ClearSwitchPoints");
3481 			}
3482 		}
3483 	}
3484 	else
3485 	{
3486 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to ClearSwitchPoints is not a Schedule Value");
3487 	}
3488 }
3489 
3490 //-----------------------------------------------------------------------------
3491 // <Manager::GetSwitchPoint>
3492 // Gets switch point data from the schedule
3493 //-----------------------------------------------------------------------------
GetSwitchPoint(ValueID const & _id,uint8 const _idx,uint8 * o_hours,uint8 * o_minutes,int8 * o_setback)3494 bool Manager::GetSwitchPoint(ValueID const& _id, uint8 const _idx, uint8* o_hours, uint8* o_minutes, int8* o_setback)
3495 {
3496 	bool res = false;
3497 
3498 	if (ValueID::ValueType_Schedule == _id.GetType())
3499 	{
3500 		if (Driver* driver = GetDriver(_id.GetHomeId()))
3501 		{
3502 			Internal::LockGuard LG(driver->m_nodeMutex);
3503 			if (Internal::VC::ValueSchedule* value = static_cast<Internal::VC::ValueSchedule*>(driver->GetValue(_id)))
3504 			{
3505 				res = value->GetSwitchPoint(_idx, o_hours, o_minutes, o_setback);
3506 				value->Release();
3507 			}
3508 			else
3509 			{
3510 				OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetSwitchPoint");
3511 			}
3512 		}
3513 	}
3514 	else
3515 	{
3516 		OZW_ERROR(OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID, "ValueID passed to GetSwitchPoint is not a Schedule Value");
3517 	}
3518 
3519 	return res;
3520 }
3521 
3522 //-----------------------------------------------------------------------------
3523 //	SwitchAll
3524 //-----------------------------------------------------------------------------
3525 
3526 //-----------------------------------------------------------------------------
3527 // <Manager::SwitchAllOn>
3528 // All devices that support the SwitchAll command class will be turned on
3529 //-----------------------------------------------------------------------------
SwitchAllOn(uint32 const _homeId)3530 void Manager::SwitchAllOn(uint32 const _homeId)
3531 {
3532 	if (Driver* driver = GetDriver(_homeId))
3533 	{
3534 		return driver->SwitchAllOn();
3535 	}
3536 }
3537 
3538 //-----------------------------------------------------------------------------
3539 // <Manager::SwitchAllOff>
3540 // All devices that support the SwitchAll command class will be turned off
3541 //-----------------------------------------------------------------------------
SwitchAllOff(uint32 const _homeId)3542 void Manager::SwitchAllOff(uint32 const _homeId)
3543 {
3544 	if (Driver* driver = GetDriver(_homeId))
3545 	{
3546 		return driver->SwitchAllOff();
3547 	}
3548 }
3549 
3550 //-----------------------------------------------------------------------------
3551 //	Configuration Parameters
3552 //-----------------------------------------------------------------------------
3553 
3554 //-----------------------------------------------------------------------------
3555 // <Manager::SetConfigParam>
3556 // Set the value of one of the configuration parameters of a device
3557 //-----------------------------------------------------------------------------
SetConfigParam(uint32 const _homeId,uint8 const _nodeId,uint8 const _param,int32 _value,uint8 const _size)3558 bool Manager::SetConfigParam(uint32 const _homeId, uint8 const _nodeId, uint8 const _param, int32 _value, uint8 const _size)
3559 {
3560 	if (Driver* driver = GetDriver(_homeId))
3561 	{
3562 		return driver->SetConfigParam(_nodeId, _param, _value, _size);
3563 	}
3564 
3565 	return false;
3566 }
3567 
3568 //-----------------------------------------------------------------------------
3569 // <Manager::RequestConfigParam>
3570 // Request the value of one of the configuration parameters of a device
3571 //-----------------------------------------------------------------------------
RequestConfigParam(uint32 const _homeId,uint8 const _nodeId,uint8 const _param)3572 void Manager::RequestConfigParam(uint32 const _homeId, uint8 const _nodeId, uint8 const _param)
3573 {
3574 	if (Driver* driver = GetDriver(_homeId))
3575 	{
3576 		driver->RequestConfigParam(_nodeId, _param);
3577 	}
3578 }
3579 
3580 //-----------------------------------------------------------------------------
3581 // <Manager::RequestAllConfigParams>
3582 // Request the values of all of the known configuration parameters of a device
3583 //-----------------------------------------------------------------------------
RequestAllConfigParams(uint32 const _homeId,uint8 const _nodeId)3584 void Manager::RequestAllConfigParams(uint32 const _homeId, uint8 const _nodeId)
3585 {
3586 	if (Driver* driver = GetDriver(_homeId))
3587 	{
3588 		Internal::LockGuard LG(driver->m_nodeMutex);
3589 		Node* node = driver->GetNode(_nodeId);
3590 		if (node)
3591 		{
3592 			node->SetQueryStage(Node::QueryStage_Configuration);
3593 		}
3594 	}
3595 }
3596 
3597 //-----------------------------------------------------------------------------
3598 //	Groups
3599 //-----------------------------------------------------------------------------
3600 
3601 //-----------------------------------------------------------------------------
3602 // <Manager::GetNumGroups>
3603 // Gets the number of association groups reported by this node
3604 //-----------------------------------------------------------------------------
GetNumGroups(uint32 const _homeId,uint8 const _nodeId)3605 uint8 Manager::GetNumGroups(uint32 const _homeId, uint8 const _nodeId)
3606 {
3607 	if (Driver* driver = GetDriver(_homeId))
3608 	{
3609 		return driver->GetNumGroups(_nodeId);
3610 	}
3611 
3612 	return 0;
3613 }
3614 
3615 //-----------------------------------------------------------------------------
3616 // <Manager::GetAssociations>
3617 // Gets the associations for a group
3618 //-----------------------------------------------------------------------------
GetAssociations(uint32 const _homeId,uint8 const _nodeId,uint8 const _groupIdx,uint8 ** o_associations)3619 uint32 Manager::GetAssociations(uint32 const _homeId, uint8 const _nodeId, uint8 const _groupIdx, uint8** o_associations)
3620 {
3621 	if (Driver* driver = GetDriver(_homeId))
3622 	{
3623 		return driver->GetAssociations(_nodeId, _groupIdx, o_associations);
3624 	}
3625 
3626 	return 0;
3627 }
3628 
3629 //-----------------------------------------------------------------------------
3630 // <Manager::GetAssociations>
3631 // Gets the associations for a group
3632 // struct InstanceAssociation is defined in Group.h and contains
3633 // a (NodeID, End Point) pair.
3634 //-----------------------------------------------------------------------------
GetAssociations(uint32 const _homeId,uint8 const _nodeId,uint8 const _groupIdx,InstanceAssociation ** o_associations)3635 uint32 Manager::GetAssociations(uint32 const _homeId, uint8 const _nodeId, uint8 const _groupIdx, InstanceAssociation** o_associations)
3636 {
3637 	if (Driver* driver = GetDriver(_homeId))
3638 	{
3639 		return driver->GetAssociations(_nodeId, _groupIdx, o_associations);
3640 	}
3641 
3642 	return 0;
3643 }
3644 
3645 //-----------------------------------------------------------------------------
3646 // <Manager::GetMaxAssociations>
3647 // Gets the maximum number of associations for a group
3648 //-----------------------------------------------------------------------------
GetMaxAssociations(uint32 const _homeId,uint8 const _nodeId,uint8 const _groupIdx)3649 uint8 Manager::GetMaxAssociations(uint32 const _homeId, uint8 const _nodeId, uint8 const _groupIdx)
3650 {
3651 	if (Driver* driver = GetDriver(_homeId))
3652 	{
3653 		return driver->GetMaxAssociations(_nodeId, _groupIdx);
3654 	}
3655 
3656 	return 0;
3657 }
3658 
3659 //-----------------------------------------------------------------------------
3660 // <Manager::IsMultiInstance>
3661 // Returns true is group supports multi instance.
3662 //-----------------------------------------------------------------------------
IsMultiInstance(uint32 const _homeId,uint8 const _nodeId,uint8 const _groupIdx)3663 bool Manager::IsMultiInstance(uint32 const _homeId, uint8 const _nodeId, uint8 const _groupIdx)
3664 {
3665 	if (Driver* driver = GetDriver(_homeId))
3666 	{
3667 		return driver->IsMultiInstance(_nodeId, _groupIdx);
3668 	}
3669 	return 0;
3670 }
3671 
3672 //-----------------------------------------------------------------------------
3673 // <Manager::GetGroupLabel>
3674 // Gets the label for a particular group
3675 //-----------------------------------------------------------------------------
GetGroupLabel(uint32 const _homeId,uint8 const _nodeId,uint8 const _groupIdx)3676 string Manager::GetGroupLabel(uint32 const _homeId, uint8 const _nodeId, uint8 const _groupIdx)
3677 {
3678 	if (Driver* driver = GetDriver(_homeId))
3679 	{
3680 		return driver->GetGroupLabel(_nodeId, _groupIdx);
3681 	}
3682 
3683 	return "";
3684 }
3685 
3686 //-----------------------------------------------------------------------------
3687 // <Manager::AddAssociation>
3688 // Adds a node to an association group
3689 //-----------------------------------------------------------------------------
AddAssociation(uint32 const _homeId,uint8 const _nodeId,uint8 const _groupIdx,uint8 const _targetNodeId,uint8 const _endPoint)3690 void Manager::AddAssociation(uint32 const _homeId, uint8 const _nodeId, uint8 const _groupIdx, uint8 const _targetNodeId, uint8 const _endPoint)
3691 {
3692 	if (Driver* driver = GetDriver(_homeId))
3693 	{
3694 		driver->AddAssociation(_nodeId, _groupIdx, _targetNodeId, _endPoint);
3695 	}
3696 }
3697 
3698 //-----------------------------------------------------------------------------
3699 // <Manager::RemoveAssociation>
3700 // Removes a node from an association group
3701 //-----------------------------------------------------------------------------
RemoveAssociation(uint32 const _homeId,uint8 const _nodeId,uint8 const _groupIdx,uint8 const _targetNodeId,uint8 const _endPoint)3702 void Manager::RemoveAssociation(uint32 const _homeId, uint8 const _nodeId, uint8 const _groupIdx, uint8 const _targetNodeId, uint8 const _endPoint)
3703 {
3704 	if (Driver* driver = GetDriver(_homeId))
3705 	{
3706 		driver->RemoveAssociation(_nodeId, _groupIdx, _targetNodeId, _endPoint);
3707 	}
3708 }
3709 
3710 //-----------------------------------------------------------------------------
3711 //	Notifications
3712 //-----------------------------------------------------------------------------
3713 
3714 //-----------------------------------------------------------------------------
3715 // <Manager::AddWatcher>
3716 // Add a watcher to the list
3717 //-----------------------------------------------------------------------------
AddWatcher(pfnOnNotification_t _watcher,void * _context)3718 bool Manager::AddWatcher(pfnOnNotification_t _watcher, void* _context)
3719 {
3720 	// Ensure this watcher is not already on the list
3721 	m_notificationMutex->Lock();
3722 	for (list<Watcher*>::iterator it = m_watchers.begin(); it != m_watchers.end(); ++it)
3723 	{
3724 		if (((*it)->m_callback == _watcher) && ((*it)->m_context == _context))
3725 		{
3726 			// Already in the list
3727 			m_notificationMutex->Unlock();
3728 			return false;
3729 		}
3730 	}
3731 
3732 	m_watchers.push_back(new Watcher(_watcher, _context));
3733 	m_notificationMutex->Unlock();
3734 	return true;
3735 }
3736 
3737 //-----------------------------------------------------------------------------
3738 // <Manager::RemoveWatcher>
3739 // Remove a watcher from the list
3740 //-----------------------------------------------------------------------------
RemoveWatcher(pfnOnNotification_t _watcher,void * _context)3741 bool Manager::RemoveWatcher(pfnOnNotification_t _watcher, void* _context)
3742 {
3743 	m_notificationMutex->Lock();
3744 	list<Watcher*>::iterator it = m_watchers.begin();
3745 	while (it != m_watchers.end())
3746 	{
3747 		if (((*it)->m_callback == _watcher) && ((*it)->m_context == _context))
3748 		{
3749 			delete (*it);
3750 			list<Watcher*>::iterator next = m_watchers.erase(it);
3751 			for (list<list<Watcher*>::iterator*>::iterator extIt = m_watcherIterators.begin(); extIt != m_watcherIterators.end(); ++extIt)
3752 			{
3753 				if ((**extIt) == it)
3754 				{
3755 					(**extIt) = next;
3756 				}
3757 			}
3758 			m_notificationMutex->Unlock();
3759 			return true;
3760 		}
3761 		++it;
3762 	}
3763 
3764 	m_notificationMutex->Unlock();
3765 	return false;
3766 }
3767 
3768 //-----------------------------------------------------------------------------
3769 // <Manager::NotifyWatchers>
3770 // Notify any watching objects of a value change
3771 //-----------------------------------------------------------------------------
NotifyWatchers(Notification * _notification)3772 void Manager::NotifyWatchers(Notification* _notification)
3773 {
3774 	m_notificationMutex->Lock();
3775 	list<Watcher*>::iterator it = m_watchers.begin();
3776 	m_watcherIterators.push_back(&it);
3777 	while (it != m_watchers.end())
3778 	{
3779 		Watcher* pWatcher = *(it++);
3780 		pWatcher->m_callback(_notification, pWatcher->m_context);
3781 	}
3782 	m_watcherIterators.pop_back();
3783 	m_notificationMutex->Unlock();
3784 }
3785 
3786 //-----------------------------------------------------------------------------
3787 //	Controller commands
3788 //-----------------------------------------------------------------------------
3789 
3790 //-----------------------------------------------------------------------------
3791 // <Manager::ResetController>
3792 // Reset controller and erase all node information
3793 //-----------------------------------------------------------------------------
ResetController(uint32 const _homeId)3794 void Manager::ResetController(uint32 const _homeId)
3795 {
3796 	if (Driver* driver = GetDriver(_homeId))
3797 	{
3798 		Internal::Platform::Event *event = new Internal::Platform::Event();
3799 		driver->ResetController(event);
3800 		Internal::Platform::Wait::Single(event);
3801 		event->Release();
3802 		string path = driver->GetControllerPath();
3803 		Driver::ControllerInterface intf = driver->GetControllerInterfaceType();
3804 		RemoveDriver(path);
3805 		AddDriver(path, intf);
3806 		Internal::Platform::Wait::Multiple( NULL, 0, 500);
3807 	} OPENZWAVE_DEPRECATED_WARNINGS_OFF;
3808 	RemoveAllScenes(_homeId);
3809 	OPENZWAVE_DEPRECATED_WARNINGS_ON;
3810 }
3811 
3812 //-----------------------------------------------------------------------------
3813 // <Manager::SoftReset>
3814 // Soft-reset the Z-Wave controller chip
3815 //-----------------------------------------------------------------------------
SoftReset(uint32 const _homeId)3816 void Manager::SoftReset(uint32 const _homeId)
3817 {
3818 	if (Driver* driver = GetDriver(_homeId))
3819 	{
3820 		driver->SoftReset();
3821 	}
3822 }
3823 
3824 //-----------------------------------------------------------------------------
3825 // <Manager::BeginControllerCommand>
3826 // Start the controller performing one of its network management functions
3827 //-----------------------------------------------------------------------------
BeginControllerCommand(uint32 const _homeId,Driver::ControllerCommand _command,Driver::pfnControllerCallback_t _callback,void * _context,bool _highPower,uint8 _nodeId,uint8 _arg)3828 bool Manager::BeginControllerCommand(uint32 const _homeId, Driver::ControllerCommand _command, Driver::pfnControllerCallback_t _callback,				// = NULL
3829 		void* _context,								// = NULL
3830 		bool _highPower,							// = false
3831 		uint8 _nodeId,								// = 0xff
3832 		uint8 _arg								// = 0
3833 		)
3834 {
3835 	if (Driver* driver = GetDriver(_homeId))
3836 	{
3837 		return driver->BeginControllerCommand(_command, _callback, _context, _highPower, _nodeId, _arg);
3838 	}
3839 
3840 	return false;
3841 }
3842 
3843 //-----------------------------------------------------------------------------
3844 // <Manager::CancelControllerCommand>
3845 // Stop the current controller function
3846 //-----------------------------------------------------------------------------
CancelControllerCommand(uint32 const _homeId)3847 bool Manager::CancelControllerCommand(uint32 const _homeId)
3848 {
3849 	if (Driver* driver = GetDriver(_homeId))
3850 	{
3851 		return (driver->CancelControllerCommand());
3852 	}
3853 
3854 	return false;
3855 }
3856 
3857 //-----------------------------------------------------------------------------
3858 // <Manager::TestNetworkNode>
3859 // Send a number of test messages to a node and record results.
3860 //-----------------------------------------------------------------------------
TestNetworkNode(uint32 const _homeId,uint8 const _nodeId,uint32 const _count)3861 void Manager::TestNetworkNode(uint32 const _homeId, uint8 const _nodeId, uint32 const _count)
3862 {
3863 	if (Driver* driver = GetDriver(_homeId))
3864 	{
3865 		driver->TestNetwork(_nodeId, _count);
3866 	}
3867 }
3868 
3869 //-----------------------------------------------------------------------------
3870 // <Manager::TestNetwork>
3871 // Send a number of test messages to every node and record results.
3872 //-----------------------------------------------------------------------------
TestNetwork(uint32 const _homeId,uint32 const _count)3873 void Manager::TestNetwork(uint32 const _homeId, uint32 const _count)
3874 {
3875 	if (Driver* driver = GetDriver(_homeId))
3876 	{
3877 		driver->TestNetwork(0, _count);
3878 	}
3879 }
3880 
3881 //-----------------------------------------------------------------------------
3882 // <Manager::HealNetworkNode>
3883 // Heal a single node in the network
3884 //-----------------------------------------------------------------------------
HealNetworkNode(uint32 const _homeId,uint8 const _nodeId,bool _doRR)3885 void Manager::HealNetworkNode(uint32 const _homeId, uint8 const _nodeId, bool _doRR)
3886 {
3887 	if (Driver* driver = GetDriver(_homeId))
3888 	{
3889 		Internal::LockGuard LG(driver->m_nodeMutex);
3890 		Node* node = driver->GetNode(_nodeId);
3891 		if (node)
3892 		{
3893 			driver->BeginControllerCommand(Driver::ControllerCommand_RequestNodeNeighborUpdate, NULL, NULL, true, _nodeId, 0);
3894 			if (_doRR)
3895 			{
3896 				driver->UpdateNodeRoutes(_nodeId, true);
3897 			}
3898 		}
3899 	}
3900 }
3901 
3902 //-----------------------------------------------------------------------------
3903 // <Manager::HealNetwork>
3904 // Heal the Z-Wave network one node at a time.
3905 //-----------------------------------------------------------------------------
HealNetwork(uint32 const _homeId,bool _doRR)3906 void Manager::HealNetwork(uint32 const _homeId, bool _doRR)
3907 {
3908 	if (Driver* driver = GetDriver(_homeId))
3909 	{
3910 		Internal::LockGuard LG(driver->m_nodeMutex);
3911 		for (uint8 i = 0; i < 255; i++)
3912 		{
3913 			if (driver->m_nodes[i] != NULL)
3914 			{
3915 				driver->BeginControllerCommand(Driver::ControllerCommand_RequestNodeNeighborUpdate, NULL, NULL, true, i, 0);
3916 				if (_doRR)
3917 				{
3918 					driver->UpdateNodeRoutes(i, true);
3919 				}
3920 			}
3921 		}
3922 	}
3923 }
3924 //-----------------------------------------------------------------------------
3925 // <Manager::AddNode>
3926 // Add a Device to the Network.
3927 //-----------------------------------------------------------------------------
AddNode(uint32 const _homeId,bool _doSecurity)3928 bool Manager::AddNode(uint32 const _homeId, bool _doSecurity)
3929 {
3930 	if (Driver *driver = GetDriver(_homeId))
3931 	{
3932 		Internal::LockGuard LG(driver->m_nodeMutex);
3933 		/* we use the Args option to communicate if Security CC should be initialized */
3934 		return driver->BeginControllerCommand(Driver::ControllerCommand_AddDevice,
3935 		NULL, NULL, true, 0, (_doSecurity == true ? 1 : 0));
3936 	}
3937 	return false;
3938 }
3939 
3940 //-----------------------------------------------------------------------------
3941 // <Manager::RemoveNode>
3942 // Remove a Device from the Network.
3943 //-----------------------------------------------------------------------------
RemoveNode(uint32 const _homeId)3944 bool Manager::RemoveNode(uint32 const _homeId)
3945 {
3946 	if (Driver *driver = GetDriver(_homeId))
3947 	{
3948 		Internal::LockGuard LG(driver->m_nodeMutex);
3949 		return driver->BeginControllerCommand(Driver::ControllerCommand_RemoveDevice,
3950 		NULL, NULL, true, 0, 0);
3951 	}
3952 	return false;
3953 }
3954 
3955 //-----------------------------------------------------------------------------
3956 // <Manager::RemoveFailedNode>
3957 // Remove a Specific Device from the network if its non-responsive.
3958 //-----------------------------------------------------------------------------
RemoveFailedNode(uint32 const _homeId,uint8 const _nodeId)3959 bool Manager::RemoveFailedNode(uint32 const _homeId, uint8 const _nodeId)
3960 {
3961 	if (Driver *driver = GetDriver(_homeId))
3962 	{
3963 		Internal::LockGuard LG(driver->m_nodeMutex);
3964 		return driver->BeginControllerCommand(Driver::ControllerCommand_RemoveFailedNode,
3965 		NULL, NULL, true, _nodeId, 0);
3966 	}
3967 	return false;
3968 }
3969 
3970 //-----------------------------------------------------------------------------
3971 // <Manager::HasNodeFailed>
3972 // Test if the Controller Believes the Node has Failed.
3973 //-----------------------------------------------------------------------------
HasNodeFailed(uint32 const _homeId,uint8 const _nodeId)3974 bool Manager::HasNodeFailed(uint32 const _homeId, uint8 const _nodeId)
3975 {
3976 	if (Driver *driver = GetDriver(_homeId))
3977 	{
3978 		Internal::LockGuard LG(driver->m_nodeMutex);
3979 		return driver->BeginControllerCommand(Driver::ControllerCommand_HasNodeFailed,
3980 		NULL, NULL, true, _nodeId, 0);
3981 	}
3982 	return false;
3983 }
3984 
3985 //-----------------------------------------------------------------------------
3986 // <Manager::AssignReturnRoute>
3987 // Ask a Node to update its Return Route to the Controller
3988 //-----------------------------------------------------------------------------
AssignReturnRoute(uint32 const _homeId,uint8 const _nodeId)3989 bool Manager::AssignReturnRoute(uint32 const _homeId, uint8 const _nodeId)
3990 {
3991 	if (Driver *driver = GetDriver(_homeId))
3992 	{
3993 		Internal::LockGuard LG(driver->m_nodeMutex);
3994 		return driver->BeginControllerCommand(Driver::ControllerCommand_AssignReturnRoute,
3995 		NULL, NULL, true, _nodeId, 0);
3996 	}
3997 	return false;
3998 }
3999 
4000 //-----------------------------------------------------------------------------
4001 // <Manager::RequestNodeNeighborUpdate>
4002 // Ask a Node to update its Neighbor Table.
4003 //-----------------------------------------------------------------------------
RequestNodeNeighborUpdate(uint32 const _homeId,uint8 const _nodeId)4004 bool Manager::RequestNodeNeighborUpdate(uint32 const _homeId, uint8 const _nodeId)
4005 {
4006 	if (Driver *driver = GetDriver(_homeId))
4007 	{
4008 		Internal::LockGuard LG(driver->m_nodeMutex);
4009 		return driver->BeginControllerCommand(Driver::ControllerCommand_RequestNodeNeighborUpdate,
4010 		NULL, NULL, true, _nodeId, 0);
4011 	}
4012 	return false;
4013 }
4014 
4015 //-----------------------------------------------------------------------------
4016 // <Manager::DeleteAllReturnRoutes>
4017 // Ask a Node to delete all its Return Routes
4018 //-----------------------------------------------------------------------------
DeleteAllReturnRoutes(uint32 const _homeId,uint8 const _nodeId)4019 bool Manager::DeleteAllReturnRoutes(uint32 const _homeId, uint8 const _nodeId)
4020 {
4021 	if (Driver *driver = GetDriver(_homeId))
4022 	{
4023 		Internal::LockGuard LG(driver->m_nodeMutex);
4024 		return driver->BeginControllerCommand(Driver::ControllerCommand_DeleteAllReturnRoutes,
4025 		NULL, NULL, true, _nodeId, 0);
4026 	}
4027 	return false;
4028 }
4029 
4030 //-----------------------------------------------------------------------------
4031 // <Manager::SendNodeInformation>
4032 // Send a NIF frame from the Controller to the Node
4033 //-----------------------------------------------------------------------------
SendNodeInformation(uint32 const _homeId,uint8 const _nodeId)4034 bool Manager::SendNodeInformation(uint32 const _homeId, uint8 const _nodeId)
4035 {
4036 	if (Driver *driver = GetDriver(_homeId))
4037 	{
4038 		Internal::LockGuard LG(driver->m_nodeMutex);
4039 		return driver->BeginControllerCommand(Driver::ControllerCommand_SendNodeInformation,
4040 		NULL, NULL, true, _nodeId, 0);
4041 	}
4042 	return false;
4043 }
4044 
4045 //-----------------------------------------------------------------------------
4046 // <Manager::CreateNewPrimary>
4047 // Send a NIF frame from the Controller to the Node
4048 //-----------------------------------------------------------------------------
CreateNewPrimary(uint32 const _homeId)4049 bool Manager::CreateNewPrimary(uint32 const _homeId)
4050 {
4051 	if (Driver *driver = GetDriver(_homeId))
4052 	{
4053 		Internal::LockGuard LG(driver->m_nodeMutex);
4054 		return driver->BeginControllerCommand(Driver::ControllerCommand_CreateNewPrimary,
4055 		NULL, NULL, true, 0, 0);
4056 	}
4057 	return false;
4058 }
4059 
4060 //-----------------------------------------------------------------------------
4061 // <Manager::ReceiveConfiguration>
4062 // Send a NIF frame from the Controller to the Node
4063 //-----------------------------------------------------------------------------
ReceiveConfiguration(uint32 const _homeId)4064 bool Manager::ReceiveConfiguration(uint32 const _homeId)
4065 {
4066 	if (Driver *driver = GetDriver(_homeId))
4067 	{
4068 		Internal::LockGuard LG(driver->m_nodeMutex);
4069 		return driver->BeginControllerCommand(Driver::ControllerCommand_ReceiveConfiguration,
4070 		NULL, NULL, true, 0, 0);
4071 	}
4072 	return false;
4073 }
4074 
4075 //-----------------------------------------------------------------------------
4076 // <Manager::ReplaceFailedNode>
4077 // Send a NIF frame from the Controller to the Node
4078 //-----------------------------------------------------------------------------
ReplaceFailedNode(uint32 const _homeId,uint8 const _nodeId)4079 bool Manager::ReplaceFailedNode(uint32 const _homeId, uint8 const _nodeId)
4080 {
4081 	if (Driver *driver = GetDriver(_homeId))
4082 	{
4083 		Internal::LockGuard LG(driver->m_nodeMutex);
4084 		return driver->BeginControllerCommand(Driver::ControllerCommand_ReplaceFailedNode,
4085 		NULL, NULL, true, _nodeId, 0);
4086 	}
4087 	return false;
4088 }
4089 
4090 //-----------------------------------------------------------------------------
4091 // <Manager::TransferPrimaryRole>
4092 // Send a NIF frame from the Controller to the Node
4093 //-----------------------------------------------------------------------------
TransferPrimaryRole(uint32 const _homeId)4094 bool Manager::TransferPrimaryRole(uint32 const _homeId)
4095 {
4096 	if (Driver *driver = GetDriver(_homeId))
4097 	{
4098 		Internal::LockGuard LG(driver->m_nodeMutex);
4099 		return driver->BeginControllerCommand(Driver::ControllerCommand_TransferPrimaryRole,
4100 		NULL, NULL, true, 0, 0);
4101 	}
4102 	return false;
4103 }
4104 
4105 //-----------------------------------------------------------------------------
4106 // <Manager::RequestNetworkUpdate>
4107 // Send a NIF frame from the Controller to the Node
4108 //-----------------------------------------------------------------------------
RequestNetworkUpdate(uint32 const _homeId,uint8 const _nodeId)4109 bool Manager::RequestNetworkUpdate(uint32 const _homeId, uint8 const _nodeId)
4110 {
4111 	if (Driver *driver = GetDriver(_homeId))
4112 	{
4113 		Internal::LockGuard LG(driver->m_nodeMutex);
4114 		return driver->BeginControllerCommand(Driver::ControllerCommand_RequestNetworkUpdate,
4115 		NULL, NULL, true, _nodeId, 0);
4116 	}
4117 	return false;
4118 }
4119 
4120 //-----------------------------------------------------------------------------
4121 // <Manager::ReplicationSend>
4122 // Send a NIF frame from the Controller to the Node
4123 //-----------------------------------------------------------------------------
ReplicationSend(uint32 const _homeId,uint8 const _nodeId)4124 bool Manager::ReplicationSend(uint32 const _homeId, uint8 const _nodeId)
4125 {
4126 	if (Driver *driver = GetDriver(_homeId))
4127 	{
4128 		Internal::LockGuard LG(driver->m_nodeMutex);
4129 		return driver->BeginControllerCommand(Driver::ControllerCommand_ReplicationSend,
4130 		NULL, NULL, true, _nodeId, 0);
4131 	}
4132 	return false;
4133 }
4134 
4135 //-----------------------------------------------------------------------------
4136 // <Manager::CreateButton>
4137 // Send a NIF frame from the Controller to the Node
4138 //-----------------------------------------------------------------------------
CreateButton(uint32 const _homeId,uint8 const _nodeId,uint8 const _buttonid)4139 bool Manager::CreateButton(uint32 const _homeId, uint8 const _nodeId, uint8 const _buttonid)
4140 {
4141 	if (Driver *driver = GetDriver(_homeId))
4142 	{
4143 		Internal::LockGuard LG(driver->m_nodeMutex);
4144 		return driver->BeginControllerCommand(Driver::ControllerCommand_CreateButton,
4145 		NULL, NULL, true, _nodeId, _buttonid);
4146 	}
4147 	return false;
4148 }
4149 
4150 //-----------------------------------------------------------------------------
4151 // <Manager::DeleteButton>
4152 // Send a NIF frame from the Controller to the Node
4153 //-----------------------------------------------------------------------------
DeleteButton(uint32 const _homeId,uint8 const _nodeId,uint8 const _buttonid)4154 bool Manager::DeleteButton(uint32 const _homeId, uint8 const _nodeId, uint8 const _buttonid)
4155 {
4156 	if (Driver *driver = GetDriver(_homeId))
4157 	{
4158 		Internal::LockGuard LG(driver->m_nodeMutex);
4159 		return driver->BeginControllerCommand(Driver::ControllerCommand_DeleteButton,
4160 		NULL, NULL, true, _nodeId, _buttonid);
4161 	}
4162 	return false;
4163 }
4164 
4165 //-----------------------------------------------------------------------------
4166 // <Manager::SendRawData>
4167 // Send a custom message to a node.
4168 // XXX TODO - Move the implementation to the Driver Class
4169 //-----------------------------------------------------------------------------
SendRawData(uint32 const _homeId,uint8 const _nodeId,string const & _logText,uint8 const _msgType,bool const _sendSecure,uint8 const * _content,uint8 const _length)4170 void Manager::SendRawData(uint32 const _homeId, uint8 const _nodeId, string const& _logText, uint8 const _msgType, bool const _sendSecure, uint8 const* _content, uint8 const _length)
4171 {
4172 	if (Driver *driver = GetDriver(_homeId))
4173 	{
4174 		Internal::LockGuard LG(driver->m_nodeMutex);
4175 		Node* node = driver->GetNode(_nodeId);
4176 		if (node)
4177 		{
4178 			Internal::Msg* msg = new Internal::Msg(_logText, _nodeId, _msgType, FUNC_ID_ZW_SEND_DATA, true);
4179 			for (uint8 i = 0; i < _length; i++)
4180 			{
4181 				msg->Append(_content[i]);
4182 			}
4183 			msg->Append(driver->GetTransmitOptions());
4184 			if (_sendSecure)
4185 			{
4186 				msg->setEncrypted();
4187 			}
4188 			driver->SendMsg(msg, Driver::MsgQueue_Send);
4189 		}
4190 	}
4191 }
4192 
4193 //-----------------------------------------------------------------------------
4194 // <Manager::GetNumScenes>
4195 // Return the number of defined scenes.
4196 //-----------------------------------------------------------------------------
GetNumScenes()4197 uint8 Manager::GetNumScenes()
4198 {
4199 	return Internal::Scene::s_sceneCnt;
4200 }
4201 
4202 //-----------------------------------------------------------------------------
4203 // <Manager::GetAllScenes>
4204 // Return an array of all Scene Ids
4205 //-----------------------------------------------------------------------------
GetAllScenes(uint8 ** _sceneIds)4206 uint8 Manager::GetAllScenes(uint8** _sceneIds)
4207 {
4208 	*_sceneIds = NULL;
4209 	return Internal::Scene::GetAllScenes(_sceneIds);
4210 }
4211 
4212 //-----------------------------------------------------------------------------
4213 // <Manager::RemoveAllScenes>
4214 // Remove every scene id
4215 //-----------------------------------------------------------------------------
RemoveAllScenes(uint32 const _homeId)4216 void Manager::RemoveAllScenes(uint32 const _homeId)
4217 {
4218 	for (int i = 1; i < 256; i++)
4219 	{
4220 		if (_homeId == 0)	// remove every device from every scene
4221 		{
4222 			OPENZWAVE_DEPRECATED_WARNINGS_OFF
4223 			RemoveScene(i);
4224 		OPENZWAVE_DEPRECATED_WARNINGS_ON
4225 	}
4226 	else
4227 	{
4228 		Internal::Scene *scene = Internal::Scene::Get(i);
4229 		if (scene != NULL)
4230 		{
4231 			scene->RemoveValues(_homeId);
4232 		}
4233 	}
4234 }
4235 }
4236 
4237 //-----------------------------------------------------------------------------
4238 // <Manager::CreateScene>
4239 // Create a new scene and return new Scene ID.
4240 //-----------------------------------------------------------------------------
CreateScene()4241 uint8 Manager::CreateScene()
4242 {
4243 for (int i = 1; i < 256; i++)
4244 {
4245 	Internal::Scene* scene = Internal::Scene::Get(i);
4246 	if (scene != NULL)
4247 	{
4248 		continue;
4249 	}
4250 	new Internal::Scene(i);
4251 	return i;
4252 }
4253 return 0;
4254 }
4255 
4256 //-----------------------------------------------------------------------------
4257 // <Manager::RemoveScene>
4258 // Remove scene and delete its contents
4259 //-----------------------------------------------------------------------------
RemoveScene(uint8 const _sceneId)4260 bool Manager::RemoveScene(uint8 const _sceneId)
4261 {
4262 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4263 if (scene != NULL)
4264 {
4265 	delete scene;
4266 	return true;
4267 }
4268 return false;
4269 }
4270 
4271 //-----------------------------------------------------------------------------
4272 // <Manager::AddSceneValue>
4273 // Add a bool ValueID/value pair to the scene
4274 //-----------------------------------------------------------------------------
AddSceneValue(uint8 const _sceneId,ValueID const & _valueId,bool const _value)4275 bool Manager::AddSceneValue(uint8 const _sceneId, ValueID const& _valueId, bool const _value)
4276 {
4277 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4278 if (scene != NULL)
4279 {
4280 	return scene->AddValue(_valueId, _value ? "True" : "False");
4281 }
4282 return false;
4283 }
4284 
4285 //-----------------------------------------------------------------------------
4286 // <Manager::AddSceneValue>
4287 // Add a byte ValueID/value pair to the scene
4288 //-----------------------------------------------------------------------------
AddSceneValue(uint8 const _sceneId,ValueID const & _valueId,uint8 const _value)4289 bool Manager::AddSceneValue(uint8 const _sceneId, ValueID const& _valueId, uint8 const _value)
4290 {
4291 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4292 if (scene != NULL)
4293 {
4294 	char str[16];
4295 	snprintf(str, sizeof(str), "%d", _value);
4296 	return scene->AddValue(_valueId, str);
4297 }
4298 return false;
4299 }
4300 
4301 //-----------------------------------------------------------------------------
4302 // <Manager::AddSceneValue>
4303 // Add a decimal ValueID/value pair to the scene
4304 //-----------------------------------------------------------------------------
AddSceneValue(uint8 const _sceneId,ValueID const & _valueId,float const _value)4305 bool Manager::AddSceneValue(uint8 const _sceneId, ValueID const& _valueId, float const _value)
4306 {
4307 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4308 if (scene != NULL)
4309 {
4310 	char str[16];
4311 	snprintf(str, sizeof(str), "%f", _value);
4312 	return scene->AddValue(_valueId, str);
4313 }
4314 return false;
4315 }
4316 
4317 //-----------------------------------------------------------------------------
4318 // <Manager::AddSceneValue>
4319 // Add an integer ValueID/value pair to the scene
4320 //-----------------------------------------------------------------------------
AddSceneValue(uint8 const _sceneId,ValueID const & _valueId,int32 const _value)4321 bool Manager::AddSceneValue(uint8 const _sceneId, ValueID const& _valueId, int32 const _value)
4322 {
4323 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4324 if (scene != NULL)
4325 {
4326 	char str[16];
4327 	snprintf(str, sizeof(str), "%d", _value);
4328 	return scene->AddValue(_valueId, str);
4329 }
4330 return false;
4331 }
4332 
4333 //-----------------------------------------------------------------------------
4334 // <Manager::AddSceneValue>
4335 // Add a short ValueID/value pair to the scene
4336 //-----------------------------------------------------------------------------
AddSceneValue(uint8 const _sceneId,ValueID const & _valueId,int16 const _value)4337 bool Manager::AddSceneValue(uint8 const _sceneId, ValueID const& _valueId, int16 const _value)
4338 {
4339 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4340 if (scene != NULL)
4341 {
4342 	char str[16];
4343 	snprintf(str, sizeof(str), "%d", _value);
4344 	return scene->AddValue(_valueId, str);
4345 }
4346 return false;
4347 }
4348 
4349 //-----------------------------------------------------------------------------
4350 // <Manager::AddSceneValue>
4351 // Add a string ValueID/value pair to the scene
4352 //-----------------------------------------------------------------------------
AddSceneValue(uint8 const _sceneId,ValueID const & _valueId,string const & _value)4353 bool Manager::AddSceneValue(uint8 const _sceneId, ValueID const& _valueId, string const& _value)
4354 {
4355 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4356 if (scene != NULL)
4357 {
4358 	return scene->AddValue(_valueId, _value);
4359 }
4360 return false;
4361 }
4362 
4363 //-----------------------------------------------------------------------------
4364 // <Manager::AddSceneValueListSelection>
4365 // Add a list selection item ValueID/value pair to the scene (as string)
4366 //-----------------------------------------------------------------------------
AddSceneValueListSelection(uint8 const _sceneId,ValueID const & _valueId,string const & _value)4367 bool Manager::AddSceneValueListSelection(uint8 const _sceneId, ValueID const& _valueId, string const& _value)
4368 {
4369 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4370 if (scene != NULL)
4371 {
4372 	return scene->AddValue(_valueId, _value);
4373 }
4374 return false;
4375 }
4376 
4377 //-----------------------------------------------------------------------------
4378 // <Manager::AddSceneValueListSelection>
4379 // Add a list selection item ValueID/value pair to the scene (as integer)
4380 //-----------------------------------------------------------------------------
AddSceneValueListSelection(uint8 const _sceneId,ValueID const & _valueId,int32 const _value)4381 bool Manager::AddSceneValueListSelection(uint8 const _sceneId, ValueID const& _valueId, int32 const _value)
4382 {
4383 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4384 if (scene != NULL)
4385 {
4386 	char str[16];
4387 	snprintf(str, sizeof(str), "%d", _value);
4388 	return scene->AddValue(_valueId, str);
4389 }
4390 return false;
4391 }
4392 
4393 //-----------------------------------------------------------------------------
4394 // <Manager::RemoveSceneValue>
4395 // Remove a ValueID/value pair from the scene
4396 //-----------------------------------------------------------------------------
RemoveSceneValue(uint8 const _sceneId,ValueID const & _valueId)4397 bool Manager::RemoveSceneValue(uint8 const _sceneId, ValueID const& _valueId)
4398 {
4399 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4400 if (scene != NULL)
4401 {
4402 	return scene->RemoveValue(_valueId);
4403 }
4404 return false;
4405 }
4406 
4407 //-----------------------------------------------------------------------------
4408 // <Manager::SceneGetValues>
4409 // Return a scene's Value ID
4410 //-----------------------------------------------------------------------------
SceneGetValues(uint8 const _sceneId,vector<ValueID> * o_value)4411 int Manager::SceneGetValues(uint8 const _sceneId, vector<ValueID>* o_value)
4412 {
4413 o_value->clear();
4414 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4415 if (scene != NULL)
4416 {
4417 	return scene->GetValues(o_value);
4418 }
4419 return 0;
4420 }
4421 
4422 //-----------------------------------------------------------------------------
4423 // <Manager::SceneGetValueAsBool>
4424 // Return a scene's Value ID bool value
4425 //-----------------------------------------------------------------------------
SceneGetValueAsBool(uint8 const _sceneId,ValueID const & _valueId,bool * o_value)4426 bool Manager::SceneGetValueAsBool(uint8 const _sceneId, ValueID const& _valueId, bool* o_value)
4427 {
4428 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4429 if (scene != NULL)
4430 {
4431 	string str;
4432 	if (scene->GetValue(_valueId, &str))
4433 	{
4434 		*o_value = !strcasecmp("true", str.c_str());
4435 		return true;
4436 	}
4437 }
4438 return false;
4439 }
4440 
4441 //-----------------------------------------------------------------------------
4442 // <Manager::SceneGetValueAsByte>
4443 // Return a scene's Value ID byte value
4444 //-----------------------------------------------------------------------------
SceneGetValueAsByte(uint8 const _sceneId,ValueID const & _valueId,uint8 * o_value)4445 bool Manager::SceneGetValueAsByte(uint8 const _sceneId, ValueID const& _valueId, uint8* o_value)
4446 {
4447 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4448 if (scene != NULL)
4449 {
4450 	string str;
4451 	if (scene->GetValue(_valueId, &str))
4452 	{
4453 		*o_value = (uint8) atoi(str.c_str());
4454 		return true;
4455 	}
4456 }
4457 return false;
4458 }
4459 
4460 //-----------------------------------------------------------------------------
4461 // <Manager::SceneGetValueAsFloat>
4462 // Return a scene's Value ID float value
4463 //-----------------------------------------------------------------------------
SceneGetValueAsFloat(uint8 const _sceneId,ValueID const & _valueId,float * o_value)4464 bool Manager::SceneGetValueAsFloat(uint8 const _sceneId, ValueID const& _valueId, float* o_value)
4465 {
4466 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4467 if (scene != NULL)
4468 {
4469 	string str;
4470 	if (scene->GetValue(_valueId, &str))
4471 	{
4472 		*o_value = (float) atof(str.c_str());
4473 		return true;
4474 	}
4475 }
4476 return false;
4477 }
4478 
4479 //-----------------------------------------------------------------------------
4480 // <Manager::SceneGetValueAsInt>
4481 // Return a scene's Value ID integer value
4482 //-----------------------------------------------------------------------------
SceneGetValueAsInt(uint8 const _sceneId,ValueID const & _valueId,int32 * o_value)4483 bool Manager::SceneGetValueAsInt(uint8 const _sceneId, ValueID const& _valueId, int32* o_value)
4484 {
4485 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4486 if (scene != NULL)
4487 {
4488 	string str;
4489 	if (scene->GetValue(_valueId, &str))
4490 	{
4491 		*o_value = (int32) atoi(str.c_str());
4492 		return true;
4493 	}
4494 }
4495 return false;
4496 }
4497 
4498 //-----------------------------------------------------------------------------
4499 // <Manager::SceneGetValueAsShort>
4500 // Return a scene's Value ID short value
4501 //-----------------------------------------------------------------------------
SceneGetValueAsShort(uint8 const _sceneId,ValueID const & _valueId,int16 * o_value)4502 bool Manager::SceneGetValueAsShort(uint8 const _sceneId, ValueID const& _valueId, int16* o_value)
4503 {
4504 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4505 if (scene != NULL)
4506 {
4507 	string str;
4508 	if (scene->GetValue(_valueId, &str))
4509 	{
4510 		*o_value = (int16) atoi(str.c_str());
4511 		return true;
4512 	}
4513 }
4514 return false;
4515 }
4516 
4517 //-----------------------------------------------------------------------------
4518 // <Manager::SceneGetValueAsString>
4519 // Return a scene's Value ID string value
4520 //-----------------------------------------------------------------------------
SceneGetValueAsString(uint8 const _sceneId,ValueID const & _valueId,string * o_value)4521 bool Manager::SceneGetValueAsString(uint8 const _sceneId, ValueID const& _valueId, string* o_value)
4522 {
4523 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4524 if (scene != NULL)
4525 {
4526 	if (scene->GetValue(_valueId, o_value))
4527 	{
4528 		return true;
4529 	}
4530 }
4531 return false;
4532 }
4533 
4534 //-----------------------------------------------------------------------------
4535 // <Manager::SceneGetValueListSelection>
4536 // Return a scene's Value ID list selection (as string) value
4537 //-----------------------------------------------------------------------------
SceneGetValueListSelection(uint8 const _sceneId,ValueID const & _valueId,string * o_value)4538 bool Manager::SceneGetValueListSelection(uint8 const _sceneId, ValueID const& _valueId, string* o_value)
4539 {
4540 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4541 if (scene != NULL)
4542 {
4543 	if (scene->GetValue(_valueId, o_value))
4544 	{
4545 		return true;
4546 	}
4547 }
4548 return false;
4549 }
4550 
4551 //-----------------------------------------------------------------------------
4552 // <Manager::SceneGetValueListSelection>
4553 // Return a scene's Value ID list selection (as integer) value
4554 //-----------------------------------------------------------------------------
SceneGetValueListSelection(uint8 const _sceneId,ValueID const & _valueId,int32 * o_value)4555 bool Manager::SceneGetValueListSelection(uint8 const _sceneId, ValueID const& _valueId, int32* o_value)
4556 {
4557 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4558 if (scene != NULL)
4559 {
4560 	string str;
4561 	if (scene->GetValue(_valueId, &str))
4562 	{
4563 		*o_value = (int32) atoi(str.c_str());
4564 		return true;
4565 	}
4566 }
4567 return false;
4568 }
4569 
4570 //-----------------------------------------------------------------------------
4571 // <Manager::SetSceneValue>
4572 // Set a scene's ValueID bool value.
4573 //-----------------------------------------------------------------------------
SetSceneValue(uint8 const _sceneId,ValueID const & _valueId,bool const _value)4574 bool Manager::SetSceneValue(uint8 const _sceneId, ValueID const& _valueId, bool const _value)
4575 {
4576 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4577 if (scene != NULL)
4578 {
4579 	return scene->SetValue(_valueId, _value ? "True" : "False");
4580 }
4581 return false;
4582 }
4583 
4584 //-----------------------------------------------------------------------------
4585 // <Manager::SetSceneValue>
4586 // Set a scene's ValueID byte value.
4587 //-----------------------------------------------------------------------------
SetSceneValue(uint8 const _sceneId,ValueID const & _valueId,uint8 const _value)4588 bool Manager::SetSceneValue(uint8 const _sceneId, ValueID const& _valueId, uint8 const _value)
4589 {
4590 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4591 if (scene != NULL)
4592 {
4593 	char str[16];
4594 	snprintf(str, sizeof(str), "%d", _value);
4595 	return scene->SetValue(_valueId, str);
4596 }
4597 return false;
4598 }
4599 
4600 //-----------------------------------------------------------------------------
4601 // <Manager::SetSceneValue>
4602 // Set a scene's ValueID float value.
4603 //-----------------------------------------------------------------------------
SetSceneValue(uint8 const _sceneId,ValueID const & _valueId,float const _value)4604 bool Manager::SetSceneValue(uint8 const _sceneId, ValueID const& _valueId, float const _value)
4605 {
4606 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4607 if (scene != NULL)
4608 {
4609 	char str[16];
4610 	snprintf(str, sizeof(str), "%f", _value);
4611 	return scene->SetValue(_valueId, str);
4612 }
4613 return false;
4614 }
4615 
4616 //-----------------------------------------------------------------------------
4617 // <Manager::SetSceneValue>
4618 // Set a scene's ValueID integer value.
4619 //-----------------------------------------------------------------------------
SetSceneValue(uint8 const _sceneId,ValueID const & _valueId,int32 const _value)4620 bool Manager::SetSceneValue(uint8 const _sceneId, ValueID const& _valueId, int32 const _value)
4621 {
4622 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4623 if (scene != NULL)
4624 {
4625 	char str[16];
4626 	snprintf(str, sizeof(str), "%d", _value);
4627 	return scene->SetValue(_valueId, str);
4628 }
4629 return false;
4630 }
4631 
4632 //-----------------------------------------------------------------------------
4633 // <Manager::SetSceneValue>
4634 // Set a scene's ValueID short value.
4635 //-----------------------------------------------------------------------------
SetSceneValue(uint8 const _sceneId,ValueID const & _valueId,int16 const _value)4636 bool Manager::SetSceneValue(uint8 const _sceneId, ValueID const& _valueId, int16 const _value)
4637 {
4638 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4639 if (scene != NULL)
4640 {
4641 	char str[16];
4642 	snprintf(str, sizeof(str), "%d", _value);
4643 	return scene->SetValue(_valueId, str);
4644 }
4645 return false;
4646 }
4647 
4648 //-----------------------------------------------------------------------------
4649 // <Manager::SetSceneValue>
4650 // Set a scene's ValueID string value.
4651 //-----------------------------------------------------------------------------
SetSceneValue(uint8 const _sceneId,ValueID const & _valueId,string const & _value)4652 bool Manager::SetSceneValue(uint8 const _sceneId, ValueID const& _valueId, string const& _value)
4653 {
4654 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4655 if (scene != NULL)
4656 {
4657 	return scene->SetValue(_valueId, _value);
4658 }
4659 return false;
4660 }
4661 
4662 //-----------------------------------------------------------------------------
4663 // <Manager::SetSceneValueListSelection>
4664 // Set a scene's ValueID list item value (as string).
4665 //-----------------------------------------------------------------------------
SetSceneValueListSelection(uint8 const _sceneId,ValueID const & _valueId,string const & _value)4666 bool Manager::SetSceneValueListSelection(uint8 const _sceneId, ValueID const& _valueId, string const& _value)
4667 {
4668 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4669 if (scene != NULL)
4670 {
4671 	return scene->SetValue(_valueId, _value);
4672 }
4673 return false;
4674 }
4675 
4676 //-----------------------------------------------------------------------------
4677 // <Manager::SetSceneValueListSelection>
4678 // Set a scene's ValueID list item value (as integer).
4679 //-----------------------------------------------------------------------------
SetSceneValueListSelection(uint8 const _sceneId,ValueID const & _valueId,int32 const _value)4680 bool Manager::SetSceneValueListSelection(uint8 const _sceneId, ValueID const& _valueId, int32 const _value)
4681 {
4682 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4683 if (scene != NULL)
4684 {
4685 	char str[16];
4686 	snprintf(str, sizeof(str), "%d", _value);
4687 	return scene->SetValue(_valueId, str);
4688 }
4689 return false;
4690 }
4691 
4692 //-----------------------------------------------------------------------------
4693 // <Manager::GetSceneLabel>
4694 // Return a scene's label
4695 //-----------------------------------------------------------------------------
GetSceneLabel(uint8 const _sceneId)4696 string Manager::GetSceneLabel(uint8 const _sceneId)
4697 {
4698 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4699 if (scene != NULL)
4700 {
4701 	return scene->GetLabel();
4702 }
4703 return NULL;
4704 }
4705 
4706 //-----------------------------------------------------------------------------
4707 // <Manager::SetSceneLabel>
4708 // Set a scene's label
4709 //-----------------------------------------------------------------------------
SetSceneLabel(uint8 const _sceneId,string const & _value)4710 void Manager::SetSceneLabel(uint8 const _sceneId, string const& _value)
4711 {
4712 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4713 if (scene != NULL)
4714 {
4715 	scene->SetLabel(_value);
4716 }
4717 }
4718 
4719 //-----------------------------------------------------------------------------
4720 // <Manager::SceneExists>
4721 // Check if a Scene ID exists
4722 //-----------------------------------------------------------------------------
SceneExists(uint8 const _sceneId)4723 bool Manager::SceneExists(uint8 const _sceneId)
4724 {
4725 return Internal::Scene::Get(_sceneId) != NULL;
4726 }
4727 
4728 //-----------------------------------------------------------------------------
4729 // <Manager::ActivateScene>
4730 // Perform all the settings for the given Scene ID
4731 //-----------------------------------------------------------------------------
ActivateScene(uint8 const _sceneId)4732 bool Manager::ActivateScene(uint8 const _sceneId)
4733 {
4734 Internal::Scene *scene = Internal::Scene::Get(_sceneId);
4735 if (scene != NULL)
4736 {
4737 	return scene->Activate();
4738 }
4739 return false;
4740 }
4741 
4742 //-----------------------------------------------------------------------------
4743 // <Manager::GetDriverStatistics>
4744 // Retrieve driver based counters.
4745 //-----------------------------------------------------------------------------
GetDriverStatistics(uint32 const _homeId,Driver::DriverData * _data)4746 void Manager::GetDriverStatistics(uint32 const _homeId, Driver::DriverData* _data)
4747 {
4748 if (Driver* driver = GetDriver(_homeId))
4749 {
4750 	driver->GetDriverStatistics(_data);
4751 }
4752 
4753 }
4754 
4755 //-----------------------------------------------------------------------------
4756 // <Manager::GetNodeStatistics>
4757 // Retrieve driver based counters.
4758 //-----------------------------------------------------------------------------
GetNodeStatistics(uint32 const _homeId,uint8 const _nodeId,Node::NodeData * _data)4759 void Manager::GetNodeStatistics(uint32 const _homeId, uint8 const _nodeId, Node::NodeData* _data)
4760 {
4761 if (Driver* driver = GetDriver(_homeId))
4762 {
4763 	driver->GetNodeStatistics(_nodeId, _data);
4764 }
4765 
4766 }
4767 
4768 //-----------------------------------------------------------------------------
4769 // <Manager::GetNodeRouteScheme>
4770 // Convert the RouteScheme to a String
4771 //-----------------------------------------------------------------------------
GetNodeRouteScheme(Node::NodeData * _data)4772 string Manager::GetNodeRouteScheme(Node::NodeData *_data)
4773 {
4774 switch (_data->m_routeScheme)
4775 {
4776 	case ROUTINGSCHEME_IDLE:
4777 		return "Idle";
4778 	case ROUTINGSCHEME_DIRECT:
4779 		return "Direct";
4780 	case ROUTINGSCHEME_CACHED_ROUTE_SR:
4781 		return "Static Route";
4782 	case ROUTINGSCHEME_CACHED_ROUTE:
4783 		return "Last Working Route";
4784 	case ROUTINGSCHEME_CACHED_ROUTE_NLWR:
4785 		return "Next to Last Working Route";
4786 	case ROUTINGSCHEME_ROUTE:
4787 		return "Auto Route";
4788 	case ROUTINGSCHEME_RESORT_DIRECT:
4789 		return "Resort to Direct";
4790 	case ROUTINGSCHEME_RESORT_EXPLORE:
4791 		return "Explorer Route";
4792 }
4793 return "Unknown";
4794 }
4795 
4796 //-----------------------------------------------------------------------------
4797 // <Manager::GetNodeRouteSpeed>
4798 // Convert the RouteSpeed to a String.
4799 //-----------------------------------------------------------------------------
GetNodeRouteSpeed(Node::NodeData * _data)4800 string Manager::GetNodeRouteSpeed(Node::NodeData *_data)
4801 {
4802 switch (_data->m_routeSpeed)
4803 {
4804 	case ROUTE_SPEED_AUTO:
4805 		return "Auto";
4806 	case ROUTE_SPEED_9600:
4807 		return "9600";
4808 	case ROUTE_SPEED_40K:
4809 		return "40K";
4810 	case ROUTE_SPEED_100K:
4811 		return "100K";
4812 }
4813 return "Unknown";
4814 }
4815 
4816 //-----------------------------------------------------------------------------
4817 // <Manager::GetMetaData>
4818 // Retrieve MetaData about a Node.
4819 //-----------------------------------------------------------------------------
GetMetaData(uint32 const _homeId,uint8 const _nodeId,Node::MetaDataFields _metadata)4820 string const Manager::GetMetaData(uint32 const _homeId, uint8 const _nodeId, Node::MetaDataFields _metadata)
4821 {
4822 if (Driver* driver = GetDriver(_homeId))
4823 {
4824 	return driver->GetMetaData(_nodeId, _metadata);
4825 }
4826 return "";
4827 }
4828 
4829 //-----------------------------------------------------------------------------
4830 // <Manager::GetChangeLog>
4831 // Retrieve ChangeLog of a Configuration File about a Node.
4832 //-----------------------------------------------------------------------------
GetChangeLog(uint32 const _homeId,uint8 const _nodeId,uint32_t revision)4833 Node::ChangeLogEntry const Manager::GetChangeLog(uint32 const _homeId, uint8 const _nodeId, uint32_t revision)
4834 {
4835 if (Driver* driver = GetDriver(_homeId))
4836 {
4837 	return driver->GetChangeLog(_nodeId, revision);
4838 }
4839 Node::ChangeLogEntry cle;
4840 cle.revision = -1;
4841 return cle;
4842 }
4843 
4844 //-----------------------------------------------------------------------------
4845 // <Manager::checkLatestConfigFileRevision>
4846 // get the latest config file revision
4847 //-----------------------------------------------------------------------------
checkLatestConfigFileRevision(uint32 const _homeId,uint8 const _nodeId)4848 bool Manager::checkLatestConfigFileRevision(uint32 const _homeId, uint8 const _nodeId)
4849 {
4850 if (Driver *driver = GetDriver(_homeId))
4851 {
4852 	Internal::LockGuard LG(driver->m_nodeMutex);
4853 	Node* node = driver->GetNode(_nodeId);
4854 	if (node)
4855 	{
4856 		return driver->CheckNodeConfigRevision(node);
4857 	}
4858 }
4859 return false;
4860 }
4861 
4862 //-----------------------------------------------------------------------------
4863 // <Manager::checkLatestMFSRevision>
4864 // get the latest ManufacturerSpecific.xml file revision
4865 //-----------------------------------------------------------------------------
checkLatestMFSRevision(uint32 const _homeId)4866 bool Manager::checkLatestMFSRevision(uint32 const _homeId)
4867 {
4868 if (Driver *driver = GetDriver(_homeId))
4869 {
4870 	return driver->CheckMFSConfigRevision();
4871 }
4872 return false;
4873 }
4874 
4875 //-----------------------------------------------------------------------------
4876 // <Manager::downloadLatestConfigFileRevision>
4877 // Download the latest Config File Revision for a node.
4878 //-----------------------------------------------------------------------------
downloadLatestConfigFileRevision(uint32 const _homeId,uint8 const _nodeId)4879 bool Manager::downloadLatestConfigFileRevision(uint32 const _homeId, uint8 const _nodeId)
4880 {
4881 if (Driver *driver = GetDriver(_homeId))
4882 {
4883 	Internal::LockGuard LG(driver->m_nodeMutex);
4884 	Node* node = driver->GetNode(_nodeId);
4885 	if (node)
4886 	{
4887 		return driver->downloadConfigRevision(node);
4888 	}
4889 }
4890 return false;
4891 }
4892 
4893 //-----------------------------------------------------------------------------
4894 // <Manager::downloadLatestMFSRevision>
4895 // Download the Latest ManufacturerSpecific Revision
4896 //-----------------------------------------------------------------------------
downloadLatestMFSRevision(uint32 const _homeId)4897 bool Manager::downloadLatestMFSRevision(uint32 const _homeId)
4898 {
4899 if (Driver *driver = GetDriver(_homeId))
4900 {
4901 	return driver->downloadMFSRevision();
4902 }
4903 return false;
4904 }
4905 
4906