|
From: <tho...@us...> - 2012-01-01 21:57:53
|
Revision: 624
http://openautomation.svn.sourceforge.net/openautomation/?rev=624&view=rev
Author: thomas_s
Date: 2012-01-01 21:57:46 +0000 (Sun, 01 Jan 2012)
Log Message:
-----------
added 'using std::string'
replaced 'using namespace' by 'using <class>'
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/xhcp.cpp
xPLHAL/branches/thomas_s_dev/src/xhcp.h
xPLHAL/branches/thomas_s_dev/src/xhcpthread.cpp
xPLHAL/branches/thomas_s_dev/src/xhcpthread.h
xPLHAL/branches/thomas_s_dev/src/xplcache.cpp
xPLHAL/branches/thomas_s_dev/src/xplhandler.cpp
xPLHAL/branches/thomas_s_dev/src/xplmessage.cpp
Modified: xPLHAL/branches/thomas_s_dev/src/devicemanager.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/devicemanager.cpp 2012-01-01 21:56:16 UTC (rev 623)
+++ xPLHAL/branches/thomas_s_dev/src/devicemanager.cpp 2012-01-01 21:57:46 UTC (rev 624)
@@ -19,23 +19,31 @@
#include <boost/regex.hpp>
#include <cstdio>
-using namespace boost::algorithm;
+using boost::algorithm::to_lower;
+using boost::algorithm::split;
+using boost::algorithm::is_any_of;
+using boost::algorithm::token_compress_on;
#include "log.h"
#include "devicemanager.h"
#include "i_xplcache.h"
-using namespace boost::posix_time;
+using boost::posix_time::ptime;
+using boost::posix_time::second_clock;
+using boost::posix_time::minutes;
-deviceManagerClass::deviceManagerClass(IxPLCacheClass* xplcache)
+using std::string;
+using std::vector;
+
+DeviceManager::DeviceManager(IxPLCacheClass* xplcache)
:m_xPLCache(xplcache)
{
}
-void deviceManagerClass::add( const xPLDevice& device )
+void DeviceManager::add( const xPLDevice& device )
{
- writeLog("deviceManagerClass::add(" + device.VDI + ")", logLevel::debug);
+ writeLog("DeviceManager::add(" + device.VDI + ")", logLevel::debug);
if (contains( device.VDI )) {
mDeviceMap[device.VDI] = device;
} else {
@@ -44,9 +52,9 @@
}
}
-bool deviceManagerClass::remove( const std::string& deviceTag )
+bool DeviceManager::remove( const string& deviceTag )
{
- writeLog( "deviceManagerClass::remove("+deviceTag+")", logLevel::debug );
+ writeLog( "DeviceManager::remove("+deviceTag+")", logLevel::debug );
auto device = mDeviceMap.find(deviceTag);
if (device != mDeviceMap.end()) {
mDeviceMap.erase(device);
@@ -55,11 +63,11 @@
return false;
}
-bool deviceManagerClass::removeConfig( const std::string& deviceTag ) const
+bool DeviceManager::removeConfig( const string& deviceTag ) const
{
- writeLog( "deviceManagerClass::remove("+deviceTag+")", logLevel::debug );
+ writeLog( "DeviceManager::remove("+deviceTag+")", logLevel::debug );
if( containsConfig( deviceTag ) ) {
- std::vector<std::string> list = m_xPLCache->childNodes( "config." + deviceTag );
+ vector<string> list = m_xPLCache->childNodes( "config." + deviceTag );
for (auto listitem : list) {
m_xPLCache->deleteEntry(listitem);
}
@@ -68,7 +76,7 @@
return false;
}
-xPLDevice deviceManagerClass::getDevice( const std::string& deviceTag ) const
+xPLDevice DeviceManager::getDevice( const string& deviceTag ) const
{
xPLDevice retval;
auto device = mDeviceMap.find(deviceTag);
@@ -78,20 +86,20 @@
return retval;
}
-std::vector<std::string> deviceManagerClass::getAllDeviceNames() const
+vector<string> DeviceManager::getAllDeviceNames() const
{
- std::vector<std::string> retval;
+ vector<string> retval;
retval.reserve(mDeviceMap.size());
for (auto node : mDeviceMap) {
retval.push_back(node.first);
- writeLog( "deviceManagerClass::getAllDeviceNames() = "+ node.first, logLevel::debug );
+ writeLog( "DeviceManager::getAllDeviceNames() = "+ node.first, logLevel::debug );
}
return retval;
}
-void deviceManagerClass::processXplMessage( const xPLMessagePtr message )
+void DeviceManager::processXplMessage( const xPLMessagePtr message )
{
- std::string schema = message->msgClass + std::string(".") + message->msgType;
+ string schema = message->msgClass + string(".") + message->msgType;
if( message->type != xPL_MESSAGE_COMMAND )
{
if( "config.list" == schema )
@@ -121,11 +129,11 @@
}
}
-void deviceManagerClass::processConfigList( const xPLMessagePtr message )
+void DeviceManager::processConfigList( const xPLMessagePtr message )
{
- std::string source = message->getSourceVDI();
+ string source = message->getSourceVDI();
xPLDevice device = getDevice( source );
- writeLog( "deviceManagerClass::processConfigList("+source+") - found ["+device.VDI+"]", logLevel::debug );
+ writeLog( "DeviceManager::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...
@@ -146,10 +154,10 @@
}
for( auto entry : message->namedValues) {
- std::string newtag = "config." + source + ".options.";
- std::string value = entry.first;
+ string newtag = "config." + source + ".options.";
+ string value = entry.first;
to_lower(value);
- std::string key = entry.second;
+ string key = entry.second;
to_lower(key);
boost::regex re( "([a-z0-9]{1,16})\\[(\\d{1,3})\\]" );
boost::smatch matches;
@@ -180,7 +188,7 @@
}
}
-ptime deviceManagerClass::calculateExpireTime(const std::string& string_interval, int *pInterval)
+ptime DeviceManager::calculateExpireTime(const string& string_interval, int *pInterval)
{
int interval = string_interval.empty() ? atoi(string_interval.c_str()) : 5; // default to 5 minutes
if (pInterval) {
@@ -189,17 +197,17 @@
return calculateExpireTime(interval);
}
-ptime deviceManagerClass::calculateExpireTime(int interval)
+ptime DeviceManager::calculateExpireTime(int interval)
{
return second_clock::local_time() + minutes( 2* interval + 1 );
}
-void deviceManagerClass::processConfigHeartBeat( const xPLMessagePtr message )
+void DeviceManager::processConfigHeartBeat( const xPLMessagePtr message )
{
- std::string source = message->getSourceVDI();
+ string source = message->getSourceVDI();
xPLDevice device = getDevice( source );
- writeLog( "deviceManagerClass::processConfigHeartBeat("+source+") - found ["+device.VDI+"]", logLevel::debug );
+ writeLog( "DeviceManager::processConfigHeartBeat("+source+") - found ["+device.VDI+"]", logLevel::debug );
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.
@@ -235,11 +243,11 @@
}
}
-void deviceManagerClass::processCurrentConfig( const xPLMessagePtr message )
+void DeviceManager::processCurrentConfig( const xPLMessagePtr message )
{
- std::string source = message->getSourceVDI();
+ string source = message->getSourceVDI();
xPLDevice device = getDevice( source );
- writeLog( "deviceManagerClass::processCurrentConfig("+source+") - found ["+device.VDI+"]", logLevel::debug );
+ writeLog( "DeviceManager::processCurrentConfig("+source+") - found ["+device.VDI+"]", logLevel::debug );
if( "" == device.VDI ) {
// A current config turned up for a device that we don't know...
// Processing the current config doesn't make sense as long as we don't know the config list
@@ -251,14 +259,14 @@
m_xPLCache->updateEntry( "config." + source + ".current", "true", false );
}
- std::string multiKey;
+ string multiKey;
int multiCount = 0;
for( auto entry : message->namedValues) {
- std::string value = entry.first;
+ string value = entry.first;
to_lower(value);
- std::string key = entry.second;
+ string key = entry.second;
to_lower(key);
- std::string count = m_xPLCache->objectValue( "config." + source + ".options." + key + ".count" );
+ string count = m_xPLCache->objectValue( "config." + source + ".options." + key + ".count" );
if( "" != count ) {
if( multiKey == key ) {
multiCount++;
@@ -274,14 +282,14 @@
}
}
-void deviceManagerClass::processHeartbeat( xPLMessagePtr message )
+void DeviceManager::processHeartbeat( xPLMessagePtr message )
{
- std::string source = message->getSourceVDI();
+ string source = message->getSourceVDI();
xPLDevice device = getDevice( source );
int interval = 5;
ptime expires = calculateExpireTime(message->getNamedValue("interval"), &interval);
- writeLog( "deviceManagerClass::processHeartbeat("+source+") - found ["+device.VDI+"]", logLevel::debug );
+ writeLog( "DeviceManager::processHeartbeat("+source+") - found ["+device.VDI+"]", logLevel::debug );
if( "" == device.VDI ) {
// this handles a new application that identifies itself with a hbeat straight away.
@@ -316,24 +324,24 @@
}
}
-void deviceManagerClass::processRemove( xPLMessagePtr message )
+void DeviceManager::processRemove( xPLMessagePtr message )
{
- std::string source = message->getSourceVDI();
+ string source = message->getSourceVDI();
remove( source );
removeConfig( source );
}
-void deviceManagerClass::sendConfigResponse( const std::string& source, const bool removeOldValue )
+void DeviceManager::sendConfigResponse( const string& source, const bool removeOldValue )
{
- writeLog( "deviceManagerClass::sendConfigResponse("+source+", "+(removeOldValue?"true":"false")+")", logLevel::debug );
+ writeLog( "DeviceManager::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 = m_xPLCache->filterByRegEx( re );
+ vector<string> entries = m_xPLCache->filterByRegEx( re );
xPLMessage::namedValueList list;
for( auto entry : entries) {
boost::smatch matches;
boost::regex_match( entry, matches, re );
- writeLog( "deviceManagerClass::sendConfigResponse: ["+entry+"] -> ["+matches[1]+"]("+matches[2]+")",logLevel::debug );
+ writeLog( "DeviceManager::sendConfigResponse: ["+entry+"] -> ["+matches[1]+"]("+matches[2]+")",logLevel::debug );
if( matches.size() > 1 ) {
list.push_back( std::make_pair( matches[1], m_xPLCache->objectValue( entry ) ) );
}
@@ -356,24 +364,24 @@
}
}
-bool deviceManagerClass::storeNewConfig( const std::string& source, const std::string& config )
+bool DeviceManager::storeNewConfig( const string& source, const string& config )
{
- writeLog( "deviceManagerClass::storeNewConfig("+source+", "+config+")", logLevel::debug );
+ writeLog( "DeviceManager::storeNewConfig("+source+", "+config+")", logLevel::debug );
auto device = mDeviceMap.find(source);
if (device == mDeviceMap.end()) {
return false;
}
- std::vector<std::string> list;
+ vector<string> list;
split( list, config, is_any_of("\r\n"), token_compress_on );
- std::string multiKey;
+ string multiKey;
int multiCount = 0;
for( auto listitem : list) {
- std::vector<std::string> tags;
+ vector<string> tags;
split( tags, listitem, is_any_of("=") );
to_lower( tags[0] );
to_lower( tags[1] );
- std::string count = m_xPLCache->objectValue( "config." + source + ".options." + tags[0] + ".count" );
+ string count = m_xPLCache->objectValue( "config." + source + ".options." + tags[0] + ".count" );
if( "" != count ) {
if( multiKey != tags[0] ) {
multiKey = tags[0];
@@ -394,12 +402,12 @@
return true;
}
-bool deviceManagerClass::contains( const std::string& deviceTag ) const
+bool DeviceManager::contains( const string& deviceTag ) const
{
return mDeviceMap.find(deviceTag) != mDeviceMap.end();
}
-bool deviceManagerClass::containsConfig( const std::string& configTag ) const
+bool DeviceManager::containsConfig( const 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 2012-01-01 21:56:16 UTC (rev 623)
+++ xPLHAL/branches/thomas_s_dev/src/devicemanager.h 2012-01-01 21:57:46 UTC (rev 624)
@@ -27,10 +27,10 @@
#include "globals.h"
#include "xpldevice.h"
-class deviceManagerClass
+class DeviceManager
{
public:
- deviceManagerClass(IxPLCacheClass* xplcache);
+ DeviceManager(IxPLCacheClass* xplcache);
/** \brief Looks if the device deviceTag is known. */
bool contains( const std::string& deviceTag ) const;
Modified: xPLHAL/branches/thomas_s_dev/src/globals.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/globals.h 2012-01-01 21:56:16 UTC (rev 623)
+++ xPLHAL/branches/thomas_s_dev/src/globals.h 2012-01-01 21:57:46 UTC (rev 624)
@@ -28,9 +28,6 @@
class xPLCacheClass;
extern xPLCacheClass *xPLCache;
-class deviceManagerClass;
-extern deviceManagerClass *deviceManager;
-
class xPLHandler;
extern xPLHandler *xPL;
Modified: xPLHAL/branches/thomas_s_dev/src/xhcp.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xhcp.cpp 2012-01-01 21:56:16 UTC (rev 623)
+++ xPLHAL/branches/thomas_s_dev/src/xhcp.cpp 2012-01-01 21:57:46 UTC (rev 624)
@@ -23,9 +23,10 @@
using boost::asio::ip::tcp;
-XHCPServer::XHCPServer(boost::asio::io_service& io)
+XHCPServer::XHCPServer(boost::asio::io_service& io, DeviceManager* dm)
:m_io(io)
,m_acceptor(io, tcp::endpoint(tcp::v4(), 3865))
+,m_dm(dm)
{
startAccept();
}
@@ -45,6 +46,6 @@
void XHCPServer::handleAccept(socket_ptr sockPtr)
{
startAccept();
- XHCPThread* foo = new XHCPThread( sockPtr );
+ XHCPThread* foo = new XHCPThread(sockPtr, m_dm);
}
Modified: xPLHAL/branches/thomas_s_dev/src/xhcp.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xhcp.h 2012-01-01 21:56:16 UTC (rev 623)
+++ xPLHAL/branches/thomas_s_dev/src/xhcp.h 2012-01-01 21:57:46 UTC (rev 624)
@@ -33,7 +33,7 @@
//boost::thread m_thread;
public:
- XHCPServer(boost::asio::io_service& io);
+ XHCPServer(boost::asio::io_service& io, DeviceManager* dm);
~XHCPServer();
protected:
@@ -46,4 +46,5 @@
private:
boost::asio::io_service& m_io;
boost::asio::ip::tcp::tcp::acceptor m_acceptor;
+ DeviceManager* m_dm;
};
Modified: xPLHAL/branches/thomas_s_dev/src/xhcpthread.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xhcpthread.cpp 2012-01-01 21:56:16 UTC (rev 623)
+++ xPLHAL/branches/thomas_s_dev/src/xhcpthread.cpp 2012-01-01 21:57:46 UTC (rev 624)
@@ -27,14 +27,27 @@
#include "xhcpthread.h"
-using namespace boost::algorithm;
+using boost::algorithm::to_lower;
+using boost::algorithm::split;
+using boost::algorithm::is_any_of;
+using boost::algorithm::token_compress_on;
+using boost::algorithm::to_lower_copy;
+
using boost::asio::ip::tcp;
+using std::string;
+using std::vector;
-XHCPThread::XHCPThread( socket_ptr socket )
- : m_stoprequested(false), tab( "\t" ), newLine( "\r\n" ), endMultiLine( ".\r\n" ),
- sock( socket ), quit( false ),
- inMultilineRequest( false ), multilineRequestHandler( 0 ),
- m_thread(boost::bind(&XHCPThread::run, this))
+XHCPThread::XHCPThread( socket_ptr socket, DeviceManager* dm )
+ : m_stoprequested(false)
+ , tab( "\t" )
+ , newLine( "\r\n" )
+ , endMultiLine( ".\r\n" )
+ , sock( socket )
+ , quit( false )
+ , inMultilineRequest( false )
+ , multilineRequestHandler( 0 )
+ , m_thread(boost::bind(&XHCPThread::run, this))
+ , m_deviceManager(dm)
{
}
@@ -50,7 +63,7 @@
* Little helper that returns true if str doesn't end with end
* FIXME: use Boost functionality instead...
*/
-bool endDifferent( std::string str, std::string end )
+bool endDifferent( string str, string end )
{
size_t str_l = str.size();
size_t end_l = end.size();
@@ -60,7 +73,7 @@
void XHCPThread::run()
{
- writeLog( std::string("XHCPThread::run() [")+ lexical_cast<std::string>(sock.use_count()) +"]", logLevel::debug );
+ writeLog( string("XHCPThread::run() [")+ lexical_cast<string>(sock.use_count()) +"]", logLevel::debug );
// initialize here to make sure it's done in advance
// commands[ "ADDEVENT" ] = &XHCPThread::;
@@ -109,14 +122,14 @@
boost::asio::streambuf sb;
boost::system::error_code error;
- std::string greeting( "200 CHRISM-XPLHAL.SERVER1 Version 0.0 alpha XHCP 1.5 ready\r\n" );
+ string greeting( "200 CHRISM-XPLHAL.SERVER1 Version 0.0 alpha XHCP 1.5 ready\r\n" );
boost::asio::write(*sock, boost::asio::buffer(greeting));
while (!quit) {
// const int TimeoutInCommand = 5 * 1000; // during transmission of an command
// const int TimeoutExCommand = 300 * 1000; // between different commands
- std::string data;
+ string data;
while ( (!inMultilineRequest && endDifferent(data, "\r\n") )
|| ( inMultilineRequest && endDifferent(data, "\r\n.\r\n") ) ) {
@@ -124,12 +137,12 @@
std::size_t n = boost::asio::read_until(*sock, sb, '\n');
boost::asio::streambuf::const_buffers_type bufs = sb.data();
- std::string newData(
+ string newData(
boost::asio::buffers_begin(bufs),
boost::asio::buffers_begin(bufs) + n);
sb.consume(n);
/*
- std::string newData;
+ string newData;
size_t length = sock->read_some(boost::asio::buffer(newData), error);
if (error == boost::asio::error::eof)
@@ -148,7 +161,7 @@
}
writeLog( "Request: [" + data + "]", logLevel::debug );
- std::string result = (this->*multilineRequestHandler)( data );
+ string result = (this->*multilineRequestHandler)( data );
writeLog( "Result:\n[\n" + result + "]", logLevel::debug );
//socket.write( result );
boost::asio::write(*sock, boost::asio::buffer(result));
@@ -158,11 +171,11 @@
size_t spacePos = data.find( ' ' );
//boost::algorithm::to_upper( data.substr( 0, spacePos ) );
- writeLog( "data.substr( 0, spacePos ) [" + data.substr( 0, spacePos ) + "]["+(std::string::npos == spacePos ? "" : data.substr( spacePos+1 ))+"]", logLevel::error );
- writeLog( "npos: "+lexical_cast<std::string>(std::string::npos) + " - spacePos: + "+lexical_cast<std::string>(spacePos), logLevel::error );
+ writeLog( "data.substr( 0, spacePos ) [" + data.substr( 0, spacePos ) + "]["+(string::npos == spacePos ? "" : data.substr( spacePos+1 ))+"]", logLevel::error );
+ writeLog( "npos: "+lexical_cast<string>(string::npos) + " - spacePos: + "+lexical_cast<string>(spacePos), logLevel::error );
//XHCPcommand command = 0;//commands[ QString(data).section( " ", 0, 0 ).toUpper() ];
XHCPcommand command = commands[ boost::algorithm::to_upper_copy( data.substr( 0, spacePos ) ) ];
- std::string parameters = std::string::npos == spacePos ? "" : data.substr( spacePos+1 );
+ string parameters = string::npos == spacePos ? "" : data.substr( spacePos+1 );
if( !command ) {
writeLog( "Error: Command not implemented! Request: [" + data + "]", logLevel::error );
@@ -170,7 +183,7 @@
}
writeLog( "Request: [" + data + "]", logLevel::debug );
- std::string result = (this->*command)( parameters );
+ string result = (this->*command)( parameters );
writeLog( "Result:\n[\n" + result + "]", logLevel::debug );
boost::asio::write(*sock, boost::asio::buffer(result));
}
@@ -180,7 +193,7 @@
writeLog( "XHCPThread::run() - end", logLevel::debug );
}
-std::string XHCPThread::commandNotRecognised( const std::string& parameter )
+string XHCPThread::commandNotRecognised( const string& parameter )
{
writeLog( "XHCPThread::commandNotRecognised( " + parameter + " )", logLevel::debug );
return responseCode( 500 );
@@ -213,15 +226,15 @@
_return = os.str();
}
- operator std::string() {
+ operator string() {
return _return;
}
private:
- std::string _return;
+ string _return;
};
-std::string XHCPThread::commandCapabilities( const std::string& parameter )
+string XHCPThread::commandCapabilities( const string& parameter )
{
writeLog( "XHCPThread::commandCapabilities( " + parameter + " )", logLevel::debug );
if( "" == parameter || "SCRIPTING" == parameter )
@@ -234,24 +247,24 @@
}
}
-std::string XHCPThread::commandDelGlobal( const std::string& parameter )
+string XHCPThread::commandDelGlobal( const string& parameter )
{
writeLog( "XHCPThread::commandDelGlobal( " + parameter + " )", logLevel::debug );
xPLCache->deleteEntry( parameter );
return responseCode( 233 );
}
-std::string XHCPThread::commandDelDevConfig( const std::string& parameter )
+string XHCPThread::commandDelDevConfig( const string& parameter )
{
writeLog( "XHCPThread::commandDelDevConfig( " + parameter + " )", logLevel::debug );
- deviceManager->removeConfig( parameter );
+ m_deviceManager->removeConfig( parameter );
return responseCode( 235 );
}
-std::string XHCPThread::commandGetDevConfig( const std::string& parameter )
+string XHCPThread::commandGetDevConfig( const string& parameter )
{
writeLog( "XHCPThread::commandGetDevConfig( " + parameter + " )", logLevel::debug );
- xPLDevice device = deviceManager->getDevice( parameter );
+ xPLDevice device = m_deviceManager->getDevice( parameter );
if( "" == device.VDI ) // empty string if device doesn't exist
return responseCode( 417 );
@@ -259,10 +272,10 @@
if( "" == device.ConfigSource )
return responseCode( 416 );
- std::string retval = responseCode( 217 );
+ string retval = responseCode( 217 );
boost::regex regex( "config\\." + device.VDI + "\\.options\\.([a-z0-9]{1,16})" );
- std::vector<std::string> entries = xPLCache->filterByRegEx( regex );
- for( std::vector<std::string>::const_iterator it = entries.begin(); it != entries.end(); ++it )
+ vector<string> entries = xPLCache->filterByRegEx( regex );
+ for( vector<string>::const_iterator it = entries.begin(); it != entries.end(); ++it )
{
boost::smatch matches;
if( boost::regex_match( *it, matches, regex ) )
@@ -276,26 +289,26 @@
return retval;
}
-std::string XHCPThread::commandGetDevConfigValue( const std::string& parameter )
+string XHCPThread::commandGetDevConfigValue( const string& parameter )
{
writeLog( "XHCPThread::commandGetDevConfigValue( " + parameter + " )", logLevel::debug );
- std::vector<std::string> list;
+ vector<string> list;
split( list, parameter, is_any_of( " " ) );
if( list.size() != 2 ) return responseCode( 501 ); // = syntax error
- std::string retval = responseCode( 234 );
+ string retval = responseCode( 234 );
// do we have to handle mutliple entries?
- std::string count = xPLCache->objectValue( "config." + list[0] + ".options." + list[1] + ".count" );
+ string count = xPLCache->objectValue( "config." + list[0] + ".options." + list[1] + ".count" );
if( "" == count )
{ // no
- std::string entry = xPLCache->objectValue( "config." + list[0] + ".current." + list[1] );
+ string entry = xPLCache->objectValue( "config." + list[0] + ".current." + list[1] );
if( "" != entry )
retval += list[1] + "=" + entry + newLine;
} else { // yes
- std::vector<std::string> entries = xPLCache->childNodes( "config." + list[0] + ".current." + list[1] );
- for( std::vector<std::string>::const_iterator it = entries.begin(); it != entries.end(); ++it )
+ vector<string> entries = xPLCache->childNodes( "config." + list[0] + ".current." + list[1] );
+ for( vector<string>::const_iterator it = entries.begin(); it != entries.end(); ++it )
{
- std::string entry = xPLCache->objectValue( *it );
+ string entry = xPLCache->objectValue( *it );
if( "" != entry )
retval += list[1] + "=" + entry + newLine;
}
@@ -304,26 +317,26 @@
return retval;
}
-std::string XHCPThread::commandListAllDevices( const std::string& parameter )
+string XHCPThread::commandListAllDevices( const string& parameter )
{
writeLog( "XHCPThread::commandListAllGlobals( " + parameter + " )", logLevel::debug );
- std::string result = responseCode( 216 );
- std::vector<std::string> names = deviceManager->getAllDeviceNames();
- for( std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); ++it )
+ string result = responseCode( 216 );
+ vector<string> names = m_deviceManager->getAllDeviceNames();
+ for( vector<string>::const_iterator it = names.begin(); it != names.end(); ++it )
result += *it + newLine;
result += endMultiLine;
return result;
}
-std::string XHCPThread::commandListDevices( const std::string& parameter )
+string XHCPThread::commandListDevices( const string& parameter )
{
writeLog( "XHCPThread::commandListGlobals( " + parameter + " )", logLevel::debug );
- std::string result = responseCode( 216 );
- std::vector<std::string> names = deviceManager->getAllDeviceNames();
- std::string type = to_lower_copy( parameter );
- for( std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); ++it )
+ string result = responseCode( 216 );
+ vector<string> names = m_deviceManager->getAllDeviceNames();
+ string type = to_lower_copy( parameter );
+ for( vector<string>::const_iterator it = names.begin(); it != names.end(); ++it )
{
- xPLDevice device = deviceManager->getDevice( *it );
+ xPLDevice device = m_deviceManager->getDevice( *it );
bool showDevice = true;
if( "awaitingconfig" == type && !device.ConfigType ) showDevice = false;
if( "configured" == type && device.ConfigType ) showDevice = false;
@@ -333,7 +346,7 @@
{
result += device.VDI + tab;
result += timeConverter( device.Expires ) + tab;
- result += lexical_cast<std::string>( device.Interval ) + tab;
+ result += lexical_cast<string>( device.Interval ) + tab;
result += (device.ConfigType ? "Y" : "N") + tab;
result += (device.ConfigDone ? "Y" : "N") + tab;
result += (device.WaitingConfig ? "Y" : "N") + tab;
@@ -344,19 +357,19 @@
return result;
}
-std::string XHCPThread::commandListGlobals( const std::string& parameter )
+string XHCPThread::commandListGlobals( const string& parameter )
{
writeLog( "XHCPThread::commandListGlobals( " + parameter + " )", logLevel::debug );
- std::string result = responseCode( 231 );
+ string result = responseCode( 231 );
result += xPLCache->listAllObjects();
result += endMultiLine;
return result;
}
-std::string XHCPThread::commandListOptions( const std::string& parameter )
+string XHCPThread::commandListOptions( const string& parameter )
{
writeLog( "XHCPThread::commandListOptions( " + parameter + " )", logLevel::debug );
- std::string result;
+ string result;
if( "" == parameter )
result = responseCode( 501 );
else
@@ -369,10 +382,10 @@
/**
* \brief List all determinator groups
*/
-std::string XHCPThread::commandListRuleGroups( const std::string& parameter )
+string XHCPThread::commandListRuleGroups( const string& parameter )
{
writeLog( "XHCPThread::commandListRuleGroups( " + parameter + " )", logLevel::debug );
- std::string result = responseCode( 240 );
+ string result = responseCode( 240 );
// FIXME add listing of groups
result += endMultiLine;
return result;
@@ -381,29 +394,29 @@
/**
* \brief List all determinators
*/
-std::string XHCPThread::commandListRules( const std::string& parameter )
+string XHCPThread::commandListRules( const string& parameter )
{
writeLog( "XHCPThread::commandListRules( " + parameter + " )", logLevel::debug );
- std::string result = responseCode( 237 );
+ string result = responseCode( 237 );
// FIXME add listing of groups
result += endMultiLine;
return result;
}
-std::string XHCPThread::commandPutDevConfig( const std::string& parameter )
+string XHCPThread::commandPutDevConfig( const string& parameter )
{
writeLog( "XHCPThread::commandPutDevConfig( " + parameter + " )", logLevel::debug );
- static std::string device;
+ static string device;
if( inMultilineRequest )
{
inMultilineRequest = false;
multilineRequestHandler = 0;
- if( deviceManager->storeNewConfig( device, parameter ) )
+ if( m_deviceManager->storeNewConfig( device, parameter ) )
return responseCode( 220 ); // storing succeded
else
return responseCode( 503 ); // storing failed
}
- if( !deviceManager->contains( parameter ) )
+ if( !m_deviceManager->contains( parameter ) )
return responseCode( 417 );
device = parameter;
@@ -412,11 +425,11 @@
return responseCode( 320 );
}
-std::string XHCPThread::commandSetGlobal( const std::string& parameter )
+string XHCPThread::commandSetGlobal( const string& parameter )
{
writeLog( "XHCPThread::commandSetGlobal( " + parameter + " )", logLevel::debug );
- std::vector<std::string> list;
+ vector<string> list;
split( list, parameter, is_any_of( " " ) );
if( list.size() != 2 ) return responseCode( 501 );
@@ -424,7 +437,7 @@
return responseCode( 232 );
}
-std::string XHCPThread::commandSendXPlMessage( const std::string& parameter )
+string XHCPThread::commandSendXPlMessage( const string& parameter )
{
writeLog( "XHCPThread::commandSendXPlMessage( " + parameter + " ) [inMultilineRequest="+(inMultilineRequest?"true":"false")+"]", logLevel::debug );
if( inMultilineRequest )
@@ -440,7 +453,7 @@
return responseCode( 313 );
}
-std::string XHCPThread::commandQuit( const std::string& parameter )
+string XHCPThread::commandQuit( const string& parameter )
{
writeLog( "XHCPThread::commandQuit( " + parameter + " )", logLevel::debug );
quit = true;
Modified: xPLHAL/branches/thomas_s_dev/src/xhcpthread.h
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xhcpthread.h 2012-01-01 21:56:16 UTC (rev 623)
+++ xPLHAL/branches/thomas_s_dev/src/xhcpthread.h 2012-01-01 21:57:46 UTC (rev 624)
@@ -23,11 +23,12 @@
#include <boost/thread.hpp>
#include <boost/asio.hpp>
-
#include "xplcache.h"
typedef boost::shared_ptr<boost::asio::ip::tcp::tcp::socket> socket_ptr;
+class DeviceManager;
+
/**
* \brief Single connection to an xPLHAL Manager.
*
@@ -41,9 +42,10 @@
const std::string tab;
const std::string newLine;
const std::string endMultiLine;
+ DeviceManager* m_deviceManager;
public:
- XHCPThread( socket_ptr socket );
+ XHCPThread( socket_ptr socket, DeviceManager* dm );
~XHCPThread();
/** \brief The main loop of the thread. */
Modified: xPLHAL/branches/thomas_s_dev/src/xplcache.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplcache.cpp 2012-01-01 21:56:16 UTC (rev 623)
+++ xPLHAL/branches/thomas_s_dev/src/xplcache.cpp 2012-01-01 21:57:46 UTC (rev 624)
@@ -24,10 +24,17 @@
#include "xplcache.h"
-using namespace boost::algorithm;
-using namespace boost::posix_time;
-using namespace boost::filesystem;
+using boost::algorithm::starts_with;
+using boost::algorithm::iequals;
+using boost::algorithm::is_any_of;
+using boost::algorithm::split;
+using boost::posix_time::minutes;
+using boost::posix_time::second_clock;
+using boost::filesystem::path;
+using std::string;
+using std::vector;
+
timeStreamHelper timeConverter;
xPLCacheClass::CacheFilter::CacheFilter() :
@@ -35,10 +42,10 @@
mfInstance( "*" ), mfSchemType( "*" ), mfSchemClass( "*" ), expiry( false )
{}
-xPLCacheClass::CacheFilter::CacheFilter( const std::string& filter ) :
+xPLCacheClass::CacheFilter::CacheFilter( const string& filter ) :
prefTag( "cache" ), expiry( false )
{
- std::vector<std::string> list;
+ vector<string> list;
split( list, filter, is_any_of(".") );
mfType = list[0];
mfVendor = list[1];
@@ -53,16 +60,16 @@
loadCache();
}
-std::string xPLCacheClass::listAllObjects( bool forceEverything ) const
+string xPLCacheClass::listAllObjects( bool forceEverything ) const
{
writeLog( "xPLCacheClass::ListAllObjects()", logLevel::debug );
- std::string result;
+ string result;
shared_lock locker(cacheLock);
for( cacheMap::const_iterator it = cache.begin(); it != cache.end(); it++ )
{
- std::string name = it->first;
+ string name = it->first;
if( starts_with( name, "device." ) )
{
if( forceEverything || iequals( "true", cache.find("xplhal.showdevices")->second.value ) )
@@ -82,19 +89,19 @@
return result;
}
-void xPLCacheClass::updateEntry( const std::string& name, const std::string& value, const bool expires )
+void xPLCacheClass::updateEntry( const string& name, const string& value, const bool expires )
{
writeLog( "xPLCacheClass::updateEntry( \"" + name + "\", \"" + value + "\" )", logLevel::debug );
unique_lock locker(cacheLock);
cacheMap::iterator it = cache.find( name );
if( cache.end() == it )
- cache.insert( std::pair<std::string,CacheEntry>( name, CacheEntry( value, expires ) ) );
+ cache.insert( std::pair<string,CacheEntry>( name, CacheEntry( value, expires ) ) );
else
it->second = CacheEntry( value, expires );
}
-void xPLCacheClass::deleteEntry( const std::string& name )
+void xPLCacheClass::deleteEntry( const string& name )
{
writeLog( "xPLCacheClass::deleteEntry( \"" + name + "\" )", logLevel::debug );
unique_lock locker(cacheLock);
@@ -115,9 +122,9 @@
}
}
-std::vector<std::string> xPLCacheClass::childNodes( const std::string& filter ) const
+vector<string> xPLCacheClass::childNodes( const string& filter ) const
{
- std::vector<std::string> retval;
+ vector<string> retval;
for( cacheMap::const_iterator it = cache.begin(); it != cache.end(); ++it )
if( starts_with( it->first, filter ) )
@@ -126,9 +133,9 @@
return retval;
}
-std::vector<std::string> xPLCacheClass::filterByRegEx( const boost::regex& regex ) const
+vector<string> xPLCacheClass::filterByRegEx( const boost::regex& regex ) const
{
- std::vector<std::string> retval;
+ vector<string> retval;
for( cacheMap::const_iterator it = cache.begin(); it != cache.end(); ++it )
{
Modified: xPLHAL/branches/thomas_s_dev/src/xplhandler.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplhandler.cpp 2012-01-01 21:56:16 UTC (rev 623)
+++ xPLHAL/branches/thomas_s_dev/src/xplhandler.cpp 2012-01-01 21:57:46 UTC (rev 624)
@@ -18,7 +18,7 @@
#include <boost/algorithm/string/replace.hpp>
-using namespace boost::algorithm;
+using std::string;
#include "log.h"
@@ -31,7 +31,7 @@
int xPLHandler::m_refcount = 0;
-xPLHandler::xPLHandler( const std::string& host_name)
+xPLHandler::xPLHandler( const string& host_name)
: xPLService(0)
, m_exit_thread(false)
, vendor( "CHRISM" )
@@ -114,7 +114,7 @@
// send waiting messages
while( xPL_MessagePtr theMessage = xPLMessageQueue->consume( xPLService ) )
{
- writeLog("Found xPL message at " + lexical_cast<std::string>(theMessage)+ " to send...", logLevel::debug);
+ writeLog("Found xPL message at " + lexical_cast<string>(theMessage)+ " to send...", logLevel::debug);
if ( !xPL_sendMessage( theMessage ) )
writeLog("Unable to send xPL message", logLevel::debug);
else
@@ -126,29 +126,29 @@
}
}
-void xPLHandler::sendBroadcastMessage( const std::string& msgClass, const std::string& msgType, const xPLMessage::namedValueList& namedValues ) const
+void xPLHandler::sendBroadcastMessage( const string& msgClass, const string& msgType, const xPLMessage::namedValueList& namedValues ) const
{
writeLog( "xPLHandler::sendBroadcastMessage( "+msgClass+", "+msgType+" )", logLevel::debug );
xPLMessageQueue->add( xPLMessagePtr( new xPLMessage( xPL_MESSAGE_COMMAND, "*", "", "", msgClass, msgType, namedValues ) ) );
}
-void xPLHandler::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,
+void xPLHandler::sendMessage( const xPL_MessageType type, const string& tgtVendor, const string& tgtDeviceID,
+ const string& tgtInstanceID, const string& msgClass, const string& msgType,
const xPLMessage::namedValueList& namedValues ) const
{
- writeLog( "xPLHandler::sendMessage( "+lexical_cast<std::string>(type)+", "+tgtVendor+", "+tgtDeviceID+", "+tgtInstanceID+", "+msgClass+", "+msgType+" )", logLevel::debug );
+ writeLog( "xPLHandler::sendMessage( "+lexical_cast<string>(type)+", "+tgtVendor+", "+tgtDeviceID+", "+tgtInstanceID+", "+msgClass+", "+msgType+" )", logLevel::debug );
xPLMessageQueue->add( xPLMessagePtr( new xPLMessage( type, tgtVendor, tgtDeviceID, tgtInstanceID, msgClass, msgType, namedValues ) ) );
}
-void xPLHandler::sendMessage( const xPL_MessageType type, const std::string& VDI,
- const std::string& msgClass, const std::string& msgType,
+void xPLHandler::sendMessage( const xPL_MessageType type, const string& VDI,
+ const string& msgClass, const string& msgType,
const xPLMessage::namedValueList& namedValues ) const
{
size_t marker1 = VDI.find( "-" );
size_t marker2 = VDI.find( "." );
- std::string vendor = VDI.substr( 0, marker1 );
- std::string device = VDI.substr( marker1+1, marker2 - (marker1+1) );
- std::string instance = VDI.substr( marker2+1 );
+ string vendor = VDI.substr( 0, marker1 );
+ string device = VDI.substr( marker1+1, marker2 - (marker1+1) );
+ string instance = VDI.substr( marker2+1 );
xPLMessageQueue->add( xPLMessagePtr( new xPLMessage( type, vendor, device, instance, msgClass, msgType, namedValues ) ) );
}
Modified: xPLHAL/branches/thomas_s_dev/src/xplmessage.cpp
===================================================================
--- xPLHAL/branches/thomas_s_dev/src/xplmessage.cpp 2012-01-01 21:56:16 UTC (rev 623)
+++ xPLHAL/branches/thomas_s_dev/src/xplmessage.cpp 2012-01-01 21:57:46 UTC (rev 624)
@@ -20,10 +20,11 @@
#include <boost/lexical_cast.hpp>
#include <algorithm>
-using namespace boost::algorithm;
+using boost::algorithm::replace_all;
using boost::lexical_cast;
+using std::string;
-std::string xPLMessage::getTypeString() const
+string xPLMessage::getTypeString() const
{
switch(type)
{
@@ -34,17 +35,17 @@
}
}
-std::string xPLMessage::getSourceVDI() const
+string xPLMessage::getSourceVDI() const
{
- return vendor + std::string("-") + deviceID + std::string(".") + instanceID;
+ return vendor + string("-") + deviceID + string(".") + instanceID;
}
-std::string xPLMessage::getTargetVDI() const
+string xPLMessage::getTargetVDI() const
{
- return targetVendor + std::string("-") + targetDevice + std::string(".") + targetInstance;
+ return targetVendor + string("-") + targetDevice + string(".") + targetInstance;
}
-bool xPLMessage::setSourceFromVDI(const std::string& source)
+bool xPLMessage::setSourceFromVDI(const string& source)
{
size_t marker1 = source.find( "-" );
size_t marker2 = source.find( "." );
@@ -55,7 +56,7 @@
return true;
}
-bool xPLMessage::setTargetFromVDI(const std::string& target)
+bool xPLMessage::setTargetFromVDI(const string& target)
{
if (target == "*") {
isBroadcastMessage = true;
@@ -72,7 +73,7 @@
return true;
}
-std::string xPLMessage::getNamedValue(const std::string& tag) const
+string xPLMessage::getNamedValue(const string& tag) const
{
for (auto entry : namedValues) {
if (entry.first == tag) {
@@ -82,9 +83,9 @@
return "";
}
-std::string xPLMessage::printXPLMessage() const
+string xPLMessage::printXPLMessage() const
{
- std::string result;
+ string result;
result += "<" + getTypeString() + " ";
/* Source Info */
@@ -102,7 +103,7 @@
}
/* Print hop count */
- result += " (" + lexical_cast<std::string>(hopcount) + " hops) ";
+ result += " (" + lexical_cast<string>(hopcount) + " hops) ";
/* Echo Schema Info */
result += "[" + msgClass + "." + msgType + "]: ";
@@ -136,7 +137,7 @@
return true;
}
-xPLMessage::operator std::string() const
+xPLMessage::operator string() const
{
return printXPLMessage();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|