Statistics
| Branch: | Tag: | Revision:

dvbd / src / connectionmanager.cpp @ 999c60b4

History | View | Annotate | Download (2.15 KB)

1
/*
2
  Copyright 2003 John Knottenbelt
3
  
4
  This program is free software; you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation; either version 2 of the License, or
7
  (at your option) any later version.
8
 
9
  This program is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
 
14
  You should have received a copy of the GNU General Public License
15
  along with this program; if not, write to the Free Software
16
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
17
*/
18

    
19
#include "config.h"
20
#include "connectionmanager.h"
21
#include "recordconnection.h"
22
#include "connection.h"
23

    
24
ConnectionManager::~ConnectionManager()
25
{
26
  for (ConnectionList::iterator i = connections.begin(); i != connections.end();) {
27
    Connection *c = *i;
28
    i = connections.erase(i);
29
    delete c;
30
  }
31
}
32

    
33
void ConnectionManager::add(Connection *c)
34
{
35
  connections.push_back(c);
36
}
37

    
38
void ConnectionManager::addSelectFDs(Select &s) const
39
{
40
  for (ConnectionList::const_iterator i = connections.begin(); i != connections.end(); i++) 
41
    (*i)->addSelectFDs(s);
42
}
43

    
44
bool ConnectionManager::isReady(const Select &s) const
45
{
46
  for (ConnectionList::const_iterator i = connections.begin(); i != connections.end(); i++) 
47
    if ((*i)->isReady(s))
48
      return true;
49
  return false;
50
}
51

    
52
void ConnectionManager::processReady(Select &s)
53
{
54
  for (ConnectionList::iterator i = connections.begin(); i != connections.end(); ) {
55
    Connection *c = *i;
56
    if (!c->processReady(s)) {
57
      // Close terminated connections
58
      i = connections.erase(i);
59
      delete c;
60
      continue;
61
    }
62
    i++;
63
  }
64
}
65

    
66
bool ConnectionManager::removeJob(int job)
67
{
68
  for (ConnectionList::iterator i = connections.begin(); i != connections.end(); ) {
69
    RecordConnection *c = dynamic_cast<RecordConnection *>(*i);
70
    if (c != NULL && c->getJob() == job) {
71
      // Close terminated connections
72
      connections.erase(i);
73
      delete c;
74
      return true;
75
    }
76
    i++;
77
  }
78
  return false;
79
}