c++ - Dbus - 没有收到回复

标签 c++ linux dbus

我对 Dbus 有一个奇怪的问题...
我使用Dbus-1。
问题是,它只是有时发生在不同的地方。 有时用于 IDAMsg_GetFontName,有时用于 IDAMsg_GetForeColor(例如)。 也许程序运行十次正常,然后运行一次出错。或者四次正常,然后两次出错。

但我的 std::cout 和 Dbus 总是出现相同的错误消息:

Too few arguments

Did not receive a reply

但是有时我的争论怎么可能太少呢?
如何向 Dbus 提供此错误消息(看起来已发送并收到回复)?

非常感谢您的帮助。
TIA
早咬

Dbus 消息是:

Did not receive a reply. Possible causes include: the remote 
application did not send a reply, the message bus security policy 
blocked the reply, the reply timeout expired, or the network 
connection was broken.

方法的发送:

if(vMethod == IDAMsg_Init || vMethod == IDAMsg_GetFontName
|| vMethod == IDAMsg_AppQuit
|| vMethod == IDAMsg_GetBackColor || vMethod == IDAMsg_GetForeColor
|| vMethod == IDAMsg_GetBorderColor){
    dbus_message_iter_init_append(msg, &args);
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &vMsg.Str_Send[0])) {
         cout << "DBUS -- SEND -- OUT OF MEMORY 1" << endl; return 0;
    }
    if(vMethod == IDAMsg_GetBorderColor || vMethod == IDAMsg_AppQuit){
        if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &vMsg.Str_Send[1])) {
             cout << "DBUS -- SEND -- OUT of Memory 2" << endl; return 0;
        }
    }
}

回复是:

if(vMethod == IDAMsg_Init || vMethod == IDAMsg_AppQuit
|| vMethod == IDAMsg_GetFontName
|| vMethod == IDAMsg_GetBackColor || vMethod == IDAMsg_GetForeColor
|| vMethod == IDAMsg_GetBorderColor){
    if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)){
         cout << "DBUS -- REPLY -- ARG is not String 1 " << endl;
    } else {
         dbus_message_iter_get_basic(&args, &nStr_In[0]);
    }
    if(vMethod == IDAMsg_GetBorderColor || vMethod == IDAMsg_AppQuit){
        if (!dbus_message_iter_next(&args)){
             cout << "DBUS -- REPLY -- Message has too few arguments 1" << endl;
        } else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)){
             cout << "DBUS -- REPLY -- Argument is not STRING 2" << endl;
        } else {
             dbus_message_iter_get_basic(&args, &nStr_In[1]);
        }
    }
    reply = dbus_message_new_method_return(msg);
    dbus_message_iter_init_append(reply, &args);
}
if(vMethod == IDAMsg_Init){
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_BOOLEAN, &stat)) {
         cout << "DBUS -- REPLY -- OUT of Memory 1" << endl; return;
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &level)) {
         cout << "DBUS -- REPLY -- OUT of Memory 2" << endl; return;
    }
}

std::cout 输出通常是:

DBUS -- EBIDA_IDA_Server -- Method Reply for : GetForeColor
DBUS -- IDABrowse -- Got Reply  245_245_245 21614
IDA -- IDABrowse -- INCOMING CALLBACK : GetBorderColor
DBUS -- IDABrowse -- Request send with : GetBorderColor
DBUS -- EBIDA_IDA_Server -- Method Reply for : GetBorderColor
DBUS -- IDABrowse -- Got Reply  102_143_165 21614
IDA -- IDABrowse -- INCOMING CALLBACK : GetBorderColor
DBUS -- IDABrowse -- Request send with : GetBorderColor
DBUS -- EBIDA_IDA_Server -- Method Reply for : GetBorderColor
DBUS -- IDABrowse -- Got Reply  126_177_204 21614
IDA -- IDABrowse -- INCOMING CALLBACK : GetBorderColor
DBUS -- IDABrowse -- Request send with : GetBorderColor
DBUS -- EBIDA_IDA_Server -- Method Reply for : GetBorderColor
DBUS -- IDABrowse -- Got Reply  148_207_239 21614

但是如果出现问题,它看起来像这样:

DBUS -- EBIDA_IDA_Server -- Method Reply for : GetForeColor
DBUS -- IDABase -- Got Reply  245_245_245 21614
IDA -- IDABase -- INCOMING CALLBACK : GetBorderColor
DBUS -- EBIDA_IDA_Server -- Method Reply for : GetBorderColor
DBUS -- IDABase -- Request send with : GetBorderColor
DBUS --  SEND -- Message has too few arguments 1
DBUS -- IDABase -- Got Reply  Did not receive a reply. Possible 
causes include: the remote application did not send a reply, the 
message bus security policy blocked the reply, the reply timeout 
expired, or the network connection was broken. 32723

编辑:

我认为问题是这样显示的:

这是正常的输出顺序:

IDA -- IDABrowse -- INCOMING CALLBACK : GetBorderColor
DBUS -- IDABrowse -- Request sending with : GetBorderColor
DBUS -- EBIDA_IDA_Server -- Method Reply for : GetBorderColor
DBUS -- IDABrowse -- Got Reply  126_177_204 21614

发生错误时:

IDA -- IDABrowse -- INCOMING CALLBACK : GetBorderColor
DBUS -- EBIDA_IDA_Server -- Method Reply for : GetBorderColor
DBUS -- IDABrowse -- Request sending with : GetBorderColor
DBUS -- IDABrowse -- Got Reply  126_177_204 21614

如果出现错误,则第 2 行和第 3 行已更改。
然后,回复请求发送之前就存在...

最佳答案

调试此问题的方法是使用 dbus-monitorBustle查看总线上的流量(请求、回复、错误)。这应该查明错误并显示导致该错误的消息。

关于c++ - Dbus - 没有收到回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43651006/

相关文章:

java - 将参数从 shell 脚本传递到 java 类

linux - 无法使用 clang 在 linux 上构建 cuda 7.0 示例

python - PowerManagement.Inhibit 适用于 dbus-python 但不适用于 dbus-send

c++ - 在 QTreeView 中查找 QModelIndex 可见行的更简单方法

c++ - 通过 const 引用传递对象与传递无名对象

html - 将单个文件夹中的一组 html 文件的 &lt;title&gt; 标记内的所有文本大写

apache - DBus 是我要找的吗?

dbus - 如何创建 DBUS 服务

C++ Eigen : why can one add-assign but not add for the method asDiagonal()

C++11 多重移动构造函数调用