Changeset 4505 for trunk/src/capi2032/capi2032.cpp
- Timestamp:
- Oct 21, 2000, 12:28:24 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/capi2032/capi2032.cpp
r91 r4505 1 /* $Id: capi2032.cpp,v 1. 3 1999-06-10 14:27:04 phallerExp $ */1 /* $Id: capi2032.cpp,v 1.4 2000-10-20 22:28:24 sandervl Exp $ */ 2 2 3 3 /* 4 4 * CAPI2032 implementation 5 5 * 6 * Copyright 1998 Felix Maschek 7 * 6 * first implementation 1998 Felix Maschek 7 * 8 * rewritten 2000 Carsten Tenbrink 8 9 * 9 10 * Project Odin Software License can be found in LICENSE.TXT 10 11 * 11 12 */ 12 #include <os2win.h> 13 #define INCL_DOS 14 #include <os2wrap.h> 13 15 #include <stdarg.h> 14 16 #include <stdio.h> … … 21 23 #include "capi2032.h" 22 24 #include "unicode.h" 23 24 // definitions from OS/2 toolkit25 26 typedef unsigned long APIRET;27 typedef unsigned long HEV;28 29 #define SEM_INDEFINATE_WAIT -130 31 extern "C"32 {33 APIRET _System DosCloseEventSem( HEV );34 APIRET _System DosCreateEventSem( char*, HEV*, unsigned long, unsigned long );35 APIRET _System DosWaitEventSem( HEV, unsigned long );36 }37 25 38 26 // Implementation note: … … 44 32 // only provides a function CAPI_WAIT_FOR_EVENT; the function returns, 45 33 // if an event occures. 46 // The internal structure ImplCapi gives us the room for the event semaphore47 // handle. The event semaphore will be created the first time,48 // CAPI_WAIT_FOR_EVENT is called since some applications don't need this49 // functionality (actually they poll the CAPI)50 51 typedef struct _ImplCapi52 {53 DWORD ApplID;54 HEV hEvent;55 } ImplCapi;56 34 57 35 //****************************************************************************** … … 64 42 DWORD * pApplID ) 65 43 { 66 ImplCapi* pImplCapi; 67 DWORD dwResult; 68 69 #ifdef DEBUG 70 WriteLog("CAPI2032: CAPI_REGISTER"); 71 #endif 72 73 pImplCapi = new ImplCapi; 74 if( !pImplCapi ) 75 { 76 #ifdef DEBUG 77 WriteLog(" failed (no memory)!\n"); 78 #endif 79 return 0x0108; // OS ressource error (error class 0x10..) 80 } 81 82 memset( pImplCapi, 0, sizeof( ImplCapi ) ); 83 84 dwResult = CAPI_REGISTER( MessageBufferSize, maxLogicalConnection, 85 maxBDataBlocks, maxBDataLen, &pImplCapi->ApplID ); 86 87 // application successfully registered? -> save internal structure as Application ID 88 if( dwResult ) 89 { 90 *pApplID = (DWORD) pImplCapi; 91 92 #ifdef DEBUG 93 WriteLog(" successfull (ApplID: %d)\n", pImplCapi->ApplID ); 94 #endif 95 } 96 else 97 { 98 #ifdef DEBUG 99 WriteLog(" failed (%X)!\n", dwResult ); 100 #endif 101 delete pImplCapi; 102 } 103 104 return dwResult; 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 if( dwResult ) 56 { 57 dprintf((" failed (%X)!\n", dwResult )); 58 return(0x1108); 59 } 60 dprintf((" successfull (ApplID: %d)\n", *pApplID )); 61 62 // create named semaphore if neccessary 63 if( !hEvent ) 64 { 65 // create named semaphore with Application ID as last character sequenz 66 sprintf( szSemName, "\\SEM32\\CAPI2032\\SEM%d" , *pApplID ); 67 rc = DosCreateEventSem( szSemName, &hEvent, DC_SEM_SHARED, FALSE ); 68 if( rc ) 69 { 70 dprintf((" failed (DosCreateEventSem): %d!\n",rc)); 71 return 0x1108; // OS ressource error (error class 0x11..) 72 } 73 dprintf((" ok (DosCreateEventSem): hEvent:%d %s!\n", hEvent, szSemName)); 74 75 dwResult = CAPI_SET_SIGNAL( *pApplID, hEvent ); 76 if( dwResult ) 77 { 78 dprintf((" failed (CAPI_SET_SIGNAL: %X)!\n", dwResult)); 79 return 0x1108; // OS ressource error (error class 0x11..) 80 } 81 } 82 SetFS(sel); 83 return dwResult; 105 84 } 106 85 … … 110 89 DWORD ApplID ) 111 90 { 112 ImplCapi* pImplCapi = (ImplCapi*) ApplID; 113 DWORD dwResult; 114 115 #ifdef DEBUG 116 WriteLog("CAPI2032: CAPI_RELEASE (ApplID: %d)\n", pImplCapi->ApplID); 117 #endif 118 119 dwResult = CAPI_RELEASE( pImplCapi->ApplID ); 120 121 // cleanup 122 if( pImplCapi->hEvent ) 123 DosCloseEventSem( pImplCapi->hEvent ); 124 delete pImplCapi; 125 126 return dwResult; 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; 127 121 } 128 122 … … 133 127 PVOID pCAPIMessage ) 134 128 { 135 ImplCapi* pImplCapi = (ImplCapi*) ApplID; 136 DWORD dwResult; 137 138 dwResult = CAPI_PUT_MESSAGE( pImplCapi->ApplID, pCAPIMessage ); 139 140 #ifdef DEBUG 141 WriteLog("CAPI2032: CAPI_PUT_MESSAGE (ApplID: %d) Result: %X\n", pImplCapi->ApplID, dwResult); 142 #endif 143 144 return dwResult; 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; 145 140 } 146 141 … … 151 146 PVOID * ppCAPIMessage ) 152 147 { 153 ImplCapi* pImplCapi = (ImplCapi*) ApplID;154 DWORD dwResult;155 156 dwResult = CAPI_GET_MESSAGE( pImplCapi->ApplID, ppCAPIMessage ); 157 158 #ifdef DEBUG 159 WriteLog("CAPI2032: CAPI_GET_MESSAGE (ApplID: %d) Result: %X\n", pImplCapi->ApplID, dwResult);160 #endif 161 162 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; 163 158 } 164 159 … … 168 163 DWORD ApplID ) 169 164 { 170 ImplCapi* pImplCapi = (ImplCapi*) ApplID; 171 DWORD dwResult; 172 APIRET rc; 173 174 #ifdef DEBUG 175 WriteLog("CAPI2032: CAPI_WAIT_FOR_SIGNAL (ApplID: %d)", pImplCapi->ApplID); 176 #endif 177 178 // create semaphore if neccessary 179 if( !pImplCapi->hEvent ) // FM 980706: fixed condition... 180 { 181 rc = DosCreateEventSem( NULL, &pImplCapi->hEvent, 0, 0 ); 182 if( !rc ) 183 { 184 #ifdef DEBUG 185 WriteLog(" failed (DosCreateEventSem)!\n"); 186 #endif 187 return 0x1108; // OS ressource error (error class 0x11..) 188 } 189 190 dwResult = CAPI_SET_SIGNAL( pImplCapi->ApplID, pImplCapi->hEvent ); 191 if( !dwResult ) 192 { 193 #ifdef DEBUG 194 WriteLog(" failed (CAPI_SET_SIGNAL: %X)!\n", dwResult); 195 #endif 196 return 0x1108; // OS ressource error (error class 0x11..) 197 } 198 } 199 200 // wait for event 201 DosWaitEventSem( pImplCapi->hEvent, SEM_INDEFINATE_WAIT ); 202 203 #ifdef DEBUG 204 WriteLog("\n"); 205 #endif 206 207 return 0; 208 } 209 210 //****************************************************************************** 211 //****************************************************************************** 212 DWORD WIN32API OS2CAPI_GET_MANUFACTURER( 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( 213 199 char * SzBuffer ) 214 200 { 215 #ifdef DEBUG 216 WriteLog("CAPI2032: CAPI_GET_MANUFACTURER\n");217 #endif 218 219 return CAPI_GET_MANUFACTURER( SzBuffer);201 USHORT sel = RestoreOS2FS(); 202 dprintf(("CAPI2032: CAPI_GET_MANUFACTURER\n")); 203 204 CAPI_GET_MANUFACTURER( SzBuffer ); 205 SetFS(sel); 220 206 } 221 207 … … 228 214 DWORD * pManufacturerMinor ) 229 215 { 230 #ifdef DEBUG 231 WriteLog("CAPI2032: CAPI_GET_VERSION\n"); 232 #endif 233 234 return CAPI_GET_VERSION( pCAPIMajor, pCAPIMinor, 235 pManufacturerMajor, pManufacturerMinor ); 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; 236 224 } 237 225 … … 241 229 char * SzBuffer ) 242 230 { 243 #ifdef DEBUG 244 WriteLog("CAPI2032: CAPI_GET_SERIAL_NUMBER\n"); 245 #endif 246 247 return CAPI_GET_SERIAL_NUMBER( SzBuffer ); 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; 248 238 } 249 239 … … 254 244 DWORD CtrlNr ) 255 245 { 256 #ifdef DEBUG 257 WriteLog("CAPI2032: CAPI_GET_PROFILE\n"); 258 #endif 259 260 return CAPI_GET_PROFILE( SzBuffer, CtrlNr ); 261 } 262 263 //****************************************************************************** 264 //****************************************************************************** 265 DWORD WIN32API OS2CAPI_INSTALLED() 266 { 267 #ifdef DEBUG 268 WriteLog("CAPI2032: CAPI_INSTALLED\n"); 269 #endif 270 271 return CAPI_INSTALLED( ); 272 } 273 274 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 }
Note:
See TracChangeset
for help on using the changeset viewer.