Exemplo n.º 1
0
  static void Get(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation)
  {
    // only update recordings list if empty
    // so we don't mess around with the index values returned by List
    if (recordings.Count() == 0)
       recordings.Update(true);

    cRecording *recording = NULL;
    GVariant *first = g_variant_get_child_value(Parameters, 0);
    GVariant *refValue = first;
    if (g_variant_is_of_type(first, G_VARIANT_TYPE_VARIANT))
       refValue = g_variant_get_child_value(first, 0);
    if (g_variant_is_of_type(refValue, G_VARIANT_TYPE_STRING)) {
       const char *path = NULL;
       g_variant_get(refValue, "&s", &path);
       if ((path != NULL) && *path)
          recording = recordings.GetByName(path);
       }
    else if (g_variant_is_of_type(refValue, G_VARIANT_TYPE_INT32)) {
       int number = 0;
       g_variant_get(refValue, "i", &number);
       if ((number > 0) && (number <= recordings.Count()))
          recording = recordings.Get(number - 1);
       }
    if (refValue != first)
       g_variant_unref(refValue);
    g_variant_unref(first);

    GVariant *rec = BuildRecording(recording);
    g_dbus_method_invocation_return_value(Invocation, g_variant_new_tuple(&rec, 1));
  };
Exemplo n.º 2
0
  static void Play(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation)
  {
    int replyCode = 501;
    cString replyMessage;
    cRecording *recording = NULL;
    int position = -1; // default: resume
    const char *hmsf = NULL;

    GVariant *first = g_variant_get_child_value(Parameters, 0);
    GVariant *refFirst = first;
    if (g_variant_is_of_type(first, G_VARIANT_TYPE_VARIANT))
       refFirst = g_variant_get_child_value(first, 0);
    GVariant *second = g_variant_get_child_value(Parameters, 1);
    GVariant *refSecond = first;
    if (g_variant_is_of_type(first, G_VARIANT_TYPE_VARIANT))
       refSecond = g_variant_get_child_value(first, 0);

    if (g_variant_is_of_type(refFirst, G_VARIANT_TYPE_STRING)) {
       const char *path = NULL;
       g_variant_get(refFirst, "&s", &path);
       if ((path != NULL) && *path) {
          recording = recordings.GetByName(path);
          if (recording == NULL) {
             recordings.Update(true);
             recording = recordings.GetByName(path);
             if (recording == NULL)
                replyMessage = cString::sprintf("recording \"%s\" not found", path);
             }
          }
       }
    else if (g_variant_is_of_type(refFirst, G_VARIANT_TYPE_INT32)) {
       int number = 0;
       g_variant_get(refFirst, "i", &number);
       if (number > 0) {
          recording = recordings.Get(number - 1);
          if (recording == NULL) {
             recordings.Update(true);
             recording = recordings.Get(number - 1);
             if (recording == NULL)
                replyMessage = cString::sprintf("recording \"%d\" not found", number);
             }
          }
       }

    if (recording != NULL) {
       if (g_variant_is_of_type(refSecond, G_VARIANT_TYPE_STRING)) {
          g_variant_get(refSecond, "&s", &hmsf);
          if ((hmsf != NULL) && *hmsf) {
             if (strcasecmp(hmsf, "begin") == 0) {
                position = 0;
                hmsf = NULL;
                }
             else
                position = HMSFToIndex(hmsf, recording->FramesPerSecond());
             }
          else
             hmsf = NULL;
          }
       else if (g_variant_is_of_type(refSecond, G_VARIANT_TYPE_INT32))
          g_variant_get(refSecond, "i", &position);

       replyCode = 250;
#if VDRVERSNUM < 10728
       cReplayControl::SetRecording(NULL, NULL);
#else
       cReplayControl::SetRecording(NULL);
#endif
       cControl::Shutdown();
       if (position >= 0) {
          cResumeFile resume(recording->FileName(), recording->IsPesRecording());
          if (position == 0)
             resume.Delete();
          else
             resume.Save(position);
          }
#if VDRVERSNUM < 10728
       cReplayControl::SetRecording(recording->FileName(), recording->Title());
#else
       cReplayControl::SetRecording(recording->FileName());
#endif
       cControl::Launch(new cReplayControl);
       cControl::Attach();

       if (hmsf != NULL)
          replyMessage = cString::sprintf("Playing recording \"%s\" from position %s", recording->FileName(), hmsf);
       else if (position >= 0)
          replyMessage = cString::sprintf("Playing recording \"%s\" from position %d", recording->FileName(), position);
       else
          replyMessage = cString::sprintf("Resume playing recording \"%s\"", recording->FileName());
       }
    cDBusHelper::SendReply(Invocation, replyCode, *replyMessage);
    if (refFirst != first)
       g_variant_unref(refFirst);
    g_variant_unref(first);
    if (refSecond != second)
       g_variant_unref(refSecond);
    g_variant_unref(second);
  };