callable.hpp
1 #ifndef NOOS_CLOUD_CALLABLE
2 #define NOOS_CLOUD_CALLABLE
3 /*
4  * LICENSE HERE
5  */
6 #include "includes.ihh"
7 #include <noos/cloud/asio/platform.hpp>
8 #include <noos/cloud/default_error_handler.hpp>
9 #include <noos/cloud/asio/asio_https.hpp>
10 #include <noos/cloud/asio/asio_http.hpp>
11 #include <noos/cloud/asio/platform.hpp>
12 #include <noos/cloud/cloud_base.hpp>
13 #include <noos/cloud/deserialize.hpp>
14 #include <noos/cloud/vision_batch.hpp>
15 
16 namespace noos {
17 namespace cloud {
18 
26 template <class cloud_type,
27  bool keep_alive = true,
28  class socket_type = asio_https,
29  class error_handle = default_error_handler>
30 class callable
31 {
32 public:
33  using callback = typename cloud_type::callback;
34  using cloud_class = cloud_type;
35 
38  cloud_type object;
39 
41  callable() = delete;
42 
44  callable(callable const &) = delete;
45 
47  callable & operator=(const callable &) = delete;
48 
50  callable & operator=(callable &&) = delete;
51 
53  callable(callback functor,
55 
62  template <typename... parameters,
63  typename = typename std::enable_if<!std::is_same<cloud_type,cloud_batch>::value,bool>>
64  callable(callback functor,
65  platform info,
66  parameters... args);
67 
70  template <typename... parameters>
73 
75  template <typename... parameters,
76  typename = typename std::enable_if<std::is_same<cloud_type,cloud_batch>::value,bool>>
77  callable(const noos::object::picture & image,
78  platform info,
79  parameters... args);
80 
83  void send(unsigned int timeout = 2);
85  void stop();
86 protected:
88  void socket(std::function<void(std::string)> cloud_function);
90  callback functor;
91  platform endpoint;
92  std::unique_ptr<socket_type> socket_;
93  std::unique_ptr<boost::asio::streambuf> buffer_;
94  std::unique_ptr<boost::asio::ip::tcp::resolver::query> query_;
95  std::unique_ptr<boost::asio::io_service> io_;
96  std::unique_ptr<boost::asio::ip::tcp::resolver> resol_;
97 };
98 
99 template <class cloud_type,
100  bool keep_alive = true,
101  class socket_type = asio_https,
102  class error_handle = default_error_handler,
103  class ...args,
104  typename =
105  typename std::enable_if<!std::is_same<cloud_type,
106  cloud_batch>::value, bool>>
108  call(typename cloud_type::callback functor,
109  args... params)
110 {
111  return callable<cloud_type,
112  keep_alive,
113  socket_type,
114  error_handle>(functor, default_node, params...);
115 }
116 
117 #include "callable.tpl"
118 }
119 }
120 #endif
void stop()
stop calls and shutdown socket
Definition: callable.hpp:163
void send(unsigned int timeout=2)
send the cloud_type data once to the cloud endpoint
Definition: callable.hpp:138
a class which wraps around a cloud call, its socket, buffer and callback
Definition: callable.hpp:30
data of the platform where you are going to connect
Definition: platform.hpp:23
cloud service batch class
Definition: cloud_base.hpp:49
Definition: asio_handler.hpp:14
callable(vision_batch< parameters... > arg, platform=default_node)
overloaded constructor for vision_batch template cloud_type
Definition: callable.hpp:71
default error handler will output on stderr
Definition: default_error_handler.hpp:19
class which wraps around raw bytes of a picture
Definition: picture.hpp:17
vision_batch
Definition: vision_batch.hpp:44
callable & operator=(const callable &)=delete
callable(callback functor, platform info, parameters...args)
construct a callable object wrapper
Definition: callable.hpp:41
callable()=delete
no empty constructor allowed
cloud_type object
Definition: callable.hpp:38
ASIO socket controller for TLS (encrypred) cloud service calls.
Definition: asio_https.hpp:23
const platform default_node
default platform where to connect
Definition: platform.hpp:43