mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 06:50:02 +02:00
first implementation of REST and JSON interfaces for eigerReceiver
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@799 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
4d797fb3b1
commit
c44b8d34c7
@ -3,6 +3,9 @@ CFLAGS += -DSLS_RECEIVER_FUNCTION_LIST -O3
|
||||
CPPFLAGS = ${CFLAGS} # for MAC
|
||||
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++
|
||||
|
||||
POCODIR = /afs/psi.ch/user/s/sala/public/poco-slp_6.4-64bit
|
||||
JSONBOXDIR = /afs/psi.ch/user/s/sala/public/JsonBox-slp_6.4-64bit
|
||||
EIGERFLAGS = -L $(JSONBOXDIR) -L $(POCODIR)/lib -Wl,-rpath=$(POCODIR)/lib -I $(POCODIR)/include -I $(JSONBOXDIR)/include
|
||||
|
||||
#LDLIBS += -lm -lstdc++ -lpthread
|
||||
LIBS?= -L$(LIBDIR) -lSlsDetector
|
||||
@ -40,7 +43,10 @@ $(DESTDIR)/slsReceiver: lib
|
||||
mkdir -p $(DESTDIR)
|
||||
$(CXX) -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAG)
|
||||
|
||||
|
||||
eigerReceiver:
|
||||
$(CXX) $(FLAGS) $(CFLAGS) $(EIGERFLAGS) -c -o eigerReceiverTest.o eigerReceiverTest.cpp -lPocoNet -lPocoFoundation -lJsonBox
|
||||
$(CXX) $(FLAGS) $(CFLAGS) $(EIGERFLAGS) -c -o eigerReceiver.o eigerReceiver.cpp -lPocoNet -lPocoFoundation -lJsonBox
|
||||
$(CXX) $(EIGERFLAGS) eigerReceiverTest.o eigerReceiver.o -o eigerReceiverTest -lPocoNet -lPocoFoundation -lJsonBox
|
||||
|
||||
lib:
|
||||
cd ../ && $(MAKE) DESTDIR=$(LIBDIR)
|
||||
|
79
slsDetectorSoftware/slsReceiver/RestHelper.h
Normal file
79
slsDetectorSoftware/slsReceiver/RestHelper.h
Normal file
@ -0,0 +1,79 @@
|
||||
#include <Poco/Net/HTTPClientSession.h>
|
||||
#include <Poco/Net/HTTPRequest.h>
|
||||
#include <Poco/Net/HTTPResponse.h>
|
||||
#include <Poco/StreamCopier.h>
|
||||
#include <Poco/Path.h>
|
||||
#include <Poco/URI.h>
|
||||
#include <Poco/Exception.h>
|
||||
|
||||
#include "JsonBox/Value.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace Poco::Net;
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
class RestHelper {
|
||||
public:
|
||||
|
||||
void init(std::string hostname, int port){
|
||||
/*
|
||||
|
||||
*/
|
||||
full_hostname = "http://"+hostname;
|
||||
std::cout << full_hostname << std::endl;
|
||||
session = new HTTPClientSession(hostname,port );
|
||||
};
|
||||
|
||||
int get_json(std::string request, std::string* answer){
|
||||
//TODO: implement a timeout and max_retries
|
||||
|
||||
uri = new URI(full_hostname+"/"+request);
|
||||
std::string path(uri->getPathAndQuery());
|
||||
if (path.empty()) path = "/";
|
||||
|
||||
// send request
|
||||
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
|
||||
session->sendRequest(req);
|
||||
|
||||
// get response
|
||||
HTTPResponse res;
|
||||
//std::cout << res.getStatus() << " " << res.getReason() << std::endl;
|
||||
std::istream &is = session->receiveResponse(res);
|
||||
StreamCopier::copyToString(is, *answer);
|
||||
|
||||
return res.getStatus();
|
||||
};
|
||||
|
||||
int get_json(std::string request, JsonBox::Value* json_value){
|
||||
//TODO: implement a timeout and max_retries
|
||||
|
||||
uri = new URI(full_hostname+"/"+request);
|
||||
std::string path(uri->getPathAndQuery());
|
||||
if (path.empty()) path = "/";
|
||||
|
||||
// send request
|
||||
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
|
||||
session->sendRequest(req);
|
||||
|
||||
// get response
|
||||
HTTPResponse res;
|
||||
//std::cout << res.getStatus() << " " << res.getReason() << std::endl;
|
||||
std::string answer;
|
||||
std::istream &is = session->receiveResponse(res);
|
||||
StreamCopier::copyToString(is, answer);
|
||||
|
||||
std::cout << answer << std::endl;
|
||||
//returning a Json struct
|
||||
json_value->loadFromString(answer);
|
||||
|
||||
return res.getStatus();
|
||||
};
|
||||
|
||||
private:
|
||||
URI * uri;
|
||||
HTTPClientSession *session;
|
||||
std::string full_hostname;
|
||||
};
|
@ -68,6 +68,17 @@ public:
|
||||
status = slsDetectorDefs::IDLE;
|
||||
}
|
||||
|
||||
//REST call - hardcoded
|
||||
RestHelper rest ;
|
||||
rest.init("localhost",8080);
|
||||
std::string answer;
|
||||
int code = rest.get_json("status", &answer);
|
||||
std::cout << answer << std::endl;
|
||||
|
||||
JsonBox::Value json_value;
|
||||
code = rest.get_json("status", &json_value);
|
||||
std::cout << "JSON " << json_value["status"] << std::endl;
|
||||
|
||||
}
|
||||
|
||||
char *getDetectorHostname() const {
|
||||
|
@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "RestHelper.h"
|
||||
|
||||
class EigerReceiver {
|
||||
/* abstract class that defines the public interface of an eiger data receiver.
|
||||
|
Loading…
x
Reference in New Issue
Block a user