otsdaq  v1_01_03
 All Classes Namespaces Functions
SimpleSoap.cc
1 /*--------------------------------------------------------------------
2  To compile: make
3  To run:
4 --------------------------------------------------------------------*/
5 
6 #include "Tests/SimpleSoap/include/SimpleSoap.h"
7 #include "Utilities/MacroUtilities/include/Macro.h"
8 #include "Utilities/SOAPUtilities/include/SOAPUtilities.h"
9 #include <xoap/Method.h>
10 #include <xdaq/NamespaceURI.h>
11 #include <iostream>
12 
13 using namespace ots;
14 
15 XDAQ_INSTANTIATOR_IMPL(SimpleSoap)
16 
17 //========================================================================================================================
18 SimpleSoap::SimpleSoap (xdaq::ApplicationStub * s ) throw (xdaq::exception::Exception):
19  xdaq::Application(s),
20  SOAPMessenger (this)
21 {
22  xgi::bind(this,&SimpleSoap::Default, "Default" );
23  xgi::bind(this,&SimpleSoap::StateMachineXgiHandler, "StateMachineXgiHandler");
24 
25  xoap::bind(this, &SimpleSoap::Start, "Start", XDAQ_NS_URI );
26  fsm_.addState('I', "Initial", this, &SimpleSoap::stateInitial);
27  fsm_.addState('H', "Halted", this, &SimpleSoap::stateHalted);
28  fsm_.addStateTransition('I', 'H', "Initialize");
29 
30 }
31 
32 //========================================================================================================================
33 void SimpleSoap::Default(xgi::Input * in,
34  xgi::Output * out ) throw (xgi::exception::Exception)
35 {
36  std::string url="/"+getApplicationDescriptor()->getURN();
37  std::cout << __COUT_HDR_FL__ << url << std::endl;
38  //url = "http://131.225.82.72:1983";
39  *out << cgicc::HTMLDoctype(cgicc::HTMLDoctype::eStrict) << std::endl;
40  *out << cgicc::html().set("lang", "en").set("dir","ltr") << std::endl;
41  *out << cgicc::title("Simple button page") << std::endl;
42  *out<<"<body>"<<std::endl;
43  *out<<" <form name=\"input\" method=\"get\" action=\""<<url<<"/StateMachineXgiHandler"<<"\" enctype=\"multipart/form-data\">" <<std::endl;
44  *out<<" <p align=\"left\"><input type=\"submit\" name=\"StateInput\" value=\"PushStart\"/></p>" <<std::endl;
45  *out<<" </form>" <<std::endl;
46  *out<<" <form name=\"input\" method=\"get\" action=\""<<url<<"/Start"<<"\" enctype=\"multipart/form-data\">" <<std::endl;
47  *out<<" <p align=\"left\"><input type=\"submit\" name=\"StateInput\" value=\"Start\"/></p>" <<std::endl;
48  *out<<" </form>" <<std::endl;
49  *out<<"</body>"<<std::endl;
50 }
51 
52 //========================================================================================================================
53 void SimpleSoap::StateMachineXgiHandler(xgi::Input * in, xgi::Output * out ) throw (xgi::exception::Exception)
54 {
55 
56  cgicc::Cgicc cgi(in);
57  std::string Command=cgi.getElement("StateInput")->getValue();
58 
59  if (Command=="PushStart")
60  {
61  std::cout << __COUT_HDR_FL__ << "Got start" << std::endl;
62  xoap::MessageReference msg = SOAPUtilities::makeSOAPMessageReference("Start");
63  xoap::MessageReference reply = Start(msg);
64 
65  if (receive(reply) == "StartDone")
66  std::cout << __COUT_HDR_FL__ <<"Everything started correctly!" <<std::endl << std::endl;
67  else
68  std::cout << __COUT_HDR_FL__ <<"All underlying Supervisors could not be started by browser button!"<<std::endl << std::endl;
69  }
70  else if (Command == "Start")
71  {
72  //std::set<xdaq::ApplicationDescriptor*> set_SimpleSoap = getApplicationContext()->getDefaultZone()->getApplicationGroup("rivera")->getApplicationDescriptors("SimpleSoap::SimpleSoap");
73  std::set<xdaq::ApplicationDescriptor*> set_SimpleSoap = getApplicationContext()->getDefaultZone()->getApplicationGroup("daq")->getApplicationDescriptors("SimpleSoap::SimpleSoap");
74 
75  for (std::set<xdaq::ApplicationDescriptor*>::iterator i_set_SimpleSoap=set_SimpleSoap.begin(); i_set_SimpleSoap!=set_SimpleSoap.end(); ++i_set_SimpleSoap)
76  {
77  try
78  {
79  std::string sReply=send(*i_set_SimpleSoap, Command.c_str());
80 
81  if (sReply == "StartDone")
82  std::cout << __COUT_HDR_FL__ <<"Everything started correctly!" <<std::endl << std::endl;
83  else
84  std::cout << __COUT_HDR_FL__ <<"All underlying Supervisors could not be started by browser button!"<<std::endl << std::endl;
85  }
86  catch (xdaq::exception::Exception& e)
87  {
88  std::cout << __COUT_HDR_FL__
89  //<< std::stringF((*i_set_SimpleSoap)->getInstance())
90  << " Couldn't start sending a msg" << std::endl;
91  }
92  }
93  }
94  else
95  {
96  std::cout << __COUT_HDR_FL__ << "Don't understand the command: " << Command << std::endl;
97  }
98 
99  this->Default(in, out);
100 }
101 
102 //========================================================================================================================
103 xoap::MessageReference SimpleSoap::Start (xoap::MessageReference msg)
104 {
105  std::cout << __COUT_HDR_FL__ << "Starting" << std::endl;
106  return SOAPUtilities::makeSOAPMessageReference("StartDone");
107 }
108 
109 //========================================================================================================================
110 void SimpleSoap::stateInitial (toolbox::fsm::FiniteStateMachine & fsm) throw (toolbox::fsm::exception::Exception)
111 {
112  std::cout << __COUT_HDR_FL__ << "--- SimpleWeb is in its Initial state ---" << std::endl;
113  state_ = fsm_.getStateName (fsm_.getCurrentState());
114 
115  // diagService_->reportError("PixelSupervisor::stateInitial: workloop active: "+stringF(calibWorkloop_->isActive())+", workloop type: "+calibWorkloop_->getType(),DIAGINFO);
116 
117 }
118 
119 //========================================================================================================================
120 void SimpleSoap::stateHalted (toolbox::fsm::FiniteStateMachine & fsm) throw (toolbox::fsm::exception::Exception)
121 {
122  std::cout << __COUT_HDR_FL__ << "--- SimpleWeb is in its Halted state ---" << std::endl;
123  state_ = fsm_.getStateName (fsm_.getCurrentState());
124 }