ovr_sdk

annotate LibOVR/Src/Kernel/OVR_SysFile.cpp @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
rev   line source
nuclear@0 1 /**************************************************************************
nuclear@0 2
nuclear@0 3 Filename : OVR_SysFile.cpp
nuclear@0 4 Content : File wrapper class implementation (Win32)
nuclear@0 5
nuclear@0 6 Created : April 5, 1999
nuclear@0 7 Authors : Michael Antonov
nuclear@0 8
nuclear@0 9 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
nuclear@0 10
nuclear@0 11 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
nuclear@0 12 you may not use the Oculus VR Rift SDK except in compliance with the License,
nuclear@0 13 which is provided at the time of installation or download, or which
nuclear@0 14 otherwise accompanies this software in either electronic or hard copy form.
nuclear@0 15
nuclear@0 16 You may obtain a copy of the License at
nuclear@0 17
nuclear@0 18 http://www.oculusvr.com/licenses/LICENSE-3.2
nuclear@0 19
nuclear@0 20 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
nuclear@0 21 distributed under the License is distributed on an "AS IS" BASIS,
nuclear@0 22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nuclear@0 23 See the License for the specific language governing permissions and
nuclear@0 24 limitations under the License.
nuclear@0 25
nuclear@0 26 **************************************************************************/
nuclear@0 27
nuclear@0 28 #define GFILE_CXX
nuclear@0 29
nuclear@0 30 // Standard C library (Captain Obvious guarantees!)
nuclear@0 31 #include <stdio.h>
nuclear@0 32
nuclear@0 33 #include "OVR_SysFile.h"
nuclear@0 34 #include "OVR_Log.h"
nuclear@0 35
nuclear@0 36 namespace OVR {
nuclear@0 37
nuclear@0 38 // This is - a dummy file that fails on all calls.
nuclear@0 39
nuclear@0 40 class UnopenedFile : public File
nuclear@0 41 {
nuclear@0 42 public:
nuclear@0 43 UnopenedFile() { }
nuclear@0 44 ~UnopenedFile() { }
nuclear@0 45
nuclear@0 46 virtual const char* GetFilePath() { return 0; }
nuclear@0 47
nuclear@0 48 // ** File Information
nuclear@0 49 virtual bool IsValid() { return 0; }
nuclear@0 50 virtual bool IsWritable() { return 0; }
nuclear@0 51
nuclear@0 52 // Return position / file size
nuclear@0 53 virtual int Tell() { return 0; }
nuclear@0 54 virtual int64_t LTell() { return 0; }
nuclear@0 55 virtual int GetLength() { return 0; }
nuclear@0 56 virtual int64_t LGetLength() { return 0; }
nuclear@0 57
nuclear@0 58 // virtual bool Stat(FileStats *pfs) { return 0; }
nuclear@0 59 virtual int GetErrorCode() { return Error_FileNotFound; }
nuclear@0 60
nuclear@0 61 // ** Stream implementation & I/O
nuclear@0 62 virtual int Write(const uint8_t * /*pbuffer*/, int /*numBytes*/) { return -1; }
nuclear@0 63 virtual int Read(uint8_t * /*pbuffer*/, int /*numBytes*/) { return -1; }
nuclear@0 64 virtual int SkipBytes(int /*numBytes*/) { return 0; }
nuclear@0 65 virtual int BytesAvailable() { return 0; }
nuclear@0 66 virtual bool Flush() { return 0; }
nuclear@0 67 virtual int Seek(int /*offset*/, int /*origin*/) { return -1; }
nuclear@0 68 virtual int64_t LSeek(int64_t /*offset*/, int /*origin*/) { return -1; }
nuclear@0 69
nuclear@0 70 virtual int CopyFromStream(File * /*pstream*/, int /*byteSize*/) { return -1; }
nuclear@0 71 virtual bool Close() { return 0; }
nuclear@0 72 };
nuclear@0 73
nuclear@0 74
nuclear@0 75
nuclear@0 76 // ***** System File
nuclear@0 77
nuclear@0 78 // System file is created to access objects on file system directly
nuclear@0 79 // This file can refer directly to path
nuclear@0 80
nuclear@0 81 // ** Constructor
nuclear@0 82 SysFile::SysFile() : DelegatedFile(0)
nuclear@0 83 {
nuclear@0 84 pFile = *new UnopenedFile;
nuclear@0 85 }
nuclear@0 86
nuclear@0 87 Ptr<File> FileFILEOpen(const String& path, int flags, int mode);
nuclear@0 88
nuclear@0 89 // Opens a file
nuclear@0 90 SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0)
nuclear@0 91 {
nuclear@0 92 Open(path, flags, mode);
nuclear@0 93 }
nuclear@0 94
nuclear@0 95
nuclear@0 96 // ** Open & management
nuclear@0 97 // Will fail if file's already open
nuclear@0 98 bool SysFile::Open(const String& path, int flags, int mode)
nuclear@0 99 {
nuclear@0 100 pFile = FileFILEOpen(path, flags, mode);
nuclear@0 101 if ((!pFile) || (!pFile->IsValid()))
nuclear@0 102 {
nuclear@0 103 pFile = *new UnopenedFile;
nuclear@0 104 OVR_DEBUG_LOG(("Failed to open file: %s", path.ToCStr()));
nuclear@0 105 return 0;
nuclear@0 106 }
nuclear@0 107 //pFile = *OVR_NEW DelegatedFile(pFile); // MA Testing
nuclear@0 108 if (flags & Open_Buffered)
nuclear@0 109 pFile = *new BufferedFile(pFile);
nuclear@0 110 return 1;
nuclear@0 111 }
nuclear@0 112
nuclear@0 113
nuclear@0 114 // ** Overrides
nuclear@0 115
nuclear@0 116 int SysFile::GetErrorCode()
nuclear@0 117 {
nuclear@0 118 return pFile ? pFile->GetErrorCode() : Error_FileNotFound;
nuclear@0 119 }
nuclear@0 120
nuclear@0 121
nuclear@0 122 // Overrides to provide re-open support
nuclear@0 123 bool SysFile::IsValid()
nuclear@0 124 {
nuclear@0 125 return pFile && pFile->IsValid();
nuclear@0 126 }
nuclear@0 127 bool SysFile::Close()
nuclear@0 128 {
nuclear@0 129 if (IsValid())
nuclear@0 130 {
nuclear@0 131 DelegatedFile::Close();
nuclear@0 132 pFile = *new UnopenedFile;
nuclear@0 133 return 1;
nuclear@0 134 }
nuclear@0 135 return 0;
nuclear@0 136 }
nuclear@0 137
nuclear@0 138 } // OVR