source: trunk/src/capi2032/capi2032.cpp@ 10367

Last change on this file since 10367 was 6550, checked in by sandervl, 24 years ago

CT: capi update

File size: 7.7 KB
Line 
1/* $Id: capi2032.cpp,v 1.6 2001-08-16 18:13:24 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//******************************************************************************
37DWORD 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 if( dwResult )
56 {
57 dprintf((" failed (%X)!\n", dwResult ));
58 SetFS(sel);
59 return(0x1108);
60 }
61 dprintf((" successfull (ApplID: %d)\n", *pApplID ));
62
63 // create named semaphore with Application ID as last character sequenz
64 rc = DosCreateEventSem( szSemName, &hEvent, DC_SEM_SHARED, FALSE );
65 if( rc )
66 {
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));
72
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..)
79 }
80
81 SetFS(sel);
82 return dwResult;
83}
84
85//******************************************************************************
86//******************************************************************************
87DWORD WIN32API OS2CAPI_RELEASE(
88 DWORD ApplID )
89{
90 DWORD dwResult;
91 ULONG rc;
92 HEV hEvent = NULLHANDLE;
93 char szSemName[CCHMAXPATHCOMP];
94 USHORT sel = RestoreOS2FS();
95
96 dprintf(("CAPI2032: CAPI_RELEASE (ApplID: %d)\n", ApplID));
97
98 // open semaphore ( get the event Handle )
99 sprintf( szSemName, "\\SEM32\\CAPI2032\\SEM%d" , ApplID );
100
101 // enter critical section, so no other thread can access the sem
102 DosEnterCritSec();
103 // open semaphore to get the event handle
104 rc = DosOpenEventSem( szSemName, &hEvent );
105 if(rc)
106 {
107 dprintf((" failed (DosOpenEventSem) rc: %d!\n",rc));
108 }
109 // close semaphore, this will decrement the open count
110 DosCloseEventSem( hEvent );
111
112 // cleanup
113 if( hEvent )
114 {
115 dprintf(("(DosCloseEventSem) hEvent:%d %s!\n",hEvent, szSemName));
116 // final cleanup semaphore.
117 rc = DosCloseEventSem( hEvent );
118 if(rc)
119 {
120 dprintf((" failed (DosCloseEventSem) rc: %d!\n",rc));
121 }
122
123 }
124 DosExitCritSec();
125
126 dwResult = CAPI_RELEASE( ApplID );
127
128 SetFS(sel);
129 return dwResult;
130}
131
132//******************************************************************************
133//******************************************************************************
134DWORD WIN32API OS2CAPI_PUT_MESSAGE(
135 DWORD ApplID,
136 PVOID pCAPIMessage )
137{
138 DWORD dwResult;
139 USHORT sel = RestoreOS2FS();
140
141 dprintf(("CAPI2032: CAPI_PUT_MESSAGE (ApplID: %d)", ApplID));
142
143 dwResult = CAPI_PUT_MESSAGE( ApplID, pCAPIMessage );
144
145 dprintf((" Result: %X\n", dwResult));
146
147 SetFS(sel);
148 return dwResult;
149}
150
151//******************************************************************************
152//******************************************************************************
153DWORD WIN32API OS2CAPI_GET_MESSAGE(
154 DWORD ApplID,
155 PVOID * ppCAPIMessage )
156{
157 DWORD dwResult;
158 USHORT sel = RestoreOS2FS();
159 dprintf(("CAPI2032: CAPI_GET_MESSAGE (ApplID: %d)", ApplID));
160
161 dwResult = CAPI_GET_MESSAGE( ApplID, ppCAPIMessage );
162
163 dprintf((" Result: %X\n", dwResult));
164
165 SetFS(sel);
166 return dwResult;
167}
168
169//******************************************************************************
170//******************************************************************************
171DWORD WIN32API OS2CAPI_WAIT_FOR_SIGNAL(
172 DWORD ApplID )
173{
174 DWORD dwResult;
175 ULONG ulPostCount;
176 APIRET rc;
177 HEV hEvent = NULLHANDLE;
178 char szSemName[CCHMAXPATHCOMP];
179
180 dprintf(("CAPI2032: CAPI_WAIT_FOR_SIGNAL (ApplID: %d)", ApplID));
181
182 sprintf( szSemName, "\\SEM32\\CAPI2032\\SEM%d" , ApplID );
183
184 // enter critical section, so no other thread can access the sem
185 DosEnterCritSec();
186 // open semaphore to get the event handle
187 rc = DosOpenEventSem( szSemName, &hEvent );
188 if(rc)
189 {
190 DosExitCritSec();
191 dprintf((" failed (DosOpenEventSem) rc: %d!\n",rc));
192 return 0x1101;
193 }
194 // close semaphore
195 DosCloseEventSem( hEvent );
196 DosExitCritSec();
197
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));
206
207 DosResetEventSem( hEvent, &ulPostCount );
208
209 return 0;
210}
211
212//******************************************************************************
213//******************************************************************************
214VOID WIN32API OS2CAPI_GET_MANUFACTURER(
215 char * SzBuffer )
216{
217 USHORT sel = RestoreOS2FS();
218 dprintf(("CAPI2032: CAPI_GET_MANUFACTURER\n"));
219
220 CAPI_GET_MANUFACTURER( SzBuffer );
221 SetFS(sel);
222}
223
224//******************************************************************************
225//******************************************************************************
226DWORD WIN32API OS2CAPI_GET_VERSION(
227 DWORD * pCAPIMajor,
228 DWORD * pCAPIMinor,
229 DWORD * pManufacturerMajor,
230 DWORD * pManufacturerMinor )
231{
232 DWORD dwResult;
233 USHORT sel = RestoreOS2FS();
234 dprintf(("CAPI2032: CAPI_GET_VERSION\n"));
235
236 dwResult = CAPI_GET_VERSION( pCAPIMajor, pCAPIMinor,
237 pManufacturerMajor, pManufacturerMinor );
238 SetFS(sel);
239 return dwResult;
240}
241
242//******************************************************************************
243//******************************************************************************
244DWORD WIN32API OS2CAPI_GET_SERIAL_NUMBER(
245 char * SzBuffer )
246{
247 DWORD dwResult;
248 USHORT sel = RestoreOS2FS();
249 dprintf(("CAPI2032: CAPI_GET_SERIAL_NUMBER\n"));
250
251 dwResult = CAPI_GET_SERIAL_NUMBER( SzBuffer );
252 SetFS(sel);
253 return dwResult;
254}
255
256//******************************************************************************
257//******************************************************************************
258DWORD WIN32API OS2CAPI_GET_PROFILE(
259 PVOID SzBuffer,
260 DWORD CtrlNr )
261{
262 DWORD dwResult;
263 USHORT sel = RestoreOS2FS();
264 dprintf(("CAPI2032: CAPI_GET_PROFILE\n"));
265
266 dwResult = CAPI_GET_PROFILE( SzBuffer, CtrlNr );
267
268 SetFS(sel);
269 return dwResult;
270}
271
272//******************************************************************************
273//******************************************************************************
274DWORD WIN32API OS2CAPI_INSTALLED( VOID )
275{
276 DWORD dwResult;
277 USHORT sel = RestoreOS2FS();
278 dprintf(("CAPI2032: CAPI_INSTALLED"));
279
280 dwResult = CAPI_INSTALLED( );
281
282 dprintf((" result: %d\n",dwResult));
283 SetFS(sel);
284 return dwResult;
285}
Note: See TracBrowser for help on using the repository browser.