/
BrowserStreamManager.cpp
60 lines (48 loc) · 1.9 KB
/
BrowserStreamManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**********************************************************\
Original Author: Richard Bateman
Created: Jan 25, 2011
License: Dual license model; choose one of two:
New BSD License
http://www.opensource.org/licenses/bsd-license.php
- or -
GNU Lesser General Public License, version 2.1
http://www.gnu.org/licenses/lgpl-2.1.html
Copyright 2011 Richard Bateman,
Firebreath development team
\**********************************************************/
#include "BrowserStream.h"
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <algorithm>
#include "BrowserStreamManager.h"
FB::BrowserStreamManager::BrowserStreamManager()
{
}
FB::BrowserStreamManager::~BrowserStreamManager()
{
boost::recursive_mutex::scoped_lock _l(m_xtmutex);
using namespace boost::lambda;
// Force close all of the streams so that they get a callback
std::for_each(m_retainedStreams.begin(), m_retainedStreams.end(),
boost::lambda::bind(&BrowserStream::close,
boost::lambda::bind(&BrowserStreamPtr::get, boost::lambda::_1)));
m_retainedStreams.clear();
}
void FB::BrowserStreamManager::retainStream( const BrowserStreamPtr& stream )
{
boost::recursive_mutex::scoped_lock _l(m_xtmutex);
stream->AttachObserver(shared_from_this());
m_retainedStreams.insert(stream);
}
void FB::BrowserStreamManager::releaseStream( const BrowserStreamPtr& stream )
{
boost::recursive_mutex::scoped_lock _l(m_xtmutex);
stream->DetachObserver(shared_from_this());
m_retainedStreams.erase(stream);
}
bool FB::BrowserStreamManager::onStreamCompleted( FB::StreamCompletedEvent *evt, FB::BrowserStream *stream )
{
releaseStream(FB::ptr_cast<FB::BrowserStream>(stream->shared_from_this()));
return false;
}