Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15496724
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: LINUX

2009-06-24 10:37:54

浅析如何从内存中读取解析dbus系统connection相关信息
《浅析应用程序dbus_bus_get函数在lib库中的实际执行流程》

《一个dbus精简IPC实例源码》
    int *DBusConnection_server_guid;
    int *DBusConnection_transport;
    int *basep;

    conn = dbus_bus_get(DBUS_BUS_SESSION, &err); // 获取与dbus-session后台daemon连接

    basep = (int*)conn;
    DBusConnection_server_guid = &basep[30]; // 读取server_guid在内存中的偏移地址

    DBusConnection_transport = (int*)(basep[12]); // transport在内存中的偏移地址

// dbus_bus_set_unique_name(conn, "luther.gliethttp");

    fprintf(stderr, "\tserver_guid=\t%s\n\taddress=\t%s\n\texpected_guid=\t%s\n\tunique_name=\t%s\n",
                    (char*)(DBusConnection_server_guid[0]),
                    (char*)(DBusConnection_transport[8]),
                    (char*)(DBusConnection_transport[9]),
                    dbus_bus_get_unique_name(conn));
执行效果如下:
luther@gliethttp:/vobs/dbus$ env|grep DBUS
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-VRg0ZEh0PA,guid=a24e96094e174f057f1b80734a416c6c
luther@gliethttp:/vobs/dbus$ ./dbus-example receive
Listening for signals
    server_guid=    a24e96094e174f057f1b80734a416c6c
    address=    unix:abstract=/tmp/dbus-VRg0ZEh0PA
    expected_guid=    a24e96094e174f057f1b80734a416c6c
    unique_name=    :1.204
Match rule sent
^C
luther@gliethttp:/vobs/dbus$ ./dbus-example receive
Listening for signals
    server_guid=    a24e96094e174f057f1b80734a416c6c
    address=    unix:abstract=/tmp/dbus-VRg0ZEh0PA
    expected_guid=    a24e96094e174f057f1b80734a416c6c
    unique_name=    :1.205
Match rule sent

Got Signal with value gliethttp.cublog.cn

^C
luther@gliethttp:/vobs/dbus$

luther@gliethttp:~$ dbus-send --session --type=signal --dest=test.signal.sink /luther/gliethttp test.signal.Type.Test string:'gliethttp.cublog.cn'

或者不指定dest,因为dbus-session的daemon程序如果发现message类型为signal,那么即便没有dest,它也将尝试将该message发送到interface,signal想匹配的应用程序上.

luther@gliethttp:~$ dbus-send --session --type=signal /luther/gliethttp test.signal.Type.Test string:'gliethttp.cublog.cn'

ps:不加--print-reply,是因为signal没有返回数据.

我们还可以使用下面的dest地址,可以参考《对dbus路由端口名称创建和使用的一点理解》

luther@gliethttp:~$ dbus-send --session --type=signal --dest=:1.205 /luther/gliethttp test.signal.Type.Test string:'gliethttp.cublog.cn'

来看看结构体定义,因为结构体内部全部为4字节对齐变量类型,所以不必去考虑对齐字节调整问题[luther.gliethttp]
struct DBusConnection
{
0 DBusAtomic refcount; /**< Reference count. */

1 DBusMutex *mutex; /**< Lock on the entire DBusConnection */

2 DBusMutex *dispatch_mutex; /**< Protects dispatch_acquired */
3 DBusCondVar *dispatch_cond; /**< Notify when dispatch_acquired is available */
4 DBusMutex *io_path_mutex; /**< Protects io_path_acquired */
5 DBusCondVar *io_path_cond; /**< Notify when io_path_acquired is available */
  
6 DBusList *outgoing_messages; /**< Queue of messages we need to send, send the end of the list first. */
7 DBusList *incoming_messages; /**< Queue of messages we have received, end of the list received most recently. */

8 DBusMessage *message_borrowed; /**< Filled in if the first incoming message has been borrowed;
                                  * dispatch_acquired will be set by the borrower
                                  */

  
9 int n_outgoing; /**< Length of outgoing queue. */
10 int n_incoming; /**< Length of incoming queue. */

11 DBusCounter *outgoing_counter; /**< Counts size of outgoing messages. */
  
12 DBusTransport *transport; /**< Object that sends/receives messages over network. */
13 DBusWatchList *watches; /**< Stores active watches. */
14 DBusTimeoutList *timeouts; /**< Stores active timeouts. */
  
15 DBusList *filter_list; /**< List of filters. */

16 17 DBusDataSlotList slot_list; /**< Data stored by allocated integer ID */

18 DBusHashTable *pending_replies; /**< Hash of message serials to #DBusPendingCall. */
  
19 dbus_uint32_t client_serial; /**< Client serial. Increments each time a message is sent */
20 DBusList *disconnect_message_link; /**< Preallocated list node for queueing the disconnection message */

21 DBusWakeupMainFunction wakeup_main_function; /**< Function to wake up the mainloop */
22 void *wakeup_main_data; /**< Application data for wakeup_main_function */
23 DBusFreeFunction free_wakeup_main_data; /**< free wakeup_main_data */

24 DBusDispatchStatusFunction dispatch_status_function; /**< Function on dispatch status changes */
25 void *dispatch_status_data; /**< Application data for dispatch_status_function */
26 DBusFreeFunction free_dispatch_status_data; /**< free dispatch_status_data */

27 DBusDispatchStatus last_dispatch_status; /**< The last dispatch status we reported to the application. */

28 DBusList *link_cache; /**< A cache of linked list links to prevent contention
                         * for the global linked list mempool lock
                         */

29 DBusObjectTree *objects; /**< Object path handlers registered with this connection */

30 char *server_guid; /**< GUID of server if we are in shared_connections, #NULL if server GUID is unknown or connection is private */


struct DBusTransport
{
0 int refcount; /**< Reference count. */

1 const DBusTransportVTable *vtable; /**< Virtual methods for this instance. */

2 DBusConnection *connection; /**< Connection owning this transport. */

3 DBusMessageLoader *loader; /**< Message-loading buffer. */

4 DBusAuth *auth; /**< Authentication conversation */

5 DBusCredentials *credentials; /**< Credentials of other end read from the socket */

6 long max_live_messages_size; /**< Max total size of received messages. */

7 DBusCounter *live_messages_size; /**< Counter for size of all live messages. */


8 char *address; /**< Address of the server we are connecting to (#NULL for the server side of a transport) */

9 char *expected_guid; /**< GUID we expect the server to have, #NULL on server side or if we don't have an expectation */

阅读(3171) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~