summaryrefslogtreecommitdiff
path: root/status.c
blob: aff12ac07b9c707912d605174ba590aa24527d33 (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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
 * based on status.c,v 1.2 2007/05/08 10:16:23 thomas
 *
 * version by Midas
 *
 */

#include "status.h"
#include "control.h"
#include "event.h"
#include "config.h"

cStatusBlock::cStatusBlock(void):
    cStatus()
{
}

void cStatusBlock::ChannelSwitch(const cDevice *Device, int ChannelNumber)
{
  int current_channel=cDevice::CurrentChannel();
#ifdef LOGGING
  int device_number=Device->DeviceNumber();
#endif  
  
  if (cSetupBlock::LastAcceptableChannel==0)
  {
#ifdef LOGGING
    dsyslog("plugin-block: ChannelSwitch returned because LastAcceptableChannel=0");
#endif    
    cSetupBlock::LastAcceptableChannel=current_channel;
    return;
  }
  if (ChannelNumber==0)
  {
#ifdef LOGGING
    dsyslog("plugin-block: ChannelSwitch returned because ChannelNumber=0 (switch in progress).");
#endif    
    return; //Switch in progress;
  }

#ifdef LOGGING
  dsyslog("plugin-block: cStatusBlock noticed channel switch at device %d, channel no %d",device_number,ChannelNumber);
  dsyslog("plugin-block: cDevice::CurrentChannel %d",current_channel);
  dsyslog("plugin-block: Device %d, ActualDevice %d, primary Device %d",device_number,cDevice::ActualDevice()->DeviceNumber(),cDevice::PrimaryDevice()->DeviceNumber());
  for (int ii=0;ii<cDevice::NumDevices();ii++)
  {
    cDevice* tmpdev=cDevice::GetDevice(ii);
    dsyslog("plugin-block: cDevice %d replaying: %d, transferring %d, hasprogramme %d",ii,tmpdev->Replaying(),tmpdev->Transferring(),tmpdev->HasProgramme());
  }
#endif

  if (Device->DeviceNumber()!=cDevice::PrimaryDevice()->DeviceNumber())
  {
#ifdef LOGGING
    dsyslog("plugin-block: Did nothing cause ChannelSwitch not on active livedevice.");
#endif
    return;
  }


  if (ChannelNumber!=current_channel)
  {
#ifdef LOGGING
   dsyslog("plugin-block: Did nothing because ChannelNumber!=CurrentChannel (switch still in progress)");
#endif

   return;
  }

  if (cSetupBlock::DetectionMethod!=0) 
  {
#ifdef LOGGING
    dsyslog("plugin-block: ChannelSwitch returned because other detection method active");
#endif
    return;
  }


  
  if (Device->Replaying()) 
  {
#ifdef LOGGING
    dsyslog("plugin-block: Did nothing because Device is Replaying");
#endif
    return; 
  }

  const cChannel *channel = Channels.GetByNumber(ChannelNumber);
  if (channel != NULL && !channel->GroupSep()) 
  {
    cSchedulesLock schedLock;
    const cSchedules *scheds = cSchedules::Schedules(schedLock);
    if (scheds == NULL) 
    {
#ifdef LOGGING
      dsyslog("plugin-block: ChannelSwitch: scheds=null caused return");
#endif
      return;
    }

    const cSchedule *sched = scheds->GetSchedule(channel->GetChannelID());
    if (sched == NULL)
    {
#ifdef LOGGING
      dsyslog("plugin-block: ChannelSwitch: sched=null caused return");
#endif      
      return;
    }
    const cEvent *present = sched->GetPresentEvent();
    const cEvent *follow  = sched->GetFollowingEvent();
    if (present == NULL)
    {
#ifdef LOGGING
      dsyslog("plugin-block: present=null return");
#endif
      return;
    }
    if (!cControlBlock::IsRequested() && !EventsBlock.Acceptable(present->Title())) 
    {
      dsyslog("plugin-block: channel %d blocked", ChannelNumber);
      cControl::Launch(new cControlBlock(channel, present, follow));
    }
    else
    {
     cSetupBlock::LastAcceptableChannel=cDevice::CurrentChannel();
     cSetupBlock::user_direction=0;
    }
  }
  
}
  
void cStatusBlock::Replaying(const cControl *Control,
                                      const char *Name,
                                      const char *FileName, bool On)
{
 char *replaystate;
#ifdef LOGGING
 if (On) replaystate=(char*)"started";
 else replaystate=(char*)"stopped";
#endif
 cEventBlock::ReplayingRecording=(bool*)On;
 if (Name!=NULL) strncpy(cSetupBlock::ReplayingName,Name,sizeof(cSetupBlock::ReplayingName));
#ifdef LOGGING
 dsyslog("plugin-block: cStatusBlock: Replay: '%s' from '%s' %s",Name,FileName,replaystate);
#endif
}

void cStatusBlock::OsdProgramme(time_t PresentTime, const char *PresentTitle, const char *PresentSubtitle, time_t FollowingTime, const char *FollowingTitle, const char *FollowingSubtitle)
{
/*  char buffer[25];
  struct tm tm_r;
  dsyslog("status: cStatusBlock::OsdProgramme");
  strftime(buffer, sizeof(buffer), "%R", localtime_r(&PresentTime, &tm_r));
  dsyslog("%5s %s", buffer, PresentTitle);
  dsyslog("%5s %s", "", PresentSubtitle);
  strftime(buffer, sizeof(buffer), "%R", localtime_r(&FollowingTime, &tm_r));
  dsyslog("%5s %s", buffer, FollowingTitle);
  dsyslog("%5s %s", "", FollowingSubtitle);
*/
}