Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - ssrc/wispers/protocol - Protocols.h (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 6 6 100.0 %
Date: 2012-04-09 Functions: 6 6 100.0 %
Branches: 1 2 50.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright 2006-2009 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                 :            :  *     https://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                 :            : 
      17                 :            : /**
      18                 :            :  * @file
      19                 :            :  * This header defines the WSPR protocol framework.
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef __SSRC_WSPR_PROTOCOL_PROTOCOLS_H
      23                 :            : #define __SSRC_WSPR_PROTOCOL_PROTOCOLS_H
      24                 :            : 
      25                 :            : #include <ssrc/wispers-packages.h>
      26                 :            : #include <ssrc/wisp/protocol.h>
      27                 :            : 
      28                 :            : __BEGIN_NS_SSRC_WSPR
      29                 :            : 
      30                 :            : using NS_SSRC_WISP::ByteBuffer;
      31                 :            : using NS_SSRC_WISP::Packer;
      32                 :            : using NS_SSRC_WISP::Unpacker;
      33                 :            : using NS_SSRC_WISP::PackingTraits;
      34                 :            : using NS_SSRC_WISP::BinaryPackingTraits;
      35                 :            : 
      36                 :            : __END_NS_SSRC_WSPR
      37                 :            : 
      38                 :            : __BEGIN_NS_SSRC_WSPR_PROTOCOL
      39                 :            : 
      40                 :            : enum MessageProtocol {
      41                 :            :   // Wispers Standard Services (Reserved 0-1023)
      42                 :            :   Unspecified = 0,
      43                 :            :   Service     = 1,
      44                 :            :   Registry    = 2,
      45                 :            :   Log         = 3,
      46                 :            :   Session     = 4,
      47                 :            :   Renderer    = 5,
      48                 :            :   Relay       = 6,
      49                 :            :   WebService  = 7,
      50                 :            :   GroupSession = 8,
      51                 :            :   Login       = 9,
      52                 :            :   Talk        = 10,
      53                 :            :   Documents   = 11,
      54                 :            :   Preferences = 12,
      55                 :            :   Forum       = 13,
      56                 :            :   Issues      = 14,
      57                 :            :   Wiki        = 15,
      58                 :            :   Blog        = 16,
      59                 :            :   Notify      = 17,
      60                 :            :   SiteSearch  = 18,
      61                 :            :   Subscribe   = 19,
      62                 :            :   TextShards  = 20,
      63                 :            :   SimpleFS    = 21,
      64                 :            :   MaxReserved = 1023
      65                 :            : };
      66                 :            : 
      67                 :            : template<NS_SSRC_WISP_PROTOCOL::wisp_message_protocol protocol_>
      68                 :            : std::string service_type();
      69                 :            : 
      70                 :            : template<NS_SSRC_WISP_PROTOCOL::wisp_message_protocol protocol_,
      71                 :            :          typename PT = BinaryPackingTraits>
      72                 :            : struct ServiceProtocol :
      73                 :            :   public NS_SSRC_WISP_PROTOCOL::ServiceProtocol<protocol_, PT>
      74                 :            : {
      75                 :         52 :   static std::string service_type() {
      76                 :         52 :     return NS_SSRC_WSPR_PROTOCOL::service_type<protocol_>();
      77                 :            :   }
      78                 :            : 
      79                 :         46 :   static std::string service_group() {
      80                 :         46 :     return service_type();
      81                 :            :   }
      82                 :            : };
      83                 :            : 
      84                 :            : #define WSPR_SERVICE_TYPE(service_base) "wspr.srv." #service_base
      85                 :            : #define WSPR_EVENT_GROUP(service_base, event) \
      86                 :            :   "wspr.evt." service_base "." event
      87                 :            : 
      88                 :            : #define WSPR_DEFINE_PROTOCOL(protocol_base, service_base) \
      89                 :            :   template<> inline std::string service_type<protocol_base>() { \
      90                 :            :     return WSPR_SERVICE_TYPE(service_base); \
      91                 :            :   } \
      92                 :            :   inline std::string service_type_ ## service_base () {  \
      93                 :            :     return WSPR_SERVICE_TYPE(service_base); \
      94                 :            :   } \
      95                 :            :   template<NS_SSRC_WISP_PROTOCOL::wisp_message_id _id> \
      96                 :            :   struct Message ## protocol_base : public NS_SSRC_WISP_UTILITY::wisp_struct { \
      97                 :            :     static_assert(NS_SSRC_WSPR_PROTOCOL::protocol_base >= 0 &&         \
      98                 :            :                   NS_SSRC_WSPR_PROTOCOL::protocol_base <= NS_SSRC_WSPR_PROTOCOL::MaxReserved, \
      99                 :            :                   "protocol number out of range");                    \
     100                 :            :     enum { protocol = NS_SSRC_WSPR_PROTOCOL::protocol_base };         \
     101                 :            :     enum { id = _id }; \
     102                 :            :     template<class Archive> \
     103                 :            :     void serialize(Archive & ar, const unsigned int) { } \
     104                 :            :   }
     105                 :            : 
     106                 :            : #define WSPR_SERVICE_CUSTOM_TYPE(service_base) "wspr.cust." #service_base
     107                 :            : 
     108                 :            : #define WSPR_DEFINE_CUSTOM_PROTOCOL(protocol_base, service_base) \
     109                 :            :   inline std::string service_type_ ## service_base () {  \
     110                 :            :     return WSPR_SERVICE_CUSTOM_TYPE(service_base); \
     111                 :            :   } \
     112                 :            :   template<NS_SSRC_WISP_PROTOCOL::wisp_message_id _id>    \
     113                 :            :   struct Message ## protocol_base : public NS_SSRC_WISP_UTILITY::wisp_struct { \
     114                 :            :     static_assert(static_cast<int>(protocol_base) > NS_SSRC_WSPR_PROTOCOL::MaxReserved, "protocol number out of range"); \
     115                 :            :     enum { protocol = protocol_base }; \
     116                 :            :     enum { id = _id }; \
     117                 :            :     template<class Archive> \
     118                 :            :     void serialize(Archive & ar, const unsigned int) { } \
     119                 :            :   }
     120                 :            : 
     121                 :            : /**
     122                 :            :  * Returns a string identifying an unnkown service type.
     123                 :            :  * @return A string identifying an unnkown service type.
     124                 :            :  */
     125                 :         14 : inline std::string service_type_unknown() {
     126         [ +  - ]:         14 :   return WSPR_SERVICE_TYPE(unknown);
     127                 :            : }
     128                 :            : 
     129                 :            : __END_NS_SSRC_WSPR_PROTOCOL
     130                 :            : 
     131                 :            : #endif