Subversion Repositories HomeAutomation

Rev

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

Rev 1657 Rev 1679
Line 23... Line 23...
23
#include <v8-debug.h>
23
#include <v8-debug.h>
24
#include <stdio.h>
24
#include <stdio.h>
25
 
25
 
26
#include "vm/Manager.h"
26
#include "vm/Manager.h"
27
#include "common/common.h"
27
#include "common/common.h"
-
 
28
#include "config.h"
28
 
29
 
29
namespace atom {
30
namespace atom {
30
namespace vm {
31
namespace vm {
31
namespace plugin {
32
namespace plugin {
32
 
33
 
Line 37... Line 38...
37
    this->name_ = "system";
38
    this->name_ = "system";
38
   
39
   
39
    this->ExportFunction("Require",    System::Export_Require);
40
    this->ExportFunction("Require",              System::Export_Require);
40
    this->ExportFunction("Execute",    System::Export_Execute);
41
    this->ExportFunction("Execute",              System::Export_Execute);
41
    this->ExportFunction("ToHex",      System::Export_ToHex);
42
    this->ExportFunction("ToHex",                System::Export_ToHex);
-
 
43
    this->ExportFunction("SystemExport_Version", System::Export_Version);
-
 
44
    this->ExportFunction("SystemExport_License", System::Export_License);
42
}
45
}
43
 
46
 
44
System::~System()
47
System::~System()
45
{
48
{
46
 
49
 
47
}
50
}
48
 
51
 
49
void System::InitializeDone()
52
void System::InitializeDone()
50
{
53
{
51
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
52
   
-
 
53
    Plugin::InitializeDone();
54
    Plugin::InitializeDone();
54
   
55
   
55
    v8::Boolean::New(Manager::Instance()->LoadScript("interface/list.js"));
56
    Manager::Instance()->LoadScript("interface/list.js");
56
    v8::Boolean::New(Manager::Instance()->LoadScript("autostart.js"));
57
    Manager::Instance()->LoadScript("autostart.js");
57
}
58
}
58
 
59
 
59
void System::CallOutput(unsigned int request_id, std::string output)
60
void System::CallOutput(unsigned int request_id, std::string output)
60
{
61
{
61
    LOG.Info(output);
62
    LOG.Info(output);
62
}
63
}
63
 
64
 
64
Value System::Export_Require(const v8::Arguments& args)
65
Value System::Export_Require(const v8::Arguments& args)
65
{
66
{
66
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
67
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
67
   
68
   
68
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
69
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
69
   
70
   
70
    if (args.Length() < 1)
71
    if (args.Length() < 1)
71
    {
72
    {
72
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
73
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
73
        return v8::Boolean::New(false);
74
        return v8::Boolean::New(false);
74
    }
75
    }
75
   
76
   
76
    v8::String::AsciiValue str(args[0]);
77
    v8::String::AsciiValue str(args[0]);
77
   
78
   
78
    return v8::Boolean::New(Manager::Instance()->LoadScript(*str));
79
    return v8::Boolean::New(Manager::Instance()->LoadScript(*str));
79
}
80
}
80
 
81
 
81
Value System::Export_Execute(const v8::Arguments& args)
82
Value System::Export_Execute(const v8::Arguments& args)
82
{
83
{
83
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
84
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
84
   
85
   
85
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
86
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
86
   
87
   
87
    if (args.Length() < 1)
88
    if (args.Length() < 1)
88
    {
89
    {
89
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
90
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
90
        return v8::Boolean::New(false);
91
        return v8::Boolean::New(false);
91
    }
92
    }
92
   
93
   
93
    v8::String::AsciiValue command(args[0]);
94
    v8::String::AsciiValue command(args[0]);
94
   
95
   
95
    std::string output_buffer;
96
    std::string output_buffer;
96
    char output[128];
97
    char output[128];
97
   
98
   
Line 106... Line 107...
106
    while (!feof(pipe))
107
    while (!feof(pipe))
107
    {
108
    {
108
        if (fgets(output, 128, pipe) != NULL)
109
        if (fgets(output, 128, pipe) != NULL)
109
        {
110
        {
110
            output_buffer += output;
111
            output_buffer += output;
111
        }
112
        }
112
    }
113
    }
113
   
114
   
114
    pclose(pipe);
115
    pclose(pipe);
115
   
116
   
116
    return v8::String::New(output_buffer.data());
117
    return v8::String::New(output_buffer.data());
117
}
118
}
118
 
119
 
119
Value System::Export_ToHex(const v8::Arguments& args)
120
Value System::Export_ToHex(const v8::Arguments& args)
120
{
121
{
121
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
122
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
122
   
123
   
123
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
124
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
124
   
125
   
125
    if (args.Length() < 1)
126
    if (args.Length() < 1)
126
    {
127
    {
127
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
128
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
128
        return v8::Boolean::New(false);
129
        return v8::Boolean::New(false);
129
    }
130
    }
130
   
131
   
131
    return v8::String::New(common::ToHex(args[0]->Uint32Value()).data());
132
    return v8::String::New(common::ToHex(args[0]->Uint32Value()).data());
-
 
133
}
-
 
134
 
-
 
135
Value System::Export_Version(const v8::Arguments& args)
-
 
136
{
-
 
137
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
138
    return v8::String::New(VERSION);
-
 
139
}
-
 
140
 
-
 
141
Value System::Export_License(const v8::Arguments& args)
-
 
142
{
-
 
143
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
144
    return v8::String::New(LICENSE);
132
}
145
}
133
 
146
 
134
}; // namespace plugin
147
}; // namespace plugin
135
}; // namespace vm
148
}; // namespace vm
136
}; // namespace atom
149
}; // namespace atom