|
Membre actif
Zaour Étudiant - Réseaux & Télécommunications Inscription : août 2009 Messages : 235 Détails du profil  Informations personnelles : Nom : Zaour Informations professionnelles :
Activité : Étudiant - Réseaux & Télécommunications Informations forums :
Inscription : août 2009 Messages : 235 Points : 163 Points : 163
|
D-BUS - - La methode n'éxiste pas sur l'interface
Bonjour,
Je sais pas trop si je suis sur le bon forum, mais vu qu'il s'agit quand même un peu de GLib, j'ai préféré poster ici.
Mon problème est le suivant, j'essaie faire un petit test avec D-BUS, qui consiste à implémenter un objet qui servira de proxy. L'interface de ce proxy comporte un seule méthode "EchoString", qui prend en entrée une chaîne de caractère et renvoie une copie de cette chaîne.
Le problème, c'est que quand j'appelle la méthode sur mon proxy, D-BUS me dit qu'aucune méthode de ce nom avec cette signature n’existe pas pour l'interface en question, alors qu'elle est bien dans mon fichier xml 
(Plus de détails sur l'erreur ci-dessous)
Voici le code source du proxy:
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| #include <glib.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus.h>
#include "test.h"
int
main (void)
{
GMainLoop *loop;
TestObject *t_object;
g_type_init ();
t_object = g_object_new (TEST_TYPE_OBJECT, NULL);
loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);
g_object_unref (t_object);
return 0;
} |
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| /* test.h */
#ifndef __TEST_H__
#define __TEST_H__
#include <glib-object.h>
G_BEGIN_DECLS
#define TEST_TYPE_OBJECT (test_object_get_type())
#define TEST_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), TEST_TYPE_OBJECT))
#define TEST_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), TEST_TYPE_OBJECT, TestObject))
#define TEST_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), TEST_TYPE_OBJECT))
#define TEST_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TEST_TYPE_OBJECT, TestObjectClass))
typedef struct _TestObjectClass TestObjectClass;
typedef struct _TestObject TestObject;
typedef struct _TestObjectPrivate TestObjectPrivate;
struct _TestObject
{
GObject parent_object;
TestObjectPrivate *priv;
};
struct _TestObjectClass
{
GObjectClass parent_class;
};
GType test_object_get_type (void) G_GNUC_CONST;
G_END_DECLS
#endif |
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| /* test.c */
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include <stdlib.h>
#include "test.h"
struct _TestObjectPrivate
{
DBusGConnection *connection;
DBusGProxy *bus_proxy;
};
G_DEFINE_TYPE (TestObject, test_object, G_TYPE_OBJECT)
gboolean test_echo_string (TestObject *t_obj, gchar *str_in, gchar **str_out_ptr, GError **error);
static void test_object_dispose (GObject *object);
void
test_object_init (TestObject *t_obj)
{
TestObjectPrivate *t_obj_priv;
GError *error;
guint32 x;
t_obj_priv = t_obj->priv = G_TYPE_INSTANCE_GET_PRIVATE (t_obj, TEST_TYPE_OBJECT, TestObjectPrivate);
error = NULL;
t_obj_priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
if (t_obj_priv->connection == NULL) {
g_printerr("Failed to open connection to bus: %s\n",
error->message);
exit (1);
}
t_obj_priv->bus_proxy = dbus_g_proxy_new_for_name(t_obj_priv->connection, "org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus");
g_debug("About to request D-Bus name...\n");
if (!dbus_g_proxy_call(t_obj_priv->bus_proxy, "RequestName", &error,
G_TYPE_STRING, "home.joker.Test",
G_TYPE_UINT,
DBUS_NAME_FLAG_ALLOW_REPLACEMENT
| DBUS_NAME_FLAG_REPLACE_EXISTING
| DBUS_NAME_FLAG_DO_NOT_QUEUE,
G_TYPE_INVALID,
G_TYPE_UINT, &x,
G_TYPE_INVALID))
{
g_printerr("Couldn't acquire name: %s\n", error->message);
exit(1);
}
else if (x != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
g_printerr("Couldn't acquire name: RequestName returned %u\n", x);
exit(1);
}
g_debug("D-Bus name acquired\n");
dbus_g_connection_register_g_object(t_obj_priv->connection, "/home/joker/test", G_OBJECT(t_obj));
}
#include "test-object-glue.h"
void
test_object_class_init (TestObjectClass *t_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (t_class);
object_class->dispose = test_object_dispose;
g_type_class_add_private (object_class, sizeof (TestObjectPrivate));
dbus_g_object_type_install_info (TEST_TYPE_OBJECT, &dbus_glib_test_object_info);
}
gboolean
test_echo_string (TestObject *t_obj, gchar *str_in, gchar **str_out_ptr, GError **error)
{
*str_out_ptr = g_strdup (str_in);
if (NULL == *str_out_ptr)
{
g_set_error (error, g_quark_from_static_string ("echo"),
0xdeadbeef,
"Unable to allocate memory !");
return FALSE;
}
return TRUE;
}
static void
test_object_dispose (GObject *object)
{
TestObject *t_object = TEST_OBJECT (object);
if (NULL != t_object->priv->bus_proxy)
{
g_object_unref (t_object->priv->bus_proxy);
t_object->priv->bus_proxy = NULL;
}
G_OBJECT_CLASS (test_object_parent_class)->dispose (object);
} |
Code :
1 2 3 4 5 6 7 8 9 10 11 12
| <?xml version="1.0" encoding="UTF-8"?>
<node name="/home/joker/test">
<interface name="home.joker.test">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="test"/>
<method name="EchoString">
<arg type="s" name="str_in" direction="in" />
<arg type="s" name="str_out_ptr" direction="out" />
</method>
<!-- Add more methods/signals if you want -->
</interface>
</node> |
Citation:
[zaour@joker dbus-activ]$ dbus-binding-tool --mode=glib-server --prefix=test test-object-infos.xml > test-object-glue.h
[zaour@joker dbus-activ]$ gcc *.c $(pkg-config --libs --cflags dbus-glib-1) -W -Wall -std=c99 -o server
test.c: In function ‘test_echo_string’:
test.c:79:31: attention : unused parameter ‘t_obj’ [-Wunused-parameter]
[zaour@joker dbus-activ]$ ./server
** (process:6418): DEBUG: About to request D-Bus name...
** (process:6418): DEBUG: D-Bus name acquired
|
Et voici le code source, où j'appelle la méthode:
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #include <glib.h>
#include <dbus/dbus-glib.h>
int
main (int argc, char **argv)
{
DBusGConnection *connection;
GError *error;
DBusGProxy *proxy;
char send[] = "Hello, World !\n";
char *result;
g_type_init ();
error = NULL;
connection = dbus_g_bus_get (DBUS_BUS_SESSION,
&error);
if (connection == NULL)
{
g_printerr ("Failed to open connection to bus: %s\n",
error->message);
g_error_free (error);
exit (1);
}
/* Création du proxy */
proxy = dbus_g_proxy_new_for_name (connection,
"home.joker.Test",
"/home/joker/Test",
"home.joker.test");
/* Appel d'EchoString, attente d'une réponse */
error = NULL;
if (!dbus_g_proxy_call (proxy, "EchoString", &error,
G_TYPE_STRING, send, G_TYPE_INVALID,
G_TYPE_STRING, &result, G_TYPE_INVALID))
{
if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
g_printerr ("Caught remote method exception %s: %s",
dbus_g_error_get_name (error),
error->message);
else
g_printerr ("Error: %s\n", error->message);
g_error_free (error);
exit (1);
}
/* Affichage du résultat */
g_print ("String on the message bus:\n");
g_print (result);
g_free (result);
g_object_unref (proxy);
return 0;
} |
Citation:
[zaour@joker essai]$ ./a.out
Error: Method "EchoString" with signature "s" on interface "home.joker.test" doesn't exist
[zaour@joker essai]$
|
Alors si quelqu'un a une idée de la provenance du problème, ça serait génial 
Merci
|