CAPS Universe documentation
1.0.4
All you need to know to be successful
|
The Printing Coordinator calls back. More...
Data Structures | |
struct | caps_cl_notifier |
Define notifier callbacks for Printing Coordinator clients. More... | |
Macros | |
#define | CAPS_NOTIFIER_HANDLED 0 |
#define | CAPS_NOTIFIER_NOT_YET_HANDLED 1 |
Functions | |
int | caps_cl_notifiers_process (struct caps_cl_handle *instance) |
int | caps_cl_connection_fd_get (struct caps_cl_handle *instance) |
Notifier API.
Sometimes you are interested in state changes of printers and/or print jobs. Instead of polling their state all the time, you can be called back via a notfier instead.
Printer related state change notifications can be:
Job related state change notifications can be:
For this, you can register notifiers:
Using the notifiers looks like the example in Be part of the whole thing, only the Do all the hard work block differs:
The corresponding code example looks like in Be part of the whole thing. It is extended by the notifier functions and the structure caps_cl_notifier to register it. And the periodical call to caps_cl_notifiers_process() is added as well.
Example for a printer notifier:
Example for a print job notifier:
#define CAPS_NOTIFIER_HANDLED 0 |
Used by the notifier callback as a return value: the incoming notifier is finally processed
#define CAPS_NOTIFIER_NOT_YET_HANDLED 1 |
Used by the notifier callback as a return value: the incoming notifier isn't finally processed
int caps_cl_notifiers_process | ( | struct caps_cl_handle * | instance | ) |
Process CAPS printer and job related notifiers
[in] | instance | Client instance |
0 | On success |
-EIO | If the connection to the printing coordinator was (unexpectedly) closed |
Processing a notifier means dispatching the received information to the registered notifier callback functions.
If notifiers are ready to process, this function processes them and returns immediately. If no notifier is present when called (e.g. queue is empty, nothing to be done), it waits for a notifier to arrive until a timeout of one second and then returns.
In a main loop you can call this function, whenever the filedescriptor of the underlying connection signals data is present (refer caps_cl_connection_fd_get()).
int caps_cl_connection_fd_get | ( | struct caps_cl_handle * | instance | ) |
Retrieve the underlying communication filedescriptor for main loop inclusion
[in] | instance | Client instance |
Positive | Filehandle |
-1 | Connection is in a state where the filedescriptor cannot be exported |
If it returns '-1' you need to call caps_cl_notifiers_process() periodically instead.