2 * mvs-minfo-provider-service.c
4 * This file is part of maevies
5 * Copyright (C) 2010 Simón Pena <spenap@gmail.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
19 #include <dbus/dbus-glib-bindings.h>
21 #include "mvs-minfo-provider-service.h"
22 #include "mvs-minfo-provider.h"
24 #define MINFO_PROVIDER_SERVICE_OBJECT_PATH "/MInfoProvider"
25 #define MINFO_PROVIDER_SERVICE_NAME "com.simonpena.maevies.minfoprovider"
27 G_DEFINE_TYPE (MvsMInfoProviderService, mvs_minfo_provider_service, G_TYPE_OBJECT)
40 mvs_minfo_provider_service_signals[LAST_SIGNAL] = { 0 };
42 #define GET_PRIVATE(o) \
43 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MVS_TYPE_MINFO_PROVIDER_SERVICE, MvsMInfoProviderServicePrivate))
45 struct _MvsMInfoProviderServicePrivate {
46 MvsMInfoProvider *minfo_provider;
47 DBusGConnection *connection;
51 mvs_minfo_provider_service_query (MvsMInfoProviderService *self,
56 return mvs_minfo_provider_query (self->priv->minfo_provider,
60 #include "mvs-minfo-provider-service-glue.h"
63 response_received_cb (MvsMInfoProvider *provider, gpointer response,
66 MvsMInfoProviderService *self = MVS_MINFO_PROVIDER_SERVICE (user_data);
67 g_signal_emit (self, mvs_minfo_provider_service_signals[RESPONSE_RECEIVED], 0);
71 setup_dbus (MvsMInfoProviderService *self)
74 guint request_name_result;
77 proxy = dbus_g_proxy_new_for_name (self->priv->connection,
82 if (!org_freedesktop_DBus_request_name (proxy,
83 MINFO_PROVIDER_SERVICE_NAME,
84 0, &request_name_result,
86 g_warning ("Unable to register service: %s", error->message);
90 dbus_g_connection_register_g_object (self->priv->connection,
91 MINFO_PROVIDER_SERVICE_OBJECT_PATH,
94 g_object_unref (proxy);
98 mvs_minfo_provider_service_set_property (GObject *object, guint property_id,
99 const GValue *value, GParamSpec *pspec)
101 MvsMInfoProviderService *self = MVS_MINFO_PROVIDER_SERVICE (object);
103 switch (property_id) {
105 if (!self->priv->connection) {
106 DBusGConnection *tmp = g_value_get_pointer (value);
108 self->priv->connection =
109 dbus_g_connection_ref (tmp);
113 g_assert (self->priv->connection);
116 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
121 mvs_minfo_provider_service_finalize (GObject *object)
123 MvsMInfoProviderService *self = MVS_MINFO_PROVIDER_SERVICE (object);
125 if (self->priv->connection) {
126 dbus_g_connection_unref (self->priv->connection);
128 g_object_unref (self->priv->minfo_provider);
129 G_OBJECT_CLASS (mvs_minfo_provider_service_parent_class)->finalize (object);
133 mvs_minfo_provider_service_class_init (MvsMInfoProviderServiceClass *klass)
135 GObjectClass *object_class = G_OBJECT_CLASS (klass);
137 g_type_class_add_private (klass, sizeof (MvsMInfoProviderServicePrivate));
139 object_class->set_property = mvs_minfo_provider_service_set_property;
140 object_class->finalize = mvs_minfo_provider_service_finalize;
142 g_object_class_install_property
143 (object_class, PROP_DBUSGCONN,
144 g_param_spec_pointer ("connection", "DBusGConnection",
146 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
148 dbus_g_object_type_install_info (MVS_TYPE_MINFO_PROVIDER_SERVICE,
149 &dbus_glib_mvs_minfo_provider_service_object_info);
151 mvs_minfo_provider_service_signals[RESPONSE_RECEIVED] =
152 g_signal_new ("response-received",
153 G_TYPE_FROM_CLASS (klass),
158 g_cclosure_marshal_VOID__VOID,
165 mvs_minfo_provider_service_init (MvsMInfoProviderService *self)
167 self->priv = GET_PRIVATE (self);
168 self->priv->minfo_provider = mvs_minfo_provider_new ();
169 self->priv->connection = NULL;
171 g_signal_connect (self->priv->minfo_provider, "response-received",
172 G_CALLBACK (response_received_cb), self);
175 MvsMInfoProviderService*
176 mvs_minfo_provider_service_new (DBusGConnection *connection)
178 return g_object_new (MVS_TYPE_MINFO_PROVIDER_SERVICE,
179 "connection", connection, NULL);