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 #endif
00035 Com
00036 {
00037 public:
00053 typedef enum
00054 {
00055 NoError,
00056 ErrorConnectionRefused,
00057 ErrorSocketSend,
00058 ErrorSocketRead,
00059 ErrorImageServerCreate,
00060 ErrorImageServerBind,
00061 ErrorTimeout,
00062 ErrorConnectionBusy,
00063 ErrorClientCreate,
00064 ErrorHostNotFound,
00065 ErrorUndefined,
00066 ErrorWinsock2Initialization,
00067 ErrorAlreadyConnected
00068 } Error;
00069
00076 typedef enum
00077 {
00078 NotConnected = 0,
00079 HostLookupState = 1,
00080 Connecting = 2,
00081 Connected = 3,
00082 ClosingState = 6
00083 } ConnectionState;
00084
00092 Com( bool useQueuedCallback = false );
00093
00094 virtual ~Com();
00095
00102 ComId id() const;
00103
00110 void connect( bool isBlocking = true );
00111
00117 void disconnect();
00118
00124 bool isConnected() const;
00125
00136 void setAddress( const char* address );
00137
00145 const char* address() const;
00146
00153 void setImageServerPort( unsigned int port = 8080 );
00154
00165 unsigned int imageServerPort() const;
00166
00170 ConnectionState connectionState() const;
00171
00177 bool isPassiveMode() const;
00178
00186 bool waitForUpdate( unsigned int timeout = 200 );
00187
00196 void setMinimumUpdateCycleTime( unsigned int msecs );
00197
00198 rec::iocontrol::remotestate::SensorState sensorState();
00199
00200 void setSetState( const rec::iocontrol::remotestate::SetState& setState );
00201
00208 void processEvents();
00209
00217 bool hasPendingEvents() const;
00218
00227 virtual void errorEvent( Error error, const char* errorString );
00228
00235 virtual void connectedEvent();
00236
00243 virtual void connectionClosedEvent();
00244
00250 virtual void connectionStateChangedEvent( ConnectionState newState, ConnectionState oldState );
00251
00255 virtual void updateEvent();
00256
00261 virtual void modeChangedEvent( bool isPassiveMode );
00262
00263 private:
00264 ComImpl* _impl;
00265 };
00266
00270 class ComException : public RobotinoException
00271 {
00272 public:
00273 ComException( Com::Error e, const char* message )
00274 : RobotinoException( message )
00275 , error( e )
00276 {
00277 }
00278
00279 const Com::Error error;
00280 };
00281 }
00282 }
00283 }
00284 #endif