Savarese Software Research Corporation
BaseMessage.h
Go to the documentation of this file.
1 /* Copyright 2006 Savarese Software Research Corporation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.savarese.com/software/ApacheLicense-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
21 #ifndef __SSRC_SPREAD_BASE_MESSAGE_H
22 #define __SSRC_SPREAD_BASE_MESSAGE_H
23 
24 #include <string>
25 
27 
28 // sp.h includes stddef.h, so we need to include it before sp.h in
29 // order to ensure it gets skipped while inside the Spread namespace.
30 #include <cstddef>
31 
33 # include <sp.h>
34 
35  // Convert define to typedef.
36 # if defined(int16)
37  typedef int16 foo_int16;
38 # undef int16
39  typedef foo_int16 int16;
40 # endif
42 
43 #include <ssrc/spread/Error.h>
44 #include <ssrc/spread/GroupList.h>
45 
47 
48 #ifdef LIBSSRCSPREAD_ENABLE_MEMBERSHIP_INFO
49 
50 // Forward declaration
51 class MembershipInfo;
52 
53 #endif
54 
60 class BaseMessage {
61 public:
63  typedef Spread::int16 message_type;
64 
66  typedef Spread::service service_type;
67 
81  enum Service {
82  Unreliable = UNRELIABLE_MESS,
83  Reliable = RELIABLE_MESS,
84  FIFO = FIFO_MESS,
85  Causal = CAUSAL_MESS,
86  Agreed = AGREED_MESS,
87  Safe = SAFE_MESS,
88  SelfDiscard = SELF_DISCARD,
89  DropReceive = DROP_RECV,
90 #define SERVICE_TYPE_DISCARD(s) s ## SelfDiscard = s | SelfDiscard
91 
98 
99 #undef SERVICE_TYPE_DISCARD
100  };
101 
102 private:
103 
104 #ifdef LIBSSRCSPREAD_ENABLE_MEMBERSHIP_INFO
105 
106  void get_vs_set_members(const Spread::vs_set_info *vs_set,
107  GroupList *members, unsigned int offset = 0) const;
108 
109 #endif
110 
111 protected:
112 
113  message_type _type;
114  service_type _service_type;
116  string _sender;
117 
124  _type(0), _service_type(Safe), _endian_mismatch(false), _sender("")
125  { }
126 
127 #ifdef LIBSSRCSPREAD_ENABLE_MEMBERSHIP_INFO
128 
129  virtual int sp_get_membership_info(Spread::membership_info *info) const = 0;
130 
131  virtual int sp_get_vs_set_members(const Spread::vs_set_info *vs_set,
132  Spread::group_type member_names[],
133  unsigned int member_names_count) const = 0;
134 
135  virtual int sp_get_vs_sets_info(Spread::vs_set_info *vs_sets,
136  unsigned int num_vs_sets,
137  unsigned int *index) const = 0;
138 
139 #endif
140 
141 public:
142 
144  virtual ~BaseMessage() { }
145 
151  virtual unsigned int size() const = 0;
152 
154  virtual void clear() = 0;
155 
156 #ifdef LIBSSRCSPREAD_ENABLE_MEMBERSHIP_INFO
157 
158  void get_membership_info(MembershipInfo & info) const SSRC_DECL_THROW(Error);
159 
160 #endif
161 
167  void set_service(const service_type service) {
168  _service_type = service;
169  }
170 
177  service_type service() const {
178  return _service_type;
179  }
180 
185  void set_type(const message_type type) {
186  _type = type;
187  }
188 
193  message_type type() const {
194  return _type;
195  }
196 
201  void set_sender(const string & sender) {
202  _sender = sender;
203  }
204 
209  const string & sender() const {
210  return _sender;
211  }
212 
217  void set_endian_mismatch(const bool mismatch = true) {
218  _endian_mismatch = mismatch;
219  }
220 
227  bool endian_mismatch() const {
228  return _endian_mismatch;
229  }
230 
232  void set_agreed() {
234  }
235 
240  bool is_agreed() const {
241  return Is_agreed_mess(service());
242  }
243 
245  void set_causal() {
247  }
248 
253  bool is_causal() const {
254  return Is_causal_mess(service());
255  }
256 
258  void set_fifo() {
259  set_service(FIFO);
260  }
261 
266  bool is_fifo() const {
267  return Is_fifo_mess(service());
268  }
269 
271  void set_reliable() {
273  }
274 
279  bool is_reliable() const {
280  return Is_reliable_mess(service());
281  }
282 
284  void set_unreliable() {
286  }
287 
292  bool is_unreliable() const {
293  return Is_unreliable_mess(service());
294  }
295 
297  void set_safe() {
298  set_service(Safe);
299  }
300 
305  bool is_safe() const {
306  return Is_safe_mess(service());
307  }
308 
316  void set_self_discard(const bool discard = true) {
317  _service_type |= SelfDiscard;
318  if(!discard)
319  _service_type ^= SelfDiscard;
320  }
321 
328  bool is_self_discard() const {
329  return Is_self_discard(service());
330  }
331 
337  bool is_regular() const {
338  return Is_regular_mess(service());
339  }
340 
345  bool is_membership() const {
346  return Is_membership_mess(service());
347  }
348 };
349 
351 
352 #endif

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