ifw  0.0.1-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
requestHandler.h
Go to the documentation of this file.
1 #ifndef REQUEST_HANDLER_H
2 #define REQUEST_HANDLER_H
3 
4 
5 #include <QString>
6 
7 
8 #include <rad/MsgRequestor.hpp>
9 #include <rad/Helper.hpp>
10 #include <rad/Logger.hpp>
11 
13 
14 template <typename TYPEREQ, typename TYPEREP>
15 class RequestHandler
16 {
17 
18 
19 public:
21 
23 
24 public slots:
25 
26  bool SendSynch(const std::string endpoint, TYPEREQ req, const long replyTimeout)
27  {
31  this, std::placeholders::_1,
32  std::placeholders::_2));
33  size_t nbytes = requestor.Send(req, replyTimeout);
34  if (nbytes < 0) {
35  RAD_LOG_ERROR() << "ERROR sending command.";
36  return false;
37  }
38 
39  try {
40  mIOS.run();
41  } catch (...) {
42  RAD_LOG_ERROR() << "ERROR running IOS.";
43  return false;
44  }
45  return true;
46  };
47 
48 private:
49  void ReplyCallback(const std::error_code& errCode, TYPEREP rep)
50  {
51  if (!errCode) {
52  std::cout << rep.reply() << std::endl;
53 // if (rep.has_aborted())
54 // {
55 // RAD_LOG_ERROR() << "aborted: " << rep.reply();
56 // }
57 // if (rep.has_error())
58 // {
59 // RAD_LOG_ERROR() << "error: " << rep.reply();
60 // }
61 // if (rep.has_timeout())
62 // {
63 // RAD_LOG_ERROR() << "timeout reached:" << rep.reply();
64 // }
65 
66  // QString temp = QString::fromStdString(rep.reply());
67  // bool a = temp.QString::toUpper().contains("ERROR");
68  // if (a)
69  //m_window->statusBar()->setStyleSheet("color: redwaf in");
70  // else
71  //m_window->statusBar()->setStyleSheet("color: blue");
72  //m_window->statusBar()->showMessage(QString::fromStdString(rep.reply()));
73  }
74  mIOS.stop();
75  };
76 
77  boost::asio::io_service mIOS;
78 };
79 
80 
81 
82 
83 
84 #endif // SETUP_OBJECT_H
85 
86 
87 
#define RAD_LOG_ERROR()
Definition: Logger.hpp:266
size_t Send(const TYPEREQ &payload, const long timeout=0)
Definition: MsgRequestor.hpp:88
RequestHandler()
Definition: requestHandler.h:20
boost::asio::io_service mIOS
Definition: main.cpp:67
Definition: main.cpp:31
static std::string CreateIdentity()
Definition: Helper.cpp:126
bool SendSynch(const std::string endpoint, TYPEREQ req, const long replyTimeout)
Definition: requestHandler.h:26
Definition: MsgRequestor.hpp:34
optional int32 error_code
Definition: topics.proto:14
void ReplyCallback(const std::error_code &err_code, TYPEREP rep)
Definition: main.cpp:56
~RequestHandler()
Definition: requestHandler.h:22