multi-user: Expose function to check service user favorite 05/30505/3
authorZhang zhengguang <zhengguang.zhang@intel.com>
Wed, 19 Nov 2014 01:50:45 +0000 (09:50 +0800)
committerZhang zhengguang <zhengguang.zhang@intel.com>
Fri, 21 Nov 2014 06:43:27 +0000 (14:43 +0800)
Expose the function to check whether the service is favorite
to the current user.

Change-Id: Ib232f16c652ec94ef2e10b199a638a98554a1066

doc/service-api.txt
src/service.c

index 74c8345..0238d22 100644 (file)
@@ -122,6 +122,13 @@ Methods            dict GetProperties()  [deprecated]
 
                        Possible Errors: None
 
+               boolean GetUserFavorite() [experimental]
+
+                       This function is used to check whether this service
+                       is favorite to the current user.
+
+                       Possible Errors: None
+
 Signals                PropertyChanged(string name, variant value)
 
                        This signal indicates a changed value of the given
index 55cf02c..5eca970 100644 (file)
@@ -4472,6 +4472,30 @@ static DBusMessage *reset_counters(DBusConnection *conn,
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
+static DBusMessage *get_user_favorite(DBusConnection *conn,
+                                       DBusMessage *msg, void *user_data)
+{
+       DBusMessage *reply;
+       uid_t uid = USER_NONE;
+       dbus_bool_t user_favorite = false;
+       struct connman_service *service = user_data;
+
+       connman_dbus_get_connection_unix_user_sync(conn,
+                                       dbus_message_get_sender(msg),
+                                       &uid);
+       if (uid == USER_ROOT)
+               user_favorite = service->favorite;
+       else if (uid != USER_NONE && uid == service->user.favorite_user) {
+               DBG("The service is favorite to this user!");
+               user_favorite = true;
+       }
+
+       reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+       dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN,
+                               &user_favorite, DBUS_TYPE_INVALID);
+       return reply;
+}
+
 static struct _services_notify {
        int id;
        GHashTable *add;
@@ -4613,6 +4637,9 @@ static const GDBusMethodTable service_methods[] = {
                        GDBUS_ARGS({ "service", "o" }), NULL,
                        move_after) },
        { GDBUS_METHOD("ResetCounters", NULL, NULL, reset_counters) },
+       { GDBUS_METHOD("GetUserFavorite",
+                       NULL, GDBUS_ARGS({ "value", "v" }),
+                       get_user_favorite) },
        { },
 };