6 #ifndef CPPIPC_MAGIC_MACROS_HPP 7 #define CPPIPC_MAGIC_MACROS_HPP 8 #include <core/system/cppipc/ipc_object_base.hpp> 9 #include <core/system/cppipc/registration_macros.hpp> 10 #ifndef DISABLE_TURI_CPPIPC_PROXY_GENERATION 11 #include <core/system/cppipc/server/comm_server.hpp> 12 #include <core/system/cppipc/client/object_proxy.hpp> 13 #include <core/system/cppipc/cppipc.hpp> 15 #include <core/system/cppipc/common/ipc_deserializer.hpp> 16 #include <core/storage/serialization/serialization_includes.hpp> 17 #include <boost/preprocessor.hpp> 18 #define __GENERATE_REGISTRATION__(r, base_name, elem) \ 19 REGISTER(base_name::BOOST_PP_TUPLE_ELEM(3,1,elem)) 22 #define __GENERATE_PROXY_ARGS__(r, ni, i, elem) elem BOOST_PP_CAT(arg_,i) \ 23 BOOST_PP_COMMA_IF(BOOST_PP_GREATER(ni, BOOST_PP_ADD(i, 1))) 25 #define __GENERATE_PROXY_CALL_ARGS__(r, ni, i, elem) BOOST_PP_CAT(arg_,i) \ 26 BOOST_PP_COMMA_IF(BOOST_PP_GREATER(ni, BOOST_PP_ADD(i, 1))) 29 #define __GENERATE_BASE__(r, _, elem) \ 30 virtual BOOST_PP_TUPLE_ELEM(3, 0, elem) \ 31 BOOST_PP_TUPLE_ELEM(3,1, elem) ( \ 32 BOOST_PP_SEQ_FOR_EACH_I(__GENERATE_PROXY_ARGS__, \ 33 BOOST_PP_SEQ_SIZE(BOOST_PP_TUPLE_ELEM(3, 2,elem)), \ 34 BOOST_PP_TUPLE_ELEM(3,2, elem)) \ 37 #define __GENERATE_PROXY_CALLS__(r, base_name, elem) \ 38 inline BOOST_PP_TUPLE_ELEM(3, 0, elem) \ 39 BOOST_PP_TUPLE_ELEM(3,1, elem) \ 40 ( BOOST_PP_SEQ_FOR_EACH_I(__GENERATE_PROXY_ARGS__, \ 41 BOOST_PP_SEQ_SIZE(BOOST_PP_TUPLE_ELEM(3, 2,elem)), \ 42 BOOST_PP_TUPLE_ELEM(3,2, elem)) ) { \ 43 return proxy.call(&base_name::BOOST_PP_TUPLE_ELEM(3,1,elem) \ 44 BOOST_PP_COMMA_IF(BOOST_PP_GREATER(BOOST_PP_SEQ_SIZE(BOOST_PP_TUPLE_ELEM(3,2,elem)),0)) \ 45 BOOST_PP_SEQ_FOR_EACH_I(__GENERATE_PROXY_CALL_ARGS__, \ 46 BOOST_PP_SEQ_SIZE(BOOST_PP_TUPLE_ELEM(3, 2,elem)), \ 47 BOOST_PP_TUPLE_ELEM(3, 2, elem)) \ 52 #define __ADD_PAREN_1__(A, B, C) ((A, B, C)) __ADD_PAREN_2__ 53 #define __ADD_PAREN_2__(A, B, C) ((A, B, C)) __ADD_PAREN_1__ 54 #define __ADD_PAREN_1___END 55 #define __ADD_PAREN_2___END 56 #define __ADD_PARENS__(INPUT) BOOST_PP_CAT(__ADD_PAREN_1__ INPUT,_END) 106 #define GENERATE_INTERFACE(base_name, proxy_name, functions) \ 107 class base_name : public cppipc::ipc_object_base { \ 109 typedef proxy_name proxy_object_type; \ 110 inline virtual ~base_name() { } \ 111 inline virtual void save(turi::oarchive& oarc) const {} \ 112 inline virtual void load(turi::iarchive& iarc) {} \ 113 BOOST_PP_SEQ_FOR_EACH(__GENERATE_BASE__, _, __ADD_PARENS__(functions)) \ 114 REGISTRATION_BEGIN(base_name) \ 115 BOOST_PP_SEQ_FOR_EACH(__GENERATE_REGISTRATION__, base_name, __ADD_PARENS__(functions)) \ 184 #define GENERATE_PROXY(base_name, proxy_name, functions) \ 185 class proxy_name : public base_name { \ 187 cppipc::object_proxy<base_name> proxy; \ 188 inline proxy_name(cppipc::comm_client& comm, \ 189 bool auto_create = true, \ 190 size_t object_id = (size_t)(-1)): \ 191 proxy(comm, auto_create, object_id){ } \ 192 inline void save(turi::oarchive& oarc) const { \ 193 oarc << proxy.get_object_id(); \ 195 inline size_t __get_object_id() const { \ 196 return proxy.get_object_id(); \ 198 inline void load(turi::iarchive& iarc) { \ 199 size_t objid; iarc >> objid; \ 200 proxy.set_object_id(objid); \ 202 BOOST_PP_SEQ_FOR_EACH(__GENERATE_PROXY_CALLS__, base_name, __ADD_PARENS__(functions)) \ 285 #ifdef DISABLE_TURI_CPPIPC_PROXY_GENERATION 287 #define GENERATE_INTERFACE_AND_PROXY(base_name, proxy_name, functions) \ 289 GENERATE_INTERFACE(base_name, proxy_name, functions) 293 #define GENERATE_INTERFACE_AND_PROXY(base_name, proxy_name, functions) \ 295 GENERATE_INTERFACE(base_name, proxy_name, functions) \ 296 GENERATE_PROXY(base_name, proxy_name, functions)