void NetworkQueue::execute_script ( const QString & filename ) { if( m_script_file->isOpen() ) throw IllegalCall( FromHere(), "Another script is already in execution." ); m_script_file->setFileName( filename ); if( !m_script_file->exists() ) throw FileSystemError( FromHere(), "The file [" + filename.toStdString() + "] does not exist." ); BasicCommands::dispatcher = this; BasicCommands::tree_root = ThreadManager::instance().tree().root(); BasicCommands::current_component = ThreadManager::instance().tree().root(); if( !m_script_file->open( QIODevice::ReadOnly ) ) NLog::global()->add_error( m_script_file->errorString() ); else { NLog::global()->add_message("Running script: " + filename); m_script_stream->setDevice( m_script_file ); if(!filename.endsWith(".py")) // non-python, assume CFscript { send_next_command(); } else // python { const URI script_engine_path("//Tools/Python/ScriptEngine", common::URI::Scheme::CPATH); SignalOptions options; options.add("script", m_script_stream->readAll().toStdString()); SignalFrame frame = options.create_frame("execute_script", script_engine_path, script_engine_path); dispatch_signal("execute_script", script_engine_path, frame); } } }
void CJournal::execute_signals (const boost::filesystem::path & filename) { if (m_root.expired()) throw IllegalCall(FromHere(), "Component \'" + name() + "\' has no root"); boost::shared_ptr<XmlDoc> xmldoc = XML::parse_file(filename); XmlNode doc_node = Protocol::goto_doc_node(*xmldoc.get()); // rapidxml::xml_node * signals_map = doc_node.content->first_node(); // bool found_map = false; rapidxml::xml_node<>* node = nullptr; // rapidxml::xml_attribute<>* key_attr = nullptr; CRoot& root = Core::instance().root(); const char * frame_tag = Protocol::Tags::node_frame(); XmlNode signal_map = Map(doc_node).find_value( Protocol::Tags::key_signals() ); // for( ; signals_map != nullptr ; signals_map = signals_map->next_sibling()) // { // key_attr = signals_map->first_attribute("key"); // found_map = key_attr != nullptr && std::strcmp(key_attr->value(), "signals") == 0; // if(found_map) // break; // } if( !signal_map.is_valid() ) throw XmlError(FromHere(), "Could not find \'signals\' map."); node = signal_map.content->first_node( frame_tag ); for( ; node != nullptr ; node = node->next_sibling(frame_tag) ) { rapidxml::xml_attribute<>* type_attr = node->first_attribute("type"); if(type_attr != nullptr && std::strcmp(type_attr->value(), "signal") == 0) { rapidxml::xml_attribute<>* target_attr = node->first_attribute("target"); rapidxml::xml_attribute<>* receiver_attr = node->first_attribute("receiver"); std::string target = target_attr != nullptr ? target_attr->value() : ""; std::string receiver = receiver_attr != nullptr ? receiver_attr->value() : ""; if(target.empty()) CFwarn << "Warning: missing or empty target. Skipping this signal." << CFendl; if(receiver.empty()) CFwarn << "Warning: missing or empty receiver. Skipping this signal." << CFendl; if(receiver == "//Root/Core") // server specific component continue; try { SignalFrame sf(node); root.retrieve_component(receiver)->call_signal(target, sf); } catch(Exception & e) { CFerror << e.what() << CFendl; } } } }