$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 /*-------------------------------------------------------------------- 00002 To compile: make 00003 To run: 00004 --------------------------------------------------------------------*/ 00005 00006 #include "Tests/SimpleSoap/include/SimpleSoap.h" 00007 #include <xdaq/NamespaceURI.h> 00008 #include <xoap/Method.h> 00009 #include <iostream> 00010 #include "Utilities/MacroUtilities/include/Macro.h" 00011 #include "Utilities/SOAPUtilities/include/SOAPUtilities.h" 00012 00013 using namespace ots; 00014 00015 XDAQ_INSTANTIATOR_IMPL(SimpleSoap) 00016 00017 //======================================================================================================================== 00018 SimpleSoap::SimpleSoap(xdaq::ApplicationStub* s) 00019 : xdaq::Application(s), SOAPMessenger(this) 00020 { 00021 xgi::bind(this, &SimpleSoap::Default, "Default"); 00022 xgi::bind(this, &SimpleSoap::StateMachineXgiHandler, "StateMachineXgiHandler"); 00023 00024 xoap::bind(this, &SimpleSoap::Start, "Start", XDAQ_NS_URI); 00025 fsm_.addState('I', "Initial", this, &SimpleSoap::stateInitial); 00026 fsm_.addState('H', "Halted", this, &SimpleSoap::stateHalted); 00027 fsm_.addStateTransition('I', 'H', "Initialize"); 00028 } 00029 00030 //======================================================================================================================== 00031 void SimpleSoap::Default(xgi::Input* in, xgi::Output* out) 00032 { 00033 std::string url = "/" + getApplicationDescriptor()->getURN(); 00034 std::cout << __COUT_HDR_FL__ << url << std::endl; 00035 // url = "http://131.225.82.72:1983"; 00036 *out << cgicc::HTMLDoctype(cgicc::HTMLDoctype::eStrict) << std::endl; 00037 *out << cgicc::html().set("lang", "en").set("dir", "ltr") << std::endl; 00038 *out << cgicc::title("Simple button page") << std::endl; 00039 *out << "<body>" << std::endl; 00040 *out << " <form name=\"input\" method=\"get\" action=\"" << url 00041 << "/StateMachineXgiHandler" 00042 << "\" enctype=\"multipart/form-data\">" << std::endl; 00043 *out << " <p align=\"left\"><input type=\"submit\" name=\"StateInput\" " 00044 "value=\"PushStart\"/></p>" 00045 << std::endl; 00046 *out << " </form>" << std::endl; 00047 *out << " <form name=\"input\" method=\"get\" action=\"" << url << "/Start" 00048 << "\" enctype=\"multipart/form-data\">" << std::endl; 00049 *out << " <p align=\"left\"><input type=\"submit\" name=\"StateInput\" " 00050 "value=\"Start\"/></p>" 00051 << std::endl; 00052 *out << " </form>" << std::endl; 00053 *out << "</body>" << std::endl; 00054 } 00055 00056 //======================================================================================================================== 00057 void SimpleSoap::StateMachineXgiHandler(xgi::Input* in, xgi::Output* out) 00058 { 00059 cgicc::Cgicc cgi(in); 00060 std::string Command = cgi.getElement("StateInput")->getValue(); 00061 00062 if(Command == "PushStart") 00063 { 00064 std::cout << __COUT_HDR_FL__ << "Got start" << std::endl; 00065 xoap::MessageReference msg = SOAPUtilities::makeSOAPMessageReference("Start"); 00066 xoap::MessageReference reply = Start(msg); 00067 00068 if(receive(reply) == "StartDone") 00069 std::cout << __COUT_HDR_FL__ << "Everything started correctly!" << std::endl 00070 << std::endl; 00071 else 00072 std::cout 00073 << __COUT_HDR_FL__ 00074 << "All underlying Supervisors could not be started by browser button!" 00075 << std::endl 00076 << std::endl; 00077 } 00078 else if(Command == "Start") 00079 { 00080 // std::set<xdaq::ApplicationDescriptor*> set_SimpleSoap = 00081 // getApplicationContext()->getDefaultZone()->getApplicationGroup("rivera")->getApplicationDescriptors("SimpleSoap::SimpleSoap"); 00082 std::set<xdaq::ApplicationDescriptor*> set_SimpleSoap = 00083 getApplicationContext() 00084 ->getDefaultZone() 00085 ->getApplicationGroup("daq") 00086 ->getApplicationDescriptors("SimpleSoap::SimpleSoap"); 00087 00088 for(std::set<xdaq::ApplicationDescriptor*>::iterator i_set_SimpleSoap = 00089 set_SimpleSoap.begin(); 00090 i_set_SimpleSoap != set_SimpleSoap.end(); 00091 ++i_set_SimpleSoap) 00092 { 00093 try 00094 { 00095 std::string sReply = send(*i_set_SimpleSoap, Command.c_str()); 00096 00097 if(sReply == "StartDone") 00098 std::cout << __COUT_HDR_FL__ << "Everything started correctly!" 00099 << std::endl 00100 << std::endl; 00101 else 00102 std::cout << __COUT_HDR_FL__ 00103 << "All underlying Supervisors could not be started by " 00104 "browser button!" 00105 << std::endl 00106 << std::endl; 00107 } 00108 catch(xdaq::exception::Exception& e) 00109 { 00110 std::cout << __COUT_HDR_FL__ 00111 //<< std::stringF((*i_set_SimpleSoap)->getInstance()) 00112 << " Couldn't start sending a msg" << std::endl; 00113 } 00114 } 00115 } 00116 else 00117 { 00118 std::cout << __COUT_HDR_FL__ << "Don't understand the command: " << Command 00119 << std::endl; 00120 } 00121 00122 this->Default(in, out); 00123 } 00124 00125 //======================================================================================================================== 00126 xoap::MessageReference SimpleSoap::Start(xoap::MessageReference msg) 00127 { 00128 std::cout << __COUT_HDR_FL__ << "Starting" << std::endl; 00129 return SOAPUtilities::makeSOAPMessageReference("StartDone"); 00130 } 00131 00132 //======================================================================================================================== 00133 void SimpleSoap::stateInitial(toolbox::fsm::FiniteStateMachine& fsm) 00134 { 00135 std::cout << __COUT_HDR_FL__ << "--- SimpleWeb is in its Initial state ---" 00136 << std::endl; 00137 state_ = fsm_.getStateName(fsm_.getCurrentState()); 00138 00139 // diagService_->reportError("PixelSupervisor::stateInitial: workloop active: 00140 // "+stringF(calibWorkloop_->isActive())+", workloop type: 00141 // "+calibWorkloop_->getType(),DIAGINFO); 00142 } 00143 00144 //======================================================================================================================== 00145 void SimpleSoap::stateHalted(toolbox::fsm::FiniteStateMachine& fsm) 00146 { 00147 std::cout << __COUT_HDR_FL__ << "--- SimpleWeb is in its Halted state ---" 00148 << std::endl; 00149 state_ = fsm_.getStateName(fsm_.getCurrentState()); 00150 }