Autodetach unused receiver

Message ID 43BE7632.10709@cadsoft.de
State New
Headers

Commit Message

Klaus Schmidinger Jan. 6, 2006, 1:52 p.m. UTC
  Patrick Fischer wrote:
> So I have written an Patch that fixed that unused cReceiver will be 
> detached automaticly if the source was changed.
> 
> Attach a cReceiver to Channel ABC on PID xyz.
> If you switch to an other Channel on the same transponder the you can 
> still receiver the data on the PID xyz. But if you switch to an other 
> Channel on an other transponder, then the receiver needs to detached 
> (NeedsDetachReceivers). (depends on the Prio)
> 
> For me it seems to be forgotten from Klaus.
> So I hope my patch will fix it.
> I need it for my Plugin.
> 
> Hope this will included in 1.5.x :-)

Well, I'd say this should be included in version 1.4 ;-)

Please test the attached version of the patch, which is
how I'm going to do it. The line numbers may be somewhat
off, because I've already made some other changes.

Klaus
  

Patch

--- device.h	2005/12/29 14:51:59	1.67
+++ device.h	2006/01/06 13:20:25
@@ -520,6 +520,8 @@ 
        ///< Detaches the given receiver from this device.
   void DetachAll(int Pid);
        ///< Detaches all receivers from this device for this pid.
+  void DetachAllReceivers(void);
+       ///< Detaches all receivers from this device.
   };
 
 /// Derived cDevice classes that can receive channels will have to provide
--- device.c	2006/01/06 12:56:44	1.116
+++ device.c	2006/01/06 13:50:00
@@ -604,10 +604,14 @@ 
   if (LiveView)
      StopReplay();
 
+  // If this card is switched to an other transponder, any receivers still
+  // attached to it ineed to be automatically detached:
+  bool NeedsDetachReceivers = false;
+
   // If this card can't receive this channel, we must not actually switch
   // the channel here, because that would irritate the driver when we
   // start replaying in Transfer Mode immediately after switching the channel:
-  bool NeedsTransferMode = (LiveView && IsPrimaryDevice() && !ProvidesChannel(Channel, Setup.PrimaryLimit));
+  bool NeedsTransferMode = (LiveView && IsPrimaryDevice() && !ProvidesChannel(Channel, Setup.PrimaryLimit, &NeedsDetachReceivers));
 
   eSetChannelResult Result = scrOk;
 
@@ -615,11 +619,14 @@ 
   // use the card that actually can receive it and transfer data from there:
 
   if (NeedsTransferMode) {
-     cDevice *CaDevice = GetDevice(Channel, 0);
+     cDevice *CaDevice = GetDevice(Channel, 0, &NeedsDetachReceivers);
      if (CaDevice && CanReplay()) {
         cStatus::MsgChannelSwitch(this, 0); // only report status if we are actually going to switch the channel
-        if (CaDevice->SetChannel(Channel, false) == scrOk) // calling SetChannel() directly, not SwitchChannel()!
+        if (CaDevice->SetChannel(Channel, false) == scrOk) { // calling SetChannel() directly, not SwitchChannel()!
+           if (NeedsDetachReceivers)
+              CaDevice->DetachAllReceivers();
            cControl::Launch(new cTransferControl(CaDevice, Channel->Vpid(), Channel->Apids(), Channel->Dpids(), Channel->Spids()));
+           }
         else
            Result = scrNoTransfer;
         }
@@ -653,6 +660,8 @@ 
            }
 #endif
         }
+     if (NeedsDetachReceivers)
+        DetachAllReceivers();
      if (SetChannelDevice(Channel, LiveView)) {
         // Start section handling:
         if (sectionHandler) {
@@ -1269,6 +1278,15 @@ 
      }
 }
 
+void cDevice::DetachAllReceivers(void)
+{
+  cMutexLock MutexLock(&mutexReceiver);
+  for (int i = 0; i < MAXRECEIVERS; i++) {
+      if (receiver[i])
+         Detach(receiver[i]);
+      }
+}
+
 // --- cTSBuffer -------------------------------------------------------------
 
 cTSBuffer::cTSBuffer(int File, int Size, int CardIndex)