ODPlat.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* OpenDoors Online Software Programming Toolkit
  2. * (C) Copyright 1991 - 1999 by Brian Pirie.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. *
  19. * File: ODPlat.h
  20. *
  21. * Description: Contains platform-related definitions and prototypes for
  22. * those function's whose implementation is platform-specific
  23. * (functions implemented in odplat.c). Non-platform specific
  24. * utility functions are defined in odutil.h and implemented in
  25. * odutil.c.
  26. *
  27. * Revisions: Date Ver Who Change
  28. * ---------------------------------------------------------------
  29. * Oct 14, 1994 6.00 BP Created.
  30. * Nov 01, 1994 6.00 BP Added ODDir...() functions.
  31. * Dec 31, 1994 6.00 BP Added timing, file delete functions.
  32. * Dec 31, 1994, 6.00 BP Added ODMultitasker and ODPlatInit()
  33. * Nov 14, 1995 6.00 BP 32-bit portability.
  34. * Nov 17, 1995 6.00 BP Added multithreading functions.
  35. * Dec 13, 1995 6.00 BP Added ODThreadWaitForExit().
  36. * Dec 13, 1995 6.00 BP Added ODThreadGetCurrent().
  37. * Jan 23, 1996 6.00 BP Added ODProcessExit().
  38. * Jan 30, 1996 6.00 BP Add semaphore timeout.
  39. * Jan 31, 1996 6.00 BP Add ODTimerLeft(), rm ODTimerSleep().
  40. * Feb 19, 1996 6.00 BP Changed version number to 6.00.
  41. * Mar 03, 1996 6.10 BP Begin version 6.10.
  42. */
  43. #ifndef _INC_ODPLAT
  44. #define _INC_ODPLAT
  45. #include <time.h>
  46. #include "ODTypes.h"
  47. #include "ODGen.h"
  48. #ifdef ODPLAT_NIX
  49. #include <sys/time.h>
  50. #endif
  51. #ifdef ODPLAT_WIN32
  52. #include "windows.h"
  53. #endif /* ODPLAT_WIN32 */
  54. /* odplat.c initialization function prototype */
  55. void ODPlatInit(void);
  56. /* ========================================================================= */
  57. /* Millisecond timer functions. */
  58. /* ========================================================================= */
  59. /* Timer data type. */
  60. typedef struct
  61. {
  62. #ifdef ODPLAT_DOS
  63. clock_t Start;
  64. clock_t Duration;
  65. #elif defined(ODPLAT_NIX)
  66. time_t Start;
  67. tODMilliSec Duration;
  68. #else /* !ODPLAT_DOS */
  69. tODMilliSec Start;
  70. tODMilliSec Duration;
  71. #endif /* !ODPLAT_DOS */
  72. } tODTimer;
  73. /* Timer function prototypes. */
  74. void ODTimerStart(tODTimer *pTimer, tODMilliSec Duration);
  75. BOOL ODTimerElapsed(tODTimer *pTimer);
  76. void ODTimerWaitForElapse(tODTimer *pTimer);
  77. tODMilliSec ODTimerLeft(tODTimer *pTimer);
  78. /* ========================================================================= */
  79. /* Multithreading and synchronization support. */
  80. /* ========================================================================= */
  81. #ifdef OD_MULTITHREADED
  82. /* Thread handle data type. */
  83. #ifdef ODPLAT_WIN32
  84. typedef HANDLE tODThreadHandle;
  85. #endif /* ODPLAT_WIN32 */
  86. /* Thread priority enumeration. */
  87. typedef enum
  88. {
  89. OD_PRIORITY_LOWEST,
  90. OD_PRIORITY_BELOW_NORMAL,
  91. OD_PRIORITY_NORMAL,
  92. OD_PRIORITY_ABOVE_NORMAL,
  93. OD_PRIORITY_HIGHEST
  94. } tODThreadPriority;
  95. /* Thread start proceedure type. */
  96. #define OD_THREAD_FUNC WINAPI
  97. #ifdef ODPLAT_WIN32
  98. typedef DWORD (OD_THREAD_FUNC ptODThreadProc)(void *);
  99. #endif /* ODPLAT_WIN32 */
  100. /* Thread creation, temination and suspension. */
  101. tODResult ODThreadCreate(tODThreadHandle *phThread,
  102. ptODThreadProc *pfThreadProc, void *pThreadParam);
  103. void ODThreadExit();
  104. tODResult ODThreadTerminate(tODThreadHandle hThread);
  105. tODResult ODThreadSuspend(tODThreadHandle hThread);
  106. tODResult ODThreadResume(tODThreadHandle hThread);
  107. tODResult ODThreadSetPriority(tODThreadHandle hThread,
  108. tODThreadPriority ThreadPriority);
  109. void ODThreadWaitForExit(tODThreadHandle hThread);
  110. tODThreadHandle ODThreadGetCurrent(void);
  111. /* Semaphore handle data type. */
  112. #ifdef ODPLAT_WIN32
  113. typedef HANDLE tODSemaphoreHandle;
  114. #endif /* ODPLAT_WIN32 */
  115. /* Semaphore manipulation functions. */
  116. tODResult ODSemaphoreAlloc(tODSemaphoreHandle *phSemaphore, INT nInitialCount,
  117. INT nMaximumCount);
  118. void ODSemaphoreFree(tODSemaphoreHandle hSemaphore);
  119. void ODSemaphoreUp(tODSemaphoreHandle hSemaphore, INT nIncrementBy);
  120. tODResult ODSemaphoreDown(tODSemaphoreHandle hSemaphore, tODMilliSec Timeout);
  121. #endif /* OD_MULTITHREADED */
  122. void ODProcessExit(INT nExitCode);
  123. /* ========================================================================= */
  124. /* DOS multitasker information. */
  125. /* ========================================================================= */
  126. #ifdef ODPLAT_DOS
  127. typedef enum
  128. {
  129. kMultitaskerNone,
  130. kMultitaskerDV,
  131. kMultitaskerWin,
  132. kMultitaskerOS2
  133. } tODMultitasker;
  134. extern tODMultitasker ODMultitasker;
  135. #endif /* ODPLAT_DOS */
  136. /* ========================================================================= */
  137. /* Directory Access. */
  138. /* ========================================================================= */
  139. /* Open directory handle type. */
  140. typedef tODHandle tODDirHandle;
  141. /* Directory entry structure. */
  142. #define DIR_FILENAME_SIZE 1024
  143. #define DIR_ATTRIB_NORMAL 0x00
  144. #define DIR_ATTRIB_RDONLY 0x01
  145. #define DIR_ATTRIB_HIDDEN 0x02
  146. #define DIR_ATTRIB_SYSTEM 0x04
  147. #define DIR_ATTRIB_LABEL 0x08
  148. #define DIR_ATTRIB_DIREC 0x10
  149. #define DIR_ATTRIB_ARCH 0x20
  150. typedef struct
  151. {
  152. char szFileName[DIR_FILENAME_SIZE];
  153. WORD wAttributes;
  154. time_t LastWriteTime;
  155. DWORD dwFileSize;
  156. } tODDirEntry;
  157. /* Directory function prototypes. */
  158. tODResult ODDirOpen(CONST char *pszPath, WORD wAttributes, tODDirHandle *phDir);
  159. tODResult ODDirRead(tODDirHandle hDir, tODDirEntry *pDirEntry);
  160. void ODDirClose(tODDirHandle hDir);
  161. void ODDirChangeCurrent(char *pszPath);
  162. void ODDirGetCurrent(char *pszPath, INT nMaxPathChars);
  163. /* ========================================================================= */
  164. /* Miscellaneous Functions. */
  165. /* ========================================================================= */
  166. tODResult ODFileDelete(CONST char *pszPath);
  167. BOOL ODFileAccessMode(char *pszFilename, int nAccessMode);
  168. #endif /* !_INC_ODPLAT */