Subversion Repositories HomeAutomation

Rev

Rev 1604 | 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 <map>
  26.  
  27. #include <boost/shared_ptr.hpp>
  28. #include <v8.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.     friend class Plugin;
  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.    
  54.     void Start(std::string script_path);
  55.     void Call(std::string name, ArgumentListPointer arguments);
  56.     bool LoadScript(std::string scriptname);
  57.    
  58. private:
  59.     typedef std::map<std::string, Plugin::Pointer> PluginList;
  60.    
  61.     static Pointer instance_;
  62.    
  63.     std::string script_path_;
  64.    
  65.     v8::Persistent<v8::Context> context_;
  66.     v8::HandleScope handle_scope_;
  67.     v8::Persistent<v8::ObjectTemplate> object_template_;
  68.    
  69.     PluginList plugins_;
  70.     ImportFunctionList functions_;
  71.    
  72.     Manager();
  73.    
  74.     void StartHandler();
  75.     void CallHandler(std::string name, ArgumentListPointer arguments);
  76.     bool LoadScriptHandler(std::string scriptname);
  77.    
  78.     std::string FormatException(v8::TryCatch& try_catch);
  79.    
  80.     logging::Logger LOG;
  81. };
  82.  
  83. }; // namespace vm
  84. }; // namespace atom
  85.  
  86. #endif // VM_MANAGER_H
  87.