Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial work on passing flags to IFile objects to allow for special handling of context. #1004

Closed
wants to merge 12 commits into from
3 changes: 3 additions & 0 deletions xbmc/filesystem/File.cpp
Expand Up @@ -233,10 +233,13 @@ bool CFile::Open(const CStdString& strFileName, unsigned int flags)
if (m_flags & READ_CACHED)
{
m_pFile = new CFileCache();
m_pFile->SetFlags(m_flags);
return m_pFile->Open(url);
}

m_pFile = CFileFactory::CreateLoader(url);
m_pFile->SetFlags(m_flags);

if (!m_pFile)
return false;

Expand Down
15 changes: 0 additions & 15 deletions xbmc/filesystem/File.h
Expand Up @@ -45,21 +45,6 @@ class IFileCallback
virtual ~IFileCallback() {};
};

/* indicate that caller can handle truncated reads, where function returns before entire buffer has been filled */
#define READ_TRUNCATED 0x01

/* indicate that that caller support read in the minimum defined chunk size, this disables internal cache then */
#define READ_CHUNKED 0x02

/* use cache to access this file */
#define READ_CACHED 0x04

/* open without caching. regardless to file type. */
#define READ_NO_CACHE 0x08

/* calcuate bitrate for file while reading */
#define READ_BITRATE 0x10

class CFileStreamBuffer;

class CFile
Expand Down
24 changes: 23 additions & 1 deletion xbmc/filesystem/FileCache.cpp
Expand Up @@ -154,8 +154,20 @@ bool CFileCache::Open(const CURL& url)
return false;
}

// Set default sane flags if no flags were set
if (m_flags == 0) {
// Set sane flags, and ensure that the cache flag gets cleared.
unsigned int flags = 0;
flags |= READ_NO_CACHE ;
flags |= READ_TRUNCATED ;
flags |= READ_CHUNKED ;
flags &= ~READ_CACHED ;
m_flags = flags ;
};


// opening the source file.
if (!m_source.Open(m_sourcePath, READ_NO_CACHE | READ_TRUNCATED | READ_CHUNKED))
if (!m_source.Open(m_sourcePath, m_flags))
{
CLog::Log(LOGERROR,"%s - failed to open source <%s>", __FUNCTION__, m_sourcePath.c_str());
Close();
Expand Down Expand Up @@ -482,3 +494,13 @@ int CFileCache::IoControl(EIoControl request, void* param)

return -1;
}

void CFileCache::SetFlags(unsigned int flags)
{
// Set sane flags, and ensure that the cache flag gets cleared.
flags |= READ_NO_CACHE ;
flags |= READ_TRUNCATED ;
flags |= READ_CHUNKED ;
flags &= ~READ_CACHED ;
m_flags = flags;
}
5 changes: 4 additions & 1 deletion xbmc/filesystem/FileCache.h
Expand Up @@ -60,7 +60,9 @@ namespace XFILE
IFile *GetFileImp();

virtual CStdString GetContent();


virtual void SetFlags(unsigned int flags);

private:
CCacheStrategy *m_pCache;
bool m_bDeleteCache;
Expand All @@ -78,6 +80,7 @@ namespace XFILE
unsigned m_writeRateActual;
bool m_cacheFull;
CCriticalSection m_sync;
unsigned int m_flags;
};

}
38 changes: 38 additions & 0 deletions xbmc/filesystem/FileFlags.h
@@ -0,0 +1,38 @@
/*
* XBMC Media Center
* Copyright (c) 2002 Frodo
* Portions Copyright (c) by the authors of ffmpeg and xvid
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

// FileFlags.h: Definition of flags on CFile/IFile objects
//
//////////////////////////////////////////////////////////////////////

/* indicate that caller can handle truncated reads, where function returns before entire buffer has been filled */
#define READ_TRUNCATED 0x01

/* indicate that that caller support read in the minimum defined chunk size, this disables internal cache then */
#define READ_CHUNKED 0x02

/* use cache to access this file */
#define READ_CACHED 0x04

/* open without caching. regardless to file type. */
#define READ_NO_CACHE 0x08

/* calcuate bitrate for file while reading */
#define READ_BITRATE 0x10
5 changes: 5 additions & 0 deletions xbmc/filesystem/IFile.cpp
Expand Up @@ -88,3 +88,8 @@ bool IFile::ReadString(char *szLine, int iLineLength)
}
return true;
}

void IFile::SetFlags(unsigned int flags)
{
m_flags = flags;
}
6 changes: 6 additions & 0 deletions xbmc/filesystem/IFile.h
Expand Up @@ -33,6 +33,7 @@
#endif

#include "URL.h"
#include "FileFlags.h"

#include <stdio.h>
#include <stdint.h>
Expand Down Expand Up @@ -99,6 +100,11 @@ class IFile
virtual int IoControl(EIoControl request, void* param) { return -1; }

virtual CStdString GetContent() { return "application/octet-stream"; }

virtual void SetFlags(unsigned int flags);

private:
unsigned int m_flags;
};

class CRedirectException
Expand Down