|
From: <tho...@us...> - 2011-12-18 20:39:24
|
Revision: 596
http://openautomation.svn.sourceforge.net/openautomation/?rev=596&view=rev
Author: thomas_s
Date: 2011-12-18 20:39:17 +0000 (Sun, 18 Dec 2011)
Log Message:
-----------
- now using pragma once for header files
- added boost::signals2 for better seperation of classes
- use xPLMessage (C++-Version) for internal use
Modified Paths:
--------------
xPLHAL/branches/thomas_s_dev/src/devicemanager.cpp
xPLHAL/branches/thomas_s_dev/src/devicemanager.h
xPLHAL/branches/thomas_s_dev/src/globals.h
xPLHAL/branches/thomas_s_dev/src/i_properties.h
xPLHAL/branches/thomas_s_dev/src/i_xplcache.h
xPLHAL/branches/thomas_s_dev/src/log.h
xPLHAL/branches/thomas_s_dev/src/main.cpp
xPLHAL/branches/thomas_s_dev/src/response_codes.h
xPLHAL/branches/thomas_s_dev/src/xhcp.h
xPLHAL/branches/thomas_s_dev/src/xhcpthread.h
xPLHAL/branches/thomas_s_dev/src/xplcache.h
xPLHAL/branches/thomas_s_dev/src/xpldevice.h
xPLHAL/branches/thomas_s_dev/src/xplhandler.cpp
xPLHAL/branches/thomas_s_dev/src/xplhandler.h
xPLHAL/branches/thomas_s_dev/src/xplmessage.h
xPLHAL/branches/thomas_s_dev/src/xplmessagequeue.h
Removed Paths:
-------------
xPLHAL/branches/thomas_s_dev/src/i_devicemanager.h
xPLHAL/branches/thomas_s_dev/src/i_xplhandler.h
Modified: xPLHAL/branches/thomas_s_dev/src/devicemanager.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/devicemanager.cpp 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/devicemanager.cpp 2011-12-18 20:39:17 UTC (rev 596)
@@ -29,12 +29,12 @@
using namespace boost::posix_time;
-deviceManagerClass::deviceManagerClass(IxPLHandler* xplhandler, IxPLCacheClass* xplcache)
-:m_xPL(xplhandler)
-,m_xPLCache(xplcache)
+deviceManagerClass::deviceManagerClass(IxPLCacheClass* xplcache)
+:m_xPLCache(xplcache)
{
}
+
void deviceManagerClass::add( const xPLDevice& device )
{
writeLog("deviceManagerClass::add(" + device.VDI + ")", logLevel::debug);
@@ -90,8 +90,40 @@
}
return retval;
}
+
+void deviceManagerClass::processXplMessage( const xPLMessagePtr message )
+{
+ std::string schema = message->msgClass + std::string(".") + message->msgType;
+ if( message->type != xPL_MESSAGE_COMMAND )
+ {
+ if( "config.list" == schema )
+ {
+ // someone (probably we) have asked for the config list - handle it now...
+ processConfigList( message );
+ } else if( "config.current" == schema )
+ {
+ // someone requested the device to send it's current configuration
+ processCurrentConfig( message );
+ } else if( "config.app" == schema || "config.basic" == schema )
+ {
+ // a new device poped up and wants to be configured
+ processConfigHeartBeat( message );
+ } else if( "hbeat.basic" == schema || "hbeat.app" == schema )
+ {
+ /*
+ If msgSource = MySourceTag Then
+ RaiseEvent AddtoCache("xplhal." & msgSource & ".alive", Now.ToString, False)
+ End If
+ */
+ processHeartbeat( message );
+ } else if( "hbeat.end" == schema )
+ {
+ processRemove( message );
+ }
+ }
+}
-void deviceManagerClass::processConfigList( const xPL_MessagePtr message )
+void deviceManagerClass::processConfigList( const xPLMessagePtr message )
{
std::string source = extractSourceFromXplMessage(message);
xPLDevice device = getDevice( source );
@@ -100,7 +132,9 @@
// A config list turned up that we haven't asked for...
// create a new device...
int interval = 5;
- ptime expires = calculateExpireTime(xPL_getMessageNamedValue(message, "interval"), &interval);
+ //\TODO: implement xPL_getMessageNamedValue
+// ptime expires = calculateExpireTime(xPL_getMessageNamedValue(message, "interval"), &interval);
+ ptime expires = calculateExpireTime("5", &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
@@ -115,14 +149,12 @@
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( auto entry : message->namedValues) {
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 );
+ std::string value = entry.first;
+ to_lower(value);
+ std::string key = entry.second;
+ to_lower(key);
boost::regex re( "([a-z0-9]{1,16})\\[(\\d{1,3})\\]" );
boost::smatch matches;
if (boost::regex_match(value, matches, re)) {
@@ -145,9 +177,13 @@
else {
// try to get at least the current config
xPLMessage::namedValueList command_request; command_request.push_back( std::make_pair( "command", "request" ) );
- m_xPL->sendMessage( xPL_MESSAGE_COMMAND,
- xPL_getSourceVendor( message ), xPL_getSourceDeviceID( message ), xPL_getSourceInstanceID( message ),
- "config", "current", command_request );
+ xPLMessagePtr msg( new xPLMessage(xPL_MESSAGE_COMMAND,
+ message->vendor,
+ message->deviceID,
+ message->instanceID,
+ "config", "current",
+ command_request) );
+ m_sigSendXplMessage(msg);
}
}
@@ -165,7 +201,7 @@
return second_clock::local_time() + minutes( 2* interval + 1 );
}
-void deviceManagerClass::processConfigHeartBeat( const xPL_MessagePtr message )
+void deviceManagerClass::processConfigHeartBeat( const xPLMessagePtr message )
{
std::string source = extractSourceFromXplMessage(message);
@@ -175,7 +211,9 @@
// 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.
int interval = 5;
- ptime expires = calculateExpireTime(xPL_getMessageNamedValue(message, "interval"), &interval);
+ //\TODO
+// ptime expires = calculateExpireTime(xPL_getMessageNamedValue(message, "interval"), &interval);
+ ptime expires = calculateExpireTime("5", &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
@@ -198,14 +236,18 @@
// 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" ) );
- m_xPL->sendMessage( xPL_MESSAGE_COMMAND,
- xPL_getSourceVendor( message ), xPL_getSourceDeviceID( message ), xPL_getSourceInstanceID( message ),
- "config", "list", command_request );
+ xPLMessagePtr msg( new xPLMessage(xPL_MESSAGE_COMMAND,
+ message->vendor,
+ message->deviceID,
+ message->instanceID,
+ "config", "list",
+ command_request) );
+ m_sigSendXplMessage(msg);
mDeviceMap[device.VDI].ConfigListSent = true;
}
}
-void deviceManagerClass::processCurrentConfig( const xPL_MessagePtr message )
+void deviceManagerClass::processCurrentConfig( const xPLMessagePtr message )
{
std::string source = extractSourceFromXplMessage(message);
xPLDevice device = getDevice( source );
@@ -220,16 +262,14 @@
// 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 );
- xPL_NameValuePairPtr nvPair = NULL;
- int nvCount = xPL_getNamedValueCount(nvList);
+
std::string multiKey;
- int multiCount = 0;
- for( int nvIndex = 0; nvIndex < nvCount; nvIndex++ ) {
- nvPair = xPL_getNamedValuePairAt( nvList, nvIndex );
- std::string value = nvPair->itemValue; to_lower( value );
- std::string key = nvPair->itemName ; to_lower( key );
+ int multiCount = 0;
+ for( auto entry : message->namedValues) {
+ std::string value = entry.first;
+ to_lower(value);
+ std::string key = entry.second;
+ to_lower(key);
std::string count = m_xPLCache->objectValue( "config." + source + ".options." + key + ".count" );
if( "" != count ) {
if( multiKey == key ) {
@@ -253,14 +293,22 @@
+ xPL_getSourceInstanceID( message );
}
+std::string deviceManagerClass::extractSourceFromXplMessage( xPLMessagePtr message )
+{
+ return std::string(message->vendor + "-"
+ + message->deviceID + "."
+ + message->instanceID);
+}
-void deviceManagerClass::processHeartbeat( xPL_MessagePtr message )
+void deviceManagerClass::processHeartbeat( xPLMessagePtr message )
{
std::string source = extractSourceFromXplMessage(message);
xPLDevice device = getDevice( source );
int interval = 5;
- ptime expires = calculateExpireTime(xPL_getMessageNamedValue(message, "interval"), &interval);
+ //\TODO
+// ptime expires = calculateExpireTime(xPL_getMessageNamedValue(message, "interval"), &interval);
+ ptime expires = calculateExpireTime("5", &interval);
writeLog( "deviceManagerClass::processHeartbeat("+source+") - found ["+device.VDI+"]", logLevel::debug );
if( "" == device.VDI ) {
@@ -281,9 +329,13 @@
// Throw it a config request anyway, see what turns up..
xPLMessage::namedValueList command_request; command_request.push_back( std::make_pair( "command", "request" ) );
- m_xPL->sendMessage( xPL_MESSAGE_COMMAND,
- xPL_getSourceVendor( message ), xPL_getSourceDeviceID( message ), xPL_getSourceInstanceID( message ),
- "config", "list" , command_request );
+ xPLMessagePtr msg( new xPLMessage(xPL_MESSAGE_COMMAND,
+ message->vendor,
+ message->deviceID,
+ message->instanceID,
+ "config", "list",
+ command_request) );
+ m_sigSendXplMessage(msg);
/* // that code below was from the VB - but we don't need it as processConfigList will
// itself send the config.current request...
m_xPL->sendMessage( xPL_MESSAGE_COMMAND,
@@ -295,7 +347,7 @@
}
}
-void deviceManagerClass::processRemove( xPL_MessagePtr message )
+void deviceManagerClass::processRemove( xPLMessagePtr message )
{
std::string source = extractSourceFromXplMessage(message);
@@ -319,7 +371,18 @@
}
if( list.size() > 0 ) {
- m_xPL->sendMessage( xPL_MESSAGE_COMMAND, source, "config", "response", list );
+ size_t marker1 = source.find( "-" );
+ size_t marker2 = source.find( "." );
+ std::string vendor = source.substr( 0, marker1 );
+ std::string device = source.substr( marker1+1, marker2 - (marker1+1) );
+ std::string instance = source.substr( marker2+1 );
+ xPLMessagePtr msg( new xPLMessage(xPL_MESSAGE_COMMAND,
+ vendor,
+ device,
+ instance,
+ "config", "response",
+ list) );
+ m_sigSendXplMessage(msg);
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"...
@@ -379,3 +442,7 @@
return m_xPLCache->childNodes( "config." + configTag ).size() > 0;
}
+boost::signals2::connection deviceManagerClass::connect(const xPLHandler::signal_t::slot_type &subscriber)
+{
+ return m_sigSendXplMessage.connect(subscriber);
+}
Modified: xPLHAL/branches/thomas_s_dev/src/devicemanager.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/devicemanager.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/devicemanager.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,3 +1,4 @@
+#pragma once
/*
xPLHAL implementation in C++
Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
@@ -16,27 +17,22 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef DEVICEMANAGER_H
-#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 "xplhandler.h"
#include "xplcache.h"
#include "globals.h"
#include "xpldevice.h"
-#include "i_devicemanager.h"
-class deviceManagerClass: public IdeviceManagerClass
+class deviceManagerClass
{
public:
- deviceManagerClass(IxPLHandler* xplhandler, IxPLCacheClass* xplcache);
+ deviceManagerClass(IxPLCacheClass* xplcache);
+
+ boost::signals2::connection connect(const xPLHandler::signal_t::slot_type &subscriber);
/** \brief Looks if the device deviceTag is known. */
bool contains( const std::string& deviceTag ) const;
@@ -54,16 +50,19 @@
/** \brief Returns all known device names */
std::vector<std::string> getAllDeviceNames() const;
+ /** \brief process incoming xpl messages and check if they are for us */
+ void processXplMessage( const xPLMessagePtr message );
+
/** \brief Handle the returned config list that someone (porbably we) have asked for */
- void processConfigList ( const xPL_MessagePtr message );
+ void processConfigList ( const xPLMessagePtr message );
/** \brief Called when a new device poped up and is waiting to be configured */
- void processConfigHeartBeat( const xPL_MessagePtr message );
+ void processConfigHeartBeat( const xPLMessagePtr message );
/** \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 processCurrentConfig ( const xPLMessagePtr message );
+ void processHeartbeat ( const xPLMessagePtr message );
+ void processRemove ( const xPLMessagePtr message );
void sendConfigResponse( const std::string& source, const bool removeOldValue );
@@ -73,12 +72,12 @@
private:
/*! \TODO: move to correct class, maybe xplMessage */
std::string extractSourceFromXplMessage( xPL_MessagePtr message );
+ std::string extractSourceFromXplMessage( xPLMessagePtr 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;
+ xPLHandler::signal_t m_sigSendXplMessage;
};
-
-#endif // DEVICEMANAGER_H
Modified: xPLHAL/branches/thomas_s_dev/src/globals.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/globals.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/globals.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,3 +1,4 @@
+#pragma once
/*
xPLHAL implementation in C++
Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
@@ -16,9 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef GLOBALS_H
-#define GLOBALS_H
-
#include "boost/filesystem.hpp"
/**
@@ -44,5 +42,3 @@
extern boost::filesystem::path DataFileFolder;
extern boost::filesystem::path ScriptEngineFolder;
extern boost::filesystem::path rulesFolder;
-
-#endif // GLOBALS_H
Deleted: xPLHAL/branches/thomas_s_dev/src/i_devicemanager.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/i_devicemanager.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/i_devicemanager.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,42 +0,0 @@
-/*
- 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
Modified: xPLHAL/branches/thomas_s_dev/src/i_properties.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/i_properties.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/i_properties.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,5 +1,4 @@
-#ifndef __I_PROPERTIES_H__
-#define __I_PROPERTIES_H__
+#pragma once
//! \brief Properties Interface
class IProperties
@@ -19,5 +18,3 @@
/** \brief deletes property */
virtual void deleteProperty(const std::string& name) = 0;
};
-
-#endif
Modified: xPLHAL/branches/thomas_s_dev/src/i_xplcache.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/i_xplcache.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/i_xplcache.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,3 +1,4 @@
+#pragma once
/*
xPLHAL implementation in C++
Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
@@ -16,9 +17,6 @@
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>
@@ -62,5 +60,3 @@
/** \brief Save object cache to file system */
virtual void saveCache( void ) const = 0;
};
-
-#endif // IXPLCACHE_H
Deleted: xPLHAL/branches/thomas_s_dev/src/i_xplhandler.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/i_xplhandler.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/i_xplhandler.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,50 +0,0 @@
-/*
- 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/log.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/log.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/log.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,3 +1,4 @@
+#pragma once
/*
xPLHAL implementation in C++
Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
@@ -16,9 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef LOG_H
-#define LOG_H
-
#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/lexical_cast.hpp>
@@ -119,5 +117,3 @@
doLog( m, level );
}
} static writeLog;
-
-#endif // LOG_H
Modified: xPLHAL/branches/thomas_s_dev/src/main.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/main.cpp 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/main.cpp 2011-12-18 20:39:17 UTC (rev 596)
@@ -107,8 +107,8 @@
xPLCache = new xPLCacheClass;
XHCPServer *xhcpServer = new XHCPServer();
xPL = new xPLHandler( boost::asio::ip::host_name() ); //xPL->start();
- deviceManager = new deviceManagerClass(xPL, xPLCache);
- xPL->setDeviceManager(deviceManager);
+ deviceManager = new deviceManagerClass(xPLCache);
+ xPL->connect(boost::bind(&deviceManagerClass::processXplMessage, deviceManager, _1));
writeLog( "started", logLevel::all );
// force everyone to send their configuration so that we start up to date...
Modified: xPLHAL/branches/thomas_s_dev/src/response_codes.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/response_codes.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/response_codes.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,3 +1,4 @@
+#pragma once
/*
xPLHAL implementation in C++
Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
@@ -16,9 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef RESPONSE_CODES_H
-#define RESPONSE_CODES_H
-
#include <map>
#include <string>
@@ -108,4 +106,3 @@
std::string operator()( int code ) { return std::string(codes[code]); }
} static responseCode;
-#endif /* RESPONSE_CODES_H */
\ No newline at end of file
Modified: xPLHAL/branches/thomas_s_dev/src/xhcp.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xhcp.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/xhcp.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,3 +1,4 @@
+#pragma once
/*
xPLHAL implementation in C++
Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
@@ -16,9 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef XHCP_H
-#define XHCP_H
-
#include <boost/asio.hpp>
#include <boost/thread.hpp>
@@ -46,5 +44,3 @@
void handleAccept(socket_ptr sockPtr);
void startAccept();
};
-
-#endif // XHCP_H
Modified: xPLHAL/branches/thomas_s_dev/src/xhcpthread.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xhcpthread.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/xhcpthread.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,3 +1,4 @@
+#pragma once
/*
xPLHAL implementation in C++
Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
@@ -16,9 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef XHCPTHREAD_H
-#define XHCPTHREAD_H
-
#include <map>
#include <boost/smart_ptr.hpp>
@@ -87,5 +85,3 @@
boost::thread m_thread;
};
-
-#endif // XHCPTHREAD_H
Modified: xPLHAL/branches/thomas_s_dev/src/xplcache.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplcache.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/xplcache.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,3 +1,4 @@
+#pragma once
/*
xPLHAL implementation in C++
Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
@@ -16,9 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef XPLCACHE_H
-#define XPLCACHE_H
-
#include <string>
#include <vector>
#include <map>
@@ -155,5 +153,3 @@
/** \brief Save object cache to file system */
void saveCache( void ) const;
};
-
-#endif // XPLCACHE_H
Modified: xPLHAL/branches/thomas_s_dev/src/xpldevice.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xpldevice.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/xpldevice.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,3 +1,4 @@
+#pragma once
/*
xPLHAL implementation in C++
Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
@@ -16,9 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef __XPLDEVICE_H__
-#define __XPLDEVICE_H__
-
#include <string>
#include <boost/date_time/posix_time/posix_time.hpp>
@@ -36,5 +34,3 @@
bool Suspended; /** \brief lost heartbeat */
bool Current; /** \brief asked for current */
};
-
-#endif
Modified: xPLHAL/branches/thomas_s_dev/src/xplhandler.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplhandler.cpp 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/xplhandler.cpp 2011-12-18 20:39:17 UTC (rev 596)
@@ -21,7 +21,6 @@
using namespace boost::algorithm;
#include "log.h"
-#include "i_devicemanager.h"
#include "xplhandler.h"
#include "globals.h"
@@ -32,13 +31,12 @@
int xPLHandler::m_refcount = 0;
-xPLHandler::xPLHandler( const std::string& host_name, IdeviceManagerClass* devManager )
+xPLHandler::xPLHandler( const std::string& host_name)
: 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);
@@ -102,11 +100,6 @@
}
}
-void xPLHandler::setDeviceManager(IdeviceManagerClass* devManager)
-{
- m_deviceManager = devManager;
-}
-
void xPLHandler::run()
{
writeLog( "xPLHandler::run()", logLevel::debug );
@@ -164,11 +157,9 @@
std::string result;
/* Source Info */
- result += xPL_getSourceVendor(theMessage);
- result += "-";
- result += xPL_getSourceDeviceID(theMessage);
- result += ".",
- result += xPL_getSourceInstanceID(theMessage);
+ result += xPL_getSourceVendor(theMessage) + std::string("-");
+ result += xPL_getSourceDeviceID(theMessage) + std::string(".");
+ result += xPL_getSourceInstanceID(theMessage);
result += " -> ";
/* Handle various target types */
@@ -179,10 +170,8 @@
result += "XPL-GROUP.";
result += xPL_getTargetGroup(theMessage);
} else {
- result += xPL_getTargetVendor(theMessage);
- result += "-";
- result += xPL_getTargetDeviceID(theMessage);
- result += ".";
+ result += xPL_getTargetVendor(theMessage) + std::string("-");
+ result += xPL_getTargetDeviceID(theMessage) + std::string(".");
result += xPL_getTargetInstanceID(theMessage);
}
}
@@ -211,10 +200,8 @@
result += "] ";
/* Echo Schema Info */
- result += xPL_getSchemaClass(theMessage);
- result += ".";
- result += xPL_getSchemaType(theMessage);
- result += ": ";
+ result += xPL_getSchemaClass(theMessage) + std::string(".");
+ result += xPL_getSchemaType(theMessage) + std::string(": ");
xPL_NameValueListPtr nvList = xPL_getMessageBody(theMessage);
xPL_NameValuePairPtr nvPair = NULL;
@@ -251,36 +238,34 @@
void xPLHandler::handleXPLMessage( xPL_MessagePtr theMessage)
{
printXPLMessage( theMessage );
-
- //RaiseEvent ParseMessageForCache(e.XplMsg)
- //RaiseEvent ParseMessageForRules(e.XplMsg)
-
- std::string schema = xPL_getSchemaClass(theMessage) + std::string(".") + xPL_getSchemaType(theMessage);
- if( xPL_getMessageType(theMessage) != xPL_MESSAGE_COMMAND )
- {
- if( "config.list" == schema )
- {
- // someone (probably we) have asked for the config list - handle it now...
- m_deviceManager->processConfigList( theMessage );
- } else if( "config.current" == schema )
- {
- // someone requested the device to send it's current configuration
- m_deviceManager->processCurrentConfig( theMessage );
- } else if( "config.app" == schema || "config.basic" == schema )
- {
- // a new device poped up and wants to be configured
- m_deviceManager->processConfigHeartBeat( theMessage );
- } else if( "hbeat.basic" == schema || "hbeat.app" == schema )
- {
- /*
- If msgSource = MySourceTag Then
- RaiseEvent AddtoCache("xplhal." & msgSource & ".alive", Now.ToString, False)
- End If
- */
- m_deviceManager->processHeartbeat( theMessage );
- } else if( "hbeat.end" == schema )
- {
- m_deviceManager->processRemove( theMessage );
+
+ xPLMessage::namedValueList values;
+ xPL_NameValueListPtr nvList = xPL_getMessageBody(theMessage);
+ xPL_NameValuePairPtr nvPair = NULL;
+ int nvIndex = 0;
+ int nvCount = xPL_getNamedValueCount(nvList);
+ /* Write Name/Value Pairs out */
+ for (nvIndex = 0; nvIndex < nvCount; nvIndex++) {
+ nvPair = xPL_getNamedValuePairAt(nvList, nvIndex);
+
+ if (nvPair->itemValue != NULL) {
+ values.push_back( std::make_pair( nvPair->itemName, nvPair->itemValue ) );
}
}
+ xPLMessagePtr msg( new xPLMessage( xPL_getMessageType(theMessage),
+ xPL_getSourceVendor(theMessage),
+ xPL_getSourceDeviceID(theMessage),
+ xPL_getSourceInstanceID(theMessage),
+ xPL_getSchemaClass(theMessage),
+ xPL_getSchemaType(theMessage),
+ values) );
+
+ m_sigRceivedXplMessage(msg);
+
}
+
+boost::signals2::connection xPLHandler::connect(const signal_t::slot_type &subscriber)
+{
+ return m_sigRceivedXplMessage.connect(subscriber);
+}
+
Modified: xPLHAL/branches/thomas_s_dev/src/xplhandler.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplhandler.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/xplhandler.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,3 +1,4 @@
+#pragma once
/*
xPLHAL implementation in C++
Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
@@ -16,36 +17,32 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
-#ifndef XPLHANDLER_H
-#define XPLHANDLER_H
-
#include <vector>
#include <string>
#include <boost/thread.hpp>
#include <boost/thread/locks.hpp>
+#include <boost/signals2/signal.hpp>
// this is also including the xPL.h
-#include "i_xplhandler.h"
#include "xplmessagequeue.h"
-class IdeviceManagerClass;
-
/**
* \brief Handle all xPL communication.
*/
-class xPLHandler: public IxPLHandler
+class xPLHandler
{
/** \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:
+ typedef boost::signals2::signal<void (xPLMessagePtr)> signal_t;
public:
- xPLHandler( const std::string& host_name, IdeviceManagerClass* devManager = 0);
+ xPLHandler( const std::string& host_name);
~xPLHandler();
- void setDeviceManager(IdeviceManagerClass* devManager);
+ boost::signals2::connection connect(const signal_t::slot_type &subscriber);
void run();
@@ -78,7 +75,5 @@
boost::thread* m_thread;
static int m_refcount;
bool m_exit_thread;
- IdeviceManagerClass* m_deviceManager;
+ signal_t m_sigRceivedXplMessage;
};
-
-#endif // XPLHANDLER_H
Modified: xPLHAL/branches/thomas_s_dev/src/xplmessage.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplmessage.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/xplmessage.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,3 +1,4 @@
+#pragma once
/*
xPLHAL implementation in C++
Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
@@ -16,9 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef XPLMESSAGE_H
-#define XPLMESSAGE_H
-
#include <vector>
#include <string>
#include <boost/shared_ptr.hpp>
@@ -62,5 +60,3 @@
msgClass(_msgClass), msgType(_msgType), namedValues(_namedValues) {}
};
typedef boost::shared_ptr<xPLMessage> xPLMessagePtr;
-
-#endif // XPLMESSAGEQUEUE_H
Modified: xPLHAL/branches/thomas_s_dev/src/xplmessagequeue.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplmessagequeue.h 2011-12-18 16:24:30 UTC (rev 595)
+++ xPLHAL/branches/thomas_s_dev/src/xplmessagequeue.h 2011-12-18 20:39:17 UTC (rev 596)
@@ -1,3 +1,4 @@
+#pragma once
/*
xPLHAL implementation in C++
Copyright (C) 2009 by Christian Mayer - xpl at ChristianMayer dot de
@@ -16,9 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef XPLMESSAGEQUEUE_H
-#define XPLMESSAGEQUEUE_H
-
#include <vector>
#include <queue>
#include <string>
@@ -50,5 +48,3 @@
\returns Returns 0 if no message available or the message. */
xPL_MessagePtr consume( const xPL_ServicePtr& service );
};
-
-#endif // XPLMESSAGEQUEUE_H
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|