wml::CupsCtrl Class Reference

#include <CupsCtrl.h>

List of all members.

Public Member Functions

 CupsCtrl (std::string addr, int port=0)
void initialise (void)
void setCupsdAddress (std::string s)
std::string getCupsdAddress (void)
bool getAccepting (std::string cupsPrinter)
void setAccepting (std::string cupsPrinter, bool accept, std::string directory="/printers/%s")
bool getEnabled (std::string cupsPrinter)
void setEnabled (std::string cupsPrinter, bool enable, std::string directory="/printers/%s")
bool getShared (std::string cupsPrinter)
void setShared (std::string cupsPrinter, bool enable, std::string directory="/printers/%s")
bool printerExists (std::string cupsPrinter)
std::string getState (std::string cupsPrinter)
std::string getStateMsg (std::string cupsPrinter)
std::string getStateReasons (std::string cupsPrinter)
bool getFullStatus (std::string cupsPrinter, wml::QueueCupsStatus &qstat)
void getJobList (std::string cupsPrinter, std::vector< wml::CupsJob > &jList, std::string whichJobs="")
void getJobList (std::string cupsPrinter, std::vector< wml::CupsJob > &jList, int numJobs=0, std::string whichJobs="")
void getJobStatus (std::string cupsPrinter, int id, wml::CupsJob &j)
wml::CupsJob getJob (std::string id)
std::string getInfo (std::string cupsPrinter)
void setInfo (std::string cupsPrinter, std::string s)
void setClassInfo (std::string cupsPrinter, std::string s)
std::string getLocation (std::string cupsPrinter)
void setLocation (std::string cupsPrinter, std::string s)
void setClassLocation (std::string cupsClass, std::string s)
std::string getMakeModel (std::string cupsPrinter)
void setMakeModel (std::string cupsPrinter, std::string s)
std::string getDeviceURI (std::string cupsPrinter)
std::vector< std::string > getMemberUris (std::string cupsPrinter)
void setDeviceURI (std::string cupsPrinter, std::string s)
void setPPD (std::string cupsPrinter, std::string ppdTag)
void getPPDToFile (std::string cupsPrinter, std::string file)
wml::Ppd getPPD (std::string cupsPrinter)
void setPPDFromFile (std::string cupsPrinter, std::string sourcePPDFile)
std::string getPPDNickname (std::string cupsPrinter)
std::vector< std::string > getPPDListOfMakes (void)
std::vector< wml::PpdgetPPDListOfModels (std::string make)
std::vector< wml::PpdOptiongetPPDOptions (std::string cupsPrinter)
void setPPDOption (std::string cupsPrinter, std::string keyword, std::string value)
void addPrinter (std::string cupsPrinter, std::string devURI)
void addPrinter (std::string cupsPrinter, std::string s, std::string sourcePPD)
void deletePrinter (std::string cupsPrinter)
std::string getCupsURI (std::string cupsPrinter)
std::vector< std::string > getCupsPrinterList (wml::GET_PRINTERS getPrinters)
std::vector< std::string > getPrinterClassesList (void)
std::vector< std::string > getPrinterList (void)
std::vector< std::string > getClassesList (void)
wml::QTYPE getQueueType (std::string queuename)
int createJob (std::string cupsQueue, std::string title="", std::string asUser="", std::string docName="", int numOptions=0, cups_option_t *options=(cups_option_t *) 0)
void holdJob (int jobId, std::string asUser)
void releaseJob (int jobId, std::string asUser)
void cancelJob (int jobId, std::string asUser)
void restartJob (int jobId, std::string asUser)
void moveJob (int jobId, std::string asUser, std::string destQueue)
void sendDocument (int jobId, std::string filePath, std::string asUser, std::string docName="", std::string format="", bool lastInSet=true)
int printFile (std::string filePath, std::string jobTitle, std::string cupsQueue)
std::list< std::string > getCupsPrinterList2 (void)
std::string getPrinterAttribute (const char *printerName, wml::IppAttr &attr)
std::vector< std::string > getQueueAttribute (const char *printerName, wml::IppAttr &attr)
void setPrinterAttribute (const char *printerName, wml::IppAttr &attr)
void setPrinterAttributes (const char *printerName, wml::IppAttr &attr1, wml::IppAttr &attr2)
void setClassAttribute (const char *printerName, wml::IppAttr &attr)
void setClassMembers (std::string className, std::vector< std::string > members)
void sendPrinterCommand (const char *printerName, std::string asUser, std::string reason, ipp_op_t command, std::string directory="/printers/%s")
std::string errorString (ipp_status_t err)
std::string errorString (http_status_t err)
void sendJobCommand (int jobId, std::string asUser, ipp_op_t command)
void cancelJobs (std::string printerName)
void pauseJobs (std::string printerName)
void releaseJobs (std::string printerName)

Static Public Member Functions

static bool printerNameIsValid (std::string s)
static bool addrIsValid (std::string s)
static bool lpdqIsValid (std::string s)
static bool portIsValid (std::string s)
static bool titleIsValid (std::string s)


Detailed Description

A C++ wrapper around the CUPS API, with functions to get status information from and send commands to the cupsd.

Intended always to be run in try/catch, as CUPS errors are passed back as exceptions. (Or at least that was the initial plan).

Definition at line 90 of file CupsCtrl.h.


Member Function Documentation

void wml::CupsCtrl::addPrinter ( std::string  cupsPrinter,
std::string  s,
std::string  sourcePPD 
)

add printer, with device URI, and at the same time, set the PPD file.

void wml::CupsCtrl::addPrinter ( std::string  cupsPrinter,
std::string  devURI 
)

This checks that the printer doesn't exist, then calls setDeviceURI() to create it.

static bool wml::CupsCtrl::addrIsValid ( std::string  s  )  [static]

Return true if the string s is a name which is valid to be a CUPS device address.

void wml::CupsCtrl::cancelJob ( int  jobId,
std::string  asUser 
)

As the user asUser, this IPP_CANCEL_JOBs jobId

void wml::CupsCtrl::cancelJobs ( std::string  printerName  ) 

Cancels all jobs on the queue with the given printer name

int wml::CupsCtrl::createJob ( std::string  cupsQueue,
std::string  title = "",
std::string  asUser = "",
std::string  docName = "",
int  numOptions = 0,
cups_option_t *  options = (cups_option_t *) 0 
)

Request that a job is created on the cupsd. Return the job id.

void wml::CupsCtrl::deletePrinter ( std::string  cupsPrinter  ) 

Delete the printer.

std::string wml::CupsCtrl::errorString ( http_status_t  err  ) 

Gets the string equivalent of the http_status_t status/error.

std::string wml::CupsCtrl::errorString ( ipp_status_t  err  ) 

Same effect as cupsLastErrorString(), except that cupsLastErrorString doesn't seem to work.

bool wml::CupsCtrl::getAccepting ( std::string  cupsPrinter  ) 

Query cupsd for whether the given cupsPrinter is accepting

std::vector<std::string> wml::CupsCtrl::getClassesList ( void   ) 

Wrapper around getCupsPrinterList. Returns a vector containing only classes

std::string wml::CupsCtrl::getCupsdAddress ( void   ) 

Get the cupsd address

std::vector<std::string> wml::CupsCtrl::getCupsPrinterList ( wml::GET_PRINTERS  getPrinters  ) 

Get a list of printer on the cupsd. Return as vector.

std::list<std::string> wml::CupsCtrl::getCupsPrinterList2 ( void   ) 

Like getCupsPrinterList but returns a list rather than a vector.

std::string wml::CupsCtrl::getCupsURI ( std::string  cupsPrinter  ) 

Return the "cups" URI for the queue. Something like: ipp://circle.wml:631/printers/hp3005

std::string wml::CupsCtrl::getDeviceURI ( std::string  cupsPrinter  ) 

Return the printer destination URI. Something like: socket://hp3005.wml:9100

bool wml::CupsCtrl::getEnabled ( std::string  cupsPrinter  ) 

Query cupsd for whether the given cupsPrinter is enabled

bool wml::CupsCtrl::getFullStatus ( std::string  cupsPrinter,
wml::QueueCupsStatus qstat 
)

Get all status info for the queue cupsPrinter in the minimum number of cupsd connections, storing the results in qstat. Return true if the printer was found and status was set, false otherwise.

std::string wml::CupsCtrl::getInfo ( std::string  cupsPrinter  ) 

Return a string (in English) of the printer info.

wml::CupsJob wml::CupsCtrl::getJob ( std::string  id  ) 

Retrieves the job with the given id from the cups daemon and returns a CupsJob representation of that job

void wml::CupsCtrl::getJobList ( std::string  cupsPrinter,
std::vector< wml::CupsJob > &  jList,
int  numJobs = 0,
std::string  whichJobs = "" 
)

Get a list of the jobs for the printer cupsPrinter. Can pass in whichJobs as "all" or "completed" to show all jobs or only completed jobs. If whichJobs is left empty, only currently processing jobs are listed. Fills jList with up to numJobs jobs from the cupsd, most recent first. If numJobs is 0, then there is no limit on the number of jobs returned in jList.

This should be faster if you only want to get the information of the last one (or few) jobs.

void wml::CupsCtrl::getJobList ( std::string  cupsPrinter,
std::vector< wml::CupsJob > &  jList,
std::string  whichJobs = "" 
)

Get a list of the jobs for the printer cupsPrinter. Can pass in whichJobs as "all" or "completed" to show all jobs or only completed jobs. If whichJobs is left empty, only currently processing jobs are listed.

void wml::CupsCtrl::getJobStatus ( std::string  cupsPrinter,
int  id,
wml::CupsJob j 
)

Get the Job information for the given Job ID, placing it in CupsJob j. If id == 0, then get the job information for the last job processed or in-process.

std::string wml::CupsCtrl::getLocation ( std::string  cupsPrinter  ) 

Return a string (in English) of the printer location.

std::string wml::CupsCtrl::getMakeModel ( std::string  cupsPrinter  ) 

Return a string (in English) of the printer make and model (i.e. the PPD "make and model").

std::vector<std::string> wml::CupsCtrl::getMemberUris ( std::string  cupsPrinter  ) 

Similar to getDeviceURI, but returns a vector of URIs. Useful for getting the members of a class

wml::Ppd wml::CupsCtrl::getPPD ( std::string  cupsPrinter  ) 

Return a PPD object containing some PPD info for the given cupsPrinter. Does not return the ppd-name, which is generated internally in the cupsd, and which is not returned by this method.

std::vector<std::string> wml::CupsCtrl::getPPDListOfMakes ( void   ) 

Obtain a list of the printer "makes" for which there are available PPD files stored on the system. This makes a CUPS_GET_PPDS IPP request to the cupsd to get the information.

std::vector<wml::Ppd> wml::CupsCtrl::getPPDListOfModels ( std::string  make  ) 

Get the list of PPD drivers (models) for the given make. This makes a CUPS_GET_PPDS IPP request to the cupsd to get the information.

std::string wml::CupsCtrl::getPPDNickname ( std::string  cupsPrinter  ) 

Get the PPD file stored in ppd-name on the cupsd for this queue and then obtain its nickname.

std::vector<wml::PpdOption> wml::CupsCtrl::getPPDOptions ( std::string  cupsPrinter  ) 

Obtain the PPD options for the given printer.

void wml::CupsCtrl::getPPDToFile ( std::string  cupsPrinter,
std::string  file 
)

Get the PPD for the queue cupsPrinter to the given file.

std::string wml::CupsCtrl::getPrinterAttribute ( const char *  printerName,
wml::IppAttr attr 
)

Get the value of the attribute attr for the printer printerName. attr should have been configured with name before being passed to this function.

attr has its value set, and when done, attr.getString() is returned by this function.

std::vector<std::string> wml::CupsCtrl::getPrinterClassesList ( void   ) 

Wrapper around getCupsPrinterList. Returns a vector containing all classes and printers

std::vector<std::string> wml::CupsCtrl::getPrinterList ( void   ) 

Wrapper around getCupsPrinterList. Returns a vector containing only printers

std::vector<std::string> wml::CupsCtrl::getQueueAttribute ( const char *  printerName,
wml::IppAttr attr 
)

Similar to getPrinterAttribute, but returns a vector of strings, instead of a single string. Useful when an attribute contains more than one value, such as the member-uris attribute of a class.

wml::QTYPE wml::CupsCtrl::getQueueType ( std::string  queuename  ) 

Determines whether the queue is a printer or a class and returns the result as a string.

bool wml::CupsCtrl::getShared ( std::string  cupsPrinter  ) 

Query cupsd for whether the given cupsPrinter is shared

std::string wml::CupsCtrl::getState ( std::string  cupsPrinter  ) 

Return a string (in English) of the printer state.

std::string wml::CupsCtrl::getStateMsg ( std::string  cupsPrinter  ) 

Return a string (in English) of the printer state message, which is not the same as the printer state.

void wml::CupsCtrl::holdJob ( int  jobId,
std::string  asUser 
)

As the user asUser, this IPP_HOLD_JOBs jobId

void wml::CupsCtrl::initialise ( void   ) 

After setting address, this makes a connection to the cupsd.

static bool wml::CupsCtrl::lpdqIsValid ( std::string  s  )  [static]

Return true if the string s is a name which is valid to be a destination queue.

void wml::CupsCtrl::moveJob ( int  jobId,
std::string  asUser,
std::string  destQueue 
)

As the user asUser, move the job jobId to the queue destQueue.

void wml::CupsCtrl::pauseJobs ( std::string  printerName  ) 

Pauses all jobs on the queue with the given printer name

static bool wml::CupsCtrl::portIsValid ( std::string  s  )  [static]

Return true if the string s is a name which is valid to be a CUPS port.

bool wml::CupsCtrl::printerExists ( std::string  cupsPrinter  ) 

Is there a printer with the given name set up on the cupsd?

static bool wml::CupsCtrl::printerNameIsValid ( std::string  s  )  [static]

Return true if the string s is a name which is valid to be a CUPS printer name.

int wml::CupsCtrl::printFile ( std::string  filePath,
std::string  jobTitle,
std::string  cupsQueue 
)

Print the file at filePath to the CUPS queue cupsQueue. Throw exceptions if the file does not exist, or if the cupsd refuses to print it. Return the job id.

void wml::CupsCtrl::releaseJob ( int  jobId,
std::string  asUser 
)

As the user asUser, this IPP_RELEASE_JOBs jobId

void wml::CupsCtrl::releaseJobs ( std::string  printerName  ) 

Resumes all jobs on the queue with the given printer name

void wml::CupsCtrl::restartJob ( int  jobId,
std::string  asUser 
)

As the user asUser, this IPP_RESTART_JOBs jobId

void wml::CupsCtrl::sendDocument ( int  jobId,
std::string  filePath,
std::string  asUser,
std::string  docName = "",
std::string  format = "",
bool  lastInSet = true 
)

Send a file specified by filePath to the cupsd, adding it to the job with id jobId. Optionally set the document name and the format string. If lastInSet is false, the doc will not be printed immediately.

void wml::CupsCtrl::sendJobCommand ( int  jobId,
std::string  asUser,
ipp_op_t  command 
)

General function for sending job commands (such as cancel, etc) to the Cups daemon, to be applied to the job with the id provided

void wml::CupsCtrl::sendPrinterCommand ( const char *  printerName,
std::string  asUser,
std::string  reason,
ipp_op_t  command,
std::string  directory = "/printers/%s" 
)

Send a command for the queue, such as CUPS_ACCEPT_JOBS, CUPS_REJECT_JOBS, IPP_PAUSE_PRINTER or IPP_RESUME_PRINTER.

void wml::CupsCtrl::setAccepting ( std::string  cupsPrinter,
bool  accept,
std::string  directory = "/printers/%s" 
)

Enable printer cupsPrinter if enable is true, disable it otherwise.

void wml::CupsCtrl::setClassAttribute ( const char *  printerName,
wml::IppAttr attr 
)

Same as setPrinterAttribute, but used for classes rather than printers.

void wml::CupsCtrl::setClassInfo ( std::string  cupsPrinter,
std::string  s 
)

Same as above, but works for a class rather than a printer

void wml::CupsCtrl::setClassLocation ( std::string  cupsClass,
std::string  s 
)

Same as above, but works for a class rather than a printer

void wml::CupsCtrl::setClassMembers ( std::string  className,
std::vector< std::string >  members 
)

Sets up the members of a class. The vector members contains the names of the members to be added to the class

void wml::CupsCtrl::setCupsdAddress ( std::string  s  ) 

Sets the cupsd address.

void wml::CupsCtrl::setDeviceURI ( std::string  cupsPrinter,
std::string  s 
)

Set the printer destination URI to s. This is the "create a cups printer" command - if the printer doesn't exist a new one is added with the given device uri.

void wml::CupsCtrl::setEnabled ( std::string  cupsPrinter,
bool  enable,
std::string  directory = "/printers/%s" 
)

Enable printer cupsPrinter if enable is true, disable it otherwise.

void wml::CupsCtrl::setInfo ( std::string  cupsPrinter,
std::string  s 
)

Set the info Cups parameter to s.

void wml::CupsCtrl::setLocation ( std::string  cupsPrinter,
std::string  s 
)

Set the location Cups parameter to s.

void wml::CupsCtrl::setMakeModel ( std::string  cupsPrinter,
std::string  s 
)

Set the make and model string

void wml::CupsCtrl::setPPD ( std::string  cupsPrinter,
std::string  ppdTag 
)

Set the PPD for the given cupsPrinter. ppdTag is the identifier for the PPD, which must be available on the cupsd system.

void wml::CupsCtrl::setPPDFromFile ( std::string  cupsPrinter,
std::string  sourcePPDFile 
)

Set the provided PPD file for the given cupsPrinter.

void wml::CupsCtrl::setPPDOption ( std::string  cupsPrinter,
std::string  keyword,
std::string  value 
)

Set the PPD option identified by keyword to value.

void wml::CupsCtrl::setPrinterAttribute ( const char *  printerName,
wml::IppAttr attr 
)

Set an IPP attribute for printerName. attr should have been set up with the attribute name and the attribute value.

void wml::CupsCtrl::setPrinterAttributes ( const char *  printerName,
wml::IppAttr attr1,
wml::IppAttr attr2 
)

Set two IPP attributes for printerName. attrs should have been set up with the attribute name and the attribute value.

void wml::CupsCtrl::setShared ( std::string  cupsPrinter,
bool  enable,
std::string  directory = "/printers/%s" 
)

Enable sharing for printer cupsPrinter if enable is true, disable sharing otherwise.

static bool wml::CupsCtrl::titleIsValid ( std::string  s  )  [static]

Return true if the string s is a valid to be a CUPS job title.


The documentation for this class was generated from the following file:

Generated on Wed Apr 6 11:14:38 2011 for wmlcups by  doxygen 1.5.9