|
solarpowerlog trunk
|
00001 /* 00002 * CSharedConnectionMaster.h 00003 * 00004 * Created on: Sep 13, 2010 00005 * Author: tobi 00006 */ 00007 00008 #ifndef CSHAREDCONNECTIONMASTER_H_ 00009 #define CSHAREDCONNECTIONMASTER_H_ 00010 00011 #ifdef HAVE_CONFIG_H 00012 #include "config.h" 00013 #include "porting.h" 00014 #endif 00015 00016 #ifdef HAVE_COMMS_SHAREDCONNECTION 00017 00018 #include <list> 00019 #include <semaphore.h> 00020 00021 #include "interfaces/IConnect.h" 00022 #include "Connections/CAsyncCommand.h" 00023 #include "patterns/ICommandTarget.h" 00024 #include "patterns/ICommand.h" 00025 #include "CSharedConnectionSlave.h" 00026 00027 00028 // Token inserted by this or the slave class to specify individual timeouts. 00029 // At this timestamp, the command can be considered timed-out. 00030 #define ICONNECT_TOKEN_TIMEOUTTIMESTAMP "CSharedConnection_Timeout" 00031 00032 #define ICONNECT_TOKEN_PRV_ORIGINALCOMMAND "CSharedConnection_OrgiginalWork" 00033 00034 #define SHARED_CONN_MASTER_DEFAULTTIMEOUT (3000UL) 00035 00036 class CSharedConnectionMaster: public IConnect, ICommandTarget 00037 { 00038 00039 protected: 00040 friend class CSharedConnection; 00041 friend class CSharedConnectionSlave; 00042 CSharedConnectionMaster(const string & configurationname); 00043 00044 public: 00045 virtual ~CSharedConnectionMaster(); 00046 00047 void ExecuteCommand(const ICommand *Command); 00048 00049 protected: 00050 00051 virtual bool Connect(ICommand *callback); 00052 00053 virtual bool Disconnect(ICommand *callback); 00054 00055 virtual void SetupLogger(const string& parentlogger, const string & = ""); 00056 00057 virtual bool Send(const char *tosend, unsigned int len, ICommand *callback = 00058 NULL); 00059 00060 virtual bool Send(const string& tosend, ICommand *callback = NULL); 00061 00062 virtual bool Receive(ICommand *callback); 00063 00064 virtual bool CheckConfig(void); 00065 00066 virtual bool IsConnected(void); 00067 00068 private: 00069 IConnect *connection; 00070 00071 list<ICommand*> readcommands; 00072 00073 // When is the current receive scheduled to timeout? 00074 boost::posix_time::ptime readtimeout; 00075 00076 }; 00077 00078 #endif 00079 00080 #endif /* CSHAREDCONNECTIONMASTER_H_ */