[6550] | 1 | /* $Id: capi2032.cpp,v 1.6 2001-08-16 18:13:24 sandervl Exp $ */
|
---|
[91] | 2 |
|
---|
[4] | 3 | /*
|
---|
| 4 | * CAPI2032 implementation
|
---|
| 5 | *
|
---|
[4505] | 6 | * first implementation 1998 Felix Maschek
|
---|
[4] | 7 | *
|
---|
[4505] | 8 | * rewritten 2000 Carsten Tenbrink
|
---|
[4] | 9 | *
|
---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 11 | *
|
---|
| 12 | */
|
---|
[4505] | 13 | #define INCL_DOS
|
---|
| 14 | #include <os2wrap.h>
|
---|
[4] | 15 | #include <stdarg.h>
|
---|
| 16 | #include <stdio.h>
|
---|
| 17 | #include <stdlib.h>
|
---|
| 18 | #include <string.h>
|
---|
| 19 |
|
---|
| 20 | #include <memory.h>
|
---|
| 21 |
|
---|
| 22 | #include "misc.h"
|
---|
| 23 | #include "capi2032.h"
|
---|
| 24 | #include "unicode.h"
|
---|
| 25 |
|
---|
| 26 | // Implementation note:
|
---|
| 27 | //
|
---|
| 28 | // The Implementation for OS/2 and Win32 are nearly the same. Most of the
|
---|
| 29 | // functions are implemented exactly the same way. The only difference is
|
---|
| 30 | // the signal handling. The OS/2 implementation needs a event semaphore
|
---|
| 31 | // which will be posted if an event occures. The Win32 implementation
|
---|
| 32 | // only provides a function CAPI_WAIT_FOR_EVENT; the function returns,
|
---|
| 33 | // if an event occures.
|
---|
| 34 |
|
---|
| 35 | //******************************************************************************
|
---|
| 36 | //******************************************************************************
|
---|
| 37 | DWORD WIN32API OS2CAPI_REGISTER(
|
---|
| 38 | DWORD MessageBufferSize,
|
---|
| 39 | DWORD maxLogicalConnection,
|
---|
| 40 | DWORD maxBDataBlocks,
|
---|
| 41 | DWORD maxBDataLen,
|
---|
| 42 | DWORD * pApplID )
|
---|
| 43 | {
|
---|
[4505] | 44 | DWORD dwResult;
|
---|
| 45 | APIRET rc;
|
---|
| 46 | USHORT sel = RestoreOS2FS();
|
---|
| 47 | HEV hEvent = NULLHANDLE;
|
---|
| 48 | char szSemName[CCHMAXPATHCOMP];
|
---|
[4] | 49 |
|
---|
[4505] | 50 | dprintf(("CAPI2032: CAPI_REGISTER"));
|
---|
[4] | 51 |
|
---|
[4505] | 52 | dwResult = CAPI_REGISTER( MessageBufferSize, maxLogicalConnection,
|
---|
| 53 | maxBDataBlocks, maxBDataLen, pApplID );
|
---|
[4] | 54 |
|
---|
[4505] | 55 | if( dwResult )
|
---|
| 56 | {
|
---|
| 57 | dprintf((" failed (%X)!\n", dwResult ));
|
---|
[6550] | 58 | SetFS(sel);
|
---|
[4505] | 59 | return(0x1108);
|
---|
| 60 | }
|
---|
| 61 | dprintf((" successfull (ApplID: %d)\n", *pApplID ));
|
---|
[4] | 62 |
|
---|
[6550] | 63 | // create named semaphore with Application ID as last character sequenz
|
---|
| 64 | rc = DosCreateEventSem( szSemName, &hEvent, DC_SEM_SHARED, FALSE );
|
---|
| 65 | if( rc )
|
---|
[4505] | 66 | {
|
---|
[6550] | 67 | dprintf((" failed (DosCreateEventSem): %d!\n",rc));
|
---|
| 68 | SetFS(sel);
|
---|
| 69 | return 0x1108; // OS ressource error (error class 0x11..)
|
---|
| 70 | }
|
---|
| 71 | dprintf((" ok (DosCreateEventSem): hEvent:%d %s!\n", hEvent, szSemName));
|
---|
[4] | 72 |
|
---|
[6550] | 73 | dwResult = CAPI_SET_SIGNAL( *pApplID, hEvent );
|
---|
| 74 | if( dwResult )
|
---|
| 75 | {
|
---|
| 76 | dprintf((" failed (CAPI_SET_SIGNAL: %X)!\n", dwResult));
|
---|
| 77 | SetFS(sel);
|
---|
| 78 | return 0x1108; // OS ressource error (error class 0x11..)
|
---|
[4505] | 79 | }
|
---|
[6550] | 80 |
|
---|
| 81 | SetFS(sel);
|
---|
[4505] | 82 | return dwResult;
|
---|
[4] | 83 | }
|
---|
| 84 |
|
---|
| 85 | //******************************************************************************
|
---|
| 86 | //******************************************************************************
|
---|
| 87 | DWORD WIN32API OS2CAPI_RELEASE(
|
---|
| 88 | DWORD ApplID )
|
---|
| 89 | {
|
---|
[4505] | 90 | DWORD dwResult;
|
---|
| 91 | ULONG rc;
|
---|
| 92 | HEV hEvent = NULLHANDLE;
|
---|
| 93 | char szSemName[CCHMAXPATHCOMP];
|
---|
| 94 | USHORT sel = RestoreOS2FS();
|
---|
[4] | 95 |
|
---|
[4505] | 96 | dprintf(("CAPI2032: CAPI_RELEASE (ApplID: %d)\n", ApplID));
|
---|
[4] | 97 |
|
---|
[6550] | 98 | // open semaphore ( get the event Handle )
|
---|
[4505] | 99 | sprintf( szSemName, "\\SEM32\\CAPI2032\\SEM%d" , ApplID );
|
---|
[6550] | 100 |
|
---|
| 101 | // enter critical section, so no other thread can access the sem
|
---|
| 102 | DosEnterCritSec();
|
---|
| 103 | // open semaphore to get the event handle
|
---|
[4505] | 104 | rc = DosOpenEventSem( szSemName, &hEvent );
|
---|
| 105 | if(rc)
|
---|
| 106 | {
|
---|
| 107 | dprintf((" failed (DosOpenEventSem) rc: %d!\n",rc));
|
---|
| 108 | }
|
---|
[6550] | 109 | // close semaphore, this will decrement the open count
|
---|
| 110 | DosCloseEventSem( hEvent );
|
---|
| 111 |
|
---|
[4505] | 112 | // cleanup
|
---|
| 113 | if( hEvent )
|
---|
| 114 | {
|
---|
| 115 | dprintf(("(DosCloseEventSem) hEvent:%d %s!\n",hEvent, szSemName));
|
---|
[6550] | 116 | // final cleanup semaphore.
|
---|
[4505] | 117 | rc = DosCloseEventSem( hEvent );
|
---|
| 118 | if(rc)
|
---|
| 119 | {
|
---|
| 120 | dprintf((" failed (DosCloseEventSem) rc: %d!\n",rc));
|
---|
| 121 | }
|
---|
[6550] | 122 |
|
---|
[4505] | 123 | }
|
---|
[6550] | 124 | DosExitCritSec();
|
---|
| 125 |
|
---|
[4505] | 126 | dwResult = CAPI_RELEASE( ApplID );
|
---|
[4] | 127 |
|
---|
[4505] | 128 | SetFS(sel);
|
---|
| 129 | return dwResult;
|
---|
[4] | 130 | }
|
---|
| 131 |
|
---|
| 132 | //******************************************************************************
|
---|
| 133 | //******************************************************************************
|
---|
| 134 | DWORD WIN32API OS2CAPI_PUT_MESSAGE(
|
---|
| 135 | DWORD ApplID,
|
---|
| 136 | PVOID pCAPIMessage )
|
---|
| 137 | {
|
---|
[4505] | 138 | DWORD dwResult;
|
---|
| 139 | USHORT sel = RestoreOS2FS();
|
---|
[4] | 140 |
|
---|
[4505] | 141 | dprintf(("CAPI2032: CAPI_PUT_MESSAGE (ApplID: %d)", ApplID));
|
---|
[4] | 142 |
|
---|
[4505] | 143 | dwResult = CAPI_PUT_MESSAGE( ApplID, pCAPIMessage );
|
---|
[4] | 144 |
|
---|
[4505] | 145 | dprintf((" Result: %X\n", dwResult));
|
---|
| 146 |
|
---|
| 147 | SetFS(sel);
|
---|
| 148 | return dwResult;
|
---|
[4] | 149 | }
|
---|
| 150 |
|
---|
| 151 | //******************************************************************************
|
---|
| 152 | //******************************************************************************
|
---|
| 153 | DWORD WIN32API OS2CAPI_GET_MESSAGE(
|
---|
| 154 | DWORD ApplID,
|
---|
| 155 | PVOID * ppCAPIMessage )
|
---|
| 156 | {
|
---|
[4505] | 157 | DWORD dwResult;
|
---|
| 158 | USHORT sel = RestoreOS2FS();
|
---|
| 159 | dprintf(("CAPI2032: CAPI_GET_MESSAGE (ApplID: %d)", ApplID));
|
---|
[4] | 160 |
|
---|
[4505] | 161 | dwResult = CAPI_GET_MESSAGE( ApplID, ppCAPIMessage );
|
---|
[4] | 162 |
|
---|
[4505] | 163 | dprintf((" Result: %X\n", dwResult));
|
---|
[4] | 164 |
|
---|
[4505] | 165 | SetFS(sel);
|
---|
| 166 | return dwResult;
|
---|
[4] | 167 | }
|
---|
| 168 |
|
---|
| 169 | //******************************************************************************
|
---|
| 170 | //******************************************************************************
|
---|
| 171 | DWORD WIN32API OS2CAPI_WAIT_FOR_SIGNAL(
|
---|
| 172 | DWORD ApplID )
|
---|
| 173 | {
|
---|
[4505] | 174 | DWORD dwResult;
|
---|
| 175 | ULONG ulPostCount;
|
---|
| 176 | APIRET rc;
|
---|
| 177 | HEV hEvent = NULLHANDLE;
|
---|
| 178 | char szSemName[CCHMAXPATHCOMP];
|
---|
[4] | 179 |
|
---|
[4505] | 180 | dprintf(("CAPI2032: CAPI_WAIT_FOR_SIGNAL (ApplID: %d)", ApplID));
|
---|
[4] | 181 |
|
---|
[4505] | 182 | sprintf( szSemName, "\\SEM32\\CAPI2032\\SEM%d" , ApplID );
|
---|
[6550] | 183 |
|
---|
| 184 | // enter critical section, so no other thread can access the sem
|
---|
| 185 | DosEnterCritSec();
|
---|
| 186 | // open semaphore to get the event handle
|
---|
[4505] | 187 | rc = DosOpenEventSem( szSemName, &hEvent );
|
---|
| 188 | if(rc)
|
---|
| 189 | {
|
---|
[6550] | 190 | DosExitCritSec();
|
---|
[4505] | 191 | dprintf((" failed (DosOpenEventSem) rc: %d!\n",rc));
|
---|
| 192 | return 0x1101;
|
---|
| 193 | }
|
---|
[6550] | 194 | // close semaphore
|
---|
| 195 | DosCloseEventSem( hEvent );
|
---|
| 196 | DosExitCritSec();
|
---|
[4] | 197 |
|
---|
[4505] | 198 | // wait for event
|
---|
| 199 | rc = DosWaitEventSem( hEvent, SEM_INDEFINITE_WAIT );
|
---|
| 200 | if(rc)
|
---|
| 201 | {
|
---|
| 202 | dprintf((" failed (DosWaitEventSem) rc: %d!\n",rc));
|
---|
| 203 | return 0x1101;
|
---|
| 204 | }
|
---|
| 205 | dprintf((" ok got hEvent: %u!\n",hEvent));
|
---|
[4] | 206 |
|
---|
[4505] | 207 | DosResetEventSem( hEvent, &ulPostCount );
|
---|
[4] | 208 |
|
---|
[4505] | 209 | return 0;
|
---|
[4] | 210 | }
|
---|
| 211 |
|
---|
| 212 | //******************************************************************************
|
---|
| 213 | //******************************************************************************
|
---|
[4505] | 214 | VOID WIN32API OS2CAPI_GET_MANUFACTURER(
|
---|
[4] | 215 | char * SzBuffer )
|
---|
| 216 | {
|
---|
[4505] | 217 | USHORT sel = RestoreOS2FS();
|
---|
| 218 | dprintf(("CAPI2032: CAPI_GET_MANUFACTURER\n"));
|
---|
[4] | 219 |
|
---|
[4505] | 220 | CAPI_GET_MANUFACTURER( SzBuffer );
|
---|
| 221 | SetFS(sel);
|
---|
[4] | 222 | }
|
---|
| 223 |
|
---|
| 224 | //******************************************************************************
|
---|
| 225 | //******************************************************************************
|
---|
| 226 | DWORD WIN32API OS2CAPI_GET_VERSION(
|
---|
| 227 | DWORD * pCAPIMajor,
|
---|
| 228 | DWORD * pCAPIMinor,
|
---|
| 229 | DWORD * pManufacturerMajor,
|
---|
| 230 | DWORD * pManufacturerMinor )
|
---|
| 231 | {
|
---|
[4505] | 232 | DWORD dwResult;
|
---|
| 233 | USHORT sel = RestoreOS2FS();
|
---|
| 234 | dprintf(("CAPI2032: CAPI_GET_VERSION\n"));
|
---|
[4] | 235 |
|
---|
[4505] | 236 | dwResult = CAPI_GET_VERSION( pCAPIMajor, pCAPIMinor,
|
---|
| 237 | pManufacturerMajor, pManufacturerMinor );
|
---|
| 238 | SetFS(sel);
|
---|
| 239 | return dwResult;
|
---|
[4] | 240 | }
|
---|
| 241 |
|
---|
| 242 | //******************************************************************************
|
---|
| 243 | //******************************************************************************
|
---|
| 244 | DWORD WIN32API OS2CAPI_GET_SERIAL_NUMBER(
|
---|
| 245 | char * SzBuffer )
|
---|
| 246 | {
|
---|
[4505] | 247 | DWORD dwResult;
|
---|
| 248 | USHORT sel = RestoreOS2FS();
|
---|
| 249 | dprintf(("CAPI2032: CAPI_GET_SERIAL_NUMBER\n"));
|
---|
[4] | 250 |
|
---|
[4505] | 251 | dwResult = CAPI_GET_SERIAL_NUMBER( SzBuffer );
|
---|
| 252 | SetFS(sel);
|
---|
| 253 | return dwResult;
|
---|
[4] | 254 | }
|
---|
| 255 |
|
---|
| 256 | //******************************************************************************
|
---|
| 257 | //******************************************************************************
|
---|
| 258 | DWORD WIN32API OS2CAPI_GET_PROFILE(
|
---|
| 259 | PVOID SzBuffer,
|
---|
| 260 | DWORD CtrlNr )
|
---|
| 261 | {
|
---|
[4505] | 262 | DWORD dwResult;
|
---|
| 263 | USHORT sel = RestoreOS2FS();
|
---|
| 264 | dprintf(("CAPI2032: CAPI_GET_PROFILE\n"));
|
---|
[4] | 265 |
|
---|
[4505] | 266 | dwResult = CAPI_GET_PROFILE( SzBuffer, CtrlNr );
|
---|
| 267 |
|
---|
| 268 | SetFS(sel);
|
---|
| 269 | return dwResult;
|
---|
[4] | 270 | }
|
---|
| 271 |
|
---|
| 272 | //******************************************************************************
|
---|
| 273 | //******************************************************************************
|
---|
[4505] | 274 | DWORD WIN32API OS2CAPI_INSTALLED( VOID )
|
---|
[4] | 275 | {
|
---|
[4505] | 276 | DWORD dwResult;
|
---|
| 277 | USHORT sel = RestoreOS2FS();
|
---|
| 278 | dprintf(("CAPI2032: CAPI_INSTALLED"));
|
---|
[4] | 279 |
|
---|
[4505] | 280 | dwResult = CAPI_INSTALLED( );
|
---|
| 281 |
|
---|
| 282 | dprintf((" result: %d\n",dwResult));
|
---|
| 283 | SetFS(sel);
|
---|
| 284 | return dwResult;
|
---|
[4] | 285 | }
|
---|