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