dbus C API の例http://www.matthew.ath.cx/misc/dbusがあります。また、改善された github にもあります https://github.com/wware/stuff/blob/master/dbus-example/dbus-example.c。呼び出しを行って応答を取得する query() 関数では、19 行目から 23 行目を追加して、以下に示すようにタイムアウトを処理する必要がありますか? 実行する場合、20 行目の保留中の行で ...unref を呼び出す必要がありますか? この例の流れを読んで、それが私たちのやるべきことだと思います。
// send message and get a handle for a reply
if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout
fprintf(stderr, "Out Of Memory!\n");
exit(1);
}
if (NULL == pending) {
fprintf(stderr, "Pending Call Null\n");
exit(1);
}
dbus_connection_flush(conn);
printf("Request Sent\n");
// free message
dbus_message_unref(msg);
// block until we recieve a reply
dbus_pending_call_block(pending);
/*do we need to handle the timeout case? -- line 20*/
if ( ! dbus_pending_call_get_completed(pending) ) {
/*do we need to unref pending? -- line 22 */
dbus_pending_call_unref(pending); /* --line 23 */
fprintf(stderr, "Reply timeout\n");
return(1);
}