mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 21:07:13 +02:00
able to send data to eigerbe
tweaks on logging added configuration_map, to flexibly pass options to the different receivers some more fixes to method overloads still very preliminary
This commit is contained in:
@ -19,17 +19,13 @@
|
||||
|
||||
#include "JsonBox/Value.h"
|
||||
|
||||
//#include "logger.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <exception>
|
||||
|
||||
#define EIGER_DEBUG
|
||||
#ifdef EIGER_DEBUG
|
||||
#define DEBUG(x) do { std::cerr << "[DEBUG] " << x << std::endl; } while (0)
|
||||
#else
|
||||
#define DEBUG(x)
|
||||
#endif
|
||||
|
||||
|
||||
using namespace Poco::Net;
|
||||
@ -39,7 +35,7 @@ using namespace std;
|
||||
class RestHelper {
|
||||
public:
|
||||
|
||||
RestHelper(int timeout=10, int n_tries=3){
|
||||
RestHelper(int timeout=10, int n_tries=10){
|
||||
/**
|
||||
*
|
||||
*
|
||||
@ -78,18 +74,22 @@ class RestHelper {
|
||||
*/
|
||||
|
||||
//Check for http:// string
|
||||
FILE_LOG(logDEBUG) << __func__ << " starting";
|
||||
string proto_str = "http://";
|
||||
|
||||
if( size_t found = hostname.find(proto_str) != string::npos ){
|
||||
cout << hostname << endl;
|
||||
|
||||
char c1[hostname.size()-found-1];
|
||||
cout << c1 << endl;
|
||||
size_t length1 = hostname.copy(c1, hostname.size()-found-1, proto_str.size());
|
||||
c1[length1]='\0';
|
||||
hostname = c1;
|
||||
}
|
||||
|
||||
full_hostname = "http://"+hostname;
|
||||
session = new HTTPClientSession(hostname,port );
|
||||
session = new HTTPClientSession(hostname, port );
|
||||
session->setKeepAliveTimeout( Timespan( http_timeout,0) );
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -168,7 +168,7 @@ class RestHelper {
|
||||
string answer;
|
||||
int code = send_request(session, req, &answer);
|
||||
if(code == 0 ) {
|
||||
DEBUG("ANSWER " << answer );
|
||||
FILE_LOG(logDEBUG) << "ANSWER " << answer;
|
||||
json_value->loadFromString(answer);
|
||||
}
|
||||
delete uri;
|
||||
@ -176,7 +176,7 @@ class RestHelper {
|
||||
};
|
||||
|
||||
|
||||
int post_json(string request, string *answer, string request_body=""){
|
||||
int post_json(string request, string *answer, string request_body="{}"){
|
||||
/**
|
||||
*
|
||||
*
|
||||
@ -192,15 +192,16 @@ class RestHelper {
|
||||
if (path.empty()) path = "/";
|
||||
HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 );
|
||||
req.setContentType("application/json\r\n");
|
||||
req.setContentLength( request.length() );
|
||||
|
||||
cout << "REQUEST BODY " << request_body << endl;
|
||||
req.setContentLength( request_body.length() );
|
||||
int code = send_request(session, req, answer, request_body);
|
||||
|
||||
delete uri;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
int post_json(string request, JsonBox::Value* json_value, string request_body=""){
|
||||
int post_json(string request, JsonBox::Value* json_value, string request_body="{}"){
|
||||
/**
|
||||
*
|
||||
*
|
||||
@ -283,7 +284,7 @@ class RestHelper {
|
||||
return code;
|
||||
}
|
||||
catch (exception& e){
|
||||
cout << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping 5 seconds (" << n << "/"<<n_connection_tries << ")" << endl;
|
||||
FILE_LOG(logERROR) << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping 5 seconds (" << n << "/"<<n_connection_tries << ")";
|
||||
sleep(5);
|
||||
}
|
||||
n+=1;
|
||||
|
@ -32,7 +32,7 @@
|
||||
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
|
||||
*/
|
||||
|
||||
class UDPBaseImplementation : private virtual slsReceiverDefs, public UDPInterface {
|
||||
class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInterface {
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -45,7 +45,8 @@ class UDPBaseImplementation : private virtual slsReceiverDefs, public UDPInterfa
|
||||
*/
|
||||
virtual ~UDPBaseImplementation();
|
||||
|
||||
|
||||
void configure(map<string, string> config_map);
|
||||
|
||||
|
||||
/**
|
||||
* delete and free member parameters
|
||||
|
@ -13,6 +13,7 @@
|
||||
* @short base class with all the functions for a receiver, set/get parameters, start/stop etc.
|
||||
*/
|
||||
|
||||
#include <exception>
|
||||
|
||||
#include "sls_receiver_defs.h"
|
||||
#include "receiver_defs.h"
|
||||
@ -20,7 +21,6 @@
|
||||
|
||||
#include "utilities.h"
|
||||
#include "logger.h"
|
||||
|
||||
/*
|
||||
void print_not_implemented(string method_name){
|
||||
std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl;
|
||||
@ -78,9 +78,10 @@ class UDPInterface {
|
||||
* Factory create method
|
||||
*/
|
||||
static UDPInterface *create(string receiver_type = "standard");
|
||||
|
||||
|
||||
public:
|
||||
virtual void configure(map<string, string> config_map) = 0;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
|
||||
*/
|
||||
|
||||
class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImplementation {
|
||||
class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseImplementation {
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -47,7 +47,10 @@ class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImp
|
||||
*/
|
||||
virtual ~UDPRESTImplementation();
|
||||
|
||||
|
||||
|
||||
void initialize_REST();
|
||||
|
||||
void configure(map<string, string> config_map);
|
||||
|
||||
/**
|
||||
* delete and free member parameters
|
||||
@ -57,14 +60,28 @@ class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImp
|
||||
/**
|
||||
* initialize member parameters
|
||||
*/
|
||||
void initializeMembers();
|
||||
//void initializeMembers();
|
||||
|
||||
/**
|
||||
* Set detector hostname
|
||||
* @param c hostname
|
||||
*/
|
||||
//void initialize(const char *detectorHostName);
|
||||
|
||||
/* Returns detector hostname
|
||||
/returns hostname
|
||||
* caller needs to deallocate the returned char array.
|
||||
* if uninitialized, it must return NULL
|
||||
*/
|
||||
//char *getDetectorHostname() const;
|
||||
|
||||
|
||||
/**
|
||||
* Set receiver type
|
||||
* @param det detector type
|
||||
* Returns success or FAIL
|
||||
*/
|
||||
int setDetectorType(detectorType det);
|
||||
//int setDetectorType(detectorType det);
|
||||
|
||||
|
||||
//Frame indices and numbers caught
|
||||
@ -192,18 +209,6 @@ class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImp
|
||||
*/
|
||||
runStatus getStatus() const;
|
||||
|
||||
/**
|
||||
* Set detector hostname
|
||||
* @param c hostname
|
||||
*/
|
||||
void initialize(const char *detectorHostName);
|
||||
|
||||
/* Returns detector hostname
|
||||
/returns hostname
|
||||
* caller needs to deallocate the returned char array.
|
||||
* if uninitialized, it must return NULL
|
||||
*/
|
||||
//char *getDetectorHostname() const;
|
||||
|
||||
/**
|
||||
* Set Ethernet Interface or IP to listen to
|
||||
@ -811,6 +816,9 @@ public:
|
||||
//REST specific
|
||||
bool isInitialized;
|
||||
RestHelper * rest ;
|
||||
int rest_port; // receiver backend port
|
||||
string rest_hostname; // receiver hostname
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -5,6 +5,19 @@
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
#define STRINGIFY(x) #x
|
||||
#define TOSTRING(x) STRINGIFY(x)
|
||||
#define MYCONCAT(x,y)
|
||||
#define __AT__ string(__FILE__) + string("::") + string(__func__) + string("(): ")
|
||||
|
||||
//":" TOSTRING(__LINE__)
|
||||
|
||||
/*
|
||||
void error(const char *location, const char *msg){
|
||||
printf("Error at %s: %s\n", location, msg);
|
||||
}
|
||||
*/
|
||||
|
||||
inline std::string NowTime();
|
||||
|
||||
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4};
|
||||
@ -110,7 +123,7 @@ template <typename T> std::ostringstream& Log<T>::Get(TLogLevel level)
|
||||
template <typename T> Log<T>::~Log()
|
||||
{
|
||||
os << std::endl;
|
||||
T::Output(os.str());
|
||||
T::Output( os.str());
|
||||
}
|
||||
|
||||
template <typename T> TLogLevel& Log<T>::ReportingLevel()
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
using namespace std;
|
||||
#include "sls_receiver_defs.h"
|
||||
|
||||
@ -9,5 +11,5 @@ using namespace std;
|
||||
//#define EIGER_DEBUG
|
||||
|
||||
|
||||
int read_config_file(string fname, int *tcpip_port_no);
|
||||
int read_config_file(string fname, int *tcpip_port_no, map<string, string> * configuration_map);
|
||||
|
||||
|
Reference in New Issue
Block a user