Subversion Repositories HomeAutomation

Rev

Rev 1603 | Rev 1608 | 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 "Plugin.h"
  34. #include "types.h"
  35.  
  36. namespace atom {
  37. namespace vm {
  38.  
  39. class Manager : public common::IoService
  40. {
  41. public:
  42.     typedef boost::shared_ptr<Manager> Pointer;
  43.    
  44.     virtual ~Manager();
  45.    
  46.     static Pointer Instance();
  47.     static void Create();
  48.     static void Delete();
  49.    
  50.     void AddPlugin(Plugin::Pointer plugin);
  51.    
  52.     void Start(std::string script_path);
  53.     void Call(std::string name, ArgumentListPointer arguments);
  54.     bool LoadScript(std::string scriptname);
  55.     bool LoadScriptHandler(std::string scriptname);
  56.    
  57. private:
  58.     typedef std::vector<Plugin::Pointer> PluginList;
  59.    
  60.     static Pointer instance_;
  61.    
  62.     std::string script_path_;
  63.    
  64.     v8::Persistent<v8::Context> context_;
  65.     v8::HandleScope handle_scope_;
  66.     v8::Persistent<v8::ObjectTemplate> object_template_;
  67.    
  68.     PluginList plugins_;
  69.     ImportFunctionList functions_;
  70.    
  71.     Manager();
  72.    
  73.     void StartHandler();
  74.     void CallHandler(std::string name, ArgumentListPointer arguments);
  75.    
  76.     std::string FormatException(v8::TryCatch& try_catch);
  77.    
  78.     logging::Logger LOG;
  79. };
  80.  
  81. }; // namespace vm
  82. }; // namespace atom
  83.  
  84. #endif // VM_MANAGER_H
  85.