Ssrc C++ Binding for Spread 1.0.15 Unit Test Coverage
Current view: top level - ssrc/spread - Error.h (source / functions) Hit Total Coverage
Test: Ssrc C++/Lua/Perl/Python/Ruby Bindings for Spread 1.0.15 Unit Tests Lines: 0 7 0.0 %
Date: 2017-11-28 00:28:17 Functions: 0 3 0.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       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                 :            : 
      16                 :            : /**
      17                 :            :  * @file
      18                 :            :  * This header defines the Error class.
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifndef __SSRC_SPREAD_ERROR_H
      22                 :            : #define __SSRC_SPREAD_ERROR_H
      23                 :            : 
      24                 :            : #include <ssrc/libssrcspread-packages.h>
      25                 :            : 
      26                 :            : // sp.h includes stddef.h, so we need to include it before sp.h in
      27                 :            : // order to ensure it gets skipped while inside the Spread namespace.
      28                 :            : #include <cstddef>
      29                 :            : 
      30                 :            : __BEGIN_NS_SPREAD_INCLUDE
      31                 :            : # include <sp.h>
      32                 :            : __END_NS_SPREAD_INCLUDE
      33                 :            : 
      34                 :            : __BEGIN_NS_SSRC_SPREAD
      35                 :            : 
      36                 :            : /**
      37                 :            :  * Error is a container for a %Spread error code and is thrown
      38                 :            :  * by the library in only truly exceptional circumstances.
      39                 :            :  */
      40                 :            : class Error {
      41                 :            :   const int _error;
      42                 :            : 
      43                 :            : public:
      44                 :            : 
      45                 :            :   /**
      46                 :            :    * Code is not a proper enumeration, but rather a specification of
      47                 :            :    * constants corresponding to %Spread return and error codes.  We do
      48                 :            :    * not document the meaning of these codes.  See the %Spread C API
      49                 :            :    * documentation to understand their meaning.
      50                 :            :    */
      51                 :            :   enum Code {
      52                 :            :     AcceptSession     = ACCEPT_SESSION,
      53                 :            :     IllegalSpread     = ILLEGAL_SPREAD,
      54                 :            :     CouldNotConnect   = COULD_NOT_CONNECT,
      55                 :            :     RejectQuota       = REJECT_QUOTA,
      56                 :            :     RejectNoName      = REJECT_NO_NAME,
      57                 :            :     RejectIllegalName = REJECT_ILLEGAL_NAME,
      58                 :            :     RejectNotUnique   = REJECT_NOT_UNIQUE,
      59                 :            :     RejectVersion     = REJECT_VERSION,
      60                 :            :     ConnectionClosed  = CONNECTION_CLOSED,
      61                 :            :     RejectAuth        = REJECT_AUTH,
      62                 :            :     IllegalSession    = ILLEGAL_SESSION,
      63                 :            :     IllegalService    = ILLEGAL_SERVICE,
      64                 :            :     IllegalMessage    = ILLEGAL_MESSAGE,
      65                 :            :     IllegalGroup      = ILLEGAL_GROUP,
      66                 :            :     BufferTooShort    = BUFFER_TOO_SHORT,
      67                 :            :     GroupsTooShort    = GROUPS_TOO_SHORT,
      68                 :            :     MessageTooLong    = MESSAGE_TOO_LONG
      69                 :            : #if (LIBSSRCSPREAD_SPREAD_MAJOR_VERSION >= 4)
      70                 :            :     , NetErrorOnSession = NET_ERROR_ON_SESSION
      71                 :            : #endif
      72                 :            : #if (LIBSSRCSPREAD_SPREAD_MAJOR_VERSION >= 5)
      73                 :            :     , IllegalTime = ILLEGAL_TIME
      74                 :            : #endif
      75                 :            :   };
      76                 :            : 
      77                 :            :   /**
      78                 :            :    * Creates an Error instance containing the spcified error code.
      79                 :            :    * @param err The %Spread error code.
      80                 :            :    */
      81                 :          0 :   explicit Error(const int err) : _error(err) { }
      82                 :            : 
      83                 :            :   /**
      84                 :            :    * Returns the error code used to create the Error.
      85                 :            :    * @return The error code used to create the Error.
      86                 :            :    */
      87                 :            :   int error() const {
      88                 :            :     return _error;
      89                 :            :   }
      90                 :            : 
      91                 :            :   /**
      92                 :            :    * Prints the message corresponding to the error via SP_error.  We'd
      93                 :            :    * like to give you the message as a string, but the documented
      94                 :            :    * %Spread C API does not provide such a facility.
      95                 :            :    */
      96                 :          0 :   void print() const {
      97                 :          0 :     Spread::SP_error(_error);
      98                 :          0 :   }
      99                 :            : };
     100                 :            : 
     101                 :            : 
     102                 :            : /**
     103                 :            :  * BufferSizeError is a container for a BufferTooShort or
     104                 :            :  * GroupTooShort errror, reporting the buffer size required for
     105                 :            :  * success.  Only in a rare circumstance will this error be thrown by
     106                 :            :  * the library.  In every expected situation the library handles the
     107                 :            :  * error itself by automatically resizing buffers and reattempting the
     108                 :            :  * operation or by truncating the buffer if so-specified by the user.
     109                 :            :  */
     110                 :            : class BufferSizeError : public Error {
     111                 :            :   const unsigned int _size;
     112                 :            : 
     113                 :            : public:
     114                 :            : 
     115                 :            :   /**
     116                 :            :    * Creates a BufferSizeError instance with the specified error code and
     117                 :            :    * required buffer size.
     118                 :            :    * @param err The %Spread error code.
     119                 :            :    * @param size The required buffer size for a successful retry.
     120                 :            :    */
     121                 :          0 :   BufferSizeError(const int err, const unsigned int size) :
     122                 :          0 :     Error(err), _size(size)
     123                 :          0 :   { }
     124                 :            : 
     125                 :            :   /**
     126                 :            :    * Returns the required buffer size for a successful retry.
     127                 :            :    * @return The required buffer size for a successful retry.
     128                 :            :    */
     129                 :            :   unsigned int size() const {
     130                 :            :     return _size;
     131                 :            :   }
     132                 :            : };
     133                 :            : 
     134                 :            : __END_NS_SSRC_SPREAD
     135                 :            : 
     136                 :            : #endif