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, Helmut Reiser
00006     email                : roelle@informatik.uni-muenchen.de, reiser@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 // time methods
00034 //
00035 
00036 const void LOW_platformMisc_Linux::p_secSleep( const unsigned int inSeconds)
00037 {
00038   p_nanoSleep( inSeconds, 0);
00039 }
00040 
00041 
00042 const void LOW_platformMisc_Linux::p_milliSleep( const unsigned long inMilliSeconds)
00043 {
00044   unsigned int  sec  = inMilliSeconds/1000;
00045   unsigned long nsec = (inMilliSeconds%1000)*1000000;
00046   p_nanoSleep( sec, nsec);
00047 }
00048 
00049 
00050 const void LOW_platformMisc_Linux::p_microSleep( const unsigned long inMicroSeconds)
00051 {
00052   unsigned int  sec  = inMicroSeconds/1000000;
00053   unsigned long nsec = (inMicroSeconds%1000000)*1000;
00054   p_nanoSleep( sec, nsec);
00055 }
00056 
00057 
00058 const void LOW_platformMisc_Linux::p_nanoSleep( const unsigned long inNanoSeconds)
00059 {
00060   p_nanoSleep( 0, inNanoSeconds);
00061 }
00062 
00063 
00064 const void LOW_platformMisc_Linux::p_nanoSleep( const unsigned int inSeconds, const unsigned long inNanoSeconds)
00065 {
00066   struct timespec  sleepTime, remainTime;
00067   
00068   sleepTime.tv_sec  = inSeconds + inNanoSeconds/1000000000;
00069   sleepTime.tv_nsec = inNanoSeconds % 1000000000;
00070   
00071   while( ::nanosleep( &sleepTime, &remainTime) != 0 ) {
00072     sleepTime.tv_sec  = remainTime.tv_sec + remainTime.tv_nsec/1000000000;
00073     sleepTime.tv_nsec = remainTime.tv_nsec % 1000000000;
00074   }
00075 }
00076 
00077 
00078 const void LOW_platformMisc_Linux::p_getTimestamp( LOW_platformMisc::timestamp_t &outTimestamp)
00079 {
00080   struct timeval  tStamp;
00081   gettimeofday( &tStamp, 0);
00082   outTimestamp.sec    = tStamp.tv_sec;
00083   outTimestamp.milSec = tStamp.tv_usec / 1000;
00084 }
00085 
00086 
00087 const LOW_platformMiscFactory::threadIdent_t  LOW_platformMisc_Linux::p_getThreadID()
00088 {
00089   return getpid();
00090 }
00091 
00092 
00093 const std::string LOW_platformMisc_Linux::p_getHostname()
00094 {
00095   char name[1025];
00096 
00097   gethostname( name, 1024);
00098 
00099   return string( name);
00100 }
00101 

Generated on Sun Jan 12 21:07:43 2003 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001