Subversion Repositories HomeAutomation

Rev

Rev 1947 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  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>
  29. #include <boost/asio.hpp>
  30. #include <v8-debug.h>
  31.  
  32. #include "types.h"
  33.  
  34. namespace atom {
  35. namespace vm {
  36.  
  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.   {                                                                           \
  45.     throw atom::exception::missing_in_param();                                  \
  46.   }
  47.  
  48. class Plugin
  49. {
  50. public:
  51.     typedef boost::shared_ptr<Plugin> Pointer;
  52.    
  53.     Plugin(boost::asio::io_service& io_service);
  54.     virtual ~Plugin();
  55.    
  56.     std::string GetName();
  57.     ExportFunctionList& GetExportFunctions();
  58.    
  59.     virtual void InitializeDone();
  60.     virtual void CallOutput(unsigned int request_id, std::string output);
  61.     virtual void CallResult(unsigned int request_id, std::string output);
  62.  
  63. protected:
  64.     typedef boost::shared_ptr<char> TrackerPointer;
  65.    
  66.     std::string name_;
  67.     TrackerPointer tracker_;
  68.     boost::asio::io_service& io_service_;
  69.    
  70.     bool Call(unsigned int request_id, std::string name, ArgumentListPointer arguments);
  71.     void Execute(unsigned int request_id, std::string code);
  72.     void ExportFunction(std::string name, v8::InvocationCallback function);
  73.     static bool ImportFunction(std::string name);
  74.    
  75. private:
  76.     ExportFunctionList export_functions_;
  77. };
  78.  
  79. }; // namespace vm
  80. }; // namespace atom
  81.  
  82. #endif // VM_PLUGIN_H
  83.