-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyModuleStub.h
100 lines (75 loc) · 2.46 KB
/
PyModuleStub.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
//
// PyModuleStub.h
// PyRIDE
//
// Created by Xun Wang on 8/04/11.
// Copyright 2011 Galaxy Network. All rights reserved.
//
#ifndef PyModuleStub_h_DEFINED
#define PyModuleStub_h_DEFINED
#include "ServerDataProcessor.h"
// Python redefine the following definition
// and cause compiler warning.
#ifdef _POSIX_C_SOURCE
#undef _POSIX_C_SOURCE
#endif
#ifdef _XOPEN_SOURCE
#undef _XOPEN_SOURCE
#endif
#include <Python.h>
namespace pyride {
class PyOutputWriter
{
public:
virtual void write( const char * msg ) = 0;
virtual void broadcastMessage( const char * data ) = 0;
virtual PyObject * mainScript() = 0;
virtual ~PyOutputWriter() {}
};
class PyModuleExtendedCommandHandler;
class PyModuleExtension
{
public:
PyModuleExtension( const char * name );
virtual ~PyModuleExtension();
std::string & name() { return name_; }
PyObject * init( PyOutputWriter * pow );
bool invokeCallback( const char * fnName, PyObject * arg );
bool invokeCallback( const char * fnName, PyObject * arg, PyObject * & result );
void write( const char * str );
void sendTeamMessage( const char * mesg );
void setTeamColour( TeamColour teamColour );
void fini();
char clientID() const { return clientID_; }
void clientID( char cID );
protected:
char clientID_;
std::string name_;
PyOutputWriter * pow_;
PyObject * pPyModule_;
PyModuleExtendedCommandHandler * pyModuleCommandHandler_;
virtual PyObject * createPyModule() = 0;
void swapCallbackHandler( PyObject * & master, PyObject * newObj );
void invokeCallbackHandler( PyObject * & cbObj, PyObject * arg );
};
class PyModuleExtendedCommandHandler : public PyRideExtendedCommandHandler
{
public:
PyModuleExtendedCommandHandler( PyModuleExtension * pyExtModule = NULL );
private:
bool executeRemoteCommand( PyRideExtendedCommand command, int & retVal,
const unsigned char * optionalData = NULL,
const int optionalDataLength = 0 );
void cancelCurrentOperation();
bool onUserLogOn( const std::string & name );
void onUserLogOff( const std::string & name );
int onExclusiveCtrlRequest( const std::string & name );
void onExclusiveCtrlRelease( const std::string & name );
void onTimer( const long timerID );
void onTimerLapsed( const long timerID );
void onSnapshotImage( const string & name );
PyModuleExtension * pyExtModule_;
};
extern std::vector<long> g_PyModuleTimerList;
} // namespace pyride
#endif // PyModuleStub_h_DEFINED