Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 969 | runge | 1 | /*************************************************************************** |
| 2 | * Copyright (C) December 10, 2008 by Mattias Runge * |
||
| 3 | * mattias@runge.se * |
||
| 4 | * virtualmachine.h * |
||
| 5 | * * |
||
| 6 | * This program is free software; you can redistribute it and/or modify * |
||
| 7 | * it under the terms of the GNU General Public License as published by * |
||
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
||
| 9 | * (at your option) any later version. * |
||
| 10 | * * |
||
| 11 | * This program is distributed in the hope that it will be useful, * |
||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
| 14 | * GNU General Public License for more details. * |
||
| 15 | * * |
||
| 16 | * You should have received a copy of the GNU General Public License * |
||
| 17 | * along with this program; if not, write to the * |
||
| 18 | * Free Software Foundation, Inc., * |
||
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
| 20 | ***************************************************************************/ |
||
| 21 | |||
| 22 | #ifndef _VIRTUALMACHINE_H |
||
| 23 | #define _VIRTUALMACHINE_H |
||
| 24 | |||
| 25 | using namespace std; |
||
| 26 | |||
| 27 | #include <map> |
||
| 28 | #include <string> |
||
| 29 | #include <queue> |
||
| 30 | |||
| 31 | #include "../v8/include/v8.h" |
||
| 32 | #include "../SyslogStream/syslogstream.h" |
||
| 33 | #include "../Settings/settings.h" |
||
| 34 | #include "../CanNet/cannetmanager.h" |
||
| 35 | #include "../CanNet/canmessage.h" |
||
| 36 | #include "../Threads/semaphore.h" |
||
| 37 | #include "../Threads/threadsafequeue.h" |
||
| 38 | #include "intervalthread.h" |
||
| 976 | runge | 39 | #include "socketthread.h" |
| 969 | runge | 40 | |
| 41 | using namespace v8; |
||
| 42 | |||
| 43 | Handle<Value> VirtualMachine_log(const Arguments& args); |
||
| 44 | Handle<Value> VirtualMachine_sendCanMessage(const Arguments& args); |
||
| 986 | runge | 45 | Handle<Value> VirtualMachine_sendCanNMTMessage(const Arguments& args); |
| 969 | runge | 46 | Handle<Value> VirtualMachine_loadScript(const Arguments& args); |
| 971 | runge | 47 | Handle<Value> VirtualMachine_stopIntervalThread(const Arguments& args); |
| 48 | Handle<Value> VirtualMachine_startIntervalThread(const Arguments& args); |
||
| 976 | runge | 49 | Handle<Value> VirtualMachine_stopSocketThread(const Arguments& args); |
| 50 | Handle<Value> VirtualMachine_startSocketThread(const Arguments& args); |
||
| 51 | Handle<Value> VirtualMachine_sendToSocketThread(const Arguments& args); |
||
| 981 | runge | 52 | Handle<Value> VirtualMachine_uint2hex(const Arguments& args); |
| 969 | runge | 53 | |
| 54 | class VirtualMachine : public Thread<VirtualMachine> |
||
| 55 | { |
||
| 56 | public: |
||
| 57 | static VirtualMachine& getInstance(); |
||
| 58 | static void deleteInstance(); |
||
| 59 | |||
| 60 | void queueCanMessage(CanMessage canMessage); |
||
| 61 | void queueExpression(string expression); |
||
| 62 | |||
| 63 | void run(); |
||
| 64 | |||
| 65 | bool loadScript(string scriptName); |
||
| 976 | runge | 66 | |
| 971 | runge | 67 | unsigned int startIntervalThread(unsigned int timeout); |
| 68 | bool stopIntervalThread(unsigned int id); |
||
| 969 | runge | 69 | |
| 976 | runge | 70 | unsigned int startSocketThread(string address, int port, unsigned int reconnectTimeout); |
| 71 | bool stopSocketThread(unsigned int id); |
||
| 72 | void sendToSocketThread(unsigned int id, string data); |
||
| 73 | |||
| 969 | runge | 74 | private: |
| 986 | runge | 75 | void callHandleNMTMessage(CanMessage canMessage); |
| 969 | runge | 76 | void callHandleMessage(CanMessage canMessage); |
| 77 | bool runExpression(string expression); |
||
| 995 | runge | 78 | void printException(TryCatch* tryCatch); |
| 969 | runge | 79 | |
| 80 | VirtualMachine(); |
||
| 81 | ~VirtualMachine(); |
||
| 82 | static VirtualMachine* myInstance; |
||
| 83 | |||
| 986 | runge | 84 | Handle<Function> myFunctionHandleNMTMessage; |
| 969 | runge | 85 | Handle<Function> myFunctionOfflineCheck; |
| 86 | Handle<Function> myFunctionHandleMessage; |
||
| 87 | Handle<Function> myFunctionStartup; |
||
| 88 | |||
| 89 | Handle<ObjectTemplate> myGlobal; |
||
| 90 | HandleScope myHandleScope; |
||
| 91 | Handle<Context> myContext; |
||
| 92 | |||
| 93 | Semaphore mySemaphore; |
||
| 94 | |||
| 95 | ThreadSafeQueue<string> myExpressions; |
||
| 96 | ThreadSafeQueue<CanMessage> myCanMessages; |
||
| 97 | |||
| 971 | runge | 98 | map<int, IntervalThread> myIntervalThreads; |
| 983 | runge | 99 | map<int, SocketThread*> mySocketThreads; |
| 969 | runge | 100 | }; |
| 101 | |||
| 102 | #endif /* _VIRTUALMACHINE_H */ |
||
| 103 |