-#include "E_DBus.h"
-#include "e_dbus_private.h"
-#include <Eina.h>
-#include <stdio.h>
-#include <stdlib.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <string.h>
+#include "e_dbus_private.h"
+
static E_DBus_Interface *introspectable_interface = NULL;
static E_DBus_Interface *properties_interface = NULL;
typedef struct E_DBus_Method E_DBus_Method;
typedef struct E_DBus_Signal E_DBus_Signal;
-Ecore_Strbuf * e_dbus_object_introspect(E_DBus_Object *obj);
+Eina_Strbuf * e_dbus_object_introspect(E_DBus_Object *obj);
static void e_dbus_object_unregister(DBusConnection *conn, void *user_data);
static DBusHandlerResult e_dbus_object_handler(DBusConnection *conn, DBusMessage *message, void *user_data);
static E_DBus_Signal *e_dbus_signal_new(const char *name, const char *signature);
static void e_dbus_object_signal_free(E_DBus_Signal *s);
-static void _introspect_indent_append(Ecore_Strbuf *buf, int level);
-static void _introspect_interface_append(Ecore_Strbuf *buf, E_DBus_Interface *iface, int level);
-static void _introspect_method_append(Ecore_Strbuf *buf, E_DBus_Method *method, int level);
-static void _introspect_signal_append(Ecore_Strbuf *buf, E_DBus_Signal *signal, int level);
-static void _introspect_arg_append(Ecore_Strbuf *buf, const char *type, const char *direction, int level);
+static void _introspect_indent_append(Eina_Strbuf *buf, int level);
+static void _introspect_interface_append(Eina_Strbuf *buf, E_DBus_Interface *iface, int level);
+static void _introspect_method_append(Eina_Strbuf *buf, E_DBus_Method *method, int level);
+static void _introspect_signal_append(Eina_Strbuf *buf, E_DBus_Signal *signal, int level);
+static void _introspect_arg_append(Eina_Strbuf *buf, const char *type, const char *direction, int level);
//static Eina_List *standard_methods = NULL;
cb_introspect(E_DBus_Object *obj, DBusMessage *msg)
{
DBusMessage *ret;
- Ecore_Strbuf *buf;
+ Eina_Strbuf *buf;
if (obj->introspection_dirty || !obj->introspection_data)
{
}
if (obj->introspection_data) free(obj->introspection_data);
- obj->introspection_data = strdup(ecore_strbuf_string_get(buf));
- ecore_strbuf_free(buf);
+ obj->introspection_data = strdup(eina_strbuf_string_get(buf));
+ eina_strbuf_free(buf);
}
//printf("XML: \n\n%s\n\n", obj->introspection_data);
ret = dbus_message_new_method_return(msg);
e_dbus_object_init(void)
{
introspectable_interface = e_dbus_interface_new("org.freedesktop.DBus.Introspectable");
- properties_interface = e_dbus_interface_new("org.freedesktop.DBus.Properties");
+ properties_interface = e_dbus_interface_new(E_DBUS_FDO_INTERFACE_PROPERTIES);
if (!introspectable_interface || !properties_interface)
{
if (introspectable_interface) e_dbus_interface_unref(introspectable_interface);
properties_interface = NULL;
}
-/**
- * Add a dbus object.
- *
- * @param conn the connection on with the object should listen
- * @param object_path a unique string identifying an object (e.g. org/enlightenment/WindowManager
- * @param data custom data to set on the object (retrievable via
- * e_dbus_object_data_get())
- */
EAPI E_DBus_Object *
e_dbus_object_add(E_DBus_Connection *conn, const char *object_path, void *data)
{
E_DBus_Object *obj;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(conn, NULL);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, NULL);
+
obj = calloc(1, sizeof(E_DBus_Object));
if (!obj) return NULL;
return obj;
}
-/**
- * Free a dbus object
- *
- * @param obj the object to free
- */
EAPI void
e_dbus_object_free(E_DBus_Object *obj)
{
free(obj);
}
-/**
- * @brief Fetch the data pointer for a dbus object
- * @param obj the dbus object
- */
EAPI void *
e_dbus_object_data_get(E_DBus_Object *obj)
{
return obj->data;
}
-/**
- * @brief Get the dbus connection of a dbus object
- * @param obj the dbus object
- */
EAPI E_DBus_Connection *
e_dbus_object_conn_get(E_DBus_Object *obj)
{
return obj->conn;
}
-/**
- * @brief Get the path of a dbus object
- * @param obj the dbus object
- */
EAPI const char *
e_dbus_object_path_get(E_DBus_Object *obj)
{
return obj->path;
}
-/**
- * @brief Get the interfaces of a dbus object
- * @param obj the dbus object
- */
EAPI const Eina_List *
e_dbus_object_interfaces_get(E_DBus_Object *obj)
{
return obj->interfaces;
}
-/**
- * @brief Sets the callback to fetch properties from an object
- * @param obj the object
- * @param func the callback
- */
EAPI void
e_dbus_object_property_get_cb_set(E_DBus_Object *obj, E_DBus_Object_Property_Get_Cb func)
{
obj->cb_property_get = func;
}
-/**
- * @brief Sets the callback to set properties on an object
- * @param obj the object
- * @param func the callback
- */
EAPI void
e_dbus_object_property_set_cb_set(E_DBus_Object *obj, E_DBus_Object_Property_Set_Cb func)
{
EAPI void
e_dbus_object_interface_attach(E_DBus_Object *obj, E_DBus_Interface *iface)
{
+ EINA_SAFETY_ON_NULL_RETURN(obj);
+ EINA_SAFETY_ON_NULL_RETURN(iface);
+
e_dbus_interface_ref(iface);
obj->interfaces = eina_list_append(obj->interfaces, iface);
obj->introspection_dirty = 1;
DBG("e_dbus_object_interface_detach (%s, %s) ", obj->path, iface->name);
found = eina_list_data_find(obj->interfaces, iface);
- if (found == NULL) return;
+ if (!found) return;
obj->interfaces = eina_list_remove(obj->interfaces, iface);
obj->introspection_dirty = 1;
}
-/**
- * Add a method to an object
- *
- * @param iface the E_DBus_Interface to which this method belongs
- * @param member the name of the method
- * @param signature an optional message signature. if provided, then messages
- * with invalid signatures will be automatically rejected
- * (an Error response will be sent) and introspection data
- * will be available.
- *
- * @return 1 if successful, 0 if failed (e.g. no memory)
- */
EAPI int
e_dbus_interface_method_add(E_DBus_Interface *iface, const char *member, const char *signature, const char *reply_signature, E_DBus_Method_Cb func)
{
return 1;
}
-/**
- * Add a signal to an object
- *
- * @param iface the E_DBus_Interface to which this signal belongs
- * @param name the name of the signal
- * @param signature an optional message signature.
- *
- * @return 1 if successful, 0 if failed (e.g. no memory)
- */
EAPI int
e_dbus_interface_signal_add(E_DBus_Interface *iface, const char *name, const char *signature)
{
else
reply = m->func(obj, message);
+ /* user can choose reply later */
+ if (!reply)
+ return DBUS_HANDLER_RESULT_HANDLED;
+
dbus_connection_send(conn, reply, &serial);
dbus_message_unref(reply);
}
static void
-e_dbus_object_unregister(DBusConnection *conn, void *user_data)
+e_dbus_object_unregister(DBusConnection *conn __UNUSED__, void *user_data __UNUSED__)
{
/* free up the object struct? */
}
-Ecore_Strbuf *
+Eina_Strbuf *
e_dbus_object_introspect(E_DBus_Object *obj)
{
- Ecore_Strbuf *buf;
+ Eina_Strbuf *buf;
int level = 0;
E_DBus_Interface *iface;
Eina_List *l;
- buf = ecore_strbuf_new();
+ buf = eina_strbuf_new();
/* Doctype */
- ecore_strbuf_append(buf, "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n");
+ eina_strbuf_append(buf, "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n");
- ecore_strbuf_append(buf, "<node name=\"");
- ecore_strbuf_append(buf, obj->path);
- ecore_strbuf_append(buf, "\">\n");
+ eina_strbuf_append(buf, "<node name=\"");
+ eina_strbuf_append(buf, obj->path);
+ eina_strbuf_append(buf, "\">\n");
level++;
EINA_LIST_FOREACH(obj->interfaces, l, iface)
_introspect_interface_append(buf, iface, level);
- ecore_strbuf_append(buf, "</node>\n");
+ eina_strbuf_append(buf, "</node>\n");
return buf;
}
static void
-_introspect_indent_append(Ecore_Strbuf *buf, int level)
+_introspect_indent_append(Eina_Strbuf *buf, int level)
{
/* XXX optimize this? */
int i = level * 2;
while (i-- > 0)
- ecore_strbuf_append_char(buf, ' ');
+ eina_strbuf_append_char(buf, ' ');
}
static void
-_introspect_interface_append(Ecore_Strbuf *buf, E_DBus_Interface *iface, int level)
+_introspect_interface_append(Eina_Strbuf *buf, E_DBus_Interface *iface, int level)
{
- E_DBus_Method *method;
- E_DBus_Signal *signal;
+ E_DBus_Method *m;
+ E_DBus_Signal *s;
Eina_List *l;
_introspect_indent_append(buf, level);
- ecore_strbuf_append(buf, "<interface name=\"");
- ecore_strbuf_append(buf, iface->name);
- ecore_strbuf_append(buf, "\">\n");
+ eina_strbuf_append(buf, "<interface name=\"");
+ eina_strbuf_append(buf, iface->name);
+ eina_strbuf_append(buf, "\">\n");
level++;
DBG("introspect iface: %s", iface->name);
- EINA_LIST_FOREACH(iface->methods, l, method)
- _introspect_method_append(buf, method, level);
- EINA_LIST_FOREACH(iface->signals, l, signal)
- _introspect_signal_append(buf, signal, level);
+ EINA_LIST_FOREACH(iface->methods, l, m)
+ _introspect_method_append(buf, m, level);
+ EINA_LIST_FOREACH(iface->signals, l, s)
+ _introspect_signal_append(buf, s, level);
level--;
_introspect_indent_append(buf, level);
- ecore_strbuf_append(buf, "</interface>\n");
+ eina_strbuf_append(buf, "</interface>\n");
}
static void
-_introspect_method_append(Ecore_Strbuf *buf, E_DBus_Method *method, int level)
+_introspect_method_append(Eina_Strbuf *buf, E_DBus_Method *method, int level)
{
DBusSignatureIter iter;
char *type;
_introspect_indent_append(buf, level);
DBG("introspect method: %s\n", method->member);
- ecore_strbuf_append(buf, "<method name=\"");
- ecore_strbuf_append(buf, method->member);
- ecore_strbuf_append(buf, "\">\n");
+ eina_strbuf_append(buf, "<method name=\"");
+ eina_strbuf_append(buf, method->member);
+ eina_strbuf_append(buf, "\">\n");
level++;
/* append args */
level--;
_introspect_indent_append(buf, level);
- ecore_strbuf_append(buf, "</method>\n");
+ eina_strbuf_append(buf, "</method>\n");
}
static void
-_introspect_signal_append(Ecore_Strbuf *buf, E_DBus_Signal *signal, int level)
+_introspect_signal_append(Eina_Strbuf *buf, E_DBus_Signal *s, int level)
{
DBusSignatureIter iter;
char *type;
_introspect_indent_append(buf, level);
- DBG("introspect signal: %s", signal->name);
- ecore_strbuf_append(buf, "<signal name=\"");
- ecore_strbuf_append(buf, signal->name);
- ecore_strbuf_append(buf, "\">\n");
+ DBG("introspect signal: %s", s->name);
+ eina_strbuf_append(buf, "<signal name=\"");
+ eina_strbuf_append(buf, s->name);
+ eina_strbuf_append(buf, "\">\n");
level++;
/* append args */
- if (signal->signature &&
- signal->signature[0] &&
- dbus_signature_validate(signal->signature, NULL))
+ if (s->signature &&
+ s->signature[0] &&
+ dbus_signature_validate(s->signature, NULL))
{
- dbus_signature_iter_init(&iter, signal->signature);
+ dbus_signature_iter_init(&iter, s->signature);
while ((type = dbus_signature_iter_get_signature(&iter)))
{
_introspect_arg_append(buf, type, NULL, level);
level--;
_introspect_indent_append(buf, level);
- ecore_strbuf_append(buf, "</signal>\n");
+ eina_strbuf_append(buf, "</signal>\n");
}
static void
-_introspect_arg_append(Ecore_Strbuf *buf, const char *type, const char *direction, int level)
+_introspect_arg_append(Eina_Strbuf *buf, const char *type, const char *direction, int level)
{
_introspect_indent_append(buf, level);
- ecore_strbuf_append(buf, "<arg type=\"");
- ecore_strbuf_append(buf, type);
+ eina_strbuf_append(buf, "<arg type=\"");
+ eina_strbuf_append(buf, type);
if (direction)
{
- ecore_strbuf_append(buf, "\" direction=\"");
- ecore_strbuf_append(buf, direction);
+ eina_strbuf_append(buf, "\" direction=\"");
+ eina_strbuf_append(buf, direction);
}
- ecore_strbuf_append(buf, "\"/>\n");
+ eina_strbuf_append(buf, "\"/>\n");
}
+
+
+DBusConnection *e_dbus_conn_object_get(E_DBus_Connection *conn)
+{
+ if (conn!=NULL)
+ return conn->conn;
+}