|
From: <tho...@us...> - 2011-11-20 21:31:07
|
Revision: 535
http://openautomation.svn.sourceforge.net/openautomation/?rev=535&view=rev
Author: thomas_s
Date: 2011-11-20 21:31:00 +0000 (Sun, 20 Nov 2011)
Log Message:
-----------
- added removed global vars from devicemanager to enable unit testing with mock objects
- implemented first unittest
Modified Paths:
--------------
xPLHAL/branches/thomas_s_dev/CMakeLists.txt
xPLHAL/branches/thomas_s_dev/src/CMakeLists.txt
xPLHAL/branches/thomas_s_dev/src/devicemanager.cpp
xPLHAL/branches/thomas_s_dev/src/devicemanager.h
xPLHAL/branches/thomas_s_dev/src/main.cpp
xPLHAL/branches/thomas_s_dev/src/xplcache.h
xPLHAL/branches/thomas_s_dev/src/xplhandler.cpp
xPLHAL/branches/thomas_s_dev/src/xplhandler.h
xPLHAL/branches/thomas_s_dev/test/CMakeLists.txt
Added Paths:
-----------
xPLHAL/branches/thomas_s_dev/src/i_devicemanager.h
xPLHAL/branches/thomas_s_dev/src/i_xplcache.h
xPLHAL/branches/thomas_s_dev/src/i_xplhandler.h
xPLHAL/branches/thomas_s_dev/test/test_devicemanager.cpp
Removed Paths:
-------------
xPLHAL/branches/thomas_s_dev/test/test_test.cpp
Modified: xPLHAL/branches/thomas_s_dev/CMakeLists.txt
===================================================================
--- xPLHAL/branches/thomas_s_dev/CMakeLists.txt 2011-11-20 21:29:50 UTC (rev 534)
+++ xPLHAL/branches/thomas_s_dev/CMakeLists.txt 2011-11-20 21:31:00 UTC (rev 535)
@@ -24,7 +24,7 @@
#set(CMAKE_CXX_COMPILER lsbc++)
message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
-set(create_STATIC_build ON)
+set(create_STATIC_build OFF)
if(create_STATIC_build)
message("Creating a static build...")
Modified: xPLHAL/branches/thomas_s_dev/src/CMakeLists.txt
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/CMakeLists.txt 2011-11-20 21:29:50 UTC (rev 534)
+++ xPLHAL/branches/thomas_s_dev/src/CMakeLists.txt 2011-11-20 21:31:00 UTC (rev 535)
@@ -18,7 +18,7 @@
cmake_minimum_required(VERSION 2.6)
#set(CMAKE_CXX_FLAGS "-g -O2 -std=c++0x")
-set(CMAKE_CXX_FLAGS "-g -std=c++0x")
+set(CMAKE_CXX_FLAGS "-g -Os -std=c++0x")
set(xPLHAL_SRCS xplmessagequeue.cpp devicemanager.cpp xplhandler.cpp xplcache.cpp xhcpthread.cpp log.cpp xhcp.cpp main.cpp)
add_executable(xPLHAL ${xPLHAL_SRCS})
Modified: xPLHAL/branches/thomas_s_dev/src/devicemanager.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/devicemanager.cpp 2011-11-20 21:29:50 UTC (rev 534)
+++ xPLHAL/branches/thomas_s_dev/src/devicemanager.cpp 2011-11-20 21:31:00 UTC (rev 535)
@@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include <cstdio>
@@ -24,75 +25,57 @@
#include "log.h"
#include "devicemanager.h"
+#include "i_xplcache.h"
using namespace boost::posix_time;
-void deviceManagerClass::add( const xPLDevice& device ) const
+deviceManagerClass::deviceManagerClass(IxPLHandler* xplhandler, IxPLCacheClass* xplcache)
+:m_xPL(xplhandler)
+,m_xPLCache(xplcache)
{
- writeLog( "deviceManagerClass::add("+device.VDI+")", logLevel::debug );
- if( contains( device.VDI ) ) {
- update( device );
- } else {
- std::string newtag = "device." + device.VDI + ".";
- ptime expires = second_clock::local_time() + minutes( 2*device.Interval + 1 );
+}
- xPLCache->updateEntry(newtag + "vdi", device.VDI, false);
- xPLCache->updateEntry(newtag + "configdone", device.ConfigDone?"true":"false", false);
- xPLCache->updateEntry(newtag + "configmissing", device.ConfigMissing?"true":"false", false);
- xPLCache->updateEntry(newtag + "configsource", device.ConfigSource, false);
- xPLCache->updateEntry(newtag + "configtype", device.ConfigType?"true":"false", false);
- xPLCache->updateEntry(newtag + "waitingconfig", device.WaitingConfig?"true":"false", false);
- xPLCache->updateEntry(newtag + "current", device.Current?"true":"false", false);
- xPLCache->updateEntry(newtag + "configlistsent", device.ConfigListSent?"true":"false", false);
- xPLCache->updateEntry(newtag + "suspended", device.Suspended?"true":"false", false);
- xPLCache->updateEntry(newtag + "interval", lexical_cast<std::string>(device.Interval), false);
- xPLCache->updateEntry(newtag + "expires", timeConverter( expires ), false);
+void deviceManagerClass::add( const xPLDevice& device )
+{
+ writeLog("deviceManagerClass::add(" + device.VDI + ")", logLevel::debug);
+ if (contains( device.VDI )) {
+ mDeviceMap[device.VDI] = device;
+ } else {
+ mDeviceMap[device.VDI] = device;
+ mDeviceMap[device.VDI].Expires = calculateExpireTime(device.Interval);
}
}
-bool deviceManagerClass::remove( const std::string& deviceTag ) const
+bool deviceManagerClass::remove( const std::string& deviceTag )
{
writeLog( "deviceManagerClass::remove("+deviceTag+")", logLevel::debug );
- if( contains( deviceTag ) ) {
- std::vector<std::string> list = xPLCache->childNodes( "device." + deviceTag );
- //for( std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); it++ )
- for( auto it : list )
- xPLCache->deleteEntry( it );
+ auto device = mDeviceMap.find(deviceTag);
+ if (device != mDeviceMap.end()) {
+ mDeviceMap.erase(device);
return true;
- } else {
- return false;
}
+ return false;
}
bool deviceManagerClass::removeConfig( const std::string& deviceTag ) const
{
writeLog( "deviceManagerClass::remove("+deviceTag+")", logLevel::debug );
if( containsConfig( deviceTag ) ) {
- std::vector<std::string> list = xPLCache->childNodes( "config." + deviceTag );
- //for( std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); it++ )
- for (auto it : list)
- xPLCache->deleteEntry( it );
+ std::vector<std::string> list = m_xPLCache->childNodes( "config." + deviceTag );
+ for (auto listitem : list) {
+ m_xPLCache->deleteEntry(listitem);
+ }
return true;
- } else {
- return false;
}
+ return false;
}
xPLDevice deviceManagerClass::getDevice( const std::string& deviceTag ) const
{
xPLDevice retval;
- if( contains( deviceTag ) ) {
- retval.ConfigDone = xPLCache->objectValue( "device." + deviceTag + ".configdone" ) == "true";
- retval.ConfigMissing = xPLCache->objectValue( "device." + deviceTag + ".configmissing" ) == "true";
- retval.ConfigSource = xPLCache->objectValue( "device." + deviceTag + ".configsource" );
- retval.ConfigType = xPLCache->objectValue( "device." + deviceTag + ".configtype" ) == "true";
- retval.Current = xPLCache->objectValue( "device." + deviceTag + ".current" ) == "true";
- retval.Expires = timeConverter( xPLCache->objectValue( "device." + deviceTag + ".expires" ) );
- retval.Interval = atoi(xPLCache->objectValue( "device." + deviceTag + ".interval" ).c_str());
- retval.VDI = xPLCache->objectValue( "device." + deviceTag + ".vdi" );
- retval.WaitingConfig = xPLCache->objectValue( "device." + deviceTag + ".waitingconfig" ) == "true";
- retval.ConfigListSent = xPLCache->objectValue( "device." + deviceTag + ".configlistsent" ) == "true";
- retval.Suspended = xPLCache->objectValue( "device." + deviceTag + ".suspended" ) == "true";
+ auto device = mDeviceMap.find(deviceTag);
+ if (device != mDeviceMap.end()) {
+ retval = device->second;
}
return retval;
}
@@ -100,42 +83,24 @@
std::vector<std::string> deviceManagerClass::getAllDeviceNames() const
{
std::vector<std::string> retval;
- std::vector<std::string> nodes = xPLCache->childNodes( "device." );
-// for( std::vector<std::string>::iterator it = nodes.begin(); it != nodes.end(); ++it )
- for (auto node : nodes) {
- if( ends_with( node, ".vdi" ) ) {
- retval.push_back( node.substr( 7, node.size() - 7 - 4 ) ); // leave "device." and ".vdi" away
- writeLog( "deviceManagerClass::getAllDeviceNames() = "+ node.substr( 7, node.size() - 7 - 4 ), logLevel::debug );
- }
+ retval.reserve(mDeviceMap.size());
+ for (auto node : mDeviceMap) {
+ retval.push_back(node.first);
+ writeLog( "deviceManagerClass::getAllDeviceNames() = "+ node.first, logLevel::debug );
}
return retval;
}
-void deviceManagerClass::update( const xPLDevice& device ) const
+void deviceManagerClass::processConfigList( const xPL_MessagePtr message )
{
- writeLog( "deviceManagerClass::update("+device.VDI+") - known: "+ (contains( device.VDI )?"true":"false"), logLevel::debug );
-
- if( contains( device.VDI ) ) {
- remove( device.VDI );
- }
- writeLog( "deviceManagerClass::update("+device.VDI+") -> add", logLevel::debug );
- add( device );
-}
-
-void deviceManagerClass::processConfigList( const xPL_MessagePtr message ) const
-{
- std::string source = std::string("")
- + xPL_getSourceVendor ( message ) + "-"
- + xPL_getSourceDeviceID ( message ) + "."
- + xPL_getSourceInstanceID( message );
+ std::string source = extractSourceFromXplMessage(message);
xPLDevice device = getDevice( source );
writeLog( "deviceManagerClass::processConfigList("+source+") - found ["+device.VDI+"]", logLevel::debug );
if( "" == device.VDI ) {
// A config list turned up that we haven't asked for...
// create a new device...
- const char* intervalString = xPL_getMessageNamedValue( message, "interval" );
- int interval = intervalString ? atoi(intervalString) : 5; // default to 5 minutes
- ptime expires = second_clock::local_time() + minutes( 2*interval + 1 );
+ int interval = 5;
+ ptime expires = calculateExpireTime(xPL_getMessageNamedValue(message, "interval"), &interval);
device.VDI = source; // vendor / device / instance = unique id
device.ConfigDone = false; // false = new waiting check, true = sent/not required
device.ConfigMissing = false; // true = no config file, no response from device, false = have/waiting config
@@ -147,57 +112,70 @@
device.Suspended = false; // lost heartbeat
device.Interval = interval; // current heartbeat interval
device.Expires = expires; // time expires
- update( device );
+ mDeviceMap[device.VDI] = device;
}
xPL_NameValueListPtr nvList = xPL_getMessageBody( message );
xPL_NameValuePairPtr nvPair = NULL;
int nvCount = xPL_getNamedValueCount(nvList);
- for( int nvIndex = 0; nvIndex < nvCount; nvIndex++ ) {
+ for (int nvIndex = 0; nvIndex < nvCount; nvIndex++ ) {
std::string newtag = "config." + source + ".options.";
nvPair = xPL_getNamedValuePairAt( nvList, nvIndex );
std::string value = nvPair->itemValue; to_lower( value );
std::string key = nvPair->itemName ; to_lower( key );
boost::regex re( "([a-z0-9]{1,16})\\[(\\d{1,3})\\]" );
boost::smatch matches;
- if( boost::regex_match( value, matches, re) ) {
- xPLCache->updateEntry( newtag + matches[1] , "" , false );
- xPLCache->updateEntry( newtag + matches[1] + ".type" , key , false );
- xPLCache->updateEntry( newtag + matches[1] + ".count", matches[2], false );
- } else {
- xPLCache->updateEntry( newtag + value , "" , false );
- xPLCache->updateEntry( newtag + value + ".type" , key , false );
- xPLCache->updateEntry( newtag + value + ".count", "" , false );
+ if (boost::regex_match(value, matches, re)) {
+ m_xPLCache->updateEntry( newtag + matches[1] , "" , false );
+ m_xPLCache->updateEntry( newtag + matches[1] + ".type" , key , false );
+ m_xPLCache->updateEntry( newtag + matches[1] + ".count", matches[2], false );
+ }
+ else {
+ m_xPLCache->updateEntry( newtag + value , "" , false );
+ m_xPLCache->updateEntry( newtag + value + ".type" , key , false );
+ m_xPLCache->updateEntry( newtag + value + ".count", "" , false );
}
}
// send the config response, but only if we have a config (e.g. from the use via XHCP)
- if( xPLCache->exists( "config." + source + ".current" ) ) {
- xPLCache->updateEntry( "device." + source + ".configdone", "true", false );
+ if( m_xPLCache->exists( "config." + source + ".current" ) ) {
+ mDeviceMap[source].ConfigDone = true;
sendConfigResponse( source, false );
- } else {
+ }
+ else {
// try to get at least the current config
xPLMessage::namedValueList command_request; command_request.push_back( std::make_pair( "command", "request" ) );
- xPL->sendMessage( xPL_MESSAGE_COMMAND,
+ m_xPL->sendMessage( xPL_MESSAGE_COMMAND,
xPL_getSourceVendor( message ), xPL_getSourceDeviceID( message ), xPL_getSourceInstanceID( message ),
"config", "current", command_request );
}
}
-void deviceManagerClass::processConfigHeartBeat( const xPL_MessagePtr message ) const
+ptime deviceManagerClass::calculateExpireTime(const char* string_interval, int *pInterval)
{
- std::string source = std::string("")
- + xPL_getSourceVendor ( message ) + "-"
- + xPL_getSourceDeviceID ( message ) + "."
- + xPL_getSourceInstanceID( message );
+ int interval = string_interval ? atoi(string_interval) : 5; // default to 5 minutes
+ if (pInterval) {
+ *pInterval = interval;
+ }
+ return calculateExpireTime(interval);
+}
+
+ptime deviceManagerClass::calculateExpireTime(int interval)
+{
+ return second_clock::local_time() + minutes( 2* interval + 1 );
+}
+
+void deviceManagerClass::processConfigHeartBeat( const xPL_MessagePtr message )
+{
+ std::string source = extractSourceFromXplMessage(message);
+
xPLDevice device = getDevice( source );
writeLog( "deviceManagerClass::processConfigHeartBeat("+source+") - found ["+device.VDI+"]", logLevel::debug );
- if( "" == device.VDI ) {
+ if( device.VDI.empty() ) {
// this handles a new application that identifies itself with a hbeat straight away.
// it must either be storing it's config locally, can't be configured, or is configured somewhere else.
- const char* intervalString = xPL_getMessageNamedValue( message, "interval" );
- int interval = intervalString ? atoi(intervalString) : 5; // default to 5 minutes
- ptime expires = second_clock::local_time() + minutes( 2*interval + 1 );
+ int interval = 5;
+ ptime expires = calculateExpireTime(xPL_getMessageNamedValue(message, "interval"), &interval);
device.VDI = source; // vendor / device / instance = unique id
device.ConfigDone = false; // false = new waiting check, true = sent/not required
device.ConfigMissing = true; // true = no config file, no response from device, false = have/waiting config
@@ -209,29 +187,27 @@
device.Suspended = false; // lost heartbeat
device.Interval = interval; // current heartbeat interval
device.Expires = expires; // time expires
- update( device );
+ mDeviceMap[device.VDI] = device;
} else {
- xPLCache->updateEntry( "device." + source + ".expires", timeConverter( second_clock::local_time() + minutes( 2*device.Interval + 1 ) ), false );
+ mDeviceMap[device.VDI].Expires = calculateExpireTime(device.Interval);
+ mDeviceMap[device.VDI].ConfigSource = "objectcache";
// FIXME - that line look like that in the VB code - but it seems really strange!
- xPLCache->updateEntry( "device." + source + ".expires.configdone", "objectcache", false );
+// m_xPLCache->updateEntry( "device." + source + ".expires.configdone", "objectcache", false );
}
// ask device for configuration (if haven't asked it before...)
if( !device.ConfigListSent ) {
xPLMessage::namedValueList command_request; command_request.push_back( std::make_pair( "command", "request" ) );
- xPL->sendMessage( xPL_MESSAGE_COMMAND,
+ m_xPL->sendMessage( xPL_MESSAGE_COMMAND,
xPL_getSourceVendor( message ), xPL_getSourceDeviceID( message ), xPL_getSourceInstanceID( message ),
"config", "list", command_request );
- xPLCache->updateEntry( "device." + source + ".configlistsend", "true", false );
+ mDeviceMap[device.VDI].ConfigListSent = true;
}
}
-void deviceManagerClass::processCurrentConfig( const xPL_MessagePtr message ) const
+void deviceManagerClass::processCurrentConfig( const xPL_MessagePtr message )
{
- std::string source = std::string("")
- + xPL_getSourceVendor ( message ) + "-"
- + xPL_getSourceDeviceID ( message ) + "."
- + xPL_getSourceInstanceID( message );
+ std::string source = extractSourceFromXplMessage(message);
xPLDevice device = getDevice( source );
writeLog( "deviceManagerClass::processCurrentConfig("+source+") - found ["+device.VDI+"]", logLevel::debug );
if( "" == device.VDI ) {
@@ -240,8 +216,9 @@
// => just treat it like an heartbeat
return processConfigHeartBeat( message );
} else {
- xPLCache->updateEntry( "config." + source + ".expires", timeConverter( second_clock::local_time() + minutes( 2*device.Interval + 1 ) ), false );
- xPLCache->updateEntry( "config." + source + ".current", "true", false );
+// ptime expires = calculateExpireTime(device.Interval);
+// m_xPLCache->updateEntry( "config." + source + ".expires", timeConverter(calculateExpireTime(device.Interval), false ));
+ m_xPLCache->updateEntry( "config." + source + ".current", "true", false );
}
xPL_NameValueListPtr nvList = xPL_getMessageBody( message );
@@ -253,7 +230,7 @@
nvPair = xPL_getNamedValuePairAt( nvList, nvIndex );
std::string value = nvPair->itemValue; to_lower( value );
std::string key = nvPair->itemName ; to_lower( key );
- std::string count = xPLCache->objectValue( "config." + source + ".options." + key + ".count" );
+ std::string count = m_xPLCache->objectValue( "config." + source + ".options." + key + ".count" );
if( "" != count ) {
if( multiKey == key ) {
multiCount++;
@@ -265,20 +242,25 @@
snprintf( buf, 6, "{%.3d}", multiCount );
key += buf;
}
- xPLCache->updateEntry( "config." + source + ".current." + key, value, false );
+ m_xPLCache->updateEntry( "config." + source + ".current." + key, value, false );
}
}
-void deviceManagerClass::processHeartbeat( xPL_MessagePtr message ) const
+std::string deviceManagerClass::extractSourceFromXplMessage( xPL_MessagePtr message )
{
- std::string source = std::string("")
- + xPL_getSourceVendor ( message ) + "-"
- + xPL_getSourceDeviceID ( message ) + "."
- + xPL_getSourceInstanceID( message );
+ return std::string(xPL_getSourceVendor(message)) + "-"
+ + xPL_getSourceDeviceID ( message ) + "."
+ + xPL_getSourceInstanceID( message );
+}
+
+void deviceManagerClass::processHeartbeat( xPL_MessagePtr message )
+{
+ std::string source = extractSourceFromXplMessage(message);
+
xPLDevice device = getDevice( source );
- int interval = atoi(std::string( xPL_getMessageNamedValue( message, "interval" ) ).c_str());
- ptime expires = second_clock::local_time() + minutes( 2*interval + 1 );
+ int interval = 5;
+ ptime expires = calculateExpireTime(xPL_getMessageNamedValue(message, "interval"), &interval);
writeLog( "deviceManagerClass::processHeartbeat("+source+") - found ["+device.VDI+"]", logLevel::debug );
if( "" == device.VDI ) {
@@ -295,56 +277,52 @@
device.Suspended = false; // lost heartbeat
device.Interval = interval; // current heartbeat interval
device.Expires = expires; // time expires
- update( device );
+ mDeviceMap[device.VDI] = device;
// Throw it a config request anyway, see what turns up..
xPLMessage::namedValueList command_request; command_request.push_back( std::make_pair( "command", "request" ) );
- xPL->sendMessage( xPL_MESSAGE_COMMAND,
+ m_xPL->sendMessage( xPL_MESSAGE_COMMAND,
xPL_getSourceVendor( message ), xPL_getSourceDeviceID( message ), xPL_getSourceInstanceID( message ),
"config", "list" , command_request );
/* // that code below was from the VB - but we don't need it as processConfigList will
// itself send the config.current request...
- xPL->sendMessage( xPL_MESSAGE_COMMAND,
+ m_xPL->sendMessage( xPL_MESSAGE_COMMAND,
xPL_getSourceVendor( message ), xPL_getSourceDeviceID( message ), xPL_getSourceInstanceID( message ),
"config", "current", command_request );
*/
} else {
- xPLCache->updateEntry( "device." + source + ".expires", timeConverter( expires ), false );
+ mDeviceMap[source].Expires = expires;
}
}
-void deviceManagerClass::processRemove( xPL_MessagePtr message ) const
+void deviceManagerClass::processRemove( xPL_MessagePtr message )
{
- std::string source = std::string("")
- + xPL_getSourceVendor ( message ) + "-"
- + xPL_getSourceDeviceID ( message ) + "."
- + xPL_getSourceInstanceID( message );
+ std::string source = extractSourceFromXplMessage(message);
remove( source );
removeConfig( source );
}
-void deviceManagerClass::sendConfigResponse( const std::string& source, const bool removeOldValue ) const
+void deviceManagerClass::sendConfigResponse( const std::string& source, const bool removeOldValue )
{
writeLog( "deviceManagerClass::sendConfigResponse("+source+", "+(removeOldValue?"true":"false")+")", logLevel::debug );
boost::regex re( "config\\." + source + "\\.current\\.([a-z0-9]{1,16})(?:\\{([0-9]{1,3})\\})?" );
- std::vector<std::string> entries = xPLCache->filterByRegEx( re );
+ std::vector<std::string> entries = m_xPLCache->filterByRegEx( re );
xPLMessage::namedValueList list;
-// for( std::vector<std::string>::const_iterator it = entries.begin(); it != entries.end(); ++it )
for( auto entry : entries) {
boost::smatch matches;
boost::regex_match( entry, matches, re );
writeLog( "deviceManagerClass::sendConfigResponse: ["+entry+"] -> ["+matches[1]+"]("+matches[2]+")",logLevel::debug );
if( matches.size() > 1 ) {
- list.push_back( std::make_pair( matches[1], xPLCache->objectValue( entry ) ) );
+ list.push_back( std::make_pair( matches[1], m_xPLCache->objectValue( entry ) ) );
}
}
if( list.size() > 0 ) {
- xPL->sendMessage( xPL_MESSAGE_COMMAND, source, "config", "response", list );
- xPLCache->updateEntry( "config." + source + ".configmissing", "false", false );
- xPLCache->updateEntry( "config." + source + ".waitingconfig", "false", false );
- xPLCache->updateEntry( "config." + source + ".configdone" , "true" , false ); // FIXME the VB code says "false"...
+ m_xPL->sendMessage( xPL_MESSAGE_COMMAND, source, "config", "response", list );
+ m_xPLCache->updateEntry( "config." + source + ".configmissing", "false", false );
+ m_xPLCache->updateEntry( "config." + source + ".waitingconfig", "false", false );
+ m_xPLCache->updateEntry( "config." + source + ".configdone" , "true" , false ); // FIXME the VB code says "false"...
}
if( removeOldValue ) {
@@ -353,24 +331,24 @@
}
}
-bool deviceManagerClass::storeNewConfig( const std::string& source, const std::string& config ) const
+bool deviceManagerClass::storeNewConfig( const std::string& source, const std::string& config )
{
writeLog( "deviceManagerClass::storeNewConfig("+source+", "+config+")", logLevel::debug );
- if( !contains( source ) ) {
+ auto device = mDeviceMap.find(source);
+ if (device == mDeviceMap.end()) {
return false;
}
std::vector<std::string> list;
split( list, config, is_any_of("\r\n"), token_compress_on );
std::string multiKey;
- int multiCount = 0;
-// for( std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it )
- for( auto it : list) {
+ int multiCount = 0;
+ for( auto listitem : list) {
std::vector<std::string> tags;
- split( tags, it, is_any_of("=") );
+ split( tags, listitem, is_any_of("=") );
to_lower( tags[0] );
to_lower( tags[1] );
- std::string count = xPLCache->objectValue( "config." + source + ".options." + tags[0] + ".count" );
+ std::string count = m_xPLCache->objectValue( "config." + source + ".options." + tags[0] + ".count" );
if( "" != count ) {
if( multiKey != tags[0] ) {
multiKey = tags[0];
@@ -383,10 +361,21 @@
snprintf( buf, 6, "{%.3d}", multiCount );
tags[0] += buf;
}
- xPLCache->updateEntry( "config." + source + ".current." + tags[0], tags[1], false );
+ m_xPLCache->updateEntry( "config." + source + ".current." + tags[0], tags[1], false );
}
- if( xPLCache->childNodes( "config." + source + ".current" ).size() > 0 ) {
+ if( m_xPLCache->childNodes( "config." + source + ".current" ).size() > 0 ) {
sendConfigResponse( source, false ); // FIXME the VB said true - but why should I delete the values that I've just stored?
}
return true;
}
+
+bool deviceManagerClass::contains( const std::string& deviceTag ) const
+{
+ return mDeviceMap.find(deviceTag) != mDeviceMap.end();
+}
+
+bool deviceManagerClass::containsConfig( const std::string& configTag ) const
+{
+ return m_xPLCache->childNodes( "config." + configTag ).size() > 0;
+}
+
Modified: xPLHAL/branches/thomas_s_dev/src/devicemanager.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/devicemanager.h 2011-11-20 21:29:50 UTC (rev 534)
+++ xPLHAL/branches/thomas_s_dev/src/devicemanager.h 2011-11-20 21:31:00 UTC (rev 535)
@@ -20,52 +20,65 @@
#define DEVICEMANAGER_H
#include <string>
+#include <map>
// this is also including the xPL.h with its data structures:
#include "xplhandler.h"
+class IxPLHandler;
+class IxPLCacheClass;
+
#include "xplcache.h"
#include "globals.h"
#include "xpldevice.h"
+#include "i_devicemanager.h"
-class deviceManagerClass
+class deviceManagerClass: public IdeviceManagerClass
{
- public:
- /** \brief Looks if the device deviceTag is known. */
- bool contains( const std::string& deviceTag ) const
- { return xPLCache->childNodes( "device." + deviceTag ).size() > 0; }
+ public:
+ deviceManagerClass(IxPLHandler* xplhandler, IxPLCacheClass* xplcache);
- /** \brief Looks if the config configTag is known. */
- bool containsConfig( const std::string& configTag ) const
- { return xPLCache->childNodes( "config." + configTag ).size() > 0; }
+ /** \brief Looks if the device deviceTag is known. */
+ bool contains( const std::string& deviceTag ) const;
- void add( const xPLDevice& device ) const;
- bool remove( const std::string& deviceTag ) const;
- bool removeConfig( const std::string& deviceTag ) const;
+ /** \brief Looks if the config configTag is known. */
+ bool containsConfig( const std::string& configTag ) const;
- /** \brief Returns the device deviceTag when it's known or an empty device */
- xPLDevice getDevice( const std::string& deviceTag ) const;
+ void add( const xPLDevice& device );
+ bool remove( const std::string& deviceTag );
+ bool removeConfig( const std::string& deviceTag ) const;
- /** \brief Returns all known device names */
- std::vector<std::string> getAllDeviceNames() const;
+ /** \brief Returns the device deviceTag when it's known or an empty device */
+ xPLDevice getDevice( const std::string& deviceTag ) const;
- void update( const xPLDevice& device ) const;
+ /** \brief Returns all known device names */
+ std::vector<std::string> getAllDeviceNames() const;
- /** \brief Handle the returned config list that someone (porbably we) have asked for */
- void processConfigList ( const xPL_MessagePtr message ) const;
+ /** \brief Handle the returned config list that someone (porbably we) have asked for */
+ void processConfigList ( const xPL_MessagePtr message );
- /** \brief Called when a new device poped up and is waiting to be configured */
- void processConfigHeartBeat( const xPL_MessagePtr message ) const;
+ /** \brief Called when a new device poped up and is waiting to be configured */
+ void processConfigHeartBeat( const xPL_MessagePtr message );
- /** \brief Called when a device sends its configuration */
- void processCurrentConfig ( const xPL_MessagePtr message ) const;
- void processHeartbeat ( const xPL_MessagePtr message ) const;
- void processRemove ( const xPL_MessagePtr message ) const;
+ /** \brief Called when a device sends its configuration */
+ void processCurrentConfig ( const xPL_MessagePtr message );
+ void processHeartbeat ( const xPL_MessagePtr message );
+ void processRemove ( const xPL_MessagePtr message );
- void sendConfigResponse( const std::string& source, const bool removeOldValue ) const;
-
- /** \brief A new configuration arrived via XHCP, handle it... */
- bool storeNewConfig( const std::string& source, const std::string& config ) const;
+ void sendConfigResponse( const std::string& source, const bool removeOldValue );
+
+ /** \brief A new configuration arrived via XHCP, handle it... */
+ bool storeNewConfig( const std::string& source, const std::string& config );
+
+ private:
+ /*! \TODO: move to correct class, maybe xplMessage */
+ std::string extractSourceFromXplMessage( xPL_MessagePtr message );
+ boost::posix_time::ptime calculateExpireTime(int interval);
+ boost::posix_time::ptime calculateExpireTime(const char* string_interval, int *pInterval = 0);
+
+ IxPLHandler* m_xPL;
+ IxPLCacheClass* m_xPLCache;
+ std::map<std::string, xPLDevice> mDeviceMap;
};
#endif // DEVICEMANAGER_H
Added: xPLHAL/branches/thomas_s_dev/src/i_devicemanager.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/i_devicemanager.h (rev 0)
+++ xPLHAL/branches/thomas_s_dev/src/i_devicemanager.h 2011-11-20 21:31:00 UTC (rev 535)
@@ -0,0 +1,42 @@
+/*
+ xPLHAL implementation in C++
+ Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef IDEVICEMANAGER_H
+#define IDEVICEMANAGER_H
+
+// this is also including the xPL.h with its data structures:
+#include "xplhandler.h"
+
+class IdeviceManagerClass
+{
+ public:
+ virtual ~IdeviceManagerClass() {}
+
+ /** \brief Handle the returned config list that someone (porbably we) have asked for */
+ virtual void processConfigList ( const xPL_MessagePtr message ) = 0;
+
+ /** \brief Called when a new device poped up and is waiting to be configured */
+ virtual void processConfigHeartBeat( const xPL_MessagePtr message ) = 0;
+
+ /** \brief Called when a device sends its configuration */
+ virtual void processCurrentConfig ( const xPL_MessagePtr message ) = 0;
+ virtual void processHeartbeat ( const xPL_MessagePtr message ) = 0;
+ virtual void processRemove ( const xPL_MessagePtr message ) = 0;
+};
+
+#endif // IDEVICEMANAGER_H
Added: xPLHAL/branches/thomas_s_dev/src/i_xplcache.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/i_xplcache.h (rev 0)
+++ xPLHAL/branches/thomas_s_dev/src/i_xplcache.h 2011-11-20 21:31:00 UTC (rev 535)
@@ -0,0 +1,66 @@
+/*
+ xPLHAL implementation in C++
+ Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef IXPLCACHE_H
+#define IXPLCACHE_H
+
+#include <string>
+#include <vector>
+#include <boost/regex.hpp>
+
+//class boost::regex;
+
+class IxPLCacheClass
+{
+ public:
+
+ /** \returns true if the element name exists. */
+ virtual bool exists( const std::string& name ) const = 0;
+
+ /** \returns the value of element name if it exists - or an empty std::string otherwise. */
+ virtual std::string objectValue( const std::string& name ) const = 0;
+
+ /** \returns all objectes stored in the cache. */
+ virtual std::string listAllObjects( bool forceEverything = false ) const = 0;
+
+ /** \brief Create a new object or update it if it exists in the cache. */
+ virtual void updateEntry( const std::string& name, const std::string& value, const bool expires = true ) = 0;
+
+ /** \brief Delete an object if it exists in the cache - or do nothing. */
+ virtual void deleteEntry( const std::string& name ) = 0;
+
+ /** \brief Delete all expired entries. */
+ virtual void flushExpiredEntries( void ) = 0;
+
+ /** \returns all entries that start with filter. */
+ virtual std::vector<std::string> childNodes( const std::string& filter ) const = 0;
+
+ /** \returns all entries that fit the regular expression. */
+ virtual std::vector<std::string> filterByRegEx( const boost::regex& regex ) const = 0;
+
+ /** \returns all entries that fit the regular expression. */
+ virtual std::vector<std::string> filterByRegEx( const std::string& regex ) const = 0;
+
+ /** \brief Load object cache from file system */
+ virtual void loadCache( void ) = 0;
+
+ /** \brief Save object cache to file system */
+ virtual void saveCache( void ) const = 0;
+};
+
+#endif // IXPLCACHE_H
Added: xPLHAL/branches/thomas_s_dev/src/i_xplhandler.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/i_xplhandler.h (rev 0)
+++ xPLHAL/branches/thomas_s_dev/src/i_xplhandler.h 2011-11-20 21:31:00 UTC (rev 535)
@@ -0,0 +1,50 @@
+/*
+ xPLHAL implementation in C++
+ Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef IXPLHANDLER_H
+#define IXPLHANDLER_H
+
+#include <string>
+
+// this is also including the xPL.h
+#include "xplmessagequeue.h"
+
+/**
+ * \brief Handle all xPL communication.
+ */
+class IxPLHandler
+{
+ public:
+ virtual ~IxPLHandler() {}
+
+ /** \brief Broadcast one message to the xPL network. */
+ virtual void sendBroadcastMessage( const std::string& msgClass, const std::string& msgType, const xPLMessage::namedValueList& namedValues ) const = 0;
+
+ /** \brief Send a directed message to the xPL network. */
+ virtual void sendMessage( const xPL_MessageType type, const std::string& tgtVendor, const std::string& tgtDeviceID,
+ const std::string& tgtInstanceID, const std::string& msgClass, const std::string& msgType,
+ const xPLMessage::namedValueList& namedValues ) const = 0;
+
+ /** \brief Send a directed message to the xPL network. */
+ virtual void sendMessage( const xPL_MessageType type, const std::string& VDI,
+ const std::string& msgClass, const std::string& msgType, const xPLMessage::namedValueList& namedValues ) const = 0;
+
+};
+
+#endif // IXPLHANDLER_H
Modified: xPLHAL/branches/thomas_s_dev/src/main.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/main.cpp 2011-11-20 21:29:50 UTC (rev 534)
+++ xPLHAL/branches/thomas_s_dev/src/main.cpp 2011-11-20 21:31:00 UTC (rev 535)
@@ -107,7 +107,8 @@
xPLCache = new xPLCacheClass;
XHCPServer *xhcpServer = new XHCPServer();
xPL = new xPLHandler( boost::asio::ip::host_name() ); //xPL->start();
- deviceManager = new deviceManagerClass();
+ deviceManager = new deviceManagerClass(xPL, xPLCache);
+ xPL->setDeviceManager(deviceManager);
writeLog( "started", logLevel::all );
// force everyone to send their configuration so that we start up to date...
Modified: xPLHAL/branches/thomas_s_dev/src/xplcache.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplcache.h 2011-11-20 21:29:50 UTC (rev 534)
+++ xPLHAL/branches/thomas_s_dev/src/xplcache.h 2011-11-20 21:31:00 UTC (rev 535)
@@ -26,6 +26,7 @@
#include <boost/thread/shared_mutex.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/regex.hpp>
+#include "i_xplcache.h"
/** Helper function */
@@ -64,7 +65,7 @@
*
* This class contains a std::map to stores xPL messages and the global variables.
*/
-class xPLCacheClass
+class xPLCacheClass: public IxPLCacheClass
{
protected:
/**
Modified: xPLHAL/branches/thomas_s_dev/src/xplhandler.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplhandler.cpp 2011-11-20 21:29:50 UTC (rev 534)
+++ xPLHAL/branches/thomas_s_dev/src/xplhandler.cpp 2011-11-20 21:31:00 UTC (rev 535)
@@ -21,9 +21,10 @@
using namespace boost::algorithm;
#include "log.h"
-#include "devicemanager.h"
+#include "i_devicemanager.h"
#include "xplhandler.h"
+#include "globals.h"
/** Handle a change to the logger service configuration */
/* static void configChangedHandler(xPL_ServicePtr theService, xPL_ObjectPtr userData) {
@@ -31,10 +32,13 @@
int xPLHandler::m_refcount = 0;
-xPLHandler::xPLHandler( const std::string& host_name )
- : xPLService(0),
- m_exit_thread(false),
- vendor( "CHRISM" ), deviceID( "xplhalqt" ), instanceID( host_name )
+xPLHandler::xPLHandler( const std::string& host_name, IdeviceManagerClass* devManager )
+: xPLService(0)
+, m_exit_thread(false)
+, vendor( "CHRISM" )
+, deviceID( "xplhalqt" )
+, instanceID( host_name )
+, m_deviceManager(devManager)
{
writeLog( "xPLHandler::xPLHandler( "+host_name+" )", logLevel::debug );
//xPL_setDebugging(TRUE);
@@ -98,6 +102,10 @@
}
}
+void xPLHandler::setDeviceManager(IdeviceManagerClass* devManager)
+{
+ m_deviceManager = devManager;
+}
void xPLHandler::run()
{
@@ -253,15 +261,15 @@
if( "config.list" == schema )
{
// someone (probably we) have asked for the config list - handle it now...
- deviceManager->processConfigList( theMessage );
+ m_deviceManager->processConfigList( theMessage );
} else if( "config.current" == schema )
{
// someone requested the device to send it's current configuration
- deviceManager->processCurrentConfig( theMessage );
+ m_deviceManager->processCurrentConfig( theMessage );
} else if( "config.app" == schema || "config.basic" == schema )
{
// a new device poped up and wants to be configured
- deviceManager->processConfigHeartBeat( theMessage );
+ m_deviceManager->processConfigHeartBeat( theMessage );
} else if( "hbeat.basic" == schema || "hbeat.app" == schema )
{
/*
@@ -269,10 +277,10 @@
RaiseEvent AddtoCache("xplhal." & msgSource & ".alive", Now.ToString, False)
End If
*/
- deviceManager->processHeartbeat( theMessage );
+ m_deviceManager->processHeartbeat( theMessage );
} else if( "hbeat.end" == schema )
{
- deviceManager->processRemove( theMessage );
+ m_deviceManager->processRemove( theMessage );
}
}
}
Modified: xPLHAL/branches/thomas_s_dev/src/xplhandler.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplhandler.h 2011-11-20 21:29:50 UTC (rev 534)
+++ xPLHAL/branches/thomas_s_dev/src/xplhandler.h 2011-11-20 21:31:00 UTC (rev 535)
@@ -27,21 +27,26 @@
#include <boost/thread/locks.hpp>
// this is also including the xPL.h
+#include "i_xplhandler.h"
#include "xplmessagequeue.h"
+class IdeviceManagerClass;
+
/**
* \brief Handle all xPL communication.
*/
-class xPLHandler
+class xPLHandler: public IxPLHandler
{
/** \brief variable to ensure that the xPL library is only called at the same time... */
//mutable boost::mutex xPLLock;
//typedef boost::lock_guard<boost::mutex> lock_guard;
public:
- xPLHandler( const std::string& host_name );
+ xPLHandler( const std::string& host_name, IdeviceManagerClass* devManager = 0);
~xPLHandler();
+ void setDeviceManager(IdeviceManagerClass* devManager);
+
void run();
/** \brief Broadcast one message to the xPL network. */
@@ -73,6 +78,7 @@
boost::thread* m_thread;
static int m_refcount;
bool m_exit_thread;
+ IdeviceManagerClass* m_deviceManager;
};
#endif // XPLHANDLER_H
Modified: xPLHAL/branches/thomas_s_dev/test/CMakeLists.txt
===================================================================
--- xPLHAL/branches/thomas_s_dev/test/CMakeLists.txt 2011-11-20 21:29:50 UTC (rev 534)
+++ xPLHAL/branches/thomas_s_dev/test/CMakeLists.txt 2011-11-20 21:31:00 UTC (rev 535)
@@ -14,15 +14,31 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#project(xPLHALTest)
cmake_minimum_required(VERSION 2.6)
-set(CMAKE_CXX_FLAGS "-g -Os")
-set(xPLHALTest_SRCS test_test.cpp)
+include(CTest)
-add_executable(test_runner ${xPLHALTest_SRCS})
+find_package(Boost COMPONENTS unit_test_framework REQUIRED)
+
+file(GLOB_RECURSE UnitTests_sources *.cpp)
+
+#set(UnitTest_tsrc ../src/devicemanager.cpp ../src/xplcache.cpp ../src/xplhandler.cpp ../src/xplmessagequeue.cpp)
+set(UnitTest_tsrc ../src/devicemanager.cpp)
+
+add_executable(test_runner ${UnitTests_sources} ${UnitTest_tsrc})
+
+include_directories(../src)
+
+enable_testing()
+
+set(CMAKE_CXX_FLAGS "-g -std=c++0x -fprofile-arcs -ftest-coverage")
+#set(xPLHALTest_SRCS test_test.cpp test_xplcache.cpp)
+#add_executable(test_runner ${xPLHALTest_SRCS})
#message(STATUS "Boost_LIBRARIES=${Boost_LIBRARIES}")
#message(STATUS "LIBRARIES=${LIBS}")
+#message(STATUS "SOURCE=${SOURCES}")
#target_link_libraries(xPLHAL ${Boost_LIBRARIES} -dynamic xPL pthread -static)
-target_link_libraries(test_runner ${LIBS} boost_unit_test_framework-mt)
+target_link_libraries(test_runner ${LIBS})
+add_test(UnitTests test_runner)
+
Added: xPLHAL/branches/thomas_s_dev/test/test_devicemanager.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/test/test_devicemanager.cpp (rev 0)
+++ xPLHAL/branches/thomas_s_dev/test/test_devicemanager.cpp 2011-11-20 21:31:00 UTC (rev 535)
@@ -0,0 +1,147 @@
+#include "../src/devicemanager.h"
+#define BOOST_TEST_MODULE "DeviceManager"
+#include <boost/test/unit_test.hpp>
+
+//#include "xplcache.h"
+#include "devicemanager.h"
+
+// load globas and give them their space to live
+//#include "globals.h"
+
+#if 0
+using namespace boost::filesystem;
+path xPLHalRootFolder;
+path DataFileFolder;
+path ScriptEngineFolder;
+path rulesFolder;
+#endif
+
+
+class MockXplHandler: public IxPLHandler
+{
+ public:
+ void sendBroadcastMessage( const std::string& msgClass, const std::string& msgType, const xPLMessage::namedValueList& namedValues ) const
+ {
+ std::cerr << "sendBroadcastMessage(" << msgClass;
+ std::cerr << std::endl;
+ }
+
+ /** \brief Send a directed message to the xPL network. */
+ void sendMessage( const xPL_MessageType type, const std::string& tgtVendor, const std::string& tgtDeviceID,
+ const std::string& tgtInstanceID, const std::string& msgClass, const std::string& msgType,
+ const xPLMessage::namedValueList& namedValues ) const
+ {
+ std::cerr << "sendMessage";
+ std::cerr << std::endl;
+ }
+
+ /** \brief Send a directed message to the xPL network. */
+ void sendMessage( const xPL_MessageType type, const std::string& VDI,
+ const std::string& msgClass, const std::string& msgType, const xPLMessage::namedValueList& namedValues ) const
+ {
+ std::cerr << "sendMessage";
+ std::cerr << std::endl;
+ }
+};
+
+class MockXplCache: public IxPLCacheClass
+{
+ /** \returns true if the element name exists. */
+ virtual bool exists( const std::string& name ) const
+ {
+ return false;
+ }
+
+ /** \returns the value of element name if it exists - or an empty std::string otherwise. */
+ virtual std::string objectValue( const std::string& name ) const { return ""; }
+
+ /** \returns all objectes stored in the cache. */
+ virtual std::string listAllObjects( bool forceEverything = false ) const { return ""; }
+
+ /** \brief Create a new object or update it if it exists in the cache. */
+ virtual void updateEntry( const std::string& name, const std::string& value, const bool expires = true ) { }
+
+ /** \brief Delete an object if it exists in the cache - or do nothing. */
+ virtual void deleteEntry( const std::string& name ) { }
+
+ /** \brief Delete all expired entries. */
+ virtual void flushExpiredEntries( void ) { }
+
+ /** \returns all entries that start with filter. */
+ virtual std::vector<std::string> childNodes( const std::string& filter ) const { std::vector<std::string> a; return a; }
+
+ /** \returns all entries that fit the regular expression. */
+ virtual std::vector<std::string> filterByRegEx( const boost::regex& regex ) const { std::vector<std::string> a; return a; }
+
+ /** \returns all entries that fit the regular expression. */
+ virtual std::vector<std::string> filterByRegEx( const std::string& regex ) const { std::vector<std::string> a; return a; }
+
+ /** \brief Load object cache from file system */
+ virtual void loadCache( void ) { }
+
+ /** \brief Save object cache to file system */
+ virtual void saveCache( void ) const { }
+};
+
+BOOST_AUTO_TEST_SUITE(DeviceManagerSuite);
+
+BOOST_AUTO_TEST_CASE( add_device )
+{
+ xPL_MessagePtr msg = new xPL_Message;
+ msg->messageType = xPL_MESSAGE_TRIGGER;
+ msg->hopCount = 0;
+ msg->receivedMessage = TRUE; /* TRUE if received, FALSE if being sent */
+ msg->sourceVendor = "pnxs";
+ msg->sourceDeviceID = "hs485";
+ msg->sourceInstanceID = "default1";
+ msg->isGroupMessage = FALSE;
+ msg->groupName = 0;
+ msg->isBroadcastMessage = TRUE;
+ msg->targetVendor = "*";
+ msg->targetDeviceID = "";
+ msg->targetInstanceID = "";
+ msg->schemaClass = "blah";
+ msg->schemaType = "blub";
+ xPL_addMessageNamedValue(msg, "tag", "value");
+
+ MockXplHandler mockHandler;
+ MockXplCache mockCache;
+
+ deviceManagerClass dm(&mockHandler, &mockCache);
+ BOOST_CHECK( dm.contains("pnxs-hs485.default1") == false);
+ dm.processHeartbeat(msg);
+ BOOST_CHECK( dm.contains("pnxs-hs485.default1") == true);
+}
+
+BOOST_AUTO_TEST_CASE( remove_device )
+{
+ xPL_MessagePtr msg = new xPL_Message;
+ msg->messageType = xPL_MESSAGE_TRIGGER;
+ msg->hopCount = 0;
+ msg->receivedMessage = TRUE; /* TRUE if received, FALSE if being sent */
+ msg->sourceVendor = "pnxs";
+ msg->sourceDeviceID = "hs485";
+ msg->sourceInstanceID = "default1";
+ msg->isGroupMessage = FALSE;
+ msg->groupName = 0;
+ msg->isBroadcastMessage = TRUE;
+ msg->targetVendor = "*";
+ msg->targetDeviceID = "";
+ msg->targetInstanceID = "";
+ msg->schemaClass = "blah";
+ msg->schemaType = "blub";
+ xPL_addMessageNamedValue(msg, "tag", "value");
+
+ MockXplHandler mockHandler;
+ MockXplCache mockCache;
+
+ deviceManagerClass dm(&mockHandler, &mockCache);
+ BOOST_CHECK( dm.contains("pnxs-hs485.default1") == false);
+ dm.processHeartbeat(msg);
+ BOOST_CHECK( dm.contains("pnxs-hs485.default1") == true);
+
+ dm.processRemove(msg);
+ BOOST_CHECK( dm.contains("pnxs-hs485.default1") == false);
+}
+
+BOOST_AUTO_TEST_SUITE_END();
Deleted: xPLHAL/branches/thomas_s_dev/test/test_test.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/test/test_test.cpp 2011-11-20 21:29:50 UTC (rev 534)
+++ xPLHAL/branches/thomas_s_dev/test/test_test.cpp 2011-11-20 21:31:00 UTC (rev 535)
@@ -1,8 +0,0 @@
-#define BOOST_TEST_DYN_LINK
-#define BOOST_TEST_MODULE "MyTest"
-#include <boost/test/unit_test.hpp>
-
-BOOST_AUTO_TEST_CASE( my_test )
-{
- BOOST_CHECK( true );
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|