2 * Copyright (C) 2011-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
22 #include "threads/SingleLock.h"
23 #include "PipesManager.h"
24 #include "utils/StringUtils.h"
27 using namespace XFILE;
29 CPipeFile::CPipeFile() : m_pos(0), m_length(-1), m_pipe(NULL)
33 CPipeFile::~CPipeFile()
38 int64_t CPipeFile::GetPosition()
43 int64_t CPipeFile::GetLength()
48 void CPipeFile::SetLength(int64_t len)
53 bool CPipeFile::Open(const CURL& url)
55 CStdString name = url.Get();
56 m_pipe = PipesManager::GetInstance().OpenPipe(name);
58 m_pipe->AddListener(this);
59 return (m_pipe != NULL);
62 bool CPipeFile::Exists(const CURL& url)
64 CStdString name = url.Get();
65 return PipesManager::GetInstance().Exists(name);
68 int CPipeFile::Stat(const CURL& url, struct __stat64* buffer)
73 int CPipeFile::Stat(struct __stat64* buffer)
75 memset(buffer,0,sizeof(struct __stat64));
76 buffer->st_size = m_length;
80 unsigned int CPipeFile::Read(void* lpBuf, int64_t uiBufSize)
85 return m_pipe->Read((char *)lpBuf,(int)uiBufSize);
88 int CPipeFile::Write(const void* lpBuf, int64_t uiBufSize)
93 // m_pipe->Write return bool. either all was written or not.
94 return m_pipe->Write((const char *)lpBuf,(int)uiBufSize) ? (int)uiBufSize : 0;
97 void CPipeFile::SetEof()
104 bool CPipeFile::IsEof()
108 return m_pipe->IsEof();
111 bool CPipeFile::IsEmpty()
115 return m_pipe->IsEmpty();
118 int64_t CPipeFile::Seek(int64_t iFilePosition, int iWhence)
123 void CPipeFile::Close()
127 m_pipe->RemoveListener(this);
128 PipesManager::GetInstance().ClosePipe(m_pipe);
133 bool CPipeFile::IsClosed()
135 return (m_pipe == NULL);
138 void CPipeFile::Flush()
144 bool CPipeFile::OpenForWrite(const CURL& url, bool bOverWrite)
146 CStdString name = url.Get();
148 m_pipe = PipesManager::GetInstance().CreatePipe(name);
150 m_pipe->AddListener(this);
151 return (m_pipe != NULL);
154 bool CPipeFile::Delete(const CURL& url)
159 bool CPipeFile::Rename(const CURL& url, const CURL& urlnew)
164 int CPipeFile::IoControl(int request, void* param)
169 CStdString CPipeFile::GetName() const
172 return StringUtils::EmptyString;
173 return m_pipe->GetName();
176 void CPipeFile::OnPipeOverFlow()
178 CSingleLock lock(m_lock);
179 for (size_t l=0; l<m_listeners.size(); l++)
180 m_listeners[l]->OnPipeOverFlow();
183 int64_t CPipeFile::GetAvailableRead()
185 return m_pipe->GetAvailableRead();
188 void CPipeFile::OnPipeUnderFlow()
190 for (size_t l=0; l<m_listeners.size(); l++)
191 m_listeners[l]->OnPipeUnderFlow();
194 void CPipeFile::AddListener(IPipeListener *l)
196 CSingleLock lock(m_lock);
197 for (size_t i=0; i<m_listeners.size(); i++)
199 if (m_listeners[i] == l)
202 m_listeners.push_back(l);
205 void CPipeFile::RemoveListener(IPipeListener *l)
207 CSingleLock lock(m_lock);
208 std::vector<XFILE::IPipeListener *>::iterator i = m_listeners.begin();
209 while(i != m_listeners.end())
212 i = m_listeners.erase(i);
218 void CPipeFile::SetOpenThreashold(int threashold)
220 m_pipe->SetOpenThreashold(threashold);