~jamesh/mediascanner/ca-certs-dependency

« back to all changes in this revision

Viewing changes to src/grlmediascanner/mediasource.cpp

  • Committer: Tarmac
  • Author(s): James Henstridge
  • Date: 2013-09-24 07:40:59 UTC
  • mfrom: (386.1.2 multiple-notify)
  • Revision ID: tarmac-20130924074059-kdruohj9v1ksurzo
If notify_change_start() is called multiple times, don't return an error on the subsequent calls.  Instead, increment a counter so we can disable change notification on an equal number of calls to notify_change_stop().

Approved by PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
        : root_manager_(new mediascanner::MediaRootManager)
66
66
        , task_facade_(root_manager_)
67
67
        , task_manager_("media_scanner media source")
68
 
        , change_id_(0) {
 
68
        , change_id_(0)
 
69
        , change_notify_count_(0) {
69
70
        root_manager_->initialize();
70
71
    }
71
72
 
80
81
 
81
82
    mediascanner::dbus::MediaScannerProxy service_proxy_;
82
83
    unsigned change_id_;
 
84
    int change_notify_count_;
83
85
};
84
86
 
85
87
namespace mediascanner {
887
889
        GRL_MEDIA_SCANNER_SOURCE(source);
888
890
    g_return_val_if_fail(media_scanner_source != NULL, false);
889
891
 
890
 
    if (media_scanner_source->priv->change_id_) {
891
 
        g_set_error_literal(error, GRL_CORE_ERROR,
892
 
                            GRL_CORE_ERROR_NOTIFY_CHANGED_FAILED,
893
 
                            "Already subsribed to change notifications");
894
 
        return false;
 
892
    // Has change notification already been enabled?
 
893
    media_scanner_source->priv->change_notify_count_++;
 
894
    if (media_scanner_source->priv->change_notify_count_ > 1) {
 
895
        return true;
895
896
    }
896
897
 
897
898
    // Unsubscribe to D-Bus signal
937
938
        GRL_MEDIA_SCANNER_SOURCE(source);
938
939
    g_return_val_if_fail(media_scanner_source != NULL, false);
939
940
 
940
 
    if (not media_scanner_source->priv->change_id_) {
 
941
    if (not media_scanner_source->priv->change_id_ ||
 
942
        media_scanner_source->priv->change_notify_count_ <= 0) {
941
943
        g_set_error_literal(error, GRL_CORE_ERROR,
942
944
                            GRL_CORE_ERROR_NOTIFY_CHANGED_FAILED,
943
945
                            "Not subsribed to change notifications");
944
946
        return false;
945
947
    }
946
948
 
 
949
    // If change notification has been enabled more than once, only
 
950
    // disable it on an equal number of notify_change_stop() calls.
 
951
    media_scanner_source->priv->change_notify_count_--;
 
952
    if (media_scanner_source->priv->change_notify_count_ > 0) {
 
953
        return true;
 
954
    }
 
955
 
947
956
    // Unsubscribe from D-Bus signal
948
957
    // FIXME(M5): Wrap nicely in <dbusutils.h>
949
958
    dbus::MediaScannerProxy *const service =