38 # include <dsn/cpp/clientlet.h> 39 # include <dsn/cpp/service_app.h> 58 template <
typename TResponse>
69 _response = r._response;
72 void operator () (
const TResponse& resp)
74 if (_response !=
nullptr)
76 ::dsn::marshall(_response, resp);
83 return _response ==
nullptr;
87 dsn_message_t _response;
94 serverlet(
const char* nm,
int task_bucket_count = 8);
98 template<
typename TRequest>
99 bool register_rpc_handler(dsn_task_code_t rpc_code,
const char* rpc_name_,
void (T::*handler)(
const TRequest&),
dsn_gpid gpid =
dsn_gpid{ 0 });
101 template<
typename TRequest,
typename TResponse>
102 bool register_rpc_handler(dsn_task_code_t rpc_code,
const char* rpc_name_,
void (T::*handler)(
const TRequest&, TResponse&),
dsn_gpid gpid =
dsn_gpid{ 0 });
104 template<
typename TRequest,
typename TResponse>
107 bool register_rpc_handler(dsn_task_code_t rpc_code,
const char* rpc_name_,
void (T::*handler)(dsn_message_t),
dsn_gpid gpid =
dsn_gpid{ 0 });
111 template<
typename TResponse>
112 void reply(dsn_message_t request,
const TResponse& resp);
115 const std::string& name()
const {
return _name; }
118 template<
typename TCallback>
119 struct handler_context
131 :
clientlet(task_bucket_count), _name(nm)
140 template<
typename T>
template<
typename TRequest>
143 typedef handler_context<void (T::*)(const TRequest&)> hc_type1;
144 auto hc = (hc_type1*)malloc(
sizeof(hc_type1));
145 hc->this_ = (T*)
this;
150 auto hc2 = (hc_type1*)param;
153 ::dsn::unmarshall(request, req);
154 ((hc2->this_)->*(hc2->cb))(req);
160 template<
typename T>
template<
typename TRequest,
typename TResponse>
163 typedef handler_context<void (T::*)(const TRequest&, TResponse&)> hc_type2;
164 auto hc = (hc_type2*)malloc(
sizeof(hc_type2));
165 hc->this_ = (T*)
this;
170 auto hc2 = (hc_type2*)param;
173 ::dsn::unmarshall(request, req);
176 ((hc2->this_)->*(hc2->cb))(req, resp);
185 template<
typename T>
template<
typename TRequest,
typename TResponse>
188 typedef handler_context<void (T::*)(const TRequest&, rpc_replier<TResponse>&)> hc_type3;
189 auto hc = (hc_type3*)malloc(
sizeof(hc_type3));
190 hc->this_ = (T*)
this;
195 auto hc2 = (hc_type3*)param;
198 ::dsn::unmarshall(request, req);
201 ((hc2->this_)->*(hc2->cb))(req, replier);
210 typedef handler_context<void (T::*)(dsn_message_t)> hc_type4;
211 auto hc = (hc_type4*)malloc(
sizeof(hc_type4));
212 hc->this_ = (T*)
this;
217 auto hc2 = (hc_type4*)param;
218 ((hc2->this_)->*(hc2->cb))(request);
228 if (cb !=
nullptr) free(cb);
229 return cb !=
nullptr;
232 template<
typename T>
template<
typename TResponse>
236 ::dsn::marshall(msg, resp);
DSN_API dsn_message_t dsn_msg_create_response(dsn_message_t request)
create a RPC response message correspondent to the given request message
Definition: serverlet.h:91
DSN_API void dsn_rpc_reply(dsn_message_t response, dsn_error_t err DEFAULT(0))
reply with a response which is created using dsn_msg_create_response
void(* dsn_rpc_request_handler_t)(dsn_message_t, void *)
callback prototype for TASK_TYPE_RPC_REQUEST
Definition: api_task.h:69
Definition: auto_codes.h:105
Definition: api_layer1.h:683
DSN_API void * dsn_rpc_unregiser_handler(dsn_task_code_t code, dsn_gpid gpid DEFAULT(dsn_gpid{0}))
unregister callback to handle RPC request, and returns void* context upon dsn_rpc_register_handler ...
Definition: serverlet.h:59
Definition: clientlet.h:48
DSN_API bool dsn_rpc_register_handler(dsn_task_code_t code, const char *name, dsn_rpc_request_handler_t cb, void *context, dsn_gpid gpid DEFAULT(dsn_gpid{0}))
register callback to handle RPC request