Subversion Repositories HomeAutomation

Rev

Rev 1619 | 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.     void CallHandler(std::string plugin_name, unsigned int request_id, std::string name, ArgumentListPointer arguments);
  59.     void ExecuteHandler(std::string plugin_name, unsigned int request_id, std::string code);
  60.    
  61.     bool LoadScript(std::string scriptname);
  62.     bool ImportFunction(std::string functionname);
  63.    
  64.     v8::Persistent<v8::Context>& GetContext();
  65.    
  66. private:
  67.     typedef std::vector<Plugin::Pointer> PluginList;
  68.    
  69.     static Pointer instance_;
  70.    
  71.     std::string script_path_;
  72.    
  73.     v8::Persistent<v8::Context> context_;
  74.     v8::HandleScope handle_scope_;
  75.     v8::Persistent<v8::ObjectTemplate> object_template_;
  76.    
  77.     PluginList plugins_;
  78.     ImportFunctionList functions_;
  79.    
  80.     Manager();
  81.    
  82.     void StartHandler();
  83.  
  84.    
  85.     void SendResponse(std::string plugin_name, unsigned int request_id, std::string response);
  86.    
  87.     std::string FormatException(v8::TryCatch& try_catch);
  88.    
  89.     logging::Logger LOG;
  90. };
  91.  
  92. }; // namespace vm
  93. }; // namespace atom
  94.  
  95. #endif // VM_MANAGER_H
  96.