Subversion Repositories HomeAutomation

Rev

Rev 1656 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1601 runge 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>
1603 runge 25
#include <vector>
1601 runge 26
 
27
#include <boost/shared_ptr.hpp>
1604 runge 28
#include <v8-debug.h>
1601 runge 29
 
30
#include "logging/Logger.h"
31
#include "common/IoService.h"
1644 runge 32
#include "common/common.h"
1601 runge 33
 
1608 runge 34
#include "net/types.h"
35
 
1601 runge 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);
1656 runge 54
    void Start(std::string script_path, std::string user_script_path);
1601 runge 55
 
1608 runge 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
 
1647 runge 59
    bool CallHandler(std::string plugin_name, unsigned int request_id, std::string name, ArgumentListPointer arguments);
1625 runge 60
    void ExecuteHandler(std::string plugin_name, unsigned int request_id, std::string code);
61
 
1601 runge 62
    bool LoadScript(std::string scriptname);
1608 runge 63
    bool ImportFunction(std::string functionname);
1601 runge 64
 
1619 runge 65
    v8::Persistent<v8::Context>& GetContext();
66
 
1601 runge 67
private:
1603 runge 68
    typedef std::vector<Plugin::Pointer> PluginList;
1601 runge 69
 
70
    static Pointer instance_;
71
 
72
    std::string script_path_;
1656 runge 73
    std::string user_script_path_;
1601 runge 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_;
1644 runge 81
    common::StringList loaded_scripts_;
1647 runge 82
    std::string current_plugin_name_;
83
    unsigned int current_request_id_;    
1601 runge 84
 
85
    Manager();
86
 
87
    void StartHandler();
1625 runge 88
 
1647 runge 89
    static Value Export_Log(const v8::Arguments& args);    
1601 runge 90
 
1647 runge 91
    void CallOutput(std::string output);
2107 runge 92
    void CallResult(std::string output);
1608 runge 93
 
1601 runge 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