forked from genielabs/HomeGenie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated all CommadClasses to support new message handling pipeline.
- Loading branch information
Showing
33 changed files
with
863 additions
and
531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 55 additions & 42 deletions
97
MigFiles/SupportLibraries/ZWaveLib/Handlers/CommandClassFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace ZWaveLib.Handlers | ||
{ | ||
class CommandClassFactory | ||
{ | ||
public static ICommandClass GetCommandClass(byte ccId) | ||
{ | ||
if(_commandClasses == null) | ||
_commandClasses = CollectCommandClasses(); | ||
|
||
Type type; | ||
if (!_commandClasses.TryGetValue(ccId, out type)) | ||
return null; | ||
|
||
var cc = (ICommandClass)Activator.CreateInstance(type); | ||
return cc; | ||
} | ||
|
||
private static Dictionary<byte, Type> _commandClasses; | ||
|
||
private static Dictionary<byte, Type> CollectCommandClasses() | ||
{ | ||
var iCommandClassTypes = new Dictionary<byte, Type>(); | ||
var iType = typeof(ICommandClass); | ||
var types = Assembly.GetExecutingAssembly().GetTypes().Where(t => iType.IsAssignableFrom(t)); | ||
|
||
foreach (var type in types) | ||
{ | ||
var cc = (ICommandClass)Activator.CreateInstance(type); | ||
var id = cc.GetCommandClassId(); | ||
_commandClasses.Add(id, type); | ||
} | ||
|
||
return iCommandClassTypes; | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace ZWaveLib.Handlers | ||
{ | ||
class CommandClassFactory | ||
{ | ||
static readonly object lck = new object(); | ||
|
||
public static ICommandClass GetCommandClass(byte ccId) | ||
{ | ||
if (_commandClasses == null) | ||
{ | ||
lock (lck) | ||
{ | ||
if (_commandClasses == null) | ||
{ | ||
_commandClasses = CollectCommandClasses(); | ||
} | ||
} | ||
} | ||
|
||
Type type; | ||
if (!_commandClasses.TryGetValue(ccId, out type)) | ||
return null; | ||
|
||
var cc = (ICommandClass)Activator.CreateInstance(type); | ||
return cc; | ||
} | ||
|
||
private static Dictionary<byte, Type> _commandClasses; | ||
|
||
private static Dictionary<byte, Type> CollectCommandClasses() | ||
{ | ||
var iCommandClassTypes = new Dictionary<byte, Type>(); | ||
var iType = typeof (ICommandClass); | ||
|
||
var assemblyTypes = Assembly.GetExecutingAssembly().GetTypes(); | ||
var types = assemblyTypes.Where(t => iType.IsAssignableFrom(t)).ToList(); | ||
|
||
foreach (var type in types) | ||
{ | ||
if (type == iType) | ||
continue; // we are not going to use interface itself | ||
var cc = (ICommandClass) Activator.CreateInstance(type); | ||
var id = cc.GetCommandClassId(); | ||
iCommandClassTypes.Add(id, type); | ||
} | ||
|
||
return iCommandClassTypes; | ||
} | ||
} | ||
} |
Oops, something went wrong.