|
solarpowerlog trunk
|
#include <IConnect.h>


Public Member Functions | |
| IConnect (const string &configurationname) | |
| virtual void | SetupLogger (const string &parentlogger, const string &spec="Comms") |
| Setupp the Logger. | |
| virtual | ~IConnect () |
| Desctructor. | |
| virtual bool | Connect (ICommand *callback=NULL)=0 |
| virtual bool | Disconnect (ICommand *callback=NULL)=0 |
| virtual bool | Send (const char *tosend, unsigned int len, ICommand *callback=NULL)=0 |
| virtual bool | Send (const string &tosend, ICommand *callback=NULL) |
| virtual bool | Receive (ICommand *cmd)=0 |
| virtual bool | CheckConfig (void)=0 |
| virtual bool | IsConnected (void) |
Protected Member Functions | |
| virtual void | _main (void) |
| virtual void | StartWorkerThread (void) |
| Start the Worker thread. | |
| virtual bool | IsTermRequested (void) |
| Check if termination of the worker thread has been requested. | |
| virtual bool | IsThreadRunning (void) |
Protected Attributes | |
| string | ConfigurationPath |
| Storage for the Configuration Path to extract settings. | |
| ILogger | logger |
| boost::thread | workerthread |
| ASYNC OPERATION. | |
| boost::recursive_mutex | mutex |
| Mutex to protect data. | |
Interface for all communication classes
This Interface is the API for all concrete comm methods. The class is abstract, so it cannot be instanciated by itself.
Anyway, it is intended, that the class is only created by the IConnectFactory.
Synchronous and asyncronous operations
(Prelimiary, as currently in developement) FIXME Update docs when ready! When the asynch operations are implemented, synchronous operations should be depreciated, as the might infer with the timings of other inverters.
The IConnect methods can be used synchronous and asyncronous,( if the communication classes support this. But the plans are to make these all async-capable)
The customers of the IConnect classes can choose if they want to use the async or sync methods by specifying optional ICommand arguments. If they are obmitted (and therefore defaulting to NULL pointers) the command will use synchronous methods, so returning the result directly (boolean). The booleans are used because of how solarpowerlog developed
If the asynchronous commands are used, the result is placed into the ICommand-data void pointer, which has to be casted to an int. Here "errno" conventions are used. Negative numbers tell that an error occured, zero means success. Please see the documentation of the methods for expected error codes.
ICommand ownership As usual, ICommands that are submitted to this class, will be owned by this class. So do not delete them, as they will be automatically deleted by the WorkScheduler.
Definition at line 118 of file IConnect.h.
| IConnect::IConnect | ( | const string & | configurationname | ) |
Constructor.
The constructor gets the configuration path to be used to extract its configuration.
Definition at line 43 of file IConnect.cpp.
| IConnect::~IConnect | ( | ) | [virtual] |
Desctructor.
Definition at line 56 of file IConnect.cpp.
| virtual void IConnect::_main | ( | void | ) | [inline, protected, virtual] |
function of the thread.
Reimplemented in CConnectDummy.
Definition at line 279 of file IConnect.h.
| virtual bool IConnect::CheckConfig | ( | void | ) | [pure virtual] |
Check the configuration for validty. Retrurn false on config errors. (program will abort then!)
Implemented in CConnectDummy.
| virtual bool IConnect::Connect | ( | ICommand * | callback = NULL | ) | [pure virtual] |
Connect to something NOTE: Needed to be overriden! ALWAYS Open in a NON_BLOCK way, or implement a worker thread Connect to the target, so comms can happen.
The target and the settings are retrieved out of the configuration.
SYNCHRONOUNS OPERATION: Connect and return if it has succeeded. May block, but should be limited to some seconds.
ASYNCHRONOUS OPERATION: Connect async and use the ICommand to tell the result.
Implemented in CConnectDummy.
| virtual bool IConnect::Disconnect | ( | ICommand * | callback = NULL | ) | [pure virtual] |
Tear down the connection.
SYNCHRONOUNS OPERATION: Just Disconnect. If this could fail, return false on failure, else true.
ASYNCHRONOUS OPERATION: Disconnect async and use the ICommand to tell the result.
ASYNCHRNOUNS ERROR CODES. The result will be placed in the supplied ICommand's data field.
The value will be usually EIO, as one hs to ask himself: What can go wrong here?
Implemented in CConnectDummy.
| virtual bool IConnect::IsConnected | ( | void | ) | [inline, virtual] |
Check if we believe the connection is still active Note: if the concrete implementation cannot tell, it should always return true, as the default implementaion does. (the inverter class has to do some kind of timeout-handling anyway)
Definition at line 254 of file IConnect.h.
| bool IConnect::IsTermRequested | ( | void | ) | [protected, virtual] |
Check if termination of the worker thread has been requested.
Definition at line 79 of file IConnect.cpp.
| bool IConnect::IsThreadRunning | ( | void | ) | [protected, virtual] |
Check if thread is running
Definition at line 87 of file IConnect.cpp.
| virtual bool IConnect::Receive | ( | ICommand * | cmd | ) | [pure virtual] |
Receive data from connection and place it into a std::string
Try to receive data from the other end and place everything readed into the supplied std::string.
| wheretoplace | object for data storage. |
| cmd | ICommand to be used for async notification. |
ASYNCHRONOUS ERRORS: The implementation might use errors out of error.h to specify the cause of the error.
These error values are defined in their meaning:
EIO I/O Error on the comms. Reason unknown or something unexpected happended. (one should close and reopen the connection)
ETIMEDOUT Read request timed out: No bytes received during configured timeout.
ENOTCONN Connection went down, e.g. eof received.
Implemented in CConnectDummy.
| virtual bool IConnect::Send | ( | const char * | tosend, |
| unsigned int | len, | ||
| ICommand * | callback = NULL |
||
| ) | [pure virtual] |
Send a array of characters (can be used as binary transport, too)
| tosend | what to send |
| len | how many bytes |
Implemented in CConnectDummy.
| virtual bool IConnect::Send | ( | const string & | tosend, |
| ICommand * | callback = NULL |
||
| ) | [inline, virtual] |
Send a string
| tosend | std::string to send |
Definition at line 202 of file IConnect.h.
| void IConnect::SetupLogger | ( | const string & | parentlogger, |
| const string & | spec = "Comms" |
||
| ) | [virtual] |
Setupp the Logger.
Definition at line 51 of file IConnect.cpp.
| void IConnect::StartWorkerThread | ( | void | ) | [protected, virtual] |
Start the Worker thread.
Definition at line 69 of file IConnect.cpp.

string IConnect::ConfigurationPath [protected] |
Storage for the Configuration Path to extract settings.
Definition at line 261 of file IConnect.h.
ILogger IConnect::logger [protected] |
Associated logger.
Definition at line 266 of file IConnect.h.
boost::recursive_mutex IConnect::mutex [protected] |
Mutex to protect data.
Definition at line 274 of file IConnect.h.
boost::thread IConnect::workerthread [protected] |