xbmc
IFile.h
1 /*
2  * Copyright (c) 2002 Frodo
3  * Portions Copyright (c) by the authors of ffmpeg and xvid
4  * Copyright (C) 2002-2018 Team Kodi
5  * This file is part of Kodi - https://kodi.tv
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  * See LICENSES/README.md for more information.
9  */
10 
11 #pragma once
12 
13 // IFile.h: interface for the IFile class.
14 //
16 
17 #include "PlatformDefs.h" // for __stat64, ssize_t
18 
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <sys/stat.h>
22 #include <string>
23 #include <vector>
24 
25 #if !defined(SIZE_MAX) || !defined(SSIZE_MAX)
26 #include <limits.h>
27 #ifndef SIZE_MAX
28 #define SIZE_MAX UINTPTR_MAX
29 #endif // ! SIZE_MAX
30 #ifndef SSIZE_MAX
31 #define SSIZE_MAX INTPTR_MAX
32 #endif // ! SSIZE_MAX
33 #endif // ! SIZE_MAX || ! SSIZE_MAX
34 
35 #include "IFileTypes.h"
36 
37 class CURL;
38 
39 namespace XFILE
40 {
41 
42 class IFile
43 {
44 public:
45  IFile();
46  virtual ~IFile();
47 
48  virtual bool Open(const CURL& url) = 0;
49  virtual bool OpenForWrite(const CURL& url, bool bOverWrite = false) { return false; }
50  virtual bool ReOpen(const CURL& url) { return false; }
51  virtual bool Exists(const CURL& url) = 0;
64  virtual int Stat(const CURL& url, struct __stat64* buffer) = 0;
76  virtual int Stat(struct __stat64* buffer);
85  virtual ssize_t Read(void* bufPtr, size_t bufSize) = 0;
94  virtual ssize_t Write(const void* bufPtr, size_t bufSize) { return -1;}
95  virtual bool ReadString(char *szLine, int iLineLength);
96  virtual int64_t Seek(int64_t iFilePosition, int iWhence = SEEK_SET) = 0;
97  virtual void Close() = 0;
98  virtual int64_t GetPosition() = 0;
99  virtual int64_t GetLength() = 0;
100  virtual void Flush() { }
101  virtual int Truncate(int64_t size) { return -1; }
102 
103  /* Returns the minimum size that can be read from input stream. *
104  * For example cdrom access where access could be sector based. *
105  * This will cause file system to buffer read requests, to *
106  * to meet the requirement of CFile. *
107  * It can also be used to indicate a file system is non buffered *
108  * but accepts any read size, have it return the value 1 */
109  virtual int GetChunkSize() {return 0;}
110  virtual double GetDownloadSpeed() { return 0.0; }
111 
112  virtual bool Delete(const CURL& url) { return false; }
113  virtual bool Rename(const CURL& url, const CURL& urlnew) { return false; }
114  virtual bool SetHidden(const CURL& url, bool hidden) { return false; }
115 
116  virtual int IoControl(EIoControl request, void* param) { return -1; }
117 
118  virtual const std::string GetProperty(XFILE::FileProperty type, const std::string &name = "") const
119  {
120  return type == XFILE::FILE_PROPERTY_CONTENT_TYPE ? "application/octet-stream" : "";
121  };
122 
123  virtual const std::vector<std::string> GetPropertyValues(XFILE::FileProperty type, const std::string &name = "") const
124  {
125  std::vector<std::string> values;
126  std::string value = GetProperty(type, name);
127  if (!value.empty())
128  {
129  values.emplace_back(value);
130  }
131  return values;
132  }
133 };
134 
136 {
137 public:
138  IFile *m_pNewFileImp;
139  CURL *m_pNewUrl;
140 
142 
143  CRedirectException(IFile *pNewFileImp, CURL *pNewUrl=NULL);
144 };
145 
146 }
Definition: IFile.h:135
Definition: Scraper.h:41
Definition: URL.h:20
virtual ssize_t Read(void *bufPtr, size_t bufSize)=0
Attempt to read bufSize bytes from currently opened file into buffer bufPtr.
Definition: IFile.h:42
virtual ssize_t Write(const void *bufPtr, size_t bufSize)
Attempt to write bufSize bytes from buffer bufPtr into currently opened file.
Definition: IFile.h:94
virtual int Stat(const CURL &url, struct __stat64 *buffer)=0
Fills struct __stat64 with information about file specified by url.