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;
}
Example #2
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");
}
Example #3
0
static void
new_connection_cb (DBusServer    * server,
                   DBusConnection* connection,
                   gpointer        user_data)
{
  dbus_int32_t  slot = -1;
  GObject     * object;
  if (!dbus_connection_allocate_data_slot (&slot))
    {
      g_warning ("error allocating data slot for DBusConnection");
      dbus_connection_close (connection);
      return;
    }

  dbus_connection_ref (connection);

  dbus_connection_set_allow_anonymous (connection, TRUE);
  dbus_connection_setup_with_g_main (connection, NULL);

  object = g_object_new (p2p_object_get_type (), NULL);
  dbus_g_connection_register_g_object (dbus_connection_get_g_connection (connection),
                                       "/", object);
  dbus_connection_set_data (connection, slot,
                            object, g_object_unref);
}
Example #4
0
static gint
_get_slot ()
{
    static gint slot = -1;
    if (slot == -1) {
        dbus_connection_allocate_data_slot (&slot);
    }
    return slot;
}
Example #5
0
int
main(int argc, char *argv[])
{
    librdf_world* world;
    GMainLoop *loop;
    DBusServer *server;
    DBusError error;
    char *program=argv[0];

    if (argc < 2) {
        fprintf (stderr, "%s: USAGE [server address]\n", program);
        return 1;
    }

    world=librdf_new_world();
    librdf_world_open(world);

    g_thread_init (NULL);
    dbus_gthread_init ();

    dbus_error_init (&error);
    server = dbus_server_listen (argv[1], &error);
    if (server == NULL)
    {
        fprintf (stderr, "Failed to start server on %s: %s\n",
                 argv[1], error.message);
        dbus_error_free (&error);
        return 1;
    }

    if (!dbus_connection_allocate_data_slot (&handler_slot))
        g_error ("no memory for data slot");

    disconnect_handler =
        dbus_message_handler_new (handle_disconnect, NULL, NULL);
    if (disconnect_handler == NULL)
        g_error ("no memory for handler");

    dbus_server_set_new_connection_function (server,
            new_connection_callback,
            NULL, NULL);

    dbus_server_setup_with_g_main (server, NULL);

    loop = g_main_loop_new (NULL, FALSE);
    g_main_run (loop);

    librdf_free_world(world);

#ifdef LIBRDF_MEMORY_DEBUG
    librdf_memory_report(stderr);
#endif

    /* keep gcc -Wall happy */

    return 0;
}
int main()
{
	DBusConnection* connection;
	DBusError error;
	int cnt;
	int data_slot = -1;
	threadData1 thrData;
	
	pthread_t thread[MAX_THREAD];
	int thrVal[MAX_THREAD]={0};
	void* thrValPtr[MAX_THREAD];
	
	for(cnt=0; cnt<MAX_THREAD; cnt++)
		thrValPtr[cnt] = (void*)&thrVal[cnt];

	 
	dbus_error_init(&error);
	connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
	if(!connection || dbus_error_is_set(&error))
		return handle_error(&error);
	
	pthread_mutex_init(&thrData.mutex, NULL);
	pthread_cond_init(&thrData.cond, NULL);
 	thrData.ret = 0;
 	
 	dbus_connection_allocate_data_slot(&data_slot);
	dbus_connection_set_data(connection, data_slot, &thrData, NULL);
 	
 	dbus_threads_init_default();

 	for(cnt=0; cnt<MAX_THREAD; cnt++)
 		pthread_create(&thread[cnt], NULL, &send_msg1, &data_slot);
	 
	sleep(1);  
	
	pthread_cond_broadcast(&thrData.cond);
	
	for(cnt=0; cnt<MAX_THREAD; cnt++)
		pthread_join(thread[cnt], &thrValPtr[cnt]); 
	 
	if(thrData.ret != MAX_THREAD)
	{ 
		std_log(LOG_FILENAME_LINE, "No. of threads crashed %d", (MAX_THREAD - thrData.ret));
		create_xml(1);
		return 1;
	}
	 
	dbus_connection_unref(connection);
	
	std_log(LOG_FILENAME_LINE, "Test Successful"); 
	create_xml(0);
	return 0;
}
Example #7
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");
}
Example #8
0
dbus_bool_t dbus_a_setup_connection(DBusConnection* connection) {
  struct ConnectionData* c;

  c = CreateConnectionData(connection);

  if (c != NULL) {
    dbus_connection_set_watch_functions(connection,
					AddWatchFunction,
					RemoveWatchFunction,
					WatchToggledFunction,
					c, NULL);
  
    dbus_connection_set_timeout_functions(connection,
					  AddTimeoutFunction,
					  RemoveTimeoutFunction,
					  TimeoutToggledFunction,
					  c, NULL);

    dbus_connection_set_dispatch_status_function(connection, DispatchStatusFunction,
						 c, NULL);

    dbus_connection_set_wakeup_main_function(connection, WakeupMainFunction,
					     c, NULL);

    kprintf("Slot A: %ld\n", Slot);
    if (dbus_connection_allocate_data_slot(&Slot)) {
      kprintf("Slot B: %ld\n", Slot);
      if (dbus_connection_set_data(connection, Slot, c, DeleteConnectionData)) {
	kprintf("Slot C: %ld\n", Slot);
	return TRUE;
      }
    }
  }

  DeleteConnectionData(c);
  return FALSE;
}
Example #9
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;
}
/* 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);
    }
}
Example #11
0
/**
 * dbus_connection_setup_with_g_main:
 * @connection: the connection
 * @context: the #GMainContext or #NULL for default context
 *
 * Sets the watch and timeout functions of a #DBusConnection
 * to integrate the connection with the GLib main loop.
 * Pass in #NULL for the #GMainContext unless you're
 * doing something specialized.
 *
 * If called twice for the same context, does nothing the second
 * time. If called once with context A and once with context B,
 * context B replaces context A as the context monitoring the
 * connection.
 */
void
dbus_connection_setup (DBusConnection *connection,
                       GMainContext   *context)
{
    ConnectionSetup *old_setup;
    ConnectionSetup *cs;

    do {
        /* FIXME we never free the slot, so its refcount just keeps growing,
         * which is kind of broken.
         */
        dbus_connection_allocate_data_slot (&_dbus_gmain_connection_slot);
        if (_dbus_gmain_connection_slot < 0)
            break;

        if (context == NULL)
            context = g_main_context_default ();

        cs = NULL;

        old_setup = dbus_connection_get_data (connection, _dbus_gmain_connection_slot);
        if (old_setup != NULL) {
            if (old_setup->context == context)
                return; /* nothing to do */

            cs = connection_setup_new_from_old (context, old_setup);

            /* Nuke the old setup */
            dbus_connection_set_data (connection, _dbus_gmain_connection_slot, NULL, NULL);
            old_setup = NULL;
        }

        if (cs == NULL)
            cs = connection_setup_new (context, connection);

        if (!dbus_connection_set_data (connection, _dbus_gmain_connection_slot, cs,
                                       (DBusFreeFunction)connection_setup_free))
            break;

        if (!dbus_connection_set_watch_functions (connection,
                                                  add_watch,
                                                  remove_watch,
                                                  watch_toggled,
                                                  cs, NULL))
            break;

        if (!dbus_connection_set_timeout_functions (connection,
                                                    add_timeout,
                                                    remove_timeout,
                                                    timeout_toggled,
                                                    cs, NULL))
            break;

        dbus_connection_set_wakeup_main_function (connection,
                            wakeup_main,
                            cs, NULL);

        return;
    } while (0);
    
    g_error ("Not enough memory to set up DBusConnection for use with GLib");
}