| 1 | /* $Id: capi2032.cpp,v 1.5 2000-10-21 09:24:03 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * CAPI2032 implementation | 
|---|
| 5 | * | 
|---|
| 6 | * first implementation 1998 Felix Maschek | 
|---|
| 7 | * | 
|---|
| 8 | * rewritten 2000 Carsten Tenbrink | 
|---|
| 9 | * | 
|---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 11 | * | 
|---|
| 12 | */ | 
|---|
| 13 | #define  INCL_DOS | 
|---|
| 14 | #include <os2wrap.h> | 
|---|
| 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 | { | 
|---|
| 44 | DWORD dwResult; | 
|---|
| 45 | APIRET rc; | 
|---|
| 46 | USHORT sel = RestoreOS2FS(); | 
|---|
| 47 | HEV    hEvent = NULLHANDLE; | 
|---|
| 48 | char   szSemName[CCHMAXPATHCOMP]; | 
|---|
| 49 |  | 
|---|
| 50 | dprintf(("CAPI2032: CAPI_REGISTER")); | 
|---|
| 51 |  | 
|---|
| 52 | dwResult = CAPI_REGISTER( MessageBufferSize, maxLogicalConnection, | 
|---|
| 53 | maxBDataBlocks, maxBDataLen, pApplID ); | 
|---|
| 54 |  | 
|---|
| 55 | SetFS(sel); | 
|---|
| 56 | if( dwResult ) | 
|---|
| 57 | { | 
|---|
| 58 | dprintf((" failed (%X)!\n", dwResult )); | 
|---|
| 59 | return(0x1108); | 
|---|
| 60 | } | 
|---|
| 61 | dprintf((" successfull (ApplID: %d)\n", *pApplID )); | 
|---|
| 62 |  | 
|---|
| 63 | // create named semaphore if neccessary | 
|---|
| 64 | if( !hEvent ) | 
|---|
| 65 | { | 
|---|
| 66 | // create named semaphore with Application ID as last character sequenz | 
|---|
| 67 | sprintf( szSemName, "\\SEM32\\CAPI2032\\SEM%d" , *pApplID ); | 
|---|
| 68 | rc = DosCreateEventSem( szSemName, &hEvent, DC_SEM_SHARED, FALSE ); | 
|---|
| 69 | if( rc ) | 
|---|
| 70 | { | 
|---|
| 71 | dprintf((" failed (DosCreateEventSem): %d!\n",rc)); | 
|---|
| 72 | return 0x1108; // OS ressource error (error class 0x11..) | 
|---|
| 73 | } | 
|---|
| 74 | dprintf((" ok (DosCreateEventSem): hEvent:%d %s!\n", hEvent, szSemName)); | 
|---|
| 75 |  | 
|---|
| 76 | dwResult = CAPI_SET_SIGNAL( *pApplID, hEvent ); | 
|---|
| 77 | if( dwResult ) | 
|---|
| 78 | { | 
|---|
| 79 | dprintf((" failed (CAPI_SET_SIGNAL: %X)!\n", dwResult)); | 
|---|
| 80 | return 0x1108; // OS ressource error (error class 0x11..) | 
|---|
| 81 | } | 
|---|
| 82 | } | 
|---|
| 83 | return dwResult; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | //****************************************************************************** | 
|---|
| 87 | //****************************************************************************** | 
|---|
| 88 | DWORD WIN32API OS2CAPI_RELEASE( | 
|---|
| 89 | DWORD ApplID ) | 
|---|
| 90 | { | 
|---|
| 91 | DWORD dwResult; | 
|---|
| 92 | ULONG rc; | 
|---|
| 93 | HEV    hEvent = NULLHANDLE; | 
|---|
| 94 | char   szSemName[CCHMAXPATHCOMP]; | 
|---|
| 95 | USHORT sel = RestoreOS2FS(); | 
|---|
| 96 |  | 
|---|
| 97 | dprintf(("CAPI2032: CAPI_RELEASE (ApplID: %d)\n", ApplID)); | 
|---|
| 98 |  | 
|---|
| 99 | // open semaphore | 
|---|
| 100 | sprintf( szSemName, "\\SEM32\\CAPI2032\\SEM%d" , ApplID ); | 
|---|
| 101 | rc = DosOpenEventSem( szSemName, &hEvent ); | 
|---|
| 102 | if(rc) | 
|---|
| 103 | { | 
|---|
| 104 | dprintf((" failed (DosOpenEventSem) rc: %d!\n",rc)); | 
|---|
| 105 | } | 
|---|
| 106 | // cleanup | 
|---|
| 107 | if( hEvent ) | 
|---|
| 108 | { | 
|---|
| 109 | dprintf(("(DosCloseEventSem) hEvent:%d %s!\n",hEvent, szSemName)); | 
|---|
| 110 | rc = DosCloseEventSem( hEvent ); | 
|---|
| 111 | hEvent = NULLHANDLE; | 
|---|
| 112 | if(rc) | 
|---|
| 113 | { | 
|---|
| 114 | dprintf((" failed (DosCloseEventSem) rc: %d!\n",rc)); | 
|---|
| 115 | } | 
|---|
| 116 | } | 
|---|
| 117 | dwResult = CAPI_RELEASE( ApplID ); | 
|---|
| 118 |  | 
|---|
| 119 | SetFS(sel); | 
|---|
| 120 | return dwResult; | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | //****************************************************************************** | 
|---|
| 124 | //****************************************************************************** | 
|---|
| 125 | DWORD WIN32API OS2CAPI_PUT_MESSAGE( | 
|---|
| 126 | DWORD ApplID, | 
|---|
| 127 | PVOID pCAPIMessage ) | 
|---|
| 128 | { | 
|---|
| 129 | DWORD dwResult; | 
|---|
| 130 | USHORT sel = RestoreOS2FS(); | 
|---|
| 131 |  | 
|---|
| 132 | dprintf(("CAPI2032: CAPI_PUT_MESSAGE (ApplID: %d)", ApplID)); | 
|---|
| 133 |  | 
|---|
| 134 | dwResult = CAPI_PUT_MESSAGE( ApplID, pCAPIMessage ); | 
|---|
| 135 |  | 
|---|
| 136 | dprintf((" Result: %X\n", dwResult)); | 
|---|
| 137 |  | 
|---|
| 138 | SetFS(sel); | 
|---|
| 139 | return dwResult; | 
|---|
| 140 | } | 
|---|
| 141 |  | 
|---|
| 142 | //****************************************************************************** | 
|---|
| 143 | //****************************************************************************** | 
|---|
| 144 | DWORD WIN32API OS2CAPI_GET_MESSAGE( | 
|---|
| 145 | DWORD ApplID, | 
|---|
| 146 | PVOID * ppCAPIMessage ) | 
|---|
| 147 | { | 
|---|
| 148 | DWORD dwResult; | 
|---|
| 149 | USHORT sel = RestoreOS2FS(); | 
|---|
| 150 | dprintf(("CAPI2032: CAPI_GET_MESSAGE (ApplID: %d)", ApplID)); | 
|---|
| 151 |  | 
|---|
| 152 | dwResult = CAPI_GET_MESSAGE( ApplID, ppCAPIMessage ); | 
|---|
| 153 |  | 
|---|
| 154 | dprintf((" Result: %X\n", dwResult)); | 
|---|
| 155 |  | 
|---|
| 156 | SetFS(sel); | 
|---|
| 157 | return dwResult; | 
|---|
| 158 | } | 
|---|
| 159 |  | 
|---|
| 160 | //****************************************************************************** | 
|---|
| 161 | //****************************************************************************** | 
|---|
| 162 | DWORD WIN32API OS2CAPI_WAIT_FOR_SIGNAL( | 
|---|
| 163 | DWORD ApplID ) | 
|---|
| 164 | { | 
|---|
| 165 | DWORD dwResult; | 
|---|
| 166 | ULONG ulPostCount; | 
|---|
| 167 | APIRET rc; | 
|---|
| 168 | HEV    hEvent = NULLHANDLE; | 
|---|
| 169 | char   szSemName[CCHMAXPATHCOMP]; | 
|---|
| 170 |  | 
|---|
| 171 | dprintf(("CAPI2032: CAPI_WAIT_FOR_SIGNAL (ApplID: %d)", ApplID)); | 
|---|
| 172 |  | 
|---|
| 173 | // open semaphore | 
|---|
| 174 | sprintf( szSemName, "\\SEM32\\CAPI2032\\SEM%d" , ApplID ); | 
|---|
| 175 | rc = DosOpenEventSem( szSemName, &hEvent ); | 
|---|
| 176 | if(rc) | 
|---|
| 177 | { | 
|---|
| 178 | dprintf((" failed (DosOpenEventSem) rc: %d!\n",rc)); | 
|---|
| 179 | return 0x1101; | 
|---|
| 180 | } | 
|---|
| 181 |  | 
|---|
| 182 | // wait for event | 
|---|
| 183 | rc = DosWaitEventSem( hEvent, SEM_INDEFINITE_WAIT ); | 
|---|
| 184 | if(rc) | 
|---|
| 185 | { | 
|---|
| 186 | dprintf((" failed (DosWaitEventSem) rc: %d!\n",rc)); | 
|---|
| 187 | return 0x1101; | 
|---|
| 188 | } | 
|---|
| 189 | dprintf((" ok got hEvent: %u!\n",hEvent)); | 
|---|
| 190 |  | 
|---|
| 191 | DosResetEventSem( hEvent, &ulPostCount ); | 
|---|
| 192 |  | 
|---|
| 193 | return 0; | 
|---|
| 194 | } | 
|---|
| 195 |  | 
|---|
| 196 | //****************************************************************************** | 
|---|
| 197 | //****************************************************************************** | 
|---|
| 198 | VOID WIN32API OS2CAPI_GET_MANUFACTURER( | 
|---|
| 199 | char * SzBuffer ) | 
|---|
| 200 | { | 
|---|
| 201 | USHORT sel = RestoreOS2FS(); | 
|---|
| 202 | dprintf(("CAPI2032: CAPI_GET_MANUFACTURER\n")); | 
|---|
| 203 |  | 
|---|
| 204 | CAPI_GET_MANUFACTURER( SzBuffer ); | 
|---|
| 205 | SetFS(sel); | 
|---|
| 206 | } | 
|---|
| 207 |  | 
|---|
| 208 | //****************************************************************************** | 
|---|
| 209 | //****************************************************************************** | 
|---|
| 210 | DWORD WIN32API OS2CAPI_GET_VERSION( | 
|---|
| 211 | DWORD * pCAPIMajor, | 
|---|
| 212 | DWORD * pCAPIMinor, | 
|---|
| 213 | DWORD * pManufacturerMajor, | 
|---|
| 214 | DWORD * pManufacturerMinor ) | 
|---|
| 215 | { | 
|---|
| 216 | DWORD dwResult; | 
|---|
| 217 | USHORT sel = RestoreOS2FS(); | 
|---|
| 218 | dprintf(("CAPI2032: CAPI_GET_VERSION\n")); | 
|---|
| 219 |  | 
|---|
| 220 | dwResult = CAPI_GET_VERSION( pCAPIMajor, pCAPIMinor, | 
|---|
| 221 | pManufacturerMajor, pManufacturerMinor ); | 
|---|
| 222 | SetFS(sel); | 
|---|
| 223 | return dwResult; | 
|---|
| 224 | } | 
|---|
| 225 |  | 
|---|
| 226 | //****************************************************************************** | 
|---|
| 227 | //****************************************************************************** | 
|---|
| 228 | DWORD WIN32API OS2CAPI_GET_SERIAL_NUMBER( | 
|---|
| 229 | char * SzBuffer ) | 
|---|
| 230 | { | 
|---|
| 231 | DWORD dwResult; | 
|---|
| 232 | USHORT sel = RestoreOS2FS(); | 
|---|
| 233 | dprintf(("CAPI2032: CAPI_GET_SERIAL_NUMBER\n")); | 
|---|
| 234 |  | 
|---|
| 235 | dwResult = CAPI_GET_SERIAL_NUMBER( SzBuffer ); | 
|---|
| 236 | SetFS(sel); | 
|---|
| 237 | return dwResult; | 
|---|
| 238 | } | 
|---|
| 239 |  | 
|---|
| 240 | //****************************************************************************** | 
|---|
| 241 | //****************************************************************************** | 
|---|
| 242 | DWORD WIN32API OS2CAPI_GET_PROFILE( | 
|---|
| 243 | PVOID SzBuffer, | 
|---|
| 244 | DWORD CtrlNr ) | 
|---|
| 245 | { | 
|---|
| 246 | DWORD dwResult; | 
|---|
| 247 | USHORT sel = RestoreOS2FS(); | 
|---|
| 248 | dprintf(("CAPI2032: CAPI_GET_PROFILE\n")); | 
|---|
| 249 |  | 
|---|
| 250 | dwResult = CAPI_GET_PROFILE( SzBuffer, CtrlNr ); | 
|---|
| 251 |  | 
|---|
| 252 | SetFS(sel); | 
|---|
| 253 | return dwResult; | 
|---|
| 254 | } | 
|---|
| 255 |  | 
|---|
| 256 | //****************************************************************************** | 
|---|
| 257 | //****************************************************************************** | 
|---|
| 258 | DWORD WIN32API OS2CAPI_INSTALLED( VOID ) | 
|---|
| 259 | { | 
|---|
| 260 | DWORD dwResult; | 
|---|
| 261 | USHORT sel = RestoreOS2FS(); | 
|---|
| 262 | dprintf(("CAPI2032: CAPI_INSTALLED")); | 
|---|
| 263 |  | 
|---|
| 264 | dwResult = CAPI_INSTALLED( ); | 
|---|
| 265 |  | 
|---|
| 266 | dprintf((" result: %d\n",dwResult)); | 
|---|
| 267 | SetFS(sel); | 
|---|
| 268 | return dwResult; | 
|---|
| 269 | } | 
|---|