English 中文(简体)
DBus Glib with C++: Can t 创立了银河,释放了它,并造成这种情况。
原标题:DBus Glib with C++: Can t create a DBusGProxy, release it and create that again

Im在内部使用Glib与其他模块连接的校正。

This lib has a initialize method that sets up the dbus connection and a terminate method that finalizes all the internal resources (including the dbus connection). At least it should do this.

然而,在要求采用终止方法之后,我可以再次敲响警钟(当然,我再次称之为初步方法,然后再再次提出滥用方法)。

使用C++的Im主要(少量使用校准在C)。

这里是我的内部破坏者:

#ifdef __cplusplus
extern "C" {
#endif

#include <dbus/dbus-glib.h>
#include <stdio.h>

#define _DBUS_SERVICE       "Removed due to restrictions"
#define _DBUS_PATH      "/"
#define _DBUS_INTERFACE "Removed due to restrictions"

static DBusGConnection * my_dbus_conn = NULL;
static DBusGProxy * my_proxy = NULL;

gboolean dbus_init() {
    GError *error = NULL;
    g_type_init();
    my_dbus_conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
    if (my_dbus_conn == NULL) {
        g_printerr("DBUS Connection Error (%s)
", error->message);
        g_error_free(error);
        return false;
    }
    my_proxy = dbus_g_proxy_new_for_name(my_dbus_conn, _DBUS_SERVICE, _DBUS_PATH, _DBUS_INTERFACE);
    if (my_proxy == NULL) {
        g_printerr("ERROR: DBUS Proxy creation Error (%s)
", error->message);
        g_error_free(error);
        return false;
    }
    return true;
}

DBusGProxy * dbus_get_proxy() {
    if (my_proxy == NULL) {
        dbus_init();
    }
    return my_proxy;
}

void dbus_term() {
    g_object_unref(G_OBJECT (my_proxy));
    dbus_g_connection_unref(my_dbus_conn);
    my_dbus_conn = NULL;
}

#ifdef __cplusplus
}
#endif

我在此呼吁:

MY_G_DEBUG("Manager", "Creating Server IPC stub...");
this->m_pDbusServer = get_proxy();

if (this->m_pDbusServer == NULL) {
    return;
}

MY_G_DEBUG("Manager", "CheckPoint 1!");
gboolean success;
GError *gerror = NULL;
char **l_pHelloWorldReply;

success = dbus_server_helloworld(this->m_pDbusServer, "Hello World from Manager", &l_pHelloWorldReply, &gerror);

MY_G_DEBUG("Manager", "CheckPoint 2!");

if (success == FALSE) {
    MY_G_DEBUG("Manager", "CheckPoint 3!");
    if (gerror == NULL) {
        MY_G_DEBUG("Manager", "CRITICAL: Hello World call Failed (error not set)");
    } else {
        MY_G_DEBUG("Manager", "CRITICAL: Hello World call Failed (%s)", gerror->message);
        g_error_free(gerror);
        gerror = NULL;
    }
    return;
} else {
    MY_G_DEBUG("Manager", "CheckPoint 4!");
    for (guint ii = 0; l_pHelloWorldReply[ii] != NULL; ii++) {
        MY_G_DEBUG("Manager", "Hello World response %d: %s", ii, l_pHelloWorldReply[ii]);
    }
}

MY_G_DEBUG("Manager", "CheckPoint 5!");

这里是伐木产出:

(process:24498): Manager-DEBUG: Checkpoint: 1!
(process:24498): Manager-DEBUG: Checkpoint: 2!
(process:24498): Manager-DEBUG: Checkpoint: 3!
(process:24498): Manager-DEBUG: CRITICAL: Hello World call Failed (error not set)

每次我称之为“临时”职能时,我都会发出错误信息,但我无法固定。

(process:24498): GLib-GObject-WARNING **: invalid uninstantiatable type `<invalid>  in cast to `GObject 
(process:24498): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)  failed

The first time I try to call methods, everything works well... I strongly believe that s caused by the dbus_term issue.

是否有人想为什么发生这种情况?

非常感谢。

最佳回答

在新法典中使用bus,而是使用银。

GDBus是2.26英寸的新管道。 其优于 d贝的优点包括使用全球化学品统一分类法(GAsync*,GCancellable),使用全球价值链替代类型,并更好地提供校对支持。

See http://library.gnome.org/devel/gio/2.28/ch29.html for migrating to GDBus.

问题回答

放弃最后提及仍然开放的潜水线是ug的。 你使用的具有约束力的问题之一是,很难知道联系实际上何时关闭。 它有些不满意,但我的做法是,在连接像会议公共汽车这样的众所周知的公交车上留下一 reference。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签