ScriptableMonitorNode.cpp
Go to the documentation of this file.
00001 /*
00002  * ScriptableAnalyzerNode.cpp
00003  *
00004  *  Created on: Oct 30, 2013
00005  *      Author: blackpc
00006  */
00007 
00008 #include <scriptable_monitor/ScriptableMonitorNode.h>
00009 
00010 ScriptableMonitorNode::ScriptableMonitorNode()
00011 {
00012         _scriptHost.start();
00013 
00014         ros::NodeHandle node("~");
00015 
00016         _addScriptSubscriber =
00017                         node.subscribe("/scriptable_monitor/add_script", 0, &ScriptableMonitorNode::onAddScriptMessage, this);
00018 
00019         _deleteScriptSubscriber =
00020                         node.subscribe("/scriptable_monitor/delete_script", 0, &ScriptableMonitorNode::onDeleteScriptMessage, this);
00021 
00022         _getScriptsService =
00023                         node.advertiseService("/scriptable_monitor/get_scripts", &ScriptableMonitorNode::getScripts, this);
00024 
00025         _addScriptService =
00026                         node.advertiseService("/scriptable_monitor/add_script", &ScriptableMonitorNode::addScript, this);
00027 }
00028 
00029 ScriptableMonitorNode::~ScriptableMonitorNode()
00030 {
00031         _addScriptSubscriber.shutdown();
00032         _deleteScriptSubscriber.shutdown();
00033         _scriptHost.stop();
00034 }
00035 
00036 bool ScriptableMonitorNode::addScript(
00037                 scriptable_monitor::AddScriptRequest& request,
00038                 scriptable_monitor::AddScriptResponse& response)
00039 {
00040         cout << "================================================" << endl;
00041         cout << request.script.data << endl;
00042         cout << "================================================" << endl;
00043 
00044         AddScriptResponse addScriptResponse = _scriptHost.addScript(request.script.data);
00045 
00046         response.message.data = addScriptResponse.message;
00047         response.success = addScriptResponse.success ? 1 : 0;
00048 
00049         return true;
00050 }
00051 
00052 bool ScriptableMonitorNode::getScripts(
00053                 scriptable_monitor::GetScriptsRequest& request,
00054                 scriptable_monitor::GetScriptsResponse& response)
00055 {
00056         set<PythonScriptPtr> scripts = _scriptHost.getScripts();
00057 
00058         foreach(PythonScriptPtr script, scripts) {
00059                 scriptable_monitor::Script s;
00060 
00061                 s.name = script->getName();
00062                 s.interval = script->getInterval();
00063                 s.validations = script->getValidations();
00064                 s.type = "Python";
00065                 s.fail_type = (int)script->getFailType();
00066                 // s.last_execution = script->getExecutionTime
00067 
00068                 foreach(string topic, script->getUsedTopics())
00069                         s.topics.push_back(topic);
00070 
00071                 foreach(string function, script->getUsedInternalFunction())
00072                         s.functions.push_back(function);
00073 
00074                 response.scripts.push_back(s);
00075         }
00076 
00077         return true;
00078 }
00079 
00080 void ScriptableMonitorNode::onAddScriptMessage(
00081                 const std_msgs::String::ConstPtr script)
00082 {
00083         _scriptHost.addScript(script->data);
00084 }
00085 
00086 void ScriptableMonitorNode::onDeleteScriptMessage(
00087                 const std_msgs::String::ConstPtr scriptName)
00088 {
00089         _scriptHost.deleteScript(scriptName->data);
00090 }


scriptable_monitor
Author(s):
autogenerated on Wed Aug 26 2015 16:21:30