Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
decisions: improve ensure API
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Raab committed Nov 17, 2020
1 parent bd21584 commit 581c6bf
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions doc/decisions/ensure.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,36 @@ Integrate `kdbEnsure` in `kdbOpen(Key *errorKey, KeySet *contract)` but only all

## Implications

`elektraNotificationOpen` needs to be removed and instead we need a new API:
`elektraNotificationOpen` will only return a contract KeySet:

```c
KeySet * contract = ksNew (0, KS_END);
elektraNotificationGetContract (contract);
KDB * kdb = kdbOpen (key, contract); // contract contains notification config
elektraIoSetBinding (kdb, binding);
elektraNotificationContract (contract, iobinding);
```
Similar contract getters need to be introduced for other functionality, like gopts:
The same for gopts:
```c
elektraGOptsContract (contract, argc, argv, environ));
```

Finally, we create `KDB` with the contracts we got before:

```c
KeySet * contract = ksNew (0, KS_END);
elektraGOptsGetContract (contract, argc, argv, environ);
KDB * kdb = kdbOpen (key, contract);
```

The high-level API can make this more pretty, though.
Opening `KDB` will fail if any of the contracts cannot be ensured.

The cleanup happens within:

```c
kdbClose (kdb, errorKey);
ksDel (contract);
```
It is save to use the contract `KeySet` also for `kdbGet` and `kdbSet`
invocations.
## Related Decisions
Expand Down

0 comments on commit 581c6bf

Please sign in to comment.