2 * Many concepts and protocol are taken from
3 * the Boxee project. http://www.boxee.tv
5 * Copyright (C) 2011-2013 Team XBMC
8 * This Program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This Program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with XBMC; see the file COPYING. If not, see
20 * <http://www.gnu.org/licenses/>.
24 #ifndef __PIPES_MANAGER__H__
25 #define __PIPES_MANAGER__H__
27 #include "threads/CriticalSection.h"
28 #include "threads/Event.h"
29 #include "utils/StdString.h"
30 #include "utils/RingBuffer.h"
34 #define PIPE_DEFAULT_MAX_SIZE (6 * 1024 * 1024)
42 virtual ~IPipeListener() {}
43 virtual void OnPipeOverFlow() = 0;
44 virtual void OnPipeUnderFlow() = 0;
50 Pipe(const CStdString &name, int nMaxSize = PIPE_DEFAULT_MAX_SIZE );
52 const CStdString &GetName();
55 void DecRef(); // a pipe does NOT delete itself with ref-count 0.
61 * Read into the buffer from the Pipe the num of bytes asked for
62 * blocking forever (which happens to be 5 minutes in this case).
64 * In the case where nWaitMillis is provided block for that number
65 * of milliseconds instead.
67 int Read(char *buf, int nMaxSize, int nWaitMillis = -1);
70 * Write into the Pipe from the buffer the num of bytes asked for
73 * In the case where nWaitMillis is provided block for that number
74 * of milliseconds instead.
76 bool Write(const char *buf, int nSize, int nWaitMillis = -1);
83 void AddListener(IPipeListener *l);
84 void RemoveListener(IPipeListener *l);
89 int GetAvailableRead();
90 void SetOpenThreashold(int threashold);
99 CStdString m_strPipeName;
101 int m_nOpenThreashold;
106 std::vector<XFILE::IPipeListener *> m_listeners;
108 CCriticalSection m_lock;
115 virtual ~PipesManager();
116 static PipesManager &GetInstance();
118 CStdString GetUniquePipeName();
119 XFILE::Pipe *CreatePipe(const CStdString &name="", int nMaxPipeSize = PIPE_DEFAULT_MAX_SIZE);
120 XFILE::Pipe *OpenPipe(const CStdString &name);
121 void ClosePipe(XFILE::Pipe *pipe);
122 bool Exists(const CStdString &name);
127 std::map<CStdString, XFILE::Pipe *> m_pipes;
129 CCriticalSection m_lock;