Savarese Software Research Corporation
ServiceProtocol.h
Go to the documentation of this file.
1 /*
2  * Copyright 2006-2008 Savarese Software Research Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.savarese.com/software/ApacheLicense-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #ifndef __SSRC_WISP_PROTOCOL_SERVICE_PROTOCOL_H
23 #define __SSRC_WISP_PROTOCOL_SERVICE_PROTOCOL_H
24 
28 
29 #include <ssrc/spread/Message.h>
30 
31 #include <string>
32 #include <cstdint>
33 
35 
36 /* We use Spread message type as our protocol indicator and
37  * encode the message type inside the message itself. This way, we
38  * don't have to worry about running out of id numbers.
39  */
40 typedef NS_SSRC_SPREAD::Message::message_type wisp_message_protocol;
41 typedef std::uint16_t wisp_message_id;
42 
43 template<typename PT> class Caller;
44 
45 template<wisp_message_protocol protocol_, typename PT = BinaryPackingTraits>
46 struct ServiceProtocol {
47  enum { protocol = protocol_ };
48 
49  typedef PT packing_traits;
51 };
52 
53 #define WISP_DEFINE_PROTOCOL(protocol_base) \
54  template<NS_SSRC_WISP_PROTOCOL::wisp_message_id _id> \
55  struct Message ## protocol_base : public NS_SSRC_WISP_UTILITY::wisp_struct { \
56  enum { protocol = protocol_base }; \
57  enum { id = _id }; \
58  template<class Archive> \
59  void serialize(Archive & ar, const unsigned int) { } \
60  }
61 
62 // Convenience macros for defining message types.
63 
64 #define __WISP_PROTOCOL_MESSAGE(in_template, call, base, members) \
65  struct BOOST_PP_CAT(Message, call) : public base<call> { \
66  BOOST_PP_SEQ_FOR_EACH(__WISP_STRUCT_MEMBER, _, members) \
67  BOOST_PP_CAT(Message, call)() : \
68  BOOST_PP_SEQ_FOR_EACH_I(__WISP_STRUCT_DEFAULT_INIT_MEMBER, _, members) { } \
69  explicit BOOST_PP_CAT(Message, call)(BOOST_PP_SEQ_FOR_EACH_I(__WISP_STRUCT_PARAM, in_template, members)) : \
70  BOOST_PP_SEQ_FOR_EACH_I(__WISP_STRUCT_INIT_MEMBER, _, members) { } \
71  __WISP_STRUCT_SERIALIZE_MEMBERS(members) \
72  __WISP_STRUCT_VISIT(members) \
73  }
74 
75 #define __WISP_PROTOCOL_MESSAGE_WITH_INIT(in_template, call, base, members, initializers) \
76  struct BOOST_PP_CAT(Message, call) : public base<call> { \
77  BOOST_PP_SEQ_FOR_EACH(__WISP_STRUCT_MEMBER, _, members) \
78  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)) : \
79  BOOST_PP_SEQ_FOR_EACH_I(__WISP_STRUCT_INIT_MEMBER, _, members) { } \
80  __WISP_STRUCT_SERIALIZE_MEMBERS(members) \
81  __WISP_STRUCT_VISIT(members) \
82  }
83 
84 #define WISP_PROTOCOL_MESSAGE(call, base, members) \
85  __WISP_PROTOCOL_MESSAGE(0, call, base, members)
86 
87 #define WISP_PROTOCOL_MESSAGE_T(call, base, members) \
88  __WISP_PROTOCOL_MESSAGE(1, call, base, members)
89 
90 #define WISP_PROTOCOL_MESSAGE_WITH_INIT(call, base, members, initializers) \
91  __WISP_PROTOCOL_MESSAGE_WITH_INIT(0, call, base, members, BOOST_PP_SEQ_TO_ARRAY(initializers))
92 
93 #define WISP_PROTOCOL_MESSAGE_WITH_INIT_T(call, base, members, initializers) \
94  __WISP_PROTOCOL_MESSAGE_WITH_INIT(1, call, base, members, BOOST_PP_SEQ_TO_ARRAY(initializers))
95 
97 
98 #endif

Savarese Software Research Corporation
Copyright © 2006-2012 Savarese Software Research Corporation. All rights reserved.