-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to raise an event/signal? #62
Comments
Did you get this to work? |
Yes, I managed to get it to work. I've posted my minimal example here, in case it helps someone in the future. If you run it, you can use I think I had a bit of a fundamental misunderstanding how DBus properties are modeled. I thought that if a DBus interface called for a list of properties, you would model that directly in your C# DBus Interface. It seems like the idea is that instead you expose the methods in the interface as defined by DBus called There does seem to be something special with the In the unit test code, there is the using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Tmds.DBus;
[assembly: InternalsVisibleTo(Tmds.DBus.Connection.DynamicAssemblyName)]
namespace publishproperty
{
class Program
{
static void Main(string[] args)
{
Task.Run(async () =>
{
using (var connection = new Connection(Address.System))
{
await connection.ConnectAsync();
var exposed = new Example();
await connection.RegisterObjectAsync(exposed);
int globalWarming = 0;
while (true)
{
// Setting this value will create a signal on the bus with the new temperature value
exposed.Value = globalWarming++;
await Task.Delay(TimeSpan.FromSeconds(1));
}
}
}).Wait();
}
}
public class Example : ITemperature
{
int _value;
public int Value
{
get { return _value; }
set
{
_value = value;
OnPropertiesChanged?.Invoke(PropertyChanges.ForProperty(nameof(Value), value));
}
}
public ObjectPath ObjectPath => new ObjectPath("/com/example/object1");
public event Action<PropertyChanges> OnPropertiesChanged;
public Task<IDisposable> WatchPropertiesAsync(Action<PropertyChanges> handler)
{
return SignalWatcher.AddAsync(this, nameof(OnPropertiesChanged), handler);
}
}
[DBusInterface("com.example")]
interface ITemperature : IDBusObject
{
Task<IDisposable> WatchPropertiesAsync(Action<PropertyChanges> handler);
}
} |
All of the examples/code I could find seem to show how you could create a proxy object and subscribe to signals that the remote object raises. I.e. consume events/signals.
How do I publish a local object that raises a signal?
I need to raise the PropertiesChanged signal for
myObject
and pass some values through in a dictionary.Any help greatly appreciated.
The text was updated successfully, but these errors were encountered: