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.
14 #include "threads/CriticalSection.h"
15 #include "threads/Event.h"
16 #include "utils/RingBuffer.h"
22 #define PIPE_DEFAULT_MAX_SIZE (6 * 1024 * 1024)
30 virtual ~IPipeListener() = default;
31 virtual void OnPipeOverFlow() = 0;
32 virtual void OnPipeUnderFlow() = 0;
38 Pipe(const std::string
&name
, int nMaxSize
= PIPE_DEFAULT_MAX_SIZE
);
40 const std::string
&GetName();
43 void DecRef(); // a pipe does NOT delete itself with ref-count 0.
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);
58 * Write into the Pipe from the buffer the num of bytes asked for
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);
71 void AddListener(IPipeListener
*l
);
72 void RemoveListener(IPipeListener
*l
);
77 int GetAvailableRead();
78 void SetOpenThreshold(int threshold
);
87 std::string m_strPipeName
;
94 std::vector
<XFILE::IPipeListener
*> m_listeners
;
96 CCriticalSection m_lock
;
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
);
113 int m_nGenIdHelper
= 1;
114 std::map
<std::string
, XFILE::Pipe
*> m_pipes
;
116 CCriticalSection m_lock
;