mono / dbus-sharp

DBus Sharp
http://mono.github.com/dbus-sharp
MIT License
76 stars 59 forks source link

Not able to catch the Dbus-Signal ? #67

Closed RajatRokade closed 7 years ago

RajatRokade commented 7 years ago

I have written a C# application to connect with the linux application running on virtual machine and i am able to connect and execute different methods. I am not able to catch the signal emitted by my Linux application even though i can see it in the dubs-monitor.

C# Code:

using System;
using NDesk.DBus;
using org.freedesktop.DBus;
using System.Threading;

namespace DBusGeneric
{
    public class Program
    {
        public static Connection conn;
        public static Test Store;
        public static string InterfaceName = "org.gnome.Shell.SearchProvider2";
        public delegate void OnEmitSignalHandler();

        static void Main(string[] args)
        {

            conn = Connection.Open("tcp:host=IP Address,port=Port No");

            Thread thread = new Thread(MainLoop);
            thread.Start();

            string name = "org.freedesktop.DBus";
            ObjectPath opath = new ObjectPath("/");
            IBus bus = conn.GetObject<IBus>(name, opath);
            bus.Hello();

            string busName = "org.example.TestServer";
            ObjectPath objPath = new ObjectPath("/org/example/TestObject");
            Introspectable intr = conn.GetObject<Introspectable>(busName, objPath);
            string xmlData = intr.Introspect(); ;
            Console.WriteLine("\n");
            Console.WriteLine("xmlData: " + xmlData);

            Console.WriteLine("\n");

            Store = conn.GetObject<Test>(busName, objPath);
            Store.OnEmitSignal += Store_OnEmitSignal;
            Store.EmitSignal();
            Store.Ping();

            Console.ReadKey();

        }

        public static void  MainLoop()
        {
            while(true)
            {
                conn.Iterate();
            }

        }

        private static void Store_OnEmitSignal()
        {
            Console.WriteLine("/////////////////// Received Signal ///////////////////////");
        }

        [Interface("org.example.TestInterface")]
        public interface Test
        {
            event OnEmitSignalHandler OnEmitSignal;
            void EmitSignal();
            string Ping();

        }
    }
    }

dbus-monitor (Virtual Machine)

method call time=1510038376.630555 sender=:1.1110 -> destination=:1.0 serial=42 path=/org/example/TestObject; interface=org.example.TestInterface; member=EmitSignal
signal time=1510038376.631501 sender=:1.0 -> destination=(null destination) serial=43730 path=/org/example/TestObject; interface=org.example.TestInterface; member=OnEmitSignal
method return time=1510038376.631530 sender=:1.0 -> destination=:1.1110 serial=43731 reply_serial=42
method call time=1510038376.672772 sender=:1.1110 -> destination=org.freedesktop.DBus serial=43 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch
   string "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus',arg0='org.example.TestServer'"
method call time=1510038376.673839 sender=:1.1110 -> destination=org.freedesktop.DBus serial=44 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch
   string "type='signal',sender='org.example.TestServer',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',path='/org/example/TestObject',arg0='org.example.TestInterface'"
method call time=1510038376.675216 sender=:1.1110 -> destination=org.freedesktop.DBus serial=45 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch
   string "type='signal',sender='org.example.TestServer',interface='org.example.TestInterface',path='/org/example/TestObject'"

It is visible that when i call EmitSignal method, OnEmitSignal is being emitted but i cant see it on the windows side.

I tried to do the Glib main loop integration but i could not build and use the reference of Ndesk.Dbus.Glib.

Can anyone help me on how can i achieve this and also capture signals from VM on my windows system.