ovr_sdk
diff 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 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/LibOVR/Src/Kernel/OVR_SysFile.cpp Wed Jan 14 06:51:16 2015 +0200 1.3 @@ -0,0 +1,138 @@ 1.4 +/************************************************************************** 1.5 + 1.6 +Filename : OVR_SysFile.cpp 1.7 +Content : File wrapper class implementation (Win32) 1.8 + 1.9 +Created : April 5, 1999 1.10 +Authors : Michael Antonov 1.11 + 1.12 +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. 1.13 + 1.14 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 1.15 +you may not use the Oculus VR Rift SDK except in compliance with the License, 1.16 +which is provided at the time of installation or download, or which 1.17 +otherwise accompanies this software in either electronic or hard copy form. 1.18 + 1.19 +You may obtain a copy of the License at 1.20 + 1.21 +http://www.oculusvr.com/licenses/LICENSE-3.2 1.22 + 1.23 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 1.24 +distributed under the License is distributed on an "AS IS" BASIS, 1.25 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.26 +See the License for the specific language governing permissions and 1.27 +limitations under the License. 1.28 + 1.29 +**************************************************************************/ 1.30 + 1.31 +#define GFILE_CXX 1.32 + 1.33 +// Standard C library (Captain Obvious guarantees!) 1.34 +#include <stdio.h> 1.35 + 1.36 +#include "OVR_SysFile.h" 1.37 +#include "OVR_Log.h" 1.38 + 1.39 +namespace OVR { 1.40 + 1.41 +// This is - a dummy file that fails on all calls. 1.42 + 1.43 +class UnopenedFile : public File 1.44 +{ 1.45 +public: 1.46 + UnopenedFile() { } 1.47 + ~UnopenedFile() { } 1.48 + 1.49 + virtual const char* GetFilePath() { return 0; } 1.50 + 1.51 + // ** File Information 1.52 + virtual bool IsValid() { return 0; } 1.53 + virtual bool IsWritable() { return 0; } 1.54 + 1.55 + // Return position / file size 1.56 + virtual int Tell() { return 0; } 1.57 + virtual int64_t LTell() { return 0; } 1.58 + virtual int GetLength() { return 0; } 1.59 + virtual int64_t LGetLength() { return 0; } 1.60 + 1.61 +// virtual bool Stat(FileStats *pfs) { return 0; } 1.62 + virtual int GetErrorCode() { return Error_FileNotFound; } 1.63 + 1.64 + // ** Stream implementation & I/O 1.65 + virtual int Write(const uint8_t * /*pbuffer*/, int /*numBytes*/) { return -1; } 1.66 + virtual int Read(uint8_t * /*pbuffer*/, int /*numBytes*/) { return -1; } 1.67 + virtual int SkipBytes(int /*numBytes*/) { return 0; } 1.68 + virtual int BytesAvailable() { return 0; } 1.69 + virtual bool Flush() { return 0; } 1.70 + virtual int Seek(int /*offset*/, int /*origin*/) { return -1; } 1.71 + virtual int64_t LSeek(int64_t /*offset*/, int /*origin*/) { return -1; } 1.72 + 1.73 + virtual int CopyFromStream(File * /*pstream*/, int /*byteSize*/) { return -1; } 1.74 + virtual bool Close() { return 0; } 1.75 +}; 1.76 + 1.77 + 1.78 + 1.79 +// ***** System File 1.80 + 1.81 +// System file is created to access objects on file system directly 1.82 +// This file can refer directly to path 1.83 + 1.84 +// ** Constructor 1.85 +SysFile::SysFile() : DelegatedFile(0) 1.86 +{ 1.87 + pFile = *new UnopenedFile; 1.88 +} 1.89 + 1.90 +Ptr<File> FileFILEOpen(const String& path, int flags, int mode); 1.91 + 1.92 +// Opens a file 1.93 +SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0) 1.94 +{ 1.95 + Open(path, flags, mode); 1.96 +} 1.97 + 1.98 + 1.99 +// ** Open & management 1.100 +// Will fail if file's already open 1.101 +bool SysFile::Open(const String& path, int flags, int mode) 1.102 +{ 1.103 + pFile = FileFILEOpen(path, flags, mode); 1.104 + if ((!pFile) || (!pFile->IsValid())) 1.105 + { 1.106 + pFile = *new UnopenedFile; 1.107 + OVR_DEBUG_LOG(("Failed to open file: %s", path.ToCStr())); 1.108 + return 0; 1.109 + } 1.110 + //pFile = *OVR_NEW DelegatedFile(pFile); // MA Testing 1.111 + if (flags & Open_Buffered) 1.112 + pFile = *new BufferedFile(pFile); 1.113 + return 1; 1.114 +} 1.115 + 1.116 + 1.117 +// ** Overrides 1.118 + 1.119 +int SysFile::GetErrorCode() 1.120 +{ 1.121 + return pFile ? pFile->GetErrorCode() : Error_FileNotFound; 1.122 +} 1.123 + 1.124 + 1.125 +// Overrides to provide re-open support 1.126 +bool SysFile::IsValid() 1.127 +{ 1.128 + return pFile && pFile->IsValid(); 1.129 +} 1.130 +bool SysFile::Close() 1.131 +{ 1.132 + if (IsValid()) 1.133 + { 1.134 + DelegatedFile::Close(); 1.135 + pFile = *new UnopenedFile; 1.136 + return 1; 1.137 + } 1.138 + return 0; 1.139 +} 1.140 + 1.141 +} // OVR