[videodb] Remove nested transaction when saving state after stopping PVR playback
[xbmc.git] / xbmc / filesystem / IFile.h
blobd76d6ed1adf83ceaad281c52c4d2cb10ffde5e0f
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
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 * See LICENSES/README.md for more information.
9 */
11 #pragma once
13 // IFile.h: interface for the IFile class.
15 //////////////////////////////////////////////////////////////////////
17 #include "PlatformDefs.h" // for __stat64, ssize_t
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <sys/stat.h>
22 #include <string>
23 #include <vector>
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
35 #include "IFileTypes.h"
37 class CURL;
39 namespace XFILE
42 class IFile
44 public:
45 IFile();
46 virtual ~IFile();
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;
52 /**
53 * Fills struct __stat64 with information about file specified by url.
54 * For st_mode function will set correctly _S_IFDIR (directory) flag and may set
55 * _S_IREAD (read permission), _S_IWRITE (write permission) flags if such
56 * information is available. Function may set st_size (file size), st_atime,
57 * st_mtime, st_ctime (access, modification, creation times).
58 * Any other flags and members of __stat64 that didn't updated with actual file
59 * information will be set to zero (st_nlink can be set ether to 1 or zero).
60 * @param url specifies requested file
61 * @param buffer pointer to __stat64 buffer to receive information about file
62 * @return zero of success, -1 otherwise.
64 virtual int Stat(const CURL& url, struct __stat64* buffer) = 0;
65 /**
66 * Fills struct __stat64 with information about currently open file
67 * For st_mode function will set correctly _S_IFDIR (directory) flag and may set
68 * _S_IREAD (read permission), _S_IWRITE (write permission) flags if such
69 * information is available. Function may set st_size (file size), st_atime,
70 * st_mtime, st_ctime (access, modification, creation times).
71 * Any other flags and members of __stat64 that didn't updated with actual file
72 * information will be set to zero (st_nlink can be set ether to 1 or zero).
73 * @param buffer pointer to __stat64 buffer to receive information about file
74 * @return zero of success, -1 otherwise.
76 virtual int Stat(struct __stat64* buffer);
77 /**
78 * Attempt to read bufSize bytes from currently opened file into buffer bufPtr.
79 * @param bufPtr pointer to buffer
80 * @param bufSize size of the buffer
81 * @return number of successfully read bytes if any bytes were read and stored in
82 * buffer, zero if no bytes are available to read (end of file was reached)
83 * or undetectable error occur, -1 in case of any explicit error
85 virtual ssize_t Read(void* bufPtr, size_t bufSize) = 0;
86 /**
87 * Attempt to write bufSize bytes from buffer bufPtr into currently opened file.
88 * @param bufPtr pointer to buffer
89 * @param bufSize size of the buffer
90 * @return number of successfully written bytes if any bytes were written,
91 * zero if no bytes were written and no detectable error occur,
92 * -1 in case of any explicit error
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; }
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; }
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; }
116 virtual int IoControl(EIoControl request, void* param) { return -1; }
118 virtual const std::string GetProperty(XFILE::FileProperty type, const std::string &name = "") const
120 return type == XFILE::FILE_PROPERTY_CONTENT_TYPE ? "application/octet-stream" : "";
123 virtual const std::vector<std::string> GetPropertyValues(XFILE::FileProperty type, const std::string &name = "") const
125 std::vector<std::string> values;
126 std::string value = GetProperty(type, name);
127 if (!value.empty())
129 values.emplace_back(value);
131 return values;
135 class CRedirectException
137 public:
138 IFile *m_pNewFileImp;
139 CURL *m_pNewUrl;
141 CRedirectException();
143 CRedirectException(IFile *pNewFileImp, CURL *pNewUrl=NULL);