From: Reinhard Pfau Date: Tue, 21 Oct 2008 12:46:58 +0000 (+0000) Subject: libasyncio: (reinhard) moved some stuff into a separate utils module. Building RPMs... X-Git-Tag: v0.3~89 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=aba4c34d56e1c270663b4166c7ea7e8f23f06b74;p=libasyncio libasyncio: (reinhard) moved some stuff into a separate utils module. Building RPMs now works. --- diff --git a/AUTHORS b/AUTHORS index abc505d..4f722c1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1 +1,6 @@ -Reinhard Pfau +Authors of libasyncio: +====================== + +Reinhard Pfau + + diff --git a/Makefile.am b/Makefile.am index 5ac978e..112f367 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ AUTOMAKE_OPTIONS = foreign -SUBDIRS = asyncio glue_t2n unittest doc +SUBDIRS = utils asyncio glue_t2n unittest doc EXTRA_DIST+= LICENSE diff --git a/README b/README index e69de29..aa28536 100644 --- a/README +++ b/README @@ -0,0 +1,38 @@ +libasyncio +=========== + +a library providing an infrastructure for dealing with asnychronous +io and support event driven programming. + +The basic idea for this lib is to provide classes which hide the details +of polling/selecting for events on file descriptors and provide a more +convenient interface which supports the idea of event driven programming. + + +The library was originally developed by Intra2net as part of the +Intranator connection daemon which is part of the Intranator (see http://www.intranator.com/). +During development it was extracted as a separate module. +And then we decide to publish it under The GNU Lesser Public License (LGPL). + + + +The libasyncio provides: + +- basic class for handling reading from and writing to fd's +- filter plugin support for incoming/outgoing data. +- timer events +- deferred function calls; "frozen" function calls +- start and handle subprocesses (connecting to their stdin/stdout/stderr) +- unix domain socket handling +- event signals (using boost-signal lib) +- ... and some more stuff. + + +It depend on the boost library (see http://www.boost.org/). + + +Links: +====== + +the boost library: http://www.boost.org/ +Intra2net: http://www.intra2net.com/ diff --git a/TODO b/TODO index e69de29..66aa10c 100644 --- a/TODO +++ b/TODO @@ -0,0 +1,6 @@ +TODO list +========== + +optimize, consolidate, beautify (a never ending task :-) ) + + diff --git a/asyncio/Makefile.am b/asyncio/Makefile.am index 4e25b19..eadb89d 100644 --- a/asyncio/Makefile.am +++ b/asyncio/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = @LIBI2NCOMMON_CFLAGS@ @BOOST_CPPFLAGS@ +INCLUDES = -I$(top_srcdir)/utils @BOOST_CPPFLAGS@ @LIBI2NCOMMON_CFLAGS@ METASOURCES = AUTO lib_LTLIBRARIES = libasyncio.la libasyncio_la_SOURCES = async_callout.cpp async_io.cpp async_pipe.cpp \ @@ -9,5 +9,12 @@ libasyncio_la_LIBADD = @LIBI2NCOMMON_LIBS@ @BOOST_LDFLAGS@ @BOOST_SIGNALS_LIB@ libasyncio_la_LDFLAGS = -version-info @LIBASYNCIO_LIB_VERSION@ -pkgconfigdir=$(libdir)/pkgconfig +pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA= libasyncio.pc + +$(top_srcdir)/headerlist.asyncio: $(include_HEADERS) + list='$(include_HEADERS)'; \ + ( for n in $$list; do echo $(includedir)/$$n ; done) > $@ + +.PHONY: headerlist +headerlist: $(top_srcdir)/headerlist.asyncio diff --git a/asyncio/async_io.cpp b/asyncio/async_io.cpp index 28f7b77..95d916b 100644 --- a/asyncio/async_io.cpp +++ b/asyncio/async_io.cpp @@ -43,9 +43,11 @@ #define ODOUT(msg) do {} while (0) #endif + namespace { +using namespace AsyncIo::Utils; /* * configuration: @@ -121,95 +123,11 @@ struct PollDataCluster }; // eo struct PollDataCluster -template -class PtrList : public std::list -{ - typedef std::list inherited; - public: - bool dirty; - - static int Instances; - - public: - - PtrList() - : dirty(false) - { - ++Instances; - } // eo PtrList - - - ~PtrList() - { - ODOUT(""); - --Instances; - } - - - /** - * add a new item pointer to the list. - * - * @param item item pointer which should be added - */ - void add_item(T* item) - { - typename inherited::iterator it= std::find(inherited::begin(), inherited::end(), item); - if (it != inherited::end()) - { - // nothing to do since item is already in the list - return; - } - push_back(item); - } // eo add - - - /** - * remove an item pointer from the list by setting NULL at the current position of the item and mark - * the list as dirty. - * - * @param item the io object which should be removed from the list. - */ - void remove_item(T* item) - { - typename inherited::iterator it= std::find(inherited::begin(), inherited::end(), item); - if (it == inherited::end()) - { - // nothing to do: - return; - } - *it = NULL; // forget the pointer - dirty= true; // ..and mark the list as dirty (i.e. has NULL elements) - } // eo remove - - - /** - * cleans the list of objects by removing the NULL elements (if any). - * - * @note this function should only be called when it is ensured that no other functions using iterators of this list. - */ - void clean_list() - { - if (!dirty) - { - // nothing to do - return; - } - // remove the NULL elements now: - erase( - std::remove( inherited::begin(), inherited::end(), (T*)NULL), - inherited::end() ); - dirty= false; - } // eo clean_list - - -}; // eo class PtrList - - -typedef PtrList IOList; -typedef PtrList TimerList; +typedef PtrList< AsyncIo::IOImplementation, true > IOList; +typedef PtrList< AsyncIo::TimerBase, true > TimerList; -template<> int IOList::Instances= 0; -template<> int TimerList::Instances= 0; +template<> int IOList::GlobalCountType::InstanceCount= 0; +template<> int TimerList::GlobalCountType::InstanceCount= 0; /** @@ -329,35 +247,6 @@ struct FilterMatch { }; // eo struct FilterMatch -void get_current_real_time(long& current_sec, long& current_msec) -{ - struct timeval tv; - gettimeofday(&tv,NULL); - current_sec= tv.tv_sec; - current_msec= (tv.tv_usec / 1000); - if (current_msec >= 1000) - { - current_sec += (current_msec / 1000); - current_msec%= 1000; - } -} // eo get_current_real_time - - -void get_current_monotonic_time(long& current_sec, long& current_msec) -{ - long nsec; - if (monotonic_clock_gettime(current_sec,nsec)) - { - current_msec= nsec / 1000000L; - } - else - { - //fallback... - get_current_real_time(current_sec,current_msec); - } -} // eo get_current_monotonic_time - - } // eo anonymous namespace @@ -368,118 +257,6 @@ namespace AsyncIo { -/** - * @brief gets the current time as MilliTime structure. - * @param[out] mt reference to the MilliTime strcucture which is filled with the result. - */ -void get_current_real_time(MilliTime& mt) -{ - long sec, msec; - ::get_current_real_time(sec,msec); - mt.set(sec,msec); -} // eo get_current_real_time - - -/** - * @brief gets the current time as MilliTime structure. - * @param[out] mt reference to the MilliTime strcucture which is filled with the result. - */ -void get_current_monotonic_time(MilliTime& mt) -{ - long sec, msec; - ::get_current_monotonic_time(sec,msec); - mt.set(sec,msec); -} // eo get_current_monotonic_time - - -/* - * implementation of MilliTime - */ - -MilliTime::MilliTime(long sec, long msec) -: mt_sec(sec), mt_msec(msec) -{ - normalize(); -} // eo MilliTime::MilliTime - - -void MilliTime::set(long sec, long msec) -{ - mt_sec= sec; - mt_msec= msec; - normalize(); -} // eo MilliTime::set - - -/** - * normalizes the values, so that mt_msec has a value between 0 and 999. - */ -void MilliTime::normalize() -{ - if (mt_msec < 0) - { - mt_sec += (mt_msec / 1000) - 1; - mt_msec = (mt_msec % 1000) + 1000; - } - else if (mt_msec>=1000) - { - mt_sec+= (mt_msec / 1000); - mt_msec %= 1000; - } -} // eo MilliTime::normalize - - -/** - * determine if the represented point in time is before another one. - * @param other the other point in time. - * @return true if the own point in time is before the other one. - */ -bool MilliTime::operator < (MilliTime& other) -{ - normalize(); - other.normalize(); - return - (mt_sec < other.mt_sec) - || (( mt_sec == other.mt_sec) && (mt_msec < other.mt_msec)); -} // eo MilliTime::operator < - - -/** - * determine if two point in times are equal. - * @param other the point in time to compare with. - * @return true if the represented times are equal. - */ -bool MilliTime::operator == (MilliTime& other) -{ - normalize(); - other.normalize(); - return (( mt_sec == other.mt_sec) && (mt_msec == other.mt_msec)); -} // eo MilliTime::operator < - -/** - * @brief subtracts a time delta from the object. - * @param lhs the time delta to subtract. - * @return reference to the object itself. - */ -MilliTime& MilliTime::operator -= (const MilliTime& lhs) -{ - mt_sec -= lhs.mt_sec; - mt_msec -= lhs.mt_msec; -} // eo operator -= - - -/** - * @brief adds a time delta from the object. - * @param lhs the time delta to add. - * @return reference to the object itself. - */ -MilliTime& MilliTime::operator += (const MilliTime& lhs) -{ - mt_sec += lhs.mt_sec; - mt_msec += lhs.mt_msec; -} // eo operator += - - /* * implementation of TimerBase */ @@ -501,7 +278,7 @@ TimerBase::TimerBase() TimerBase::~TimerBase() { ODOUT("enter"); - if (internal_io::TimerList::Instances) + if (internal_io::TimerList::Instances()) { ODOUT("remove from list"); internal_io::g_timer_list().remove_item(this); @@ -704,7 +481,7 @@ IOImplementation::IOImplementation(int read_fd, int write_fd) IOImplementation::~IOImplementation() { close(); - if (internal_io::IOList::Instances) + if (internal_io::IOList::Instances()) { internal_io::g_io_list().remove_item(this); } diff --git a/asyncio/async_io.hpp b/asyncio/async_io.hpp index fb2278f..f86f7b5 100644 --- a/asyncio/async_io.hpp +++ b/asyncio/async_io.hpp @@ -18,6 +18,8 @@ #include #include +#include + #include #include @@ -28,7 +30,7 @@ namespace AsyncIo { using namespace I2n; - +using Utils::MilliTime; /* * forward declarations @@ -60,53 +62,6 @@ struct Direction }; // eo struct IODirection; -/** - * structure for storing (a point in time as) seconds and milliseconds. - */ -struct MilliTime -{ - long mt_sec; - long mt_msec; - - MilliTime(long sec=0, long msec=0); - - void set(long sec, long msec=0); - - inline long long get_milliseconds() const - { - return ((long long)mt_sec * 1000L + mt_msec); - } // eo get_milliseconds - - void normalize(); - - bool operator < (MilliTime& other); - bool operator == (MilliTime& other); - - MilliTime& operator -= (const MilliTime& lhs); - MilliTime& operator += (const MilliTime& lhs); - -}; // eo struct MilliTime - - -inline MilliTime operator + (const MilliTime& rhs, const MilliTime& lhs) -{ - MilliTime t(rhs); - return t+= lhs; -} // eo operator + (const MilliTime& rhs, const MilliTime lhs) - -inline MilliTime operator - (const MilliTime& rhs, const MilliTime& lhs) -{ - MilliTime t(rhs); - return t-= lhs; -} // eo operator - (const MilliTime& rhs, const MilliTime lhs) - - -inline bool operator <= (MilliTime& rhs, MilliTime& lhs) -{ - return (rhs #include @@ -23,6 +23,7 @@ namespace AsyncIo { +using namespace Utils; namespace { diff --git a/glue_t2n/async_io_t2n.hpp b/glue_t2n/asyncio_t2n.hpp similarity index 100% rename from glue_t2n/async_io_t2n.hpp rename to glue_t2n/asyncio_t2n.hpp diff --git a/templates/cpp b/templates/cpp index e89ea90..1e7c72f 100644 --- a/templates/cpp +++ b/templates/cpp @@ -5,7 +5,7 @@ * @author Reinhard Pfau \ * * @copyright © Copyright 2008 Intra2Net AG - * @license commercial + * @license LGPL * @contact info@intra2net.com * */ diff --git a/templates/hpp b/templates/hpp index e89ea90..6b422d3 100644 --- a/templates/hpp +++ b/templates/hpp @@ -5,7 +5,7 @@ * @author Reinhard Pfau \ * * @copyright © Copyright 2008 Intra2Net AG - * @license commercial + * @license LPGL * @contact info@intra2net.com * */ diff --git a/unittest/Makefile.am b/unittest/Makefile.am index 9466d50..00320f0 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -1,9 +1,9 @@ -INCLUDES = -I$(top_srcdir)/. -I$(top_srcdir)/common -I$(top_srcdir)/connd \ - -I$(top_srcdir)/simpleio @BOOST_CPPFLAGS@ @CPPUNIT_CFLAGS@ @LIBI2NCOMMON_CFLAGS@ +INCLUDES = -I$(top_srcdir)/. -I$(top_srcdir)/asyncio -I$(top_srcdir)/utils \ + @BOOST_CPPFLAGS@ @CPPUNIT_CFLAGS@ @LIBI2NCOMMON_CFLAGS@ METASOURCES = AUTO check_PROGRAMS = testsimpleio testsimpleio_SOURCES = test.cpp test_simpleio_basics.cpp -testsimpleio_LDADD = $(top_builddir)/simpleio/libsimpleio.la @BOOST_LDFLAGS@ \ - @BOOST_SIGNALS_LIB@ @CPPUNIT_LIBS@ @LIBI2NCOMMON_LIBS@ +testsimpleio_LDADD = $(top_builddir)/utils/libasyncio_utils.la \ + $(top_builddir)/asyncio/libasyncio.la @BOOST_LDFLAGS@ @BOOST_SIGNALS_LIB@ @CPPUNIT_LIBS@ @LIBI2NCOMMON_LIBS@ TESTS = testsimpleio diff --git a/unittest/test_simpleio_basics.cpp b/unittest/test_simpleio_basics.cpp index b791e33..5abc582 100644 --- a/unittest/test_simpleio_basics.cpp +++ b/unittest/test_simpleio_basics.cpp @@ -37,7 +37,7 @@ using namespace I2n; -using namespace I2n::AsyncIo; +using namespace AsyncIo; using namespace CppUnit; diff --git a/utils/Makefile.am b/utils/Makefile.am new file mode 100644 index 0000000..f0e9e6a --- /dev/null +++ b/utils/Makefile.am @@ -0,0 +1,18 @@ +INCLUDES = @BOOST_CPPFLAGS@ +METASOURCES = AUTO +lib_LTLIBRARIES = libasyncio_utils.la +include_HEADERS = asyncio_ptr_list.hpp asyncio_utils.hpp asyncio_time_tools.hpp +libasyncio_utils_la_SOURCES = asyncio_time_tools.cpp asyncio_utils.cpp + +libasyncio_utils_la_LDFLAGS = -version-info @LIBASYNCIO_LIB_VERSION@ + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA= libasyncio_utils.pc + + +$(top_srcdir)/headerlist.utils: $(include_HEADERS) + list='$(include_HEADERS)'; \ + ( for n in $$list; do echo $(includedir)/$$n ; done) > $@ + +.PHONY: headerlist +headerlist: $(top_srcdir)/headerlist.utils diff --git a/utils/asyncio_ptr_list.hpp b/utils/asyncio_ptr_list.hpp new file mode 100644 index 0000000..1a36483 --- /dev/null +++ b/utils/asyncio_ptr_list.hpp @@ -0,0 +1,221 @@ +/** + * @file + * @brief a pointer list + * + * provides a pointer list which is prepared for being used in nested + * iterator loops. + * + * @author Reinhard Pfau \ + * + * @copyright © Copyright 2008 Intra2Net AG + * @license LGPL + * @contact info@intra2net.com + * + */ + +#ifndef __ASYNCIO__PTR_LIST_HPP__ +#define __ASYNCIO__PTR_LIST_HPP__ + +#include +#include + + +namespace AsyncIo +{ +namespace Utils +{ + + +/** + * @brief provides a global instance counter. + * + * The global instance counter must be initialized by the module which uses it. + * The main purpose for this is to keep track of the instances when PtrList's are + * used as global objects. + */ +template< class T, bool globalcounted > +class GlobalCounted +{ + static int InstanceCount; + + public: + + GlobalCounted() + { + ++InstanceCount; + } // eo GlobalCounted + + + virtual ~GlobalCounted() + { + --InstanceCount; + } // eo ~GlobalCounted + + static int Instances() + { + return InstanceCount; + } +}; // eo GlobalCounted + + +template<> +class GlobalCounted< class T, false > +{ + public: + GlobalCounted() + { + } // eo GlobalCounted + + + virtual ~GlobalCounted() + { + } // eo ~GlobalCounted + +}; // eo GlobalCounted + + + +/** + * @brief pointer list which supports deletion by set to NULL. + * + * This list can be used in nested iterator loops as long as some conditions + * are fulfilled: + * - inside the loops each iterator value is tested for not get NULL. + * - cleaning the list is only allowed when the outmost loop exits. + * . + * + * + * @tparam T type of the pointers. + * @tparam globalcounted determine if a global instance counter should be included. + */ +template +class PtrList +: public GlobalCounted< PtrList< T, globalcounted >, globalcounted > +, protected std::list +{ + typedef std::list inherited; + + public: + typedef GlobalCounted< PtrList< T, globalcounted >, globalcounted > GlobalCountType; + + typedef typename inherited::iterator iterator; + typedef typename inherited::const_iterator const_iterator; + + public: + + PtrList() + : Dirty(false) + { + } // eo PtrList + + + ~PtrList() + { + } // eo ~PtrList + + + /** + * @brief add a new item pointer to the list. + * + * @param item item pointer which should be added + */ + void add_item(T* item) + { + typename inherited::iterator it= std::find(inherited::begin(), inherited::end(), item); + if (it != inherited::end()) + { + // nothing to do since item is already in the list + return; + } + push_back(item); + } // eo add + + + /** + * @brief remove an item pointer from the list by setting to NULL. + * + * This sets the pointer in the list to NULL and marks the list as dirty. + * + * @param item the io object which should be removed from the list. + */ + void remove_item(T* item) + { + typename inherited::iterator it= std::find(inherited::begin(), inherited::end(), item); + if (it == inherited::end()) + { + // nothing to do: + return; + } + *it = NULL; // forget the pointer + Dirty= true; // ..and mark the list as dirty (i.e. has NULL elements) + } // eo remove + + + /** + * @brief cleans the list of objects by removing the NULL elements (if any). + * + * @note this function should only be called when it is ensured that no + * other functions using iterators of this list. + */ + void clean_list() + { + if (!Dirty) + { + // nothing to do + return; + } + // remove the NULL elements now: + erase( + std::remove( inherited::begin(), inherited::end(), (T*)NULL), + inherited::end() ); + Dirty= false; + } // eo clean_list + + + /** + * @brief explicit set the list dirty. + * + * use this to mark the list as dirty, when an item is set to NULL via + * a non const iterator. + * + * @note This is really dirty; better use remove_item(T*) in that cases! + */ + void set_dirty() + { + Dirty= true; + } // eo set_dirty + + + iterator begin() + { + return inherited::begin(); + } + + + iterator end() + { + return inherited::end(); + } + + + const_iterator begin() const + { + return inherited::begin(); + } + + + const_iterator end() const + { + return inherited::end(); + } + + protected: + bool Dirty; + +}; // eo class PtrList + + +} // eo namespace Utils +} // eo namespace AsyncIo + +#endif diff --git a/utils/asyncio_time_tools.cpp b/utils/asyncio_time_tools.cpp new file mode 100644 index 0000000..a89a24c --- /dev/null +++ b/utils/asyncio_time_tools.cpp @@ -0,0 +1,214 @@ +/** + * @file + * @brief + * + * @author Reinhard Pfau \ + * + * @copyright © Copyright 2008 Intra2Net AG + * @license LGPL + * @contact info@intra2net.com + * + */ + +#include "asyncio_time_tools.hpp" + +#include +#include +#include +#include + + +// define missing POSIX.1b constants... + +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 0 +#endif +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC 1 +#endif + +namespace AsyncIo +{ +namespace Utils +{ + + +namespace +{ + + +/** + * @brief fetches the value from the monotonic clock source. + * @param[out] seconds the seconds. + * @param[out] nano_seconds the nano seconds. + * @return @a true if the clock was successfully read. + */ +bool monotonic_clock_gettime(long int& seconds, long int& nano_seconds) +{ + struct timespec tp[1]; + int res= ::syscall(__NR_clock_gettime, CLOCK_MONOTONIC, tp); + if (0 == res) + { + seconds= tp->tv_sec; + nano_seconds= tp->tv_nsec; + } + return (res==0); +} // eo monotonic_clock_gettime(long int&,long int&) + + + + +void get_current_real_time(long& current_sec, long& current_msec) +{ + struct timeval tv; + gettimeofday(&tv,NULL); + current_sec= tv.tv_sec; + current_msec= (tv.tv_usec / 1000); + if (current_msec >= 1000) + { + current_sec += (current_msec / 1000); + current_msec%= 1000; + } +} // eo get_current_real_time + + +void get_current_monotonic_time(long& current_sec, long& current_msec) +{ + long nsec; + if (monotonic_clock_gettime(current_sec,nsec)) + { + current_msec= nsec / 1000000L; + } + else + { + //fallback... + get_current_real_time(current_sec,current_msec); + } +} // eo get_current_monotonic_time + + + +} // eo anonymous namespace + +/**************************************************************************\ +\**************************************************************************/ + + +/* + * implementation of MilliTime + */ + +MilliTime::MilliTime(long sec, long msec) +: mt_sec(sec), mt_msec(msec) +{ + normalize(); +} // eo MilliTime::MilliTime + + +void MilliTime::set(long sec, long msec) +{ + mt_sec= sec; + mt_msec= msec; + normalize(); +} // eo MilliTime::set + + +/** + * normalizes the values, so that mt_msec has a value between 0 and 999. + */ +void MilliTime::normalize() +{ + if (mt_msec < 0) + { + mt_sec += (mt_msec / 1000) - 1; + mt_msec = (mt_msec % 1000) + 1000; + } + else if (mt_msec>=1000) + { + mt_sec+= (mt_msec / 1000); + mt_msec %= 1000; + } +} // eo MilliTime::normalize + + +/** + * determine if the represented point in time is before another one. + * @param other the other point in time. + * @return true if the own point in time is before the other one. + */ +bool MilliTime::operator < (MilliTime& other) +{ + normalize(); + other.normalize(); + return + (mt_sec < other.mt_sec) + || (( mt_sec == other.mt_sec) && (mt_msec < other.mt_msec)); +} // eo MilliTime::operator < + + +/** + * determine if two point in times are equal. + * @param other the point in time to compare with. + * @return true if the represented times are equal. + */ +bool MilliTime::operator == (MilliTime& other) +{ + normalize(); + other.normalize(); + return (( mt_sec == other.mt_sec) && (mt_msec == other.mt_msec)); +} // eo MilliTime::operator < + +/** + * @brief subtracts a time delta from the object. + * @param lhs the time delta to subtract. + * @return reference to the object itself. + */ +MilliTime& MilliTime::operator -= (const MilliTime& lhs) +{ + mt_sec -= lhs.mt_sec; + mt_msec -= lhs.mt_msec; +} // eo operator -= + + +/** + * @brief adds a time delta from the object. + * @param lhs the time delta to add. + * @return reference to the object itself. + */ +MilliTime& MilliTime::operator += (const MilliTime& lhs) +{ + mt_sec += lhs.mt_sec; + mt_msec += lhs.mt_msec; +} // eo operator += + + + +/** + * @brief gets the current time as MilliTime structure. + * @param[out] mt reference to the MilliTime strcucture which is filled with the result. + */ +void get_current_real_time(MilliTime& mt) +{ + long sec, msec; + get_current_real_time(sec,msec); + mt.set(sec,msec); +} // eo get_current_real_time + + +/** + * @brief gets the current time as MilliTime structure. + * @param[out] mt reference to the MilliTime strcucture which is filled with the result. + */ +void get_current_monotonic_time(MilliTime& mt) +{ + long sec, msec; + get_current_monotonic_time(sec,msec); + mt.set(sec,msec); +} // eo get_current_monotonic_time + + + + + +} // eo namespace Utils +} // eo namespace AsyncIo diff --git a/utils/asyncio_time_tools.hpp b/utils/asyncio_time_tools.hpp new file mode 100644 index 0000000..38cab2b --- /dev/null +++ b/utils/asyncio_time_tools.hpp @@ -0,0 +1,83 @@ +/** + * @file + * @brief + * + * @author Reinhard Pfau \ + * + * @copyright © Copyright 2008 Intra2Net AG + * @license LPGL + * @contact info@intra2net.com + * + */ + +#ifndef __ASYNCIO__TIME_TOOLS_HPP__ +#define __ASYNCIO__TIME_TOOLS_HPP__ + +namespace AsyncIo +{ +namespace Utils +{ + +/** + * @brief structure for storing (a point in time as) seconds and milliseconds. + */ +struct MilliTime +{ + long mt_sec; + long mt_msec; + + MilliTime(long sec=0, long msec=0); + + void set(long sec, long msec=0); + + inline long long get_milliseconds() const + { + return ((long long)mt_sec * 1000L + mt_msec); + } // eo get_milliseconds + + void normalize(); + + bool operator < (MilliTime& other); + bool operator == (MilliTime& other); + + MilliTime& operator -= (const MilliTime& lhs); + MilliTime& operator += (const MilliTime& lhs); + +}; // eo struct MilliTime + + +inline MilliTime operator + (const MilliTime& rhs, const MilliTime& lhs) +{ + MilliTime t(rhs); + return t+= lhs; +} // eo operator + (const MilliTime& rhs, const MilliTime lhs) + +inline MilliTime operator - (const MilliTime& rhs, const MilliTime& lhs) +{ + MilliTime t(rhs); + return t-= lhs; +} // eo operator - (const MilliTime& rhs, const MilliTime lhs) + + +inline bool operator <= (MilliTime& rhs, MilliTime& lhs) +{ + return (rhs + * + * @copyright © Copyright 2008 Intra2Net AG + * @license LGPL + * @contact info@intra2net.com + * + */ + +namespace AsyncIo +{ +namespace Utils +{ + + + +} // eo namespace Utils +} // eo namespace AsyncIo diff --git a/utils/asyncio_utils.hpp b/utils/asyncio_utils.hpp new file mode 100644 index 0000000..a8e0e93 --- /dev/null +++ b/utils/asyncio_utils.hpp @@ -0,0 +1,15 @@ +/** + * @file + * @brief convenience file for including all util header at once. + * + * @author Reinhard Pfau \ + * + * @copyright © Copyright 2008 Intra2Net AG + * @license LPGL + * @contact info@intra2net.com + * + */ + + +#include "asyncio_ptr_list.hpp" +#include "asyncio_time_tools.hpp" diff --git a/utils/libasyncio_utils.pc.in b/utils/libasyncio_utils.pc.in new file mode 100644 index 0000000..7954ef6 --- /dev/null +++ b/utils/libasyncio_utils.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libasyncio_utils +Description: utils for the asynchrounous io lib +Version: @VERSION@ +Libs: -L${libdir} -lasyncio_utils +Cflags: -I${includedir}