1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 // -*- c++ -*- 19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 20 21 // O S C L _ F I L E _ N A T I V E 22 23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 24 25 /*! \addtogroup osclio OSCL IO 26 * 27 * @{ 28 */ 29 30 31 /*! \file oscl_file_native.h 32 \brief The file oscl_file_native.h defines the class OsclNativeFile. 33 This is the porting layer for basic file I/O operations. 34 */ 35 36 #ifndef OSCL_FILE_NATIVE_H_INCLUDED 37 #define OSCL_FILE_NATIVE_H_INCLUDED 38 39 #ifndef OSCLCONFIG_IO_H_INCLUDED 40 #include "osclconfig_io.h" 41 #endif 42 43 #ifndef OSCL_BASE_H_INCLUDED 44 #include "oscl_base.h" 45 #endif 46 47 #ifndef OSCL_AOSTATUS_H_INCLUDED 48 #include "oscl_aostatus.h" 49 #endif 50 51 #ifndef OSCL_FILE_IO_H_INCLUDED 52 #include "oscl_file_io.h" 53 #endif 54 55 #ifndef OSCL_FILE_TYPES_H_INCLUDED 56 #include "oscl_file_types.h" 57 #endif 58 59 60 /** 61 * OsclNativeFileIO defines the native file operations that must be implemented 62 * by every Oscl platform. 63 */ 64 65 class Oscl_FileServer; 66 class OsclNativeFile : public HeapBase 67 { 68 public: 69 OsclNativeFile(); 70 ~OsclNativeFile(); 71 72 // These are the Native OS File IO calls. 73 int32 Open(const OsclFileHandle&, uint32 mode 74 , const OsclNativeFileParams& params 75 , Oscl_FileServer& fileserv); 76 int32 Open(const oscl_wchar *filename, uint32 mode 77 , const OsclNativeFileParams& params 78 , Oscl_FileServer& fileserv); 79 int32 Open(const char *filename, uint32 mode 80 , const OsclNativeFileParams& params 81 , Oscl_FileServer& fileserv); 82 uint32 Read(OsclAny *buffer, uint32 size, uint32 numelements); 83 uint32 Write(const OsclAny *buffer, uint32 size, uint32 numelements); 84 int32 Seek(TOsclFileOffset offset, Oscl_File::seek_type origin); 85 TOsclFileOffset Tell(); 86 int32 Flush(); 87 int32 EndOfFile(); 88 TOsclFileOffset Size(); 89 int32 Close(); 90 91 //query for current open mode. Mode()92 uint32 Mode() 93 { 94 return iMode; 95 } 96 97 //get last filesystem error. 98 int32 GetError(); 99 100 /*! 101 ** Asynchronous read. 102 ** 103 ** @param buffer: data buffer, must be at least size*numelements bytes 104 ** @param size: size of elements 105 ** @param numelements: number of elements to read 106 ** @param status: Request status for asynchronous completion 107 ** @returns: 0 for success. 108 **/ 109 int32 ReadAsync(OsclAny*buffer, uint32 size, uint32 numelements, OsclAOStatus& status); 110 /*! 111 ** Get the number of elements read in the last call to ReadAsync. 112 ** @returns: number of elements read. 113 **/ 114 uint32 GetReadAsyncNumElements(); 115 /*! 116 ** @returns: true if async read is supported natively. 117 **/ 118 bool HasAsyncRead(); 119 /*! 120 ** Cancel any pending async read. 121 **/ 122 void ReadAsyncCancel(); 123 124 private: 125 int32 OpenFileOrSharedFd(const char *filename, const char *openmode); 126 127 //current open mode 128 uint32 iMode; 129 130 //was an open file handle passed in? 131 bool iOpenFileHandle; 132 133 //native file object. 134 FILE* iFile; 135 136 #ifdef ENABLE_SHAREDFD_PLAYBACK 137 int iSharedFd; 138 long long iSharedFileOffset; 139 long long iSharedFileSize; 140 long long iSharedFilePosition; 141 #endif 142 }; 143 144 #endif // OSCL_FILE_NATIVE_H_INCLUDED 145 146 /*! @} */ 147 148