LCOV - code coverage report
Current view: top level - cc - session.h (source / functions) Hit Total Coverage
Test: report.info Lines: 7 7 100.0 %
Date: 2012-05-15 Functions: 3 7 42.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 6 50.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2009  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #ifndef _ISC_SESSION_H
      16                 :            : #define _ISC_SESSION_H 1
      17                 :            : 
      18                 :            : #include <string>
      19                 :            : 
      20                 :            : #include <boost/function.hpp>
      21                 :            : 
      22                 :            : #include <exceptions/exceptions.h>
      23                 :            : 
      24                 :            : #include <cc/data.h>
      25                 :            : #include <cc/session_config.h>
      26                 :            : 
      27                 :            : namespace asio {
      28                 :            : class io_service;
      29                 :            : }
      30                 :            : 
      31                 :            : namespace isc {
      32                 :            :     namespace cc {
      33                 :            :         class SessionImpl;
      34                 :            : 
      35                 :          5 :         class SessionError : public isc::Exception {
      36                 :            :         public:
      37                 :          2 :             SessionError(const char* file, size_t line, const char* what) :
      38 [ +  - ][ +  - ]:          5 :                 isc::Exception(file, line, what) {}
      39                 :            :         };
      40                 :            : 
      41                 :            :         /// \brief A standard Exception class that is thrown when a
      42                 :            :         /// blocking readData call does not read the given number of
      43                 :            :         /// bytes before the timeout expires
      44                 :          3 :         class SessionTimeout : public isc::Exception {
      45                 :            :         public:
      46                 :            :             SessionTimeout(const char* file, size_t line, const char* what) :
      47         [ +  - ]:          3 :                 isc::Exception(file, line, what) {}
      48                 :            :         };
      49                 :            : 
      50                 :            :         /// \brief The AbstractSession class is an abstract base class that
      51                 :            :         /// defines the interfaces of Session.
      52                 :            :         /// The intended primary usage of abstraction is to allow tests for the
      53                 :            :         /// user class of Session without requiring actual communication
      54                 :            :         /// channels.
      55                 :            :         /// For simplicity we only define the methods that are necessary for
      56                 :            :         /// existing test cases that use this base class.  Eventually we'll
      57                 :            :         /// probably have to extend them.
      58                 :            :         class AbstractSession {
      59                 :            :             ///
      60                 :            :             /// \name Constructors, Assignment Operator and Destructor.
      61                 :            :             ///
      62                 :            :             /// Note: The copy constructor and the assignment operator are
      63                 :            :             /// intentionally defined as private to make it explicit that
      64                 :            :             /// this is a pure base class.
      65                 :            :             //@{
      66                 :            :         private:
      67                 :            :             AbstractSession(const AbstractSession& source);
      68                 :            :             AbstractSession& operator=(const AbstractSession& source);
      69                 :            :         protected:
      70                 :            :             /// \brief The default constructor.
      71                 :            :             ///
      72                 :            :             /// This is intentionally defined as \c protected as this base
      73                 :            :             /// class should never be instantiated (except as part of a
      74                 :            :             /// derived class).
      75                 :        189 :             AbstractSession() {}
      76                 :            :         public:
      77                 :            :             /// \brief The destructor.
      78                 :        189 :             virtual ~AbstractSession() {}
      79                 :            :             //@}
      80                 :            :             virtual void establish(const char* socket_file) = 0;
      81                 :            :             virtual void disconnect() = 0;
      82                 :            :             virtual int group_sendmsg(isc::data::ConstElementPtr msg,
      83                 :            :                                       std::string group,
      84                 :            :                                       std::string instance = "*",
      85                 :            :                                       std::string to = "*") = 0;
      86                 :            :             virtual bool group_recvmsg(isc::data::ConstElementPtr& envelope,
      87                 :            :                                        isc::data::ConstElementPtr& msg,
      88                 :            :                                        bool nonblock = true,
      89                 :            :                                        int seq = -1) = 0;
      90                 :            :             virtual void subscribe(std::string group,
      91                 :            :                                    std::string instance = "*") = 0;
      92                 :            :             virtual void unsubscribe(std::string group,
      93                 :            :                              std::string instance = "*") = 0;
      94                 :            :             virtual void startRead(boost::function<void()> read_callback) = 0;
      95                 :            :             virtual int reply(isc::data::ConstElementPtr envelope,
      96                 :            :                                isc::data::ConstElementPtr newmsg) = 0;
      97                 :            :             virtual bool hasQueuedMsgs() const = 0;
      98                 :            : 
      99                 :            :             /// \brief Sets the default timeout for blocking reads
     100                 :            :             ///        in this session to the given number of milliseconds
     101                 :            :             /// \param milliseconds the timeout for blocking reads in
     102                 :            :             ///        milliseconds; if this is set to 0, reads will block
     103                 :            :             ///        forever.
     104                 :            :             virtual void setTimeout(size_t milliseconds) = 0;
     105                 :            : 
     106                 :            :             /// \brief Returns the current timeout for blocking reads
     107                 :            :             /// \return The timeout (in milliseconds)
     108                 :            :             virtual size_t getTimeout() const = 0;
     109                 :            :         };
     110                 :            : 
     111                 :            :     class Session : public AbstractSession {
     112                 :            :         private:
     113                 :            :             SessionImpl* impl_;
     114                 :            : 
     115                 :            :         private:
     116                 :            :             Session(const Session& source);
     117                 :            :             Session& operator=(const Session& source);
     118                 :            : 
     119                 :            :         public:
     120                 :            :             Session(asio::io_service& ioservice);
     121                 :            :             virtual ~Session();
     122                 :            : 
     123                 :            :             virtual void startRead(boost::function<void()> read_callback);
     124                 :            : 
     125                 :            :             virtual void establish(const char* socket_file = NULL);
     126                 :            :             virtual void disconnect();
     127                 :            :             virtual void subscribe(std::string group,
     128                 :            :                                    std::string instance = "*");
     129                 :            :             virtual void unsubscribe(std::string group,
     130                 :            :                              std::string instance = "*");
     131                 :            :             virtual int group_sendmsg(isc::data::ConstElementPtr msg,
     132                 :            :                                       std::string group,
     133                 :            :                                       std::string instance = "*",
     134                 :            :                                       std::string to = "*");
     135                 :            :             virtual bool group_recvmsg(isc::data::ConstElementPtr& envelope,
     136                 :            :                                        isc::data::ConstElementPtr& msg,
     137                 :            :                                        bool nonblock = true,
     138                 :            :                                        int seq = -1);
     139                 :            :             virtual int reply(isc::data::ConstElementPtr envelope,
     140                 :            :                               isc::data::ConstElementPtr newmsg);
     141                 :            :             virtual bool hasQueuedMsgs() const;
     142                 :            :             virtual void setTimeout(size_t milliseconds);
     143                 :            :             virtual size_t getTimeout() const;
     144                 :            :     private:
     145                 :            :             void sendmsg(isc::data::ConstElementPtr msg);
     146                 :            :             void sendmsg(isc::data::ConstElementPtr env,
     147                 :            :                          isc::data::ConstElementPtr msg);
     148                 :            :             bool recvmsg(isc::data::ConstElementPtr& msg,
     149                 :            :                          bool nonblock = true,
     150                 :            :                          int seq = -1);
     151                 :            :             bool recvmsg(isc::data::ConstElementPtr& env,
     152                 :            :                          isc::data::ConstElementPtr& msg,
     153                 :            :                          bool nonblock = true,
     154                 :            :                          int seq = -1);
     155                 :            :         };
     156                 :            :     } // namespace cc
     157                 :            : } // namespace isc
     158                 :            : 
     159                 :            : #endif // _ISC_SESSION_H
     160                 :            : 
     161                 :            : // Local Variables:
     162                 :            : // mode: c++
     163                 :            : // End:

Generated by: LCOV version 1.9