Statistics
| Branch: | Tag: | Revision:

dvbd / lobby.h @ bfdb7446

History | View | Annotate | Download (2.06 KB)

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

    
20
#if !defined __LOBBY_H
21
#define __LOBBY_H
22

    
23
#include "select.h"
24
#include "connectionmanager.h"
25

    
26
#include <string>
27
#include <list>
28

    
29
class ConnectionManager;
30
class TunerManager;
31
class Scheduler;
32
class UnixServerSocket;
33

    
34
class Lobby : public Selectable {
35
public:
36
  Lobby(const std::string &socketFilename, 
37
        TunerManager *tm, ConnectionManager *cm,
38
        Scheduler *scheduler);
39

    
40
  virtual ~Lobby();
41

    
42
  virtual void addSelectFDs(Select &s) const;
43
  virtual bool isReady(const Select &s) const;
44
  void processReady(Select &s);
45

    
46
private:
47
  UnixServerSocket *server;
48
  TunerManager *tm;
49
  ConnectionManager *cm;
50
  Scheduler *scheduler;
51

    
52
  void setRandomSeed();
53
  std::string generateId();
54

    
55
  // Associates the file descriptor
56
  // with it's id (cookie)
57
  class Control {
58
  public:
59
    Control(int fd, const std::string &id)
60
      : fd(fd), id(id)
61
    {
62
    };
63

    
64
    int getFD() const {
65
      return fd;
66
    }
67

    
68
    bool matches(const std::string &id) {
69
      if (this->id.empty())
70
        return false;
71
      else 
72
        return this->id == id;
73
    }
74

    
75
    void setId(const std::string &id) {
76
      this->id = id;
77
    };
78

    
79
    const std::string &getId() const {
80
      return id;
81
    }
82

    
83
  private:
84
    int fd;
85
    std::string id;
86
  };
87

    
88
  typedef std::list<int> ClientList;
89
  ClientList clients;
90

    
91
  typedef std::list<Control> ControlList;
92
  ControlList controllers;
93
};
94

    
95
#endif // __LOBBY_H
96