Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

LOW_platformMisc_Linux.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_platformMisc_Linux.cpp  -  description
00003                              -------------------
00004     begin                : Thu Aug 1 2002
00005     copyright            : (C) 2002 by Harald Roelle
00006     email                : roelle@informatik.uni-muenchen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00019 #define _POSIX_C_SOURCE 199309 
00020 
00021 #include <time.h>
00022 #include <unistd.h>
00023 #include <sys/types.h>
00024 #include <sys/ipc.h>
00025 #include <sys/time.h>
00026 
00027 #include "LOW_platformMisc_Linux.h"
00028 
00029 
00030 
00031 //=====================================================================================
00032 //
00033 // constructors
00034 //
00035 
00036 LOW_platformMisc_Linux::LOW_platformMisc_Linux()
00037 {
00038 }
00039 
00040 
00041 LOW_platformMisc_Linux::~LOW_platformMisc_Linux()
00042 {
00043 }
00044 
00045 
00046 //=====================================================================================
00047 //
00048 // time methods
00049 //
00050 
00051 const void LOW_platformMisc_Linux::p_secSleep( const unsigned int inSeconds) const
00052 {
00053   p_nanoSleep( inSeconds, 0);
00054 }
00055 
00056 
00057 const void LOW_platformMisc_Linux::p_milliSleep( const unsigned long inMilliSeconds) const
00058 {
00059   unsigned int  sec  = inMilliSeconds/1000;
00060   unsigned long nsec = (inMilliSeconds%1000)*1000000;
00061   p_nanoSleep( sec, nsec);
00062 }
00063 
00064 
00065 const void LOW_platformMisc_Linux::p_microSleep( const unsigned long inMicroSeconds) const
00066 {
00067   unsigned int  sec  = inMicroSeconds/1000000;
00068   unsigned long nsec = (inMicroSeconds%1000000)*1000;
00069   p_nanoSleep( sec, nsec);
00070 }
00071 
00072 
00073 const void LOW_platformMisc_Linux::p_nanoSleep( const unsigned long inNanoSeconds) const
00074 {
00075   p_nanoSleep( 0, inNanoSeconds);
00076 }
00077 
00078 
00079 const void LOW_platformMisc_Linux::p_nanoSleep( const unsigned int inSeconds, const unsigned long inNanoSeconds) const
00080 {
00081   struct timespec  sleepTime, remainTime;
00082   
00083   sleepTime.tv_sec  = inSeconds + inNanoSeconds/1000000000;
00084   sleepTime.tv_nsec = inNanoSeconds % 1000000000;
00085   
00086   while( ::nanosleep( &sleepTime, &remainTime) != 0 ) {
00087     sleepTime.tv_sec  = remainTime.tv_sec + remainTime.tv_nsec/1000000000;
00088     sleepTime.tv_nsec = remainTime.tv_nsec % 1000000000;
00089   }
00090 }
00091 
00092 
00093 const void LOW_platformMisc_Linux::p_getTimestamp( LOW_platformMisc::timestamp_t &outTimestamp) const
00094 {
00095   struct timeval  tStamp;
00096   gettimeofday( &tStamp, 0);
00097   outTimestamp.sec    = tStamp.tv_sec;
00098   outTimestamp.milSec = tStamp.tv_usec / 1000;
00099 }
00100 
00101 
00102 const LOW_platformMiscFactory::threadIdent_t  LOW_platformMisc_Linux::p_getThreadID() const
00103 {
00104   return getpid();
00105 }
00106 
00107 
00108 const std::string LOW_platformMisc_Linux::p_getHostname() const
00109 {
00110   char name[1025];
00111 
00112   gethostname( name, 1024);
00113 
00114   return std::string( name);
00115 }
00116 

Generated on Tue Feb 3 11:30:26 2004 for OneWireLibrary++ by doxygen 1.3.2