Skip to content
Snippets Groups Projects

Draft: Re-implement missing functionality-peermanager

Files
8
+ 18
141
@@ -19,7 +19,6 @@
#include "peer-manager.h"
static void vdd_peer_manager_async_initable_init (GAsyncInitableIface *iface);
static void vdd_peer_manager_peer_manager_init (CsrPeerManagerInterface *iface);
static void vdd_peer_manager_dispose (GObject *object);
@@ -39,10 +38,6 @@ static void vdd_peer_manager_ensure_peer_info_async (CsrPeerManag
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
/* TODO function returning CbyProcessInfo for
* vdd_peer_manager_ensure_peer_info_finish need to
* update with latest implementation
*/
static void * vdd_peer_manager_ensure_peer_info_finish (CsrPeerManager *peer_manager,
GAsyncResult *result,
@@ -75,18 +70,12 @@ static void authority_changed_cb (PolkitAuthor
/* Structure for values in the peers table. */
typedef struct
{
/* TODO
* CbyProcessInfo *process_info;
**/
guint watch_id;
} PeerInfo;
static void
peer_info_free (PeerInfo *info)
{
/*TODO
* g_object_unref (info->process_info);
**/
if (info->watch_id != 0)
g_bus_unwatch_name (info->watch_id);
@@ -95,6 +84,22 @@ peer_info_free (PeerInfo *info)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PeerInfo, peer_info_free)
static void
polkitsubject_call_data_free (PolkitSubject *data)
{
g_free (data);
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PolkitSubject, polkitsubject_call_data_free)
Please register or sign in to reply
static void
polkit_call_data_free (PolkitAuthorizationResult *data)
{
g_free (data);
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PolkitAuthorizationResult, polkit_call_data_free)
/**
* VddPeerManager:
*
@@ -355,13 +360,6 @@ vdd_peer_manager_new_finish (GAsyncResult *result,
result, error));
}
static void ensure_peer_info_cb (GObject *object,
GAsyncResult *result,
gpointer user_data);
static void peer_vanished_cb (GDBusConnection *connection,
const gchar *name,
gpointer user_data);
typedef struct
{
gchar *sender; /* owned */
@@ -398,9 +396,6 @@ vdd_peer_manager_ensure_peer_info_async (CsrPeerManager *peer_manager,
if (peer_info != NULL)
{
/*TODO
* g_task_return_pointer (task, g_object_ref (peer_info->process_info),g_object_unref);
**/
return;
}
else
@@ -413,108 +408,17 @@ vdd_peer_manager_ensure_peer_info_async (CsrPeerManager *peer_manager,
g_task_set_task_data (task, g_steal_pointer (&data),
(GDestroyNotify) ensure_peer_info_data_free);
/* TODO
cby_process_info_new_for_dbus_sender_async (sender, connection,
cancellable,
ensure_peer_info_cb,
g_steal_pointer (&task));
*/
}
}
static void
ensure_peer_info_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
VddPeerManager *self;
g_autoptr (GTask) task = G_TASK (user_data);
EnsurePeerInfoData *data;
/* TODO
* g_autoptr (CbyProcessInfo) process_info = NULL;
*/
g_autoptr (PeerInfo) peer_info = NULL;
GError *error = NULL;
self = VDD_PEER_MANAGER (g_task_get_source_object (task));
/* TODO
* process_info = cby_process_info_new_for_dbus_sender_finish (result, &error);
*/
data = g_task_get_task_data (task);
if (error != NULL)
{
g_task_return_error (task, error);
return;
}
/* Add to the table of watched peers. We can guarantee that the
* peer_vanished_cb() callback will not be invoked from within our call to
* g_bus_watch_name_on_connection(), so there’s no need to worry about this
* PeerInfo being destroyed part-way through creation.
*
* If there were two concurrent calls to
* vdd_peer_manager_ensure_peer_info_async() for the same peer, the #PeerInfo
* for the second one will replace that from the first, which is fine.
*
* FIXME: Add a unit test for this. */
peer_info = g_new0 (PeerInfo, 1);
/*TODO
* peer_info->process_info = g_object_ref (process_info);
**/
peer_info->watch_id = g_bus_watch_name_on_connection (data->connection,
data->sender,
G_BUS_NAME_WATCHER_FLAGS_NONE,
NULL,
peer_vanished_cb, self,
NULL);
//TODO
#if 0
g_hash_table_insert (self->peers, g_strdup (data->sender),
g_steal_pointer (&peer_info));
g_object_notify (G_OBJECT (self), "peers");
g_task_return_pointer (task, g_object_ref (process_info), g_object_unref);
#endif
}
static void
peer_vanished_cb (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
VddPeerManager *self = VDD_PEER_MANAGER (user_data);
g_autofree gchar *name_copy = g_strdup (name);
/* Signal the vanishing, if this was a peer we were tracking. Keep a copy of
* the name for the signal emission, as it may be freed by GIO when we unwatch
* the name as part of the cleanup triggered by g_hash_table_remove(). */
if (g_hash_table_remove (self->peers, name))
{
DEBUG ("Peer ‘%s’ vanished.", name_copy);
g_signal_emit_by_name (self, "peer-vanished", name_copy);
g_object_notify (G_OBJECT (self), "peers");
}
}
/* TODO function returning CbyProcessInfo for
* vdd_peer_manager_ensure_peer_info_finish need to
* update with latest implementation
*/
static void *
vdd_peer_manager_ensure_peer_info_finish (CsrPeerManager *peer_manager,
GAsyncResult *result,
GError **error)
{
GTask *task = G_TASK (result);
g_return_val_if_fail (g_task_is_valid (result, peer_manager), NULL);
/* TODO
return g_task_propagate_pointer (task, error);
*/
}
typedef struct
@@ -587,10 +491,7 @@ check_authorization_cb1 (GObject *obj,
g_autoptr (GTask) task = G_TASK (user_data);
AuthorizationCheckData *data;
g_autoptr (GError) error = NULL;
/*TODO
* g_autoptr (PolkitSubject) subject = NULL;
* g_autoptr (CbyProcessInfo) process_info = NULL;
* */
g_autoptr (PolkitSubject) subject = NULL;
data = g_task_get_task_data (task);
/* Get the peer’s info. */
@@ -603,22 +504,6 @@ check_authorization_cb1 (GObject *obj,
return;
}
//TODO
#if 0
/* FIXME: Do we want to do other authorisation checks against
* @process_info? */
if (cby_process_info_get_process_type (process_info) ==
CBY_PROCESS_TYPE_UNKNOWN)
{
g_task_return_new_error (task, G_DBUS_ERROR,
G_DBUS_ERROR_ACCESS_DENIED,
_("Unknown-type processes cannot access vehicle "
"data."));
return;
}
#endif
/* Check the peer’s authorisation. */
{
g_auto (GStrv) keys = NULL;
@@ -639,9 +524,7 @@ check_authorization_cb1 (GObject *obj,
* #CbyProcessInfo. This won’t work if we’re running on the session bus.
* */
/*TODO
subject = polkit_system_bus_name_new (data->sender);
*/
polkit_authority_check_authorization (self->authority, NULL,
data->action_id, data->details,
@@ -657,14 +540,9 @@ check_authorization_cb2 (GObject *obj,
gpointer user_data)
{
g_autoptr (GTask) task = G_TASK (user_data);
/* TODO
g_autoptr (PolkitAuthorizationResult) auth_result = NULL;
* */
g_autoptr (PolkitAuthorizationResult) auth_result = NULL;
g_autoptr (GError) error = NULL;
//TODO
#if 0
auth_result = polkit_authority_check_authorization_finish (POLKIT_AUTHORITY (obj),
result, &error);
@@ -700,7 +578,6 @@ check_authorization_cb2 (GObject *obj,
return;
}
#endif
g_task_return_boolean (task, TRUE);
}
Loading