-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[add] - filepipe implentation needed for airtunes - thx to team boxee
- Loading branch information
Showing
5 changed files
with
774 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
/* | ||
* Copyright (C) 2011 Team XBMC | ||
* http://www.xbmc.org | ||
* | ||
* 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, 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 XBMC; see the file COPYING. If not, write to | ||
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | ||
* http://www.gnu.org/copyleft/gpl.html | ||
* | ||
*/ | ||
|
||
#include "FilePipe.h" | ||
#include "threads/SingleLock.h" | ||
#include "PipesManager.h" | ||
#include "utils/StringUtils.h" | ||
|
||
using namespace XFILE; | ||
|
||
CFilePipe::CFilePipe() : m_pos(0), m_length(-1), m_pipe(NULL) | ||
{ | ||
} | ||
|
||
CFilePipe::~CFilePipe() | ||
{ | ||
Close(); | ||
} | ||
|
||
int64_t CFilePipe::GetPosition() | ||
{ | ||
return m_pos; | ||
} | ||
|
||
int64_t CFilePipe::GetLength() | ||
{ | ||
return m_length; | ||
} | ||
|
||
void CFilePipe::SetLength(int64_t len) | ||
{ | ||
m_length = len; | ||
} | ||
|
||
bool CFilePipe::Open(const CURL& url) | ||
{ | ||
CStdString name = url.Get(); | ||
m_pipe = PipesManager::GetInstance().OpenPipe(name); | ||
if (m_pipe) | ||
m_pipe->AddListener(this); | ||
return (m_pipe != NULL); | ||
} | ||
|
||
bool CFilePipe::Exists(const CURL& url) | ||
{ | ||
CStdString name = url.Get(); | ||
return PipesManager::GetInstance().Exists(name); | ||
} | ||
|
||
int CFilePipe::Stat(const CURL& url, struct __stat64* buffer) | ||
{ | ||
return -1; | ||
} | ||
|
||
int CFilePipe::Stat(struct __stat64* buffer) | ||
{ | ||
memset(buffer,0,sizeof(struct __stat64)); | ||
buffer->st_size = m_length; | ||
return 0; | ||
} | ||
|
||
unsigned int CFilePipe::Read(void* lpBuf, int64_t uiBufSize) | ||
{ | ||
if (!m_pipe) | ||
return -1; | ||
|
||
return m_pipe->Read((char *)lpBuf,uiBufSize,INFINITE); | ||
} | ||
|
||
int CFilePipe::Write(const void* lpBuf, int64_t uiBufSize) | ||
{ | ||
if (!m_pipe) | ||
return -1; | ||
|
||
return (int)(m_pipe->Write((const char *)lpBuf,uiBufSize,INFINITE)); // its not the size. its bool. either all was written or not. | ||
} | ||
|
||
void CFilePipe::SetEof() | ||
{ | ||
if (!m_pipe) | ||
return ; | ||
m_pipe->SetEof(); | ||
} | ||
|
||
bool CFilePipe::IsEof() | ||
{ | ||
if (!m_pipe) | ||
return true; | ||
return m_pipe->IsEof(); | ||
} | ||
|
||
bool CFilePipe::IsEmpty() | ||
{ | ||
if (!m_pipe) | ||
return true; | ||
return m_pipe->IsEmpty(); | ||
} | ||
|
||
int64_t CFilePipe::Seek(int64_t iFilePosition, int iWhence) | ||
{ | ||
return -1; | ||
} | ||
|
||
void CFilePipe::Close() | ||
{ | ||
if (m_pipe) | ||
{ | ||
PipesManager::GetInstance().ClosePipe(m_pipe); | ||
m_pipe->RemoveListener(this); | ||
} | ||
m_pipe = NULL; | ||
} | ||
|
||
bool CFilePipe::IsClosed() | ||
{ | ||
return (m_pipe == NULL); | ||
} | ||
|
||
void CFilePipe::Flush() | ||
{ | ||
if (m_pipe) | ||
m_pipe->Flush(); | ||
} | ||
|
||
bool CFilePipe::OpenForWrite(const CURL& url, bool bOverWrite) | ||
{ | ||
CStdString name = url.Get(); | ||
|
||
m_pipe = PipesManager::GetInstance().CreatePipe(name); | ||
if (m_pipe) | ||
m_pipe->AddListener(this); | ||
return (m_pipe != NULL); | ||
} | ||
|
||
bool CFilePipe::Delete(const CURL& url) | ||
{ | ||
return false; | ||
} | ||
|
||
bool CFilePipe::Rename(const CURL& url, const CURL& urlnew) | ||
{ | ||
return false; | ||
} | ||
|
||
int CFilePipe::IoControl(int request, void* param) | ||
{ | ||
return -1; | ||
} | ||
|
||
CStdString CFilePipe::GetName() const | ||
{ | ||
if (!m_pipe) | ||
return StringUtils::EmptyString; | ||
return m_pipe->GetName(); | ||
} | ||
|
||
void CFilePipe::OnPipeOverFlow() | ||
{ | ||
CSingleLock lock(m_lock); | ||
for (size_t l=0; l<m_listeners.size(); l++) | ||
m_listeners[l]->OnPipeOverFlow(); | ||
} | ||
|
||
__int64 CFilePipe::GetAvailableRead() | ||
{ | ||
return m_pipe->GetAvailableRead(); | ||
} | ||
|
||
void CFilePipe::OnPipeUnderFlow() | ||
{ | ||
for (size_t l=0; l<m_listeners.size(); l++) | ||
m_listeners[l]->OnPipeUnderFlow(); | ||
} | ||
|
||
void CFilePipe::AddListener(IPipeListener *l) | ||
{ | ||
CSingleLock lock(m_lock); | ||
for (size_t i=0; i<m_listeners.size(); i++) | ||
{ | ||
if (m_listeners[i] == l) | ||
return; | ||
} | ||
m_listeners.push_back(l); | ||
} | ||
|
||
void CFilePipe::RemoveListener(IPipeListener *l) | ||
{ | ||
CSingleLock lock(m_lock); | ||
std::vector<XFILE::IPipeListener *>::iterator i = m_listeners.begin(); | ||
while(i != m_listeners.end()) | ||
{ | ||
if ( (*i) == l) | ||
i = m_listeners.erase(i); | ||
else | ||
i++; | ||
} | ||
} | ||
|
||
void CFilePipe::SetOpenThreashold(int threashold) | ||
{ | ||
m_pipe->SetOpenThreashold(threashold); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
// FilePipe.h: interface for the CFilePipe class. | ||
// | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
#if !defined(AFX_FILEPIPE_H__DD2B0A9E_4971_4A29_B525_78CEFCDAF4A1__INCLUDED_) | ||
#define AFX_FILEPIPE_H__DD2B0A9E_4971_4A29_B525_78CEFCDAF4A1__INCLUDED_ | ||
|
||
#if _MSC_VER > 1000 | ||
#pragma once | ||
#endif // _MSC_VER > 1000 | ||
|
||
#include "IFile.h" | ||
#include "utils/AutoPtrHandle.h" | ||
#include "utils/StdString.h" | ||
#include "threads/Event.h" | ||
#include "threads/CriticalSection.h" | ||
#include "utils/RingBuffer.h" | ||
#include "PipesManager.h" | ||
|
||
namespace XFILE | ||
{ | ||
|
||
class CFilePipe : public IFile, public IPipeListener | ||
{ | ||
public: | ||
CFilePipe(); | ||
virtual ~CFilePipe(); | ||
virtual int64_t GetPosition(); | ||
virtual int64_t GetLength(); | ||
virtual void SetLength(int64_t len); | ||
virtual bool Open(const CURL& url); | ||
virtual bool Exists(const CURL& url); | ||
virtual int Stat(const CURL& url, struct __stat64* buffer); | ||
virtual int Stat(struct __stat64* buffer); | ||
virtual unsigned int Read(void* lpBuf, int64_t uiBufSize); | ||
virtual int Write(const void* lpBuf, int64_t uiBufSize); | ||
virtual int64_t Seek(int64_t iFilePosition, int iWhence = SEEK_SET); | ||
virtual void Close(); | ||
virtual void Flush(); | ||
virtual __int64 GetAvailableRead(); | ||
|
||
virtual bool OpenForWrite(const CURL& url, bool bOverWrite = false); | ||
|
||
virtual bool Delete(const CURL& url); | ||
virtual bool Rename(const CURL& url, const CURL& urlnew); | ||
virtual int IoControl(int request, void* param); | ||
|
||
CStdString GetName() const; | ||
|
||
virtual void OnPipeOverFlow(); | ||
virtual void OnPipeUnderFlow(); | ||
|
||
void AddListener(IPipeListener *l); | ||
void RemoveListener(IPipeListener *l); | ||
|
||
void SetEof(); | ||
bool IsEof(); | ||
bool IsEmpty(); | ||
bool IsClosed(); | ||
|
||
void SetOpenThreashold(int threashold); | ||
|
||
protected: | ||
int64_t m_pos; | ||
int64_t m_length; | ||
|
||
XFILE::Pipe *m_pipe; | ||
|
||
CCriticalSection m_lock; | ||
std::vector<XFILE::IPipeListener *> m_listeners; | ||
}; | ||
|
||
} | ||
#endif // !defined(AFX_FILEPIPE_H__DD2B0A9E_4971_4A29_B525_78CEFCDAF4A1__INCLUDED_) |
Oops, something went wrong.