Commit 46ac67dc authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by Alejandro Homs Puron
Browse files

Define XxxxReq shortcuts for shared_ptr<Requests::Xxxx> types:

* Idem for MessagePtr = shared_ptr<Stream::Message>
parent 2f9ded8d
Pipeline #20448 failed with stages
in 1 minute and 8 seconds
......@@ -119,6 +119,11 @@ namespace eigerapi
void* m_buffer;
};
typedef std::shared_ptr<CurlLoop::FutureRequest> CurlReq;
typedef std::shared_ptr<Command> CommandReq;
typedef std::shared_ptr<Param> ParamReq;
typedef std::shared_ptr<Transfer> TransferReq;
enum COMMAND_NAME {INITIALIZE,ARM, DISARM,TRIGGER,CANCEL,ABORT,
FILEWRITER_CLEAR};
enum PARAM_NAME {TEMP,
......@@ -177,32 +182,31 @@ namespace eigerapi
Requests(const std::string& address);
~Requests();
std::shared_ptr<Command> get_command(COMMAND_NAME);
std::shared_ptr<Param> get_param(PARAM_NAME);
std::shared_ptr<Param> get_param(PARAM_NAME,bool&);
std::shared_ptr<Param> get_param(PARAM_NAME,double&);
std::shared_ptr<Param> get_param(PARAM_NAME,int&);
std::shared_ptr<Param> get_param(PARAM_NAME,unsigned int&);
std::shared_ptr<Param> get_param(PARAM_NAME,std::string&);
CommandReq get_command(COMMAND_NAME);
ParamReq get_param(PARAM_NAME);
ParamReq get_param(PARAM_NAME,bool&);
ParamReq get_param(PARAM_NAME,double&);
ParamReq get_param(PARAM_NAME,int&);
ParamReq get_param(PARAM_NAME,unsigned int&);
ParamReq get_param(PARAM_NAME,std::string&);
std::shared_ptr<Param> set_param(PARAM_NAME,bool);
std::shared_ptr<Param> set_param(PARAM_NAME,double);
std::shared_ptr<Param> set_param(PARAM_NAME,int);
std::shared_ptr<Param> set_param(PARAM_NAME,unsigned int);
std::shared_ptr<Param> set_param(PARAM_NAME,const std::string&);
std::shared_ptr<Param> set_param(PARAM_NAME,const char*);
ParamReq set_param(PARAM_NAME,bool);
ParamReq set_param(PARAM_NAME,double);
ParamReq set_param(PARAM_NAME,int);
ParamReq set_param(PARAM_NAME,unsigned int);
ParamReq set_param(PARAM_NAME,const std::string&);
ParamReq set_param(PARAM_NAME,const char*);
std::shared_ptr<Transfer> start_transfer(const std::string& src_filename,
const std::string& target_path,
bool delete_after_transfer = true);
std::shared_ptr<CurlLoop::FutureRequest> delete_file(const std::string& filename,
bool full_url = false);
TransferReq start_transfer(const std::string& src_filename,
const std::string& target_path,
bool delete_after_transfer = true);
CurlReq delete_file(const std::string& filename, bool full_url = false);
void cancel(std::shared_ptr<CurlLoop::FutureRequest> request);
void cancel(CurlReq request);
private:
std::shared_ptr<Param> _create_get_param(PARAM_NAME);
ParamReq _create_get_param(PARAM_NAME);
template <class T>
std::shared_ptr<Param> _set_param(PARAM_NAME,const T&);
ParamReq _set_param(PARAM_NAME,const T&);
typedef std::map<int,std::string> CACHE_TYPE;
......
......@@ -60,6 +60,11 @@ private:
using namespace eigerapi;
typedef Requests::CommandReq CommandReq;
typedef Requests::ParamReq ParamReq;
typedef Requests::TransferReq TransferReq;
typedef Requests::CurlReq CurlReq;
static const char* CSTR_EIGERCONFIG = "config";
static const char* CSTR_EIGERSTATUS = "status";
static const char* CSTR_EIGERSTATUS_BOARD = "status/board_000";
......@@ -218,7 +223,7 @@ Requests::Requests(const std::string& address) :
url << base_url.str() << CSTR_SUBSYSTEMDETECTOR << '/'
<< CSTR_EIGERAPI << '/' << CSTR_EIGERVERSION << '/';
std::shared_ptr<Param> version_request(new Param(url.str()));
ParamReq version_request(new Param(url.str()));
version_request->_fill_get_request();
m_loop.add_request(version_request);
......@@ -248,142 +253,126 @@ Requests::~Requests()
{
}
std::shared_ptr<Requests::Command>
Requests::get_command(Requests::COMMAND_NAME cmd_name)
CommandReq Requests::get_command(Requests::COMMAND_NAME cmd_name)
{
CACHE_TYPE::iterator cmd_url = m_cmd_cache_url.find(cmd_name);
if(cmd_url == m_cmd_cache_url.end())
THROW_EIGER_EXCEPTION(RESOURCE_NOT_FOUND,get_cmd_name(cmd_name));
std::shared_ptr<Requests::Command> cmd(new Command(cmd_url->second));
CommandReq cmd(new Command(cmd_url->second));
cmd->_fill_request();
m_loop.add_request(cmd);
return cmd;
}
std::shared_ptr<Requests::Param>
Requests::get_param(Requests::PARAM_NAME param_name)
ParamReq Requests::get_param(Requests::PARAM_NAME param_name)
{
std::shared_ptr<Requests::Param> param = _create_get_param(param_name);
ParamReq param = _create_get_param(param_name);
m_loop.add_request(param);
return param;
}
#define GENERATE_GET_PARAM() \
std::shared_ptr<Requests::Param> param = _create_get_param(param_name); \
ParamReq param = _create_get_param(param_name); \
param->_set_return_value(ret_value); \
\
m_loop.add_request(param); \
return param; \
std::shared_ptr<Requests::Param>
Requests::get_param(Requests::PARAM_NAME param_name,bool& ret_value)
ParamReq Requests::get_param(Requests::PARAM_NAME param_name,bool& ret_value)
{
GENERATE_GET_PARAM();
}
std::shared_ptr<Requests::Param>
Requests::get_param(Requests::PARAM_NAME param_name,
ParamReq Requests::get_param(Requests::PARAM_NAME param_name,
double& ret_value)
{
GENERATE_GET_PARAM();
}
std::shared_ptr<Requests::Param>
Requests::get_param(Requests::PARAM_NAME param_name,
ParamReq Requests::get_param(Requests::PARAM_NAME param_name,
int& ret_value)
{
GENERATE_GET_PARAM();
}
std::shared_ptr<Requests::Param>
Requests::get_param(Requests::PARAM_NAME param_name,
ParamReq Requests::get_param(Requests::PARAM_NAME param_name,
unsigned int& ret_value)
{
GENERATE_GET_PARAM();
}
std::shared_ptr<Requests::Param>
Requests::get_param(Requests::PARAM_NAME param_name,
ParamReq Requests::get_param(Requests::PARAM_NAME param_name,
std::string& ret_value)
{
GENERATE_GET_PARAM();
}
std::shared_ptr<Requests::Param>
Requests::_create_get_param(Requests::PARAM_NAME param_name)
ParamReq Requests::_create_get_param(Requests::PARAM_NAME param_name)
{
CACHE_TYPE::iterator param_url = m_param_cache_url.find(param_name);
if(param_url == m_param_cache_url.end())
THROW_EIGER_EXCEPTION(RESOURCE_NOT_FOUND,get_param_name(param_name));
std::shared_ptr<Requests::Param> param(new Param(param_url->second));
ParamReq param(new Param(param_url->second));
param->_fill_get_request();
return param;
}
template <class T>
std::shared_ptr<Requests::Param>
Requests::_set_param(Requests::PARAM_NAME param_name,const T& value)
ParamReq Requests::_set_param(Requests::PARAM_NAME param_name,const T& value)
{
CACHE_TYPE::iterator param_url = m_param_cache_url.find(param_name);
if(param_url == m_param_cache_url.end())
THROW_EIGER_EXCEPTION(RESOURCE_NOT_FOUND,get_param_name(param_name));
std::shared_ptr<Requests::Param> param(new Param(param_url->second));
ParamReq param(new Param(param_url->second));
param->_fill_set_request(value);
m_loop.add_request(param);
return param;
}
std::shared_ptr<Requests::Param>
Requests::set_param(Requests::PARAM_NAME name,bool value)
ParamReq Requests::set_param(Requests::PARAM_NAME name,bool value)
{
return _set_param(name,value);
}
std::shared_ptr<Requests::Param>
Requests::set_param(PARAM_NAME name,double value)
ParamReq Requests::set_param(PARAM_NAME name,double value)
{
return _set_param(name,value);
}
std::shared_ptr<Requests::Param>
Requests::set_param(PARAM_NAME name,int value)
ParamReq Requests::set_param(PARAM_NAME name,int value)
{
return _set_param(name,value);
}
std::shared_ptr<Requests::Param>
Requests::set_param(PARAM_NAME name,unsigned int value)
ParamReq Requests::set_param(PARAM_NAME name,unsigned int value)
{
return _set_param(name,value);
}
std::shared_ptr<Requests::Param>
Requests::set_param(PARAM_NAME name,const std::string& value)
ParamReq Requests::set_param(PARAM_NAME name,const std::string& value)
{
return _set_param(name,value);
}
std::shared_ptr<Requests::Param>
Requests::set_param(PARAM_NAME name,const char* value)
ParamReq Requests::set_param(PARAM_NAME name,const char* value)
{
return _set_param(name,value);
}
std::shared_ptr<Requests::Transfer>
Requests::start_transfer(const std::string& src_filename,
const std::string& dest_path,
bool delete_after_transfer)
TransferReq Requests::start_transfer(const std::string& src_filename,
const std::string& dest_path,
bool delete_after_transfer)
{
std::ostringstream url;
url << "http://" << m_address << '/' << CSTR_DATA << '/'
<< src_filename;
std::shared_ptr<Transfer> transfer(new Transfer(*this,
TransferReq transfer(new Transfer(*this,
url.str(),
dest_path,
delete_after_transfer));
......@@ -391,8 +380,7 @@ Requests::start_transfer(const std::string& src_filename,
return transfer;
}
std::shared_ptr<CurlLoop::FutureRequest>
Requests::delete_file(const std::string& filename,bool full_url)
CurlReq Requests::delete_file(const std::string& filename,bool full_url)
{
std::ostringstream url;
if(!full_url)
......@@ -401,15 +389,14 @@ Requests::delete_file(const std::string& filename,bool full_url)
else
url << filename;
std::shared_ptr<CurlLoop::FutureRequest>
delete_req(new CurlLoop::FutureRequest(url.str()));
CurlReq delete_req(new CurlLoop::FutureRequest(url.str()));
CURL* handle = delete_req->get_handle();
curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE");
m_loop.add_request(delete_req);
return delete_req;
}
void Requests::cancel(std::shared_ptr<CurlLoop::FutureRequest> req)
void Requests::cancel(CurlReq req)
{
m_loop.cancel_request(req);
}
......
......@@ -35,6 +35,9 @@ using namespace lima::Eiger;
using namespace std;
using namespace eigerapi;
typedef Requests::CommandReq CommandReq;
typedef Requests::ParamReq ParamReq;
typedef Requests::TransferReq TransferReq;
#define HANDLE_EIGERERROR(req, e) { \
THROW_HW_ERROR(Error) << (req)->get_url() << ":" << (e).what(); \
......@@ -42,8 +45,7 @@ using namespace eigerapi;
#define EIGER_SYNC_CMD_TIMEOUT(CommandType,timeout) \
{ \
std::shared_ptr<Requests::Command> cmd = \
m_requests->get_command(CommandType); \
CommandReq cmd = m_requests->get_command(CommandType); \
try \
{ \
cmd->wait(timeout); \
......@@ -60,7 +62,7 @@ using namespace eigerapi;
#define EIGER_SYNC_SET_PARAM(ParamType,value) \
{ \
std::shared_ptr<Requests::Param> req = \
ParamReq req = \
m_requests->set_param(ParamType,value); \
try \
{ \
......@@ -74,7 +76,7 @@ using namespace eigerapi;
#define EIGER_SYNC_GET_PARAM(ParamType,value) \
{ \
std::shared_ptr<Requests::Param> req = \
ParamReq req = \
m_requests->get_param(ParamType,value); \
try \
{ \
......@@ -102,7 +104,6 @@ class MultiParamRequest
public:
typedef Requests::PARAM_NAME Name;
typedef std::shared_ptr<Requests::Param> Request;
MultiParamRequest(Camera& cam, bool parallel)
: m_cam(cam), m_parallel(parallel)
......@@ -128,13 +129,14 @@ public:
}
}
Request operator [](Name name)
ParamReq operator [](Name name)
{ return m_map[name]; }
private:
typedef std::list<Request> RequestList;
typedef std::list<ParamReq> RequestList;
typedef std::map<Name, ParamReq> RequestMap;
void add(Name name, Request req)
void add(Name name, ParamReq req)
{
m_list.push_back(req);
m_map[name] = req;
......@@ -143,7 +145,7 @@ private:
wait(req);
}
void wait(Request req)
void wait(ParamReq req)
{
DEB_MEMBER_FUNCT();
......@@ -160,7 +162,7 @@ private:
Camera& m_cam;
bool m_parallel;
RequestList m_list;
std::map<Name, Request> m_map;
RequestMap m_map;
};
} // namespace Eiger
......@@ -295,8 +297,7 @@ void Camera::initialize()
AutoMutex lock(m_cond.mutex());
DEB_ALWAYS() << "Initializing detector ... ";
m_initialize_state = RUNNING;
std::shared_ptr<Requests::Command> async_initialize =
m_requests->get_command(Requests::INITIALIZE);
CommandReq async_initialize = m_requests->get_command(Requests::INITIALIZE);
lock.unlock();
std::shared_ptr<CurlLoop::FutureRequest::Callback> cbk(new InitCallback(*this));
......@@ -373,8 +374,7 @@ void Camera::prepareAcq()
DEB_TRACE() << "Arm start";
double timeout = 5 * 60.; // 5 min timeout
std::shared_ptr<Requests::Command> arm_cmd =
m_requests->get_command(Requests::ARM);
CommandReq arm_cmd = m_requests->get_command(Requests::ARM);
try
{
arm_cmd->wait(timeout);
......@@ -402,8 +402,7 @@ void Camera::startAcq()
if(m_trig_mode == IntTrig ||
m_trig_mode == IntTrigMult)
{
std::shared_ptr<Requests::Command> trigger =
m_requests->get_command(Requests::TRIGGER);
CommandReq trigger = m_requests->get_command(Requests::TRIGGER);
m_trigger_state = RUNNING;
lock.unlock();
......@@ -441,9 +440,9 @@ void Camera::getDetectorImageSize(Size& size) ///< [out] image dimensions
{
DEB_MEMBER_FUNCT();
std::shared_ptr<Requests::Param> width_request =
ParamReq width_request =
m_requests->get_param(Requests::DETECTOR_WITDH);
std::shared_ptr<Requests::Param> height_request =
ParamReq height_request =
m_requests->get_param(Requests::DETECTOR_HEIGHT);
Requests::Param::Value width = width_request->get();
......@@ -621,7 +620,7 @@ void Camera::getExposureTimeRange(double& min_expo, ///< [out] minimum exposure
const
{
DEB_MEMBER_FUNCT();
std::shared_ptr<Requests::Param> exp_time =
ParamReq exp_time =
m_requests->get_param(Requests::EXPOSURE);
try
{
......@@ -863,11 +862,8 @@ void Camera::_acquisition_finished(bool ok)
std::string error_msg;
//First we will disarm
if(ok)
if(m_trig_mode != IntTrigMult ||
(m_trig_mode == IntTrigMult && m_image_number == m_nb_frames))
std::shared_ptr<Requests::Command> disarm =
m_requests->get_command(Requests::DISARM);
if(ok && ((m_trig_mode != IntTrigMult) || (m_image_number == m_nb_frames)))
CommandReq disarm = m_requests->get_command(Requests::DISARM);
AutoMutex lock(m_cond.mutex());
m_trigger_state = ok ? IDLE : ERROR;
......@@ -1213,7 +1209,7 @@ void Camera::setCompressionType(Camera::CompressionType type)
}
DEB_TRACE() << DEB_VAR1(s);
std::shared_ptr<Requests::Param> type_req =
ParamReq type_req =
m_requests->get_param(Requests::COMPRESSION_TYPE);
Requests::Param::Value types_allowed = type_req->get_allowed_values();
const vector<string>& l = types_allowed.string_array;
......
......@@ -41,6 +41,10 @@
using namespace lima;
using namespace lima::Eiger;
using namespace eigerapi;
typedef Requests::ParamReq ParamReq;
typedef Stream::MessagePtr MessagePtr;
// --- Message struct ---
struct Stream::Message
{
......@@ -172,8 +176,8 @@ void Stream::setActive(bool active)
}
DEB_TRACE() << "STREAM_HEADER_DETAIL:" << DEB_VAR1(header_detail_str);
std::shared_ptr<Requests::Param> header_detail_req =
m_cam.m_requests->set_param(Requests::STREAM_HEADER_DETAIL,header_detail_str);
ParamReq header_detail_req = m_cam.m_requests->set_param(Requests::STREAM_HEADER_DETAIL,
header_detail_str);
try {
header_detail_req->wait();
} catch (const eigerapi::EigerException &e) {
......@@ -183,8 +187,8 @@ void Stream::setActive(bool active)
const char* active_str = active ? "enabled" : "disabled";
DEB_TRACE() << "STREAM_MODE:" << DEB_VAR1(active_str);
std::shared_ptr<Requests::Param> active_req =
m_cam.m_requests->set_param(Requests::STREAM_MODE,active_str);
ParamReq active_req = m_cam.m_requests->set_param(Requests::STREAM_MODE,
active_str);
try {
active_req->wait();
} catch (const eigerapi::EigerException &e) {
......@@ -239,8 +243,7 @@ void* Stream::_runFunc(void *streamPt)
}
static inline bool _get_json_header(std::shared_ptr<Stream::Message> &msg,
Json::Value& header)
static inline bool _get_json_header(MessagePtr &msg, Json::Value& header)
{
DEB_GLOBAL_FUNCT();
void* data = zmq_msg_data(msg->get_msg());
......@@ -334,11 +337,11 @@ void Stream::_run()
}
if(items[1].revents & ZMQ_POLLIN) // reading stream
{
std::vector<std::shared_ptr<Stream::Message>> pending_messages;
std::vector<MessagePtr> pending_messages;
pending_messages.reserve(9);
int more;
do {
std::shared_ptr<Stream::Message> msg(new Stream::Message());
MessagePtr msg(new Stream::Message());
_CHECK_RETURN(zmq_msg_recv(msg->get_msg(),stream_socket,0));
more = zmq_msg_more(msg->get_msg());
pending_messages.emplace_back(msg);
......@@ -517,7 +520,7 @@ bool Stream::get_msg(void* aDataBuffer,void*& msg_data,size_t& msg_size,int& dep
return false;
MessageNDepth message_depth = it->second;
std::shared_ptr<Stream::Message> message = message_depth.first;
MessagePtr message = message_depth.first;
depth = message_depth.second;
msg_data = zmq_msg_data(message->get_msg());
msg_size = zmq_msg_size(message->get_msg());
......
......@@ -37,6 +37,8 @@ namespace lima
DEB_CLASS_NAMESPC(DebModCamera,"Stream","Eiger");
public:
class Message;
typedef std::shared_ptr<Stream::Message> MessagePtr;
enum HeaderDetail {ALL,BASIC,OFF};
Stream(Camera&);
......@@ -67,7 +69,7 @@ namespace lima
class _BufferCtrlObj;
friend class _BufferCtrlObj;
typedef std::pair<std::shared_ptr<Stream::Message>,int> MessageNDepth;
typedef std::pair<MessagePtr,int> MessageNDepth;
typedef std::map<void*,MessageNDepth> Data2Message;
static void* _runFunc(void*);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment