Savarese Software Research Corporation
Protocols.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2009 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  *     https://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_WSPR_PROTOCOL_PROTOCOLS_H
00023 #define __SSRC_WSPR_PROTOCOL_PROTOCOLS_H
00024 
00025 #include <ssrc/wispers-packages.h>
00026 #include <ssrc/wisp/protocol.h>
00027 
00028 __BEGIN_NS_SSRC_WSPR
00029 
00030 using NS_SSRC_WISP::ByteBuffer;
00031 using NS_SSRC_WISP::Packer;
00032 using NS_SSRC_WISP::Unpacker;
00033 using NS_SSRC_WISP::PackingTraits;
00034 using NS_SSRC_WISP::BinaryPackingTraits;
00035 
00036 __END_NS_SSRC_WSPR
00037 
00038 __BEGIN_NS_SSRC_WSPR_PROTOCOL
00039 
00040 enum MessageProtocol {
00041   // Wispers Standard Services (Reserved 0-1023)
00042   Unspecified = 0,
00043   Service     = 1,
00044   Registry    = 2,
00045   Log         = 3,
00046   Session     = 4,
00047   Renderer    = 5,
00048   Relay       = 6,
00049   WebService  = 7,
00050   GroupSession = 8,
00051   Login       = 9,
00052   Talk        = 10,
00053   Documents   = 11,
00054   Preferences = 12,
00055   Forum       = 13,
00056   Issues      = 14,
00057   Wiki        = 15,
00058   Blog        = 16,
00059   Notify      = 17,
00060   SiteSearch  = 18,
00061   Subscribe   = 19,
00062   TextShards  = 20,
00063   SimpleFS    = 21,
00064   MaxReserved = 1023
00065 };
00066 
00067 template<NS_SSRC_WISP_PROTOCOL::wisp_message_protocol protocol_>
00068 std::string service_type();
00069 
00070 template<NS_SSRC_WISP_PROTOCOL::wisp_message_protocol protocol_,
00071          typename PT = BinaryPackingTraits>
00072 struct ServiceProtocol :
00073   public NS_SSRC_WISP_PROTOCOL::ServiceProtocol<protocol_, PT>
00074 {
00075   static std::string service_type() {
00076     return NS_SSRC_WSPR_PROTOCOL::service_type<protocol_>();
00077   }
00078 
00079   static std::string service_group() {
00080     return service_type();
00081   }
00082 };
00083 
00084 #define WSPR_SERVICE_TYPE(service_base) "wspr.srv." #service_base
00085 #define WSPR_EVENT_GROUP(service_base, event) \
00086   "wspr.evt." service_base "." event
00087 
00088 #define WSPR_DEFINE_PROTOCOL(protocol_base, service_base) \
00089   template<> inline std::string service_type<protocol_base>() { \
00090     return WSPR_SERVICE_TYPE(service_base); \
00091   } \
00092   inline std::string service_type_ ## service_base () {  \
00093     return WSPR_SERVICE_TYPE(service_base); \
00094   } \
00095   template<NS_SSRC_WISP_PROTOCOL::wisp_message_id _id> \
00096   struct Message ## protocol_base : public NS_SSRC_WISP_UTILITY::wisp_struct { \
00097     static_assert(NS_SSRC_WSPR_PROTOCOL::protocol_base >= 0 &&         \
00098                   NS_SSRC_WSPR_PROTOCOL::protocol_base <= NS_SSRC_WSPR_PROTOCOL::MaxReserved, \
00099                   "protocol number out of range");                    \
00100     enum { protocol = NS_SSRC_WSPR_PROTOCOL::protocol_base };         \
00101     enum { id = _id }; \
00102     template<class Archive> \
00103     void serialize(Archive & ar, const unsigned int) { } \
00104   }
00105 
00106 #define WSPR_SERVICE_CUSTOM_TYPE(service_base) "wspr.cust." #service_base
00107 
00108 #define WSPR_DEFINE_CUSTOM_PROTOCOL(protocol_base, service_base) \
00109   inline std::string service_type_ ## service_base () {  \
00110     return WSPR_SERVICE_CUSTOM_TYPE(service_base); \
00111   } \
00112   template<NS_SSRC_WISP_PROTOCOL::wisp_message_id _id>    \
00113   struct Message ## protocol_base : public NS_SSRC_WISP_UTILITY::wisp_struct { \
00114     static_assert(static_cast<int>(protocol_base) > NS_SSRC_WSPR_PROTOCOL::MaxReserved, "protocol number out of range"); \
00115     enum { protocol = protocol_base }; \
00116     enum { id = _id }; \
00117     template<class Archive> \
00118     void serialize(Archive & ar, const unsigned int) { } \
00119   }
00120 
00125 inline std::string service_type_unknown() {
00126   return WSPR_SERVICE_TYPE(unknown);
00127 }
00128 
00129 __END_NS_SSRC_WSPR_PROTOCOL
00130 
00131 #endif

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