kodi
FileCache.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "CacheStrategy.h"
12 #include "File.h"
13 #include "IFile.h"
14 #include "threads/CriticalSection.h"
15 #include "threads/Thread.h"
16 
17 #include <atomic>
18 #include <chrono>
19 #include <memory>
20 
21 using namespace std::chrono_literals;
22 
23 namespace XFILE
24 {
25 
26  class CFileCache : public IFile, public CThread
27  {
28  public:
29  explicit CFileCache(const unsigned int flags);
30  ~CFileCache() override;
31 
32  // CThread methods
33  void Process() override;
34  void OnExit() override;
35  void StopThread(bool bWait = true) override;
36 
37  // IFIle methods
38  bool Open(const CURL& url) override;
39  void Close() override;
40  bool Exists(const CURL& url) override;
41  int Stat(const CURL& url, struct __stat64* buffer) override;
42 
43  ssize_t Read(void* lpBuf, size_t uiBufSize) override;
44 
45  int64_t Seek(int64_t iFilePosition, int iWhence) override;
46  int64_t GetPosition() override;
47  int64_t GetLength() override;
48 
49  int IoControl(EIoControl request, void* param) override;
50 
51  IFile *GetFileImp();
52 
53  const std::string GetProperty(XFILE::FileProperty type, const std::string &name = "") const override;
54 
55  const std::vector<std::string> GetPropertyValues(XFILE::FileProperty type, const std::string& name = "") const override
56  {
57  return std::vector<std::string>();
58  }
59 
60  private:
61  std::unique_ptr<CCacheStrategy> m_pCache;
62  int m_seekPossible = 0;
63  CFile m_source;
64  std::string m_sourcePath;
65  CEvent m_seekEvent;
66  CEvent m_seekEnded;
67  int64_t m_nSeekResult = 0;
68  int64_t m_seekPos = 0;
69  int64_t m_readPos = 0;
70  int64_t m_writePos = 0;
71  unsigned m_chunkSize = 0;
72  uint32_t m_writeRate = 0;
73  uint32_t m_writeRateActual = 0;
74  uint32_t m_writeRateLowSpeed = 0;
75  int64_t m_forwardCacheSize = 0;
76  int64_t m_maxForward = 0;
77  bool m_bFilling = false;
78  std::atomic<int64_t> m_fileSize;
79  unsigned int m_flags;
80  CCriticalSection m_sync;
81  std::chrono::milliseconds m_processWait{100ms};
82  };
83 
84 }
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
Definition: Scraper.h:41
Definition: Thread.h:44
Definition: URL.h:21
Definition: File.h:37
Definition: IFile.h:42
Definition: FileCache.h:26