Rev 995 | Rev 1007 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 995 | Rev 999 | ||
|---|---|---|---|
| Line 35... | Line 35... | ||
| 35 | #include "../CanNet/canmessage.h" |
35 | #include "../CanNet/canmessage.h" |
| 36 | #include "../Threads/semaphore.h" |
36 | #include "../Threads/semaphore.h" |
| 37 | #include "../Threads/threadsafequeue.h" |
37 | #include "../Threads/threadsafequeue.h" |
| 38 | #include "intervalthread.h" |
38 | #include "intervalthread.h" |
| 39 | #include "socketthread.h" |
39 | #include "socketthread.h" |
| - | 40 | #include "commandthread.h" |
|
| - | 41 | #include "expression.h" |
|
| 40 | 42 | ||
| 41 | using namespace v8; |
43 | using namespace v8; |
| 42 | - | ||
| 43 | Handle<Value> VirtualMachine_log(const Arguments& args); |
- | |
| 44 | Handle<Value> VirtualMachine_sendCanMessage(const Arguments& args); |
- | |
| 45 | Handle<Value> VirtualMachine_sendCanNMTMessage(const Arguments& args); |
- | |
| 46 | Handle<Value> VirtualMachine_loadScript(const Arguments& args); |
- | |
| 47 | Handle<Value> VirtualMachine_stopIntervalThread(const Arguments& args); |
- | |
| 48 | Handle<Value> VirtualMachine_startIntervalThread(const Arguments& args); |
- | |
| 49 | Handle<Value> VirtualMachine_stopSocketThread(const Arguments& args); |
- | |
| 50 | Handle<Value> VirtualMachine_startSocketThread(const Arguments& args); |
- | |
| 51 | Handle<Value> VirtualMachine_sendToSocketThread(const Arguments& args); |
- | |
| 52 | Handle<Value> VirtualMachine_uint2hex(const Arguments& args); |
- | |
| 53 | 44 | ||
| 54 | class VirtualMachine : public Thread<VirtualMachine> |
45 | class VirtualMachine : public Thread<VirtualMachine> |
| 55 | { |
46 | { |
| 56 | public: |
47 | public: |
| 57 | static VirtualMachine& getInstance(); |
48 | static VirtualMachine& getInstance(); |
| 58 | static void deleteInstance(); |
49 | static void deleteInstance(); |
| 59 | - | ||
| 60 | void queueCanMessage(CanMessage canMessage); |
- | |
| 61 | void queueExpression(string expression); |
- | |
| 62 | 50 | ||
| 63 | void run(); |
51 | void run(); |
| - | 52 | ||
| - | 53 | void queueExpression(Expression expression); |
|
| - | 54 | void queueExpression(string script) { queueExpression(Expression(script)); }; |
|
| 64 | 55 | ||
| 65 | bool loadScript(string scriptName); |
56 | bool loadScript(string scriptName); |
| 66 | 57 | ||
| 67 | unsigned int startIntervalThread(unsigned int timeout); |
58 | unsigned int startIntervalThread(unsigned int timeout); |
| 68 | bool stopIntervalThread(unsigned int id); |
59 | bool stopIntervalThread(unsigned int id); |
| 69 | 60 | ||
| 70 | unsigned int startSocketThread(string address, int port, unsigned int reconnectTimeout); |
61 | unsigned int startSocketThread(string address, int port, unsigned int reconnectTimeout); |
| 71 | bool stopSocketThread(unsigned int id); |
62 | bool stopSocketThread(unsigned int id); |
| 72 | void sendToSocketThread(unsigned int id, string data); |
63 | void sendToSocketThread(unsigned int id, string data); |
| - | 64 | ||
| - | 65 | void sendToCommandClient(unsigned int id, string data); |
|
| - | 66 | void disconnectCommandClient(unsigned int id); |
|
| - | 67 | ||
| - | 68 | void print(unsigned int id, string data); |
|
| - | 69 | ||
| - | 70 | static Handle<Value> _quit(const Arguments& args); |
|
| - | 71 | static Handle<Value> _print(const Arguments& args); |
|
| - | 72 | static Handle<Value> _log(const Arguments& args); |
|
| - | 73 | static Handle<Value> _sendCanMessage(const Arguments& args); |
|
| - | 74 | static Handle<Value> _sendCanNMTMessage(const Arguments& args); |
|
| - | 75 | static Handle<Value> _loadScript(const Arguments& args); |
|
| - | 76 | static Handle<Value> _stopIntervalThread(const Arguments& args); |
|
| - | 77 | static Handle<Value> _startIntervalThread(const Arguments& args); |
|
| - | 78 | static Handle<Value> _stopSocketThread(const Arguments& args); |
|
| - | 79 | static Handle<Value> _startSocketThread(const Arguments& args); |
|
| - | 80 | static Handle<Value> _sendToSocketThread(const Arguments& args); |
|
| - | 81 | static Handle<Value> _uint2hex(const Arguments& args); |
|
| 73 | 82 | ||
| 74 | private: |
83 | private: |
| 75 | void callHandleNMTMessage(CanMessage canMessage); |
- | |
| 76 | void callHandleMessage(CanMessage canMessage); |
- | |
| 77 | bool runExpression( |
84 | bool runExpression(Expression expression); |
| 78 |
|
85 | string formatException(TryCatch* tryCatch); |
| 79 | 86 | ||
| 80 | VirtualMachine(); |
87 | VirtualMachine(); |
| 81 | ~VirtualMachine(); |
88 | ~VirtualMachine(); |
| 82 | static VirtualMachine* myInstance; |
89 | static VirtualMachine* myInstance; |
| 83 | 90 | ||
| 84 | Handle<Function> myFunctionHandleNMTMessage; |
- | |
| 85 | Handle<Function> myFunctionOfflineCheck; |
- | |
| 86 | Handle<Function> myFunctionHandleMessage; |
- | |
| 87 | Handle<Function> myFunctionStartup; |
91 | Handle<Function> myFunctionStartup; |
| 88 | 92 | ||
| 89 | Handle<ObjectTemplate> myGlobal; |
93 | Handle<ObjectTemplate> myGlobal; |
| 90 | HandleScope myHandleScope; |
94 | HandleScope myHandleScope; |
| 91 | Handle<Context> myContext; |
95 | Handle<Context> myContext; |
| 92 | 96 | ||
| 93 | Semaphore mySemaphore; |
97 | Semaphore mySemaphore; |
| 94 | 98 | ||
| 95 | ThreadSafeQueue< |
99 | ThreadSafeQueue<Expression> myExpressions; |
| 96 | ThreadSafeQueue<CanMessage> myCanMessages; |
- | |
| 97 | 100 | ||
| 98 | map<int, IntervalThread> myIntervalThreads; |
101 | map<int, IntervalThread*> myIntervalThreads; |
| 99 | map<int, SocketThread*> mySocketThreads; |
102 | map<int, SocketThread*> mySocketThreads; |
| - | 103 | ||
| - | 104 | CommandThread myCommandThread; |
|
| 100 | }; |
105 | }; |
| 101 | 106 | ||
| 102 | #endif /* _VIRTUALMACHINE_H */ |
107 | #endif /* _VIRTUALMACHINE_H */ |
| 103 | 108 | ||