FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
BrowserStreamManager.cpp
1 /**********************************************************\
2 Original Author: Richard Bateman
3 
4 Created: Jan 25, 2011
5 License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12 Copyright 2011 Richard Bateman,
13  Firebreath development team
14 \**********************************************************/
15 
16 #include "BrowserStream.h"
17 #include "precompiled_headers.h" // On windows, everything above this line in PCH
18 
19 #include <boost/lambda/lambda.hpp>
20 #include <boost/lambda/bind.hpp>
21 #include <boost/thread/shared_mutex.hpp>
22 #include <algorithm>
23 
24 #include "BrowserStreamManager.h"
25 
26 FB::BrowserStreamManager::BrowserStreamManager()
27 {
28 
29 }
30 
31 FB::BrowserStreamManager::~BrowserStreamManager()
32 {
33  boost::recursive_mutex::scoped_lock _l(m_xtmutex);
34  using namespace boost::lambda;
35 
36  // Force close all of the streams so that they get a callback
37  std::for_each(m_retainedStreams.begin(), m_retainedStreams.end(),
38  boost::lambda::bind(&BrowserStream::close,
39  boost::lambda::bind(&BrowserStreamPtr::get, boost::lambda::_1)));
40  m_retainedStreams.clear();
41 }
42 
43 void FB::BrowserStreamManager::retainStream( const BrowserStreamPtr& stream )
44 {
45  boost::recursive_mutex::scoped_lock _l(m_xtmutex);
46  stream->AttachObserver(shared_from_this());
47  m_retainedStreams.insert(stream);
48 }
49 
50 void FB::BrowserStreamManager::releaseStream( const BrowserStreamPtr& stream )
51 {
52  boost::recursive_mutex::scoped_lock _l(m_xtmutex);
53  stream->DetachObserver(shared_from_this());
54  m_retainedStreams.erase(stream);
55 }
56 
57 bool FB::BrowserStreamManager::onStreamCompleted( FB::StreamCompletedEvent *evt, FB::BrowserStream *stream )
58 {
59  releaseStream(FB::ptr_cast<FB::BrowserStream>(stream->shared_from_this()));
60  return false;
61 }
62 
This is the abstract base class (interface class) for a browser stream.
Definition: BrowserStream.h:41
This event is fired when a stream has completed downloading.
Definition: StreamEvents.h:148