---
name: "Zim::GUI::Daemon"
section: "3pm"
platform: "linux"
package: "zim"
version: "0.25-1"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/Zim::GUI::Daemon"
---

# Zim::GUI::Daemon(3pm)

Zim::GUI::Daemon - IPC module for the zim GUI

```
        # Daemon process
        Zim::GUI::Daemon->daemonize( sub { ... } );
        exit;
        # Client process
        Zim::GUI::Daemon->do('open', $notebook, $page);
```

This module contains all the IPC code to make various processes work together. The idea is to have one process without a interface running as a daemon. This daemon listens to a UNIX domain socket for commands. This daemon spawns clients to open multiple notebooks. The daemon keeps filhandlers to the STDIN of each client to communicate with them. This module is not object oriented because we only use a single instance of the daemon per process anyway. Method for the clients to pass a single command to the daemon. Arguments should be scalar and will be passed to the command routine.

Wrap this within method an `"eval { }"` block because it will die if no daemon is listening. Method for clients to request a list of notebooks. Assumes that STDIN is flushed. Unless `$Zim::DEBUG` is set this dissociates the current process from its parent process (like your shell). Then it opens the daemon socket.

CODE is the callback that is called when a new client is opened in the child  process. It should get the notebook and the page as arguments when called. Called after `"daemonize()"` to wait for input. Does not return untill a client calls the command "quit".\
 **Commands** All commands have method that starts with "ACTION\_". These are the routines that clients are allowed to call, so they are our public interface. The daemon calls these with the PID of the client followed by any arguments passed by the client. To call these remotely use `"do()"` and provide the arguments after PID for each function. If there is a child process open for NOTEBOOK it is called to open PAGE. Else a new child is spawn to open NOTEBOOK and PAGE.

NOTEBOOK and PAGE are both optional, PID is the PID of the calling client, not of the child handling NOTEBOOK. If NOTEBOOK is undefined a new child is spawn that could for example show the notebook dialog. If there is no child with NAME run one using `"CLASS-"`run(@ARGS)\>. Can be used by plugins to run a special process. Allows the child process to tell it's short name to the daemon. THis name does not need to be unique. Will print a list of open notebooks to STDIN of PID. Or to STDOUT if PID is not a child process. Pass `@ARGS` to a child process. TO can be either a PID or a NOTEBOOK. Used for testing or to interact directly with other process instances. Send ARGS to all processes except the one that is broadcasting. Exit the main loop in the daemon. Call `"broadcast Close FORCE"` first if you want all the child processes to exit nicely as well.\
 **Other routines** Function that serializes list into a single string. Function that splits line into list. Jaap Karssenberg (Pardus) \<pardus@cpan.org\> Copyright (c) 2008 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
