Subversion Repositories HomeAutomation

Rev

Rev 1608 | Rev 1644 | Go to most recent revision | 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_MANAGER_H
  22. #define VM_MANAGER_H
  23.  
  24. #include <string>
  25. #include <vector>
  26.  
  27. #include <boost/shared_ptr.hpp>
  28. #include <v8-debug.h>
  29.  
  30. #include "logging/Logger.h"
  31. #include "common/IoService.h"
  32.  
  33. #include "net/types.h"
  34.  
  35. #include "Plugin.h"
  36. #include "types.h"
  37.  
  38. namespace atom {
  39. namespace vm {
  40.  
  41. class Manager : public common::IoService
  42. {
  43. public:
  44.     typedef boost::shared_ptr<Manager> Pointer;
  45.    
  46.     virtual ~Manager();
  47.    
  48.     static Pointer Instance();
  49.     static void Create();
  50.     static void Delete();
  51.    
  52.     void AddPlugin(Plugin::Pointer plugin);
  53.     void Start(std::string script_path);
  54.    
  55.     void Call(std::string plugin_name, unsigned int request_id, std::string name, ArgumentListPointer arguments);
  56.     void Execute(std::string plugin_name, unsigned int request_id, std::string code);
  57.    
  58.     bool LoadScript(std::string scriptname);
  59.     bool ImportFunction(std::string functionname);
  60.    
  61.     v8::Persistent<v8::Context>& GetContext();
  62.    
  63. private:
  64.     typedef std::vector<Plugin::Pointer> PluginList;
  65.    
  66.     static Pointer instance_;
  67.    
  68.     std::string script_path_;
  69.    
  70.     v8::Persistent<v8::Context> context_;
  71.     v8::HandleScope handle_scope_;
  72.     v8::Persistent<v8::ObjectTemplate> object_template_;
  73.    
  74.     PluginList plugins_;
  75.     ImportFunctionList functions_;
  76.    
  77.     Manager();
  78.    
  79.     void StartHandler();
  80.    
  81.     void CallHandler(std::string plugin_name, unsigned int request_id, std::string name, ArgumentListPointer arguments);
  82.     void ExecuteHandler(std::string plugin_name, unsigned int request_id, std::string code);
  83.    
  84.     void SendResponse(std::string plugin_name, unsigned int request_id, std::string response);
  85.    
  86.     std::string FormatException(v8::TryCatch& try_catch);
  87.    
  88.     logging::Logger LOG;
  89. };
  90.  
  91. }; // namespace vm
  92. }; // namespace atom
  93.  
  94. #endif // VM_MANAGER_H
  95.