libtasks Documentation  1.6
uwsgi_thrift_async_handler.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #ifndef _UWSGI_THRIFT_ASYNC_HANDLER_H_
9 #define _UWSGI_THRIFT_ASYNC_HANDLER_H_
10 
11 #include <tasks/net/uwsgi_task.h>
12 #include <string>
13 #include <functional>
14 #include <memory>
15 
16 namespace tasks {
17 namespace net {
18 
21 template <class thrift_result_type, // generated by thrift
22  class thrift_args_type> // generated by thrift
24  public:
25  using handler_finish_func_t = std::function<void()>;
26  using result_t = thrift_result_type;
27  using args_t = thrift_args_type;
28 
29  private:
33 
34  protected:
36  inline const uwsgi_request& request() const { return m_uwsgi_task->request(); }
37 
39  inline const uwsgi_request* request_p() const { return m_uwsgi_task->request_p(); }
40 
42  inline http_response& response() { return m_uwsgi_task->response(); }
43 
46 
48  inline void finish() { m_finish_func(); }
49 
51  inline void set_error(std::string msg) {
53  set_exception(e);
54  }
55 
56  public:
58 
62  virtual void service(std::shared_ptr<args_t> args) = 0;
63 
66  virtual std::string service_name() const = 0;
67 
69  inline result_t& result_base() { return m_result; }
70 
72  inline auto result() -> decltype((m_result.success)) { return m_result.success; }
73 
75  inline void set_uwsgi_task(uwsgi_task* t) { m_uwsgi_task = t; }
76 
82 };
83 
84 } // net
85 } // tasks
86 
87 #endif // _UWSGI_THRIFT_ASYNC_HANDLER_H_
The HTTP response implementation.
Definition: http_response.h:19
auto result() -> decltype((m_result.success))
Return a reference to the thrift result object. A thrift handler uses this to return data...
http_response & response()
Definition: uwsgi_task.h:55
uwsgi_request * request_p()
Definition: uwsgi_task.h:49
A helper class for basic error reporting.
Definition: error_base.h:18
void set_error(std::string msg)
Report an error.
Tasks execption class.
The base class for the uwsgi protocol implementation.
Definition: uwsgi_task.h:30
The uwsgi protocol implementation for a request. The response is a HTTP/1.1 response.
Definition: uwsgi_request.h:27
virtual std::string service_name() const =0
result_t & result_base()
Return a reference to the thrift result base object.
virtual void service(std::shared_ptr< args_t > args)=0
void set_exception(tasks_exception &e)
Set an exception to report an error.
Definition: error_base.h:54
void set_uwsgi_task(uwsgi_task *t)
The uwsgi_thrift_async_processor uses this method to assign the underlying uwsgi_task object...
http_response * response_p()
Definition: uwsgi_task.h:61
uwsgi_request & request()
Definition: uwsgi_task.h:43
void finish()
Async handlers call this method to trigger the processor callback.