diff options
author | Teddy Wing | 2018-10-05 13:31:26 +0200 |
---|---|---|
committer | Teddy Wing | 2018-10-05 13:31:26 +0200 |
commit | 4b482ff81bd094966af282b8ffd0a09ad1b18d78 (patch) | |
tree | 58b438aa5ea3366cdac79c0e03b5b8c62b65e518 /lib/dome-key-map | |
parent | fb46a8b01ccf243b0caa360e360c43f1fc2df7de (diff) | |
download | DomeKey-4b482ff81bd094966af282b8ffd0a09ad1b18d78.tar.bz2 |
Set up IPC to enable reloading the mappings file
My original plan was to use an `NSXPCConnection` to handle the IPC for
reloading mappings.
For some background, this is what I'm envisioning:
1. DomeKey is running in the background
2. User wants to make a change to their config. Update `mappings.dkmap`.
3. The new mappings file needs to be re-parsed and reloaded into memory.
The simplest thing we could do is just quit and relaunch DomeKey. but
that's kind of a pain. So instead, we run something like this from
the command line:
$ dome-key --reload-mappings
This will tell the running DomeKey process to update its mappings by
reloading the mappings file.
As I said, I was going to use `NSXPCConnection` for the IPC
communication, as it had come up in my research for IPC mechanisms on OS
X. I knew I didn't want to use a TCP socket as that seemed like too much
overhead. The ability to pass messages to classes "directly" using
`NSXPCConnection` was very appealing. However, I got a little lazy
trying to learn it. It has a whole model for how the communication
should work, including various procedures that need to be set up using
its API. It started to feel like a bit of a pain.
At that point I started looking into alternatives. One idea was to move
the IPC into the Rust code and use Unix Domain Sockets
(https://doc.rust-lang.org/std/os/unix/net/struct.UnixListener.html). I
was tempted to go this route, but I wasn't a fan of the need to always
be listening, the potential need to spawn a thread to reload the
mappings to free up the main workload, the need to figure out a way to
pass `State` (which keeps our parsed mappings in memory) around, and the
fact that only plain strings are passed, instead of messages in the case
of `NSXPCConnection`.
I came across
https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/OSX_Technology_Overview/SystemTechnology/SystemTechnology.html
where I discovered BSD notifications and `notify.3`. This seemed to be
the lightweight easy-to-use solution that I was looking for. After
following a little sample code, it works like a charm.
Diffstat (limited to 'lib/dome-key-map')
0 files changed, 0 insertions, 0 deletions