summaryrefslogtreecommitdiff
path: root/status.cpp
blob: 1cc114f6c02651e057929f7e09efbdcc7b972796 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * status.cpp: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 */

#include "status.h"

cStatusMarkAd::cStatusMarkAd()
{
    memset(recv,0,sizeof(recv));
}

int cStatusMarkAd::GetFreeReceiver()
{
    for (int i=0; i<(MAXDEVICES*MAXRECEIVERS); i++)
    {
        if (recv[i]==NULL) return i;
    }
    return -1;
}

int cStatusMarkAd::FindReceiver(const char *FileName)
{
    for (int i=0; i<(MAXDEVICES*MAXRECEIVERS); i++)
    {
        if (recv[i])
        {
            if (!strcmp(recv[i]->FileName(),FileName)) return i;
        }
    }
    return -1;
}

void cStatusMarkAd::Recording(const cDevice *Device, const char *Name, const char *FileName, bool On)
{
    if (!Device) return; // just to be safe
    if (!FileName) return; // we cannot operate without a filename

    int recvnumber;

    if (On)
    {
        if (!Name) return; // we cannot operate without name ;)

        cTimer *timer=NULL;

        for (cTimer *Timer = Timers.First(); Timer; Timer=Timers.Next(Timer))
        {
            if (Timer->Recording() && (!strcmp(Timer->File(),Name)))
            {
                timer=Timer;
                break;
            }
        }

        if (!timer) return;

        recvnumber=GetFreeReceiver();
        if  (recvnumber<0) return;

        recv[recvnumber] = new cMarkAdReceiver(recvnumber,FileName,timer);
        dsyslog("markad [%i]: start recording %s ",recvnumber,FileName);
        ((cDevice *) Device)->AttachReceiver(recv[recvnumber]);
    }
    else
    {
        recvnumber=FindReceiver(FileName);
        if (recvnumber<0) return;

        dsyslog("markad [%i]: stop recording %s ",recvnumber,FileName);
        ((cDevice *) Device)->Detach(recv[recvnumber]);
        if (!recv[recvnumber]->FoundMarks())
        {
            // TODO: start standalone markad with logo detection
        }
        delete recv[recvnumber];
        recv[recvnumber]=NULL;
    }

}