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

Last change on this file since 46 was 46, checked in by sandervl, 26 years ago

* empty log message *

File size: 7.1 KB
Line 
1/*
2 * CAPI2032 implementation
3 *
4 * Copyright 1998 Felix Maschek
5 *
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 */
10#include <os2win.h>
11#include <stdarg.h>
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15
16#include <memory.h>
17
18#include "misc.h"
19#include "capi2032.h"
20#include "unicode.h"
21
22// definitions from OS/2 toolkit
23
24typedef unsigned long APIRET;
25typedef unsigned long HEV;
26
27#define SEM_INDEFINATE_WAIT -1
28
29extern "C"
30{
31 APIRET _System DosCloseEventSem( HEV );
32 APIRET _System DosCreateEventSem( char*, HEV*, unsigned long, unsigned long );
33 APIRET _System DosWaitEventSem( HEV, unsigned long );
34}
35
36// Implementation note:
37//
38// The Implementation for OS/2 and Win32 are nearly the same. Most of the
39// functions are implemented exactly the same way. The only difference is
40// the signal handling. The OS/2 implementation needs a event semaphore
41// which will be posted if an event occures. The Win32 implementation
42// only provides a function CAPI_WAIT_FOR_EVENT; the function returns,
43// if an event occures.
44// The internal structure ImplCapi gives us the room for the event semaphore
45// handle. The event semaphore will be created the first time,
46// CAPI_WAIT_FOR_EVENT is called since some applications don't need this
47// functionality (actually they poll the CAPI)
48
49typedef struct _ImplCapi
50 {
51 DWORD ApplID;
52 HEV hEvent;
53 } ImplCapi;
54
55//******************************************************************************
56//******************************************************************************
57DWORD WIN32API OS2CAPI_REGISTER(
58 DWORD MessageBufferSize,
59 DWORD maxLogicalConnection,
60 DWORD maxBDataBlocks,
61 DWORD maxBDataLen,
62 DWORD * pApplID )
63{
64 ImplCapi* pImplCapi;
65 DWORD dwResult;
66
67#ifdef DEBUG
68 WriteLog("CAPI2032: CAPI_REGISTER");
69#endif
70
71 pImplCapi = new ImplCapi;
72 if( !pImplCapi )
73 {
74#ifdef DEBUG
75 WriteLog(" failed (no memory)!\n");
76#endif
77 return 0x0108; // OS ressource error (error class 0x10..)
78 }
79
80 memset( pImplCapi, 0, sizeof( ImplCapi ) );
81
82 dwResult = CAPI_REGISTER( MessageBufferSize, maxLogicalConnection,
83 maxBDataBlocks, maxBDataLen, &pImplCapi->ApplID );
84
85 // application successfully registered? -> save internal structure as Application ID
86 if( dwResult )
87 {
88 *pApplID = (DWORD) pImplCapi;
89
90#ifdef DEBUG
91 WriteLog(" successfull (ApplID: %d)\n", pImplCapi->ApplID );
92#endif
93 }
94 else
95 {
96#ifdef DEBUG
97 WriteLog(" failed (%X)!\n", dwResult );
98#endif
99 delete pImplCapi;
100 }
101
102 return dwResult;
103}
104
105//******************************************************************************
106//******************************************************************************
107DWORD WIN32API OS2CAPI_RELEASE(
108 DWORD ApplID )
109{
110 ImplCapi* pImplCapi = (ImplCapi*) ApplID;
111 DWORD dwResult;
112
113#ifdef DEBUG
114 WriteLog("CAPI2032: CAPI_RELEASE (ApplID: %d)\n", pImplCapi->ApplID);
115#endif
116
117 dwResult = CAPI_RELEASE( pImplCapi->ApplID );
118
119 // cleanup
120 if( pImplCapi->hEvent )
121 DosCloseEventSem( pImplCapi->hEvent );
122 delete pImplCapi;
123
124 return dwResult;
125}
126
127//******************************************************************************
128//******************************************************************************
129DWORD WIN32API OS2CAPI_PUT_MESSAGE(
130 DWORD ApplID,
131 PVOID pCAPIMessage )
132{
133 ImplCapi* pImplCapi = (ImplCapi*) ApplID;
134 DWORD dwResult;
135
136 dwResult = CAPI_PUT_MESSAGE( pImplCapi->ApplID, pCAPIMessage );
137
138#ifdef DEBUG
139 WriteLog("CAPI2032: CAPI_PUT_MESSAGE (ApplID: %d) Result: %X\n", pImplCapi->ApplID, dwResult);
140#endif
141
142 return dwResult;
143}
144
145//******************************************************************************
146//******************************************************************************
147DWORD WIN32API OS2CAPI_GET_MESSAGE(
148 DWORD ApplID,
149 PVOID * ppCAPIMessage )
150{
151 ImplCapi* pImplCapi = (ImplCapi*) ApplID;
152 DWORD dwResult;
153
154 dwResult = CAPI_GET_MESSAGE( pImplCapi->ApplID, ppCAPIMessage );
155
156#ifdef DEBUG
157 WriteLog("CAPI2032: CAPI_GET_MESSAGE (ApplID: %d) Result: %X\n", pImplCapi->ApplID, dwResult);
158#endif
159
160 return dwResult;
161}
162
163//******************************************************************************
164//******************************************************************************
165DWORD WIN32API OS2CAPI_WAIT_FOR_SIGNAL(
166 DWORD ApplID )
167{
168 ImplCapi* pImplCapi = (ImplCapi*) ApplID;
169 DWORD dwResult;
170 APIRET rc;
171
172#ifdef DEBUG
173 WriteLog("CAPI2032: CAPI_WAIT_FOR_SIGNAL (ApplID: %d)", pImplCapi->ApplID);
174#endif
175
176 // create semaphore if neccessary
177 if( !pImplCapi->hEvent ) // FM 980706: fixed condition...
178 {
179 rc = DosCreateEventSem( NULL, &pImplCapi->hEvent, 0, 0 );
180 if( !rc )
181 {
182#ifdef DEBUG
183 WriteLog(" failed (DosCreateEventSem)!\n");
184#endif
185 return 0x1108; // OS ressource error (error class 0x11..)
186 }
187
188 dwResult = CAPI_SET_SIGNAL( pImplCapi->ApplID, pImplCapi->hEvent );
189 if( !dwResult )
190 {
191#ifdef DEBUG
192 WriteLog(" failed (CAPI_SET_SIGNAL: %X)!\n", dwResult);
193#endif
194 return 0x1108; // OS ressource error (error class 0x11..)
195 }
196 }
197
198 // wait for event
199 DosWaitEventSem( pImplCapi->hEvent, SEM_INDEFINATE_WAIT );
200
201#ifdef DEBUG
202 WriteLog("\n");
203#endif
204
205 return 0;
206}
207
208//******************************************************************************
209//******************************************************************************
210DWORD WIN32API OS2CAPI_GET_MANUFACTURER(
211 char * SzBuffer )
212{
213#ifdef DEBUG
214 WriteLog("CAPI2032: CAPI_GET_MANUFACTURER\n");
215#endif
216
217 return CAPI_GET_MANUFACTURER( SzBuffer );
218}
219
220//******************************************************************************
221//******************************************************************************
222DWORD WIN32API OS2CAPI_GET_VERSION(
223 DWORD * pCAPIMajor,
224 DWORD * pCAPIMinor,
225 DWORD * pManufacturerMajor,
226 DWORD * pManufacturerMinor )
227{
228#ifdef DEBUG
229 WriteLog("CAPI2032: CAPI_GET_VERSION\n");
230#endif
231
232 return CAPI_GET_VERSION( pCAPIMajor, pCAPIMinor,
233 pManufacturerMajor, pManufacturerMinor );
234}
235
236//******************************************************************************
237//******************************************************************************
238DWORD WIN32API OS2CAPI_GET_SERIAL_NUMBER(
239 char * SzBuffer )
240{
241#ifdef DEBUG
242 WriteLog("CAPI2032: CAPI_GET_SERIAL_NUMBER\n");
243#endif
244
245 return CAPI_GET_SERIAL_NUMBER( SzBuffer );
246}
247
248//******************************************************************************
249//******************************************************************************
250DWORD WIN32API OS2CAPI_GET_PROFILE(
251 PVOID SzBuffer,
252 DWORD CtrlNr )
253{
254#ifdef DEBUG
255 WriteLog("CAPI2032: CAPI_GET_PROFILE\n");
256#endif
257
258 return CAPI_GET_PROFILE( SzBuffer, CtrlNr );
259}
260
261//******************************************************************************
262//******************************************************************************
263DWORD WIN32API OS2CAPI_INSTALLED()
264{
265#ifdef DEBUG
266 WriteLog("CAPI2032: CAPI_INSTALLED\n");
267#endif
268
269 return CAPI_INSTALLED( );
270}
271
272
Note: See TracBrowser for help on using the repository browser.