public async Task LocalServer(DBusDaemonProtocol protocol) { if (!File.Exists("dbus-daemon")) { throw new SkipTestException("dbus-daemon not present"); } string service = "any.service"; string listenAddress = null; switch (protocol) { case DBusDaemonProtocol.Tcp: listenAddress = "tcp:host=localhost"; break; case DBusDaemonProtocol.Unix: listenAddress = $"unix:path={Path.GetTempPath()}/{Path.GetRandomFileName()}"; break; case DBusDaemonProtocol.UnixAbstract: listenAddress = $"unix:abstract={Guid.NewGuid()}"; break; } throw new NotImplementedException(); #if false // server var server = new ServerConnectionOptions(); using (var connection = new Connection(server)) { await connection.RegisterObjectAsync(new PingPong()); var boundAddress = await server.StartAsync(listenAddress); for (int i = 0; i < 2; i++) { // client using (var client = new Connection(boundAddress)) { // method await client.ConnectAsync(); var proxy = client.CreateProxy <IPingPong>(service, PingPong.Path); var echoed = await proxy.EchoAsync("test"); Assert.Equal("test", echoed); // signal var tcs = new TaskCompletionSource <string>(); await proxy.WatchPongAsync(message => tcs.SetResult(message)); await proxy.PingAsync("hello world"); var reply = await tcs.Task; Assert.Equal("hello world", reply); } } } #endif }
public Task StartAsync(DBusDaemonProtocol protocol = DBusDaemonProtocol.Default, string socketPath = null) { if (_state != State.Created) { throw new InvalidOperationException("Daemon has already been started or is disposed"); } _state = State.Started; _configFile = Path.GetTempFileName(); if (protocol == DBusDaemonProtocol.Unix) { socketPath = socketPath ?? Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); File.WriteAllText(_configFile, s_config.Replace("$LISTEN", $"unix:path={socketPath}")); } else if (protocol == DBusDaemonProtocol.UnixAbstract) { socketPath = socketPath ?? Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); File.WriteAllText(_configFile, s_config.Replace("$LISTEN", $"unix:abstract={socketPath}")); } else // DBusDaemonProtocol.Tcp { File.WriteAllText(_configFile, s_config.Replace("$LISTEN", "tcp:host=localhost,port=0")); } var startInfo = new ProcessStartInfo { FileName = "dbus-daemon", Arguments = $"--config-file={_configFile} --print-address", UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true }; var tcs = new TaskCompletionSource <bool>(); _process = new Process() { StartInfo = startInfo }; _process.OutputDataReceived += (sender, dataArgs) => { if (Address == null) { Address = dataArgs.Data; tcs.SetResult(true); } }; _process.Start(); _process.BeginOutputReadLine(); return(tcs.Task); }
public async Task Transport(DBusDaemonProtocol protocol) { if (DBusDaemon.IsSELinux && protocol == DBusDaemonProtocol.Tcp) { throw new SkipTestException("Cannot provide SELinux context to DBus daemon over TCP"); } using (var dbusDaemon = new DBusDaemon()) { await dbusDaemon.StartAsync(protocol); var connection = new Connection(dbusDaemon.Address); var connectionInfo = await connection.ConnectAsync(); Assert.StartsWith(":", connectionInfo.LocalName); Assert.Equal(true, connectionInfo.RemoteIsBus); } }