~ubuntu-branches/ubuntu/raring/tracker/raring

« back to all changes in this revision

Viewing changes to src/libtracker-miner/tracker-miner-object.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl
  • Date: 2011-08-26 00:26:14 UTC
  • mfrom: (4.3.17 sid)
  • Revision ID: package-import@ubuntu.com-20110826002614-4qjfs9jhh5gs4p13
Tags: 0.10.24-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
  "      <arg type='s' name='reason' direction='in' />"
88
88
  "      <arg type='i' name='cookie' direction='out' />"
89
89
  "    </method>"
 
90
  "    <method name='PauseForProcess'>"
 
91
  "      <arg type='s' name='application' direction='in' />"
 
92
  "      <arg type='s' name='reason' direction='in' />"
 
93
  "      <arg type='i' name='cookie' direction='out' />"
 
94
  "    </method>"
90
95
  "    <method name='Resume'>"
91
96
  "      <arg type='i' name='cookie' direction='in' />"
92
97
  "    </method>"
125
130
        gint cookie;
126
131
        gchar *application;
127
132
        gchar *reason;
 
133
        gchar *watch_name;
 
134
        guint watch_name_id;
128
135
} PauseData;
129
136
 
130
137
enum {
161
168
                                                GError                **error);
162
169
static void       pause_data_destroy           (gpointer                data);
163
170
static PauseData *pause_data_new               (const gchar            *application,
164
 
                                                const gchar            *reason);
 
171
                                                const gchar            *reason,
 
172
                                                const gchar            *watch_name,
 
173
                                                guint                   watch_name_id);
165
174
static void       handle_method_call           (GDBusConnection        *connection,
166
175
                                                const gchar            *sender,
167
176
                                                const gchar            *object_path,
665
674
 
666
675
static PauseData *
667
676
pause_data_new (const gchar *application,
668
 
                const gchar *reason)
 
677
                const gchar *reason,
 
678
                const gchar *watch_name,
 
679
                guint        watch_name_id)
669
680
{
670
681
        PauseData *data;
671
682
        static gint cookie = 1;
675
686
        data->cookie = cookie++;
676
687
        data->application = g_strdup (application);
677
688
        data->reason = g_strdup (reason);
 
689
        data->watch_name = g_strdup (watch_name);
 
690
        data->watch_name_id = watch_name_id;
678
691
 
679
692
        return data;
680
693
}
686
699
 
687
700
        pd = data;
688
701
 
 
702
        if (pd->watch_name_id) {
 
703
                g_bus_unwatch_name (pd->watch_name_id);
 
704
        }
 
705
 
 
706
        g_free (pd->watch_name);
 
707
 
689
708
        g_free (pd->reason);
690
709
        g_free (pd->application);
691
710
 
838
857
        return g_hash_table_size (miner->priv->pauses);
839
858
}
840
859
 
 
860
static void
 
861
pause_process_disappeared_cb (GDBusConnection *connection,
 
862
                              const gchar     *name,
 
863
                              gpointer         user_data)
 
864
{
 
865
        TrackerMiner *miner;
 
866
        PauseData *pd = NULL;
 
867
        GError *error = NULL;
 
868
        GHashTableIter iter;
 
869
        gpointer key, value;
 
870
 
 
871
        miner = user_data;
 
872
 
 
873
        g_message ("Process with name:'%s' has disappeared", name);
 
874
 
 
875
        g_hash_table_iter_init (&iter, miner->priv->pauses);
 
876
        while (g_hash_table_iter_next (&iter, &key, &value)) {
 
877
                PauseData *pd_iter = value;
 
878
 
 
879
                if (g_strcmp0 (name, pd_iter->watch_name) == 0) {
 
880
                        pd = pd_iter;
 
881
                        break;
 
882
                }
 
883
        }
 
884
 
 
885
        if (!pd) {
 
886
                g_critical ("Could not find PauseData for process with name:'%s'", name);
 
887
                return;
 
888
        }
 
889
 
 
890
        /* Resume */
 
891
        g_message ("Resuming pause associated with process");
 
892
 
 
893
        tracker_miner_resume (miner, pd->cookie, &error);
 
894
 
 
895
        if (error) {
 
896
                g_warning ("Could not resume miner, %s", error->message);
 
897
                g_error_free (error);
 
898
        }
 
899
}
 
900
 
841
901
static gint
842
 
tracker_miner_pause_internal (TrackerMiner  *miner,
843
 
                              const gchar   *application,
844
 
                              const gchar   *reason,
845
 
                              GError       **error)
 
902
miner_pause_internal (TrackerMiner  *miner,
 
903
                      const gchar   *application,
 
904
                      const gchar   *reason,
 
905
                      const gchar   *calling_name,
 
906
                      GError       **error)
846
907
{
847
908
        PauseData *pd;
848
909
        GHashTableIter iter;
849
910
        gpointer key, value;
 
911
        guint watch_name_id = 0;
850
912
 
851
913
        /* Check this is not a duplicate pause */
852
914
        g_hash_table_iter_init (&iter, miner->priv->pauses);
862
924
                }
863
925
        }
864
926
 
865
 
        pd = pause_data_new (application, reason);
 
927
        if (calling_name) {
 
928
                g_message ("Watching process with name:'%s'", calling_name);
 
929
                watch_name_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
 
930
                                                  calling_name,
 
931
                                                  G_BUS_NAME_WATCHER_FLAGS_NONE,
 
932
                                                  NULL,
 
933
                                                  pause_process_disappeared_cb,
 
934
                                                  miner,
 
935
                                                  NULL);
 
936
        }
 
937
 
 
938
        pd = pause_data_new (application, reason, calling_name, watch_name_id);
866
939
 
867
940
        g_hash_table_insert (miner->priv->pauses,
868
941
                             GINT_TO_POINTER (pd->cookie),
917
990
                application = miner->priv->name;
918
991
        }
919
992
 
920
 
        return tracker_miner_pause_internal (miner, application, reason, error);
 
993
        return miner_pause_internal (miner, application, reason, NULL, error);
921
994
}
922
995
 
923
996
/**
1008
1081
 *
1009
1082
 * Since: 0.10
1010
1083
 **/
1011
 
G_CONST_RETURN gchar *
 
1084
const gchar *
1012
1085
tracker_miner_get_dbus_full_name (TrackerMiner *miner)
1013
1086
{
1014
1087
        return miner->priv->full_name;
1024
1097
 *
1025
1098
 * Since: 0.10
1026
1099
 **/
1027
 
G_CONST_RETURN gchar *
 
1100
const gchar *
1028
1101
tracker_miner_get_dbus_full_path (TrackerMiner *miner)
1029
1102
{
1030
1103
        return miner->priv->full_path;
1142
1215
                                                application,
1143
1216
                                                reason);
1144
1217
 
1145
 
        cookie = tracker_miner_pause_internal (miner, application, reason, &local_error);
 
1218
        cookie = miner_pause_internal (miner, application, reason, NULL, &local_error);
 
1219
        if (cookie == -1) {
 
1220
                tracker_dbus_request_end (request, local_error);
 
1221
 
 
1222
                g_dbus_method_invocation_return_gerror (invocation, local_error);
 
1223
 
 
1224
                g_error_free (local_error);
 
1225
 
 
1226
                return;
 
1227
        }
 
1228
 
 
1229
        tracker_dbus_request_end (request, NULL);
 
1230
        g_dbus_method_invocation_return_value (invocation,
 
1231
                                               g_variant_new ("(i)", cookie));
 
1232
}
 
1233
 
 
1234
static void
 
1235
handle_method_call_pause_for_process (TrackerMiner          *miner,
 
1236
                                      GDBusMethodInvocation *invocation,
 
1237
                                      GVariant              *parameters)
 
1238
{
 
1239
        GError *local_error = NULL;
 
1240
        gint cookie;
 
1241
        const gchar *application = NULL, *reason = NULL;
 
1242
        TrackerDBusRequest *request;
 
1243
 
 
1244
        g_variant_get (parameters, "(&s&s)", &application, &reason);
 
1245
 
 
1246
        tracker_gdbus_async_return_if_fail (application != NULL, invocation);
 
1247
        tracker_gdbus_async_return_if_fail (reason != NULL, invocation);
 
1248
 
 
1249
        request = tracker_g_dbus_request_begin (invocation,
 
1250
                                                "%s(application:'%s', reason:'%s')",
 
1251
                                                __PRETTY_FUNCTION__,
 
1252
                                                application,
 
1253
                                                reason);
 
1254
 
 
1255
        cookie = miner_pause_internal (miner,
 
1256
                                       application,
 
1257
                                       reason,
 
1258
                                       g_dbus_method_invocation_get_sender (invocation),
 
1259
                                       &local_error);
1146
1260
        if (cookie == -1) {
1147
1261
                tracker_dbus_request_end (request, local_error);
1148
1262
 
1244
1358
 
1245
1359
        if (g_strcmp0 (method_name, "IgnoreNextUpdate") == 0) {
1246
1360
                handle_method_call_ignore_next_update (miner, invocation, parameters);
1247
 
        } else
1248
 
        if (g_strcmp0 (method_name, "Resume") == 0) {
 
1361
        } else if (g_strcmp0 (method_name, "Resume") == 0) {
1249
1362
                handle_method_call_resume (miner, invocation, parameters);
1250
 
        } else
1251
 
        if (g_strcmp0 (method_name, "Pause") == 0) {
 
1363
        } else if (g_strcmp0 (method_name, "Pause") == 0) {
1252
1364
                handle_method_call_pause (miner, invocation, parameters);
1253
 
        } else
1254
 
        if (g_strcmp0 (method_name, "GetPauseDetails") == 0) {
 
1365
        } else if (g_strcmp0 (method_name, "PauseForProcess") == 0) {
 
1366
                handle_method_call_pause_for_process (miner, invocation, parameters);
 
1367
        } else if (g_strcmp0 (method_name, "GetPauseDetails") == 0) {
1255
1368
                handle_method_call_get_pause_details (miner, invocation, parameters);
1256
 
        } else
1257
 
        if (g_strcmp0 (method_name, "GetProgress") == 0) {
 
1369
        } else if (g_strcmp0 (method_name, "GetProgress") == 0) {
1258
1370
                handle_method_call_get_progress (miner, invocation, parameters);
1259
 
        } else
1260
 
        if (g_strcmp0 (method_name, "GetStatus") == 0) {
 
1371
        } else if (g_strcmp0 (method_name, "GetStatus") == 0) {
1261
1372
                handle_method_call_get_status (miner, invocation, parameters);
1262
1373
        } else {
1263
1374
                g_assert_not_reached ();