Zim::GUI::Daemon.3pm

Langue: en

Autres versions - même langue

Version: 2009-02-23 (debian - 07/07/09)

Section: 3 (Bibliothèques de fonctions)

NAME

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

SYNOPSIS

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

DESCRIPTION

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.

METHODS

"exists()"
Returns boolean to check if we have a daemon or not.
"do(CMD, @ARGS)"
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.

"list()"
Method for clients to request a list of notebooks. Assumes that STDIN is flushed.
"daemonize(CODE)"
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.

"main()"
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.

"ACTION_open(PID, NOTEBOOK, PAGE, @ARGS)"
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.

"ACTION_run(PID, NAME, CLASS, @ARGS)"
If there is no child with NAME run one using "CLASS-"run(@ARGS)>. Can be used by plugins to run a special process.
"ACTION_register(PID, NAME)"
Allows the child process to tell it's short name to the daemon. THis name does not need to be unique.
"ACTION_list(PID)"
Will print a list of open notebooks to STDIN of PID. Or to STDOUT if PID is not a child process.
"ACTION_tell(PID, TO, @ARGS)"
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.
"ACTION_broadcast(PID, @ARGS)"
Send ARGS to all processes except the one that is broadcasting.
"ACTION_quit(PID)"
Quit the daemon if all children have exited. To quit all children try something like "broadcast Close FORCE".

Other routines

"join_line(@STRING)"
Function that serializes list into a single string.
"split_line(STRING)"
Function that splits line into list.

AUTHOR

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.

SEE ALSO