diff --git a/doc/doxygen.conf b/doc/doxygen.conf index 347af2ef86bf4786d49b13d48c12146b0d001b01..3090f72ee4651a4edae8e411cce9aae7c5c66526 100644 --- a/doc/doxygen.conf +++ b/doc/doxygen.conf @@ -7,27 +7,26 @@ # Project related configuration options #--------------------------------------------------------------------------- DOXYFILE_ENCODING = UTF-8 -PROJECT_NUMBER = +PROJECT_NUMBER = OUTPUT_DIRECTORY = ../doc CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English BRIEF_MEMBER_DESC = YES REPEAT_BRIEF = NO -ABBREVIATE_BRIEF = +ABBREVIATE_BRIEF = ALWAYS_DETAILED_SEC = NO INLINE_INHERITED_MEMB = NO FULL_PATH_NAMES = YES -STRIP_FROM_PATH = -STRIP_FROM_INC_PATH = +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = SHORT_NAMES = NO JAVADOC_AUTOBRIEF = NO QT_AUTOBRIEF = NO MULTILINE_CPP_IS_BRIEF = NO -DETAILS_AT_TOP = NO INHERIT_DOCS = YES SEPARATE_MEMBER_PAGES = NO TAB_SIZE = 8 -ALIASES = +ALIASES = OPTIMIZE_OUTPUT_FOR_C = YES OPTIMIZE_OUTPUT_JAVA = NO OPTIMIZE_FOR_FORTRAN = NO @@ -64,11 +63,11 @@ GENERATE_TODOLIST = YES GENERATE_TESTLIST = YES GENERATE_BUGLIST = YES GENERATE_DEPRECATEDLIST= YES -ENABLED_SECTIONS = +ENABLED_SECTIONS = MAX_INITIALIZER_LINES = 30 SHOW_USED_FILES = YES SHOW_DIRECTORIES = YES -FILE_VERSION_FILTER = +FILE_VERSION_FILTER = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- @@ -78,7 +77,7 @@ WARN_IF_UNDOCUMENTED = YES WARN_IF_DOC_ERROR = YES WARN_NO_PARAMDOC = NO WARN_FORMAT = "$file:$line: $text" -WARN_LOGFILE = +WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- @@ -89,7 +88,7 @@ FILE_PATTERNS = *.c \ *.h \ *.cpp RECURSIVE = YES -EXCLUDE = +EXCLUDE = EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = *.tab.c \ *.tab.h \ @@ -99,13 +98,13 @@ EXCLUDE_PATTERNS = *.tab.c \ *glr.c \ *llr.c \ *general.h -EXCLUDE_SYMBOLS = +EXCLUDE_SYMBOLS = EXAMPLE_PATH = ../src/examples -EXAMPLE_PATTERNS = +EXAMPLE_PATTERNS = EXAMPLE_RECURSIVE = NO IMAGE_PATH = ../doc/images -INPUT_FILTER = -FILTER_PATTERNS = +INPUT_FILTER = +FILTER_PATTERNS = FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- # configuration options related to source browsing @@ -123,24 +122,24 @@ VERBATIM_HEADERS = YES #--------------------------------------------------------------------------- ALPHABETICAL_INDEX = YES COLS_IN_ALPHA_INDEX = 5 -IGNORE_PREFIX = +IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- GENERATE_HTML = YES HTML_OUTPUT = html HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = -HTML_STYLESHEET = +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = HTML_ALIGN_MEMBERS = YES GENERATE_HTMLHELP = NO GENERATE_DOCSET = NO DOCSET_FEEDNAME = "Doxygen generated docs" DOCSET_BUNDLE_ID = org.doxygen.Project HTML_DYNAMIC_SECTIONS = NO -CHM_FILE = -HHC_LOCATION = +CHM_FILE = +HHC_LOCATION = GENERATE_CHI = NO BINARY_TOC = NO TOC_EXPAND = NO @@ -157,8 +156,8 @@ LATEX_CMD_NAME = latex MAKEINDEX_CMD_NAME = makeindex COMPACT_LATEX = NO PAPER_TYPE = a4 -EXTRA_PACKAGES = -LATEX_HEADER = +EXTRA_PACKAGES = +LATEX_HEADER = PDF_HYPERLINKS = YES USE_PDFLATEX = NO LATEX_BATCHMODE = NO @@ -170,8 +169,8 @@ GENERATE_RTF = NO RTF_OUTPUT = rtf COMPACT_RTF = NO RTF_HYPERLINKS = NO -RTF_STYLESHEET_FILE = -RTF_EXTENSIONS_FILE = +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- @@ -184,8 +183,8 @@ MAN_LINKS = NO #--------------------------------------------------------------------------- GENERATE_XML = NO XML_OUTPUT = xml -XML_SCHEMA = -XML_DTD = +XML_SCHEMA = +XML_DTD = XML_PROGRAMLISTING = YES #--------------------------------------------------------------------------- # configuration options for the AutoGen Definitions output @@ -197,32 +196,32 @@ GENERATE_AUTOGEN_DEF = NO GENERATE_PERLMOD = NO PERLMOD_LATEX = NO PERLMOD_PRETTY = YES -PERLMOD_MAKEVAR_PREFIX = +PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- -# Configuration options related to the preprocessor +# Configuration options related to the preprocessor #--------------------------------------------------------------------------- ENABLE_PREPROCESSING = YES MACRO_EXPANSION = NO EXPAND_ONLY_PREDEF = NO SEARCH_INCLUDES = YES -INCLUDE_PATH = -INCLUDE_FILE_PATTERNS = +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = PREDEFINED = _USE_MPI=1 -EXPAND_AS_DEFINED = +EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- -# Configuration::additions related to external references +# Configuration::additions related to external references #--------------------------------------------------------------------------- -TAGFILES = -GENERATE_TAGFILE = +TAGFILES = +GENERATE_TAGFILE = ALLEXTERNALS = NO EXTERNAL_GROUPS = YES PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- -# Configuration options related to the dot tool +# Configuration options related to the dot tool #--------------------------------------------------------------------------- CLASS_DIAGRAMS = YES -MSCGEN_PATH = +MSCGEN_PATH = HIDE_UNDOC_RELATIONS = YES HAVE_DOT = YES CLASS_GRAPH = YES @@ -237,8 +236,8 @@ CALLER_GRAPH = YES GRAPHICAL_HIERARCHY = YES DIRECTORY_GRAPH = NO DOT_IMAGE_FORMAT = png -DOT_PATH = -DOTFILE_DIRS = +DOT_PATH = +DOTFILE_DIRS = DOT_GRAPH_MAX_NODES = 50 MAX_DOT_GRAPH_DEPTH = 2 DOT_TRANSPARENT = YES @@ -246,6 +245,6 @@ DOT_MULTI_TARGETS = NO GENERATE_LEGEND = YES DOT_CLEANUP = YES #--------------------------------------------------------------------------- -# Configuration::additions related to the search engine +# Configuration::additions related to the search engine #--------------------------------------------------------------------------- SEARCHENGINE = NO diff --git a/doc/main.dox b/doc/main.dox index 91e02bf1b48f10c08b2d0826d23c23f49429836a..d701a4b2bc72a91afadf67d7c0e1225f3f26e0c5 100644 --- a/doc/main.dox +++ b/doc/main.dox @@ -1,31 +1,31 @@ -/*! \mainpage General IRI utilities +/*! \mainpage General IRI utilities - \section Introduction + \section Introduction This set of tools provide basic functionalities that are generally needed in many applications. These utilities include mutual exclusion objects, exceptions, threads, logic events and also generic communication devices. Next, a brief description of each one is provided. - \subsection Mutex + \subsection Mutex Basic mutual exclusion object interface to handle multiple threads to access the - same shared resources. There exist no example of use of mutexes, but they are used + same shared resources. There exist no example of use of mutexes, but they are used in most of the other utilities, so check them for examples of use. \subsection Exceptions Generic exceptions to be used as a base for all other exceptions. It provides some - basic error message handling, and each inherited exception may add as much - information as needed. There is no examples of use of exceptions, but it is used + basic error message handling, and each inherited exception may add as much + information as needed. There is no examples of use of exceptions, but it is used in most of other utilities, so check them for examples of use. \subsection threads Threadserver and Threads This utility provides a simple and easy to use interface to threads, isolating the low level details from the end user. The threads may be used direcltly or else - through a thread server which allows to create and handle as many threads as - neceessary without direct access to the threads themselves. In this case, each + through a thread server which allows to create and handle as many threads as + neceessary without direct access to the threads themselves. In this case, each thread is assigned a unique identifier which is used to identify it in the server. @@ -36,10 +36,10 @@ \subsection events Eventserver and Events - This utility provides a simple and easy way to use asynchronous notifications + This utility provides a simple and easy way to use asynchronous notifications between threads, allowing them to wait on several heterogeneous conditions without wasting CPU time. The events may be used directly or else through an event server, - which allows to create and handle as many events as needed. In this case each event + which allows to create and handle as many events as needed. In this case each event is assigned a unique identifier which is used to identify it in the server. There exist examples of both events being used directly (test_events) and also @@ -48,24 +48,24 @@ events. There exist also an other example that uses both events and threads using their - servers (test_bothservers), which gives a good example on how to use them + servers (test_bothservers), which gives a good example on how to use them together. \subsection log Log - This utility provides a simple way to log information into files. Each object is - associated to single file, and all the logged messages include a time stamp of - the log time. + This utility provides a simple way to log information into files. Each object is + associated to single file, and all the logged messages include a time stamp of + the log time. \subsection time Time This utility provides a simple and easy way to use time. Each CTime object has - got a time and using the class members and operations it is possible to get - time in seconds, milliseconds or C/system types such as timespec, or time_t; - set a time, sum, difference or average times, do time comparisions or print + got a time and using the class members and operations it is possible to get + time in seconds, milliseconds or C/system types such as timespec, or time_t; + set a time, sum, difference or average times, do time comparisions or print time in human readable format. - There exist an example which uses all of class methods. Also in a bad use + There exist an example which uses all of class methods. Also in a bad use which reach to an exception. \section Installation @@ -74,9 +74,9 @@ This package requires of the following libraries and packages - <A href="http://www.cmake.org">cmake</A>, a cross-platform build system. - - <A href="http://www.doxygen.org">doxygen</a> and + - <A href="http://www.doxygen.org">doxygen</a> and <A href="http://www.graphviz.org">graphviz</a> to generate the documentation. - - stdc++, + - stdc++, - pthread, the POSIX thread library. . @@ -84,7 +84,7 @@ - sudo make dep . from the <em>build</em> folder and after calling the <em>cmake ..</em> command. - + Under linux all of these utilities are available in ready-to-use packages. Under MacOS most of the packages are available via <a href="http://www.finkproject.org/">fink</a>. <br> @@ -114,7 +114,7 @@ \subsection Configuration - The default build mode is DEBUG. That is, objects and executables + The default build mode is DEBUG. That is, objects and executables include debug information. The RELEASE build mode optimizes for speed. To build in this mode @@ -132,7 +132,7 @@ . as root and the shared libraries will be copied to <em>/usr/local/lib/iridrivers</em> directory - and the header files will be copied to <em>/usr/local/include/iridrivers</em> dierctory. At + and the header files will be copied to <em>/usr/local/include/iridrivers</em> dierctory. At this point, the library may be used by any user. To remove the library from the system, exceute @@ -154,7 +154,7 @@ Finally, it is also nevessary to link with the desired libraries by using the following command - - TARGET_LINK_LIBRARIES(<executable name> ${iriutils_LIBRARY}) + - TARGET_LINK_LIBRARIES(<executable name> ${iriutils_LIBRARY}) . All these steps are automatically done when the new project is created following the instructions @@ -162,7 +162,7 @@ \section License - This package is licensed under a + This package is licensed under a <a href="http://www.gnu.org/licenses/lgpl.html"> LGPL 3.0 License</a>. @@ -179,6 +179,6 @@ GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. + along with this program. If not, see <http://www.gnu.org/licenses/>. */ diff --git a/src/examples/test_time.cpp b/src/examples/test_time.cpp index a1d27b9849f53b9beac204d107e0e595c02b9a1a..1e640a96eda8d77a7dd626879982d921272f4e97 100644 --- a/src/examples/test_time.cpp +++ b/src/examples/test_time.cpp @@ -25,80 +25,108 @@ This example output will be something similar to this: \verbatim - TIME MANAGER EXAMPLE - Example: create times (t0,t1,t2) + TIME MANAGER EXAMPLE + Example: create times (t0,t1,t2) - t0: 1266942571 040254747 + t0: 1314886453.799155 - Example: sleep 300 ms + Example: sleep 300 ms - Example: set t1 [0.300r] + Example: set t1 (0.300 rel) - t1: 1266942571 340338484 - t1o: 0 300083737 + t1: 1314886454.099320 + t1o: 0.300164 - Example: set t3 delayed 300 ms [0.300a] + Example: set t3 delayed 200 ms (0.200 abs) - t3: 0 300000000 + t3: 0.200000 - Example: sleep 1705 ms + Example: sleep 1705 ms - Example: set t2 [2.005r] + Example: set t2 (2.005 rel) - t2: 1266942573 045406666 - t2o: 2 005151919 + t2: 1314886455.804489 + t2o: 2.005333 - Example: t2 - t1 [1.705] + Example: t2 - t1 (1.705) - td: 1 705068182 - tdo: 1 705068182 + td: 1.705169 + tdo: 1.705169 - Example: + addition (t1+t2) + Example: + addition (t1+t2) - ts: 2533885144 385745150 - tso: 2 305235656 + ts: 2629772909.903809 + tso: 2.305498 + ulongmax: 4294967295 - Example: + Exception (overvalue) + Example: + Exception (overvalue) -[Exception caught] - CTime CTime::operator+(CTime&) at time/CTime.cpp:129 -Error: [CTime class] - Result higher than ulong max + [Exception caught] - CTime CTime::operator+(CTime&) at /home/mmorta/codi/drivers/iriutils/trunk/src/time/ctime.cpp:195 + Error: [CTime class] - Result higher than ulong max - Example: average (t1,t2) + Example: average (t1,t2) - ta: 1266942572 192872524 - tao: 1 152617827 + ta: 1314886454.951905 + tao: 1.152749 - Example: comparative (t1==t2, t3==t2) + Example: comparative (t1==t2, t3==t2) ?: false true - Example: getting time (t1) + Example: comparative (t1<t2, t1<=t2, t3>t2, t3>=t2) + t1: 1314886454.099320 + t2: 1314886455.804489 + t3: 1314886455.804489 + ?: <: true <=: true + ?: >: false >=: true + + Example: getting time (t1/t0) + + seconds and nanoseconds: + 1314886454 99320101 + 0 300164204 double Seconds: - 1.26694e+09 - 0.3 + 1.31489e+09 + 0 double milliseconds: - 4.22219e+09 - 300 - Format 0: - 1266942571 340338484 - 0 300083737 + 6.26462e+08 + 300 + Format ctf_secnano: + 1314886454 099320101 + 0 300164204 Format ctf_datetime: - 2010-02-23,17:29:31 - 1970-01-01,01:00:00 + 2011-09-01,16:14:14 + 1970-01-01,01:00:00 Format ctf_ms: - 1266942571.340 - 0.300 + 1314886454.099 + 0.300 + Format ctf_us: + 1314886454.099320 + 0.300164 Timespec - 1266942571 340338484 + 1314886454 99320101 Time_t - 1266942571 - some formats using time_t - 2010-02-23,17:29:31 - 05:29PM - Tue Feb 23 17:29:31 2010 + 1314886454 + some formats using time_t + 2011-09-01,16:14:14 + 04:14PM + Thu Sep 1 16:14:14 2011 + + Example: Using Reference Time + + Set Reference and wait 1 second + + Time ref: 1314886455.805064 + t1: 1.000107 + t2: 1314886455.804489 + + Set useRef(true) for t2 and set its time + + t2: 1.000163 Is ref used?: true - Example: END + + Example: END \endverbatim @@ -127,24 +155,24 @@ int main(void) cout << "\n Example: sleep 300 ms " << endl; usleep(300000); - cout << "\n Example: set t1 [0.300r]\n\n"; + cout << "\n Example: set t1 (0.300 rel)\n\n"; t1.set(); CTime t10 = t1 - t0; cout << " t1: " << t1 << "\n t1o: " << t10 << endl; - cout << "\n Example: set t3 delayed 300 ms [0.300a]\n\n"; - t3.set(300); + cout << "\n Example: set t3 delayed 200 ms (0.200 abs)\n\n"; + t3.set(200); cout << " t3: " << t3 << endl; cout << "\n Example: sleep 1705 ms " << endl; usleep(1705000); - cout << "\n Example: set t2 [2.005r]\n\n"; + cout << "\n Example: set t2 (2.005 rel)\n\n"; t2.set(); t20 = t2 - t0; cout << " t2: " << t2 << "\n t2o: " << t20 << endl; - cout << "\n Example: t2 - t1 [1.705]\n\n"; + cout << "\n Example: t2 - t1 (1.705)\n\n"; td = t2 - t1; td0 = t20 - t10; cout << " td: " << td << "\n tdo: " << td0 << endl; @@ -177,11 +205,14 @@ int main(void) cout << " t1: " << t1 << "\n t2: " << t2 << endl << " t3: " << t3 << endl << " ?: <: " << boolalpha << (bool)(t1<t2) << " <=: " << (bool)(t1<=t2) << endl - << " ?: >: " << boolalpha << (bool)(t3>t2) << " >=: " << (bool)(t3>=t2) << endl - << endl; + << " ?: >: " << boolalpha << (bool)(t3>t2) << " >=: " << (bool)(t3>=t2) << endl; + + cout << "\n Example: getting time (t1/t0)\n\n"; - cout << "\n Example: getting time (t1)\n\n"; + cout << " seconds and nanoseconds:" << endl + << " " << t1.seconds() << " " << t1.nanoseconds() << endl + << " " << t10.seconds() << " " << t10.nanoseconds() << endl; cout << " double Seconds:" << endl << " " << t1.getTimeInSeconds() << endl << " " << t10.getTimeInSeconds() << endl @@ -229,6 +260,21 @@ int main(void) strftime (buffer,80,"%F,%T\n %I:%M%p\n %c",timeinfo); cout << " " << buffer << endl; + cout << "\n Example: Using Reference Time\n\n"; + cout << " Set Reference and wait 1 second" << endl << endl; + t1.setRef(); + sleep(1); + t1.set(); + CTime tzero = t1.getRef(); + cout << " Time ref: " << tzero << endl; + cout << " t1: " << t1 << endl; + cout << " t2: " << t2 << endl << endl; + cout << " Set useRef(true) for t2 and set its time" << endl << endl; + t2.useRef(true); + t2.set(); + cout << " t2: " << t2 << " Is ref used?: " << t2.isRefUsed() << endl << endl; + + cout << "\n Example: END\n\n"; return(1); diff --git a/src/threads/threadserver.h b/src/threads/threadserver.h index d8186e980591faaa3b2acb2c5e854cbffbe44593..3aa8be9ef3d42aa63a3385dbc52e8840e2530ce9 100644 --- a/src/threads/threadserver.h +++ b/src/threads/threadserver.h @@ -23,16 +23,16 @@ #include "thread.h" #include "mutex.h" -/** +/** * \brief Global thread server * * This class implements a thread server which is global to the application * and also only one instance exist that is shared by all objects requiring * threads. * - * There is no limit in the number of threads that can be created in the whole + * There is no limit in the number of threads that can be created in the whole * application. Each of this threads is assigned a unique identifier at creation - * time which is provided by the user. All identifier must be different, an + * time which is provided by the user. All identifier must be different, an * they are used afterwards to access the desired thread. * * By using an identifier to access the desired thread, this class also isolates @@ -47,9 +47,9 @@ * * This class also has a CMutex object to avoid race conditions or data * corruption while several threads of execution are trying to access the same - * thread. + * thread. * - * This class uses exceptions to report errors. The name of the exception + * This class uses exceptions to report errors. The name of the exception * class associated to this class is CThreadServerException. For a more detailes * descritpion, see the corresponding documentation. * @@ -60,24 +60,24 @@ class CThreadServer /** * \brief Reference to the unique instance of this class * - * This reference points to the unique instance of this class. By default - * it is set to NULL, and it is initialized in the first call to the + * This reference points to the unique instance of this class. By default + * it is set to NULL, and it is initialized in the first call to the * instance() function. after that, successive calls to rhat function * will return the pointer to the previously created object. - */ + */ static CThreadServer* pinstance; /** * \brief Thread handler * * This static list of threads can be used by all objects in an application * and it is used to handle all the threads in an unified way. All threads - * are created and handled through the public interface of the class and + * are created and handled through the public interface of the class and * can be referenced by its identifier. By default this list is empty. */ std::list<CThread> thread_list; /// Mutual exclusion object for the thread handler /** This mutual exclusion object is used to handle several threads accessing - * the list of acvtive threads. Several CMutex objects are used to avoid + * the list of acvtive threads. Several CMutex objects are used to avoid * blocking the events while handling the threads. */ CMutex access_threads; @@ -86,15 +86,15 @@ class CThreadServer * \brief Default constructor * * This constructor initializes the thread list and the mutex object to access - * it. The list can only be modified through the public interface of the + * it. The list can only be modified through the public interface of the * class. * - * The reference to the newly created object is not modified. This constructor + * The reference to the newly created object is not modified. This constructor * is only called once and from inside the instance() function. It can not * be called directly by the user since it is declared as protected. - */ + */ CThreadServer(); - /** + /** * \brief Copy constructor * * This constructor is used to initialize a new object with the contents of @@ -104,29 +104,29 @@ class CThreadServer * * \param object an existing instance of a CThreadServer class which has been * already initialized. - */ + */ CThreadServer(const CThreadServer& object); /** * \brief assign operator overloading * - * This function overloads the assign operator for this class. Since there - * could be only one instance of this class, only the pinstance attribute + * This function overloads the assign operator for this class. Since there + * could be only one instance of this class, only the pinstance attribute * must be copied, but since it is static, nothing is to be done. * * \param object an existing instance of a CThreadServer class which has been * already initialized. * - */ + */ CThreadServer& operator = (const CThreadServer& object); /** * \brief Function to search for an specific thread * * This function is used to search for a particular thread inside the - * thread handler list. It is protected because no one outside the class - * can have access to the particular CThread objects. + * thread handler list. It is protected because no one outside the class + * can have access to the particular CThread objects. * - * If the required thread exists, a reference to it is returned by the - * function, but if there is no thread with the provided identifier, the + * If the required thread exists, a reference to it is returned by the + * function, but if there is no thread with the provided identifier, the * function return a NULL reference, but does not throw any exception. * * 3YThis function throws a CThreadServerException in case of any error. See @@ -134,11 +134,11 @@ class CThreadServer * exception class. * * \param thread_id A null terminated string that identifies the desired - * thread. The necessary memory for this string must be allocated before + * thread. The necessary memory for this string must be allocated before * calling this function. * * \return A reference to the desired CThread object, or a NULL reference - * if the thread with the provided identifier does not belong to the + * if the thread with the provided identifier does not belong to the * thread handler. */ std::list<CThread>::iterator search_thread(const std::string& thread_id); @@ -152,26 +152,26 @@ class CThreadServer * object. * * Since this function is static, it can be call anywhere in the code so - * all objects can access the unique event handler. + * all objects can access the unique event handler. + * + * \return A reference to the only instance of this class. This reference + * must not be freed until the application ends. * - * \return A reference to the only instance of this class. This reference - * must not be freed until the application ends. - * - */ + */ static CThreadServer* instance(void); // Thread handler functions /** * \brief Function to create a new thread * - * This function creates a new thread with a given identifier and adds it to + * This function creates a new thread with a given identifier and adds it to * the thread handler. If there is a thread in the internal list with the same - * identifier, the new thread is not added and an exception is thrown. + * identifier, the new thread is not added and an exception is thrown. * Otherwise, the new thread is added to the list of threads and can be accessed * immediatelly by other threads using the provided identifier. * - * This function locks the access_threads Mutex object to avoid other threads + * This function locks the access_threads Mutex object to avoid other threads * concurrently adding new threads which could cause unpredictible errors. After - * calling this function, the only way to access the newly cretaed thread is + * calling this function, the only way to access the newly cretaed thread is * through its identifier, the user does not have any reference to the CThread * object inserted into the thread list. * @@ -179,9 +179,9 @@ class CThreadServer * the corresponding documentation for a more detailed decription of this * exception class. * - * \param thread_id a null terminated string with the thread identifier. The + * \param thread_id a null terminated string with the thread identifier. The * identifier is stored internally in a different memeory location so that - * the parameter can be freed after calling this function. The identifier + * the parameter can be freed after calling this function. The identifier * must not have any spaces or special characters, and must be unique. * */ @@ -191,7 +191,7 @@ class CThreadServer * \brief Function to delete an existing thread * * This function removes an existing thread from the thread handler. If the - * desired thread is not in the internal list, an exception is thrown and + * desired thread is not in the internal list, an exception is thrown and * nothing happens. Otherwise, the thread is removed, and future reference * to it will end with an exception thrown. * @@ -203,19 +203,19 @@ class CThreadServer * the corresponding documentation for a more detailed decription of this * exception class. * - * \param thread_id a null terminated string with the thread identifier. The + * \param thread_id a null terminated string with the thread identifier. The * identifier is stored internally in a different memeory location so that - * the parameter can be freed after calling this function. The identifier + * the parameter can be freed after calling this function. The identifier * must not have any spaces or special characters, and must be unique. */ void delete_thread(const std::string& thread_id); /** * \brief Function to attach a function to a thread - * - * This function provides access to the private CThread objects through the + * + * This function provides access to the private CThread objects through the * public interface of the class. To see a more detailed description of its - * features, see the documentation on the attach() function of the CThread + * features, see the documentation on the attach() function of the CThread * class. * * The other parameters to the function are descrived in the CThread class @@ -225,17 +225,23 @@ class CThreadServer * the corresponding documentation for a more detailed decription of this * exception class. * - * \param thread_id a null terminated string with the thread identifier. The - * identifier is stored internally in a different memeory location so that - * the parameter can be freed after calling this function. The identifier + * \param thread_id a null terminated string with the thread identifier. The + * identifier is stored internally in a different memory location so that + * the parameter can be released after calling this function. The identifier * must not have any spaces or special characters, and must be unique. + * + * \param user_thread_function the function used by this thread + * + * \param param usually "this" or a structure of parameters that will be + * used by the user thread function since it is static. + * */ void attach_thread(const std::string& thread_id,void *(*user_thread_function)(void *param),void *param); - /** + /** * \brief Function to start a thread * - * This function provides access to the private CThread objects through the + * This function provides access to the private CThread objects through the * public interface of the class. To see a more detailed description of its * features, see the documentation on the start() function of the CThread * class. @@ -244,9 +250,9 @@ class CThreadServer * the corresponding documentation for a more detailed decription of this * exception class. * - * \param thread_id a null terminated string with the thread identifier. The + * \param thread_id a null terminated string with the thread identifier. The * identifier is stored internally in a different memeory location so that - * the parameter can be freed after calling this function. The identifier + * the parameter can be freed after calling this function. The identifier * must not have any spaces or special characters, and must be unique. */ void start_thread(const std::string& thread_id); @@ -254,7 +260,7 @@ class CThreadServer /** * \brief Function to request the termination of a thread * - * This function provides access to the private CThread objects through the + * This function provides access to the private CThread objects through the * public interface of the class. To see a more detailed description of its * features, see the documentation on the end() function of the CThread * class. @@ -263,17 +269,17 @@ class CThreadServer * the corresponding documentation for a more detailed decription of this * exception class. * - * \param thread_id a null terminated string with the thread identifier. The + * \param thread_id a null terminated string with the thread identifier. The * identifier is stored internally in a different memeory location so that - * the parameter can be freed after calling this function. The identifier + * the parameter can be freed after calling this function. The identifier * must not have any spaces or special characters, and must be unique. */ void end_thread(const std::string& thread_id); - /** + /** * \brief Function to immediately terminate a thread * - * This function provides access to the private CThread objects through the + * This function provides access to the private CThread objects through the * public interface of the class. To see a more detailed description of its * features, see the documentation on the kill() function of the CThread * class. @@ -282,9 +288,9 @@ class CThreadServer * the corresponding documentation for a more detailed decription of this * exception class. * - * \param thread_id a null terminated string with the thread identifier. The + * \param thread_id a null terminated string with the thread identifier. The * identifier is stored internally in a different memeory location so that - * the parameter can be freed after calling this function. The identifier + * the parameter can be freed after calling this function. The identifier * must not have any spaces or special characters, and must be unique. * */ @@ -293,7 +299,7 @@ class CThreadServer /** * \brief Function to detach a function from a thread * - * This function provides access to the private CThread objects through the + * This function provides access to the private CThread objects through the * public interface of the class. To see a more detailed description of its * features, see the documentation on the detach() function of the CThread * class. @@ -302,9 +308,9 @@ class CThreadServer * the corresponding documentation for a more detailed decription of this * exception class. * - * \param thread_id a null terminated string with the thread identifier. The + * \param thread_id a null terminated string with the thread identifier. The * identifier is stored internally in a different memeory location so that - * the parameter can be freed after calling this function. The identifier + * the parameter can be freed after calling this function. The identifier * must not have any spaces or special characters, and must be unique. */ void detach_thread(const std::string& thread_id); diff --git a/src/time/ctime.cpp b/src/time/ctime.cpp index 96acf5332ff739fef78711f9c1b8afd5c0f307ff..720ff233eea08322b86a927eabbfb911e112a635 100644 --- a/src/time/ctime.cpp +++ b/src/time/ctime.cpp @@ -18,6 +18,9 @@ #include "ctime.h" +// static members +CTime CTime::zero; + // // CONSTRUCTOR / DESTRUCTOR // @@ -25,6 +28,7 @@ // set own_time to current time CTime::CTime() { + this->use_zero = false; this->set(); this->setFormat(ctf_us); } @@ -105,16 +109,15 @@ time_t CTime::getTimeInTime_t(void) void CTime::set(double milliseconds) { timespec time_temp; - if(milliseconds<0.0) { #if defined __APPLE__ - struct timeval tv; - gettimeofday(&tv, NULL); - time_temp.tv_sec = tv.tv_sec; - time_temp.tv_nsec = tv.tv_usec*1000; + struct timeval tv; + gettimeofday(&tv, NULL); + time_temp.tv_sec = tv.tv_sec; + time_temp.tv_nsec = tv.tv_usec*1000; #else - clock_gettime(CLOCK_REALTIME, &time_temp ); + clock_gettime(CLOCK_REALTIME, &time_temp ); #endif } else @@ -123,8 +126,39 @@ void CTime::set(double milliseconds) } this->sec = time_temp.tv_sec; this->nsec = time_temp.tv_nsec; + if(this->use_zero && milliseconds<0.0) + { + this->sec -= this->zero.seconds(); + this->nsec -= this->zero.nanoseconds(); + } +} + +void CTime::setRef() +{ + this->zero.set(); + this->use_zero = true; +} + +CTime CTime::getRef() + { + return this->zero; + } + +void CTime::resetRef() +{ + this->zero.set(0); + this->use_zero = false; +} + +void CTime::useRef(bool use) +{ + this->use_zero = use; } +bool CTime::isRefUsed() +{ + return this->use_zero; +} // OPERATIONS CTime CTime::operator - (CTime &t) diff --git a/src/time/ctime.h b/src/time/ctime.h index e398a44e80abc583a748b8d7a318e5620e56a85d..dac29fd89c59dc2c0c46007879089c8f848fd5bf 100644 --- a/src/time/ctime.h +++ b/src/time/ctime.h @@ -86,11 +86,9 @@ class CTime * This value is always positive since it represents time, but when * it is the result of an arithmetic operation, its value can be * negative. - * - * This attribute is not used in the conversion functions since - * they are static. */ unsigned long sec; + /** * \brief Internal time (nanoseconds) * @@ -102,11 +100,25 @@ class CTime * This value is always positive since it represents time, but when * it is the result of an arithmetic operation, its value can be * negative. - * - * This attribute is not used in the conversion functions since - * they are static. */ unsigned long nsec; + + /** + * \brief Internal zero reference time + * + * This attribute holds the assigned Reference time in seconds. This value is + * initialized at construction time or whenever the setRef() function + * is called. + * + */ + static CTime zero; + + /** + * \brief Use or not Reference time (zero) + * + */ + bool use_zero; + /** * \brief current output format * @@ -216,7 +228,7 @@ class CTime /** \brief Get time in a timeval strcuture * - * This function returns the internal time using a timeval Linux structure. + * This function returns the internalCTime CTime::zero; time using a timeval Linux structure. * This may prove usefulll when using some Linux system functions which * require this kind of structure. * @@ -237,9 +249,33 @@ class CTime * This may prove usefulll when using some Linux system functions which * require this kind of structure. * - * return the internal time as a time_t structure + * \return the internal time as a time_t structure */ time_t getTimeInTime_t(void); + + /** + * \brief Get the reference internal time + * + * This function returns the internal time as a CTime object + * + * \return the internal ref time as a CTime object + */ + CTime getRef(); + + /** + * \brief sets if use or not the reference internal time + * + * \param use + */ + void useRef(bool use); + + /** + * \brief Get if is used or not the reference internal time + * + * \return use of the internal ref time + */ + bool isRefUsed(); + ///@} /// @name Set Time @@ -260,6 +296,21 @@ class CTime */ void set(double milliseconds=-1.0); + /** \brief Sets the internal reference time + * + * This function sets the internal time of the object. + * + */ + void setRef(); + + /** \brief Resets the reference time to the epoch + * + * This function resets the reference internal time of the object to the + * epoch time. + * + */ + void resetRef(); + ///@} /// @name Operators @@ -343,22 +394,36 @@ class CTime */ bool operator != (CTime &t); - /** \brief Comparison operator - * - * This operator is used to compare two time objects. If the two values are - * the same it returns true, and false otherwise. + /** \brief Comparison > operator * * \param t a second time object used to perform the comparation. * - * \return returns true if the two objects have different values and false - * otherwise. + * \return returns t0 > t1 */ bool operator > (CTime &t); + /** \brief Comparison < operator + * + * \param t a second time object used to perform the comparation. + * + * \return returns t0 < t1 + */ bool operator < (CTime &t); + /** \brief Comparison >= operator + * + * \param t a second time object used to perform the comparation. + * + * \return returns t0 >= t1 + */ bool operator >= (CTime &t); + /** \brief Comparison <= operator + * + * \param t a second time object used to perform the comparation. + * + * \return returns t0 <= t1 + */ bool operator <= (CTime &t); /** \brief outputs time into a ostream @@ -477,5 +542,8 @@ class CTime }; + + + #endif