Ssrc C++ Binding for Spread 1.0.15 Unit Test Coverage
Current view: top level - ssrc/spread - Message.h (source / functions) Hit Total Coverage
Test: Ssrc C++/Lua/Perl/Python/Ruby Bindings for Spread 1.0.15 Unit Tests Lines: 15 15 100.0 %
Date: 2017-11-28 00:28:17 Functions: 8 8 100.0 %
Branches: 1 2 50.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  *
       3                 :            :  * Copyright 2006 Savarese Software Research Corporation
       4                 :            :  *
       5                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
       6                 :            :  * you may not use this file except in compliance with the License.
       7                 :            :  * You may obtain a copy of the License at
       8                 :            :  *
       9                 :            :  *     http://www.savarese.com/software/ApacheLicense-2.0
      10                 :            :  *
      11                 :            :  * Unless required by applicable law or agreed to in writing, software
      12                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      13                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14                 :            :  * See the License for the specific language governing permissions and
      15                 :            :  * limitations under the License.
      16                 :            :  */
      17                 :            : 
      18                 :            : /**
      19                 :            :  * @file
      20                 :            :  * This header defines the Message class.
      21                 :            :  */
      22                 :            : 
      23                 :            : #ifndef __SSRC_SPREAD_MESSAGE_H
      24                 :            : #define __SSRC_SPREAD_MESSAGE_H
      25                 :            : 
      26                 :            : #include <ssrc/spread/detail/ByteBuffer.h>
      27                 :            : #include <ssrc/spread/MembershipInfo.h>
      28                 :            : 
      29                 :            : __BEGIN_NS_SSRC_SPREAD
      30                 :            : 
      31                 :            : /**
      32                 :            :  * Message is a reusable and resizable data buffer for sending and
      33                 :            :  * receiving messages.  We do not document its protected members
      34                 :            :  * because they are intended only for internal library use.  All of
      35                 :            :  * its useful public methods are inherited from BaseMessage and
      36                 :            :  * detail::ByteBuffer.
      37                 :            :  *
      38                 :            :  * Please note that you can directly access the message data via
      39                 :            :  * indexing with detail::Buffer::operator[] or obtaining a pointer
      40                 :            :  * to the data via:
      41                 :            :  * <pre>&message[0]</pre>
      42                 :            :  * Therefore, you will find you do not have to use detail::ByteBuffer::read
      43                 :            :  * unless you really have to make a copy of the data instead of using
      44                 :            :  * it directly.  However, you should use detail::ByteBuffer::write to avoid
      45                 :            :  * overrunning the buffer.
      46                 :            :  */
      47                 :         38 : class Message : public BaseMessage, public detail::ByteBuffer {
      48                 :            : protected:
      49                 :            : 
      50                 :            : #ifdef LIBSSRCSPREAD_ENABLE_MEMBERSHIP_INFO
      51                 :            : 
      52                 :          3 :   virtual int sp_get_membership_info(Spread::membership_info *info) const {
      53                 :          3 :     return Spread::SP_get_memb_info(&(this->operator[](0)), service(), info);
      54                 :            :   }
      55                 :            : 
      56                 :          3 :   virtual int sp_get_vs_set_members(const Spread::vs_set_info *vs_set,
      57                 :            :                                     Spread::group_type member_names[],
      58                 :            :                                     unsigned int member_names_count)
      59                 :            :     const
      60                 :            :   {
      61                 :            :     return
      62                 :          3 :       Spread::SP_get_vs_set_members(&(this->operator[](0)),
      63                 :          3 :                                     vs_set, member_names, member_names_count);
      64                 :            :   }
      65                 :            : 
      66                 :          2 :   virtual int sp_get_vs_sets_info(Spread::vs_set_info *vs_sets,
      67                 :            :                                   unsigned int num_vs_sets,
      68                 :            :                                   unsigned int *index)
      69                 :            :     const
      70                 :            :   {
      71                 :            :     return
      72                 :          2 :       Spread::SP_get_vs_sets_info(&(this->operator[](0)),
      73                 :          2 :                                   vs_sets, num_vs_sets, index);
      74                 :            :   }
      75                 :            : 
      76                 :            : #endif
      77                 :            : 
      78                 :            : public:
      79                 :            : 
      80                 :            :   enum {
      81                 :            :     /** The default capacity used to construct a Message. */
      82                 :            :     DefaultCapacity = 4096
      83                 :            :   };
      84                 :            : 
      85                 :            :   /**
      86                 :            :    * Creates a Message with the specified initial capacity (or
      87                 :            :    * DefaultCapacity if no parameter is provided).  See BaseMessage()
      88                 :            :    * for the default values of various properties, including service
      89                 :            :    * type.
      90                 :            :    *
      91                 :            :    * @param capacity The initial capacity of the message.
      92                 :            :    */
      93                 :         23 :   explicit Message(const unsigned int capacity = DefaultCapacity) :
      94         [ +  - ]:         23 :     detail::ByteBuffer(capacity) { }
      95                 :            : 
      96                 :         86 :   virtual unsigned int size() const {
      97                 :         86 :     return detail::ByteBuffer::size();
      98                 :            :   }
      99                 :            : 
     100                 :          6 :   virtual void clear() {
     101                 :          6 :     return detail::ByteBuffer::clear();
     102                 :            :   }
     103                 :            : 
     104                 :            : };
     105                 :            : 
     106                 :            : __END_NS_SSRC_SPREAD
     107                 :            : 
     108                 :            : #endif