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" |
||
| 39 | |||
| 40 | using namespace v8; |
||
| 41 | |||
| 42 | Handle<Value> VirtualMachine_log(const Arguments& args); |
||
| 43 | Handle<Value> VirtualMachine_sendCanMessage(const Arguments& args); |
||
| 44 | Handle<Value> VirtualMachine_loadScript(const Arguments& args); |
||
| 45 | Handle<Value> VirtualMachine_clearInterval(const Arguments& args); |
||
| 46 | Handle<Value> VirtualMachine_setTimeout(const Arguments& args); |
||
| 47 | Handle<Value> VirtualMachine_setInterval(const Arguments& args); |
||
| 48 | |||
| 49 | class VirtualMachine : public Thread<VirtualMachine> |
||
| 50 | { |
||
| 51 | public: |
||
| 52 | static VirtualMachine& getInstance(); |
||
| 53 | static void deleteInstance(); |
||
| 54 | |||
| 55 | void queueCanMessage(CanMessage canMessage); |
||
| 56 | void queueExpression(string expression); |
||
| 57 | |||
| 58 | void run(); |
||
| 59 | |||
| 60 | bool loadScript(string scriptName); |
||
| 61 | int setInterval(string expression, int interval, bool single); |
||
| 62 | bool clearInterval(int timeoutId); |
||
| 63 | |||
| 64 | private: |
||
| 65 | void callHandleHeartbeat(int hardwareId); |
||
| 66 | void callHandleMessage(CanMessage canMessage); |
||
| 67 | bool runExpression(string expression); |
||
| 68 | |||
| 69 | VirtualMachine(); |
||
| 70 | ~VirtualMachine(); |
||
| 71 | static VirtualMachine* myInstance; |
||
| 72 | |||
| 73 | Handle<Function> myFunctionHandleHeartbeat; |
||
| 74 | Handle<Function> myFunctionOfflineCheck; |
||
| 75 | Handle<Function> myFunctionHandleMessage; |
||
| 76 | Handle<Function> myFunctionStartup; |
||
| 77 | |||
| 78 | Handle<ObjectTemplate> myGlobal; |
||
| 79 | HandleScope myHandleScope; |
||
| 80 | Handle<Context> myContext; |
||
| 81 | |||
| 82 | Semaphore mySemaphore; |
||
| 83 | |||
| 84 | ThreadSafeQueue<string> myExpressions; |
||
| 85 | ThreadSafeQueue<CanMessage> myCanMessages; |
||
| 86 | |||
| 87 | map<int, IntervalThread> myTimers; |
||
| 88 | }; |
||
| 89 | |||
| 90 | #endif /* _VIRTUALMACHINE_H */ |
||
| 91 |