Savarese Software Research Corporation

BaseMessage.h

Go to the documentation of this file.
00001 /*
00002  * $Id: BaseMessage.h 1125 2007-11-24 06:42:46Z dfs $
00003  *
00004  * Copyright 2006 Savarese Software Research Corporation
00005  *
00006  * Licensed under the Apache License, Version 2.0 (the "License");
00007  * you may not use this file except in compliance with the License.
00008  * You may obtain a copy of the License at
00009  *
00010  *     http://www.savarese.com/software/ApacheLicense-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  */
00018 
00024 #ifndef __SAVA_SPREAD_BASE_MESSAGE_H
00025 #define __SAVA_SPREAD_BASE_MESSAGE_H
00026 
00027 #include <string>
00028 
00029 #include <sava/libsavaspread-packages.h>
00030 
00031 __BEGIN_NS_SPREAD_INCLUDE
00032 # include <sp.h>
00033 
00034   // Convert define to typedef.
00035 # if defined(int16)
00036   typedef int16 foo_int16;
00037 # undef int16
00038   typedef foo_int16 int16;
00039 # endif
00040 __END_NS_SPREAD_INCLUDE
00041 
00042 #include <sava/spread/Error.h>
00043 #include <sava/spread/GroupList.h>
00044 
00045 __BEGIN_NS_SAVA_SPREAD
00046 
00047 #ifdef LIBSAVASPREAD_ENABLE_MEMBERSHIP_INFO
00048 
00049 // Forward declaration
00050 class MembershipInfo;
00051 
00052 #endif
00053 
00059 class BaseMessage {
00060 public:
00062   typedef Spread::int16 message_type;
00063 
00065   typedef Spread::service service_type;
00066 
00080   enum Service {
00081     Unreliable  = UNRELIABLE_MESS,
00082     Reliable    = RELIABLE_MESS,
00083     FIFO        = FIFO_MESS,
00084     Causal      = CAUSAL_MESS,
00085     Agreed      = AGREED_MESS,
00086     Safe        = SAFE_MESS,
00087     SelfDiscard = SELF_DISCARD,
00088     DropReceive = DROP_RECV,
00089 #define SERVICE_TYPE_DISCARD(s) s ## SelfDiscard = s | SelfDiscard
00090 
00091     SERVICE_TYPE_DISCARD(Unreliable),
00092     SERVICE_TYPE_DISCARD(Reliable),
00093     SERVICE_TYPE_DISCARD(FIFO),
00094     SERVICE_TYPE_DISCARD(Causal),
00095     SERVICE_TYPE_DISCARD(Agreed),
00096     SERVICE_TYPE_DISCARD(Safe)
00097 
00098 #undef SERVICE_TYPE_DISCARD
00099   };
00100 
00101 private:
00102 
00103 #ifdef LIBSAVASPREAD_ENABLE_MEMBERSHIP_INFO
00104 
00105   void get_vs_set_members(const Spread::vs_set_info *vs_set,
00106                           GroupList *members, unsigned int offset = 0) const;
00107 
00108 #endif
00109 
00110 protected:
00111 
00112   message_type _type;
00113   service_type _service_type;
00114   bool _endian_mismatch;
00115   string _sender;
00116 
00122   BaseMessage() :
00123     _type(0), _service_type(Safe), _endian_mismatch(false), _sender("")
00124   { }
00125 
00126 #ifdef LIBSAVASPREAD_ENABLE_MEMBERSHIP_INFO
00127 
00128   virtual int sp_get_membership_info(Spread::membership_info *info) const = 0;
00129 
00130   virtual int sp_get_vs_set_members(const Spread::vs_set_info *vs_set,
00131                                     Spread::group_type member_names[],
00132                                     unsigned int member_names_count) const = 0;
00133 
00134   virtual int sp_get_vs_sets_info(Spread::vs_set_info *vs_sets,
00135                                   unsigned int num_vs_sets,
00136                                   unsigned int *index) const = 0;
00137 
00138 #endif
00139 
00140 public:
00141 
00143   virtual ~BaseMessage() { }
00144 
00150   virtual unsigned int size() const throw() = 0;
00151 
00153   virtual void clear() = 0;
00154 
00155 #ifdef LIBSAVASPREAD_ENABLE_MEMBERSHIP_INFO
00156 
00157   void get_membership_info(MembershipInfo & info) const throw(Error);
00158 
00159 #endif
00160 
00166   void set_service(const service_type service) throw() {
00167     _service_type = service;
00168   }
00169 
00176   service_type service() const throw() {
00177     return _service_type;
00178   }
00179 
00184   void set_type(const message_type type) throw() {
00185     _type = type;
00186   }
00187 
00192   message_type type() const throw() {
00193     return _type;
00194   }
00195 
00200   void set_sender(const string & sender) {
00201     _sender = sender;
00202   }
00203 
00208   const string & sender() const throw() {
00209     return _sender;
00210   }
00211 
00216   void set_endian_mismatch(const bool mismatch = true) throw() {
00217     _endian_mismatch = mismatch;
00218   }
00219 
00226   bool endian_mismatch() const throw() {
00227     return _endian_mismatch;
00228   }
00229 
00231   void set_agreed() throw() {
00232     set_service(Agreed);
00233   }
00234 
00239   bool is_agreed() const throw() {
00240     return Is_agreed_mess(service());
00241   }
00242 
00244   void set_causal() throw() {
00245     set_service(Causal);
00246   }
00247 
00252   bool is_causal() const throw() {
00253     return Is_causal_mess(service());
00254   }
00255 
00257   void set_fifo() throw() {
00258     set_service(FIFO);
00259   }
00260 
00265   bool is_fifo() const throw() {
00266     return Is_fifo_mess(service());
00267   }
00268 
00270   void set_reliable() throw() {
00271     set_service(Reliable);
00272   }
00273 
00278   bool is_reliable() const throw() {
00279     return Is_reliable_mess(service());
00280   }
00281 
00283   void set_unreliable() throw() {
00284     set_service(Unreliable);
00285   }
00286 
00291   bool is_unreliable() const throw() {
00292     return Is_unreliable_mess(service());
00293   }
00294 
00296   void set_safe() throw() {
00297     set_service(Safe);
00298   }
00299 
00304   bool is_safe() const throw() {
00305     return Is_safe_mess(service());
00306   }
00307 
00315   void set_self_discard(const bool discard = true) throw() {
00316     _service_type |= SelfDiscard;
00317     if(!discard)
00318       _service_type ^= SelfDiscard;
00319   }
00320 
00327   bool is_self_discard() const throw() {
00328     return Is_self_discard(service());
00329   }
00330 
00336   bool is_regular() const throw() {
00337     return Is_regular_mess(service());
00338   }
00339 
00344   bool is_membership() const throw() {
00345     return Is_membership_mess(service());
00346   }
00347 };
00348 
00349 __END_NS_SAVA_SPREAD
00350 
00351 #endif

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