| 1 | /******************************************************************************* |
|---|
| 2 | |
|---|
| 3 | Copyright 2005-2006, Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE Parser. |
|---|
| 6 | |
|---|
| 7 | OSSIE Parser is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the Lesser GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2.1 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE Parser is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | Lesser GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the Lesser GNU General Public License |
|---|
| 18 | along with OSSIE Parser; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | #ifndef PORTABILITY_H |
|---|
| 24 | #define PORTABILITY_H |
|---|
| 25 | |
|---|
| 26 | #ifdef HAVE_UNISTD_H |
|---|
| 27 | #include <unistd.h> |
|---|
| 28 | #endif |
|---|
| 29 | #ifdef HAVE_TIME_H |
|---|
| 30 | #include <time.h> |
|---|
| 31 | #endif |
|---|
| 32 | |
|---|
| 33 | namespace ossieSupport { |
|---|
| 34 | /** |
|---|
| 35 | Sleep for integer number of seconds. |
|---|
| 36 | */ |
|---|
| 37 | inline unsigned int sleep(unsigned int seconds) |
|---|
| 38 | { |
|---|
| 39 | #ifdef HAVE_UNISTD_H |
|---|
| 40 | return ::sleep(seconds); |
|---|
| 41 | #endif |
|---|
| 42 | #ifdef MSdot_NET |
|---|
| 43 | Sleep(seconds*1000); |
|---|
| 44 | #endif |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | Nano-second resolution sleep. |
|---|
| 49 | */ |
|---|
| 50 | inline int nsleep(unsigned long seconds, unsigned long nano_seconds) { |
|---|
| 51 | #ifdef HAVE_TIME_H |
|---|
| 52 | struct timespec t, rem; |
|---|
| 53 | |
|---|
| 54 | t.tv_sec = seconds; |
|---|
| 55 | t.tv_nsec = nano_seconds; |
|---|
| 56 | |
|---|
| 57 | int result = nanosleep(&t, &rem); |
|---|
| 58 | |
|---|
| 59 | return result; |
|---|
| 60 | #endif |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | #endif |
|---|