00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "LOW_deviceFactory.h"
00020
00021
00022
00023
00024
00025
00026
00027
00028 LOW_deviceFactory::LOW_deviceFactory()
00029 {
00030 }
00031
00032
00033 LOW_deviceFactory::~LOW_deviceFactory()
00034 {
00035 }
00036
00037
00038
00039
00040
00041
00042
00043 LOW_device* LOW_deviceFactory::new_SpecificDevice( LOW_netSegment &inSegment, const LOW_deviceID &inDevID)
00044 {
00045 ctorFktMap_t::iterator foundCnstr = deviceCtorsSingleton->find( inDevID.getFamilyCode());
00046
00047 if ( foundCnstr == deviceCtorsSingleton->end() )
00048 if ( unknownDevCtor == 0 )
00049 throw deviceFactory_error( "Family code unknown and no constructor for unknown devices registered.", __FILE__, __LINE__);
00050 else
00051 return unknownDevCtor( inSegment, inDevID);
00052 else
00053 return foundCnstr->second( inSegment, inDevID);
00054 }
00055
00056
00057 void LOW_deviceFactory::registerSpecificCtor( LOW_deviceIDRaw::devFamCode_t inFamCode, newInstanceFkt_t inPseudoCnstr)
00058 {
00059
00060 if ( deviceCtorsSingleton == 0 )
00061 deviceCtorsSingleton = new ctorFktMap_t();
00062
00063 if ( inFamCode == LOW_device::anyDev_famCode )
00064 throw deviceFactory_error( "Cannot register for anyDev_famCode.", __FILE__, __LINE__);
00065
00066 if ( inFamCode == LOW_device::unknownDev_famCode ) {
00067 if ( unknownDevCtor != 0 )
00068 throw deviceFactory_error( "Constructor for unknown devices already registered.", __FILE__, __LINE__);
00069 unknownDevCtor = inPseudoCnstr;
00070 }
00071 else {
00072 if ( (*deviceCtorsSingleton)[inFamCode] != 0 )
00073 throw deviceFactory_error( "Familiy type already registered. Family code: "+
00074 inFamCode, __FILE__, __LINE__);
00075 (*deviceCtorsSingleton)[inFamCode] = inPseudoCnstr;
00076 }
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 LOW_deviceFactory::ctorFktMap_t* LOW_deviceFactory::deviceCtorsSingleton = 0;
00088
00089 LOW_deviceFactory::newInstanceFkt_t LOW_deviceFactory::unknownDevCtor = 0;
00090