00001 /*************************************************************************** 00002 * Copyright (C) 2007,2008,2009 by Rick L. Vinyard, Jr. * 00003 * rvinyard@cs.nmsu.edu * 00004 * * 00005 * This file is part of the dbus-cxx library. * 00006 * * 00007 * The dbus-cxx library is free software; you can redistribute it and/or * 00008 * modify it under the terms of the GNU General Public License * 00009 * version 3 as published by the Free Software Foundation. * 00010 * * 00011 * The dbus-cxx library is distributed in the hope that it will be * 00012 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * 00013 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this software. If not see <http://www.gnu.org/licenses/>. * 00018 ***************************************************************************/ 00019 #ifndef DBUSTIMEOUT_H 00020 #define DBUSTIMEOUT_H 00021 00022 #include <dbus/dbus.h> 00023 #include <sys/time.h> 00024 #include <sys/signal.h> 00025 #include <dbus-cxx/pointer.h> 00026 00027 namespace DBus 00028 { 00029 00040 class Timeout 00041 { 00042 protected: 00043 Timeout( DBusTimeout* cobj=NULL ); 00044 00045 public: 00046 00047 typedef DBusCxxPointer<Timeout> pointer; 00048 typedef DBusCxxWeakPointer<Timeout> weak_pointer; 00049 00050 static pointer create( DBusTimeout* cobj=NULL ); 00051 00052 ~Timeout(); 00053 00054 bool is_valid() const; 00055 00056 operator bool() const; 00057 00058 int interval() const; 00059 00060 bool is_enabled() const; 00061 00062 bool handle(); 00063 00064 bool operator==(const Timeout& other) const; 00065 00066 bool operator!=(const Timeout& other) const; 00067 00068 void arm(bool should_arm=true); 00069 00070 bool is_armed(); 00071 00072 DBusTimeout* cobj(); 00073 00074 operator DBusTimeout*(); 00075 00076 protected: 00077 DBusTimeout* m_cobj; 00078 00079 timer_t m_timer_id; 00080 00081 bool m_is_armed; 00082 00083 pthread_mutex_t m_arming_mutex; 00084 00085 static void timer_callback_proxy( sigval_t sv ); 00086 00087 }; 00088 00089 } 00090 00091 #endif