time_functions.cpp
Go to the documentation of this file.
00001 
00011 /*****************************************************************************
00012 ** Includes
00013 *****************************************************************************/
00014 
00015 #include <iostream>
00016 #include <string>
00017 #include <cstdlib>
00018 #include <ecl/time_lite/config.hpp>
00019 #include "../../include/ecl/time_lite/functions.hpp"
00020 #include "../../include/ecl/time_lite/cpu_time.hpp"
00021 
00022 
00023 /*****************************************************************************
00024 ** Main
00025 *****************************************************************************/
00026 
00027 int main() {
00028 
00029 #if defined(ECL_HAS_POSIX_TIMERS) || defined(ECL_HAS_RT_TIMERS) || defined(ECL_HAS_WIN_TIMERS) || defined(ECL_HAS_MACH_TIMERS)
00030         ecl::TimeError error;
00031     ecl::TimeStructure duration, timestamp;
00032 
00033     std::cout << std::endl;
00034     std::cout << "***********************************************************" << std::endl;
00035     std::cout << "                   Sleep" << std::endl;
00036     std::cout << "***********************************************************" << std::endl;
00037     std::cout << std::endl;
00038 
00039 
00040     std::cout << "Sleep: Duration 1.3s" << std::endl;
00041     duration.tv_sec = 1;
00042     duration.tv_nsec = 300000000;
00043     error = ecl::sleep(duration);
00044     if ( error.flag() != ecl::NoError ) {
00045         abort();
00046     }
00047 
00048 
00049     std::cout << std::endl;
00050     std::cout << "***********************************************************" << std::endl;
00051     std::cout << "                   Epoch Time" << std::endl;
00052     std::cout << "***********************************************************" << std::endl;
00053     std::cout << std::endl;
00054 
00055     error = ecl::epoch_time(timestamp);
00056     if ( error.flag() != ecl::NoError ) {
00057         abort();
00058     }
00059     std::cout << "Epoch Time:" << std::endl;
00060     std::cout << "  sec : " << timestamp.tv_sec << std::endl;
00061     std::cout << "  nsec: " << timestamp.tv_nsec << std::endl;
00062 
00063     std::cout << std::endl;
00064     std::cout << "***********************************************************" << std::endl;
00065     std::cout << "                   Sleep Until" << std::endl;
00066     std::cout << "***********************************************************" << std::endl;
00067     std::cout << std::endl;
00068 
00069     timestamp.tv_sec += 2;
00070     std::cout << "Sleeping until current_time + 2 seconds." << std::endl;
00071     error = ecl::sleep_until(timestamp);
00072     if ( error.flag() != ecl::NoError ) {
00073         abort();
00074     }
00075 
00076 #ifdef ECL_HAS_CPUTIME
00077     std::cout << std::endl;
00078     std::cout << "***********************************************************" << std::endl;
00079     std::cout << "                    Cpu Time" << std::endl;
00080     std::cout << "***********************************************************" << std::endl;
00081     std::cout << std::endl;
00082 
00083     error = ecl::cpu_time(timestamp);
00084     if ( error.flag() != ecl::NoError ) {
00085         abort();
00086     }
00087     std::cout << "Cpu Time:" << std::endl;
00088     std::cout << "  sec : " << timestamp.tv_sec << std::endl;
00089     std::cout << "  nsec: " << timestamp.tv_nsec << std::endl;
00090 #endif
00091 
00092     std::cout << std::endl;
00093     std::cout << "***********************************************************" << std::endl;
00094     std::cout << "                      Passed" << std::endl;
00095     std::cout << "***********************************************************" << std::endl;
00096     std::cout << std::endl;
00097 
00098     return 0;
00099 #else
00100     std::cout << std::endl;
00101     std::cout << "***********************************************************" << std::endl;
00102     std::cout << "           This platform does not support timers. " << std::endl;
00103     std::cout << "***********************************************************" << std::endl;
00104     std::cout << std::endl;
00105 #endif
00106 
00107 }


ecl_time_lite
Author(s): Daniel Stonier
autogenerated on Wed Aug 26 2015 11:27:16