[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / filesystem / PipesManager.h
blob100f7d8c28ec76f245d25b883d43109f928d5d1f
1 /*
2 * Many concepts and protocol are taken from
3 * the Boxee project. http://www.boxee.tv
5 * Copyright (C) 2011-2018 Team Kodi
6 * This file is part of Kodi - https://kodi.tv
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 * See LICENSES/README.md for more information.
12 #pragma once
14 #include "threads/CriticalSection.h"
15 #include "threads/Event.h"
16 #include "utils/RingBuffer.h"
18 #include <map>
19 #include <string>
20 #include <vector>
22 #define PIPE_DEFAULT_MAX_SIZE (6 * 1024 * 1024)
24 namespace XFILE
27 class IPipeListener
29 public:
30 virtual ~IPipeListener() = default;
31 virtual void OnPipeOverFlow() = 0;
32 virtual void OnPipeUnderFlow() = 0;
35 class Pipe
37 public:
38 Pipe(const std::string &name, int nMaxSize = PIPE_DEFAULT_MAX_SIZE );
39 virtual ~Pipe();
40 const std::string &GetName();
42 void AddRef();
43 void DecRef(); // a pipe does NOT delete itself with ref-count 0.
44 int RefCount();
46 bool IsEmpty();
48 /**
49 * Read into the buffer from the Pipe the num of bytes asked for
50 * blocking forever (which happens to be 5 minutes in this case).
52 * In the case where nWaitMillis is provided block for that number
53 * of milliseconds instead.
55 int Read(char *buf, int nMaxSize, int nWaitMillis = -1);
57 /**
58 * Write into the Pipe from the buffer the num of bytes asked for
59 * blocking forever.
61 * In the case where nWaitMillis is provided block for that number
62 * of milliseconds instead.
64 bool Write(const char *buf, int nSize, int nWaitMillis = -1);
66 void Flush();
68 void CheckStatus();
69 void Close();
71 void AddListener(IPipeListener *l);
72 void RemoveListener(IPipeListener *l);
74 void SetEof();
75 bool IsEof();
77 int GetAvailableRead();
78 void SetOpenThreshold(int threshold);
80 protected:
82 bool m_bOpen;
83 bool m_bReadyForRead;
85 bool m_bEof;
86 CRingBuffer m_buffer;
87 std::string m_strPipeName;
88 int m_nRefCount;
89 int m_nOpenThreshold;
91 CEvent m_readEvent;
92 CEvent m_writeEvent;
94 std::vector<XFILE::IPipeListener *> m_listeners;
96 CCriticalSection m_lock;
100 class PipesManager
102 public:
103 virtual ~PipesManager();
104 static PipesManager &GetInstance();
106 std::string GetUniquePipeName();
107 XFILE::Pipe *CreatePipe(const std::string &name="", int nMaxPipeSize = PIPE_DEFAULT_MAX_SIZE);
108 XFILE::Pipe *OpenPipe(const std::string &name);
109 void ClosePipe(XFILE::Pipe *pipe);
110 bool Exists(const std::string &name);
112 protected:
113 int m_nGenIdHelper = 1;
114 std::map<std::string, XFILE::Pipe *> m_pipes;
116 CCriticalSection m_lock;