Subversion Repositories HomeAutomation

Rev

Rev 1602 | Rev 1604 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1602 Rev 1603
Line 62... Line 62...
62
    Manager::instance_.reset();
62
    Manager::instance_.reset();
63
}
63
}
64
 
64
 
65
void Manager::AddPlugin(Plugin::Pointer plugin)
65
void Manager::AddPlugin(Plugin::Pointer plugin)
66
{
66
{
67
    this->plugins_[plugin->GetName()] = plugin;
67
    this->plugins_.push_back(plugin);
68
}
68
}
69
 
69
 
70
void Manager::Start(std::string script_path)
70
void Manager::Start(std::string script_path)
71
{
71
{
72
    this->script_path_ = script_path;
72
    this->script_path_ = script_path;
Line 104... Line 104...
104
 
104
 
105
void Manager::StartHandler()
105
void Manager::StartHandler()
106
{
106
{
107
    v8::Handle<v8::ObjectTemplate> raw_template = v8::ObjectTemplate::New();
107
    v8::Handle<v8::ObjectTemplate> raw_template = v8::ObjectTemplate::New();
108
   
108
   
109
    for (PluginList::iterator it = this->plugins_.begin(); it != this->plugins_.end(); it++)
109
    for (unsigned int c = 0; c < this->plugins_.size(); c++)
110
    {
110
    {
111
        ExportFunctionList export_functions = it->second->GetExportFunctions();
111
        ExportFunctionList export_functions = this->plugins_[c]->GetExportFunctions();
112
       
112
       
113
        for (ExportFunctionList::iterator it = export_functions.begin(); it != export_functions.end(); it++)
113
        for (ExportFunctionList::iterator it = export_functions.begin(); it != export_functions.end(); it++)
114
        {
114
        {
115
            raw_template->Set(v8::String::New(it->first.data()), v8::FunctionTemplate::New(it->second));
115
            raw_template->Set(v8::String::New(it->first.data()), v8::FunctionTemplate::New(it->second));
116
        }
116
        }
Line 118... Line 118...
118
   
118
   
119
    this->context_ = v8::Context::New(NULL, raw_template);
119
    this->context_ = v8::Context::New(NULL, raw_template);
120
   
120
   
121
    v8::Context::Scope context_scope(this->context_);
121
    v8::Context::Scope context_scope(this->context_);
122
   
122
   
123
    for (PluginList::iterator it = this->plugins_.begin(); it != this->plugins_.end(); it++)
123
    for (unsigned int c = 0; c < this->plugins_.size(); c++)
124
    {
124
    {
125
        std::string scriptname = "plugin/" + it->first + ".js";
125
        std::string scriptname = "plugin/" + this->plugins_[c]->GetName() + ".js";
126
       
126
       
127
        if (this->LoadScriptHandler(scriptname))
127
        if (this->LoadScriptHandler(scriptname))
128
        {
128
        {
129
            FunctionNameList import_functions = it->second->GetImportFunctionNames();
129
            FunctionNameList import_functions = this->plugins_[c]->GetImportFunctionNames();
130
           
130
           
131
            for (unsigned int n = 0; n < import_functions.size(); n++)
131
            for (unsigned int n = 0; n < import_functions.size(); n++)
132
            {
132
            {
133
                v8::Handle<v8::String> process_name = v8::String::New(import_functions[n].data());
133
                v8::Handle<v8::String> process_name = v8::String::New(import_functions[n].data());
134
                v8::Handle<v8::Value> process_val = this->context_->Global()->Get(process_name);
134
                v8::Handle<v8::Value> process_val = this->context_->Global()->Get(process_name);
Line 148... Line 148...
148
   
148
   
149
    this->object_template_ = v8::Persistent<v8::ObjectTemplate>::New(raw_template);
149
    this->object_template_ = v8::Persistent<v8::ObjectTemplate>::New(raw_template);
150
   
150
   
151
    LOG.Info("VM initialized.");
151
    LOG.Info("VM initialized.");
152
   
152
   
153
    for (PluginList::iterator it = this->plugins_.begin(); it != this->plugins_.end(); it++)
153
    for (unsigned int c = 0; c < this->plugins_.size(); c++)
154
    {
154
    {
155
        it->second->InitializeDone();
155
        this->plugins_[c]->InitializeDone();
156
    }
156
    }
157
}
157
}
158
 
158
 
159
bool Manager::LoadScriptHandler(std::string scriptname)
159
bool Manager::LoadScriptHandler(std::string scriptname)
160
{
160
{
Line 208... Line 208...
208
            LOG.Error(this->FormatException(try_catch));
208
            LOG.Error(this->FormatException(try_catch));
209
            false;
209
            false;
210
        }
210
        }
211
    }
211
    }
212
   
212
   
213
    LOG.Info("Loaded " + scriptname + " successfully!");
213
    LOG.Info("Loaded " + scriptname + " successfully.");
214
    return true;
214
    return true;
215
}
215
}
216
 
216
 
217
std::string Manager::FormatException(v8::TryCatch& try_catch)
217
std::string Manager::FormatException(v8::TryCatch& try_catch)
218
{
218
{