[avahi] Mono apps don't get notified of ClientState.Running

Celso Pinto cpinto at yimports.com
Mon May 1 05:35:20 PDT 2006


I only checked the client-publish-service.c example.

I'm assuming it works and the code looks the same.

But you don't have to trust me on this, check the attached example and 
you'll see that the OnClientStateChange callback is never invoked.

Compile the example with: mcs -pkg:glib-sharp-2.0,avahi-sharp demo.cs

I'm thinking that probably I'll just workaround the issue and if this 
gets solved do the right thing later, but it sucks not being able to use 
the state changes to do everything.

Cheers,
Celso


Trent Lloyd wrote:
> What do the other examples do, not bother to check?
> 
> Trent
> 
> On Mon, May 01, 2006 at 04:47:38AM +0100, Celso Pinto wrote:
>> Hi again guys,
>>
>> the Connect() method doesn't work because the Client.OnClientCallback 
>> method is invoked while avahi_client_new, which means that the Client 
>> object still has an invalid Handle and Avahi.EntryGroup barfs on it.
>>
>> I'm attaching the patch if you care to take a look (it prints a couple 
>> of debug messages to stdout).
>>
>> You'll see that the output "OnClientCallback invoked for state Running" 
>> is printed before the "Got handle" message.
>>
>> Any ideas?
>>
>> Cheers,
>> Celso
>>
>> Celso Pinto wrote:
>>> Hi everyone,
>>>
>>> I'm programming an application that uses Avahi's Mono bindings and I 
>>> think I found an ugly problem: when a Mono app creates an instance of 
>>> Avahi.Client, the constructor of this class invokes the native 
>>> avahi_client_new method, which receives a parameter for the client_state 
>>> callback.
>>>
>>> While still in construction, the Avahi.Client class gets notified that 
>>> the ClientState is now Running, so the Client.OnClientCallback method is 
>>> invoked but the StateChanged event still doesn't contain any Handlers 
>>> because this is all happening during construction of the Avahi.Client 
>>> object.
>>>
>>> This means that applications, like my own, that are waiting on the 
>>> StateChanged event with a ClientState.Running value to start publishing 
>>> their services never get notified, therefore never get to publish anything.
>>>
>>> The only way to fix this problem is to create a Client.Connect() method. 
>>> This allows us to first create an instance of Avahi.Client, then add a 
>>> delegate to the StateChanged event and finally call the 
>>> Avahi.Client.Connect() method. Only then our callbacks get notified of 
>>> the running state.
>>>
>>> The big question is: because this will break the current behaviour of 
>>> the Avahi.Client class (meaning that the client connects to the daemon 
>>> during construction), will you guys make the necessary changes?
>>>
>>> Cheers,
>>> Celso
>>> _______________________________________________
>>> avahi mailing list
>>> avahi at lists.freedesktop.org
>>> http://lists.freedesktop.org/mailman/listinfo/avahi
>>>
> 
>> --- Client.cs.old	2006-05-01 03:59:28.000000000 +0100
>> +++ Client.cs	2006-05-01 04:44:05.000000000 +0100
>> @@ -117,6 +117,7 @@
>>          private ClientCallback cb;
>>          private PollCallback pollcb;
>>          private IntPtr spoll;
>> +        private ClientFlags cflags;
>>  
>>          private Thread thread;
>>  
>> @@ -251,6 +252,16 @@
>>  
>>          public Client (ClientFlags flags)
>>          {
>> +            cflags = flags;
>> +        }
>> +
>> +        public Client () : this (ClientFlags.None) {
>> +        }
>> +
>> +        public void Connect()
>> +        {
>> +            if (handle != IntPtr.Zero) return;
>> +
>>              spoll = avahi_simple_poll_new ();
>>  
>>              pollcb = OnPollCallback;
>> @@ -259,18 +270,22 @@
>>              cb = OnClientCallback;
>>  
>>              int error;
>> -            handle = avahi_client_new (poll, flags, cb, IntPtr.Zero, out error);
>> +            handle = avahi_client_new (poll, cflags, cb, IntPtr.Zero, out error);
>> +            Console.WriteLine("Got handle");
>>              if (error != 0)
>> -                throw new ClientException (error);
>> +            {
>> +                avahi_simple_poll_quit (spoll);
>> +                avahi_simple_poll_free (spoll);
>> +                handle = IntPtr.Zero;
>>  
>> +                throw new ClientException (error);
>> +            }
>> +            
>>              thread = new Thread (PollLoop);
>>              thread.IsBackground = true;
>>              thread.Start ();
>>          }
>> -
>> -        public Client () : this (ClientFlags.None) {
>> -        }
>> -
>> +        
>>          ~Client ()
>>          {
>>              Dispose ();
>> @@ -348,6 +363,7 @@
>>          
>>          private void OnClientCallback (IntPtr client, ClientState state, IntPtr userData)
>>          {
>> +            Console.WriteLine("OnClientCallback invoked for state {0}",state);
>>              if (StateChanged != null)
>>                  StateChanged (this, new ClientStateArgs (state));
>>          }
> 
>> _______________________________________________
>> avahi mailing list
>> avahi at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/avahi
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: demo.cs
Type: text/x-csharp
Size: 684 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/avahi/attachments/20060501/3babaf97/demo.bin


More information about the avahi mailing list