CAPS Universe documentation  1.0.4
All you need to know to be successful
Data Structures | Macros | Functions
printing-coordinator-local.h File Reference

Some declarations used internally only. More...

Go to the source code of this file.

Data Structures

struct  object_state_prn
 Printer state information for internal use. More...
 
struct  object_state_job
 Print job state information for internal use. More...
 
struct  object_progression_job
 Print job progression information. More...
 
struct  caps_coordinator
 
struct  caps_printer_info
 

Macros

#define DSO_VISIBLE
 
#define ARRAY_SIZE(x)   (sizeof(x)/sizeof(x[0]))
 
#define caps_invalidate_pointer(pointer)
 
#define caps_print_debug(fmt, ...)
 
#define _(string)   (string)
 
#define NLS_(string)   (string)
 
#define CONFIG_TIMEOUT   30000
 
#define CAPS_RUNTIME_CONFIG_LEVEL   "base"
 

Functions

void caps_init_runtime_data (struct caps_coordinator *database)
 
void caps_exit_runtime_data (struct caps_coordinator *database)
 
caps_identifier pc_provider_unique_printer_id_create (struct caps_coordinator *database, unsigned property)
 
int pc_provider_printer_id_free (struct caps_coordinator *database, unsigned property, caps_identifier pr_id)
 
caps_identifier pc_provider_id_by_property_get (struct caps_coordinator *database, unsigned property)
 
void pc_provider_orphaned_printer_free (struct caps_coordinator *database, unsigned property)
 
int pc_provider_printer_state_set (struct caps_coordinator *database, unsigned property, caps_identifier pr_id, const struct object_state_prn *state)
 
int pc_provider_printer_info_set (struct caps_coordinator *database, unsigned property, caps_identifier pr_id, const char *name, const char *info, const char *loction, const char *vendor, const char *model, struct caps_supported_mime_list *list)
 
int pc_provider_ppd_set (struct caps_coordinator *database, unsigned property, caps_identifier pr_id, int fh)
 
caps_identifier pc_provider_job_id_prepare (struct caps_coordinator *database, unsigned property, caps_identifier pr_id)
 
int pc_provider_job_get (struct caps_coordinator *database, unsigned property, caps_identifier pr_id, caps_identifier job_id, int *fh, const char **parameter)
 
int pc_provider_job_state_set (struct caps_coordinator *database, unsigned property, caps_identifier pr_id, caps_identifier job_id, const struct object_state_job *state)
 
int pc_provider_printing_progression_report (struct caps_coordinator *database, unsigned property, caps_identifier pr_id, caps_identifier job_id, const struct object_progression_job *p)
 
caps_identifier pc_provider_job_drain (struct caps_coordinator *database, caps_identifier pr_id)
 
int pc_provider_job_finished (struct caps_coordinator *database, unsigned property, caps_identifier pr_id, caps_identifier job_id)
 
int pc_client_job_cancel (struct caps_coordinator *database, caps_identifier *pr_id, caps_identifier job_id)
 
int pc_client_job_state_get (struct caps_coordinator *database, caps_identifier job_id, const struct object_state_job **state)
 
int pc_client_job_progression_get (struct caps_coordinator *database, caps_identifier job_id, const struct object_progression_job **p)
 
int pc_client_printer_state_get (struct caps_coordinator *database, caps_identifier pr_id, const struct object_state_prn **state)
 
void pc_client_printer_list_get (struct caps_coordinator *database, caps_identifier **list, unsigned *cnt)
 
int pc_client_printer_info_get (struct caps_coordinator *database, caps_identifier pr_id, struct caps_printer_info *info)
 
caps_identifier pc_client_job_commit (struct caps_coordinator *database, caps_identifier pr_id, int fh, const char *params)
 
int pc_client_printer_ppd_get (struct caps_coordinator *database, caps_identifier pr_id)
 
void runtime_configuration_base_read_in (struct caps_inif_table *runtime_config)
 
void runtime_configuration_class_merge_in (struct caps_inif_table *runtime_config, enum caps_user_class clss)
 
void runtime_configuration_apply (struct caps_inif_table *runtime_config, enum caps_user_class clss, const char *package)
 
void runtime_configuration_apply_verbosity (const struct caps_inif_table *runtime_config)
 
static bool is_fd_valid (int fd)
 

Detailed Description

Author
Jürgen Borleis
Warning
Use as experimental

Macro Definition Documentation

◆ DSO_VISIBLE

#define DSO_VISIBLE

◆ ARRAY_SIZE

#define ARRAY_SIZE (   x)    (sizeof(x)/sizeof(x[0]))

◆ caps_invalidate_pointer

#define caps_invalidate_pointer (   pointer)

◆ caps_print_debug

#define caps_print_debug (   fmt,
  ... 
)

◆ _

#define _ (   string)    (string)

◆ NLS_

#define NLS_ (   string)    (string)

◆ CONFIG_TIMEOUT

#define CONFIG_TIMEOUT   30000

How long to wait for a CAPS printing coordinator answer via DBUS.

Some constraints:

  • this timeout must be long enough to wait as long as the startup of the coordinater takes due to dbus actvation
  • 100 ms is too short. This request will return with an error, when the coordinator isn't running already
  • 2 sec seems okay. Even if the system is under load. But this doesn't honors the system startup use case
  • other frameworks using 30 seconds - we will do as well

◆ CAPS_RUNTIME_CONFIG_LEVEL

#define CAPS_RUNTIME_CONFIG_LEVEL   "base"

Define the INI file 'level', all run-time related settings should be at

This value is important to have all read and merged settings at the expected 'level' to make retrieving these settings successful.

Function Documentation

◆ caps_init_runtime_data()

void caps_init_runtime_data ( struct caps_coordinator database)

◆ caps_exit_runtime_data()

void caps_exit_runtime_data ( struct caps_coordinator database)

Clean up all run-time information

Parameters
[in,out]databasePrinter/job database

◆ pc_provider_unique_printer_id_create()

caps_identifier pc_provider_unique_printer_id_create ( struct caps_coordinator database,
unsigned  property 
)

Create a printing provider instance with a unique identifier and add it to the list of active printers

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's unique property for identification
Returns
Unique identifier to refer this printing provider

This provider's property will be used in every later RPC to identify the printing provider. The property will be used to check if the request matches the printing provider. The provider's property can be based on "something", a connection information for example. This information must be constant over the lifetime of the printing provider.

A printing provider can create and control more than one printer. Thus, it is allowed for one provider to create as much printers as it wants (think about an IPP service).

◆ pc_provider_printer_id_free()

int pc_provider_printer_id_free ( struct caps_coordinator database,
unsigned  property,
caps_identifier  pr_id 
)

Free a printing provider description, e.g. remove it from the list of active printers

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's property
[in]pr_idIn use 'Printer ID' to be freed
Return values
0On success
-ENODEVpr_id is invalid (should not happen, maybe related to -EPERM)
-EPERMprovider and pr_id don't match

This function is triggered by the printing provider when it calls caps_pp_instance_unregister()

Note
If the printing provider doesn't call caps_pp_instance_unregister(), the printer is still listed here, but is orphaned. Refer for pc_provider_orphaned_printer_free() how to solve this issue.

◆ pc_provider_id_by_property_get()

caps_identifier pc_provider_id_by_property_get ( struct caps_coordinator database,
unsigned  property 
)

Get the unique printer ID based on its property

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's property
Return values
PositiveThe corresponding ID
CAPS_INVALID_IDENTIFIERIf the property has no printer anymore

◆ pc_provider_orphaned_printer_free()

void pc_provider_orphaned_printer_free ( struct caps_coordinator database,
unsigned  property 
)

Free all orphaned printers from a printing provider, e.g. remove them from the active printer list

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's property

If a printing provider doesn't call caps_pp_instance_unregister() when it terminates, we do not get this event in a regular manner, e.g. it will not free its ID. We need a different method to remove no longer existing providers. This method uses the property to check if this provider is still registered here and remove its printers on demand.

If this provider has already unregistered its ID in a regular manner, we will not find its property anymore and nothing else happens.

Since a printing provider can own more than one printer, this routine loops until all related printers are removed.

◆ pc_provider_printer_state_set()

int pc_provider_printer_state_set ( struct caps_coordinator database,
unsigned  property,
caps_identifier  pr_id,
const struct object_state_prn newstate 
)

Set a printer's new state

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's property
[in]pr_idIn use 'Printer ID' to get a job for
[in]newstateThe new state
Return values
0On success
positiveClients must be informed about this change
-EINVALstate invalid
-ENODEVpr_id is invalid (should not happen, maybe related to -EPERM)
-EPERMprovider and pr_id don't match

Called by the printing provider to define a new state for its printer.

The provider can change the printer's state to one of the visible states, but never back to LIBCAPS_PP_STATE_INVISIBLE.

The provider can change the printer's state to one of the tear down states, but never back to the visible states.

Note
A provider should never receive a -ENODEV. As long as it already has registered a printer and is connected to the printing provider its printer instance should be valid here.
Precondition
New state must be valid (e.g. complete)!

Clients must be informed about a change if:

  • the provider changes from invisible to visible state or vice versa
  • the provider changes to stopped, idle or processing state

◆ pc_provider_printer_info_set()

int pc_provider_printer_info_set ( struct caps_coordinator database,
unsigned  property,
caps_identifier  pr_id,
const char *  name,
const char *  info,
const char *  location,
const char *  vendor,
const char *  model,
struct caps_supported_mime_list list 
)

Setup the main printer information

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's property
[in]pr_idIn use 'Printer ID' to get a job for
[in]namePrinter name
[in]infoShort info about the printer
[in]locationLocation info about the printer
[in]vendorVendor name
[in]modelModel name
[in]listMIME type list
Return values
0On success
positiveClients must be informed about this change
-BUSYInformation already set
-ENODEVpr_id is invalid (should not happen, maybe related to -EPERM)
-EPERMprovider and pr_id don't match

Called by the printing provider to define the main information for its printer.

Note
Can be called once. There is no need to change the information or the mime types at the printer's lifetime

◆ pc_provider_ppd_set()

int pc_provider_ppd_set ( struct caps_coordinator database,
unsigned  property,
caps_identifier  pr_id,
int  fh 
)

Add a PPD file to the printing provider data

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's property
[in]pr_idThe 'Printer ID' to set its PPD
[in]fhThe PPD file handle
Return values
0On success
-ENODEVpr_id is invalid (should not happen, maybe related to -EPERM)
-EPERMprovider and pr_id don't match
-EINVALfh seems invalid

The content of the PPD file isn't transferred - only a filehandle of the PPD.

It's possible to set the PPD more than once. In this case the previous one will be closed. The libcapsprovider creates the PPD files as invisible temporary files. If the file close here is the last one the file gets removed from the filesystem.

◆ pc_provider_job_id_prepare()

caps_identifier pc_provider_job_id_prepare ( struct caps_coordinator database,
unsigned  property,
caps_identifier  pr_id 
)

Get the next available job identifier for the printing provider in question

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's property
[in]pr_idIn use 'Printer ID' to get a job for
Return values
PositiveJob ID
0No job available, e.g. queue empty
-ENODEVpr_id is invalid (should not happen, maybe related to -EPERM)
-EPERMprovider and pr_id don't match

Printer providers can poll for new jobs or wait for the new job broadcast signal.

Todo:
It seems a bad idea to unqueue a job in two steps, instead of one in an atomic manner. pc_provider_job_id_prepare() and pc_provider_job_get() races with pc_client_job_cancel()

◆ pc_provider_job_get()

int pc_provider_job_get ( struct caps_coordinator database,
unsigned  property,
caps_identifier  pr_id,
caps_identifier  job_id,
int *  fh,
const char **  parameter 
)

Get the filehandle and printing parameter of the corresponding job

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's property
[in]pr_idIn use 'Printer ID' to get a job for
[in]job_idThe job to report the printing progression for
[out]fhFile handle of the printing job data
[out]parameterWhere to store a pointer to the printing parameter
Return values
0On success (*fh and *parameter are valid)
-ENODEVPrinter is already gone (should not happen, maybe related to -EPERM)
-EPERMprovider and pr_id don't match
-EINVALjob_id seems invalid (maybe the print job is already gone)
-EIOJob not ready to print, call pc_provider_job_id_prepare() first
Note
Does not return in case of memory failure
Todo:
It seems a bad idea to unqueue a job in two steps, instead of one in an atomic manner. pc_provider_job_id_prepare() and pc_provider_job_get() races with pc_client_job_cancel()

◆ pc_provider_job_state_set()

int pc_provider_job_state_set ( struct caps_coordinator database,
unsigned  property,
caps_identifier  pr_id,
caps_identifier  job_id,
const struct object_state_job state 
)

Set a new state of a job

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's property
[in]pr_idIn use 'Printer ID' to get a job for
[in]job_idThe job to report it's finished
[in]stateThe new state the job is in
Return values
0On success
-ENODEVPrinter is already gone (should not happen, maybe related to -EPERM)
-EPERMprovider and pr_id don't match
-EINVALjob_id seems invalid or state ID is invalid

◆ pc_provider_printing_progression_report()

int pc_provider_printing_progression_report ( struct caps_coordinator database,
unsigned  property,
caps_identifier  pr_id,
caps_identifier  job_id,
const struct object_progression_job p 
)

Report the printing progression for a specified job

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's property
[in]pr_idIn use 'Printer ID' to get a job for
[in]job_idThe job to report the printing progression for
[in]pThe progression information
Return values
0On success, do not send a job change signal to clients
1On success, send a job change signal to clients
-ENODEVPrinter is already gone (should not happen, maybe related to -EPERM)
-EPERMprovider and pr_id don't match
-EINVALjob_id seems invalid

This information is provided by the printing provider and used by a client.

This function should be used by libcapsraster and should include the copies of a medium or document as well.

◆ pc_provider_job_drain()

caps_identifier pc_provider_job_drain ( struct caps_coordinator database,
caps_identifier  pr_id 
)

Remove next job from the printing provider's queue and destroy it

Parameters
[in,out]databasePrinter data base
[in]pr_idThe printing provider's identifier to add the job to
Return values
PositiveID of the drained job
CAPS_INVALID_IDENTIFIERNo job to drain in the printing provider's queue

Drain the queue one by one. This supports sending notification about each of it.

◆ pc_provider_job_finished()

int pc_provider_job_finished ( struct caps_coordinator database,
unsigned  property,
caps_identifier  pr_id,
caps_identifier  job_id 
)

Report the job is finished

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's property
[in]pr_idIn use 'Printer ID' to get a job for
[in]job_idThe job to report it's finished
Return values
0On success
-ENODEVPrinter is already gone (should not happen, maybe related to -EPERM)
-EPERMprovider and pr_id don't match
-EINVALjob_id seems invalid

Means the job will be removed from the printer's queue.

◆ pc_client_job_cancel()

int pc_client_job_cancel ( struct caps_coordinator database,
caps_identifier pr_id,
caps_identifier  job_id 
)

Cancel the given printing job

Parameters
[in,out]databasePrinter data base
[out]pr_idWhere to store the printing provider identifier (which belongs to the job_id)
[in]job_idThe printing job identifier to cancel
Return values
0Job removed from queue
positiveThe provider must remove it
-EINVALThere is no such job

Job's state LIBCAPS_PJ_STATE_QUEUED means it is still in the coordinators printing queue and thus, we can just remove the job from the queue. pc_provider_job_get() can deal with it. In this case, the interested clients must be notified about this change.

If a job is still in the coordinators printing queue it will be removed only. If the job is already in processing state by the printing provider the job's description is only changed to "CANCEL" and all interested instances must be informed about this change.

Postcondition
The caller must send out a job state change notifier!

◆ pc_client_job_state_get()

int pc_client_job_state_get ( struct caps_coordinator database,
caps_identifier  job_id,
const struct object_state_job **  state 
)

Get the job's current state it is in

Parameters
[in,out]databasePrinter data base
[in]job_idThe printing job identifier to get the state from
[out]stateWhere to store the job's state
Return values
0On success (*state is valid)
-ENOENTJob is already gone
Attention
state->message can be NULL

◆ pc_client_job_progression_get()

int pc_client_job_progression_get ( struct caps_coordinator database,
caps_identifier  job_id,
const struct object_progression_job **  p 
)

Get the job's current progression information

Parameters
[in,out]databasePrinter data base
[in]job_idThe printing job identifier to get the state from
[in]pWhere to store the pointer to the info
Return values
0On success (returned pointer is valid)
-ENOENTNo such job
-EAGAINNo progression yet, try again later

◆ pc_client_printer_state_get()

int pc_client_printer_state_get ( struct caps_coordinator database,
caps_identifier  pr_id,
const struct object_state_prn **  state 
)

Retrieve the current state from an active printer

Parameters
[in,out]databasePrinter/job data base
[in]pr_idThe printing provider's identifier
[out]stateWhere to store the state information
Return values
0On success (*state is valid)
-ENODEVPrinter is already gone

Since a client can never query for an invisible printer, we assume here, the state is already set by the provider.

◆ pc_client_printer_list_get()

void pc_client_printer_list_get ( struct caps_coordinator database,
caps_identifier **  list,
unsigned *  cnt 
)

Create a list of currently known printer IDs

Parameters
[in]databasePrinter/job data base
[out]listWhere to store the array of printer IDs
[out]cntElement count in list
Todo:
should be of type 'size_t'
Note
Does not return in case of memory failure

◆ pc_client_printer_info_get()

int pc_client_printer_info_get ( struct caps_coordinator database,
caps_identifier  pr_id,
struct caps_printer_info info 
)

Get the main printer info

Parameters
[in,out]databasePrinter/job data base
[in]pr_idThe printing provider's identifier
[out]infoWhere to store the information
Return values
0On success (*info is valid)
-ENODEVPrinter is already gone (*info is invalid)

Should always work, since a client can query for this information only if the printer is already visible. And it is visible only, if this information is already set by the provider.

Note
In case the printer is already gone, the content in *info is untouched!

◆ pc_client_job_commit()

caps_identifier pc_client_job_commit ( struct caps_coordinator database,
caps_identifier  pr_id,
int  fh,
const char *  params 
)

Add a job to the printer's queue

Parameters
[in,out]databasePrinter data base
[in]pr_idThe printing provider's identifier to add the job to
[in]fhFile handle of the job
[in]paramsPrinting parameter (can be NULL)
Return values
PositiveJob identifier
-ENODEVPrinter is already gone
-EPERMPrinter does not accept new print jobs
Note
Changes the processing state

◆ pc_client_printer_ppd_get()

int pc_client_printer_ppd_get ( struct caps_coordinator database,
caps_identifier  pr_id 
)

Returns a file descriptor of an individual copy of the PPD

Parameters
[in,out]databasePrinter/job data base
[in]pr_idThe printing provider's identifier
Return values
positiveFile descriptor to the PPD
-EAGAINPPD not available yet, try again later on (should not happen)
-ENODEVPrinter is already gone
-EPERMInsufficient permissions in the CAPS Document Storage Directory

◆ runtime_configuration_base_read_in()

void runtime_configuration_base_read_in ( struct caps_inif_table runtime_config)

Read-in the CAPS universe shared 'caps.ini' file for basic run-time configuration

Parameters
[out]runtime_configThe configuration table to fill

Expects the file in CAPS Configuration Directory (e.g. '/etc/caps/caps.ini' for example)

Precondition
The runtime_config must already be initialized and empty!
Note
Behaviour is documented in INI file set used by printer drivers

Read-in the CAPS universe shared 'caps.ini' file for basic run-time configuration

Parameters
[out]runtime_configThe configuration table to fill

Expects the file in CAPS Configuration Directory (e.g. '/etc/caps/caps.ini' for example)

Precondition
The runtime_config must already be initialized but empty!

◆ runtime_configuration_class_merge_in()

void runtime_configuration_class_merge_in ( struct caps_inif_table runtime_config,
enum caps_user_class  clss 
)

Merge-in the shared service dependend INI file for basic run-time configuration

Parameters
[out]runtime_configThe configuration table to merge more content to
[in]clssThe class of the running program (used to identify the corresponding service dependend INI file)

For clss refer layer for the corresponding service INI file.

Precondition
The runtime_config must already be initialized
Todo:

Currently the already collected configuration gets removed if it fails to merge the class INI content

The error message needs more details: Why/What/What now?

Note
Behaviour is documented in INI file set used by printer drivers

Merge-in the shared service dependend INI file for basic run-time configuration

Parameters
[out]runtime_configThe configuration table to merge more content to
[in]clssThe class of the running program (used to identify the corresponding service dependend INI file)

For clss refer layer for the corresponding service INI file.

Precondition
The runtime_config must already be initialized
Todo:

Currently the already collected configuration gets removed if it fails to merge the class INI content

The error message needs more details: Why/What/What now?

◆ runtime_configuration_apply()

void runtime_configuration_apply ( struct caps_inif_table runtime_config,
enum caps_user_class  clss,
const char *  package 
)

Read in a fixed sequence of INI files as a base run-time configuration

Parameters
[out]runtime_config
[in]clssApplication class (refer enum caps_user_class)
[in]packageUsed for the program's INI file (can be NULL)

This function is intended for the printing coordinator internal tools and printing providers via libcapsprovider (not clients).

Precondition
The runtime_config must already be initialized
Note
Feature is documented in CAPS universe verbosity setup via INI File

Read in a fixed sequence of INI files as a base run-time configuration

Parameters
[out]runtime_config
[in]clssApplication class (refer enum caps_user_class)
[in]packageUsed for the program's INI file (can be NULL)

This function is intended for the printing coordinator internal tools and printing providers via libcapsprovider (not clients).

Precondition
The runtime_config must already be initialized
Note
Feature is documented in CAPS universe verbosity setup via INI File

◆ runtime_configuration_apply_verbosity()

void runtime_configuration_apply_verbosity ( const struct caps_inif_table runtime_config)

Apply the verbosity setting if available

Parameters
[out]runtime_configThe configuration to check for the verbosity setting

This function is intended to be used whenever a run-time config is available. It is intended to apply the requested setting as early as possible.

The verbosity setting is always expected at

The new value from the INI file is only applied if it is higher than before. Else it gets ignored to give the application a change to overwrite it locally.

◆ is_fd_valid()

static bool is_fd_valid ( int  fd)
inlinestatic

Check if the given file descriptor is still valid

Parameters
[in]fdFile descriptor to check
Return values
trueFile descriptor is valid
falseFile descriptor is invalid
Attention
This check isn't reliable!
Todo:
If the driver was started from within the template service unit, fcntl() always returns a valid file descriptor, even if the printer is already gone.