summaryrefslogtreecommitdiff
path: root/status.cpp
blob: 2af95fe7f812797ee407375e08bd36e6099d7997 (plain)
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
/*
 * status.cpp: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#include "status.h"

cStatusInfosatepg::cStatusInfosatepg(cGlobalInfosatepg *Global)
{
    global = Global;
    myFilter=new cFilterInfosatepg(global);
    myFilterDevice=NULL;
}

cStatusInfosatepg::~cStatusInfosatepg(void)
{
    if (myFilterDevice) myFilterDevice->Detach(myFilter);
    if (myFilter) delete myFilter;
}

void cStatusInfosatepg::ChannelSwitch(const cDevice *Device, int ChannelNumber)
{
    if (!ChannelNumber) return;
    if (!Device) return; // just to be safe

    bool bAddFilter=false;

    // just add filter if we aren't locked
    if (ChannelNumber==global->Channel())
    {
        cChannel *chan=Channels.GetByNumber(global->Channel());
        if (!chan) return;
        if (!Device->ProvidesTransponder(chan)) return; // ignore virtual devices
        if (Device==myFilterDevice) return; // already attached to this device
        if (!global->ReceivedAll()) bAddFilter=true;
    }

    if (bAddFilter)
    {
        if (myFilterDevice) return; // already attached to another device

        myFilterDevice = (cDevice *) Device;

        dsyslog("switching device %i to channel %i (infosatepg)",
                Device->DeviceNumber()+1,ChannelNumber);
        myFilterDevice->AttachFilter(myFilter);
        global->SetSwitched(true);
    }
    else
    {
        if (myFilterDevice)
        {
            if (Device==myFilterDevice)
            {
                dsyslog("infosatepg: detach filter");
                myFilterDevice->Detach(myFilter);
                myFilterDevice=NULL;
                global->SetWaitTimer();
                global->SetSwitched(false);
            }
        }
    }
}