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