Add object paths to introspection

Clean up headers, avoid exposing DBus api.
Remove notify should not have property changes
This commit is contained in:
Wim Taymans 2015-08-12 11:34:29 +02:00
parent e61cbb3931
commit b0e4cb4288
13 changed files with 58 additions and 48 deletions

View file

@ -21,7 +21,6 @@
#define __PINOS_CONTEXT_H__ #define __PINOS_CONTEXT_H__
#include <glib-object.h> #include <glib-object.h>
#include <gio/gio.h>
#include <client/subscribe.h> #include <client/subscribe.h>
#include <client/properties.h> #include <client/properties.h>

View file

@ -87,6 +87,8 @@ daemon_fill_info (PinosDaemonInfo *info, GDBusProxy *proxy)
GHashTable *changed = g_object_get_data (G_OBJECT (proxy), "pinos-changed-properties"); GHashTable *changed = g_object_get_data (G_OBJECT (proxy), "pinos-changed-properties");
info->id = proxy; info->id = proxy;
info->daemon_path = g_dbus_proxy_get_object_path (proxy);
info->change_mask = 0; info->change_mask = 0;
SET_STRING ("UserName", user_name, 0); SET_STRING ("UserName", user_name, 0);
SET_STRING ("HostName", host_name, 1); SET_STRING ("HostName", host_name, 1);
@ -140,6 +142,8 @@ client_fill_info (PinosClientInfo *info, GDBusProxy *proxy)
GHashTable *changed = g_object_get_data (G_OBJECT (proxy), "pinos-changed-properties"); GHashTable *changed = g_object_get_data (G_OBJECT (proxy), "pinos-changed-properties");
info->id = proxy; info->id = proxy;
info->client_path = g_dbus_proxy_get_object_path (proxy);
info->change_mask = 0; info->change_mask = 0;
SET_STRING ("Name", name, 0); SET_STRING ("Name", name, 0);
SET_PROPERTIES ("Properties", properties, 1); SET_PROPERTIES ("Properties", properties, 1);
@ -327,6 +331,7 @@ source_output_fill_info (PinosSourceOutputInfo *info, GDBusProxy *proxy)
GHashTable *changed = g_object_get_data (G_OBJECT (proxy), "pinos-changed-properties"); GHashTable *changed = g_object_get_data (G_OBJECT (proxy), "pinos-changed-properties");
info->id = proxy; info->id = proxy;
info->output_path = g_dbus_proxy_get_object_path (proxy);
info->change_mask = 0; info->change_mask = 0;
SET_STRING ("Client", client_path, 0); SET_STRING ("Client", client_path, 0);

View file

@ -31,6 +31,7 @@ G_BEGIN_DECLS
/** /**
* PinosDaemonInfo: * PinosDaemonInfo:
* @id: generic id of the daemon * @id: generic id of the daemon
* @daemon-path: unique path of the daemon
* @change_mask: bitfield of changed fields since last call * @change_mask: bitfield of changed fields since last call
* @user_name: name of the user that started the daemon * @user_name: name of the user that started the daemon
* @host_name: name of the machine the daemon is running on * @host_name: name of the machine the daemon is running on
@ -44,6 +45,7 @@ G_BEGIN_DECLS
*/ */
typedef struct { typedef struct {
gpointer id; gpointer id;
const char *daemon_path;
guint64 change_mask; guint64 change_mask;
const char *user_name; const char *user_name;
const char *host_name; const char *host_name;
@ -68,6 +70,7 @@ void pinos_context_get_daemon_info (PinosContext *context,
/** /**
* PinosClientInfo: * PinosClientInfo:
* @id: generic id of the client * @id: generic id of the client
* @client_path: unique path of the client
* @change_mask: bitfield of changed fields since last call * @change_mask: bitfield of changed fields since last call
* @name: name of client * @name: name of client
* @properties: extra properties * @properties: extra properties
@ -77,6 +80,7 @@ void pinos_context_get_daemon_info (PinosContext *context,
*/ */
typedef struct { typedef struct {
gpointer id; gpointer id;
const char *client_path;
guint64 change_mask; guint64 change_mask;
const char *name; const char *name;
PinosProperties *properties; PinosProperties *properties;
@ -189,6 +193,7 @@ typedef enum {
/** /**
* PinosSourceOutputInfo: * PinosSourceOutputInfo:
* @id: generic id of the output * @id: generic id of the output
* @path: the unique path of the output
* @change_mask: bitfield of changed fields since last call * @change_mask: bitfield of changed fields since last call
* @client_path: the owner client * @client_path: the owner client
* @source_path: the source path * @source_path: the source path
@ -202,6 +207,7 @@ typedef enum {
*/ */
typedef struct { typedef struct {
gpointer id; gpointer id;
const char *output_path;
guint64 change_mask; guint64 change_mask;
const char *client_path; const char *client_path;
const char *source_path; const char *source_path;

View file

@ -20,11 +20,8 @@
#ifndef __PINOS_MAIN_LOOP_H__ #ifndef __PINOS_MAIN_LOOP_H__
#define __PINOS_MAIN_LOOP_H__ #define __PINOS_MAIN_LOOP_H__
#include <gio/gio.h>
#include <glib-object.h> #include <glib-object.h>
#include "context.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define PINOS_TYPE_MAIN_LOOP (pinos_main_loop_get_type ()) #define PINOS_TYPE_MAIN_LOOP (pinos_main_loop_get_type ())

View file

@ -42,3 +42,15 @@ struct _PinosContextPrivate
GList *sources; GList *sources;
GList *source_outputs; GList *source_outputs;
}; };
void pinos_subscribe_get_proxy (PinosSubscribe *subscribe,
const gchar *name,
const gchar *object_path,
const gchar *interface_name,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDBusProxy * pinos_subscribe_get_proxy_finish (PinosSubscribe *subscribe,
GAsyncResult *res,
GError **error);

View file

@ -20,10 +20,9 @@
#ifndef __PINOS_STREAM_H__ #ifndef __PINOS_STREAM_H__
#define __PINOS_STREAM_H__ #define __PINOS_STREAM_H__
#include <gio/gio.h>
#include <glib-object.h> #include <glib-object.h>
#include "context.h" #include <client/context.h>
G_BEGIN_DECLS G_BEGIN_DECLS

View file

@ -21,6 +21,7 @@
#include "client/pinos.h" #include "client/pinos.h"
#include "client/enumtypes.h" #include "client/enumtypes.h"
#include "client/private.h"
struct _PinosSubscribePrivate struct _PinosSubscribePrivate
{ {
@ -125,22 +126,18 @@ on_proxy_properties_changed (GDBusProxy *proxy,
GVariant *value; GVariant *value;
gchar *key; gchar *key;
GHashTable *props; GHashTable *props;
gboolean need_notify = FALSE;
props = g_object_get_data (G_OBJECT (proxy), "pinos-changed-properties"); props = g_object_get_data (G_OBJECT (proxy), "pinos-changed-properties");
if (props == NULL) {
props = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
g_object_set_data_full (G_OBJECT (proxy),
"pinos-changed-properties",
props,
(GDestroyNotify) g_hash_table_unref);
}
g_variant_iter_init (&iter, changed_properties); g_variant_iter_init (&iter, changed_properties);
while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) { while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) {
if (!g_hash_table_contains (props, key)) if (!g_hash_table_contains (props, key))
g_hash_table_add (props, g_strdup (key)); g_hash_table_add (props, g_strdup (key));
need_notify = TRUE;
} }
notify_event (data->subscribe, data, PINOS_SUBSCRIPTION_EVENT_CHANGE); if (need_notify)
notify_event (data->subscribe, data, PINOS_SUBSCRIPTION_EVENT_CHANGE);
} }
static void static void
@ -161,6 +158,9 @@ remove_data (PinosSubscribe *subscribe,
if (data->pending) { if (data->pending) {
data->removed = TRUE; data->removed = TRUE;
} else { } else {
GHashTable *props = g_object_get_data (G_OBJECT (data->proxy), "pinos-changed-properties");
g_hash_table_remove_all (props);
notify_event (subscribe, data, PINOS_SUBSCRIPTION_EVENT_REMOVE); notify_event (subscribe, data, PINOS_SUBSCRIPTION_EVENT_REMOVE);
object_data_free (data); object_data_free (data);
} }
@ -209,6 +209,11 @@ on_proxy_created (GObject *source_object,
notify_event (subscribe, data, PINOS_SUBSCRIPTION_EVENT_NEW); notify_event (subscribe, data, PINOS_SUBSCRIPTION_EVENT_NEW);
g_object_set_data_full (G_OBJECT (data->proxy),
"pinos-changed-properties",
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL),
(GDestroyNotify) g_hash_table_unref);
for (walk = data->tasks; walk; walk = g_list_next (walk)) { for (walk = data->tasks; walk; walk = g_list_next (walk)) {
GTask *task = walk->data; GTask *task = walk->data;
g_task_return_pointer (task, g_object_ref (data->proxy), g_object_unref); g_task_return_pointer (task, g_object_ref (data->proxy), g_object_unref);

View file

@ -20,7 +20,7 @@
#ifndef __PINOS_SUBSCRIBE_H__ #ifndef __PINOS_SUBSCRIBE_H__
#define __PINOS_SUBSCRIBE_H__ #define __PINOS_SUBSCRIBE_H__
#include <glib.h> #include <glib-object.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -87,19 +87,6 @@ PinosSubscribe * pinos_subscribe_new (void);
PinosSubscriptionState pinos_subscribe_get_state (PinosSubscribe *subscribe); PinosSubscriptionState pinos_subscribe_get_state (PinosSubscribe *subscribe);
GError * pinos_subscribe_get_error (PinosSubscribe *subscribe); GError * pinos_subscribe_get_error (PinosSubscribe *subscribe);
void pinos_subscribe_get_proxy (PinosSubscribe *subscribe,
const gchar *name,
const gchar *object_path,
const gchar *interface_name,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDBusProxy * pinos_subscribe_get_proxy_finish (PinosSubscribe *subscribe,
GAsyncResult *res,
GError **error);
G_END_DECLS G_END_DECLS
#endif /* __PINOS_SUBSCRIBE_H__ */ #endif /* __PINOS_SUBSCRIBE_H__ */

View file

@ -21,7 +21,6 @@
#define __PINOS_CLIENT_SOURCE_H__ #define __PINOS_CLIENT_SOURCE_H__
#include <glib-object.h> #include <glib-object.h>
#include <gio/gio.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -29,7 +28,7 @@ typedef struct _PinosClientSource PinosClientSource;
typedef struct _PinosClientSourceClass PinosClientSourceClass; typedef struct _PinosClientSourceClass PinosClientSourceClass;
typedef struct _PinosClientSourcePrivate PinosClientSourcePrivate; typedef struct _PinosClientSourcePrivate PinosClientSourcePrivate;
#include "server/source.h" #include <server/source.h>
#define PINOS_TYPE_CLIENT_SOURCE (pinos_client_source_get_type ()) #define PINOS_TYPE_CLIENT_SOURCE (pinos_client_source_get_type ())
#define PINOS_IS_CLIENT_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_SOURCE)) #define PINOS_IS_CLIENT_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_SOURCE))

View file

@ -22,7 +22,7 @@
#include <glib-object.h> #include <glib-object.h>
#include "daemon.h" #include <server/daemon.h>
G_BEGIN_DECLS G_BEGIN_DECLS

View file

@ -21,7 +21,6 @@
#define __PINOS_DAEMON_H__ #define __PINOS_DAEMON_H__
#include <glib-object.h> #include <glib-object.h>
#include <gio/gio.h>
G_BEGIN_DECLS G_BEGIN_DECLS

View file

@ -21,7 +21,6 @@
#define __PINOS_SOURCE_H__ #define __PINOS_SOURCE_H__
#include <glib-object.h> #include <glib-object.h>
#include <gio/gio.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -29,8 +28,8 @@ typedef struct _PinosSource PinosSource;
typedef struct _PinosSourceClass PinosSourceClass; typedef struct _PinosSourceClass PinosSourceClass;
typedef struct _PinosSourcePrivate PinosSourcePrivate; typedef struct _PinosSourcePrivate PinosSourcePrivate;
#include "client/introspect.h" #include <client/introspect.h>
#include "server/source-output.h" #include <server/source-output.h>
#define PINOS_TYPE_SOURCE (pinos_source_get_type ()) #define PINOS_TYPE_SOURCE (pinos_source_get_type ())
#define PINOS_IS_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_SOURCE)) #define PINOS_IS_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_SOURCE))

View file

@ -87,6 +87,7 @@ dump_daemon_info (PinosContext *c, const PinosDaemonInfo *info, gpointer userdat
return FALSE; return FALSE;
g_print ("\tid: %p\n", info->id); g_print ("\tid: %p\n", info->id);
g_print ("\tdaemon-path: \"%s\"\n", info->daemon_path);
if (info->change_mask & (1 << 0)) if (info->change_mask & (1 << 0))
g_print ("\tuser-name: \"%s\"\n", info->user_name); g_print ("\tuser-name: \"%s\"\n", info->user_name);
if (info->change_mask & (1 << 1)) if (info->change_mask & (1 << 1))
@ -110,6 +111,7 @@ dump_client_info (PinosContext *c, const PinosClientInfo *info, gpointer userdat
return FALSE; return FALSE;
g_print ("\tid: %p\n", info->id); g_print ("\tid: %p\n", info->id);
g_print ("\tclient-path: \"%s\"\n", info->client_path);
if (info->change_mask & (1 << 0)) if (info->change_mask & (1 << 0))
g_print ("\tname: \"%s\"\n", info->name); g_print ("\tname: \"%s\"\n", info->name);
if (info->change_mask & (1 << 1)) if (info->change_mask & (1 << 1))
@ -125,16 +127,15 @@ dump_source_info (PinosContext *c, const PinosSourceInfo *info, gpointer userdat
return FALSE; return FALSE;
g_print ("\tid: %p\n", info->id); g_print ("\tid: %p\n", info->id);
g_print ("\tsource-path: \"%s\"\n", info->source_path);
if (info->change_mask & (1 << 0)) if (info->change_mask & (1 << 0))
g_print ("\tsource-path: \"%s\"\n", info->source_path);
if (info->change_mask & (1 << 1))
g_print ("\tname: \"%s\"\n", info->name); g_print ("\tname: \"%s\"\n", info->name);
if (info->change_mask & (1 << 1))
print_properties (info->properties);
if (info->change_mask & (1 << 2)) if (info->change_mask & (1 << 2))
g_print ("\tstate: %d\n", info->state); g_print ("\tstate: %d\n", info->state);
if (info->change_mask & (1 << 3)) if (info->change_mask & (1 << 3))
print_formats ("possible formats", info->possible_formats); print_formats ("possible formats", info->possible_formats);
if (info->change_mask & (1 << 4))
print_properties (info->properties);
return TRUE; return TRUE;
} }
@ -146,6 +147,7 @@ dump_source_output_info (PinosContext *c, const PinosSourceOutputInfo *info, gpo
return FALSE; return FALSE;
g_print ("\tid: %p\n", info->id); g_print ("\tid: %p\n", info->id);
g_print ("\toutput-path: \"%s\"\n", info->output_path);
if (info->change_mask & (1 << 0)) if (info->change_mask & (1 << 0))
g_print ("\tclient-path: \"%s\"\n", info->client_path); g_print ("\tclient-path: \"%s\"\n", info->client_path);
if (info->change_mask & (1 << 1)) if (info->change_mask & (1 << 1))
@ -163,7 +165,7 @@ dump_source_output_info (PinosContext *c, const PinosSourceOutputInfo *info, gpo
} }
static void static void
dump_object (PinosContext *context, GDBusProxy *proxy, PinosSubscriptionFlags flags) dump_object (PinosContext *context, gpointer id, PinosSubscriptionFlags flags)
{ {
if (flags & PINOS_SUBSCRIPTION_FLAG_DAEMON) { if (flags & PINOS_SUBSCRIPTION_FLAG_DAEMON) {
pinos_context_get_daemon_info (context, pinos_context_get_daemon_info (context,
@ -174,7 +176,7 @@ dump_object (PinosContext *context, GDBusProxy *proxy, PinosSubscriptionFlags fl
} }
else if (flags & PINOS_SUBSCRIPTION_FLAG_CLIENT) { else if (flags & PINOS_SUBSCRIPTION_FLAG_CLIENT) {
pinos_context_get_client_info_by_id (context, pinos_context_get_client_info_by_id (context,
proxy, id,
PINOS_CLIENT_INFO_FLAGS_NONE, PINOS_CLIENT_INFO_FLAGS_NONE,
dump_client_info, dump_client_info,
NULL, NULL,
@ -182,7 +184,7 @@ dump_object (PinosContext *context, GDBusProxy *proxy, PinosSubscriptionFlags fl
} }
else if (flags & PINOS_SUBSCRIPTION_FLAG_SOURCE) { else if (flags & PINOS_SUBSCRIPTION_FLAG_SOURCE) {
pinos_context_get_source_info_by_id (context, pinos_context_get_source_info_by_id (context,
proxy, id,
PINOS_SOURCE_INFO_FLAGS_FORMATS, PINOS_SOURCE_INFO_FLAGS_FORMATS,
dump_source_info, dump_source_info,
NULL, NULL,
@ -190,7 +192,7 @@ dump_object (PinosContext *context, GDBusProxy *proxy, PinosSubscriptionFlags fl
} }
else if (flags & PINOS_SUBSCRIPTION_FLAG_SOURCE_OUTPUT) { else if (flags & PINOS_SUBSCRIPTION_FLAG_SOURCE_OUTPUT) {
pinos_context_get_source_output_info_by_id (context, pinos_context_get_source_output_info_by_id (context,
proxy, id,
PINOS_SOURCE_OUTPUT_INFO_FLAGS_NONE, PINOS_SOURCE_OUTPUT_INFO_FLAGS_NONE,
dump_source_output_info, dump_source_output_info,
NULL, NULL,
@ -207,17 +209,18 @@ subscription_cb (PinosContext *context,
{ {
switch (type) { switch (type) {
case PINOS_SUBSCRIPTION_EVENT_NEW: case PINOS_SUBSCRIPTION_EVENT_NEW:
g_print ("added: %s\n", g_dbus_proxy_get_object_path (id)); g_print ("added:\n");
dump_object (context, G_DBUS_PROXY (id), flags); dump_object (context, id, flags);
break; break;
case PINOS_SUBSCRIPTION_EVENT_CHANGE: case PINOS_SUBSCRIPTION_EVENT_CHANGE:
g_print ("changed: %s\n", g_dbus_proxy_get_object_path (id)); g_print ("changed:\n");
dump_object (context, G_DBUS_PROXY (id), flags); dump_object (context, id, flags);
break; break;
case PINOS_SUBSCRIPTION_EVENT_REMOVE: case PINOS_SUBSCRIPTION_EVENT_REMOVE:
g_print ("removed: %s\n", g_dbus_proxy_get_object_path (id)); g_print ("removed:\n");
dump_object (context, id, flags);
break; break;
} }
} }