xbmc
PipeFile.h
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
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  * See LICENSES/README.md for more information.
9  */
10 
11 #pragma once
12 
13 // FilePipe.h: interface for the CPipeFile class.
14 //
16 
17 #include "IFile.h"
18 #include "PipesManager.h"
19 #include "threads/CriticalSection.h"
20 
21 #include <string>
22 #include <vector>
23 
24 namespace XFILE
25 {
26 
27 class CPipeFile : public IFile, public IPipeListener
28 {
29 public:
30  CPipeFile();
31  ~CPipeFile() override;
32  int64_t GetPosition() override;
33  int64_t GetLength() override;
34  virtual void SetLength(int64_t len);
35  bool Open(const CURL& url) override;
36  bool Exists(const CURL& url) override;
37  int Stat(const CURL& url, struct __stat64* buffer) override;
38  int Stat(struct __stat64* buffer) override;
39  ssize_t Read(void* lpBuf, size_t uiBufSize) override;
40  ssize_t Write(const void* lpBuf, size_t uiBufSize) override;
41  int64_t Seek(int64_t iFilePosition, int iWhence = SEEK_SET) override;
42  void Close() override;
43  void Flush() override;
44  virtual int64_t GetAvailableRead();
45 
46  bool OpenForWrite(const CURL& url, bool bOverWrite = false) override;
47 
48  bool Delete(const CURL& url) override;
49  bool Rename(const CURL& url, const CURL& urlnew) override;
50  int IoControl(EIoControl request, void* param) override;
51 
52  std::string GetName() const;
53 
54  void OnPipeOverFlow() override;
55  void OnPipeUnderFlow() override;
56 
57  void AddListener(IPipeListener *l);
58  void RemoveListener(IPipeListener *l);
59 
60  void SetEof();
61  bool IsEof();
62  bool IsEmpty();
63  bool IsClosed();
64 
65  void SetOpenThreshold(int threshold);
66 
67 protected:
68  int64_t m_pos = 0;
69  int64_t m_length = -1;
70 
71  XFILE::Pipe *m_pipe;
72 
73  CCriticalSection m_lock;
74  std::vector<XFILE::IPipeListener *> m_listeners;
75 };
76 
77 }
Definition: PipeFile.h:27
Definition: PipesManager.h:27
Definition: Scraper.h:41
ssize_t Read(void *lpBuf, size_t uiBufSize) override
Attempt to read bufSize bytes from currently opened file into buffer bufPtr.
Definition: PipeFile.cpp:72
Definition: URL.h:20
Definition: IFile.h:42
ssize_t Write(const void *lpBuf, size_t uiBufSize) override
Attempt to write bufSize bytes from buffer bufPtr into currently opened file.
Definition: PipeFile.cpp:83
int Stat(const CURL &url, struct __stat64 *buffer) override
Fills struct __stat64 with information about file specified by url.
Definition: PipeFile.cpp:57
Definition: PipesManager.h:35