【问题标题】:How to emit signals with dbus-sharp?如何使用 dbus-sharp 发出信号?
【发布时间】:2014-08-29 17:58:25
【问题描述】:

也发布在 github 问题跟踪器上,https://github.com/mono/dbus-sharp/issues/43

我有一个接口,其中包含一些显示在 dbus 上的方法,我可以用 d-feet 调用它们。我想在我的界面中添加一些信号,以便服务可以在其状态更改、连接丢失/恢复等时进行报告,但我不知道该怎么做。

【问题讨论】:

    标签: c# mono dbus


    【解决方案1】:

    我会回答我自己的问题:

    • 向您的 dbus 对象类添加一个事件,例如:

      public class Blah : MarshalByRefObject
      {
          public event MyEventHandler OnEvent;
      
          public void EventHandler()
          {
              if(OnEvent != null) { OnEvent(); }
          }
      }
      
    • 运行“dbus-monitor”以观察系统上的 dbus 活动

    • 调用 Blah 的 EventHandler() 方法并查看 'OnEvent' 信号是从您的 dbus 对象发送的。

    【讨论】:

      猜你喜欢
      • 2011-01-08
      • 2012-10-14
      • 2011-04-10
      • 1970-01-01
      • 2021-05-23
      • 2014-03-27
      • 2016-07-16
      • 2016-09-16
      • 1970-01-01
      相关资源
      最近更新 更多