summaryrefslogtreecommitdiff
path: root/block/status.c
blob: 64b9d850e19883a40a1c7c67373fd2f607013e03 (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
/**
 * based on status.c,v 1.2 2007/05/08 10:16:23 thomas
 *
 * version by Midas
 *
 */

#include <vdr/channels.h>

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

cStatusBlock::cStatusBlock(void):
    cStatus(),
    mLastChannel(0) // int
{
}

void cStatusBlock::ChannelSwitch(const cDevice *Device, int ChannelNumber)
{
  printf("cStatusBlock::ChannelSwitch(%p, %d)\n", Device, ChannelNumber);

#ifdef LOGGING
  dsyslog("plugin-block: cStatusBlock was informed about channel switch at device %d, channel no %d",Device->DeviceNumber(),ChannelNumber);
  dsyslog("plugin-block: cDevice::CurrentChannel %d",cDevice::CurrentChannel());
  dsyslog("plugin-block: Device %d, ActualDevice %d, primary Device %d",Device->DeviceNumber(),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",ii,tmpdev->Replaying(),tmpdev->Transferring());
  }
#endif


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

  if (mLastChannel==0)
  {
#ifdef LOGGING
    dsyslog("plugin-block: Did nothing cause mLastChannel=0 (set to %d)",cDevice::CurrentChannel());
#endif
    mLastChannel=cDevice::CurrentChannel();
    return;
  }
  
  if (ChannelNumber==0) 
  {
    mLastChannel=cDevice::CurrentChannel(); 
#ifdef LOGGING
    dsyslog("plugin-block: Did nothing because ChannelNumber=0 (some switch is in progress)"); 
#endif
    return; //seems that switching is in progress
  }
  
  if (ChannelNumber!=cDevice::CurrentChannel())
  {
#ifdef LOGGING
    dsyslog("plugin-block: Did nothing because ChannelNumber!=CurrentChannel (switch still in progress)");
#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)
		              return;

			const cSchedule *sched = scheds->GetSchedule(channel->GetChannelID());
			if (sched == NULL)
				return;

			const cEvent *present = sched->GetPresentEvent();
			const cEvent *follow  = sched->GetFollowingEvent();
			if (present == NULL)
				return;
          		
          		if (!cControlBlock::IsRequested() && !EventsBlock.Acceptable(present->Title())) {
				isyslog("plugin-block: channel %d is not acceptable at present", ChannelNumber);
				cControl::Launch(new cControlBlock(mLastChannel, channel, present, follow));
				mLastChannel=0;
			}
		}


}