예제 #1
0
static void
bus_data_free (void *data)
{
  BusData *bd = data;
  
  if (bd->is_well_known)
    {
      int i;
      _DBUS_LOCK (bus);
      /* We may be stored in more than one slot */
      /* This should now be impossible - these slots are supposed to
       * be cleared on disconnect, so should not need to be cleared on
       * finalize
       */
      i = 0;
      while (i < N_BUS_TYPES)
        {
          if (bus_connections[i] == bd->connection)
            bus_connections[i] = NULL;
          
          ++i;
        }
      _DBUS_UNLOCK (bus);
    }
  
  dbus_free (bd->unique_name);
  dbus_free (bd);

  dbus_connection_free_data_slot (&bus_data_slot);
}
예제 #2
0
static void
bus_data_free (void *data)
{
  BusData *bd = data;
  
  if (bd->is_well_known)
    {
      int i;
      _DBUS_LOCK (bus);
      /* We may be stored in more than one slot */
      i = 0;
      while (i < N_BUS_TYPES)
        {
          if (bus_connections[i] == bd->connection)
            bus_connections[i] = NULL;
          
          ++i;
        }
      _DBUS_UNLOCK (bus);
    }
  
  dbus_free (bd->unique_name);
  dbus_free (bd);

  dbus_connection_free_data_slot (&bus_data_slot);
}
int main()
{
   	DBusError error;
	DBusConnection* connection;
	dbus_int32_t data_slot = -1;
	
	dbus_error_init(&error);
	
	connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
	if(!CheckConnection(connection, &error))
	{
		create_xml(1);
		return 1;
	}
	
	if(!dbus_connection_allocate_data_slot(&data_slot))
	{
		std_log(LOG_FILENAME_LINE, "Out of Memory");
		create_xml(1);
		return 1;
	}
	
	dbus_connection_free_data_slot(&data_slot);

	dbus_connection_close(connection);
	dbus_connection_unref(connection);
	dbus_shutdown();
	
	std_log(LOG_FILENAME_LINE, "Test Successful");
	create_xml(0);
	return 0;
}
예제 #4
0
static void
teardown (Fixture *f,
    gconstpointer data)
{
  if (f->server_connection != NULL)
    {
      dbus_connection_close (f->server_connection);
      dbus_connection_unref (f->server_connection);
    }

  if (f->connection != NULL)
    {
      dbus_connection_close (f->connection);
      dbus_connection_unref (f->connection);
    }

  if (f->server != NULL)
    {
      dbus_server_disconnect (f->server);
      dbus_server_unref (f->server);
    }

  dbus_connection_free_data_slot (&connection_slot);
  dbus_server_free_data_slot (&server_slot);
  dbus_message_free_data_slot (&message_slot);
  dbus_pending_call_free_data_slot (&pending_call_slot);

  _dbus_loop_unref (f->loop);
  dbus_error_free (&f->e);
}
예제 #5
0
static BusData*
ensure_bus_data (DBusConnection *connection)
{
  BusData *bd;

  if (!dbus_connection_allocate_data_slot (&bus_data_slot))
    return NULL;

  bd = dbus_connection_get_data (connection, bus_data_slot);
  if (bd == NULL)
    {      
      bd = dbus_new0 (BusData, 1);
      if (bd == NULL)
        {
          dbus_connection_free_data_slot (&bus_data_slot);
          return NULL;
        }

      bd->connection = connection;
      
      if (!dbus_connection_set_data (connection, bus_data_slot, bd,
                                     bus_data_free))
        {
          dbus_free (bd);
          dbus_connection_free_data_slot (&bus_data_slot);
          return NULL;
        }

      /* Data slot refcount now held by the BusData */
    }
  else
    {
      dbus_connection_free_data_slot (&bus_data_slot);
    }

  return bd;
}
예제 #6
0
파일: dbus-amiga.c 프로젝트: michalsc/AROS
void dbus_a_cleanup_connection(DBusConnection* connection) {
  struct ConnectionData* c;

  kprintf("CleanupAmigaConnection\n");

  kprintf("Slot X: %ld\n", Slot);
  c = dbus_connection_get_data(connection, Slot);

  if (c != NULL) {
    dbus_connection_set_data(connection, Slot, NULL, NULL);
    dbus_connection_free_data_slot(&Slot);
    kprintf("Slot Y: %ld\n", Slot);
  }

  dbus_connection_set_dispatch_status_function(connection, NULL, NULL, NULL);
  dbus_connection_set_wakeup_main_function(connection, NULL, NULL, NULL);
  dbus_connection_set_watch_functions(connection, NULL, NULL, NULL, NULL, NULL);
  dbus_connection_set_timeout_functions(connection, NULL, NULL, NULL, NULL, NULL);

  kprintf("Slot X: %ld\n", Slot);
}
/* 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);
    }
}