source: trunk/stream_ioproc/source/streamproc.c@ 201

Last change on this file since 201 was 169, checked in by gyoung, 17 months ago

Minor code cleanup

File size: 20.0 KB
Line 
1/*
2 * Copyright (c) Chris Wohlgemuth 2005
3 * All rights reserved.
4 *
5 * http://www.geocities.com/SiliconValley/Sector/5785/
6 * http://www.os2world.com/cdwriting
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The authors name may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 */
32
33/************************************************************************/
34/* Put all #defines here */
35/************************************************************************/
36
37#define INCL_32 /* force 32 bit compile */
38#define INCL_GPIBITMAPS
39#define INCL_DOSFILEMGR
40#define INCL_WIN
41#define INCL_GPI
42#define INCL_PM
43
44#define MEMCHECK
45
46/************************************************************************/
47/* Put all #includes here */
48/************************************************************************/
49
50#include <os2.h>
51#include <stdio.h>
52#include <string.h>
53#include <stdlib.h>
54#include <stdarg.h>
55#include <io.h>
56#include <fcntl.h>
57#include <sys\stat.h>
58#include <os2medef.h>
59#include <mmioos2.h>
60#include <streamproc.h>
61
62#define DEBUG
63
64#ifdef DEBUG
65void writeLog(const char* chrFormat, ...)
66{
67 char logNameLocal[CCHMAXPATH];
68 FILE *fHandle;
69
70 sprintf(logNameLocal,"r:\\streamio.log");
71 fHandle=fopen(logNameLocal,"a");
72 if(fHandle) {
73 va_list arg_ptr;
74 void *tb;
75
76 va_start (arg_ptr, chrFormat);
77 vfprintf(fHandle, chrFormat, arg_ptr);
78 va_end (arg_ptr);
79 fclose(fHandle);
80 }
81}
82#endif
83
84
85/************************************************************************/
86/* STREAM IOProc */
87/* */
88/* ARGUMENTS: */
89/* */
90/* PSZ pmmioStr - pointer to MMIOINFO block */
91/* USHORT usMsg - MMIO message being sent */
92/* LONG lParam1 - filename or other parameter depending on message */
93/* LONG lParam2 - used with some messages as values */
94/* */
95/* */
96/* RETURN: */
97/* */
98/* MMIOM_OPEN */
99/* Success - MMIO_SUCCESS (0) */
100/* Failure - MMIO_ERROR (-1) */
101/* */
102/* MMIOM_READ */
103/* Success - Returns the number of bytes actually */
104/* read. Return 0L if no more bytes can */
105/* be read. */
106/* Failure - MMIO_ERROR (-1) */
107/* */
108/* MMIOM_WRITE */
109/* Success - Returns the number of bytes actually */
110/* written. */
111/* Failure - MMIO_ERROR (-1) */
112/* */
113/* MMIOM_SEEK */
114/* Success - Returns the new file position */
115/* Failure - MMIO_ERROR (-1) */
116/* */
117/* MMIOM_CLOSE */
118/* Success - MMIO_SUCCESS (0) */
119/* Failure - MMIO_ERROR (-1) */
120/* Other - MMIO_WARNING, file was closed but the */
121/* IOProc expected additional data */
122/* */
123/* MMIOM_GETFORMATNAME */
124/* Success - Returns the number of bytes read into */
125/* the buffer (size of format name) */
126/* Failure - Return 0 */
127/* */
128/* MMIOM_GETFORMATINFO */
129/* Success - MMIO_SUCCESS (0) */
130/* Failure - MMIO_ERROR (-1) */
131/* */
132/* MMIOM_QUERYHEADERLENGTH */
133/* Success - Returns the size of the header in bytes */
134/* Failure - Return 0 */
135/* */
136/* MMIOM_IDENTIFYFILE */
137/* Success - MMIO_SUCCESS (0) */
138/* Failure - MMIO_ERROR (-1) */
139/* */
140/* MMIOM_GETHEADER */
141/* Success - Returns number of bytes copied into */
142/* the header structure. */
143/* Failure - Return 0 */
144/* Other - If length passed in was not large */
145/* enough to hold header then, */
146/* MMIOERR_INVALID_BUFFER_LENGTH is set */
147/* in ulErrorRet. */
148/* - If header is bad, */
149/* MMIOERR_INVALID_STRUCTURE is set in */
150/* ulErrorRet */
151/* */
152/* MMIOM_SETHEADER */
153/* Success - Returns number of bytes written */
154/* Failure - Return 0 */
155/* Other - If header is bad, */
156/* MMIOERR_INVALID_STRUCTURE is set in */
157/* ulErrorRet */
158/* */
159/* DESCRIPTION: */
160/* */
161/* This routine will translate JPEG image data into */
162/* OS/2 2.0 memory bitmap data and back again. */
163/* */
164/* */
165/* GLOBAL VARS REFERENCED: */
166/* */
167/* None */
168/* */
169/* GLOBAL VARS MODIFIED: */
170/* */
171/* None */
172/* */
173/* NOTES: */
174/* */
175/* None */
176/* */
177/* SIDE EFFECTS: */
178/* */
179/* None */
180/* */
181/************************************************************************/
182
183LONG EXPENTRY IOProc_Entry (PVOID pmmioStr,
184 USHORT usMsg,
185 LONG lParam1,
186 LONG lParam2)
187
188 {
189 PMMIOINFO pmmioinfo; /* MMIOINFO block */
190
191 pmmioinfo = (PMMIOINFO) pmmioStr;
192
193//DosBeep(5000, 30);
194#ifdef DEBUG
195 writeLog("MSG: %d %x\n", usMsg,usMsg);
196#endif
197
198 switch (usMsg)
199 {
200 /*#############################################################*
201 * When Closing the file, perform the following:
202 * 1) Setup Variables
203 * 2) Process the Image buffer
204 * 3) Compress the Image to appropriate format
205 *#############################################################*/
206 case MMIOM_CLOSE:
207 {
208 /************************************************************
209 * Declare local variables.
210 ************************************************************/
211
212
213 LONG lRetCode;
214 USHORT rc;
215
216#ifdef DEBUG
217 writeLog("MMIO_CLOSE\n");
218#endif
219
220 return (MMIO_ERROR);
221#if 0
222 /***********************************************************
223 * Check for valid MMIOINFO block.
224 ***********************************************************/
225 if (!pmmioinfo)
226 return (MMIO_ERROR);
227
228 /***********************************************************
229 * Set up our working file status variable.
230 ***********************************************************/
231 pJPGInfo = (PJPGFILESTATUS)pmmioinfo->pExtraInfoStruct;
232
233 /***********************************************************
234 * Assume success for the moment....
235 ***********************************************************/
236 lRetCode = MMIO_SUCCESS;
237
238 /************************************************************
239 * see if we are in Write mode and have a buffer to write out.
240 * We have no image buffer in UNTRANSLATED mode.
241 ************************************************************/
242 if ((pmmioinfo->ulFlags & MMIO_WRITE) && (pJPGInfo->lpRGBBuf))
243 {
244 /* Write the buffer to disk */
245 }
246
247 /***********************************************************
248 * Close the file
249 ***********************************************************/
250 return (lRetCode);
251#endif
252 } /* end case of MMIOM_CLOSE */
253
254 /*#############################################################*
255 * Get the NLS format Information.
256 *#############################################################*/
257 case MMIOM_GETFORMATINFO:
258 {
259 /***********************************************************
260 * Declare local variables.
261 ***********************************************************/
262 PMMFORMATINFO pmmformatinfo;
263
264#ifdef DEBUG
265 writeLog("MMIO_GETFORMATINFO\n");
266#endif
267#if 0
268 /************************************************************
269 * Set pointer to MMFORMATINFO structure.
270 ************************************************************/
271 pmmformatinfo = (PMMFORMATINFO) lParam1;
272
273 /************************************************************
274 * Fill in the values for the MMFORMATINFO structure.
275 ************************************************************/
276 pmmformatinfo->ulStructLen = sizeof (MMFORMATINFO);
277 pmmformatinfo->fccIOProc = FOURCC_STREAM;
278 pmmformatinfo->ulIOProcType = MMIO_IOPROC_FILEFORMAT;
279 pmmformatinfo->ulMediaType = MMIO_MEDIATYPE_IMAGE;
280
281 pmmformatinfo->ulFlags = MMIO_CANREADTRANSLATED |
282 MMIO_CANSEEKTRANSLATED |
283 MMIO_CANWRITETRANSLATED
284 /* MMIO_CANREADUNTRANSLATED |
285 MMIO_CANSEEKUNTRANSLATED */;
286
287 strcpy ((PSZ) pmmformatinfo->szDefaultFormatExt, pszJPGExt);
288 if (GetNLSData( &pmmformatinfo->ulCodePage,
289 &pmmformatinfo->ulLanguage ))
290 {
291 return( -1L );
292 }
293
294 if (GetFormatStringLength( FOURCC_JPG,
295 &(pmmformatinfo->lNameLength) ))
296 {
297 return( -1L );
298 }
299#endif
300
301 return (MMIO_ERROR);
302
303 /************************************************************
304 * Return success back to the application.
305 ************************************************************/
306 return (MMIO_SUCCESS);
307 } /* end case of MMIOM_GETFORMATINFO */
308
309 /*#############################################################*
310 * Get the NLS format name.
311 *#############################################################*/
312 case MMIOM_GETFORMATNAME:
313 {
314 LONG lBytesCopied;
315
316#ifdef DEBUG
317 writeLog("MMIO_GETFORMATNAME\n");
318#endif
319
320 /************************************************************
321 * Copy format string into buffer supplied by
322 * lParam1. Only put in the amount of my string up to the
323 * allocated amount which is in lParam2. Leave enough room
324 * for the NULL termination.
325 ************************************************************/
326 lBytesCopied = GetFormatString( FOURCC_STREAM,
327 (char *)lParam1,
328 lParam2 );
329
330 return (lBytesCopied);
331 } /* end case of MMIOM_GETFORMATNAME */
332
333 /*#############################################################*
334 * Identify whether this file can be processed.
335 *#############################################################*/
336 case MMIOM_IDENTIFYFILE:
337 {
338
339 /************************************************************
340 * Declare local variables.
341 ************************************************************/
342
343 BOOL bValidJPG= FALSE;
344
345 ULONG ulTempFlags = MMIO_READ | MMIO_DENYWRITE |
346 MMIO_NOIDENTIFY;
347 /* flags used for temp open */
348 /* and close */
349#ifdef DEBUG
350 writeLog("MMIO_IDENTIFYFILE\n");
351#endif
352
353 /************************************************************
354 * We need either a file name (lParam1) or file handle (lParam2)
355 ************************************************************/
356 if (!lParam1 && !lParam2)
357 return (MMIO_ERROR);
358
359
360 return (MMIO_ERROR);
361
362 } /* end case of MMIOM_IDENTIFYFILE */
363
364 /*#############################################################*/
365 /*#############################################################*/
366 case MMIOM_OPEN:
367 {
368
369 /************************************************************
370 * Declare local variables
371 ************************************************************/
372#ifdef DEBUG
373 writeLog("MMIO_OPEN\n");
374#endif
375 /************************************************************
376 * Check for valid MMIOINFO block.
377 ************************************************************/
378 if (!pmmioinfo)
379 return (MMIO_ERROR);
380
381 return (MMIO_ERROR);
382
383 } /* end case of MMIOM_OPEN */
384
385 /*#############################################################*/
386 /*#############################################################*/
387 case MMIOM_READ:
388 {
389
390 /************************************************************
391 * Declare Local Variables
392 ************************************************************/
393 /* PJPGFILESTATUS pJPGInfo; */
394 LONG rc;
395 LONG lBytesToRead;
396
397#ifdef DEBUG
398 writeLog("MMIO_READ\n");
399#endif
400
401 /************************************************************
402 * Check for valid MMIOINFO block.
403 ************************************************************/
404 if (!pmmioinfo)
405 return (MMIO_ERROR);
406
407 return (MMIO_ERROR);
408
409 } /* end case of MMIOM_READ */
410
411 /*#############################################################*/
412 /*#############################################################*/
413
414 /*
415 * If the IOProc has a child IOProc, then pass the message on to the Child, otherwise
416 * return Unsupported Message
417 */
418 default:
419 {
420 /*
421 * Declare Local Variables.
422 */
423 // PMMFILESTATUS pVidInfo;
424 LONG lRC;
425
426 /************************************************************
427 * Check for valid MMIOINFO block.
428 ************************************************************/
429 if (!pmmioinfo)
430 return (MMIO_ERROR);
431
432 /* !!!!!!!!!!!! FIXME !!!!!!!!!!!!!*/
433 return (MMIOERR_UNSUPPORTED_MESSAGE);
434 } /* end case of Default */
435
436 } /* end SWITCH statement for MMIO messages */
437
438 return (0);
439 } /* end of window procedure */
Note: See TracBrowser for help on using the repository browser.