Main Page | Compound List | File List | Compound Members | File Members

bytestreambe.cc

Go to the documentation of this file.
00001 /*--------------------------------------------------------------------
00002  *
00003  * (C) Copyright Koninklijke Philips Electronics NV 2006. 
00004  * All rights reserved. This software is licensed under the terms of
00005  * version 2.1 of the GNU Lesser General Public License as published 
00006  * by the Free Software Foundation. For licensing and warranty
00007  * information, see the file COPYING in the main directory.
00008  *
00009  *------------------------------------------------------------------*/
00010 
00011 #include <stdlib.h>
00012 #include <stdio.h>
00013 #include "bytestreambe.h"
00014 
00015 byteStreamBE::byteStreamBE(
00016     const Id&            n,
00017     In<VYAfileName>&     fileNameF,
00018     In<int>&             nrBytesF,
00019     In<unsigned char>&   byteStreamF)    
00020 :
00021     VYAprocess(n),
00022     fileNameP(id("fileName"),fileNameF),
00023     nrBytesP(id("nrBytes"),nrBytesF),
00024     byteStreamP(id("byteStream"),byteStreamF)
00025 {}
00026 
00027 const char* byteStreamBE::type() const
00028 {
00029     return "byteStreamBE";
00030 }
00031 
00032 void byteStreamBE::main()
00033 {
00034   while(true)
00035   {
00036       FILE           *fptr;
00037       unsigned char  data;
00038       int            nrBytesWritten = 0;
00039 
00040       read(fileNameP, fileName);
00041       fptr=fopen(fileName, "wb");
00042       if (!fptr) {
00043           printf("%s: error opening output file \"%s\"\n", fullName(),(const char*)fileName);
00044           exit(1);
00045       }
00046       #ifdef VERBOSE
00047       else
00048           printf("%s: writing data to %s\n", fullName(),(const char*)fileName);
00049       #endif
00050 
00051       read(nrBytesP, nrBytes);
00052       if (nrBytes < 0) {
00053           printf("%s: error: negative number of bytes requested (%i)\n", fullName(), nrBytes);
00054           exit(1);
00055       }
00056 
00057       while ((nrBytesWritten != nrBytes) || (nrBytes == 0))
00058       {
00059           read(byteStreamP, data);
00060           if (!fwrite(&data, sizeof(unsigned char), 1, fptr))
00061           {
00062             printf("%s: error writing output file %s\n", fullName(),(const char*)fileName);
00063             exit(1);
00064           }
00065           else
00066           {
00067             nrBytesWritten++;
00068           }
00069       }
00070 
00071       #ifdef VERBOSE
00072       if (nrBytesWritten != 1)
00073           printf("%s: finished; wrote %i bytes to output file\n", fullName(), nrBytesWritten);
00074       else
00075           printf("%s: finished; wrote 1 byte to output file\n", fullName());
00076       #endif
00077 
00078       fclose(fptr);
00079   }
00080 }

Generated on Wed Feb 15 14:52:43 2006 for bytestreamfebe by doxygen 1.3.2