forked from manio/vdr-plugin-dvbapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice.cpp
More file actions
127 lines (108 loc) · 3.33 KB
/
device.cpp
File metadata and controls
127 lines (108 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* vdr-plugin-dvbapi - softcam dvbapi plugin for VDR
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "device.h"
#include "Log.h"
// -- cScDvbDevice -------------------------------------------------------------
#define SCDEVICE cScDvbDevice
#define DVBDEVICE cDvbDevice
#include "device-tmpl.cpp"
// -- cScDvbDevicePlugin -------------------------------------------------------
class cScDvbDevicePlugin : public cScDevicePlugin
{
public:
virtual cDevice *Probe(int Adapter, int Frontend, uint32_t SubSystemId);
virtual bool LateInit(cDevice *dev);
virtual bool EarlyShutdown(cDevice *dev);
};
cDevice *cScDvbDevicePlugin::Probe(int Adapter, int Frontend, uint32_t SubSystemId)
{
INFOLOG("creating standard device %d/%d", Adapter, Frontend);
return new cScDvbDevice(this, Adapter, Frontend, cScDevices::DvbOpen(DEV_DVB_CA, Adapter, Frontend, O_RDWR));
}
bool cScDvbDevicePlugin::LateInit(cDevice *dev)
{
cScDvbDevice *d = dynamic_cast<cScDvbDevice *>(dev);
if (d)
d->LateInit();
return d != 0;
}
bool cScDvbDevicePlugin::EarlyShutdown(cDevice *dev)
{
cScDvbDevice *d = dynamic_cast<cScDvbDevice *>(dev);
if (d)
d->EarlyShutdown();
return d != 0;
}
// -- cScDevices ---------------------------------------------------------------
int cScDevices::budget = 0;
void cScDevices::DvbName(const char *Name, int a, int f, char *buffer, int len)
{
snprintf(buffer, len, "%s/%s%d/%s%d", DEV_DVB_BASE, DEV_DVB_ADAPTER, a, Name, f);
}
int cScDevices::DvbOpen(const char *Name, int a, int f, int Mode, bool ReportError)
{
char FileName[128];
DvbName(Name, a, f, FileName, sizeof(FileName));
int fd = open(FileName, Mode);
if (fd < 0 && ReportError)
LOG_ERROR_STR(FileName);
return fd;
}
void cScDevices::OnPluginLoad(void)
{
cScDeviceProbe::Install();
// default device plugin must be last in the list
new cScDvbDevicePlugin;
}
void cScDevices::OnPluginUnload(void)
{
cScDeviceProbe::Remove();
}
bool cScDevices::Initialize(void)
{
return true;
}
void cScDevices::Startup(void)
{
for (int n = cDevice::NumDevices(); --n >= 0;)
{
cDevice *dev = cDevice::GetDevice(n);
for (cScDevicePlugin *dp = devplugins.First(); dp; dp = devplugins.Next(dp))
if (dp->LateInit(dev))
break;
}
}
void cScDevices::Shutdown(void)
{
for (int n = cDevice::NumDevices(); --n >= 0;)
{
cDevice *dev = cDevice::GetDevice(n);
for (cScDevicePlugin *dp = devplugins.First(); dp; dp = devplugins.Next(dp))
if (dp->EarlyShutdown(dev))
break;
}
}
void cScDevices::SetForceBudget(int n)
{
if (n >= 0 && n < MAXDVBDEVICES)
budget |= (1 << n);
}
bool cScDevices::ForceBudget(int n)
{
return budget && (budget & (1 << n));
}