Skip to content

Commit

Permalink
Merge pull request #8 from idleroamer/adapter-disposable
Browse files Browse the repository at this point in the history
Make DBusAdapter Disposable
  • Loading branch information
idleroamer authored Apr 18, 2021
2 parents a994150 + 4921119 commit 4b75c0f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ A python script is the code-generator for `qfacedotnet`. It is possible to integ
<Output ItemName="Generated" TaskParameter="Outputs" />
</Exec>
<ItemGroup>
<Compile Remove="@(Generated)" />
<Compile Include="@(Generated)" />
<FileWrites Include="@(Generated)" />
</ItemGroup>
Expand Down Expand Up @@ -114,11 +115,18 @@ A predefined name pattern of bus name makes detection of related services possib

**_NOTE:_** The "qface.registry." pattern is used in case "DBUS_SERVICE_NAME_PATTERN" environment variable not defined

### Life time of objects
### Service Lifetime

One may end the a service lifetime on dbus by unregistering the `DBusAdapter`.
Individual services can be disposed by respective `DBusAdapter`.
Given [object management](#Object-Management) governs service-client relation it would lead into connected `DBusProxy`s [ready property](#ready-property)] to be set to false.

```
server, err := dbus.SessionBus()
qfacedotnet.ObjectManager(server).UnregisterObject(DBusAdapter.ObjectPath(), nil)
```
DBusAdapter.Dispose();
```

## Limitation

There are some limitation with regards to qface:
* keyword [Model](https://doc.qt.io/qt-5/model-view-programming.html) is not supported
* keyword [Flag](https://doc.qt.io/QtIVI/idl-syntax.html#enum-or-flag) is not supported
* extends keyword is not supported
2 changes: 1 addition & 1 deletion src/generator/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

parser = argparse.ArgumentParser(description='Generates bindings for Tmds based on the qface IDL.')
parser.add_argument('--input', dest='input', type=str, required=True, nargs='+',
help='input qface interfaces, folders will be walked looking for qface interfaces')
help='input qface interfaces, folders will be globbed looking for qface interfaces')
parser.add_argument('--output', dest='output', type=str, required=False, default='.',
help='relative output path of the generated code, default value is current directory')
parser.add_argument('--dependency', dest='dependency', type=str, required=False, nargs='+', default=[],
Expand Down
10 changes: 8 additions & 2 deletions src/generator/templates/DBusAdapter.cs.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ using qfacedotnet;

namespace {{module.qualified_name}}
{
public class {{interface.name}}DBusAdapter : IDBus{{interface.name}}
public class {{interface.name}}DBusAdapter : IDBus{{interface.name}}, IDisposable
{
protected static ObjectPath _DefaultPath = new ObjectPath("/{{interface.qualified_name|replace(".","/")}}");
private readonly ObjectPath _Path;
protected I{{interface.name}} _impl;

private Connection _conn;
public ObjectPath ObjectPath { get => _Path;}

public {{interface.name}}DBusAdapter(I{{interface.name}} impl, string path = "/{{interface.qualified_name|replace(".","/")}}") {
Expand All @@ -28,6 +28,7 @@ namespace {{module.qualified_name}}
}

public async Task RegisterObject(Connection conn) {
_conn = conn;
(await qfacedotnet.ObjectManager.Manager(conn)).RegisterObject(_Path, new Dictionary<string, IDictionary<string, object>>());
await conn.RegisterObjectAsync(this);
}
Expand All @@ -37,6 +38,11 @@ namespace {{module.qualified_name}}
conn.UnregisterObject(this);
}

public async void Dispose()
{
await UnregisterObject(_conn);
}

{% for property in interface.properties %}
public virtual {{property.qfacedotnet_type}} {{property.name}}
{
Expand Down
2 changes: 1 addition & 1 deletion test/AddressBook/AddressBookTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public async Task AdapterRemoved()

var proxyReady2 = new TaskCompletionSource<bool>();
proxy.readyChanged += args => proxyReady2.SetResult(args);
await addressBookAdapter.UnregisterObject(conn2);
addressBookAdapter.Dispose();

await proxyReady2.Task;
Assert.False(proxy.ready);
Expand Down

0 comments on commit 4b75c0f

Please sign in to comment.