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

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2011  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 __ASIOLINK_SIMPLE_CALLBACK_H
      16                 :            : #define __ASIOLINK_SIMPLE_CALLBACK_H 1
      17                 :            : 
      18                 :            : #include <asiolink/io_message.h>
      19                 :            : 
      20                 :            : namespace isc {
      21                 :            : namespace asiolink {
      22                 :            : 
      23                 :            : /// \brief The \c SimpleCallback class is an abstract base class for a
      24                 :            : /// simple callback function with the signature:
      25                 :            : ///
      26                 :            : /// void simpleCallback(const IOMessage& io_message) const;
      27                 :            : ///
      28                 :            : /// Specific derived class implementations are hidden within the
      29                 :            : /// implementation.  Instances of the derived classes can be called
      30                 :            : /// as functions via the operator() interface.  Pointers to these
      31                 :            : /// instances can then be provided to the \c IOService class
      32                 :            : /// via its constructor.
      33                 :            : ///
      34                 :            : /// The \c SimpleCallback is expected to be used for basic, generic
      35                 :            : /// tasks such as checking for configuration changes.  It may also be
      36                 :            : /// used for testing purposes.
      37                 :            : class SimpleCallback {
      38                 :            :     ///
      39                 :            :     /// \name Constructors and Destructor
      40                 :            :     ///
      41                 :            :     /// Note: The copy constructor and the assignment operator are
      42                 :            :     /// intentionally defined as private, making this class non-copyable.
      43                 :            :     //@{
      44                 :            : private:
      45                 :            :     SimpleCallback(const SimpleCallback& source);
      46                 :            :     SimpleCallback& operator=(const SimpleCallback& source);
      47                 :            : protected:
      48                 :            :     /// \brief The default constructor.
      49                 :            :     ///
      50                 :            :     /// This is intentionally defined as \c protected as this base class
      51                 :            :     /// should never be instantiated (except as part of a derived class).
      52                 :        195 :     SimpleCallback() {
      53                 :        195 :         self_ = this;
      54                 :            :     }
      55                 :            : public:
      56                 :            :     /// \brief The destructor
      57                 :        195 :     virtual ~SimpleCallback() {}
      58                 :            :     /// \brief The function operator
      59                 :            :     //@}
      60                 :            :     ///
      61                 :            :     /// This makes its call indirectly via the "self" pointer, ensuring
      62                 :            :     /// that the function ultimately invoked will be the one in the derived
      63                 :            :     /// class.
      64                 :            :     ///
      65                 :            :     /// \param io_message The event message to handle
      66                 :          0 :     virtual void operator()(const IOMessage& io_message) const {
      67                 :          0 :         (*self_)(io_message);
      68                 :          0 :     }
      69                 :            : private:
      70                 :            :     SimpleCallback* self_;
      71                 :            : };
      72                 :            : 
      73                 :            : } // namespace asiolink
      74                 :            : } // namespace isc
      75                 :            : #endif // __ASIOLINK_SIMPLE_CALLBACK_H

Generated by: LCOV version 1.9