summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn (J5) Palmieri <johnp@redhat.com>2005-07-15 15:21:43 +0000
committerJohn (J5) Palmieri <johnp@redhat.com>2005-07-15 15:21:43 +0000
commita7595655fb892b4ecab852aeb971cf53bdff09cc (patch)
tree06dbb47a00b1fddec1bf8cc9b1c16dd019e2e376
parent16dbb17287c183c6f4e749a33fcffe6c03cb5766 (diff)
downloaddbus-a7595655fb892b4ecab852aeb971cf53bdff09cc.tar.gz
* bus/dispatch.c, test/test-service.c: Add testcase
for sending messages to oneself (TODO item). * python/service.py (class Object): Swap ordering of bus_name and object_path parameters to better support inheritance. * doc/dbus-tutorial.xml: change Python docs to reflect change in parameter ordering and fix the inheritance section. * doc/TODO: remove sending message to oneself TODO item
-rw-r--r--ChangeLog13
-rw-r--r--bus/dispatch.c78
-rw-r--r--doc/TODO4
-rw-r--r--doc/dbus-tutorial.xml20
-rw-r--r--python/service.py4
-rw-r--r--test/test-service.c177
6 files changed, 276 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 90fd7dd6..53e41630 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-07-14 John (J5) Palmieri <johnp@redhat.com>
+
+ * bus/dispatch.c, test/test-service.c: Add testcase
+ for sending messages to oneself (TODO item).
+
+ * python/service.py (class Object): Swap ordering of bus_name
+ and object_path parameters to better support inheritance.
+
+ * doc/dbus-tutorial.xml: change Python docs to reflect change
+ in parameter ordering and fix the inheritance section.
+
+ * doc/TODO: remove sending message to oneself TODO item
+
2005-07-15 Ross Burton <ross@openedhand.com>
* glib/dbus-gproxy.c:
diff --git a/bus/dispatch.c b/bus/dispatch.c
index 02f6c690..35c34283 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -2810,6 +2810,79 @@ check_segfault_service_auto_start (BusContext *context,
}
#define TEST_ECHO_MESSAGE "Test echo message"
+#define TEST_RUN_HELLO_FROM_SELF_MESSAGE "Test sending message to self"
+
+/* returns TRUE if the correct thing happens,
+ * but the correct thing may include OOM errors.
+ */
+static dbus_bool_t
+check_existent_hello_from_self (BusContext *context,
+ DBusConnection *connection)
+{
+ DBusMessage *message;
+ dbus_uint32_t serial;
+ dbus_bool_t retval;
+ const char *base_service;
+ const char *text;
+
+ message = dbus_message_new_method_call (EXISTENT_SERVICE_NAME,
+ "/org/freedesktop/TestSuite",
+ "org.freedesktop.TestSuite",
+ "RunHelloFromSelf");
+
+ if (message == NULL)
+ return TRUE;
+
+ text = TEST_RUN_HELLO_FROM_SELF_MESSAGE;
+ if (!dbus_message_append_args (message,
+ DBUS_TYPE_STRING, &text,
+ DBUS_TYPE_INVALID))
+ {
+ dbus_message_unref (message);
+ return TRUE;
+ }
+
+ if (!dbus_connection_send (connection, message, &serial))
+ {
+ dbus_message_unref (message);
+ return TRUE;
+ }
+
+ dbus_message_unref (message);
+ message = NULL;
+
+ bus_test_run_everything (context);
+
+ /* Note: if this test is run in OOM mode, it will block when the bus
+ * doesn't send a reply due to OOM.
+ */
+ block_connection_until_message_from_bus (context, connection, "reply from running hello from self");
+
+ message = pop_message_waiting_for_memory (connection);
+ if (message == NULL)
+ {
+ _dbus_warn ("Failed to pop message! Should have been reply from RunHelloFromSelf message\n");
+ goto out;
+ }
+
+ if (dbus_message_get_reply_serial (message) != serial)
+ {
+ _dbus_warn ("Wrong reply serial\n");
+ goto out;
+ }
+
+ dbus_message_unref (message);
+ message = NULL;
+
+ retval = TRUE;
+
+ out:
+ if (message)
+ dbus_message_unref (message);
+
+ return retval;
+}
+
/* returns TRUE if the correct thing happens,
* but the correct thing may include OOM errors.
@@ -2985,7 +3058,10 @@ check_existent_service_auto_start (BusContext *context,
dbus_message_unref (message);
message = NULL;
-
+
+ if (!check_existent_hello_from_self (context, connection))
+ goto out;
+
if (!check_send_exit_to_service (context, connection,
EXISTENT_SERVICE_NAME,
base_service))
diff --git a/doc/TODO b/doc/TODO
index 03e156dc..4218c9aa 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -12,10 +12,6 @@ Important for 1.0
dbus-marshal-recursive.c (this is mostly done now, just needs some
cleanup)
- - need to define bus behavior if you send a message to
- yourself; is it an error, or allowed? If allowed,
- we need to have a test for it in the test suite.
-
- just before 1.0, try a HAVE_INT64=0 build and be sure it runs
- dbus-pending-call.c has some API and thread safety issues to review
diff --git a/doc/dbus-tutorial.xml b/doc/dbus-tutorial.xml
index 924575f3..d066c0a9 100644
--- a/doc/dbus-tutorial.xml
+++ b/doc/dbus-tutorial.xml
@@ -7,8 +7,8 @@
<article id="index">
<articleinfo>
<title>D-BUS Tutorial</title>
- <releaseinfo>Version 0.4</releaseinfo>
- <date>14 July 2005</date>
+ <releaseinfo>Version 0.4.1</releaseinfo>
+ <date>15 July 2005</date>
<authorgroup>
<author>
<firstname>Havoc</firstname>
@@ -1479,8 +1479,8 @@ if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib
class HelloWorldObject(dbus.service.Object):
- def __init__(self, bus_name):
- dbus.service.Object.__init__(self, '/org/freedesktop/HelloWorldObject', bus_name)
+ def __init__(self, bus_name, object_path='/org/freedesktop/HelloWorldObject'):
+ dbus.service.Object.__init__(self, bus_name, object_path)
session_bus = dbus.SessionBus()
bus_name = dbus.service.BusName('org.freedesktop.HelloWorld', bus=session_bus)
@@ -1506,8 +1506,8 @@ if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib
class HelloWorldObject(dbus.service.Object):
- def __init__(self, bus_name):
- dbus.service.Object.__init__(self, '/org/freedesktop/HelloWorldObject', bus_name)
+ def __init__(self, bus_name, object_path='/org/freedesktop/HelloWorldObject'):
+ dbus.service.Object.__init__(self, bus_name, object_path)
@dbus.service.method('org.freedesktop.HelloWorldIFace')
def hello(self):
@@ -1578,8 +1578,8 @@ if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib
class HelloWorldObject(dbus.service.Object):
- def __init__(self, bus_name):
- dbus.service.Object.__init__(self, '/org/freedesktop/HelloWorldObject', bus_name)
+ def __init__(self, bus_name, object_path='/org/freedesktop/HelloWorldObject'):
+ dbus.service.Object.__init__(self, bus_name, object_path)
@dbus.service.method('org.freedesktop.HelloWorldIFace')
def hello(self):
@@ -1614,8 +1614,8 @@ gtk.main()
Let's inherit from the HelloWorldObject example above and overide the hello method to say goodbye.
<programlisting>
class HelloWorldGoodbyeObject(HelloWorldObject):
- def __init__(self, bus_name):
- HelloWorldObject.__init__(self, '/org/freedesktop/HelloWorldGoodbyeObject', bus_name)
+ def __init__(self, bus_name, object_path='/org/freedesktop/HelloWorldGoodbyeObject'):
+ HelloWorldObject.__init__(self, bus_name, object_path)
@dbus.service.method('org.freedesktop.HelloWorldGoodbyeIFace')
def hello(self):
diff --git a/python/service.py b/python/service.py
index b7504dca..18a2c81b 100644
--- a/python/service.py
+++ b/python/service.py
@@ -151,9 +151,9 @@ class Object:
"""
__metaclass__ = ObjectType
- def __init__(self, object_path, name):
+ def __init__(self, bus_name, object_path):
self._object_path = object_path
- self._name = name
+ self._name = bus_name
self._bus = name.get_bus()
self._connection = self._bus.get_connection()
diff --git a/test/test-service.c b/test/test-service.c
index 703595e4..77b8b3ca 100644
--- a/test/test-service.c
+++ b/test/test-service.c
@@ -3,6 +3,7 @@
static DBusLoop *loop;
static dbus_bool_t already_quit = FALSE;
+static dbus_bool_t hello_from_self_reply_recived = FALSE;
static void
quit (void)
@@ -21,6 +22,155 @@ die (const char *message)
exit (1);
}
+static void
+check_hello_from_self_reply (DBusPendingCall *pcall,
+ void *user_data)
+{
+ DBusMessage *reply;
+ DBusMessage *echo_message, *echo_reply;
+ DBusError error;
+ DBusConnection *connection;
+
+ int type;
+
+ dbus_error_init (&error);
+
+ connection = dbus_bus_get (DBUS_BUS_STARTER, &error);
+ if (connection == NULL)
+ {
+ fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n",
+ error.message);
+ dbus_error_free (&error);
+ die("no memory");
+ }
+
+
+ echo_message = (DBusMessage *)user_data;
+
+ reply = dbus_pending_call_steal_reply (pcall);
+
+ type = dbus_message_get_type (reply);
+
+ if (type == DBUS_MESSAGE_TYPE_METHOD_RETURN)
+ {
+ const char *s;
+ printf ("Reply from HelloFromSelf recived\n");
+
+ if (!dbus_message_get_args (echo_message,
+ &error,
+ DBUS_TYPE_STRING, &s,
+ DBUS_TYPE_INVALID))
+ {
+ echo_reply = dbus_message_new_error (echo_message,
+ error.name,
+ error.message);
+
+ if (echo_reply == NULL)
+ die ("No memory\n");
+
+ }
+ else
+ {
+ echo_reply = dbus_message_new_method_return (echo_message);
+ if (echo_reply == NULL)
+ die ("No memory\n");
+
+ if (!dbus_message_append_args (echo_reply,
+ DBUS_TYPE_STRING, &s,
+ DBUS_TYPE_INVALID))
+ die ("No memory");
+ }
+
+ if (!dbus_connection_send (connection, echo_reply, NULL))
+ die ("No memory\n");
+
+ dbus_message_unref (echo_reply);
+ }
+ else if (type == DBUS_MESSAGE_TYPE_ERROR)
+ {
+ dbus_set_error_from_message (&error, reply);
+ printf ("Error type in reply: %s\n", error.message);
+
+ if (strcmp (error.name, DBUS_ERROR_NO_MEMORY) != 0)
+ {
+ echo_reply = dbus_message_new_error (echo_reply,
+ error.name,
+ error.message);
+
+ if (echo_reply == NULL)
+ die ("No memory\n");
+
+ if (!dbus_connection_send (connection, echo_reply, NULL))
+ die ("No memory\n");
+
+ dbus_message_unref (echo_reply);
+ }
+ dbus_error_free (&error);
+ }
+ else
+ _dbus_assert_not_reached ("Unexpected message recived\n");
+
+ hello_from_self_reply_recived = TRUE;
+
+ dbus_message_unref (reply);
+ dbus_message_unref (echo_message);
+ dbus_pending_call_unref (pcall);
+}
+
+static DBusHandlerResult
+handle_run_hello_from_self (DBusConnection *connection,
+ DBusMessage *message)
+{
+ DBusError error;
+ DBusMessage *reply, *self_message;
+ DBusPendingCall *pcall;
+ char *s;
+
+ _dbus_verbose ("sending reply to Echo method\n");
+
+ dbus_error_init (&error);
+
+ if (!dbus_message_get_args (message,
+ &error,
+ DBUS_TYPE_STRING, &s,
+ DBUS_TYPE_INVALID))
+ {
+ reply = dbus_message_new_error (message,
+ error.name,
+ error.message);
+
+ if (reply == NULL)
+ die ("No memory\n");
+
+ if (!dbus_connection_send (connection, reply, NULL))
+ die ("No memory\n");
+
+ dbus_message_unref (reply);
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ printf ("Sending HelloFromSelf\n");
+
+ _dbus_verbose ("*** Sending message to self\n");
+ self_message = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
+ "/org/freedesktop/TestSuite",
+ "org.freedesktop.TestSuite",
+ "HelloFromSelf");
+
+ if (self_message == NULL)
+ die ("No memory");
+
+ if (!dbus_connection_send_with_reply (connection, self_message, &pcall, -1))
+ die("No memory");
+
+ dbus_message_ref (message);
+ if (!dbus_pending_call_set_notify (pcall, check_hello_from_self_reply, (void *)message, NULL))
+ die("No memory");
+
+ printf ("Sent HelloFromSelf\n");
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
static DBusHandlerResult
handle_echo (DBusConnection *connection,
DBusMessage *message)
@@ -123,6 +273,27 @@ path_message_func (DBusConnection *connection,
return DBUS_HANDLER_RESULT_HANDLED;
}
+
+ else if (dbus_message_is_method_call (message,
+ "org.freedesktop.TestSuite",
+ "RunHelloFromSelf"))
+ {
+ return handle_run_hello_from_self (connection, message);
+ }
+ else if (dbus_message_is_method_call (message,
+ "org.freedesktop.TestSuite",
+ "HelloFromSelf"))
+ {
+ DBusMessage *reply;
+ printf ("Recived the HelloFromSelf message\n");
+
+ reply = dbus_message_new_method_return (message);
+ if (reply == NULL)
+ die ("No memory");
+
+ if (!dbus_connection_send (connection, reply, NULL))
+ die ("No memory");
+ }
else
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
@@ -160,9 +331,9 @@ int
main (int argc,
char **argv)
{
- DBusConnection *connection;
DBusError error;
int result;
+ DBusConnection *connection;
dbus_error_init (&error);
connection = dbus_bus_get (DBUS_BUS_STARTER, &error);
@@ -209,10 +380,10 @@ main (int argc,
dbus_error_free (&error);
exit (1);
}
-
+
_dbus_verbose ("*** Test service entering main loop\n");
_dbus_loop_run (loop);
-
+
test_connection_shutdown (loop, connection);
dbus_connection_remove_filter (connection, filter_func, NULL);