6 #include "Tests/SimpleSoap/include/SimpleSoap.h"
7 #include <xdaq/NamespaceURI.h>
8 #include <xoap/Method.h>
10 #include "Utilities/MacroUtilities/include/Macro.h"
11 #include "Utilities/SOAPUtilities/include/SOAPUtilities.h"
20 xgi::bind(
this, &SimpleSoap::Default,
"Default");
21 xgi::bind(
this, &SimpleSoap::StateMachineXgiHandler,
"StateMachineXgiHandler");
23 xoap::bind(
this, &SimpleSoap::Start,
"Start", XDAQ_NS_URI);
24 fsm_.addState(
'I',
"Initial",
this, &SimpleSoap::stateInitial);
25 fsm_.addState(
'H',
"Halted",
this, &SimpleSoap::stateHalted);
26 fsm_.addStateTransition(
'I',
'H',
"Initialize");
30 void SimpleSoap::Default(xgi::Input* in, xgi::Output* out)
32 std::string url =
"/" + getApplicationDescriptor()->getURN();
33 std::cout << __COUT_HDR_FL__ << url << std::endl;
35 *out << cgicc::HTMLDoctype(cgicc::HTMLDoctype::eStrict) << std::endl;
36 *out << cgicc::html().set(
"lang",
"en").set(
"dir",
"ltr") << std::endl;
37 *out << cgicc::title(
"Simple button page") << std::endl;
38 *out <<
"<body>" << std::endl;
39 *out <<
" <form name=\"input\" method=\"get\" action=\"" << url <<
"/StateMachineXgiHandler"
40 <<
"\" enctype=\"multipart/form-data\">" << std::endl;
41 *out <<
" <p align=\"left\"><input type=\"submit\" name=\"StateInput\" "
42 "value=\"PushStart\"/></p>"
44 *out <<
" </form>" << std::endl;
45 *out <<
" <form name=\"input\" method=\"get\" action=\"" << url <<
"/Start"
46 <<
"\" enctype=\"multipart/form-data\">" << std::endl;
47 *out <<
" <p align=\"left\"><input type=\"submit\" name=\"StateInput\" "
48 "value=\"Start\"/></p>"
50 *out <<
" </form>" << std::endl;
51 *out <<
"</body>" << std::endl;
55 void SimpleSoap::StateMachineXgiHandler(xgi::Input* in, xgi::Output* out)
58 std::string Command = cgi.getElement(
"StateInput")->getValue();
60 if(Command ==
"PushStart")
62 std::cout << __COUT_HDR_FL__ <<
"Got start" << std::endl;
63 xoap::MessageReference msg = SOAPUtilities::makeSOAPMessageReference(
"Start");
64 xoap::MessageReference reply = Start(msg);
66 if(receive(reply) ==
"StartDone")
67 std::cout << __COUT_HDR_FL__ <<
"Everything started correctly!" << std::endl << std::endl;
69 std::cout << __COUT_HDR_FL__ <<
"All underlying Supervisors could not be started by browser button!" << std::endl << std::endl;
71 else if(Command ==
"Start")
75 std::set<xdaq::ApplicationDescriptor*> set_SimpleSoap =
76 getApplicationContext()->getDefaultZone()->getApplicationGroup(
"daq")->getApplicationDescriptors(
"SimpleSoap::SimpleSoap");
78 for(std::set<xdaq::ApplicationDescriptor*>::iterator i_set_SimpleSoap = set_SimpleSoap.begin(); i_set_SimpleSoap != set_SimpleSoap.end();
83 std::string sReply = send(*i_set_SimpleSoap, Command.c_str());
85 if(sReply ==
"StartDone")
86 std::cout << __COUT_HDR_FL__ <<
"Everything started correctly!" << std::endl << std::endl;
88 std::cout << __COUT_HDR_FL__
89 <<
"All underlying Supervisors could not be started by "
94 catch(xdaq::exception::Exception& e)
96 std::cout << __COUT_HDR_FL__
98 <<
" Couldn't start sending a msg" << std::endl;
104 std::cout << __COUT_HDR_FL__ <<
"Don't understand the command: " << Command << std::endl;
107 this->Default(in, out);
111 xoap::MessageReference SimpleSoap::Start(xoap::MessageReference msg)
113 std::cout << __COUT_HDR_FL__ <<
"Starting" << std::endl;
114 return SOAPUtilities::makeSOAPMessageReference(
"StartDone");
118 void SimpleSoap::stateInitial(toolbox::fsm::FiniteStateMachine& fsm)
120 std::cout << __COUT_HDR_FL__ <<
"--- SimpleWeb is in its Initial state ---" << std::endl;
121 state_ = fsm_.getStateName(fsm_.getCurrentState());
129 void SimpleSoap::stateHalted(toolbox::fsm::FiniteStateMachine& fsm)
131 std::cout << __COUT_HDR_FL__ <<
"--- SimpleWeb is in its Halted state ---" << std::endl;
132 state_ = fsm_.getStateName(fsm_.getCurrentState());