-
-
Notifications
You must be signed in to change notification settings - Fork 876
Expand file tree
/
Copy pathManager.cpp
More file actions
4943 lines (4518 loc) · 150 KB
/
Copy pathManager.cpp
File metadata and controls
4943 lines (4518 loc) · 150 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-----------------------------------------------------------------------------
//
// Manager.cpp
//
// The main public interface to OpenZWave.
//
// Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
//
// SOFTWARE NOTICE AND LICENSE
//
// This file is part of OpenZWave.
//
// OpenZWave is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// OpenZWave is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
#include <algorithm>
#include <string>
#include <sstream>
#include <iomanip>
#include "Defs.h"
#include "CompatOptionManager.h"
#include "Manager.h"
#include "Driver.h"
#include "Localization.h"
#include "Node.h"
#include "Notification.h"
#include "NotificationCCTypes.h"
#include "Options.h"
#include "Scene.h"
#include "SensorMultiLevelCCTypes.h"
#include "Utils.h"
#include "platform/Mutex.h"
#include "platform/Event.h"
#include "platform/Log.h"
#include "command_classes/CommandClasses.h"
#include "command_classes/CommandClass.h"
#include "command_classes/WakeUp.h"
#include "value_classes/ValueID.h"
#include "value_classes/ValueBool.h"
#include "value_classes/ValueButton.h"
#include "value_classes/ValueByte.h"
#include "value_classes/ValueDecimal.h"
#include "value_classes/ValueInt.h"
#include "value_classes/ValueList.h"
#include "value_classes/ValueRaw.h"
#include "value_classes/ValueSchedule.h"
#include "value_classes/ValueShort.h"
#include "value_classes/ValueString.h"
#include "value_classes/ValueBitSet.h"
using namespace OpenZWave;
Manager* Manager::s_instance = NULL;
extern uint16_t ozw_vers_major;
extern uint16_t ozw_vers_minor;
extern uint16_t ozw_vers_revision;
extern char ozw_version_string[];
//-----------------------------------------------------------------------------
// Construction
//-----------------------------------------------------------------------------
#include "platform/FileOps.h"
//-----------------------------------------------------------------------------
// <Manager::Create>
// Static creation of the singleton
//-----------------------------------------------------------------------------
Manager* Manager::Create()
{
if (Options::Get() && Options::Get()->AreLocked())
{
if ( NULL == s_instance)
{
s_instance = new Manager();
}
return s_instance;
}
// Options have not been created and locked.
Log::Create("", false, true, LogLevel_Debug, LogLevel_Debug, LogLevel_None);
Log::Write(LogLevel_Error, "Options have not been created and locked. Exiting...");
OZW_FATAL_ERROR(OZWException::OZWEXCEPTION_OPTIONS, "Options Not Created and Locked");
return NULL;
}
//-----------------------------------------------------------------------------
// <Manager::Destroy>
// Static method to destroy the singleton.
//-----------------------------------------------------------------------------
void Manager::Destroy()
{
delete s_instance;
s_instance = NULL;
}
//-----------------------------------------------------------------------------
// <Manager::getVersion>
// Static method to get the Version of OZW as a string.
//-----------------------------------------------------------------------------
std::string Manager::getVersionAsString()
{
std::ostringstream versionstream;
versionstream << ozw_vers_major << "." << ozw_vers_minor << "." << ozw_vers_revision;
return versionstream.str();
}
//-----------------------------------------------------------------------------
// <Manager::getVersionLong>
// Static method to get the long Version of OZW as a string.
//-----------------------------------------------------------------------------
std::string Manager::getVersionLongAsString()
{
std::ostringstream versionstream;
versionstream << ozw_version_string;
return versionstream.str();
}
//-----------------------------------------------------------------------------
// <Manager::getVersion>
// Static method to get the Version of OZW.
//-----------------------------------------------------------------------------
ozwversion Manager::getVersion()
{
return version(ozw_vers_major, ozw_vers_minor);
}
//-----------------------------------------------------------------------------
// <Manager::Manager>
// Constructor
//-----------------------------------------------------------------------------
Manager::Manager() :
m_notificationMutex(new Internal::Platform::Mutex())
{
// Ensure the singleton instance is set
s_instance = this;
// Create the log file (if enabled)
bool logging = false;
Options::Get()->GetOptionAsBool("Logging", &logging);
string userPath = "";
Options::Get()->GetOptionAsString("UserPath", &userPath);
string logFileNameBase = "OZW_Log.txt";
Options::Get()->GetOptionAsString("LogFileName", &logFileNameBase);
bool bAppend = false;
Options::Get()->GetOptionAsBool("AppendLogFile", &bAppend);
bool bConsoleOutput = true;
Options::Get()->GetOptionAsBool("ConsoleOutput", &bConsoleOutput);
int nSaveLogLevel = (int) LogLevel_Detail;
Options::Get()->GetOptionAsInt("SaveLogLevel", &nSaveLogLevel);
if ((nSaveLogLevel == 0) || (nSaveLogLevel > LogLevel_StreamDetail))
{
Log::Write(LogLevel_Warning, "Invalid LogLevel Specified for SaveLogLevel in Options.xml");
nSaveLogLevel = (int) LogLevel_Detail;
}
int nQueueLogLevel = (int) LogLevel_Debug;
Options::Get()->GetOptionAsInt("QueueLogLevel", &nQueueLogLevel);
if ((nQueueLogLevel == 0) || (nQueueLogLevel > LogLevel_StreamDetail))
{
Log::Write(LogLevel_Warning, "Invalid LogLevel Specified for QueueLogLevel in Options.xml");
nQueueLogLevel = (int) LogLevel_Debug;
}
int nDumpTrigger = (int) LogLevel_Warning;
Options::Get()->GetOptionAsInt("DumpTriggerLevel", &nDumpTrigger);
string logFilename = userPath + logFileNameBase;
Log::Create(logFilename, bAppend, bConsoleOutput, (LogLevel) nSaveLogLevel, (LogLevel) nQueueLogLevel, (LogLevel) nDumpTrigger);
Log::SetLoggingState(logging);
Internal::CC::CommandClasses::RegisterCommandClasses();
Internal::Scene::ReadScenes();
// petergebruers replace getVersionAsString() with getVersionLongAsString() because
// the latter prints more information, based on the status of the repository
// when "make" was run. A Makefile gets this info from git describe --long --tags --dirty
Log::Write(LogLevel_Always, "OpenZwave Version %s Starting Up", getVersionLongAsString().c_str());
Log::Write(LogLevel_Always, "Using Language Localization %s", Internal::Localization::Get()->GetSelectedLang().c_str());
Internal::NotificationCCTypes::Create();
Internal::SensorMultiLevelCCTypes::Create();
}
//-----------------------------------------------------------------------------
// <Manager::Manager>
// Destructor
//-----------------------------------------------------------------------------
Manager::~Manager()
{
// Clear the pending list
while (!m_pendingDrivers.empty())
{
list<Driver*>::iterator it = m_pendingDrivers.begin();
delete *it;
m_pendingDrivers.erase(it);
}
m_pendingDrivers.clear();
// Clear the ready map
while (!m_readyDrivers.empty())
{
map<uint32, Driver*>::iterator it = m_readyDrivers.begin();
delete it->second;
m_readyDrivers.erase(it);
}
m_readyDrivers.clear();
m_notificationMutex->Release();
// Clear the watchers list
while (!m_watchers.empty())
{
list<Watcher*>::iterator it = m_watchers.begin();
delete *it;
m_watchers.erase(it);
}
m_watchers.clear();
// Clear the generic device class list
while (!Node::s_genericDeviceClasses.empty())
{
map<uint8, Node::GenericDeviceClass*>::iterator git = Node::s_genericDeviceClasses.begin();
delete git->second;
Node::s_genericDeviceClasses.erase(git);
}
Node::s_genericDeviceClasses.clear();
while (!Node::s_basicDeviceClasses.empty())
{
map<uint8, string>::iterator git = Node::s_basicDeviceClasses.begin();
Node::s_basicDeviceClasses.erase(git);
}
Node::s_basicDeviceClasses.clear();
while (!Node::s_roleDeviceClasses.empty())
{
map<uint8, Node::DeviceClass*>::iterator git = Node::s_roleDeviceClasses.begin();
delete git->second;
Node::s_roleDeviceClasses.erase(git);
}
Node::s_roleDeviceClasses.clear();
while (!Node::s_deviceTypeClasses.empty())
{
map<uint16, Node::DeviceClass*>::iterator git = Node::s_deviceTypeClasses.begin();
delete git->second;
Node::s_deviceTypeClasses.erase(git);
}
Node::s_deviceTypeClasses.clear();
while (!Node::s_nodeTypes.empty())
{
map<uint8, Node::DeviceClass*>::iterator git = Node::s_nodeTypes.begin();
delete git->second;
Node::s_nodeTypes.erase(git);
}
Node::s_nodeTypes.clear();
Node::s_deviceClassesLoaded = false;
Log::Destroy();
}
//-----------------------------------------------------------------------------
// Configuration
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// <Manager::WriteConfig>
// Save the configuration of a driver to a file
//-----------------------------------------------------------------------------
void Manager::WriteConfig(uint32 const _homeId)
{
if (Driver* driver = GetDriver(_homeId))
{
driver->WriteCache();
Log::Write(LogLevel_Info, "mgr, Manager::WriteConfig completed for driver with home ID of 0x%.8x", _homeId);
}
else
{
Log::Write(LogLevel_Info, "mgr, Manager::WriteConfig failed - _homeId %d not found", _homeId);
}
Internal::Scene::WriteXML("zwscene.xml");
}
//-----------------------------------------------------------------------------
// Drivers
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// <Manager::AddDriver>
// Add a new Z-Wave PC Interface
//-----------------------------------------------------------------------------
bool Manager::AddDriver(string const& _controllerPath, Driver::ControllerInterface const& _interface)
{
// Make sure we don't already have a driver for this controller
// Search the pending list
for (list<Driver*>::iterator pit = m_pendingDrivers.begin(); pit != m_pendingDrivers.end(); ++pit)
{
if (_controllerPath == (*pit)->GetControllerPath())
{
Log::Write(LogLevel_Info, "mgr, Cannot add driver for controller %s - driver already exists", _controllerPath.c_str());
return false;
}
}
// Search the ready map
for (map<uint32, Driver*>::iterator rit = m_readyDrivers.begin(); rit != m_readyDrivers.end(); ++rit)
{
if (_controllerPath == rit->second->GetControllerPath())
{
Log::Write(LogLevel_Info, "mgr, Cannot add driver for controller %s - driver already exists", _controllerPath.c_str());
return false;
}
}
Driver* driver = new Driver(_controllerPath, _interface);
m_pendingDrivers.push_back(driver);
driver->Start();
Log::Write(LogLevel_Info, "mgr, Added driver for controller %s", _controllerPath.c_str());
return true;
}
//-----------------------------------------------------------------------------
// <Manager::RemoveDriver>
// Remove a Z-Wave PC Interface
//-----------------------------------------------------------------------------
bool Manager::RemoveDriver(string const& _controllerPath)
{
// Search the pending list
for (list<Driver*>::iterator pit = m_pendingDrivers.begin(); pit != m_pendingDrivers.end(); ++pit)
{
if (_controllerPath == (*pit)->GetControllerPath())
{
delete *pit;
m_pendingDrivers.erase(pit);
Log::Write(LogLevel_Info, "mgr, Driver for controller %s removed", _controllerPath.c_str());
return true;
}
}
// Search the ready map
for (map<uint32, Driver*>::iterator rit = m_readyDrivers.begin(); rit != m_readyDrivers.end(); ++rit)
{
if (_controllerPath == rit->second->GetControllerPath())
{
/* data race right here:
* Before, we were deleting the Driver Class direct from the Map... this was causing a datarace:
* 1) Driver::~Driver destructor starts deleting everything....
* 2) This Triggers Notifications such as ValueDeleted etc
* 3) Notifications are delivered to applications, and applications start calling
* Manager Functions which require the Driver (such as IsPolled(valueid))
* 4) Manager looks up the Driver in the m_readyDriver and returns a pointer to the Driver Class
* which is currently being destructed.
* 5) All Hell Breaks loose and we crash and burn.
*
* But we can't change this, as the Driver Destructor triggers internal GetDriver calls... which
* will crash and burn if they can't get a valid Driver back...
*/
Log::Write(LogLevel_Info, "mgr, Driver for controller %s pending removal", _controllerPath.c_str());
delete rit->second;
m_readyDrivers.erase(rit);
Log::Write(LogLevel_Info, "mgr, Driver for controller %s removed", _controllerPath.c_str());
return true;
}
}
Log::Write(LogLevel_Info, "mgr, Failed to remove driver for controller %s", _controllerPath.c_str());
return false;
}
//-----------------------------------------------------------------------------
// <Manager::GetDriver>
// Get a pointer to the driver for a Z-Wave PC Interface
//-----------------------------------------------------------------------------
Driver* Manager::GetDriver(uint32 const _homeId)
{
map<uint32, Driver*>::iterator it = m_readyDrivers.find(_homeId);
if (it != m_readyDrivers.end())
{
return it->second;
}
Log::Write(LogLevel_Error, "mgr, Manager::GetDriver failed - Home ID 0x%.8x is unknown", _homeId);
OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_HOMEID, "Invalid HomeId passed to GetDriver");
//assert(0); << Don't assert as this might be a valid condition when we call RemoveDriver. See comments above.
return NULL;
}
//-----------------------------------------------------------------------------
// <Manager::SetDriverReady>
// Move a driver from pending to ready, and notify any watchers
//-----------------------------------------------------------------------------
void Manager::SetDriverReady(Driver* _driver, bool success)
{
// Search the pending list
bool found = false;
for (list<Driver*>::iterator it = m_pendingDrivers.begin(); it != m_pendingDrivers.end(); ++it)
{
if ((*it) == _driver)
{
// Remove the driver from the pending list
m_pendingDrivers.erase(it);
found = true;
break;
}
}
if (found)
{
if (success)
{
Log::Write(LogLevel_Info, "mgr, Driver with Home ID of 0x%.8x is now ready.", _driver->GetHomeId());
Log::Write(LogLevel_Info, "");
// Add the driver to the ready map
m_readyDrivers[_driver->GetHomeId()] = _driver;
}
// Notify the watchers
Notification* notification = new Notification(success ? Notification::Type_DriverReady : Notification::Type_DriverFailed);
notification->SetHomeAndNodeIds(_driver->GetHomeId(), _driver->GetControllerNodeId());
if (!success)
notification->SetComPort(_driver->GetControllerPath());
_driver->QueueNotification(notification);
}
}
//-----------------------------------------------------------------------------
// <Manager::GetControllerNodeId>
//
//-----------------------------------------------------------------------------
uint8 Manager::GetControllerNodeId(uint32 const _homeId)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->GetControllerNodeId();
}
Log::Write(LogLevel_Info, "mgr, GetControllerNodeId() failed - _homeId %d not found", _homeId);
return 0xff;
}
//-----------------------------------------------------------------------------
// <Manager::GetSUCNodeId>
//
//-----------------------------------------------------------------------------
uint8 Manager::GetSUCNodeId(uint32 const _homeId)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->GetSUCNodeId();
}
Log::Write(LogLevel_Info, "mgr, GetSUCNodeId() failed - _homeId %d not found", _homeId);
return 0xff;
}
//-----------------------------------------------------------------------------
// <Manager::IsPrimaryController>
//
//-----------------------------------------------------------------------------
bool Manager::IsPrimaryController(uint32 const _homeId)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->IsPrimaryController();
}
Log::Write(LogLevel_Info, "mgr, IsPrimaryController() failed - _homeId %d not found", _homeId);
return false;
}
//-----------------------------------------------------------------------------
// <Manager::IsStaticUpdateController>
//
//-----------------------------------------------------------------------------
bool Manager::IsStaticUpdateController(uint32 const _homeId)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->IsStaticUpdateController();
}
Log::Write(LogLevel_Info, "mgr, IsStaticUpdateController() failed - _homeId %d not found", _homeId);
return false;
}
//-----------------------------------------------------------------------------
// <Manager::IsBridgeController>
//
//-----------------------------------------------------------------------------
bool Manager::IsBridgeController(uint32 const _homeId)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->IsBridgeController();
}
Log::Write(LogLevel_Info, "mgr, IsBridgeController() failed - _homeId %d not found", _homeId);
return false;
}
//-----------------------------------------------------------------------------
// <Manager::HasExtendedTxStatus>
//
//-----------------------------------------------------------------------------
bool Manager::HasExtendedTxStatus(uint32 const _homeId)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->HasExtendedTxStatus();
}
Log::Write(LogLevel_Info, "mgr, HasExtendedTxStatus() failed - _homeId %d not found", _homeId);
return false;
}
//-----------------------------------------------------------------------------
// <Manager::GetLibraryVersion>
//
//-----------------------------------------------------------------------------
string Manager::GetLibraryVersion(uint32 const _homeId)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->GetLibraryVersion();
}
Log::Write(LogLevel_Info, "mgr, GetLibraryVersion() failed - _homeId %d not found", _homeId);
return "";
}
//-----------------------------------------------------------------------------
// <Manager::GetLibraryTypeName>
//
//-----------------------------------------------------------------------------
string Manager::GetLibraryTypeName(uint32 const _homeId)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->GetLibraryTypeName();
}
Log::Write(LogLevel_Info, "mgr, GetLibraryTypeName() failed - _homeId %d not found", _homeId);
return "";
}
//-----------------------------------------------------------------------------
// <Manager::GetSendQueueCount>
//
//-----------------------------------------------------------------------------
int32 Manager::GetSendQueueCount(uint32 const _homeId)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->GetSendQueueCount();
}
Log::Write(LogLevel_Info, "mgr, GetSendQueueCount() failed - _homeId %d not found", _homeId);
return -1;
}
//-----------------------------------------------------------------------------
// <Manager::LogDriverStatistics>
// Send driver statistics to the log file
//-----------------------------------------------------------------------------
void Manager::LogDriverStatistics(uint32 const _homeId)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->LogDriverStatistics();
}
Log::Write(LogLevel_Warning, "mgr, LogDriverStatistics() failed - _homeId %d not found", _homeId);
}
//-----------------------------------------------------------------------------
// <Manager::GetControllerInterfaceType>
// Retrieve controller interface type
//-----------------------------------------------------------------------------
Driver::ControllerInterface Manager::GetControllerInterfaceType(uint32 const _homeId)
{
Driver::ControllerInterface ifType = Driver::ControllerInterface_Unknown;
if (Driver* driver = GetDriver(_homeId))
{
ifType = driver->GetControllerInterfaceType();
}
return ifType;
}
//-----------------------------------------------------------------------------
// <Manager::GetControllerPath>
// Retrieve controller interface path
//-----------------------------------------------------------------------------
string Manager::GetControllerPath(uint32 const _homeId)
{
string path = "";
if (Driver* driver = GetDriver(_homeId))
{
path = driver->GetControllerPath();
}
return path;
}
//-----------------------------------------------------------------------------
// Polling Z-Wave values
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// <Manager::GetPollInterval>
// Return the polling interval
//-----------------------------------------------------------------------------
int32 Manager::GetPollInterval()
{
for (map<uint32, Driver*>::iterator rit = m_readyDrivers.begin(); rit != m_readyDrivers.end(); ++rit)
{
return rit->second->GetPollInterval();
}
for (list<Driver*>::iterator pit = m_pendingDrivers.begin(); pit != m_pendingDrivers.end(); ++pit)
{
return (*pit)->GetPollInterval();
}
return 0;
}
//-----------------------------------------------------------------------------
// <Manager::SetPollInterval>
// Set the polling interval on all drivers
//-----------------------------------------------------------------------------
void Manager::SetPollInterval(int32 _milliseconds, bool _bIntervalBetweenPolls)
{
for (list<Driver*>::iterator pit = m_pendingDrivers.begin(); pit != m_pendingDrivers.end(); ++pit)
{
(*pit)->SetPollInterval(_milliseconds, _bIntervalBetweenPolls);
}
for (map<uint32, Driver*>::iterator rit = m_readyDrivers.begin(); rit != m_readyDrivers.end(); ++rit)
{
rit->second->SetPollInterval(_milliseconds, _bIntervalBetweenPolls);
}
}
//-----------------------------------------------------------------------------
// <Manager::EnablePoll>
// Enable polling of a value
//-----------------------------------------------------------------------------
bool Manager::EnablePoll(ValueID const &_valueId, uint8 const _intensity)
{
if (Driver* driver = GetDriver(_valueId.GetHomeId()))
{
return (driver->EnablePoll(_valueId, _intensity));
}
Log::Write(LogLevel_Info, "mgr, EnablePoll failed - Driver with Home ID 0x%.8x is not available", _valueId.GetHomeId());
return false;
}
//-----------------------------------------------------------------------------
// <Manager::DisablePoll>
// Disable polling of a value
//-----------------------------------------------------------------------------
bool Manager::DisablePoll(ValueID const &_valueId)
{
if (Driver* driver = GetDriver(_valueId.GetHomeId()))
{
return (driver->DisablePoll(_valueId));
}
Log::Write(LogLevel_Info, "mgr, DisablePoll failed - Driver with Home ID 0x%.8x is not available", _valueId.GetHomeId());
return false;
}
//-----------------------------------------------------------------------------
// <Manager::isPolled>
// Check polling status of a value
//-----------------------------------------------------------------------------
bool Manager::isPolled(ValueID const &_valueId)
{
if (Driver* driver = GetDriver(_valueId.GetHomeId()))
{
return (driver->isPolled(_valueId));
}
Log::Write(LogLevel_Info, "mgr, isPolled failed - Driver with Home ID 0x%.8x is not available", _valueId.GetHomeId());
return false;
}
//-----------------------------------------------------------------------------
// <Manager::SetPollIntensity>
// Change the intensity with which this value is polled
//-----------------------------------------------------------------------------
void Manager::SetPollIntensity(ValueID const &_valueId, uint8 const _intensity)
{
if (Driver* driver = GetDriver(_valueId.GetHomeId()))
{
return (driver->SetPollIntensity(_valueId, _intensity));
}
Log::Write(LogLevel_Error, "mgr, SetPollIntensity failed - Driver with Home ID 0x%.8x is not available", _valueId.GetHomeId());
}
//-----------------------------------------------------------------------------
// <Manager::GetPollIntensity>
// Change the intensity with which this value is polled
//-----------------------------------------------------------------------------
uint8 Manager::GetPollIntensity(ValueID const &_valueId)
{
uint8 intensity = 0;
if (Driver* driver = GetDriver(_valueId.GetHomeId()))
{
Internal::LockGuard LG(driver->m_nodeMutex);
if (Internal::VC::Value* value = driver->GetValue(_valueId))
{
intensity = value->GetPollIntensity();
value->Release();
}
else
{
OZW_ERROR(OZWException::OZWEXCEPTION_INVALID_VALUEID, "Invalid ValueID passed to GetPollIntensity");
}
}
return intensity;
}
//-----------------------------------------------------------------------------
// Retrieving Node information
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// <Manager::RefreshNodeInfo>
// Fetch the data for a node from the Z-Wave network
//-----------------------------------------------------------------------------
bool Manager::RefreshNodeInfo(uint32 const _homeId, uint8 const _nodeId)
{
if (Driver* driver = GetDriver(_homeId))
{
// Cause the node's data to be obtained from the Z-Wave network
// in the same way as if it had just been added.
Internal::LockGuard LG(driver->m_nodeMutex);
driver->ReloadNode(_nodeId);
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// <Manager::RequestNodeState>
// Fetch the command class data for a node from the Z-Wave network
//-----------------------------------------------------------------------------
bool Manager::RequestNodeState(uint32 const _homeId, uint8 const _nodeId)
{
if (Driver* driver = GetDriver(_homeId))
{
Internal::LockGuard LG(driver->m_nodeMutex);
// Retreive the Node's session and dynamic data
Node* node = driver->GetNode(_nodeId);
if (node)
{
node->SetQueryStage(Node::QueryStage_Associations);
return true;
}
}
return false;
}
//-----------------------------------------------------------------------------
// <Manager::RequestNodeDynamic>
// Fetch only the dynamic command class data for a node from the Z-Wave network
//-----------------------------------------------------------------------------
bool Manager::RequestNodeDynamic(uint32 const _homeId, uint8 const _nodeId)
{
if (Driver* driver = GetDriver(_homeId))
{
Internal::LockGuard LG(driver->m_nodeMutex);
// Retreive the Node's dynamic data
Node* node = driver->GetNode(_nodeId);
if (node)
{
node->SetQueryStage(Node::QueryStage_Dynamic);
return true;
}
}
return false;
}
//-----------------------------------------------------------------------------
// <Manager::IsNodeListeningDevice>
// Get whether the node is a listening device that does not go to sleep
//-----------------------------------------------------------------------------
bool Manager::IsNodeListeningDevice(uint32 const _homeId, uint8 const _nodeId)
{
bool res = false;
if (Driver* driver = GetDriver(_homeId))
{
res = driver->IsNodeListeningDevice(_nodeId);
}
return res;
}
//-----------------------------------------------------------------------------
// <Manager::IsNodeFrequentListeningDevice>
// Get whether the node is a listening device that does not go to sleep
//-----------------------------------------------------------------------------
bool Manager::IsNodeFrequentListeningDevice(uint32 const _homeId, uint8 const _nodeId)
{
bool res = false;
if (Driver* driver = GetDriver(_homeId))
{
res = driver->IsNodeFrequentListeningDevice(_nodeId);
}
return res;
}
//-----------------------------------------------------------------------------
// <Manager::IsNodeBeamingDevice>
// Get whether the node is a beam capable device.
//-----------------------------------------------------------------------------
bool Manager::IsNodeBeamingDevice(uint32 const _homeId, uint8 const _nodeId)
{
bool res = false;
if (Driver* driver = GetDriver(_homeId))
{
res = driver->IsNodeBeamingDevice(_nodeId);
}
return res;
}
//-----------------------------------------------------------------------------
// <Manager::IsNodeRoutingDevice>
// Get whether the node is a routing device that passes messages to other nodes
//-----------------------------------------------------------------------------
bool Manager::IsNodeRoutingDevice(uint32 const _homeId, uint8 const _nodeId)
{
bool res = false;
if (Driver* driver = GetDriver(_homeId))
{
res = driver->IsNodeRoutingDevice(_nodeId);
}
return res;
}
//-----------------------------------------------------------------------------
// <Manager::IsNodeSecurityDevice>
// Get the security attribute for a node.
//-----------------------------------------------------------------------------
bool Manager::IsNodeSecurityDevice(uint32 const _homeId, uint8 const _nodeId)
{
bool security = 0;
if (Driver* driver = GetDriver(_homeId))
{
security = driver->IsNodeSecurityDevice(_nodeId);
}
return security;
}
//-----------------------------------------------------------------------------
// <Manager::GetNodeMaxBaudRate>
// Get the maximum baud rate of a node's communications
//-----------------------------------------------------------------------------
uint32 Manager::GetNodeMaxBaudRate(uint32 const _homeId, uint8 const _nodeId)
{
uint32 baud = 0;
if (Driver* driver = GetDriver(_homeId))
{
baud = driver->GetNodeMaxBaudRate(_nodeId);
}
return baud;
}
//-----------------------------------------------------------------------------
// <Manager::GetNodeVersion>
// Get the version number of a node
//-----------------------------------------------------------------------------
uint8 Manager::GetNodeVersion(uint32 const _homeId, uint8 const _nodeId)
{
uint8 version = 0;
if (Driver* driver = GetDriver(_homeId))
{
version = driver->GetNodeVersion(_nodeId);
}
return version;
}
//-----------------------------------------------------------------------------
// <Manager::GetNodeSecurity>
// Get the security byte of a node
//-----------------------------------------------------------------------------
uint8 Manager::GetNodeSecurity(uint32 const _homeId, uint8 const _nodeId)
{
uint8 version = 0;
if (Driver* driver = GetDriver(_homeId))
{
version = driver->GetNodeSecurity(_nodeId);
}
return version;
}
//-----------------------------------------------------------------------------
// <Manager::IsNodeZWavePlus>
// Get if the Node is a ZWave Plus Supported Node
//-----------------------------------------------------------------------------
bool Manager::IsNodeZWavePlus(uint32 const _homeId, uint8 const _nodeId)
{
bool version = false;
if (Driver* driver = GetDriver(_homeId))
{
version = driver->IsNodeZWavePlus(_nodeId);
}
return version;
}
//-----------------------------------------------------------------------------
// <Manager::GetNodeBasic>
// Get the basic type of a node
//-----------------------------------------------------------------------------
uint8 Manager::GetNodeBasic(uint32 const _homeId, uint8 const _nodeId)
{
uint8 basic = 0;
if (Driver* driver = GetDriver(_homeId))
{
basic = driver->GetNodeBasic(_nodeId);
}
return basic;
}
//-----------------------------------------------------------------------------
// <Manager::GetNodeBasic>
// Get the basic type of a node
//-----------------------------------------------------------------------------
string Manager::GetNodeBasicString(uint32 const _homeId, uint8 const _nodeId)
{
if (Driver* driver = GetDriver(_homeId))
{
return driver->GetNodeBasicString(_nodeId);
}
return "Unknown";
}
//-----------------------------------------------------------------------------
// <Manager::GetNodeGeneric>
// Get the generic type of a node
//-----------------------------------------------------------------------------
uint8 Manager::GetNodeGeneric(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance)
{
uint8 genericType = 0;
if (Driver* driver = GetDriver(_homeId))
{
genericType = driver->GetNodeGeneric(_nodeId, _instance);
}
return genericType;
}
//-----------------------------------------------------------------------------
// <Manager::GetNodeGeneric>
// Get the generic type of a node
//-----------------------------------------------------------------------------
string Manager::GetNodeGenericString(uint32 const _homeId, uint8 const _nodeId, uint8 const _instance)
{
if (Driver *driver = GetDriver(_homeId))
{
return driver->GetNodeGenericString(_nodeId, _instance);
}
return "Unknown";