ServiceProtocol.h
Go to the documentation of this file.
00001 /* 00002 * Copyright 2006-2008 Savarese Software Research Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.savarese.com/software/ApacheLicense-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00022 #ifndef __SSRC_WISP_PROTOCOL_SERVICE_PROTOCOL_H 00023 #define __SSRC_WISP_PROTOCOL_SERVICE_PROTOCOL_H 00024 00025 #include <ssrc/wisp/serialization.h> 00026 #include <ssrc/wisp/utility/wisp_struct.h> 00027 #include <ssrc/wisp/utility/wisp_import.h> 00028 00029 #include <ssrc/spread/Message.h> 00030 00031 #include <string> 00032 #include <cstdint> 00033 00034 __BEGIN_NS_SSRC_WISP_PROTOCOL 00035 00036 /* We use Spread message type as our protocol indicator and 00037 * encode the message type inside the message itself. This way, we 00038 * don't have to worry about running out of id numbers. 00039 */ 00040 typedef NS_SSRC_SPREAD::Message::message_type wisp_message_protocol; 00041 typedef std::uint16_t wisp_message_id; 00042 00043 template<typename PT> class Caller; 00044 00045 template<wisp_message_protocol protocol_, typename PT = BinaryPackingTraits> 00046 struct ServiceProtocol { 00047 enum { protocol = protocol_ }; 00048 00049 typedef PT packing_traits; 00050 typedef Caller<packing_traits> caller_type; 00051 }; 00052 00053 #define WISP_DEFINE_PROTOCOL(protocol_base) \ 00054 template<NS_SSRC_WISP_PROTOCOL::wisp_message_id _id> \ 00055 struct Message ## protocol_base : public NS_SSRC_WISP_UTILITY::wisp_struct { \ 00056 enum { protocol = protocol_base }; \ 00057 enum { id = _id }; \ 00058 template<class Archive> \ 00059 void serialize(Archive & ar, const unsigned int) { } \ 00060 } 00061 00062 // Convenience macros for defining message types. 00063 00064 #define __WISP_PROTOCOL_MESSAGE(in_template, call, base, members) \ 00065 struct BOOST_PP_CAT(Message, call) : public base<call> { \ 00066 BOOST_PP_SEQ_FOR_EACH(__WISP_STRUCT_MEMBER, _, members) \ 00067 BOOST_PP_CAT(Message, call)() : \ 00068 BOOST_PP_SEQ_FOR_EACH_I(__WISP_STRUCT_DEFAULT_INIT_MEMBER, _, members) { } \ 00069 explicit BOOST_PP_CAT(Message, call)(BOOST_PP_SEQ_FOR_EACH_I(__WISP_STRUCT_PARAM, in_template, members)) : \ 00070 BOOST_PP_SEQ_FOR_EACH_I(__WISP_STRUCT_INIT_MEMBER, _, members) { } \ 00071 __WISP_STRUCT_SERIALIZE_MEMBERS(members) \ 00072 __WISP_STRUCT_VISIT(members) \ 00073 } 00074 00075 #define __WISP_PROTOCOL_MESSAGE_WITH_INIT(in_template, call, base, members, initializers) \ 00076 struct BOOST_PP_CAT(Message, call) : public base<call> { \ 00077 BOOST_PP_SEQ_FOR_EACH(__WISP_STRUCT_MEMBER, _, members) \ 00078 explicit BOOST_PP_CAT(Message, call)(BOOST_PP_SEQ_FOR_EACH_I(__WISP_STRUCT_PARAM_INIT, BOOST_PP_ARRAY_PUSH_FRONT(BOOST_PP_ARRAY_PUSH_FRONT(initializers, BOOST_PP_SUB(BOOST_PP_SEQ_SIZE(members), BOOST_PP_ARRAY_SIZE(initializers))), in_template), members)) : \ 00079 BOOST_PP_SEQ_FOR_EACH_I(__WISP_STRUCT_INIT_MEMBER, _, members) { } \ 00080 __WISP_STRUCT_SERIALIZE_MEMBERS(members) \ 00081 __WISP_STRUCT_VISIT(members) \ 00082 } 00083 00084 #define WISP_PROTOCOL_MESSAGE(call, base, members) \ 00085 __WISP_PROTOCOL_MESSAGE(0, call, base, members) 00086 00087 #define WISP_PROTOCOL_MESSAGE_T(call, base, members) \ 00088 __WISP_PROTOCOL_MESSAGE(1, call, base, members) 00089 00090 #define WISP_PROTOCOL_MESSAGE_WITH_INIT(call, base, members, initializers) \ 00091 __WISP_PROTOCOL_MESSAGE_WITH_INIT(0, call, base, members, BOOST_PP_SEQ_TO_ARRAY(initializers)) 00092 00093 #define WISP_PROTOCOL_MESSAGE_WITH_INIT_T(call, base, members, initializers) \ 00094 __WISP_PROTOCOL_MESSAGE_WITH_INIT(1, call, base, members, BOOST_PP_SEQ_TO_ARRAY(initializers)) 00095 00096 __END_NS_SSRC_WISP_PROTOCOL 00097 00098 #endif
Copyright © 2006-2010 Savarese Software Research Corporation. All rights reserved.
Copyright © 2011 Savarese Software Research Corporation. All rights reserved