LCOV - code coverage report
Current view: top level - eventdispatcher - timer.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 10 10.0 %
Date: 2019-08-08 02:52:36 Functions: 2 5 40.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2012-2019  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // This program is free software; you can redistribute it and/or modify
       4             : // it under the terms of the GNU General Public License as published by
       5             : // the Free Software Foundation; either version 2 of the License, or
       6             : // (at your option) any later version.
       7             : //
       8             : // This program is distributed in the hope that it will be useful,
       9             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      10             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      11             : // GNU General Public License for more details.
      12             : //
      13             : // You should have received a copy of the GNU General Public License
      14             : // along with this program; if not, write to the Free Software
      15             : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
      16             : 
      17             : /** \file
      18             :  * \brief Implementation of the Timer class.
      19             :  *
      20             :  * This class allows you to create a "connection" which is just a timer.
      21             :  *
      22             :  * All connections have a timer feature, but at times you have to either
      23             :  * disable a connection or you already use the timer for some other
      24             :  * reasons so we offer a separate timer class for you additional needs.
      25             :  */
      26             : 
      27             : 
      28             : // self
      29             : //
      30             : #include "eventdispatcher/timer.h"
      31             : 
      32             : #include "eventdispatcher/utils.h"
      33             : 
      34             : 
      35             : // last include
      36             : //
      37             : #include <snapdev/poison.h>
      38             : 
      39             : 
      40             : 
      41             : 
      42             : namespace ed
      43             : {
      44             : 
      45             : 
      46             : 
      47             : /** \brief Initializes the timer object.
      48             :  *
      49             :  * This function initializes the timer object with the specified \p timeout
      50             :  * defined in microseconds.
      51             :  *
      52             :  * Note that by default all snap_connection objects are marked as persistent
      53             :  * since in most cases that is the type of connections you are interested
      54             :  * in. Therefore timers are also marked as persistent. This means if you
      55             :  * want a one time callback, you want to call the remove_connection()
      56             :  * function with your timer from your callback.
      57             :  *
      58             :  * \note
      59             :  * POSIX offers timers (in Linux since kernel version 2.6), only
      60             :  * (a) these generate signals, which is generally considered slow
      61             :  * in comparison to a timeout assigned to the poll() function, and
      62             :  * (b) the kernel posts at most one timer signal at a time across
      63             :  * one process, in other words, if 5 timers time out before you are
      64             :  * given a chance to process the timer, you only get one single
      65             :  * signal.
      66             :  *
      67             :  * \param[in] communicator  The snap communicator controlling this connection.
      68             :  * \param[in] timeout_us  The timeout in microseconds.
      69             :  */
      70           0 : timer::timer(std::int64_t timeout_us)
      71             : {
      72           0 :     if(timeout_us == 0)
      73             :     {
      74             :         // if zero, we assume that the timeout is a one time trigger
      75             :         // and that it will be set to other dates at other later times
      76             :         //
      77           0 :         set_timeout_date(get_current_date());
      78             :     }
      79             :     else
      80             :     {
      81           0 :         set_timeout_delay(timeout_us);
      82             :     }
      83           0 : }
      84             : 
      85             : 
      86             : /** \brief Retrieve the socket of the timer object.
      87             : *
      88             : * Timer objects are never attached to a socket so this function always
      89             :  * returns -1.
      90             :  *
      91             :  * \note
      92             :  * You should not override this function since there is not other
      93             :  * value it can return.
      94             :  *
      95             :  * \return Always -1.
      96             :  */
      97           0 : int timer::get_socket() const
      98             : {
      99           0 :     return -1;
     100             : }
     101             : 
     102             : 
     103             : /** \brief Tell that the socket is always valid.
     104             :  *
     105             :  * This function always returns true since the timer never uses a socket.
     106             :  *
     107             :  * \return Always true.
     108             :  */
     109           0 : bool timer::valid_socket() const
     110             : {
     111           0 :     return true;
     112             : }
     113             : 
     114             : 
     115             : 
     116           6 : } // namespace ed
     117             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.12