From 9e78bae6148c9b2f9c107de614289596faf1291f Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Mon, 23 Mar 2015 11:18:05 +0100 Subject: [PATCH] solved bad_alloc --- .../src/UDPRESTImplementation.cpp | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index be929dd0d..e1b3a1114 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -87,7 +87,9 @@ int UDPRESTImplementation::get_rest_state(RestHelper * rest, string *rest_state) }; void UDPRESTImplementation::initialize_REST(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " REST status is initialized: " << isInitialized; if (rest_hostname.empty()) { FILE_LOG(logDEBUG) << __AT__ <<"can't initialize with empty string or NULL for detectorHostname"; @@ -104,7 +106,9 @@ void UDPRESTImplementation::initialize_REST(){ try{ rest->init(rest_hostname, rest_port); code = get_rest_state(rest, &answer); + std::cout << "AAAAAAAa " << answer << std::endl; + if (code != 0){ throw answer; } @@ -133,11 +137,19 @@ void UDPRESTImplementation::initialize_REST(){ ss >> test; - test = "{\"path\":\"" + string( getFilePath() ) + "\"}"; - code = rest->post_json("state/initialize", &answer, test); - FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code; code = rest->get_json("state", &answer); - FILE_LOG(logDEBUG) << __AT__ << "state got " << code << " " << answer << "\n"; + FILE_LOG(logDEBUG) << __AT__ << " state got " << code << " " << answer << "\n"; + if (answer != "INITIALIZED"){ + test = "{\"path\":\"" + string( getFilePath() ) + "\"}"; + code = rest->post_json("state/initialize", &answer, test); + } + else{ + test = "{\"path\":\"" + string( getFilePath() ) + "\"}"; + code = rest->post_json("state/configure", &answer, test); + } + FILE_LOG(logDEBUG) << __AT__ << " state/configure got " << code; + code = rest->get_json("state", &answer); + FILE_LOG(logDEBUG) << __AT__ << " state got " << code << " " << answer << "\n"; /* @@ -1169,10 +1181,8 @@ int UDPRESTImplementation::startReceiver(char message[]){ initialize_REST(); FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " initialized"; -// #ifdef VERBOSE cout << "Starting Receiver" << endl; -//#endif - + std::string answer; int code; //char *intStr = itoa(a); @@ -1184,17 +1194,21 @@ int UDPRESTImplementation::startReceiver(char message[]){ stringstream ss2; ss2 << getNumberOfFrames(); string str_n = ss2.str(); + + cout << "Starting Receiver" << endl; + std::string request_body = "{\"settings\": {\"bit_depth\": " + str_dr + ", \"nimages\": " + str_n + "}}"; //std::string request_body = "{\"settings\": {\"nimages\":1, \"scanid\":999, \"bit_depth\":16}}"; FILE_LOG(logDEBUG) << __FILE__ << "::" << " sending this configuration body: " << request_body; code = rest->post_json("state/configure", &answer, request_body); - code = rest->get_json("state", &answer); + //code = rest->get_json("state", &answer); + //FILE_LOG(logDEBUG) << __FILE__ << "::" << " got: " << answer; - code = rest->post_json("state/open", &answer); - code = rest->get_json("state", &answer); + //code = rest->post_json("state/open", &answer); + //code = rest->get_json("state", &answer); - status = slsReceiverDefs::RUNNING; + status = RUNNING; //reset listening thread variables /*