Statistics
| Branch: | Tag: | Revision:

dvbd / dvbd.cpp @ bfdb7446

History | View | Annotate | Download (2.46 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 "dvbd.h"
21
#include "tunermanager.h"
22
#include "connectionmanager.h"
23
#include "connection.h"
24
#include "lobby.h"
25
#include "configfile.h"
26
#include "stringutil.h"
27
#include "scheduler.h"
28

    
29
#include <iostream>
30

    
31
int debugLevel;
32

    
33
int main(int argc, char *argv[])
34
{
35
  // improve iostream performance
36
  std::ios::sync_with_stdio(false);
37

    
38
  ConfigFile config;
39
  
40
  config.set("socket", DEFAULT_SOCKET_FILE);
41
  config.set("pid", DEFAULT_PID_FILE);
42
  config.set("log", DEFAULT_LOG_FILE);
43
  config.set("schedule", DEFAULT_SCHED_FILE);
44
  config.set("numcards", "1");
45
  config.set("card0", DEFAULT_CARD);
46
  config.set("debug", "0");
47

    
48
  std::string configFilename;
49

    
50
  if (argc >= 2) {
51
    configFilename = argv[1];
52
    if (!config.read(configFilename)) {
53
      std::cerr << "Fatal error: failed to open config file: " 
54
                << configFilename << std::endl;
55
      return 1;
56
    }
57
  }
58
  else {
59
    configFilename = DEFAULT_CONFIG_FILE;
60
    config.read(configFilename);
61
  }
62

    
63
  debugLevel = toInt(config.get("debug"));
64

    
65
  if (debugLevel == 0)
66
    if (!daemonize(config))
67
      return 1;
68

    
69
  TunerManager tm;
70
  if (!tm.parseConfig(config)) {
71
    std::cerr << "Fatal error: failed to parse cards defined in configuration file"
72
              << std::endl;
73
    return 1;
74
  }
75

    
76
  ConnectionManager cm;
77

    
78
  Scheduler scheduler(config.get("schedule"), &tm, &cm);
79

    
80
  std::string socketFilename = config.get("socket");
81
  Lobby lobby(socketFilename, &tm, &cm, &scheduler);
82

    
83
  setupSignalHandlers();
84

    
85
  Select s;
86
  do {
87
    s.clearFDs();
88

    
89
    lobby.addSelectFDs(s);
90
    tm.addSelectFDs(s);
91
    cm.addSelectFDs(s);
92
    scheduler.addSelectFDs(s);
93

    
94
    s.wait();
95

    
96
    scheduler.process();
97
    lobby.processReady(s);
98
    cm.processReady(s);
99
    tm.processReady(s);
100

    
101
  } while (true);
102
  return 0;
103
}