Subversion Repositories HomeAutomation

Rev

Rev 1012 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1012 Rev 1024
Line 126... Line 126...
126
        myCommandThread.setSettings(stoi(commandPort), "Command console");
126
        myCommandThread.setSettings(stoi(commandPort), "Command console");
127
        myCommandThread.start();
127
        myCommandThread.start();
128
    }
128
    }
129
    else
129
    else
130
    {
130
    {
131
        SyslogStream &slog = SyslogStream::getInstance();
131
        Logger &log = Logger::getInstance();
132
        slog << "CommandPort is not defined, can not start Command console socket\n";
132
        log.add("CommandPort is not defined, can not start Command console socket\n");
133
    }
133
    }
134
 
134
 
135
 
135
 
136
    mySemaphore.lock();
136
    mySemaphore.lock();
137
 
137
 
Line 189... Line 189...
189
    return result;
189
    return result;
190
}
190
}
191
 
191
 
192
bool VirtualMachine::loadDataStore(string storeName)
192
bool VirtualMachine::loadDataStore(string storeName)
193
{
193
{
194
    SyslogStream &slog = SyslogStream::getInstance();
194
    Logger &log = Logger::getInstance();
195
 
195
 
196
    string basePath = Settings::get("BasePath") + "Services/DataStores/";
196
    string basePath = Settings::get("BasePath") + "Services/DataStores/";
197
    string scriptFileName = basePath + storeName + ".js";
197
    string scriptFileName = basePath + storeName + ".js";
198
 
198
 
199
    if (!file_exists(scriptFileName))
199
    if (!file_exists(scriptFileName))
200
    {
200
    {
201
        slog << "Failed to load datastore " + scriptFileName + ", file does not exist.\n";
201
        log.add("Failed to load datastore " + scriptFileName + ", file does not exist.\n");
202
        return false;
202
        return false;
203
    }
203
    }
204
 
204
 
205
    string scriptSource = file_get_contents(scriptFileName);
205
    string scriptSource = file_get_contents(scriptFileName);
206
 
206
 
Line 215... Line 215...
215
 
215
 
216
    Handle<Script> script = Script::Compile(source, name);
216
    Handle<Script> script = Script::Compile(source, name);
217
 
217
 
218
    if (script.IsEmpty())
218
    if (script.IsEmpty())
219
    {
219
    {
220
        slog << formatException(&tryCatch);
220
        log.add(formatException(&tryCatch));
221
        return false;
221
        return false;
222
    }
222
    }
223
    else
223
    else
224
    {
224
    {
225
        Handle<Value> result = script->Run();
225
        Handle<Value> result = script->Run();
226
 
226
 
227
        if (result.IsEmpty())
227
        if (result.IsEmpty())
228
        {
228
        {
229
            slog << formatException(&tryCatch);
229
            log.add(formatException(&tryCatch));
230
            return false;
230
            return false;
231
        }
231
        }
232
 
232
 
233
        slog << "Loaded datastore " + storeName + "\n";
233
        log.add("Loaded datastore " + storeName + "\n");
234
    }
234
    }
235
 
235
 
236
    return true;
236
    return true;
237
}
237
}
238
 
238
 
239
bool VirtualMachine::loadScript(string scriptName)
239
bool VirtualMachine::loadScript(string scriptName)
240
{
240
{
241
    SyslogStream &slog = SyslogStream::getInstance();
241
    Logger &log = Logger::getInstance();
242
 
242
 
243
    string basePath = Settings::get("BasePath") + "Services/";
243
    string basePath = Settings::get("BasePath") + "Services/";
244
    string scriptFileName = basePath + scriptName;
244
    string scriptFileName = basePath + scriptName;
245
 
245
 
246
    if (!file_exists(scriptFileName))
246
    if (!file_exists(scriptFileName))
247
    {
247
    {
248
        slog << "Failed to load " + scriptFileName + ", file does not exist.\n";
248
        log.add("Failed to load " + scriptFileName + ", file does not exist.\n");
249
        return false;
249
        return false;
250
    }
250
    }
251
 
251
 
252
    string scriptSource = file_get_contents(scriptFileName);
252
    string scriptSource = file_get_contents(scriptFileName);
253
 
253
 
Line 260... Line 260...
260
 
260
 
261
    Handle<Script> script = Script::Compile(source, name);
261
    Handle<Script> script = Script::Compile(source, name);
262
 
262
 
263
    if (script.IsEmpty())
263
    if (script.IsEmpty())
264
    {
264
    {
265
        slog << formatException(&tryCatch);
265
        log.addToSyslog(formatException(&tryCatch));
266
        return false;
266
        return false;
267
    }
267
    }
268
    else
268
    else
269
    {
269
    {
270
        Handle<Value> result = script->Run();
270
        Handle<Value> result = script->Run();
271
 
271
 
272
        if (result.IsEmpty())
272
        if (result.IsEmpty())
273
        {
273
        {
274
            slog << formatException(&tryCatch);
274
            log.addToSyslog(formatException(&tryCatch));
275
            return false;
275
            return false;
276
        }
276
        }
277
 
277
 
278
        slog << "Loaded " + scriptName + "\n";
278
        log.add("Loaded " + scriptName + "\n");
279
    }
279
    }
280
 
280
 
281
    return true;
281
    return true;
282
}
282
}
283
 
283
 
Line 344... Line 344...
344
 
344
 
345
void VirtualMachine::print(unsigned int id, string data)
345
void VirtualMachine::print(unsigned int id, string data)
346
{
346
{
347
    if (id == 0)
347
    if (id == 0)
348
    {
348
    {
349
        SyslogStream &slog = SyslogStream::getInstance();
349
        Logger &log = Logger::getInstance();
350
        slog << data;
350
        log.add(data);
351
    }
351
    }
352
    else
352
    else
353
    {
353
    {
354
        VirtualMachine &vm = VirtualMachine::getInstance();
354
        VirtualMachine &vm = VirtualMachine::getInstance();
355
        vm.sendToCommandClient(id, data);
355
        vm.sendToCommandClient(id, data);
Line 412... Line 412...
412
    return Undefined();
412
    return Undefined();
413
}
413
}
414
 
414
 
415
Handle<Value> VirtualMachine::_log(const Arguments& args)
415
Handle<Value> VirtualMachine::_log(const Arguments& args)
416
{
416
{
417
    SyslogStream &slog = SyslogStream::getInstance();
417
    Logger &log = Logger::getInstance();
418
 
418
 
419
    String::AsciiValue str(args[0]);
419
    String::AsciiValue str(args[0]);
420
 
420
 
421
    slog << *str;
421
    log.add(*str);
422
 
422
 
423
    return Undefined();
423
    return Undefined();
424
}
424
}
425
 
425
 
426
Handle<Value> VirtualMachine::_print(const Arguments& args)
426
Handle<Value> VirtualMachine::_print(const Arguments& args)