00001
00002
00003 #ifndef _REC_ROBOTINO_COM_COM_H_
00004 #define _REC_ROBOTINO_COM_COM_H_
00005
00006 #include "rec/robotino/com/ComId.h"
00007 #include "rec/robotino/com/RobotinoException.h"
00008 #include "rec/iocontrol/remotestate/SetState.h"
00009 #include "rec/iocontrol/remotestate/SensorState.h"
00010 #include <string>
00011
00012 namespace rec
00013 {
00014 namespace robotino
00015 {
00016 namespace com
00017 {
00018 class ComImpl;
00019
00023 class
00024 #ifdef WIN32
00025 # ifdef rec_robotino_com_EXPORTS
00026 __declspec(dllexport)
00027 # endif
00028 # ifdef rec_robotino_com2_EXPORTS
00029 __declspec(dllexport)
00030 # endif
00031 # ifdef rec_robotino_com3_EXPORTS
00032 __declspec(dllexport)
00033 # endif
00034 #else
00035 # ifndef SWIG
00036 __attribute__ ((visibility ("default")))
00037 # endif
00038 #endif
00039 Com
00040 {
00041 public:
00057 typedef enum
00058 {
00059 NoError,
00060 ErrorConnectionRefused,
00061 ErrorSocketSend,
00062 ErrorSocketRead,
00063 ErrorImageServerCreate,
00064 ErrorImageServerBind,
00065 ErrorTimeout,
00066 ErrorConnectionBusy,
00067 ErrorClientCreate,
00068 ErrorHostNotFound,
00069 ErrorUndefined,
00070 ErrorWinsock2Initialization,
00071 ErrorAlreadyConnected
00072 } Error;
00073
00080 typedef enum
00081 {
00082 NotConnected = 0,
00083 HostLookupState = 1,
00084 Connecting = 2,
00085 Connected = 3,
00086 ClosingState = 6
00087 } ConnectionState;
00088
00096 Com( bool useQueuedCallback = false );
00097
00098 virtual ~Com();
00099
00106 ComId id() const;
00107
00114 void connect( bool isBlocking = true );
00115
00121 void disconnect();
00122
00128 bool isConnected() const;
00129
00140 void setAddress( const char* address );
00141
00149 const char* address() const;
00150
00157 void setImageServerPort( unsigned int port = 8080 );
00158
00169 unsigned int imageServerPort() const;
00170
00174 ConnectionState connectionState() const;
00175
00181 bool isPassiveMode() const;
00182
00190 bool waitForUpdate( unsigned int timeout = 200 );
00191
00200 void setMinimumUpdateCycleTime( unsigned int msecs );
00201
00202 rec::iocontrol::remotestate::SensorState sensorState();
00203
00204 void setSetState( const rec::iocontrol::remotestate::SetState& setState );
00205
00212 void processEvents();
00213
00221 bool hasPendingEvents() const;
00222
00231 virtual void errorEvent( Error error, const char* errorString );
00232
00239 virtual void rpcServerEvent();
00240
00247 virtual void connectedEvent();
00248
00255 virtual void connectionClosedEvent();
00256
00262 virtual void connectionStateChangedEvent( ConnectionState newState, ConnectionState oldState );
00263
00267 virtual void updateEvent();
00268
00273 virtual void modeChangedEvent( bool isPassiveMode );
00274
00275 private:
00276 ComImpl* _impl;
00277 };
00278
00282 class ComException : public RobotinoException
00283 {
00284 public:
00285 ComException( Com::Error e, const char* message )
00286 : RobotinoException( message )
00287 , error( e )
00288 {
00289 }
00290
00291 const Com::Error error;
00292 };
00293 }
00294 }
00295 }
00296 #endif