示例#1
0
static void
setup (Fixture *f,
    gconstpointer data)
{
  if (!dbus_threads_init_default ())
    g_error ("OOM");

  f->loop = _dbus_loop_new ();
  g_assert (f->loop != NULL);

  dbus_error_init (&f->e);

  f->server = dbus_server_listen ("tcp:host=127.0.0.1", &f->e);
  assert_no_error (&f->e);
  g_assert (f->server != NULL);

  if (!dbus_connection_allocate_data_slot (&connection_slot))
    g_error ("OOM");

  if (!dbus_server_allocate_data_slot (&server_slot))
    g_error ("OOM");

  if (!dbus_message_allocate_data_slot (&message_slot))
    g_error ("OOM");

  if (!dbus_pending_call_allocate_data_slot (&pending_call_slot))
    g_error ("OOM");
}
示例#2
0
文件: dbusimpl.c 项目: iwaim/ibus
void
bus_dbus_impl_dispatch_message_by_rule (BusDBusImpl     *dbus,
                                        IBusMessage     *message,
                                        BusConnection   *skip_connection)
{
    g_assert (BUS_IS_DBUS_IMPL (dbus));
    g_assert (message != NULL);
    g_assert (BUS_IS_CONNECTION (skip_connection) || skip_connection == NULL);

    GList *recipients = NULL;
    GList *link = NULL;

    static gint32 data_slot = -1;

    if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) {
        return;
    }

    if (data_slot == -1) {
        dbus_message_allocate_data_slot (&data_slot);
    }

    /* If this message has been dispatched by rule, it will be ignored. */
    if (dbus_message_get_data (message, data_slot) != NULL)
        return;

    dbus_message_set_data (message, data_slot, (gpointer) TRUE, NULL);

#if 0
    if (g_strcmp0 (ibus_message_get_member (message), "ValueChanged") == 0) {
        g_debug ("Dispatch ValueChanged");
    }
#endif

    for (link = dbus->rules; link != NULL; link = link->next) {
        GList *list = bus_match_rule_get_recipients (BUS_MATCH_RULE (link->data),
                                                     message);
        recipients = g_list_concat (recipients, list);
    }

    for (link = recipients; link != NULL; link = link->next) {
        BusConnection *connection = BUS_CONNECTION (link->data);
        if (connection != skip_connection) {
            ibus_connection_send (IBUS_CONNECTION (connection), message);
        }
        g_object_unref (connection);
    }
    g_list_free (recipients);
}
示例#3
0
static void
setup (Fixture *f,
    gconstpointer data)
{
  if (!dbus_threads_init_default ())
    g_error ("OOM");

  f->n_threads = N_THREADS;
  f->n_refs = N_REFS;

  // wine sets WINESERVERSOCKET for its child processes automatically
  if (g_getenv ("WINESERVERSOCKET") != NULL)
    {
      /* Our reference-counting is really slow under Wine (it involves
       * IPC to wineserver). Do fewer iterations: enough to demonstrate
       * that it works, rather than a performance test.
       */
      f->n_threads = 10;
      f->n_refs = 10;
    }

  f->loop = _dbus_loop_new ();
  g_assert (f->loop != NULL);

  dbus_error_init (&f->e);

  f->server = dbus_server_listen ("tcp:host=127.0.0.1", &f->e);
  assert_no_error (&f->e);
  g_assert (f->server != NULL);

  if (!dbus_connection_allocate_data_slot (&connection_slot))
    g_error ("OOM");

  if (!dbus_server_allocate_data_slot (&server_slot))
    g_error ("OOM");

  if (!dbus_message_allocate_data_slot (&message_slot))
    g_error ("OOM");

  if (!dbus_pending_call_allocate_data_slot (&pending_call_slot))
    g_error ("OOM");
}
/* This test outputs TAP syntax: http://testanything.org/ */
int
main (int argc, char *argv[])
{
  dbus_int32_t slot_connection = -1;
  dbus_int32_t slot_message = -1;
  dbus_int32_t slot_pending = -1;
  DBusError error;
  DBusConnection *conn;
  DBusMessage *method;
  DBusPendingCall *pending;
  DBusMessage *reply;

  printf ("# Testing pending call error\n");

  dbus_connection_allocate_data_slot (&slot_connection);
  dbus_message_allocate_data_slot (&slot_message);
  dbus_pending_call_allocate_data_slot (&slot_pending);

  dbus_error_init (&error);
  conn = dbus_bus_get_private (DBUS_BUS_SESSION, &error);
  dbus_connection_set_data (conn, slot_connection, (void*)"connection", free_data);
  ++count;
  dbus_connection_set_exit_on_disconnect (conn, FALSE);

  method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService",
                                         "/org/freedesktop/TestSuite",
                                         "org.freedesktop.TestSuite",
                                         "Exit");
  dbus_message_set_data (method, slot_message, (void*)"method", free_data);
  ++count;

  dbus_connection_send_with_reply (conn, method, &pending, -1);
  dbus_message_unref (method);
  dbus_pending_call_set_data (pending, slot_pending, (void*)"pending", free_data);
  ++count;

  dbus_connection_close (conn);

  dbus_pending_call_block (pending);
  reply = dbus_pending_call_steal_reply (pending);
  dbus_pending_call_unref (pending);
  if (reply == NULL)
    {
      printf ("Bail out! Reply is NULL ***\n");
      exit (1);
    }
  dbus_message_set_data (reply, slot_message, (void*)"reply", free_data);
  ++count;
  if (dbus_message_get_type (reply) != DBUS_MESSAGE_TYPE_ERROR)
    {
      printf ("Bail out! Reply is not error ***\n");
      exit (1);
    }
  dbus_message_unref (reply);

  dbus_connection_unref (conn);

  dbus_connection_free_data_slot (&slot_connection);
  dbus_message_free_data_slot (&slot_message);
  dbus_pending_call_free_data_slot (&slot_pending);

  if (count != 0)
    {
      printf ("not ok # Not all refs were unrefed ***\n");
      exit (1);
    }
  else
    {
      printf ("ok\n# Testing completed\n1..1\n");
      exit (0);
    }
}
int main()
{

	DBusMessage* msg;
	dbus_int32_t data_slot = -1;
	TestData data;
	TestData* data1;
	DBusFreeFunction free_data;
	//_LIT(KOOM, "Out of Memory");
	//_LIT(KFreeFail, "Free Function is not called");
	//_LIT(KDataFail, "Fail to retrieve data");	
	
	msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
	if(!dbus_message_allocate_data_slot(&data_slot))
	{
		std_log(LOG_FILENAME_LINE,"Out of Memory");
		create_xml(1);
		return 1;
	}
	
	data.num = 20;
	data.str = (char*)malloc(data.num);
	data_free_flag = FALSE;
	strcpy(data.str, "CheckDBus");
	free_data = Free_Test_Data;
	
	if(!dbus_message_set_data(msg, data_slot, (void*)&data, free_data))
	{
		std_log(LOG_FILENAME_LINE,"Out of Memory");
		create_xml(1);
		return 1;
	}
	
	data1 = (TestData*)dbus_message_get_data(msg, data_slot);
	if(!data1)
	{
		std_log(LOG_FILENAME_LINE,"Fail to retrieve data");
		create_xml(1);
		return 1;
	} 
	
	std_log(LOG_FILENAME_LINE,"Data :: \n\tInteger value(20) = %d\n\tString value(CheckDBus) = %s", data1->num, data1->str);
	
	data.num = 30;
	data.str = (char*)malloc(data.num);
	data_free_flag = FALSE;
	strcpy(data.str, "CheckDBusFree");
	free_data = Free_Test_Data;
	
	if(!dbus_message_set_data(msg, data_slot, (void*)&data, free_data))
	{
		std_log(LOG_FILENAME_LINE,"Out of Memory");
		create_xml(1);
		return 1;
	}
	
	if(!data_free_flag)
	{
		std_log(LOG_FILENAME_LINE,"Free Function is not called");
		create_xml(1);
		return 1;
	}
			
	dbus_message_free_data_slot(&data_slot);
	
	std_log(LOG_FILENAME_LINE,"Test Successful");
	create_xml(0);
	return 0;
	
}