Statistics
| Branch: | Tag: | Revision:

dvbd / src / dvbd.cpp @ 904d298f

History | View | Annotate | Download (2.79 KB)

1 bfdb7446 jak
/*
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 904d298f jak
  config.set("socket-uid", DEFAULT_SOCKET_UID);
42
  config.set("socket-gid", DEFAULT_SOCKET_GID);
43
  config.set("socket-mode", DEFAULT_SOCKET_MODE);
44 bfdb7446 jak
  config.set("pid", DEFAULT_PID_FILE);
45
  config.set("log", DEFAULT_LOG_FILE);
46 b949d188 jak
  config.set("schedule", DEFAULT_SCHEDULE_FILE);
47 bfdb7446 jak
  config.set("numcards", "1");
48
  config.set("card0", DEFAULT_CARD);
49
  config.set("debug", "0");
50
51
  std::string configFilename;
52
53
  if (argc >= 2) {
54
    configFilename = argv[1];
55
    if (!config.read(configFilename)) {
56
      std::cerr << "Fatal error: failed to open config file: " 
57
                << configFilename << std::endl;
58
      return 1;
59
    }
60
  }
61
  else {
62
    configFilename = DEFAULT_CONFIG_FILE;
63
    config.read(configFilename);
64
  }
65
66
  debugLevel = toInt(config.get("debug"));
67
68
  if (debugLevel == 0)
69
    if (!daemonize(config))
70
      return 1;
71
72
  TunerManager tm;
73
  if (!tm.parseConfig(config)) {
74
    std::cerr << "Fatal error: failed to parse cards defined in configuration file"
75
              << std::endl;
76
    return 1;
77
  }
78
79
  ConnectionManager cm;
80
81
  Scheduler scheduler(config.get("schedule"), &tm, &cm);
82
83
  std::string socketFilename = config.get("socket");
84 904d298f jak
  std::string socketUid = config.get("socket-uid");
85
  std::string socketGid = config.get("socket-gid");
86
  std::string socketMode = config.get("socket-mode");
87
  Lobby lobby(socketFilename, socketUid, socketGid, socketMode, &tm, &cm, &scheduler);
88 bfdb7446 jak
89
  setupSignalHandlers();
90
91
  Select s;
92
  do {
93
    s.clearFDs();
94
95
    lobby.addSelectFDs(s);
96
    tm.addSelectFDs(s);
97
    cm.addSelectFDs(s);
98
    scheduler.addSelectFDs(s);
99
100
    s.wait();
101
102
    scheduler.process();
103
    lobby.processReady(s);
104
    cm.processReady(s);
105
    tm.processReady(s);
106
107
  } while (true);
108
  return 0;
109
}