Merge pull request #473 from Montellese/onplaybackspeedchanged
[vuplus_xbmc] / xbmc / filesystem / IFile.h
1 /*
2 * XBMC Media Center
3 * Copyright (c) 2002 Frodo
4 * Portions Copyright (c) by the authors of ffmpeg and xvid
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 // IFile.h: interface for the IFile class.
21 //
22 //////////////////////////////////////////////////////////////////////
23
24 #if !defined(AFX_IFILE_H__7EE73AC7_36BC_4822_93FF_44F3B0C766F6__INCLUDED_)
25 #define AFX_IFILE_H__7EE73AC7_36BC_4822_93FF_44F3B0C766F6__INCLUDED_
26
27 #if _MSC_VER > 1000
28 #pragma once
29 #endif // _MSC_VER > 1000
30
31 #ifdef _LINUX
32 #include "PlatformDefs.h" // for __stat64
33 #endif
34
35 #include "URL.h"
36
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <sys/stat.h>
40
41 namespace XFILE
42 {
43
44 struct SNativeIoControl
45 {
46   int   request;
47   void* param;
48 };
49
50 struct SCacheStatus
51 {
52   uint64_t forward;  /**< number of bytes cached forward of current position */
53   unsigned maxrate;  /**< maximum number of bytes per second cache is allowed to fill */
54   unsigned currate;  /**< average read rate from source file since last position change */
55   bool     full;     /**< is the cache full */
56 };
57
58 typedef enum {
59   IOCTRL_NATIVE        = 1, /**< SNativeIoControl structure, containing what should be passed to native ioctrl */
60   IOCTRL_SEEK_POSSIBLE = 2, /**< return 0 if known not to work, 1 if it should work */
61   IOCTRL_CACHE_STATUS  = 3, /**< SCacheStatus structure */
62   IOCTRL_CACHE_SETRATE = 4, /**< unsigned int with with speed limit for caching in bytes per second */
63 } EIoControl;
64
65 class IFile
66 {
67 public:
68   IFile();
69   virtual ~IFile();
70
71   virtual bool Open(const CURL& url) = 0;
72   virtual bool OpenForWrite(const CURL& url, bool bOverWrite = false) { return false; };
73   virtual bool Exists(const CURL& url) = 0;
74   virtual int Stat(const CURL& url, struct __stat64* buffer) = 0;
75   virtual int Stat(struct __stat64* buffer);
76   virtual unsigned int Read(void* lpBuf, int64_t uiBufSize) = 0;
77   virtual int Write(const void* lpBuf, int64_t uiBufSize) { return -1;};
78   virtual bool ReadString(char *szLine, int iLineLength);
79   virtual int64_t Seek(int64_t iFilePosition, int iWhence = SEEK_SET) = 0;
80   virtual void Close() = 0;
81   virtual int64_t GetPosition() = 0;
82   virtual int64_t GetLength() = 0;
83   virtual void Flush() { }
84
85   /* Returns the minium size that can be read from input stream.   *
86    * For example cdrom access where access could be sector based.  *
87    * This will cause file system to buffer read requests, to       *
88    * to meet the requirement of CFile.                             *
89    * It can also be used to indicate a file system is non buffered *
90    * but accepts any read size, have it return the value 1         */
91   virtual int  GetChunkSize() {return 0;}
92
93   virtual bool SkipNext(){return false;}
94
95   virtual bool Delete(const CURL& url) { return false; }
96   virtual bool Rename(const CURL& url, const CURL& urlnew) { return false; }
97   virtual bool SetHidden(const CURL& url, bool hidden) { return false; }
98
99   virtual int IoControl(EIoControl request, void* param) { return -1; }
100
101   virtual CStdString GetContent()                            { return "application/octet-stream"; }
102 };
103
104 class CRedirectException
105 {
106 public:
107   IFile *m_pNewFileImp;
108   CURL  *m_pNewUrl;
109
110   CRedirectException() : m_pNewFileImp(NULL), m_pNewUrl(NULL) { }
111   
112   CRedirectException(IFile *pNewFileImp, CURL *pNewUrl=NULL) 
113   : m_pNewFileImp(pNewFileImp)
114   , m_pNewUrl(pNewUrl) 
115   { }
116 };
117
118 }
119
120 #endif // !defined(AFX_IFILE_H__7EE73AC7_36BC_4822_93FF_44F3B0C766F6__INCLUDED_)
121
122