【发布时间】:2012-11-25 19:25:18
【问题描述】:
对于我们当前的项目,我们使用的是 DBus (1.6.n)。 它主要是在共享内存模式下从 C++ 访问的,而且效果非常好。
我现在正尝试从 C# 程序访问相同的 DBus。
为了先尝试一下,我下载了我能找到的最新版本的 dbus-sharp,并启动了下载中包含的守护程序,看看我是否可以从我的测试 C# 应用程序连接到它。
每当我建立连接时,守护程序控制台都会显示我正在与之通信,但是一旦我尝试访问连接上的任何方法,我就会收到错误;
'访问被拒绝:DBus.BusObject'
这是我尝试过的代码;
DBus.Bus dBus = null;
try
{
//input address comes from the UI and ends up as "tcp:host=localhost,port=12345";
//dBus = new Bus(InputAddress.Text + inputAddressExtension.Text);
//string s = dBus.GetId();
//dBus.Close();
//DBus.Bus bus = DBus.Bus.System;
//DBus.Bus bus = Bus.Open(InputAddress.Text + inputAddressExtension.Text);
//DBus.Bus bus = DBus.Bus.Session;
//DBus.Bus bus = DBus.Bus.Starter;
var conn = Connection.Open(InputAddress.Text + inputAddressExtension.Text);
var bus = conn.GetObject<Introspectable>(@"org.freedesktop.DBus.Introspectable", new ObjectPath("/org/freedesktop/DBus/Introspectable"));
bus.Introspect();
}
finally
{
if(dBus != null)
dBus.Close();
}
注释的代码最终也会产生同样的错误。
我已经使用调试器,它总是会在 TypeImplementer.cs 中找到以下代码;
公共类型GetImplementation(类型declType) { 输入 retT;
lock (getImplLock)
if (map.TryGetValue (declType, out retT))
return retT;
string proxyName = declType.FullName + "Proxy";
Type parentType;
if (declType.IsInterface)
parentType = typeof (BusObject);
else
parentType = declType;
TypeBuilder typeB = modB.DefineType (proxyName, TypeAttributes.Class | TypeAttributes.Public, parentType);
if (declType.IsInterface)
Implement (typeB, declType);
foreach (Type iface in declType.GetInterfaces ())
Implement (typeB, iface);
retT = typeB.CreateType (); <======== Fails here ==========
lock (getImplLock)
map[declType] = retT;
return retT;
}
我没有找到任何关于从 C# 访问 DBus 的有用示例或文档,而且最近似乎很少有关于这方面的条目,所以也许没有其他人在尝试这个。
我在与测试程序相同的文件夹中运行守护程序。 当我在 Windows 上运行时,守护进程正在侦听 tcp 设置;
string addr = "tcp:host=localhost,port=12345";
由于这是下载中包含的示例,我认为它会很简单,但可惜还没有运气。
还有其他人来过这里并知道下一个难题吗?
任何想法都将不胜感激。
【问题讨论】:
-
更新 - 我已尝试根据 'documentation'! 在与 exe 同名且扩展名为 .conf 的配置文件中添加各种设置。守护进程似乎没有注意到任何这些设置,因为我可以输入任何我喜欢的内容,并且守护进程的运行与以前完全相同。