dbus tools: generalized dbus includes 38/159538/3
authorAdrian Szyndela <adrian.s@samsung.com>
Thu, 9 Nov 2017 11:57:44 +0000 (12:57 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Thu, 9 Nov 2017 12:11:14 +0000 (13:11 +0100)
Definitions of structures used in dbus tools were included inline
in the tools. This commit creates separate include files with
the structures extracted.

Change-Id: Ib7ac526f854477d3242650ce2942f5250e7687bd

src/cc/hostcompat/dbus/gio.h [new file with mode: 0644]
src/cc/hostcompat/dbus/libdbus.h [new file with mode: 0644]
tools/dbus-connection-message-size.c
tools/dbus-latency.c
tools/dbus-message-type.c

diff --git a/src/cc/hostcompat/dbus/gio.h b/src/cc/hostcompat/dbus/gio.h
new file mode 100644 (file)
index 0000000..e2db5c8
--- /dev/null
@@ -0,0 +1,88 @@
+#ifndef HOSTCOMPAT_GIO_H
+#define HOSTCOMPAT_GIO_H
+
+typedef enum {
+       G_DBUS_MESSAGE_TYPE_INVALID,
+       G_DBUS_MESSAGE_TYPE_METHOD_CALL,
+       G_DBUS_MESSAGE_TYPE_METHOD_RETURN,
+       G_DBUS_MESSAGE_TYPE_ERROR,
+       G_DBUS_MESSAGE_TYPE_SIGNAL
+} GDBusMessageType;
+
+typedef enum {
+       G_DBUS_MESSAGE_FLAGS_NONE = 0,
+       G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED = (1<<0),
+       G_DBUS_MESSAGE_FLAGS_NO_AUTO_START = (1<<1)
+} GDBusMessageFlags;
+
+typedef enum
+{
+       G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN    = 'B',
+       G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN = 'l'
+} GDBusMessageByteOrder;
+
+typedef enum
+{
+       G_DBUS_SEND_MESSAGE_FLAGS_NONE = 0,
+       G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL = (1<<0)
+} GDBusSendMessageFlags;
+
+struct GTypeInstance {
+       ptr_t g_class;  // GTypeClass *
+};
+
+struct GObject {
+       struct GTypeInstance g_type_instance;
+
+       volatile uint_t ref_count;
+       ptr_t qdata;    // void *
+};
+
+struct GHashTable {
+       int_t size;
+       int_t mod;
+       uint_t mask;
+       int_t nnodes;
+       int_t noccupied;
+
+       ptr_t keys; // void *keys;
+       ptr_t hashes; // void *hashes;
+       ptr_t values; // void *values;
+};
+
+struct GVariant {
+       ptr_t type_info; // void *type_info;
+       ulong_t size;
+
+       union {
+               struct {
+                       ptr_t bytes; // void *bytes;
+                       ptr_t gconstpointer; // const char *gconstpointer;
+               } serialised;
+
+               struct {
+                       ptr_t children; // struct GVariant **children;
+                       ulong_t n_children;
+               } tree;
+       } content;
+
+       int_t state;
+       int_t ref_count;
+};
+
+struct GDBusMessage {
+       struct GObject parent_instance;
+       uint_t type; // GDBusMessageType type;
+       uint_t flags; // GDBusMessageFlags flags;
+       int_t locked; // gboolean
+       uint_t byte_order; // GDBusMessageByteOrder byte_order;
+       unsigned char major_protocol_version;
+       uint32_t serial;
+       ptr_t headers; // GHashTable *headers;
+       ptr_t body; // GVariant *body;
+// this part is under #ifdef G_OS_UNIX
+       ptr_t fd_list; // GUnixFDList *fd_list;
+// #endif G_OS_UNIX
+};
+
+#endif // HOSTCOMPAT_GIO_H
diff --git a/src/cc/hostcompat/dbus/libdbus.h b/src/cc/hostcompat/dbus/libdbus.h
new file mode 100644 (file)
index 0000000..ee35302
--- /dev/null
@@ -0,0 +1,150 @@
+#ifndef HOSTCOMPAT_LIBDBUS_H
+#define HOSTCOMPAT_LIBDBUS_H
+
+struct DBusString {
+       ptr_t str;
+       int_t len;
+       int_t allocated;
+       uint_t constant : 1;
+       uint_t locked : 1;
+       uint_t invalid : 1;
+       uint_t align_offset : 3;
+};
+
+struct DBusHeaderFields {
+       int_t value_pos;
+};
+
+struct DBusHeader {
+       struct DBusString data;
+
+       struct DBusHeaderFields fields[10];
+
+       uint32_t padding:3;
+       uint32_t byte_order:8;
+       unsigned char protocol_version;
+};
+
+struct DBusDataSlot {
+       ptr_t data; // void *data;
+       ptr_t dummy1; // void *dummy1;
+};
+
+struct DBusDataSlotList {
+       ptr_t slots; //DBusDataSlot *slots;
+       int_t n_slots;
+};
+
+struct DBusMessage {
+       int32_t refcount;
+       struct DBusHeader header;
+       struct DBusString body;
+
+       // we don't access anything below
+
+       uint_t locked : 1;
+       uint_t in_cache : 1;    // this is under #ifdef but it does not hurt us
+
+       ptr_t list;             // void *
+       long_t size_counter_delta;
+       int_t timeout_ms;
+
+       uint32_t changed_stamp : 21;
+       struct DBusDataSlotList slot_list;
+
+// this is under #ifndef DBUS_DISABLE_CHECKS
+// this is important if anyone wants to access fields below
+       int_t generation;
+// #endif DBUS_DISABLE_CHECKS
+
+// this part is under #ifdef HAVE_UNIX_FD_PASSING
+       ptr_t unix_fds; // int *
+
+       uint_t n_unix_fds;
+       uint_t n_unix_fds_allocated;
+
+       long_t unix_fd_counter_delta;
+// #endif HAVE_UNIX_FD_PASSING
+
+       ptr_t signature; // struct DBusString *signature;
+       ptr_t unique_sender; // struct DBusString *unique_sender;
+       ulong_t gvariant_body_last_offset;
+       ulong_t gvariant_body_last_pos;
+};
+
+struct DBusLink {
+       ptr_t prev; // struct DBusLink *prev;
+       ptr_t next; // struct DBusLink *next;
+       ptr_t data; // void *data;
+};
+
+struct DBusList {
+       ptr_t prev; // struct DBusList *prev;
+       ptr_t next; // struct DbusList *next;
+       ptr_t data; // void *data;
+};
+
+struct DBusConnection {
+       int32_t refcount;
+
+       ptr_t mutex; // DBusRMutex *mutex;
+
+       ptr_t dispatch_mutex; // DBusCMutex *dispatch_mutex;
+       ptr_t dispatch_cond; // DBusCondVar *dispatch_cond;
+       ptr_t io_path_mutex; // DBusCMutex *io_path_mutex;
+       ptr_t io_path_cond; // DBusCondVar *io_path_cond;
+
+       ptr_t outgoing_messages; // struct DBusList *outgoing_messages;
+       ptr_t incoming_messages; // struct DBusList *incoming_messages;
+       ptr_t expired_messages; // struct DBusList *expired_messages;
+
+       ptr_t message_borrowed; // struct DBusMessage *message_borrowed;
+
+       int_t n_outgoing;
+       int_t n_incoming;
+
+       ptr_t outgoing_counter; // DBusCounter *outgoing_counter;
+
+       ptr_t transport; // DBusTransport *transport;
+       ptr_t watches; // DBusWatchList *watches;
+       ptr_t timeouts; // DBusTimeoutList *timeouts;
+
+       ptr_t filter_list; // DBusList *filter_list;
+
+       ptr_t slot_mutex; // DBusRMutex *slot_mutex;
+       struct DBusDataSlotList slot_list;
+
+       ptr_t pending_replies; // DBusHashTable *pending_replies;
+
+       uint32_t client_serial;
+       ptr_t disconnect_message_link; // DBusList *disconnect_message_link;
+
+       ptr_t wakeup_main_function; // DBusWakeupMainFunction wakeup_main_function;
+       ptr_t wakeup_main_data; // void *wakeup_main_data;
+       ptr_t wants; // DBusFreeFunction free_wakeup_main_data;
+
+       ptr_t dispatch_status_function; // DBusDispatchStatusFunction dispatch_status_function;
+       ptr_t dispatch_status_data; // void *dispatch_status_data;
+       ptr_t free_dispatch_status_data; // DBusFreeFunction free_dispatch_status_data;
+
+       uint_t last_dispatch_status; // DBusDispatchStatus last_dispatch_status;
+
+       ptr_t objects; // DBusObjectTree *objects;
+
+       ptr_t server_guid; // char *server_guid;
+
+       uint32_t dispatch_acquired;     // dbus_bool_t
+       uint32_t io_path_acquired;  // dbus_bool_t
+
+       uint_t dispatch_disabled : 1;
+       uint_t shareable : 1;
+       uint_t exit_on_disconnect : 1;
+       uint_t route_peer_messages : 1;
+       uint_t disconnected_message_arrived : 1;
+       uint_t disconnected_message_processed : 1;
+
+       // There are actually some more fields below (with #ifdefs), however we do not use it.
+       // Add them if you need them.
+};
+
+#endif // LIBDBUS_H
index dd47d54ade47917d464025706e8a17d4100bf5dc..78ff46f73946bb19ef0d63cd351becc8c2a480aa 100644 (file)
@@ -1,58 +1,6 @@
 #include <hostcompat/uapi/linux/ptrace.h>
 #include <hostcompat/linux/sched.h>
-
-struct DBusString {
-       ptr_t str;
-       int_t len;
-       uint_t allocated;
-       uint_t constant : 1;
-       uint_t locked : 1;
-       uint_t invalid : 1;
-       uint_t align_offset : 3;
-};
-
-struct DBusHeaderFields {
-       int_t value_pos;
-};
-
-struct DBusHeader {
-       struct DBusString data;
-
-       struct DBusHeaderFields fields[9];
-
-       u32 padding;
-       u32 byte_order;
-       unsigned char protocol_version;
-};
-
-struct DBusMessage {
-       int_t refcount;
-       struct DBusHeader header;
-       struct DBusString body;
-
-       uint_t locked : 1;
-
-       ptr_t list;             // void *
-       long_t size_counter_delta;
-       int_t timeout_ms;
-
-       u32 changed_stamp : 21;
-       ptr_t slot_list;        // void *
-
-       int_t generation;
-
-       ptr_t unix_fds; // int *
-
-       uint_t n_unix_fds;
-       uint_t n_unix_fds_allocated;
-
-       long_t unix_fd_counter_delta;
-
-       ptr_t signature; // struct DBusString *signature;
-       ptr_t unique_sender; // struct DBusString *unique_sender;
-       ulong_t gvariant_body_last_offset;
-       ulong_t gvariant_body_last_pos;
-};
+#include <hostcompat/dbus/libdbus.h>
 
 struct data_t {
        u32 pid;
index 976206b1cbc826b42936c62af63e1c10738bdeb6..91b4cb47ab5e5a5c448a56d9e3edc09a07861408 100644 (file)
@@ -1,150 +1,7 @@
 #include <hostcompat/linux/sched.h>
 #include <hostcompat/uapi/linux/ptrace.h>
-
-typedef enum {
-  G_DBUS_MESSAGE_TYPE_INVALID,
-  G_DBUS_MESSAGE_TYPE_METHOD_CALL,
-  G_DBUS_MESSAGE_TYPE_METHOD_RETURN,
-  G_DBUS_MESSAGE_TYPE_ERROR,
-  G_DBUS_MESSAGE_TYPE_SIGNAL
-} GDBusMessageType;
-
-typedef enum {
-  G_DBUS_MESSAGE_FLAGS_NONE = 0,
-  G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED = (1<<0),
-  G_DBUS_MESSAGE_FLAGS_NO_AUTO_START = (1<<1)
-} GDBusMessageFlags;
-
-typedef enum
-{
-  G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN    = 'B',
-  G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN = 'l'
-} GDBusMessageByteOrder;
-
-typedef enum
-{
-       G_DBUS_SEND_MESSAGE_FLAGS_NONE = 0,
-       G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL = (1<<0)
-} GDBusSendMessageFlags;
-
-struct GTypeInstance {
-       ptr_t g_class;  // void *
-};
-
-struct GObject {
-       struct GTypeInstance g_type_instance;
-
-       volatile uint_t ref_count;
-       ptr_t qdata;    // void *
-};
-
-struct GDBusMessage {
-       struct GObject parent_instance;
-       GDBusMessageType type;
-       GDBusMessageFlags flags;
-       bool locked;
-       uint_t byte_order; // GDBusMessageByteOrder byte_order;
-       unsigned char major_protocol_version;
-       unsigned int serial;
-       ptr_t headers; // void *headers;
-       ptr_t body; // void *body;
-};
-
-struct DBusString {
-       ptr_t str;
-       int_t len;
-       uint_t allocated;
-       unsigned int constant : 1;
-       unsigned int locked : 1;
-       unsigned int invalid : 1;
-       unsigned int align_offset : 3;
-};
-
-struct DBusLink {
-       ptr_t prev; // struct DBusLink *prev;
-       ptr_t next; // struct DBusLink *next;
-       ptr_t data; // void *data;
-};
-
-struct DBusHeaderFields {
-       int_t value_pos;
-};
-
-struct DBusHeader {
-       struct DBusString data;
-
-       struct DBusHeaderFields fields[9];
-
-       u32 padding;
-       u32 byte_order;
-       unsigned char protocol_version;
-};
-
-struct DBusDataSlot {
-       ptr_t data; // void *data;
-       ptr_t dummy1; // void *dummy1;
-};
-
-struct DBusDataSlotList {
-       ptr_t slots; // struct DBusDataSlot *slots;
-       int_t n_slots;
-};
-
-struct DBusList {
-       ptr_t prev; // struct DBusList *prev;
-       ptr_t next; // struct DbusList *next;
-       ptr_t data; // void *data;
-};
-
-struct DBusMessage {
-       int_t refcount;
-       struct DBusHeader header;
-       struct DBusString body;
-
-       uint_t locked : 1;
-       uint_t in_cache : 1;
-
-       ptr_t counters; // void *counters;
-       long_t size_counter_delta;
-       int_t timeout_ms;
-
-       u32 changed_stamp : 21;
-       ptr_t slot_list; // struct DBusDataSlotList *slot_list;
-
-       int_t generation;
-
-       ptr_t unix_fds; // int *unix_fds;
-
-       uint_t n_unix_fds;
-       uint_t n_unix_fds_allocated;
-
-       long_t unix_fd_counter_delta;
-
-       ptr_t signature; // struct DBusString *signature;
-       ptr_t unique_sender; // struct DBusString *unique_sender;
-       long_t gvariant_body_last_offset;
-       long_t gvariant_body_last_pos;
-};
-
-struct DBusConnection {
-       int_t refcount;
-
-       ptr_t mutex; // void *mutex;
-
-       ptr_t dispatch_mutex; // void *dispatch_mutex;
-       ptr_t dispatch_cond; // void *dispatch_cond;
-       ptr_t io_path_mutex; // void *io_path_mutex;
-       ptr_t io_path_cond; // void *io_path_cond;
-
-       ptr_t outgoing_messages; // struct DBusList *outgoing_messages;
-       ptr_t incoming_messages; // struct DBusList *incoming_messages;
-       ptr_t expired_messages; // struct DBusList *expired_messages;
-
-       ptr_t message_borrowed; // struct DBusMessage *message_borrowed;
-
-       int_t n_outgoing;
-       int_t n_incoming;
-};
+#include <hostcompat/dbus/libdbus.h>
+#include <hostcompat/dbus/gio.h>
 
 struct data_t {
        int pid;
index 6246d637ec7215b292b68f17b30c8f748bec3143..ddf1a8d2288fd7622b09e22c9f6c0b9a81e27f7e 100644 (file)
 #include <hostcompat/linux/sched.h>
 #include <hostcompat/uapi/linux/ptrace.h>
+#include <hostcompat/dbus/gio.h>
+#include <hostcompat/dbus/libdbus.h>
 
 #define DBUS_TYPE_OFFSET 1
 
-typedef enum {
-  G_DBUS_MESSAGE_TYPE_INVALID,
-  G_DBUS_MESSAGE_TYPE_METHOD_CALL,
-  G_DBUS_MESSAGE_TYPE_METHOD_RETURN,
-  G_DBUS_MESSAGE_TYPE_ERROR,
-  G_DBUS_MESSAGE_TYPE_SIGNAL
-} GDBusMessageType;
-
-typedef enum {
-  G_DBUS_MESSAGE_FLAGS_NONE = 0,
-  G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED = (1<<0),
-  G_DBUS_MESSAGE_FLAGS_NO_AUTO_START = (1<<1)
-} GDBusMessageFlags;
-
-typedef enum
-{
-  G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN    = 'B',
-  G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN = 'l'
-} GDBusMessageByteOrder;
-
-struct GTypeInstance {
-       ptr_t g_class; // void *g_class;
-};
-
-struct GObject {
-       struct GTypeInstance g_type_instance;
-
-       volatile uint_t ref_count;
-       ptr_t qdata; // void *qdata;
-};
-
-struct GHashTable {
-       int_t size;
-       int_t mod;
-       uint_t mask;
-       int_t nnodes;
-       int_t noccupied;
-
-       ptr_t keys; // void *keys;
-       ptr_t hashes; // void *hashes;
-       ptr_t values; // void *values;
-};
-
-struct GVariant {
-       ptr_t type_info; // void *type_info;
-       ulong_t size;
-
-       union {
-               struct {
-                       ptr_t bytes; // void *bytes;
-                       ptr_t gconstpointer; // const char *gconstpointer;
-               } serialised;
-
-               struct {
-                       ptr_t children; // struct GVariant **children;
-                       ulong_t n_children;
-               } tree;
-       } content;
-
-       int_t state;
-       int_t ref_count;
-};
-
-struct GDBusMessage {
-       struct GObject parent_instance;
-       uint_t type; // GDBusMessageType type;
-       uint_t flags; // GDBusMessageFlags flags;
-       bool locked;
-       uint_t byte_order; // GDBusMessageByteOrder byte_order;
-       unsigned char major_protocol_version;
-       uint_t serial;
-       ptr_t headers; // struct GHashTable *headers;
-       ptr_t body; // struct GVariant *body;
-};
-
-struct DBusString {
-       ptr_t str; // void *str;
-       int_t len;
-       uint_t allocated;
-       unsigned int constant : 1;
-       unsigned int locked : 1;
-       unsigned int invalid : 1;
-       unsigned int align_offset : 3;
-};
-
-struct DBusHeaderFields {
-       int_t value_pos;
-};
-
-struct DBusHeader {
-       struct DBusString data;
-
-       struct DBusHeaderFields fields[9];
-
-       u32 padding;
-       u32 byte_order;
-       unsigned char protocol_version;
-};
-
-struct DBusMessage {
-       int_t refcount;
-       struct DBusHeader header;
-       struct DBusString body;
-
-       uint_t locked : 1;
-
-       ptr_t list; // void * list;
-       long_t size_counter_delta;
-       int_t timeout_ms;
-
-       u32 changed_stamp : 21;
-       ptr_t slot_list; // void *slot_list;
-
-       int_t generation;
-
-       ptr_t unix_fds; // int *unix_fds;
-
-       uint_t n_unix_fds;
-       uint_t n_unix_fds_allocated;
-
-       long_t unix_fd_counter_delta;
-
-       ptr_t signature; // struct DBusString *signature;
-       ptr_t unique_sender; // struct DBusString *unique_sender;
-       uint_t gvariant_body_last_offset;
-       uint_t gvariant_body_last_pos;
-};
-
 struct data_t {
        u32 pid;
        char comm[TASK_COMM_LEN];
@@ -151,7 +25,7 @@ int dbus_get_message_type(struct pt_regs *ctx, void *conn, struct DBusMessage *m
 
 int message_type(struct pt_regs *ctx, void *conn, struct DBusMessage *message) {
        const char *c = message->header.data.str;
-       c++;
+       c += DBUS_TYPE_OFFSET;
        msg_type.increment(*c);
        return 0;
 }