-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerDataProcessor.h
130 lines (103 loc) · 4.43 KB
/
ServerDataProcessor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// ServerDataProcessor.h
// PyRIDE
//
// Created by Xun Wang on 10/05/10.
// Copyright 2010 GalaxyNetwork. All rights reserved.
//
#ifndef ServerDataProcessor_h_DEFINED
#define ServerDataProcessor_h_DEFINED
#include <vector>
#include <string>
#include "PyRideNetComm.h"
#ifdef IOS_BUILD
#include "iOSAppConfigManager.h"
#else
#include "AppConfigManager.h"
#endif
namespace pyride {
typedef std::vector< FieldObject > ObservedObjects;
class ServerDataProcessor;
class PyRideExtendedCommandHandler : public VideoDeviceDataHandler
{
protected:
virtual bool executeRemoteCommand( PyRideExtendedCommand command, int & retVal,
const unsigned char * optinalData = NULL,
const int optionalDataLength = 0 ) = 0;
virtual void cancelCurrentOperation() = 0;
virtual bool onUserLogOn( const std::string & name ) { return false; }
virtual void onUserLogOff( const std::string & name ) {}
virtual int onExclusiveCtrlRequest( const std::string & name ) { return 0; }
virtual void onExclusiveCtrlRelease( const std::string & name ) {}
virtual void onTimer( const long timerID ) {}
virtual void onTimerLapsed( const long timerID ) {}
virtual void onTelemetryStreamControl( bool isStart ) {};
friend class ServerDataProcessor;
};
class ServerDataProcessor : public RobotDataHandler, VideoDeviceDataHandler
{
public:
static ServerDataProcessor * instance();
~ServerDataProcessor();
void init( const VideoDeviceList & videoObjs, const AudioDeviceList & audioObjs );
void fini();
void addCommandHandler( PyRideExtendedCommandHandler * cmdHandler = NULL );
void removeCommandHandler( PyRideExtendedCommandHandler * cmdHandler = NULL );
void discoverConsoles();
void disconnectConsole( SOCKET_T fd );
void disconnectConsoles();
void setClientID( const char clientID ) { clientID_ = clientID; }
void setTeamMemberID( int number = 1, TeamColour team = BlueTeam );
void setTeamColour( TeamColour team );
void updateRobotTelemetry( float x, float y, float heading );
void updateRobotTelemetryWithDefault();
void updateRobotTelemetry( RobotPose & pos, ObservedObjects & objects );
void blockRemoteExclusiveControl( bool isyes );
void takeCameraSnapshot( bool takeAllCamera );
int getMyIPAddress();
int activeVideoObjectList( std::vector<std::string> & namelist );
bool dispatchVideoDataTo( int vidObjID, struct sockaddr_in & cAddr,
short port, bool todispath );
bool dispatchAudioDataTo( struct sockaddr_in & cAddr,
short port, bool todispath );
bool setCameraParameter( int vidObjID, int id_idx, int value );
void updateOperationalStatus( RobotOperationalState status, const char * optionalData = NULL,
const int optionalDataLength = 0 );
TeamColour teamColour() { return (TeamColour)(clientID_ & 0xf); }
int teamMemberID() { return (clientID_ >> 4); }
const RobotInfo & defaultRobotInfo() { return defaultRobotInfo_; }
void setDefaultRobotInfo( const RobotType rtype, const RobotPose & pose, const RobotCapability & capabilities )
{
defaultRobotInfo_.type = rtype;
defaultRobotInfo_.pose = pose;
defaultRobotInfo_.capabilities = capabilities;
}
long addTimer( float initialTime, long repeats = 0, float interval = 1.0 );
void delTimer( long tID );
void delAllTimers();
long totalTimers();
bool isTimerRunning( long tID );
bool isTimerExecuting( long tID );
private:
typedef std::vector<PyRideExtendedCommandHandler *> PyRideExtendedCommandHandlerList;
PyRideNetComm * pNetComm_;
PyRideExtendedCommandHandlerList cmdHandlerList_;
VideoDeviceList * activeVideoObjs_;
AudioDeviceList * activeAudioObjs_;
RobotInfo defaultRobotInfo_;
static ServerDataProcessor * s_pServerDataProcessor;
ServerDataProcessor();
// RobotDataHandler
bool executeRemoteCommand( const unsigned char * commandData, const int dataLength, int & retVal );
void cancelCurrentOperation();
bool onUserLogOn( const unsigned char * authCode, SOCKET_T fd, struct sockaddr_in & addr );
void onUserLogOff( SOCKET_T fd );
int onExclusiveCtrlRequest( SOCKET_T fd );
void onExclusiveCtrlRelease( SOCKET_T fd );
void onTimer( const long timerID );
void onTimerLapsed( const long timerID );
void onTelemetryStreamControl( bool isStart );
void onSnapshotImage( const string & imageName );
};
} // namespace pyride
#endif // ServerDataProcessor_h_DEFINED