Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

mxcpcStreamFile_win.cpp

Go to the documentation of this file.
00001 //           ///          //                                        Mx clientSDK
00002 //          /////        ////                    Mx Crossplatform Client Library
00003 //         /// XXX     XXX ///
00004 //        ///    XXX XXX    ///     $RCSfile: mxcpcStreamFile_win.cpp,v $
00005 //       ///       XXX       ///     $Revision: 1.5 $
00006 //      ///      XXX XXX      ///     $Date: 2006/01/16 15:37:00 $
00007 //     ////    XXX     XXX    ////     $Author: cvs-kai $
00008 //    ////                     ////
00009 //   ////  M  O  B  O  T  I  X  ////////////////////////////////////////////////
00010 //  //// Security Vision Systems //////////////////////////////////////////////
00011 //                                                                          //
00012 //  Copyright (C) 2005 - 2006, MOBOTIX AG, Germany                         //
00013 //  This software is made available under the BSD licence. Please refer   //
00014 //  to the file LICENCE.TXT contained in this distribution for details.  //
00015 //                                                                      //
00016 //  /////////////////////////////////////////////////////////////////////
00017 
00018 
00019 
00020 #include <mxcpcStreamFile.h>
00021 
00022 #include <fcntl.h>
00023 #include <windows.h>
00024 
00025 
00026 
00027 /*! 
00028  *  \file mxcpcStreamFile_win.cpp
00029  *
00030  *  \brief Alternate implementation for the <tt>WINDOWS</tt> platform
00031  * 
00032  *  Differs from the original <tt>POSIX</tt>-dependent implementation in that 
00033  *  we explicitly have to request binary mode when doing an <tt>open()</tt> or
00034  *  <tt>fopen()</tt> to avoid having our carriage returns (13s) implicitly 
00035  *  toasted.
00036  */
00037 
00038  
00039 
00040 mxcpcStreamFile::mxcpcStreamFile(const char *filename) {
00041 
00042   InFile = open(filename, O_RDONLY | O_BINARY);
00043   
00044   if(InFile == -1) {
00045     CloseFileUponDestruction = false;
00046     StillUp = false;
00047   }
00048   else {
00049     OSFHandle = _get_osfhandle(InFile);
00050     CloseFileUponDestruction = true;
00051     StillUp = true;
00052   }
00053   
00054   RestoreMode = -1;
00055   
00056   TimedBlockMode = false;
00057   BlockTimeout   = 1000;
00058 }
00059 
00060 
00061 mxcpcStreamFile::mxcpcStreamFile(int fd) {
00062 
00063   InFile = fd;
00064   
00065   if((RestoreMode = setmode(fd, O_BINARY)) != -1) { 
00066     OSFHandle = _get_osfhandle(InFile);
00067     StillUp = true;
00068   }
00069   else {
00070     StillUp = false;
00071   }
00072   
00073   CloseFileUponDestruction = false;
00074   
00075   TimedBlockMode = false;
00076   BlockTimeout   = 1000;
00077 }
00078 
00079 
00080 mxcpcStreamFile::~mxcpcStreamFile() {
00081 
00082   if(RestoreMode != -1) setmode(InFile, RestoreMode);
00083   
00084   if(CloseFileUponDestruction) close(InFile);
00085 }
00086 
00087 
00088 
00089 void mxcpcStreamFile::setTimedBlockModeEnabled(bool enabled, long timeout) {
00090 
00091   TimedBlockMode = enabled;
00092   
00093   if(TimedBlockMode) BlockTimeout = timeout;
00094 }
00095 
00096 
00097 int mxcpcStreamFile::fetchBytes(unsigned char *buffer, int num) {
00098 
00099   int actually_read;
00100   
00101   if(!StillUp) return(0);
00102   
00103   if(TimedBlockMode) {
00104     if(WaitForSingleObject((HANDLE)OSFHandle, BlockTimeout) 
00105         == WAIT_TIMEOUT) return(0);
00106   }
00107   
00108   actually_read = read(InFile, buffer, num);
00109    
00110   if(actually_read <= 0) {
00111   
00112     StillUp = false;
00113     return(0);
00114   }
00115   
00116   return(actually_read);
00117 }
00118 
00119 
00120 bool mxcpcStreamFile::stillUp(void) {
00121 
00122   return(StillUp);
00123 }
00124 

Generated on Mon Jan 30 15:52:44 2006 for mxcpc by  doxygen 1.4.4