46 #include <dbus/dbus.h> 47 #include <dbus/dbus-glib-lowlevel.h> 70 : service(service), path(path), interface(interface),
110 bool constantList =
true) {
111 switch (argument.
type()) {
135 signature += DBUS_STRUCT_BEGIN_CHAR_AS_STRING;
136 foreach(
QVariant listItem, variantList) {
139 signature += DBUS_STRUCT_END_CHAR_AS_STRING;
149 qDebug() <<
"Unsupported variant type: " << argument.
type();
157 DBusMessageIter *dbus_iter) {
159 DBusMessageIter array_iter;
161 dbus_bool_t bool_data;
162 dbus_int32_t int32_data;
163 dbus_uint32_t uint32_data;
164 dbus_int64_t int64_data;
165 dbus_uint64_t uint64_data;
169 switch (argument.
type()) {
172 bool_data = argument.
toBool();
180 DBUS_TYPE_BYTE_AS_STRING, &array_iter);
195 int32_data = argument.
toInt();
202 str_data = data.
data();
212 for (idx = 0; idx < str_list.
size(); idx++) {
214 str_data = data.
data();
223 uint32_data = argument.
toUInt();
244 DBusMessageIter array_iter;
262 foreach(
QVariant listItem, variantList) {
273 foreach(
QVariant listItem, variantList) {
283 qDebug() <<
"Unsupported variant type: " << argument.
type();
291 dbus_bool_t bool_data;
292 dbus_int32_t int32_data;
293 dbus_uint32_t uint32_data;
294 dbus_int64_t int64_data;
295 dbus_uint64_t uint64_data;
302 case DBUS_TYPE_BOOLEAN:
309 case DBUS_TYPE_ARRAY:
313 DBusMessageIter array_iter;
317 if (elem_type == DBUS_TYPE_BYTE) {
321 byte_array.
append(char_data);
325 }
else if (elem_type == DBUS_TYPE_STRING) {
329 str_list.
append(str_data);
352 case DBUS_TYPE_INT32:
359 case DBUS_TYPE_UINT32:
366 case DBUS_TYPE_STRING:
374 case DBUS_TYPE_INT64:
381 case DBUS_TYPE_UINT64:
388 case DBUS_TYPE_STRUCT:
391 DBusMessageIter struct_iter;
403 qDebug() <<
"Unsupported DBUS type: " << argtype;
410 DBusMessage *message,
418 interface = dbus_message_get_interface(message);
422 DBusMessageIter dbus_iter;
433 return DBUS_HANDLER_RESULT_HANDLED;
436 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
472 qDebug() <<
"Unable to get DBUS connection!";
477 dbus_connection_setup_with_g_main(
d_ptr->
connection, g_main_context_get_thread_default());
502 DBusMessageIter dbus_iter;
506 if (arg1.isValid()) arglist << arg1;
507 if (arg2.isValid()) arglist << arg2;
508 if (arg3.isValid()) arglist << arg3;
509 if (arg4.isValid()) arglist << arg4;
510 if (arg5.isValid()) arglist << arg5;
511 if (arg6.isValid()) arglist << arg6;
512 if (arg7.isValid()) arglist << arg7;
513 if (arg8.isValid()) arglist << arg8;
534 DBusMessageIter dbus_iter;
537 arg1, arg2, arg3, arg4, arg5,
580 DBusMessageIter dbus_iter;
606 arg1, arg2, arg3, arg4, arg5,
608 DBusPendingCall *
call = NULL;
The QVariant class acts like a union for the most common Qt data types.
DBusDispatcher is a class that can send DBUS method call messages and receive unicast signals from DB...
DBusDispatcherPrivate * d_ptr
bool callAsynchronous(const QString &method, const QVariant &arg1=QVariant(), const QVariant &arg2=QVariant(), const QVariant &arg3=QVariant(), const QVariant &arg4=QVariant(), const QVariant &arg5=QVariant(), const QVariant &arg6=QVariant(), const QVariant &arg7=QVariant(), const QVariant &arg8=QVariant())
static mach_timebase_info_data_t info
dbus_bool_t dbus_pending_call_set_notify(DBusPendingCall *pending, DBusPendingCallNotifyFunction function, void *user_data, DBusFreeFunction free_user_data)
char * data()
Returns a pointer to the data stored in the byte array.
dbus_bool_t dbus_message_iter_close_container(DBusMessageIter *iter, DBusMessageIter *sub)
DBusDispatcher * dispatcher
void dbus_connection_set_exit_on_disconnect(DBusConnection *connection, dbus_bool_t exit_on_disconnect)
void dbus_message_unref(DBusMessage *message)
QByteArray & append(char c)
Appends the character ch to this byte array.
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
The QByteArray class provides an array of bytes.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
void dbus_pending_call_unref(DBusPendingCall *pending)
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
dbus_bool_t dbus_connection_send_with_reply(DBusConnection *connection, DBusMessage *message, DBusPendingCall **pending_return, int timeout_milliseconds)
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
int dbus_message_get_type(DBusMessage *message)
void synchronousDispatch(int timeout_ms)
The QString class provides a Unicode character string.
static QList< QVariant > toList(char **buf, int count, T *=0)
The QObject class is the base class of all Qt objects.
static QString variantToSignature(const QVariant &argument, bool constantList=true)
void signalReceived(const QString &interface, const QString &signal, const QList< QVariant > &args)
void emitSignalReceived(const QString &interface, const QString &signal, const QList< QVariant > &args)
The QChar class provides a 16-bit Unicode character.
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
DBusDispatcherPrivate * priv
Q_CORE_EXPORT void qDebug(const char *,...)
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
const char * dbus_message_get_error_name(DBusMessage *message)
void append(const T &t)
Inserts value at the end of the list.
DBusMessage * dbus_message_new_method_call(const char *bus_name, const char *path, const char *interface, const char *method)
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
static DBusHandlerResult signalHandler(DBusConnection *connection, DBusMessage *message, void *object_ref)
void dbus_message_iter_init_append(DBusMessage *message, DBusMessageIter *iter)
T takeFirst()
Removes the first item in the list and returns it.
DBusDispatcherPrivate(const QString &service, const QString &path, const QString &interface, const QString &signalPath)
void dbus_pending_call_cancel(DBusPendingCall *pending)
const T & at(int i) const
Returns the item at index position i in the list.
QList< QVariant > call(const QString &method, const QVariant &arg1=QVariant(), const QVariant &arg2=QVariant(), const QVariant &arg3=QVariant(), const QVariant &arg4=QVariant(), const QVariant &arg5=QVariant(), const QVariant &arg6=QVariant(), const QVariant &arg7=QVariant(), const QVariant &arg8=QVariant())
struct DBusConnection * connection
The QStringList class provides a list of strings.
DBusDispatcher(const QString &service, const QString &path, const QString &interface, QObject *parent=0)
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
qulonglong toULongLong(bool *ok=0) const
Returns the variant as as an unsigned long long int if the variant has type() ULongLong ...
int dbus_message_iter_get_element_type(DBusMessageIter *iter)
dbus_bool_t dbus_message_iter_next(DBusMessageIter *iter)
static const char * data(const QByteArray &arr)
Type
This enum type defines the types of variable that a QVariant can contain.
#define FALSE
Synonym for false.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
DBusMessage * dbus_connection_send_with_reply_and_block(DBusConnection *connection, DBusMessage *message, int timeout_milliseconds, DBusError *error)
dbus_bool_t dbus_message_iter_init(DBusMessage *message, DBusMessageIter *iter)
void dbus_message_iter_recurse(DBusMessageIter *iter, DBusMessageIter *sub)
char toAscii() const
Returns the character value of the QChar obtained using the current codec used to read C strings...
dbus_bool_t dbus_message_iter_append_basic(DBusMessageIter *iter, int type, const void *value)
void dbus_connection_unref(DBusConnection *connection)
Type type() const
Returns the storage type of the value stored in the variant.
QObject * parent() const
Returns a pointer to the parent object.
uint toUInt(bool *ok=0) const
Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray ...
int size() const
Returns the number of items in the list.
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
const char * dbus_message_get_member(DBusMessage *message)
DBusMessage * dbus_pending_call_steal_reply(DBusPendingCall *pending)
static DBusMessage * prepareDBusCall(const QString &service, const QString &path, const QString &interface, const QString &method, const QVariant &arg1=QVariant(), const QVariant &arg2=QVariant(), const QVariant &arg3=QVariant(), const QVariant &arg4=QVariant(), const QVariant &arg5=QVariant(), const QVariant &arg6=QVariant(), const QVariant &arg7=QVariant(), const QVariant &arg8=QVariant())
int size() const
Returns the number of bytes in this byte array.
struct DBusObjectPathVTable signal_vtable
int dbus_message_iter_get_arg_type(DBusMessageIter *iter)
DBusConnection * dbus_bus_get_private(DBusBusType type, DBusError *error)
static QVariant getVariantFromDBusMessage(DBusMessageIter *iter)
void dbus_connection_close(DBusConnection *connection)
static void pendingCallFunction(DBusPendingCall *pending, void *memory)
QChar toChar() const
Returns the variant as a QChar if the variant has type() Char , Int , or UInt ; otherwise returns an ...
QList< DBusPendingCall * > pending_calls
static void freePendingCallInfo(void *memory)
void emitCallReply(const QString &method, const QList< QVariant > &args, const QString &error="")
static bool constantVariantList(const QVariantList &variantList)
void callReply(const QString &method, const QList< QVariant > &args, const QString &error)
static bool appendVariantToDBusMessage(const QVariant &argument, DBusMessageIter *dbus_iter)
dbus_bool_t dbus_message_iter_open_container(DBusMessageIter *iter, int type, const char *contained_signature, DBusMessageIter *sub)
The QList class is a template class that provides lists.
void dbus_message_iter_get_basic(DBusMessageIter *iter, void *value)
dbus_bool_t dbus_message_iter_append_fixed_array(DBusMessageIter *iter, int element_type, const void *value, int n_elements)