Ejemplo n.º 1
0
int main (){

  
  boost::uuids::uuid m_UUID=boost::uuids::random_generator()();
  long msg_id=0;
    
   
  zmq::context_t *context=new zmq::context_t(3);
   

  std::vector<Store*> RemoteServices;
  

  std::string address("239.192.1.1");
  //std::stringstream tmp ("5000");

  int port=5000;
  //  tmp>>port;

  ServiceDiscovery *SD=new ServiceDiscovery(address,port,context,320);

  bool running=true;

  zmq::socket_t Ireceive (*context, ZMQ_DEALER);
  Ireceive.connect("inproc://ServiceDiscovery");

  sleep(5);

  zmq::message_t send(256);
  snprintf ((char *) send.data(), 256 , "%s" ,"All NULL") ;

  Ireceive.send(send);

      
  zmq::message_t receive;
  Ireceive.recv(&receive);
  std::istringstream iss(static_cast<char*>(receive.data()));
      
  int size;
  iss>>size;

  RemoteServices.clear();


  for(int i=0;i<size;i++){

    Store *service = new Store;

    zmq::message_t servicem;
    Ireceive.recv(&servicem);

    std::istringstream ss(static_cast<char*>(servicem.data()));
    service->JsonPaser(ss.str());

    RemoteServices.push_back(service);

  }


  zmq::message_t tmp;
  Ireceive.recv(&tmp);
 
  /*
      for(int i=0;i<RemoteServices.size();i++){

      std::string ip;
      std::string service;
      std::string status;
      
      //*(it->second)>> output;
      ip=*((*(RemoteServices.at(i)))["ip"]);
      service=*((*(RemoteServices.at(i)))["msg_value"]);
      status=*((*(RemoteServices.at(i)))["status"]);

      std::cout<<"["<<i<<"]  "<<ip<<" , "<<service<<" , "<<status<<std::endl;
    
}
  */
 




  


  /// webform
  
  Cgicc formData;

  cout << "Content-type:text/html\r\n\r\n";
  cout<<"<html>";  
  cout<<" <head> <meta http-equiv=\"refresh\" content=\"60; url=./control.cgi\"> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" /> <title>Remote ToolChain Control</title></head>"; 


  cout<<"  <link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/icon?family=Material+Icons\">";                                                    \

  cout<<"  <script defer src=\"https://code.getmdl.io/1.1.2/material.min.js\"></script>";                                                                  \

  cout<<"<link rel=\"stylesheet\" href=\"https://code.getmdl.io/1.1.2/material.indigo-deep_purple.min.css\" />";                                           \

  cout<<"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">";
  cout<<" <link rel=\"stylesheet\" href=\"styles.css\">";                                                                                                  \

  cout<<"<body>";                                                                                                                                          \

                                                                                                                                                           \

  cout<<"<!-- Always shows a header, even in smaller screens. --> ";                                                                                       \

  cout<<"<div class=\"mdl-layout mdl-js-layout mdl-layout--fixed-header\">";                                                                               \

  cout<<" <header class=\"mdl-layout__header\">";                                                                                                          \

  cout<<"<div class=\"mdl-layout__header-row\">";

  cout<<" <!-- Title -->";                                                                                                                                 \

  cout<<"<span class=\"mdl-layout-title\"> ";                                                                                                              \

  cout<<" Remote Control</span>";                                                                                                                          \

  cout<<" <!-- Add spacer, to align navigation to the right -->";                                                                                          \

  cout<<" <div class=\"mdl-layout-spacer\"></div>";                                                                                                        \

  cout<<" <!-- Navigation. We hide it in small screens. -->";                                                                                              \

  cout<<" <nav class=\"mdl-navigation mdl-layout--large-screen-only\"> ";

  cout<<" <a class=\"mdl-navigation__link\" href=\"../index.html\">Home</a>";                                                                              \

  cout<<" <a class=\"mdl-navigation__link\" href=\"/cgi-bin/control.cgi\">Control</a>";                                                                    \

  cout<<" <a class=\"mdl-navigation__link\" href=\"/cgi-bin/logs.cgi\">Logs</a>";                                                                          \

  cout<<"     <a class=\"mdl-navigation__link\" href=\"/cgi-bin/monitoring.cgi\">Monitoring</a> ";                                                         \

  cout<<"<a class=\"mdl-navigation__link\" href=\"/cgi-bin/SQL.cgi\">SQL</a> ";                                                                            \

  cout<<"   <a class=\"mdl-navigation__link\" href=\"/cgi-bin/data.cgi\">Data</a>     ";                                                                          \

  cout<<"</nav> ";
  cout<<"</div> ";

  cout<<"</header>";                                                                                                                                       \

  cout<<"<div class=\"mdl-layout__drawer\">  ";                                                                                                            \

  cout<<"<img src=\"../ANNIE-logo.png\"  width=\"90%\" height=\"10%\">";                                                                                   \

  cout<<"    <span class=\"mdl-layout-title\"></span>";                                                                                                    \

  cout<<"<div class=\"android-drawer-separator\"></div>";                                                                                                  \

  cout<<"<nav class=\"mdl-navigation\">  ";                                                                                                                \

  cout<<"<a class=\"mdl-navigation__link\" href=\"../index.html\">Home</a> ";
  cout<<" <a class=\"mdl-navigation__link\" href=\"/cgi-bin/control.cgi\">Control</a>  ";                                                                  \

  cout<<" <a class=\"mdl-navigation__link\" href=\"/cgi-bin/logs.cgi\">Logs</a>  ";                                                                        \

  cout<<" <a class=\"mdl-navigation__link\" href=\"/cgi-bin/monitoring.cgi\">Monitoring</a>";                                                              \

  cout<<"  <a class=\"mdl-navigation__link\" href=\"/cgi-bin/SQL.cgi\">SQL</a>     ";                                                                      \

  cout<<"  <a class=\"mdl-navigation__link\" href=\"/cgi-bin/data.cgi\">Data</a>";                                                                                \

  cout<<" </nav>";                                                                                                                                         \

  cout<<" </div>";
      
  cout<<"<main class=\"mdl-layout__content\"> ";                                                                                                           \

  cout<<" <div class=\"page-content\"> ";                                                                                                                  \

  cout<<"<!-- Your content goes here -->";                                                                                                                 \

                                                                                                                                                           \




 
  cout<<"<h1 align=\"center\">Remote Control ToolChain</h1>" ;

  /////////////////////////////////////////////////////////////////////
  cout<<"  <p> <table  border='1' align='center'>"; 

  cout<<"<tr> <th scope='col'><div align='center'>Service ID </div></th> ";
  cout<<"<th scope='col'><div align='center'>Service IP</div></th>";
  cout<<"<th scope='col'><div align='center'>Service Name</div></th>"; 
  cout<<"<th scope='col'><div align'center'>Service Status</div></th> </tr>";

  //cout<<"remote services size "<<RemoteServices.size();
  
  for(int i=0;i<RemoteServices.size();i++){

    std::string ip;
    std::string service;
    std::string status;
    std::string colour;

    ip=*((*(RemoteServices.at(i)))["ip"]);
    service=*((*(RemoteServices.at(i)))["msg_value"]);
    status=*((*(RemoteServices.at(i)))["status"]);
    colour="#00FFFF";

    if (status=="Online")colour="#FF00FF";
    else if (status=="Waiting to Initialise ToolChain")colour="#FFFF00";
    else{
      std::stringstream tmpstatus(status);
      tmpstatus>>status;
      if(status=="ToolChain"){
        tmpstatus>>status;
        if(status=="running")colour="#00FF00";
      }
      status=tmpstatus.str();
    }
    
    cout<<"<tr> <td bgcolor=\""<<colour<<"\">["<<i<<"]</td>"; 
    cout<<"<td bgcolor=\""<<colour<<"\">"<<ip<<"</td>";
    cout<<"<td bgcolor=\""<<colour<<"\">"<<service<<"</td> ";
    cout<<"<td bgcolor=\""<<colour<<"\">"<<status<<"</td> </tr> ";
    
    
    //std::cout<<"["<<i<<"]  "<<ip<<" , "<<service<<" , "<<status<<std::endl;
    
  }
Ejemplo n.º 2
0
bool Trigger::Initialise(std::string configfile, DataModel &data){

  if(configfile!="")  m_variables.Initialise(configfile);
  //m_variables.Print();
  
  m_data= &data;

  m_variables.Get("verbose",m_verbose);  
  m_variables.Get("VME_service_name",VME_service_name);
  m_variables.Get("numVME",numVME);
  m_variables.Get("VME_port",VME_port);  
  
  m_data->triggered=false;
  
    
  std::vector<Store*> RemoteServices;
  
  zmq::socket_t Ireceive (*(m_data->context), ZMQ_DEALER);
  Ireceive.connect("inproc://ServiceDiscovery");
  
  for(int i=0;i<11;i++){
  
  zmq::message_t send(256);
  snprintf ((char *) send.data(), 256 , "%s" ,"All NULL") ;
  
  Ireceive.send(send);
  
  zmq::message_t receive;
  Ireceive.recv(&receive);
  std::istringstream iss(static_cast<char*>(receive.data()));
  
  int size;
  iss>>size;
  
  
  for(int i=0;i<RemoteServices.size();i++){

    delete RemoteServices.at(i);
    RemoteServices.at(i)=0;
  }
  
  RemoteServices.clear();
  
  for(int i=0;i<size;i++){
    
    Store *service = new Store;
    
    zmq::message_t servicem;
    Ireceive.recv(&servicem);
    
    std::istringstream ss(static_cast<char*>(servicem.data()));
    service->JsonPaser(ss.str());
    
    std::string servicetype;
    service->Get("msg_value",servicetype);
    //printf("%s \n",servicetype.c_str());
    if(servicetype==VME_service_name)  RemoteServices.push_back(service);
    else delete service  ;
    
  }

  if (RemoteServices.size()==numVME)break;
  else  usleep(1500000);
 
  }

  if (RemoteServices.size()!=numVME){
    Log("ERROR!! Cant find all of the VME boards",0,m_verbose);
    return false;
  }

  
  for(int i=0;i<RemoteServices.size();i++){
    
    std::string ip;
    //int logport=24010;
    
    //*(it->second)>> output;
    ip=*((*(RemoteServices.at(i)))["ip"]);
    
    
    zmq::socket_t *RemoteSend = new zmq::socket_t(*(m_data->context), ZMQ_DEALER);
    int a=12000;
    RemoteSend->setsockopt(ZMQ_SNDTIMEO, a);
    RemoteSend->setsockopt(ZMQ_RCVTIMEO, a);   
 
    std::stringstream tmp;
    tmp<<"tcp://"<<ip<<":"<<VME_port;
    
    // printf("%s \n",tmp.str().c_str());
    RemoteSend->connect(tmp.str().c_str());
    
    VMESockets.push_back(RemoteSend);

  }


  for(int i=0;i<RemoteServices.size();i++){

    delete RemoteServices.at(i);
    RemoteServices.at(i)=0;
  }

  RemoteServices.clear();
  

  /* backup
  zmq::socket_t *RemoteSend = new zmq::socket_t(*(m_data->context), ZMQ_DEALER);                                                                             
  int a=12000;                                                                
  RemoteSend->setsockopt(ZMQ_SNDTIMEO, a);                                    
  RemoteSend->setsockopt(ZMQ_RCVTIMEO, a);                                    
                                                                                
  std::stringstream tmp;                                                      
  tmp<<"tcp://"<<"192.168.1.21"<<":"<<VME_port;                                           
                                                                                
  // printf("%s \n",tmp.str().c_str());                                       
  RemoteSend->connect(tmp.str().c_str());                                     
                                                                                
  VMESockets.push_back(RemoteSend);
  */


  ///////// Sending trigger settings ////////////

  //  std::cout<<"VMESockets.size() "<<VMESockets.size()<<std::endl;
  for (int i=0;i<VMESockets.size();i++){
    //std::cout<<"debug 1 "<<i<<std::endl;
    std::string query="Initialise";
    zmq::message_t message(query.length()+1);
    snprintf ((char *) message.data(), query.length()+1 , "%s" ,query.c_str() ) ;
    // std::cout<<"debug 2"<<std::endl;
    if( VMESockets.at(i)->send(message)){
      //std::cout<<"debug 3"<<std::endl;
      std::string setup;
      //m_variables.Print();
      m_variables>>setup;
      //std::cout<<"setup "<<setup<<std::endl;
      zmq::message_t message2(setup.length()+1);
      snprintf ((char *) message2.data(), setup.length()+1 , "%s" ,setup.c_str() ) ;
      //std::cout<<"debug 4 "<<setup<<std::endl;
      VMESockets.at(i)->send(message2);
      // std::cout<<"debug 5"<<std::endl;
      
      zmq::message_t re;
      if(VMESockets.at(i)->recv(&re)){
	std::istringstream iss2(static_cast<char*>(re.data()));
	//	std::cout<<"debug 6 "<<iss2.str()<<std::endl;
      }
      else{
        Log("Error receiving trigger query from VME",0,m_verbose);
        return false;

      }
      //std::cout<<"debug 7"<<std::endl;
    }

    else{