CFEL - ASG Software Suite  2.5.0
CASS
lucassview/tcpclient.cpp
Go to the documentation of this file.
1 //Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file lucassview/tcpclient.cpp file contains the classes connect to cass
5  *
6  * @author Lutz Foucar
7  */
8 #include <stdexcept>
9 #include <sstream>
10 #include <string>
11 
12 #include "tcpclient.h"
13 #include "soapCASSsoapProxy.h"
14 #include "CASSsoap.nsmap"
15 #include "id_list.h"
16 
17 using namespace lucassview;
18 
19 TCPClient::TCPClient(const std::string &server)
20  :_server(server),
21  _transferredBytes(0)
22 {}
23 
25 {
26  using namespace std;
27  bool ret(false);
28  CASSsoapProxy client;
29  client.soap_endpoint = _server.c_str();
30  client.readini(0, &ret);
31  if(!ret)
32  throw runtime_error("TCPClient::reloadIni(): Could not communicate writeini command");
33 }
34 
35 void TCPClient::controlCalibration(const std::string &command) const
36 {
37  using namespace std;
38  bool ret(false);
39  CASSsoapProxy client;
40  client.soap_endpoint = _server.c_str();
41  client.controlDarkcal(command, &ret);
42  if(!ret)
43  throw runtime_error("TCPClient::controlCalibration(): Could not communicate command '"+ command +"'");
44 }
45 
46 std::list<std::string> TCPClient::operator() ()const
47 {
48  using namespace std;
49  bool ret(false);
50  CASSsoapProxy client;
51  client.soap_endpoint = _server.c_str();
52  int retcode (client.getPostprocessorIds(&ret));
53  if( (retcode != SOAP_OK) || !ret)
54  {
55  stringstream ss;
56  ss << "TCPClient(): Could not retrieve the List of Histograms on '"<<_server<<"'";
57  throw runtime_error(ss.str());
58  }
59  soap_multipart::iterator attachment (client.dime.begin());
60  if(client.dime.end() == attachment)
61  {
62  stringstream ss;
63  ss << "There is no attachmend in the received soap data";
64  throw runtime_error(ss.str());
65  }
66 // cout << "TCPClient: DIME attachment:" << endl
67 // << " TCPClient: Memory=" << (void*)(*attachment).ptr << endl
68 // << " TCPClient: Size=" << (*attachment).size << endl
69 // << " TCPClient: Type=" << ((*attachment).type?(*attachment).type:"null") << endl
70 // << " TCPClient: ID=" << ((*attachment).id?(*attachment).id:"null") << endl;
71  _transferredBytes += (*attachment).size;
72  cass::Serializer serializer( std::string((char *)(*attachment).ptr, (*attachment).size) );
73  cass::IdList list(serializer);
74  std::list<std::string> returnlist (list.getList());
75  return returnlist;
76 }
77 
78 cass::Result<float>::shared_pointer TCPClient::operator() (const std::string &histogramkey)const
79 {
80  using namespace std;
81  using namespace std::tr1;
82  using namespace cass;
83  bool ret(false);
84  CASSsoapProxy client;
85  client.soap_endpoint = _server.c_str();
86  client.getHistogram(histogramkey,0,&ret);
87  if(!ret)
88  {
89  stringstream ss;
90  ss << "TCPClient(): Did not get Histogram with key '"<<histogramkey<<"'";
91  throw runtime_error(ss.str());
92  }
93  soap_multipart::iterator attachment(client.dime.begin());
94  if(client.dime.end() == attachment)
95  {
96  stringstream ss;
97  ss << "TCPClient(key): There is no attachmend in the received soap data";
98  throw runtime_error(ss.str());
99  }
100 // cout << "TCPClient: DIME attachment:" << endl
101 // << " TCPClient: Memory=" << (void*)(*attachment).ptr << endl
102 // << " TCPClient: Size=" << (*attachment).size << endl
103 // << " TCPClient: Type=" << ((*attachment).type?(*attachment).type:"null") << endl
104 // << " TCPClient: ID=" << ((*attachment).id?(*attachment).id:"null") << endl;
105  _transferredBytes += (*attachment).size;
107  cass::Serializer serializer( std::string((char *)(*attachment).ptr, (*attachment).size) );
108  serializer >> *result;
109  return result;
110 }
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
Definition: result.hpp:323
STL namespace.
TCPClient(const std::string &server)
constructor
void reloadIni() const
reload .ini file
A string serializer.
Definition: serializer.hpp:287
void controlCalibration(const std::string &command) const
reload .ini file
std::list< std::string > operator()() const
retrieve the list of available histograms
const Processor::names_t & getList()
getter for the internal list
std::string _server
the server to connect to
contains the classes that can serialize the key list
size_t _transferredBytes
the amount of bytes transferred
file contains the classes connect to cass