<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.tizen.messageport.Service">
- <method name="getProperties">
- <arg name="properties" type="a{sv}" direction="out"/>
- </method>
+ <property name="Id" type="u" access="read"/>
+ <property name="PortName" type="s" access="read"/>
+ <property name="IsTrusted" type="b" access="read"/>
<method name="unregister"/>
<method name="sendMessage">
<arg name="remote_service_id" type="u" direction="in"/>
<arg name="remote_port_name" type="s"/>
<arg name="remote_is_trusted" type="b"/>
</signal>
+ <signal name="unregistered"/>
</interface>
</node>
return TRUE;
}
-static GVariant *
-_msgport_service_to_variant (MsgPortDbusService *service)
-{
- GVariantBuilder v_builder;
- g_return_val_if_fail (service && MSGPORT_IS_DBUS_SERVICE (service), NULL);
-
- g_variant_builder_init (&v_builder, G_VARIANT_TYPE_VARDICT);
-
- g_variant_builder_add (&v_builder, "{sv}", "Id",
- g_variant_new_int32 (service->priv->id));
- g_variant_builder_add (&v_builder, "{sv}", "AappId",
- g_variant_new_string (msgport_dbus_manager_get_app_id
- (service->priv->owner)));
- g_variant_builder_add (&v_builder, "{sv}", "PortName",
- g_variant_new_string (service->priv->port_name));
- g_variant_builder_add (&v_builder, "{sv}", "IsTrusted",
- g_variant_new_boolean (service->priv->is_trusted));
-
- return g_variant_builder_end (&v_builder);
-}
-
-static gboolean
-_dbus_service_handle_get_properties (
- MsgPortDbusService *dbus_service,
- GDBusMethodInvocation *invocation,
- gpointer userdata)
-{
- g_return_val_if_fail (dbus_service && MSGPORT_IS_DBUS_SERVICE (dbus_service), FALSE);
-
- msgport_dbus_glue_service_complete_get_properties (
- dbus_service->priv->dbus_skeleton,
- invocation,
- _msgport_service_to_variant (dbus_service));
-
- return TRUE;
-}
-
static void
msgport_dbus_service_init (MsgPortDbusService *self)
{
G_CALLBACK (_dbus_service_handle_send_message), (gpointer)self);
g_signal_connect_swapped (priv->dbus_skeleton, "handle-unregister",
G_CALLBACK (_dbus_service_handle_unregister), (gpointer)self);
- g_signal_connect_swapped (priv->dbus_skeleton, "handle-get-properties",
- G_CALLBACK (_dbus_service_handle_get_properties), (gpointer)self);
self->priv = priv;
}
}
g_free (object_path);
+ /* set dbus-properties */
+ g_object_set (G_OBJECT (dbus_service->priv->dbus_skeleton),
+ "id", dbus_service->priv->id,
+ "port-name", dbus_service->priv->port_name,
+ "is-trusted", dbus_service->priv->is_trusted, NULL);
+
++object_conter;
return dbus_service;
messageport_error_e res;
MsgPortManager *manager = msgport_get_manager ();
+ g_assert (manager);
+ g_assert (MSGPORT_IS_MANAGER (manager));
+
res = msgport_manager_register_service (manager, name, is_trusted, cb, &port_id);
return port_id > 0 ? port_id : (int)res;
if (exists) *exists = (res == MESSAGEPORT_ERROR_NONE);
- return (int) res;
+ return res;
}
static messageport_error_e
#include "msgport-manager.h"
#include "msgport-service.h"
-#include "message-port.h" /* MESSAGEPORT_ERROR */
+#include "message-port.h" /* messageport_error_e */
#include "common/dbus-manager-glue.h"
#include "common/log.h"
#include "config.h" /* MESSAGEPORT_BUS_ADDRESS */
return id;
}
-static MsgPortService *
-_get_local_port (MsgPortManager *manager, int service_id)
-{
- const gchar *object_path = NULL;
- MsgPortService *service = NULL;
-
- object_path = g_hash_table_lookup (manager->local_services, GINT_TO_POINTER(service_id));
- if (!object_path) return NULL;
-
- service = MSGPORT_SERVICE (g_hash_table_lookup (manager->services, object_path));
- if (!service) {
- g_hash_table_remove (manager->local_services, GINT_TO_POINTER (service_id));
- return NULL;
- }
-
- return service;
-}
-
messageport_error_e
msgport_manager_register_service (MsgPortManager *manager, const gchar *port_name, gboolean is_trusted, messageport_message_cb message_cb, int *service_id)
{
if (error) {
WARN ("unable to register service (%s): %s", port_name, error->message);
+ messageport_error_e res = msgport_daemon_error_to_error(error);
g_error_free (error);
- return MESSAGEPORT_ERROR_IO_ERROR;
+ return res;
}
*service_id = _create_and_cache_service (manager, object_path, message_cb);
return MESSAGEPORT_ERROR_NONE;
}
+static MsgPortService *
+_get_local_port (MsgPortManager *manager, int service_id)
+{
+ const gchar *object_path = NULL;
+ MsgPortService *service = NULL;
+
+ object_path = g_hash_table_lookup (manager->local_services, GINT_TO_POINTER(service_id));
+ if (!object_path) return NULL;
+
+ service = MSGPORT_SERVICE (g_hash_table_lookup (manager->services, object_path));
+ if (!service) {
+ g_hash_table_remove (manager->local_services, GINT_TO_POINTER (service_id));
+ return NULL;
+ }
+
+ return service;
+}
+
messageport_error_e
msgport_manager_unregister_servcie (MsgPortManager *manager, int service_id)
{
GObject parent;
MsgPortDbusGlueService *proxy;
-
- int id; /* unique service id */
- gchar *name; /* service name */
- gboolean is_trusted; /* is trusted service */
-
- guint on_messge_signal_id;
- messageport_message_cb client_cb;
+ guint on_messge_signal_id;
+ messageport_message_cb client_cb;
};
-static int __object_counter;
-
G_DEFINE_TYPE(MsgPortService, msgport_service, G_TYPE_OBJECT)
static void
-_service_finalize (GObject *self)
-{
- MsgPortService *service = MSGPORT_SERVICE (self);
-
- g_free (service->name);
-
- G_OBJECT_CLASS (msgport_service_parent_class)->finalize (self);
-}
-
-static void
_service_dispose (GObject *self)
{
MsgPortService *service = MSGPORT_SERVICE (self);
GObjectClass *g_klass = G_OBJECT_CLASS(klass);
g_klass->dispose = _service_dispose;
- g_klass->finalize = _service_finalize;
}
static void
msgport_service_init (MsgPortService *service)
{
service->proxy = NULL;
- service->id = 0;
- service->name = NULL;
- service->is_trusted = FALSE;
service->client_cb = NULL;
service->on_messge_signal_id = 0;
}
static void
_on_got_message (MsgPortService *service, GVariant *data, const gchar *remote_app_id, const gchar *remote_port, gboolean remote_is_trusted, gpointer userdata)
{
+#ifdef ENABLE_DEBUG
gchar *str_data = g_variant_print (data, TRUE);
- DBG ("Message received : %s(%d)", str_data, g_variant_n_children (data));
+ DBG ("Message received : %s(%"G_GSIZE_FORMAT")", str_data, g_variant_n_children (data));
g_free (str_data);
+#endif
bundle *b = bundle_from_variant_map (data);
- service->client_cb (service->id, remote_app_id, remote_port, remote_is_trusted, b);
+ service->client_cb (msgport_dbus_glue_service_get_id (service->proxy), remote_app_id, remote_port, remote_is_trusted, b);
bundle_free (b);
}
MsgPortService *
msgport_service_new (GDBusConnection *connection, const gchar *path, messageport_message_cb message_cb)
{
- GVariant *properties = NULL;
- GVariantIter iter;
+ //GVariant *v_prop = NULL;
GError *error = NULL;
- MsgPortService *service = g_object_new (MSGPORT_TYPE_SERVICE, NULL);
+ MsgPortService *service = g_object_new (MSGPORT_TYPE_SERVICE, NULL);
if (!service) {
- /* FIXME: return no merory error */
return NULL;
}
service->proxy = msgport_dbus_glue_service_proxy_new_sync (connection,
- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
- NULL, path, NULL, &error);
+ G_DBUS_PROXY_FLAGS_NONE, NULL, path, NULL, &error);
if (!service->proxy) {
g_object_unref (service);
WARN ("failed create servie proxy for path '%s' : %s", path,
g_error_free (error);
return NULL;
}
-
- service->id = ++__object_counter;
-
- if (msgport_dbus_glue_service_call_get_properties_sync (service->proxy, &properties, NULL, &error)) {
- gchar *key = NULL;
- GVariant *value = NULL;
- g_variant_iter_init (&iter, properties);
-
- while (g_variant_iter_next (&iter, "{sv}", &key, &value)) {
- if ( !g_strcmp0 (key, "PortName")) service->name = g_strdup (g_variant_get_string (value, NULL));
- else if ( !g_strcmp0 (key, "IsTrusted")) service->is_trusted = g_variant_get_boolean (value);
- else {
- WARN ("Unknown property : %s", key);
- }
-
- g_free (key);
- g_variant_unref (value);
- }
+#if 0
+ v_prop = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (service->proxy), "Id");
+ if (v_prop) {
+ service->id = g_variant_get_uint32 (v_prop);
+ g_variant_unref (v_prop);
+ } else {
+ WARN ("Could not load property name 'Id' of service '%s'", path);
}
- else {
- WARN ("Failed to get properties from service proxy '%s' : %s",
- path, error->message);
- g_error_free (error);
+
+ v_prop = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (service->proxy), "PortName");
+ if (v_prop) {
+ service->name = g_strdup (g_variant_get_string (v_prop, NULL));
+ g_variant_unref (v_prop);
+ } else {
+ WARN ("Could not load property name 'PortName' of service '%s'", path);
}
+ v_prop = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (service->proxy), "IsTrusted");
+ if (v_prop) {
+ service->is_trusted = g_variant_get_boolean (v_prop);
+ g_object_unref (v_prop);
+ } else {
+ WARN ("Could not load property name 'IsTrusted' of service '%s'", path);
+ }
+#endif
service->client_cb = message_cb;
service->on_messge_signal_id = g_signal_connect_swapped (service->proxy, "on-message", G_CALLBACK (_on_got_message), service);
return service;
}
+guint
+msgport_service_id (MsgPortService *service)
+{
+ g_return_val_if_fail (service && MSGPORT_IS_SERVICE (service), 0);
+ g_return_val_if_fail (service->proxy && MSGPORT_DBUS_GLUE_IS_SERVICE (service->proxy), 0);
+
+ return msgport_dbus_glue_service_get_id (service->proxy);
+}
const gchar *
msgport_service_name (MsgPortService *service)
{
g_return_val_if_fail (service && MSGPORT_IS_SERVICE (service), NULL);
+ g_return_val_if_fail (service->proxy && MSGPORT_DBUS_GLUE_IS_SERVICE (service->proxy), NULL);
- return service->name;
+ return msgport_dbus_glue_service_get_port_name (service->proxy);
}
gboolean
msgport_service_is_trusted (MsgPortService *service)
{
g_return_val_if_fail (service && MSGPORT_IS_SERVICE (service), FALSE);
+ g_return_val_if_fail (service->proxy && MSGPORT_DBUS_GLUE_IS_SERVICE (service->proxy), FALSE);
- return service->is_trusted;
-}
-
-int
-msgport_service_id (MsgPortService *service)
-{
- g_return_val_if_fail (service && MSGPORT_IS_SERVICE (service), 0);
-
- return service->id;
+ return msgport_dbus_glue_service_get_is_trusted (service->proxy);
}
gboolean
gboolean
msgport_service_is_trusted (MsgPortService *service);
-int
+guint
msgport_service_id (MsgPortService *service);
gboolean
#include "msgport-utils.h"
+#include "common/dbus-error.h" /* MsgPortError */
#include "common/log.h"
static void
return b;
}
+messageport_error_e
+msgport_daemon_error_to_error (const GError *error)
+{
+ if (!error) return MESSAGEPORT_ERROR_NONE;
+
+ switch (error->code) {
+ case MSGPORT_ERROR_OUT_OF_MEMORY:
+ return MESSAGEPORT_ERROR_OUT_OF_MEMORY;
+ case MSGPORT_ERROR_NOT_FOUND:
+ return MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND;
+ case MSGPORT_ERROR_INVALID_PARAMS:
+ return MESSAGEPORT_ERROR_INVALID_PARAMETER;
+ case MSGPORT_ERROR_CERTIFICATE_MISMATCH:
+ return MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH;
+ case MSGPORT_ERROR_UNKNOWN:
+ case MSGPORT_ERROR_IO_ERROR:
+ return MESSAGEPORT_ERROR_IO_ERROR;
+ }
+}
#ifndef __MSGPORT_UTILS_H
-#define __MSGPORT_UTILS_
+#define __MSGPORT_UTILS_H
#include <bundle.h>
#include <glib.h>
+#include <message-port.h>
GVariant *bundle_to_variant_map (bundle *b);
bundle *bundle_from_variant_map (GVariant *v);
+messageport_error_e msgport_daemon_error_to_error (const GError *error);
+
#endif /* __MSGPORT_UTILS_H */