CAPS Universe documentation  1.0.4
All you need to know to be successful
Macros | Functions
management-printers-and-jobs.c File Reference

Printer and print job management routines. More...

Macros

#define PROGRESSION_TIMEOUT   2
 

Functions

static void database_lock (struct caps_coordinator *database)
 
static void database_unlock (struct caps_coordinator *database)
 
static void job_state_set (struct object_state_job *state, int state_id, int reason_id, const char *message)
 
static void job_mark_in_incoming_state (struct caps_job *job)
 
static void job_mark_in_queued_state (struct caps_job *job)
 
static void job_mark_in_prepared_state (struct caps_job *job)
 
static bool job_is_valid (const struct caps_job *job)
 
static bool job_is_ready_for_printing (const struct caps_job *job)
 
static bool job_is_prepared (const struct caps_job *job)
 
static void job_destroy (struct caps_job *job)
 
static void job_remove (struct caps_printer *printer, struct caps_job *job)
 
static struct caps_jobjob_get_by_id (const struct caps_printer *printer, caps_identifier job_id)
 
static struct caps_jobjob_find_in_queues (const struct caps_coordinator *database, caps_identifier *pr_id, caps_identifier job_id)
 
static caps_identifier _random_id_create (void)
 
static caps_identifier job_unique_id_create (struct caps_coordinator *database)
 
static void job_init (struct caps_job *job)
 
static struct caps_jobjob_create (void)
 
static void printer_init (struct caps_printer *printer)
 
static struct caps_printerprinter_create_new (void)
 
static void printer_mime_types_clean (struct caps_printer *printer)
 
static void printer_destroy (struct caps_printer *printer)
 
static void printer_remove (struct caps_coordinator *database, struct caps_printer *printer)
 
static struct caps_printerprinter_get_by_id (struct caps_coordinator *database, caps_identifier pr_id)
 
static struct caps_printerprinter_get_by_property (struct caps_coordinator *database, unsigned property)
 
caps_identifier pc_provider_id_by_property_get (struct caps_coordinator *database, unsigned property)
 
static caps_identifier printer_create_unique_id (struct caps_coordinator *database)
 
caps_identifier pc_provider_unique_printer_id_create (struct caps_coordinator *database, unsigned property)
 
static bool permission_check (struct caps_printer *printer, unsigned property)
 
int pc_provider_printer_id_free (struct caps_coordinator *database, unsigned property, caps_identifier pr_id)
 
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 *newstate)
 
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)
 
static struct caps_jobprinter_job_get_next_available (const struct caps_printer *printer)
 
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_ppd_set (struct caps_coordinator *database, unsigned property, caps_identifier pr_id, int fh)
 
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)
 
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_job_finished (struct caps_coordinator *database, unsigned property, caps_identifier pr_id, caps_identifier job_id)
 
caps_identifier pc_provider_job_drain (struct caps_coordinator *database, caps_identifier pr_id)
 
caps_identifier pc_client_job_commit (struct caps_coordinator *database, caps_identifier pr_id, int fh, const char *params)
 
static bool pc_provider_entry_active (struct caps_printer *printer)
 
void pc_client_printer_list_get (struct caps_coordinator *database, caps_identifier **list, unsigned *cnt)
 
int pc_client_printer_state_get (struct caps_coordinator *database, caps_identifier pr_id, const struct object_state_prn **state)
 
int pc_client_printer_info_get (struct caps_coordinator *database, caps_identifier pr_id, struct caps_printer_info *info)
 
static int return_duplicated_file (int fd)
 
int pc_client_printer_ppd_get (struct caps_coordinator *database, caps_identifier pr_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_job_cancel (struct caps_coordinator *database, caps_identifier *pr_id, caps_identifier job_id)
 
void caps_init_runtime_data (struct caps_coordinator *database)
 
void caps_exit_runtime_data (struct caps_coordinator *database)
 

Detailed Description

Author
Jürgen Borleis
Warning
Use as experimental

These functions are used by the printing coordinator to handle the printers. All printing provider and printing client calls are ending here.

Macro Definition Documentation

◆ PROGRESSION_TIMEOUT

#define PROGRESSION_TIMEOUT   2

How much time in seconds must be elapsed since the last report to generate the next job change signal on the DBUS Used in pc_provider_printing_progression_report() to reduce the noise on the DBUS.

Function Documentation

◆ database_lock()

static void database_lock ( struct caps_coordinator database)
static

Lock the printer/job database for an atomic operation

Parameters
[in,out]databasePrinter/job data base

◆ database_unlock()

static void database_unlock ( struct caps_coordinator database)
static

Unlock the printer/job database

Parameters
[in,out]databasePrinter/job data base

◆ job_state_set()

static void job_state_set ( struct object_state_job state,
int  state_id,
int  reason_id,
const char *  message 
)
static

Setup a new state for a job

Parameters
[in,out]stateThe job's state to setup
[in]state_idJob's new state ID
[in]reason_idJob's new reason ID
[in]messageAn optional message for this state or reason (can be NULL)
Note
'No message' is handled in the same way like an empty message, e.g. object_state_job::message is NULL
Each call will free the previous message

◆ job_mark_in_incoming_state()

static void job_mark_in_incoming_state ( struct caps_job job)
static

Mark a job to reflect it is in "incoming" state

Parameters
[in,out]jobThe job to change its state

"Incoming" means the job ID is committed to the client, and now we wait for the corresponding job's data

◆ job_mark_in_queued_state()

static void job_mark_in_queued_state ( struct caps_job job)
static

Mark a job to reflect it is in "queued" state

Parameters
[in,out]jobThe job to change its state

"Queued" means, the coordinator has received the job and put it into the printing provider's queue. The printing job is now ready for printing.

◆ job_mark_in_prepared_state()

static void job_mark_in_prepared_state ( struct caps_job job)
static

Mark a job to reflect it is in "unqueued" state

Parameters
[in,out]jobThe job to change its state

"Prepared" means, the printing provider has retrieved the job's identifier and now the retrieve of the job data (e.g. its filehandle) itself is awaiting in the next step.

◆ job_is_valid()

static bool job_is_valid ( const struct caps_job job)
static

Check if a job description entry is valid

Parameters
[in]jobJob to check
Return values
trueIf job description is valid
falseIf the job description is invalid

"Valid" means: description is not in initialized state anymore

Note
A missing filehandle entry just means the job is already prepared and/or processed

◆ job_is_ready_for_printing()

static bool job_is_ready_for_printing ( const struct caps_job job)
static

Check if a job is ready for printing

Parameters
[in]jobJob to check
Returns
true if valid, false else

A ready for printing job entry is:

Keep the processing_state test in sync with job_mark_in_queued_state()

◆ job_is_prepared()

static bool job_is_prepared ( const struct caps_job job)
static

Check if a job is prepared for printing

Parameters
[in]jobJob to check
Return values
trueIf prepared
falseNot yet prepared

A prepared job entry is:

"Prepared" means: the printing provider has already retrieved the job's identifier, but not yet retrieved the printing data filehandle. Keep the processing_state test in sync with job_mark_in_prepared_state()

◆ job_destroy()

static void job_destroy ( struct caps_job job)
static

Free all resources used by a job description

Parameters
[in,out]jobThe job to free

This will remove everything entirely. If the job related file descriptor is of type "self removing", this will remove the document file as well.

◆ job_remove()

static void job_remove ( struct caps_printer printer,
struct caps_job job 
)
static

Remove a job from a printer's queue

Parameters
[in]printerThe printer to remove the job from
[in,out]jobThe job to free
Precondition
Since it changes settings in a printer object, it might need to held lock
The job's state must already be one of the finished states (e.g. LIBCAPS_PJ_STATE_CANCELED, LIBCAPS_PJ_STATE_ABORTED or LIBCAPS_PJ_STATE_COMPLETED)

◆ job_get_by_id()

static struct caps_job * job_get_by_id ( const struct caps_printer printer,
caps_identifier  job_id 
)
static

Get a specific job from a printing provider's queue

Parameters
[in]printerThe printer to query the next job
[in]job_idJob identifier to find
Return values
PointerThe Job
NULLIn case there is none
Precondition
Depending on the use, it might need to held lock

◆ job_find_in_queues()

static struct caps_job * job_find_in_queues ( const struct caps_coordinator database,
caps_identifier pr_id,
caps_identifier  job_id 
)
static

Get a job based on its identifier and get its corresponding printing provider identifier as well

Parameters
[in,out]databasePrinter data base
[out]pr_idPrinting provider's identifier store
[in]job_idJob identifier to find
Return values
PointerJob on success (and *pr_id is valid)
NULLIf the job wasn't found (and *pr_id isn't touched) or if no printers are found (and *pr_id is CAPS_INVALID_IDENTIFIER)
Precondition
Depending on the use, it might need to held lock

◆ _random_id_create()

static caps_identifier _random_id_create ( void  )
static

Create a positive 64 bit number for a printer or job ID

Returns
A more or less random 64 bit positive integer (e.g. bit 63 always 0)
Note
This function expects caps_identifier is a signed 64 bit number

◆ job_unique_id_create()

static caps_identifier job_unique_id_create ( struct caps_coordinator database)
static

Create a unique identifier for a job

Parameters
[in,out]databasePrinter data base
Returns
Unique job ID

The generated job ID is unique for all currently known jobs and for the past jobs as well.

◆ job_init()

static void job_init ( struct caps_job job)
static

Init a job description structure

Parameters
[in,out]jobWhat to initialize

◆ job_create()

static struct caps_job * job_create ( void  )
static

Create a new job description structure

Returns
Pointer to a new job description
Note
does not return in case of memory failure

◆ printer_init()

static void printer_init ( struct caps_printer printer)
static

Init a printer description structure

Parameters
[in,out]printerWhat to initialize

The printer is initialized to:

  • unknown state (not invisible)
  • no valid identifier yet
  • empty information
  • empty job queue
  • no PPD yet

◆ printer_create_new()

static struct caps_printer * printer_create_new ( void  )
static

Allocate a new printer structure

Returns
Pointer to initialized printer description

The new printer gets initialized via printer_init()

◆ printer_mime_types_clean()

static void printer_mime_types_clean ( struct caps_printer printer)
static

Free printer's MIME type information

Parameters
[in,out]printerThe printer to clean its MIME type info
Todo:

Same features like free_mime_types() in libcapsprovider.c

A copy function for the MIME types can be found in copy_mime_types() in libcapsprovider as well.

◆ printer_destroy()

static void printer_destroy ( struct caps_printer printer)
static

Destroy a printer information collection, e.g. free all resources

Parameters
[in]printerThe printer structure to free
Precondition
The related job queue is expected as already empty

◆ printer_remove()

static void printer_remove ( struct caps_coordinator database,
struct caps_printer printer 
)
static

Remove this printer from the list of active printers

Parameters
[in,out]databasePrinter data base
[in,out]printerThe printer structure to remove/destroy
Precondition
Must be called with the lock held.
The job queue must be already drained

◆ printer_get_by_id()

static struct caps_printer * printer_get_by_id ( struct caps_coordinator database,
caps_identifier  pr_id 
)
static

Get an active printer description based on its identifier

Parameters
[in,out]databasePrinter data base
[in]pr_idPrinter Identifier to search for
Return values
PointerA printer description
NULLIn case the identifier does not exist
Note
Even if the pr_id is valid, a NULL can be returned, if the provider is gone in the meanwhile
Precondition
Must be called with the lock held.

◆ printer_get_by_property()

static struct caps_printer * printer_get_by_property ( struct caps_coordinator database,
unsigned  property 
)
static

Get an active printer description based on its property

Parameters
[in,out]databasePrinter data base
[in]propertyProvider's property
Return values
PointerA printer description
NULLIn case the property doesn't exist
Precondition
Must be called with the lock held.

◆ 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

◆ printer_create_unique_id()

static caps_identifier printer_create_unique_id ( struct caps_coordinator database)
static

Create a numerical unique identifier for a printing provider

Parameters
[in,out]databasePrinter data base
Returns
A unique identifier

The generated printer ID is unique for all currently active printers.

◆ 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).

◆ permission_check()

static bool permission_check ( struct caps_printer printer,
unsigned  property 
)
static

Check if the requesting provider has access permissions

Parameters
[in]printerPrinting provider's description
[in]propertyProvider's property to check for
Return values
trueIf the provider has permission
falseIf the provider has no permission

◆ 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_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

◆ printer_job_get_next_available()

static struct caps_job * printer_job_get_next_available ( const struct caps_printer printer)
static

Get the next available job waiting for print from the printer's queue

Parameters
[in]printerThe printer to unqueue the next job
Return values
PointerThe Job
NULLIn case there is none

"Available" means the job is ready, but its ID is not yet committed to the printing provider.

Todo:

ensure the order of processing (first come, first serve)

Check here, if a different job is still in printing state. This would be a failure.

Precondition
Must be called with the lock held

◆ 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_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_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_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_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_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_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_provider_entry_active()

static bool pc_provider_entry_active ( struct caps_printer printer)
static

Check if this printing provider entry is active

Parameters
[in]printerThe entry to check
Return values
trueif entry is still active
falseelse

active means, the entry is in use and the printer is visible to the public

◆ 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_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_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!

◆ return_duplicated_file()

static int return_duplicated_file ( int  fd)
static

Duplicate a file and its content

Parameters
[in]fdFile descriptor to read from
Return values
positiveFile descriptor with duplicated content
negativeerrno on failure

Since the PPD file descriptor stored here is a shared resource, we need to forward a copy of it instead. Else its racy like hell if a concurrent access happens at the client level.

Note
Does not return in case of memory failure

◆ 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

◆ 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_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!

◆ 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