コード例 #1
0
ファイル: conn.c プロジェクト: verterok/dbus-python
/* Return a new reference to a Python Connection or subclass corresponding
 * to the DBusConnection conn. For use in callbacks.
 *
 * Raises AssertionError if the DBusConnection does not have a Connection.
 */
PyObject *
DBusPyConnection_ExistingFromDBusConnection(DBusConnection *conn)
{
    PyObject *self, *ref;

    Py_BEGIN_ALLOW_THREADS
    ref = (PyObject *)dbus_connection_get_data(conn,
                                               _connection_python_slot);
    Py_END_ALLOW_THREADS
    if (ref) {
        DBG("(DBusConnection *)%p has weak reference at %p", conn, ref);
        self = PyWeakref_GetObject(ref);   /* still a borrowed ref */
        if (self && self != Py_None && DBusPyConnection_Check(self)) {
            DBG("(DBusConnection *)%p has weak reference at %p pointing to %p",
                conn, ref, self);
            TRACE(self);
            Py_INCREF(self);
            TRACE(self);
            return self;
        }
    }

    PyErr_SetString(PyExc_AssertionError,
                    "D-Bus connection does not have a Connection "
                    "instance associated with it");
    return NULL;
}
コード例 #2
0
ファイル: dbus-glib.c プロジェクト: psunkari/spicebird
/**
 * dbus_connection_get_g_connection:
 * @connection:  a #DBusConnection
 *
 * Get the #DBusGConnection corresponding to this #DBusConnection.  This only
 * makes sense if the #DBusConnection was originally a #DBusGConnection that was
 * registered with the GLib main loop.  The return value does not have its
 * refcount incremented.
 *
 * Returns: #DBusGConnection 
 */
DBusGConnection*
dbus_connection_get_g_connection (DBusConnection *connection)
{
  g_return_val_if_fail (connection, NULL);
  g_return_val_if_fail (dbus_connection_get_data (connection, _dbus_gmain_connection_slot), NULL);
  
  return DBUS_G_CONNECTION_FROM_CONNECTION (connection);
}
コード例 #3
0
ファイル: ibusconnection.c プロジェクト: XueWei/ibus
DBusHandlerResult
_message_function (DBusConnection *dbus_connection,
                   DBusMessage    *message,
                   VTableCallData *data)
{
    gboolean retval;
    IBusConnection *connection;

    connection = IBUS_CONNECTION (dbus_connection_get_data (dbus_connection, _get_slot()));
    retval = data->message_func (connection, message, data->user_data);

    return retval ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
コード例 #4
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);
}
コード例 #5
0
ファイル: dbus-bus.c プロジェクト: 325116067/semc-qsd8x50
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
static void* send_msg1(void* data)
{
	DBusConnection* connection;
	DBusError error;
	static int cnt = 1;
	dbus_int32_t no = 5;
	DBusPendingCall* pending;
	DBusMessage* msg1;
	DBusMessage* msg;
	int data_slot = *(int*)data;
	FILE* fp;
	threadData1* thrData;

	dbus_error_init(&error);
	connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
	
	thrData = (threadData1*)dbus_connection_get_data(connection, data_slot);
	if(!thrData)
		return NULL;
	
	pthread_mutex_lock(&thrData->mutex);
	
	msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "simple");
	
	dbus_message_append_args(msg, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID);
	 
	pthread_cond_wait(&thrData->cond,  &thrData->mutex);
	 
	// send message and get a handle for a reply
	   if (!dbus_connection_send_with_reply (connection, msg, &pending, -1)) { // -1 is default timeout
	   thrData->ret = 2;
//	   		exit(1);
	   }   
	   if (NULL == pending) {
	   thrData->ret = 2;
//	      exit(1);
	   } 
	   dbus_connection_flush(connection);
	   
		// free message
	   dbus_message_unref(msg);   
	  
	   // block until we recieve a reply
	   dbus_pending_call_block(pending);
	
	   // get the reply message
	   msg1 = dbus_pending_call_steal_reply(pending);
	   if (NULL == msg1) {
	   thrData->ret = 2;
	
	   }  
	   // free the pending message handle
	   dbus_pending_call_unref(pending);
		 
	  
	   dbus_message_get_args(msg1, &error, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID);
	   
	   fp = fopen("C:\\new.txt", "a+");
	   fprintf(fp, "%d\n", no);
	   fclose(fp);
	    
	   if(no == 9090)
		   {
		   thrData->ret++;
		   }
	   
	 	 
	   // free reply and close connection
	   dbus_message_unref(msg1); 
	   dbus_connection_unref(connection);
	   pthread_mutex_unlock(&thrData->mutex); 
	   return NULL;
}
コード例 #7
0
ファイル: ibusinternal.c プロジェクト: definite/ibus
/**
 * 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");
}
コード例 #8
0
ファイル: conn.c プロジェクト: verterok/dbus-python
/* Return a new reference to a Python Connection or subclass (given by cls)
 * corresponding to the DBusConnection conn, which must have been newly
 * created. For use by the Connection and Bus constructors.
 *
 * Raises AssertionError if the DBusConnection already has a Connection.
 */
static PyObject *
DBusPyConnection_NewConsumingDBusConnection(PyTypeObject *cls,
                                            DBusConnection *conn,
                                            PyObject *mainloop)
{
    Connection *self = NULL;
    PyObject *ref;
    dbus_bool_t ok;

    DBG("%s(cls=%p, conn=%p, mainloop=%p)", __func__, cls, conn, mainloop);
    DBUS_PY_RAISE_VIA_NULL_IF_FAIL(conn);

    Py_BEGIN_ALLOW_THREADS
    ref = (PyObject *)dbus_connection_get_data(conn,
                                               _connection_python_slot);
    Py_END_ALLOW_THREADS
    if (ref) {
        self = (Connection *)PyWeakref_GetObject(ref);
        ref = NULL;
        if (self && (PyObject *)self != Py_None) {
            self = NULL;
            PyErr_SetString(PyExc_AssertionError,
                            "Newly created D-Bus connection already has a "
                            "Connection instance associated with it");
            DBG("%s() fail - assertion failed, DBusPyConn has a DBusConn already", __func__);
            DBG_WHEREAMI;
            return NULL;
        }
    }
    ref = NULL;

    /* Change mainloop from a borrowed reference to an owned reference */
    if (!mainloop || mainloop == Py_None) {
        mainloop = dbus_py_get_default_main_loop();
        if (!mainloop)
            goto err;
    }
    else {
        Py_INCREF(mainloop);
    }

    DBG("Constructing Connection from DBusConnection at %p", conn);

    self = (Connection *)(cls->tp_alloc(cls, 0));
    if (!self) goto err;
    TRACE(self);

    DBG_WHEREAMI;

    self->has_mainloop = (mainloop != Py_None);
    self->conn = NULL;
    self->filters = PyList_New(0);
    if (!self->filters) goto err;
    self->object_paths = PyDict_New();
    if (!self->object_paths) goto err;

    ref = PyWeakref_NewRef((PyObject *)self, NULL);
    if (!ref) goto err;
    DBG("Created weak ref %p to (Connection *)%p for (DBusConnection *)%p",
        ref, self, conn);

    Py_BEGIN_ALLOW_THREADS
    ok = dbus_connection_set_data(conn, _connection_python_slot,
                                  (void *)ref,
                                  (DBusFreeFunction)dbus_py_take_gil_and_xdecref);
    Py_END_ALLOW_THREADS

    if (ok) {
        DBG("Attached weak ref %p ((Connection *)%p) to (DBusConnection *)%p",
            ref, self, conn);
        ref = NULL;     /* don't DECREF it - the DBusConnection owns it now */
    }
    else {
        DBG("Failed to attached weak ref %p ((Connection *)%p) to "
            "(DBusConnection *)%p - will dispose of it", ref, self, conn);
        PyErr_NoMemory();
        goto err;
    }

    DBUS_PY_RAISE_VIA_GOTO_IF_FAIL(conn, err);
    self->conn = conn;
    /* the DBusPyConnection will close it now */
    conn = NULL;

    if (self->has_mainloop
        && !dbus_py_set_up_connection((PyObject *)self, mainloop)) {
        goto err;
    }

    Py_CLEAR(mainloop);

    DBG("%s() -> %p", __func__, self);
    TRACE(self);
    return (PyObject *)self;

err:
    DBG("Failed to construct Connection from DBusConnection at %p", conn);
    Py_CLEAR(mainloop);
    Py_CLEAR(self);
    Py_CLEAR(ref);
    if (conn) {
        Py_BEGIN_ALLOW_THREADS
        dbus_connection_close(conn);
        dbus_connection_unref(conn);
        Py_END_ALLOW_THREADS
    }
    DBG("%s() fail", __func__);
    DBG_WHEREAMI;
    return NULL;
}