Inter-Process Networking
Power Manager consists of a collection of processes. These processes include the Power Manager application, the Scheduler, and per-user assistants.
These processes need to find and talk to each other. This section discusses how this communication works.
On Start Up
The Scheduler is launched and kept running using a macOS launchd
job stored in /Library/LaunchDaemons
; list Power Manager’s launchd jobs with the command:
sudo launchctl list | grep uk\.co\.dssw\.powermanager
The Scheduler opens and listens on a TCP/IP socket. The socket’s port is assigned by macOS to avoid conflicting with other processes. Only connections originating on the same computer are accepted (local host only); list Power Manager’s TCP/IP sockets with the command:
sudo lsof -i | grep uk\.co
The Scheduler needs to let other processes know what port is being used. To do this, the Schedule registers a local only service using macOS’s dns-sd
(Service Discovery); see Supporting Bonjour for the registered service details and to list Power Manager’s Service Discovery entries use the command:
dns-sd -B _pm._tcp.
Talking to the Scheduler
When the Power Manager application or another process needs to talk to the Scheduler, the following steps are performed.
The process asks macOS’s
dns-sd
if a service matching the Scheduler has been registered.If the Scheduler has not registered with
dns-sd
, then the asking process assumes the Scheduler is not running on the computer.If the Scheduler has registered,
dns-sd
provides the asking process with the port needed to connect to the Scheduler.With the socket’s port provided by
dns-sd
, the process can now open an encrypted local TCP/IP connection to the Scheduler.