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

Last change on this file since 4 was 4, checked in by ktk, 26 years ago

Import

File size: 7.2 KB
Line 
1/* $Id: capi2032.cpp,v 1.1 1999-05-24 20:19:34 ktk Exp $ */
2
3/*
4 * CAPI2032 implementation
5 *
6 * Copyright 1998 Felix Maschek
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#include <os2win.h>
13#include <stdarg.h>
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17
18#include <memory.h>
19
20#include "misc.h"
21#include "capi2032.h"
22#include "unicode.h"
23
24// definitions from OS/2 toolkit
25
26typedef unsigned long APIRET;
27typedef unsigned long HEV;
28
29#define SEM_INDEFINATE_WAIT -1
30
31extern "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
38// Implementation note:
39//
40// The Implementation for OS/2 and Win32 are nearly the same. Most of the
41// functions are implemented exactly the same way. The only difference is
42// the signal handling. The OS/2 implementation needs a event semaphore
43// which will be posted if an event occures. The Win32 implementation
44// only provides a function CAPI_WAIT_FOR_EVENT; the function returns,
45// if an event occures.
46// The internal structure ImplCapi gives us the room for the event semaphore
47// handle. The event semaphore will be created the first time,
48// CAPI_WAIT_FOR_EVENT is called since some applications don't need this
49// functionality (actually they poll the CAPI)
50
51typedef struct _ImplCapi
52 {
53 DWORD ApplID;
54 HEV hEvent;
55 } ImplCapi;
56
57//******************************************************************************
58//******************************************************************************
59DWORD WIN32API OS2CAPI_REGISTER(
60 DWORD MessageBufferSize,
61 DWORD maxLogicalConnection,
62 DWORD maxBDataBlocks,
63 DWORD maxBDataLen,
64 DWORD * pApplID )
65{
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;
105}
106
107//******************************************************************************
108//******************************************************************************
109DWORD WIN32API OS2CAPI_RELEASE(
110 DWORD ApplID )
111{
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;
127}
128
129//******************************************************************************
130//******************************************************************************
131DWORD WIN32API OS2CAPI_PUT_MESSAGE(
132 DWORD ApplID,
133 PVOID pCAPIMessage )
134{
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;
145}
146
147//******************************************************************************
148//******************************************************************************
149DWORD WIN32API OS2CAPI_GET_MESSAGE(
150 DWORD ApplID,
151 PVOID * ppCAPIMessage )
152{
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 return dwResult;
163}
164
165//******************************************************************************
166//******************************************************************************
167DWORD WIN32API OS2CAPI_WAIT_FOR_SIGNAL(
168 DWORD ApplID )
169{
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//******************************************************************************
212DWORD WIN32API OS2CAPI_GET_MANUFACTURER(
213 char * SzBuffer )
214{
215#ifdef DEBUG
216 WriteLog("CAPI2032: CAPI_GET_MANUFACTURER\n");
217#endif
218
219 return CAPI_GET_MANUFACTURER( SzBuffer );
220}
221
222//******************************************************************************
223//******************************************************************************
224DWORD WIN32API OS2CAPI_GET_VERSION(
225 DWORD * pCAPIMajor,
226 DWORD * pCAPIMinor,
227 DWORD * pManufacturerMajor,
228 DWORD * pManufacturerMinor )
229{
230#ifdef DEBUG
231 WriteLog("CAPI2032: CAPI_GET_VERSION\n");
232#endif
233
234 return CAPI_GET_VERSION( pCAPIMajor, pCAPIMinor,
235 pManufacturerMajor, pManufacturerMinor );
236}
237
238//******************************************************************************
239//******************************************************************************
240DWORD WIN32API OS2CAPI_GET_SERIAL_NUMBER(
241 char * SzBuffer )
242{
243#ifdef DEBUG
244 WriteLog("CAPI2032: CAPI_GET_SERIAL_NUMBER\n");
245#endif
246
247 return CAPI_GET_SERIAL_NUMBER( SzBuffer );
248}
249
250//******************************************************************************
251//******************************************************************************
252DWORD WIN32API OS2CAPI_GET_PROFILE(
253 PVOID SzBuffer,
254 DWORD CtrlNr )
255{
256#ifdef DEBUG
257 WriteLog("CAPI2032: CAPI_GET_PROFILE\n");
258#endif
259
260 return CAPI_GET_PROFILE( SzBuffer, CtrlNr );
261}
262
263//******************************************************************************
264//******************************************************************************
265DWORD WIN32API OS2CAPI_INSTALLED()
266{
267#ifdef DEBUG
268 WriteLog("CAPI2032: CAPI_INSTALLED\n");
269#endif
270
271 return CAPI_INSTALLED( );
272}
273
274
Note: See TracBrowser for help on using the repository browser.