CAPS Universe documentation  1.0.4
All you need to know to be successful
Data Structures | Functions | Variables
capsdoprint.c File Reference

A command line tool to print documents. More...

Data Structures

struct  doprint_info
 Collection of data to make capsdoprint work. More...
 

Functions

void sig_handler (int sig)
 
static int job_changed_notifier (void *data, caps_identifier pr_id, caps_identifier job_id, struct caps_cl_job_state *jstate, struct caps_job_progression *jprog)
 
static void job_state_print (const struct caps_cl_job_state *job_state)
 
static void job_progression_print (const struct caps_job_progression *job_prog)
 
static int job_keep_track (struct doprint_info *info)
 
static int get_first_available_printer (struct caps_cl_handle *instance, caps_identifier *id)
 
static int print_document_file (struct doprint_info *info, const char *printer_device, const char *params, int report, const char *doc)
 
static int print_document_stream (struct doprint_info *info, const char *printer_device, const char *params, int report, int fd)
 
static void handle_nls (void)
 
static void print_help (FILE *out)
 
int main (int argc, char *argv[])
 

Variables

static volatile sig_atomic_t quit = 0
 
static const char * capsdoprint_states []
 
static const struct caps_cl_notifier notifiers
 
static struct option long_options []
 

Detailed Description

Author
Jürgen Borleis
Warning
Use as experimental

Function Documentation

◆ sig_handler()

void sig_handler ( int  sig)

◆ job_changed_notifier()

static int job_changed_notifier ( void *  data,
caps_identifier  pr_id,
caps_identifier  job_id,
struct caps_cl_job_state jstate,
struct caps_job_progression jprog 
)
static

Called when a job changes its state or progression info at the printing coordinator

Parameters
[in]dataOur private data
[in]pr_idFor this printer a job's state has changed somehow
[in]job_idThis job's state has changed somehow
[in]jstateThe job's new state (if not NULL)
[in]jprogThe job's progression info (if not NULL)

Is called when the process is in a caps_cl_notifiers_process() call.

◆ job_state_print()

static void job_state_print ( const struct caps_cl_job_state job_state)
static

◆ job_progression_print()

static void job_progression_print ( const struct caps_job_progression job_prog)
static

◆ job_keep_track()

static int job_keep_track ( struct doprint_info info)
static

Keep track of the printing process

Parameters
[in]infoOur local info collection
Return values
EXIT_SUCCESSJob finished
EXIT_FAILUREJob finished, but failed somehow

This routine waits for job change notifications. Job change notifications are sent out:

  • the job moves from the CAPS Printing Coordinator to the Printing Provider
  • if some print progression was made
  • the job is finished
Precondition
Relies on the timout behaviour of caps_cl_notifiers_process()

◆ get_first_available_printer()

static int get_first_available_printer ( struct caps_cl_handle instance,
caps_identifier id 
)
static

Retrieve ID of first available printer

Parameters
[in]instanceThe library instance handle
[in]idPointer where to store the printer's ID
Return values
0On success (*id is valid),
-ENODEVNo printer found
negativeFailed to retrieve the printer list from the coordinator

◆ print_document_file()

static int print_document_file ( struct doprint_info info,
const char *  printer_device,
const char *  params,
int  report,
const char *  doc 
)
static

Print document from file

Parameters
[in]infoOur local info collection
[in]printer_deviceName of printing device (can be NULL if only one is known in the system)
[in]paramsPrinting parameters (IPP style, space separated list of key/value pairs, can be NULL)
[in]report'1' if the printing progress should be reported
[in]docThe name of the document file to print
Return values
EXIT_SUCCESSOn success
EXIT_FAILUREElse

◆ print_document_stream()

static int print_document_stream ( struct doprint_info info,
const char *  printer_device,
const char *  params,
int  report,
int  fd 
)
static

Print document from a file descriptor

Parameters
[in]infoOur local info collection
[in]printer_deviceName of printing device (can be NULL if only one is known in the system)
[in]paramsPrinting parameters (IPP style, space separated list of key/value pairs, can be NULL)
[in]report'1' if the printing progress should be reported
[in]fdThe document's file descriptor
Return values
EXIT_SUCCESSOn success
EXIT_FAILUREElse

◆ handle_nls()

static void handle_nls ( void  )
static

◆ print_help()

static void print_help ( FILE *  out)
static

◆ main()

int main ( int  argc,
char *  argv[] 
)

Variable Documentation

◆ quit

volatile sig_atomic_t quit = 0
static

◆ capsdoprint_states

const char* capsdoprint_states[]
static
Initial value:
= {
[LIBCAPS_PJ_STATE_RECEIVING] = NLS_("Receiving"),
[LIBCAPS_PJ_STATE_PROCESSING] = NLS_("Processing"),
[LIBCAPS_PJ_STATE_COMPLETED] = NLS_("Completed"),
}
@ LIBCAPS_PJ_STATE_UNKNOWN
Definition: libcapsppcommon.h:255
@ LIBCAPS_PJ_STATE_RECEIVING
Definition: libcapsppcommon.h:256
@ LIBCAPS_PJ_STATE_CANCELED
Definition: libcapsppcommon.h:261
@ LIBCAPS_PJ_STATE_COMPLETED
Definition: libcapsppcommon.h:263
@ LIBCAPS_PJ_STATE_QUEUED
Definition: libcapsppcommon.h:257
@ LIBCAPS_PJ_STATE_PREPARED
Definition: libcapsppcommon.h:258
@ LIBCAPS_PJ_STATE_PROCESSING_STOPPED
Definition: libcapsppcommon.h:260
@ LIBCAPS_PJ_STATE_ABORTED
Definition: libcapsppcommon.h:262
@ LIBCAPS_PJ_STATE_PROCESSING
Definition: libcapsppcommon.h:259
#define NLS_(string)
National Language Support related.
Definition: libcapsbase-local.h:61

Human translation of the binary job states

◆ notifiers

const struct caps_cl_notifier notifiers
static
Initial value:
= {
.provider_change = NULL,
.job_change = job_changed_notifier,
}
static int job_changed_notifier(void *data, caps_identifier pr_id, caps_identifier job_id, struct caps_cl_job_state *jstate, struct caps_job_progression *jprog)
Definition: capsdoprint.c:69

◆ long_options

struct option long_options[]
static
Initial value:
= {
{ .name = "device", .has_arg = required_argument, .val = 'd', },
{ .name = "params", .has_arg = required_argument, .val = 'p', },
{ .name = "report", .has_arg = no_argument, .val = 'r', },
{ .name = "verbose", .has_arg = no_argument, .val = 'v', },
{ .name = "help", .has_arg = no_argument, .val = 'h', },
{ .name = "version", .has_arg = no_argument, .val = 19, },
{ .name = NULL, },
}

This parser uses a free argument: the file name. This isn't currently supported by the capscmdparser. Thus, we stay with getopt_long() for now.