Statistics
| Branch: | Tag: | Revision:

dvbd / src / lobby.h @ 904d298f

History | View | Annotate | Download (2.16 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
        const std::string &socketUid,
38
        const std::string &socketGid,
39
        const std::string &socketMode,
40
        TunerManager *tm,
41
        ConnectionManager *cm,
42
        Scheduler *scheduler);
43

    
44
  virtual ~Lobby();
45

    
46
  virtual void addSelectFDs(Select &s) const;
47
  virtual bool isReady(const Select &s) const;
48
  void processReady(Select &s);
49

    
50
private:
51
  UnixServerSocket *server;
52
  TunerManager *tm;
53
  ConnectionManager *cm;
54
  Scheduler *scheduler;
55

    
56
  void setRandomSeed();
57
  std::string generateId();
58

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

    
68
    int getFD() const {
69
      return fd;
70
    }
71

    
72
    bool matches(const std::string &id) {
73
      if (this->id.empty())
74
        return false;
75
      else 
76
        return this->id == id;
77
    }
78

    
79
    void setId(const std::string &id) {
80
      this->id = id;
81
    };
82

    
83
    const std::string &getId() const {
84
      return id;
85
    }
86

    
87
  private:
88
    int fd;
89
    std::string id;
90
  };
91

    
92
  typedef std::list<int> ClientList;
93
  ClientList clients;
94

    
95
  typedef std::list<Control> ControlList;
96
  ControlList controllers;
97
};
98

    
99
#endif // __LOBBY_H
100