Rev 1947 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1601 | runge | 1 | /* |
| 2 | * |
||
| 3 | * Copyright (C) 2010 Mattias Runge |
||
| 4 | * |
||
| 5 | * This program is free software; you can redistribute it and/or modify |
||
| 6 | * it under the terms of the GNU General Public License as published by |
||
| 7 | * the Free Software Foundation; either version 2 of the License, or |
||
| 8 | * (at your option) any later version. |
||
| 9 | * |
||
| 10 | * This program is distributed in the hope that it will be useful, |
||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | * GNU General Public License for more details. |
||
| 14 | * |
||
| 15 | * You should have received a copy of the GNU General Public License along |
||
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
||
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||
| 18 | * |
||
| 19 | */ |
||
| 20 | |||
| 21 | #ifndef VM_PLUGIN_H |
||
| 22 | #define VM_PLUGIN_H |
||
| 23 | |||
| 24 | #include <string> |
||
| 25 | #include <map> |
||
| 26 | #include <vector> |
||
| 27 | |||
| 28 | #include <boost/shared_ptr.hpp> |
||
| 1625 | runge | 29 | #include <boost/asio.hpp> |
| 1604 | runge | 30 | #include <v8-debug.h> |
| 1601 | runge | 31 | |
| 32 | #include "types.h" |
||
| 33 | |||
| 34 | namespace atom { |
||
| 35 | namespace vm { |
||
| 36 | |||
| 1945 | runge | 37 | #define ATOM_VM_PLUGIN_SCOPE \ |
| 38 | v8::Locker lock; \ |
||
| 39 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); \ |
||
| 40 | v8::HandleScope handle_scope; |
||
| 41 | |||
| 42 | #define ATOM_VM_PLUGIN_NUM_PARAMS(number) \ |
||
| 43 | if (args.Length() < number) \ |
||
| 44 | { \ |
||
| 1947 | runge | 45 | throw atom::exception::missing_in_param(); \ |
| 1945 | runge | 46 | } |
| 47 | |||
| 1601 | runge | 48 | class Plugin |
| 49 | { |
||
| 50 | public: |
||
| 51 | typedef boost::shared_ptr<Plugin> Pointer; |
||
| 52 | |||
| 1625 | runge | 53 | Plugin(boost::asio::io_service& io_service); |
| 1601 | runge | 54 | virtual ~Plugin(); |
| 55 | |||
| 56 | std::string GetName(); |
||
| 57 | ExportFunctionList& GetExportFunctions(); |
||
| 58 | |||
| 59 | virtual void InitializeDone(); |
||
| 1647 | runge | 60 | virtual void CallOutput(unsigned int request_id, std::string output); |
| 2107 | runge | 61 | virtual void CallResult(unsigned int request_id, std::string output); |
| 62 | |||
| 1601 | runge | 63 | protected: |
| 1604 | runge | 64 | typedef boost::shared_ptr<char> TrackerPointer; |
| 65 | |||
| 1601 | runge | 66 | std::string name_; |
| 1604 | runge | 67 | TrackerPointer tracker_; |
| 1625 | runge | 68 | boost::asio::io_service& io_service_; |
| 1601 | runge | 69 | |
| 1647 | runge | 70 | bool Call(unsigned int request_id, std::string name, ArgumentListPointer arguments); |
| 1608 | runge | 71 | void Execute(unsigned int request_id, std::string code); |
| 1601 | runge | 72 | void ExportFunction(std::string name, v8::InvocationCallback function); |
| 1608 | runge | 73 | static bool ImportFunction(std::string name); |
| 1601 | runge | 74 | |
| 75 | private: |
||
| 76 | ExportFunctionList export_functions_; |
||
| 77 | }; |
||
| 78 | |||
| 79 | }; // namespace vm |
||
| 80 | }; // namespace atom |
||
| 81 | |||
| 82 | #endif // VM_PLUGIN_H |