Subversion Repositories HomeAutomation

Rev

Rev 1656 | 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. #include "common/common.h"
  33.  
  34. #include "net/types.h"
  35.  
  36. #include "Plugin.h"
  37. #include "types.h"
  38.  
  39. namespace atom {
  40. namespace vm {
  41.  
  42. class Manager : public common::IoService
  43. {
  44. public:
  45.     typedef boost::shared_ptr<Manager> Pointer;
  46.    
  47.     virtual ~Manager();
  48.    
  49.     static Pointer Instance();
  50.     static void Create();
  51.     static void Delete();
  52.    
  53.     void AddPlugin(Plugin::Pointer plugin);
  54.     void Start(std::string script_path, std::string user_script_path);
  55.    
  56.     void Call(std::string plugin_name, unsigned int request_id, std::string name, ArgumentListPointer arguments);
  57.     void Execute(std::string plugin_name, unsigned int request_id, std::string code);
  58.    
  59.     bool CallHandler(std::string plugin_name, unsigned int request_id, std::string name, ArgumentListPointer arguments);
  60.     void ExecuteHandler(std::string plugin_name, unsigned int request_id, std::string code);
  61.    
  62.     bool LoadScript(std::string scriptname);
  63.     bool ImportFunction(std::string functionname);
  64.    
  65.     v8::Persistent<v8::Context>& GetContext();
  66.    
  67. private:
  68.     typedef std::vector<Plugin::Pointer> PluginList;
  69.    
  70.     static Pointer instance_;
  71.    
  72.     std::string script_path_;
  73.     std::string user_script_path_;
  74.    
  75.     v8::Persistent<v8::Context> context_;
  76.     v8::HandleScope handle_scope_;
  77.     v8::Persistent<v8::ObjectTemplate> object_template_;
  78.    
  79.     PluginList plugins_;
  80.     ImportFunctionList functions_;
  81.     common::StringList loaded_scripts_;
  82.     std::string current_plugin_name_;
  83.     unsigned int current_request_id_;    
  84.    
  85.     Manager();
  86.    
  87.     void StartHandler();
  88.  
  89.     static Value Export_Log(const v8::Arguments& args);    
  90.    
  91.     void CallOutput(std::string output);
  92.     void CallResult(std::string output);
  93.    
  94.     std::string FormatException(v8::TryCatch& try_catch);
  95.    
  96.     logging::Logger LOG;
  97. };
  98.  
  99. }; // namespace vm
  100. }; // namespace atom
  101.  
  102. #endif // VM_MANAGER_H
  103.