apicomm.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. {****************************************************************************
  2. $Id$
  3. Common types, and definitions
  4. Copyright (c) 1997 Balazs Scheidler ([email protected])
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  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. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with this library; if not, write to the Free
  15. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. $Id$
  18. ****************************************************************************
  19. Changelog:
  20. Common version 0.2.6
  21. Date Version Who Comments
  22. 07/12/97 0.1 Bazsi Initial implementation (bazsi)
  23. 07/18/97 0.2 Bazsi Linux specific error codes added
  24. 07/18/97 0.2.1 Bazsi Some syntactical errors removed...
  25. 07/28/97 0.2.2 Bazsi Base error code for Video registered
  26. 07/29/97 0.2.3 Bazsi Some basic types added (PByte, PWord etc)
  27. 08/08/97 0.2.4 Bazsi Finalized error handling code (Brad's code added)
  28. 08/27/97 0.2.5 Bazsi BP doesn't like function types as return-values
  29. for functions, returning Pointer instead
  30. 09/06/97 0.2.6 Bazsi Added base error code for Keyboard
  31. 11/06/97 0.2.7 Bazsi Added base error code for FileCtrl
  32. Todo:
  33. * Some types found in the DOS unit should be included here (TextRec maybe
  34. renamed to TTextRec, FileRec etc.)
  35. * Other platform specific error codes.
  36. ****************************************************************************}
  37. unit ApiComm;
  38. interface
  39. {$i platform.inc}
  40. const
  41. { Error codes }
  42. errOk = 0;
  43. errVioBase = 1000;
  44. errKbdBase = 1010;
  45. errFileCtrlBase = 1020;
  46. errMouseBase = 1030;
  47. { The following ranges have been defined for error codes:
  48. 0 - 1000 OS dependent codes
  49. 1000 - 10000 API reserved codes
  50. 10000 - Add-on unit errors
  51. Before anyone adding a unit, contact [email protected] to assign a base
  52. error code, to avoid collisions.
  53. The symbolic names of error codes should be defined in the unit which uses
  54. those error codes, except for OS dependent ones, which should be defined here
  55. enclosed in IFDEFs. (The reason is that not always you can't always decide
  56. which error-code belongs to one unit or the other) }
  57. {$IFDEF OS_Linux}
  58. { for a more complete description of each error check /usr/include/asm/errno.h }
  59. errNotPermitted = 1;
  60. errFileNotFound = 2;
  61. errNoSuchProcess = 3;
  62. errInterruptedCall = 4;
  63. errIOError = 5;
  64. errNoDevAddr = 6;
  65. errTooManyArguments = 7;
  66. errExecError = 8;
  67. errBadFileHandle = 9;
  68. errNoChild = 10;
  69. errTryAgain = 11;
  70. errWouldBlock = errTryAgain;
  71. errOutOfMemory = 12;
  72. errNoPermission = 13;
  73. errInvalidAddress = 14; { Invalid pointer passed to kernel }
  74. errNotBlockDev = 15;
  75. errDeviceBusy = 16;
  76. errFileExists = 17;
  77. errCrossDevice = 18;
  78. errNoSuchDev = 19;
  79. errNotDirectory = 20;
  80. errIsDirectory = 21;
  81. errInvalidArgument = 22;
  82. errFileTableOverflow = 23;
  83. errTooManyOpenFiles = 24;
  84. errNotATTY = 25;
  85. errTextBusy = 26;
  86. errFileTooLarge = 27;
  87. errDiskFull = 28;
  88. errIllegalSeek = 29;
  89. errReadOnlyFS = 30;
  90. errTooManyLinks = 31;
  91. errBrokenPipe = 32;
  92. errMathDomain = 33; { Math domain error, what does this mean? }
  93. errMathRange = 34; { Math result out of range }
  94. errDeadLock = 35;
  95. errFileNameTooLong = 36;
  96. errNoLock = 37; { No record locks available }
  97. errNotImplemented = 38; { Kernel function not implemented }
  98. errDirNotEmpty = 39;
  99. errSymlinkLoop = 40;
  100. errNoMessage = 41; { ??? maybe the IPC getmsg call returns this }
  101. { Here are some errors that are too cryptic for me, I think they are not used
  102. under Linux, only on some mainframes (channel errors etc) }
  103. errBadFont = 59;
  104. errNotStream = 60;
  105. errNoData = 61;
  106. errTimeOut = 62;
  107. errNoMoreStreams = 63;
  108. errNoNetwork = 64;
  109. errPackageNotInstalled = 65; { ??? }
  110. errRemote = 66;
  111. errSevereLink = 67;
  112. errAdvertise = 68; { Advertise error??? }
  113. errSrMount = 69;
  114. errCommunication = 70; { Communication error on send? }
  115. errProtocol = 71; { Protocol error }
  116. errMuiltiHop = 72;
  117. errDotDot = 73; { RFS specific error ???}
  118. errBadMessage = 74; { Not a data message }
  119. errOverflow = 75;
  120. errNotUnique = 76; { Network name not unique }
  121. errBadFileHandleState = 77;
  122. errRemoteChange = 78; { Remote address changed }
  123. errLibAccess = 79; { Cannot access the needed shared lib }
  124. errLibCorrupt = 80; { Shared library corrupted }
  125. errLibScn = 81;
  126. errLibTooMany = 82; { Too many shared libraries }
  127. errLibExec = 83; { Attempting to execute a shared lib }
  128. errIllegalSequence = 84; { Illegal byte sequence ??? }
  129. errRestart = 85; { interrupted system call should be restarted }
  130. errStreamPipe = 86;
  131. errTooManyUsers = 87;
  132. errNotSocket = 88;
  133. errDestAddrRequired = 89;
  134. errMessageTooLong = 90;
  135. errProtocolType = 91;
  136. errNoSuchProtocol = 92;
  137. errProtocolNotSupported = 93;
  138. errSocketTypeNotSupported = 94;
  139. errOperationNotSupported= 95;
  140. errPFamilyNotSupported = 96; { Protocol family not supported }
  141. errAFamilyNotSupported = 97; { Address family not supported }
  142. errAddressInUse = 98;
  143. errAddressNotAvailable = 99;
  144. errNetDown = 100;
  145. errNetUnreachable = 101;
  146. errNetReset = 102;
  147. errConnAborted = 103;
  148. errConnReset = 104;
  149. errNoBufs = 105;
  150. errAlreadyConn = 106;
  151. errNotConn = 107;
  152. errShutdown = 108;
  153. errTooManyRefs = 109;
  154. errConnTimeOut = 110;
  155. errConnRefused = 111;
  156. errHostDown = 112;
  157. errNoRoute = 113; { No route to host }
  158. errOperationProgress = 114; { Operation already in progress }
  159. errStaleNFSHandle = 115;
  160. errStrucClean = 116; { Structure needs cleaning ? }
  161. { Xenix specific codes left out }
  162. errRemoteIO = 121;
  163. errQuotaExceeded = 122;
  164. {$ENDIF}
  165. {$IFDEF OS_DOS}
  166. { DOS specific error-codes to be added }
  167. {$ENDIF}
  168. type
  169. {$IFDEF BIT_32}
  170. CPUWord = Longint;
  171. CPUInt = Longint;
  172. {$ELSE}
  173. CPUWord = Word;
  174. CPUInt = Integer;
  175. {$ENDIF}
  176. PByte = ^Byte;
  177. PWord = ^Word;
  178. PLongint = ^Longint;
  179. { This code is taken from Brad Williams code, with some modifications }
  180. type
  181. TErrorHandlerReturnValue = (errRetry, errAbort, errContinue);
  182. { errRetry = retry the operation,
  183. errAbort = abort, return error code,
  184. errContinue = abort, without returning errorcode }
  185. TErrorHandler = function (Code: Longint; Info: Pointer): TErrorHandlerReturnValue;
  186. { ErrorHandler is the standard procedural interface for all error functions.
  187. Info may contain any data type specific to the error code passed to the
  188. function. }
  189. function GetErrorCode: Longint;
  190. { Returns the last error code, and resets it to 0 (errOK) }
  191. function GetErrorInfo: Pointer;
  192. { Returns the info assigned to the previous error, doesn't reset the value to nil }
  193. {$IFDEF PPC_BP}
  194. function SetErrorHandler(AErrorHandler: TErrorHandler): Pointer;
  195. {$ELSE}
  196. function SetErrorHandler(AErrorHandler: TErrorHandler): TErrorHandler;
  197. {$ENDIF}
  198. { Sets ErrorHandler to AErrorHandler, and returns the old one }
  199. function DefaultErrorHandler(AErrorCode: Longint; AErrorInfo: Pointer): TErrorHandlerReturnValue;
  200. { Default error handler, simply sets error code, and returns errContinue }
  201. const
  202. ErrorCode: Longint = errOk;
  203. ErrorInfo: Pointer = nil;
  204. ErrorHandler: TErrorHandler = DefaultErrorHandler;
  205. implementation
  206. function GetErrorCode: Longint;
  207. begin
  208. GetErrorCode := ErrorCode;
  209. ErrorCode := 0;
  210. end;
  211. function GetErrorInfo: Pointer;
  212. begin
  213. GetErrorInfo := ErrorInfo;
  214. end;
  215. {$IFDEF PPC_BP}
  216. function SetErrorHandler(AErrorHandler: TErrorHandler): Pointer;
  217. begin
  218. SetErrorHandler := @ErrorHandler;
  219. ErrorHandler := AErrorHandler;
  220. end;
  221. {$ELSE}
  222. function SetErrorHandler(AErrorHandler: TErrorHandler): TErrorHandler;
  223. begin
  224. SetErrorHandler := ErrorHandler;
  225. ErrorHandler := AErrorHandler;
  226. end;
  227. {$ENDIF}
  228. function DefaultErrorHandler(AErrorCode: Longint; AErrorInfo: Pointer): TErrorHandlerReturnValue;
  229. begin
  230. ErrorCode := AErrorCode;
  231. ErrorInfo := AErrorInfo;
  232. DefaultErrorHandler := errAbort; { return error code }
  233. end;
  234. end.
  235. {
  236. $Log$
  237. Revision 1.1 2000-02-29 11:43:16 pierre
  238. Common renamed APIComm to avoid problems with free vision
  239. Revision 1.1 2000/01/06 01:20:31 peter
  240. * moved out of packages/ back to topdir
  241. Revision 1.1 1999/12/23 19:36:47 peter
  242. * place unitfiles in target dirs
  243. Revision 1.1 1999/11/24 23:36:37 peter
  244. * moved to packages dir
  245. Revision 1.1 1998/12/04 12:48:24 peter
  246. * moved some dirs
  247. Revision 1.5 1998/10/28 00:02:05 peter
  248. + mouse
  249. + video.clearscreen, video.videobufsize
  250. Revision 1.4 1998/10/26 11:22:48 peter
  251. * updates
  252. Date Version Who Comments
  253. 07/12/97 0.1 Bazsi Initial implementation (bazsi)
  254. 07/18/97 0.2 Bazsi Linux specific error codes added
  255. 07/18/97 0.2.1 Bazsi Some syntactical errors removed...
  256. 07/28/97 0.2.2 Bazsi Base error code for Video registered
  257. 07/29/97 0.2.3 Bazsi Some basic types added (PByte, PWord etc)
  258. 08/08/97 0.2.4 Bazsi Finalized error handling code (Brad's code added)
  259. 08/27/97 0.2.5 Bazsi BP doesn't like function types as return-values
  260. for functions, returning Pointer instead
  261. 09/06/97 0.2.6 Bazsi Added base error code for Keyboard
  262. 11/06/97 0.2.7 Bazsi Added base error code for FileCtrl
  263. }