+ self.log(1, "'record service' failed")
+ return False
+ else:
+ event_id = self.eit
+ if event_id is None:
+ event_id = -1
+ prep_res = self.record_service.prepare(self.Filename + ".ts", self.begin, self.end, event_id )
+ if prep_res:
+ self.log(2, "'prepare' failed: error %d" % prep_res)
+ self.record_service = None
+ return False
+
+ if self.repeated:
+ epgcache = eEPGCache.getInstance()
+ queryTime=self.begin+(self.end-self.begin)/2
+ evt = epgcache.lookupEventTime(self.service_ref.ref, queryTime)
+ if evt:
+ self.description = evt.getShortDescription()
+ self.log(3, "prepare ok, writing meta information to %s" % self.Filename)
+ try:
+ f = open(self.Filename + ".ts.meta", "w")
+ f.write(str(self.service_ref) + "\n")
+ f.write(self.name + "\n")
+ f.write(self.description + "\n")
+ f.write(str(self.begin) + "\n")
+ f.close()
+ except IOError:
+ self.log(4, "failed to write meta information")
+ return True
+
+ def do_backoff(self):
+ if self.backoff == 0:
+ self.backoff = 5
+ else:
+ self.backoff *= 2
+ if self.backoff > 100:
+ self.backoff = 100
+ self.log(10, "backoff: retry in %d seconds" % self.backoff)
+
+ def activate(self):
+ next_state = self.state + 1
+ self.log(5, "activating state %d" % next_state)
+
+ if next_state == self.StatePrepared:
+ if self.tryPrepare():
+ self.log(6, "prepare ok, waiting for begin")
+ # fine. it worked, resources are allocated.
+ self.next_activation = self.begin
+ self.backoff = 0
+ return True
+
+ self.log(7, "prepare failed")
+ if self.first_try_prepare:
+ self.first_try_prepare = False
+ if config.recording.asktozap.value == 0:
+ self.log(8, "asking user to zap away")
+ Notifications.AddNotificationWithCallback(self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n"), timeout=20)
+ else: # zap without asking
+ self.log(9, "zap without asking")
+ Notifications.AddNotification(MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n"), type=MessageBox.TYPE_INFO, timeout=20)
+ self.failureCB(True)
+
+ self.do_backoff()
+ # retry
+ self.start_prepare = time.time() + self.backoff
+ return False
+ elif next_state == self.StateRunning:
+ # if this timer has been cancelled, just go to "end" state.
+ if self.cancelled:
+ return True
+
+ if self.justplay:
+ self.log(11, "zapping")
+ NavigationInstance.instance.playService(self.service_ref.ref)
+ return True
+ else:
+ self.log(11, "start recording")
+ record_res = self.record_service.start()
+
+ if record_res:
+ self.log(13, "start record returned %d" % record_res)
+ self.do_backoff()
+ # retry
+ self.begin = time.time() + self.backoff
+ return False
+
+ return True
+ elif next_state == self.StateEnded:
+ self.log(12, "stop recording")
+ if not self.justplay:
+ self.record_service.stop()
+ self.record_service = None
+ if self.afterEvent == AFTEREVENT.STANDBY:
+ if self.session is not None:
+ self.session.open(Standby, self)
+ elif self.afterEvent == AFTEREVENT.DEEPSTANDBY:
+ quitMainloop(1)
+ return True
+
+ def getNextActivation(self):
+ if self.state == self.StateEnded:
+ return self.end
+
+ next_state = self.state + 1
+
+ return {self.StatePrepared: self.start_prepare,
+ self.StateRunning: self.begin,
+ self.StateEnded: self.end }[next_state]
+
+ def failureCB(self, answer):
+ if answer == True:
+ self.log(13, "ok, zapped away")
+ #NavigationInstance.instance.stopUserServices()
+ NavigationInstance.instance.playService(self.service_ref.ref)
+ else:
+ self.log(14, "user didn't want to zap away, record will probably fail")