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/date.hpp"
00020 #include "../../include/ecl/time_lite/functions.hpp"
00021 #include "../../include/ecl/time_lite/cpu_time.hpp"
00022 
00023 
00024 /*****************************************************************************
00025 ** Main
00026 *****************************************************************************/
00027 
00028 int main() {
00029 
00030 #if defined(ECL_HAS_POSIX_TIMERS) || defined(ECL_HAS_RT_TIMERS) || defined(ECL_HAS_WIN_TIMERS) || defined(ECL_HAS_MACH_TIMERS)
00031         ecl::TimeError error;
00032     ecl::TimeStructure duration, timestamp;
00033 
00034     std::cout << std::endl;
00035     std::cout << "***********************************************************" << std::endl;
00036     std::cout << "                   Sleep" << std::endl;
00037     std::cout << "***********************************************************" << std::endl;
00038     std::cout << std::endl;
00039 
00040 
00041     std::cout << "Sleep: Duration 1.3s" << std::endl;
00042     duration.tv_sec = 1;
00043     duration.tv_nsec = 300000000;
00044     error = ecl::sleep(duration);
00045     if ( error.flag() != ecl::NoError ) {
00046         abort();
00047     }
00048 
00049 
00050     std::cout << std::endl;
00051     std::cout << "***********************************************************" << std::endl;
00052     std::cout << "                   Epoch Time" << std::endl;
00053     std::cout << "***********************************************************" << std::endl;
00054     std::cout << std::endl;
00055 
00056     error = ecl::epoch_time(timestamp);
00057     if ( error.flag() != ecl::NoError ) {
00058         abort();
00059     }
00060     std::cout << "Epoch Time:" << std::endl;
00061     std::cout << "  sec : " << timestamp.tv_sec << std::endl;
00062     std::cout << "  nsec: " << timestamp.tv_nsec << std::endl;
00063 
00064     std::cout << std::endl;
00065     std::cout << "***********************************************************" << std::endl;
00066     std::cout << "                   Sleep Until" << std::endl;
00067     std::cout << "***********************************************************" << std::endl;
00068     std::cout << std::endl;
00069 
00070     timestamp.tv_sec += 2;
00071     std::cout << "Sleeping until current_time + 2 seconds." << std::endl;
00072     error = ecl::sleep_until(timestamp);
00073     if ( error.flag() != ecl::NoError ) {
00074         abort();
00075     }
00076 
00077 #ifdef ECL_HAS_CPUTIME
00078     std::cout << std::endl;
00079     std::cout << "***********************************************************" << std::endl;
00080     std::cout << "                    Cpu Time" << std::endl;
00081     std::cout << "***********************************************************" << std::endl;
00082     std::cout << std::endl;
00083 
00084     error = ecl::cpu_time(timestamp);
00085     if ( error.flag() != ecl::NoError ) {
00086         abort();
00087     }
00088     std::cout << "Cpu Time:" << std::endl;
00089     std::cout << "  sec : " << timestamp.tv_sec << std::endl;
00090     std::cout << "  nsec: " << timestamp.tv_nsec << std::endl;
00091 #endif
00092 
00093     std::cout << std::endl;
00094     std::cout << "***********************************************************" << std::endl;
00095     std::cout << "                      Date String" << std::endl;
00096     std::cout << "***********************************************************" << std::endl;
00097     std::cout << std::endl;
00098 
00099     std::cout << "Date String: " << ecl::get_date_string() << std::endl;
00100 
00101     std::cout << std::endl;
00102     std::cout << "***********************************************************" << std::endl;
00103     std::cout << "                      Passed" << std::endl;
00104     std::cout << "***********************************************************" << std::endl;
00105     std::cout << std::endl;
00106 
00107     return 0;
00108 #else
00109     std::cout << std::endl;
00110     std::cout << "***********************************************************" << std::endl;
00111     std::cout << "           This platform does not support timers. " << std::endl;
00112     std::cout << "***********************************************************" << std::endl;
00113     std::cout << std::endl;
00114 #endif
00115 
00116 }


ecl_time_lite
Author(s): Daniel Stonier
autogenerated on Thu Jun 16 2016 09:47:18