8 #ifndef CPPCMS_RPC_JSON_OBJECT_H 9 #define CPPCMS_RPC_JSON_OBJECT_H 11 #include <cppcms/application.h> 12 #include <booster/function.h> 13 #include <cppcms/json.h> 14 #include <cppcms/cppcms_error.h> 97 void check_not_notification();
133 void bind(std::string
const &name,method_type
const &,role_type type = any_role);
143 void smd_raw(std::string
const &);
147 void smd_from_file(std::string
const &);
152 virtual void main(std::string);
167 std::string method();
194 typedef std::map<std::string,method_data> methods_map_type;
195 methods_map_type methods_;
208 template<
typename T>
struct fw_ret {
typedef T type; };
209 template<
typename T>
struct fw_ret<T const &> {
typedef T type; };
210 template<
typename T>
struct fw_ret<T const> {
typedef T type; };
212 template<>
struct fw_ret<json::value> {
typedef json::value const &type; };
213 template<>
struct fw_ret<json::object> {
typedef json::object const &type; };
214 template<>
struct fw_ret<json::array> {
typedef json::array const &type; };
215 template<>
struct fw_ret<std::string> {
typedef std::string
const &type; };
217 template<>
struct fw_ret<json::value const &> {
typedef json::value const &type; };
218 template<>
struct fw_ret<json::object const &> {
typedef json::object const &type; };
219 template<>
struct fw_ret<json::array const &> {
typedef json::array const &type; };
220 template<>
struct fw_ret<std::string const &> {
typedef std::string
const &type; };
222 template<>
struct fw_ret<json::value const> {
typedef json::value const &type; };
223 template<>
struct fw_ret<json::object const> {
typedef json::object const &type; };
224 template<>
struct fw_ret<json::array const> {
typedef json::array const &type; };
225 template<>
struct fw_ret<std::string const> {
typedef std::string
const &type; };
229 struct fw_ret_handle {
230 static typename fw_ret<T>::type extract(
json::value const &v)
232 return v.
get_value<
typename fw_ret<T>::type>();
237 struct fw_ret_handle<json::value const &>
246 struct fw_ret_handle<json::array const &>
255 struct fw_ret_handle<json::object const &>
264 struct fw_ret_handle<std::string const &>
266 static std::string
const &extract(
json::value const &v)
273 template <
typename T>
274 inline typename fw_ret<T>::type forward_value(
json::value const &v)
276 typedef typename fw_ret<T>::type return_type;
277 return fw_ret_handle<return_type>::extract(v);
282 #define CPPCMS_JSON_RPC_BINDER(N) \ 283 namespace details { \ 284 template<typename Class,typename Ptr CPPCMS_TEMPLATE_PARAMS> \ 287 void (Class::*member)(CPPCMS_FUNC_PARAMS); \ 288 void operator()(json::array const &a) const \ 291 throw call_error("Invalid parametres number"); \ 292 ((*object).*member)(CPPCMS_CALL_PARAMS); \ 296 template<typename Class,typename Ptr CPPCMS_TEMPLATE_PARAMS> \ 297 details::binder##N<Class,Ptr CPPCMS_BINDER_PARAMS> \ 298 json_method(void (Class::*m)(CPPCMS_FUNC_PARAMS),Ptr p) \ 299 { details::binder##N<Class,Ptr CPPCMS_BINDER_PARAMS> tmp={p,m}; return tmp; } \ 301 #define CPPCMS_TEMPLATE_PARAMS 302 #define CPPCMS_FUNC_PARAMS 303 #define CPPCMS_CALL_PARAMS 304 #define CPPCMS_BINDER_PARAMS 305 CPPCMS_JSON_RPC_BINDER(0)
306 #undef CPPCMS_TEMPLATE_PARAMS 307 #undef CPPCMS_FUNC_PARAMS 308 #undef CPPCMS_CALL_PARAMS 309 #undef CPPCMS_BINDER_PARAMS 311 #define CPPCMS_TEMPLATE_PARAMS ,typename P1 312 #define CPPCMS_FUNC_PARAMS P1 313 #define CPPCMS_CALL_PARAMS forward_value<P1>(a[0]) 314 #define CPPCMS_BINDER_PARAMS ,P1 315 CPPCMS_JSON_RPC_BINDER(1)
316 #undef CPPCMS_TEMPLATE_PARAMS 317 #undef CPPCMS_FUNC_PARAMS 318 #undef CPPCMS_CALL_PARAMS 319 #undef CPPCMS_BINDER_PARAMS 321 #define CPPCMS_TEMPLATE_PARAMS ,typename P1,typename P2 322 #define CPPCMS_FUNC_PARAMS P1,P2 323 #define CPPCMS_CALL_PARAMS forward_value<P1>(a[0]), forward_value<P2>(a[1]) 324 #define CPPCMS_BINDER_PARAMS ,P1,P2 325 CPPCMS_JSON_RPC_BINDER(2)
326 #undef CPPCMS_TEMPLATE_PARAMS 327 #undef CPPCMS_FUNC_PARAMS 328 #undef CPPCMS_CALL_PARAMS 329 #undef CPPCMS_BINDER_PARAMS 331 #define CPPCMS_TEMPLATE_PARAMS ,typename P1,typename P2,typename P3 332 #define CPPCMS_FUNC_PARAMS P1,P2,P3 333 #define CPPCMS_CALL_PARAMS forward_value<P1>(a[0]), forward_value<P2>(a[1]), forward_value<P3>(a[2]) 334 #define CPPCMS_BINDER_PARAMS ,P1,P2,P3 335 CPPCMS_JSON_RPC_BINDER(3)
336 #undef CPPCMS_TEMPLATE_PARAMS 337 #undef CPPCMS_FUNC_PARAMS 338 #undef CPPCMS_CALL_PARAMS 339 #undef CPPCMS_BINDER_PARAMS 341 #define CPPCMS_TEMPLATE_PARAMS ,typename P1,typename P2,typename P3,typename P4 342 #define CPPCMS_FUNC_PARAMS P1,P2,P3,P4 343 #define CPPCMS_CALL_PARAMS forward_value<P1>(a[0]), forward_value<P2>(a[1]), forward_value<P3>(a[2]), forward_value<P4>(a[3]) 344 #define CPPCMS_BINDER_PARAMS ,P1,P2,P3,P4 345 CPPCMS_JSON_RPC_BINDER(4)
346 #undef CPPCMS_TEMPLATE_PARAMS 347 #undef CPPCMS_FUNC_PARAMS 348 #undef CPPCMS_CALL_PARAMS 349 #undef CPPCMS_BINDER_PARAMS 351 #undef CPPCMS_JSON_RPC_BINDER booster::function< void(json::array const &)> method_type
Definition: rpc_json.h:128
This class is central representation of json objects.
Definition: json.h:140
Method may receive notification and return result.
Definition: rpc_json.h:120
This class represent the central event loop of the CppCMS applications.
Definition: service.h:62
The error thrown in case of bad call - parameters mismatch or invalid request.
Definition: rpc_json.h:29
Exception thrown by CppCMS framework.
Definition: cppcms_error.h:22
std::map< string_key, value > object
The json::object - std::map of json::value's.
Definition: json.h:51
json::array const & array() const
This is the namespace where all CppCMS functionality is placed.
Definition: application.h:19
role_type
Definition: rpc_json.h:119
T get_value() const
Definition: json.h:234
context is a central class that holds all specific connection related information. It encapsulates CGI request and response, cache, session and locale information
Definition: http_context.h:47
std::string const & str() const
This class represents single call of json-rpc method.
Definition: rpc_json.h:46
Method can't be used with notification calls.
Definition: rpc_json.h:121
application class is the base class for all user created applications.
Definition: application.h:82
basic_message< char > message
Definition: message.h:494
JSON-RPC service application.
Definition: rpc_json.h:114
json::object const & object() const
std::vector< value > array
The json::array - std::vector of json::value's.
Definition: json.h:47
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15