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