Implementation of Windows Print management on Linux

Source: Internet
Author: User
Article Title: Windows Print management is implemented on the Linux platform. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
This article introduces a porting method and implementation details for Windows Printer management on the Linux platform. Through this article, you can understand the relevant technologies and apply these technologies directly to actual software development.

1. Understand Windows Printer management and Linux printer Management

Windows provides a simple and complete printer management system. In Windows programming, the print function is integrated into the Graphic Device Interface module. In the GDI module, programmers can easily obtain printer information by calling APIs such as EnumPrinters. Windows's mature print management mechanism is largely thanks to the complete Printer Driver provided by printer vendors. The printer driver in Windows shields the printer from the specific printing implementation details, and provides a simple API interface for upper-layer calls.

In contrast to Windows, the printer management mechanism has gone through a long process from generation to maturity on Linux. The Linux printing system originated from the UNIX Printing System, but the UNIX system has always lacked a unified standard interface. For historical reasons, different UNIX platforms use different printing systems. Among the various UNIX Printing Solutions, the most popular are the Berkeley printing System and the System V printing System. On the one hand, different printing systems require different printing drivers; on the other hand, UNIX only has a relatively small customer base. These factors make many printer vendors abandon their support for UNIX platforms. The lack of unified printing interfaces and the imperfect underlying drivers have made printing a major functional vulnerability on the Linux platform for a long time.

In the end, the appearance of CUPS (Common UNIX Printing System) solved the above dilemma. CUPS is a general printing system on UNIX/Linux. CUPS provides a set of CUPS APIs for interaction between UNIX/Linux systems and printers. For example, you can obtain information about the printer through CUPS or set the printer through CUPS. CUPS provides support for the Berkeley and System V Printing commands. This compatibility allows the previous System to be used without large-scale modifications. At the same time, CUPS also provides a series of modular filter interfaces. With these interfaces, printer providers only need to develop one driver to meet the needs of all platforms. So far, CUPS has been supported by all UNIX and Linux platforms.

2. Printer management and transplantation Architecture

Printer management transplantation is an important part of cross-platform transplantation of applications. The print interfaces supported by different platforms are different. Therefore, the core of porting is to convert the printer management interfaces between platforms. Demonstrate the architecture of printer management porting.


Printer management porting architecture

Windows provides a series of APIs to obtain printer information. This information is encapsulated in a predefined Windows standard structure, such as DEVMODE, PRINTER_INFO_2, and PRINTER_INFO_4. Linux uses CUPS to obtain printer information, which is encapsulated in data structures such as cups_dest_t and ipp_attribute_t. You only need to correctly obtain printer information on the Linux platform and convert it into a Windows Printer data structure, you can complete printer management.

3. Basic CUPS knowledge

CUPS is a printing system on UNIX/Linux platforms. The definition and implementation of CUPS are based on the IPP (Internet Printing Protocol) Protocol. IPP is a general printing system standard, and its functions and operations are defined in detail by a series of RFC (Request for Comments. These specific functions and operations include creating IPP requests, responding to IPP requests, and setting IPP requests. RFC related to IPP includes RFC1179, RFC2910, RFC2911, and RFC3196. In the network Protocol, IPP is located on the HTTP (Hyper-Text Transport Protocol) Protocol. Therefore, the following code example involves many IPP and HTTP system calls, such as ippAddString () and httpConnectEncrypt. In addition, the following header files should be introduced before CUPS is used on UNIX/Linux platforms:


#include 
     
      #include 
      
       #include 
       
        #include 
        
       
      
     

With the basic knowledge of CUPS, We will illustrate the technical details of using CUPS for printer management and transplantation.

4. Get the number of printers

In Windows, the pcReturned parameter returned by API EnumPrinters () is used to obtain the number of printers in the system. The specific implementation of Windows programs is as follows:


int n_PrinterCount;EnumPrinters( , , , , , , &n_PrinterCount);

In Linux, the CUPS function cupsGetDests () can implement the same function. Note that after the call, the caller needs to use cupsFreeDests () to release the memory.


    cups_dest_t *dests;    int n_PrinterCount = cupsGetDests( &dests );    cupsFreeDests(count, dests);    

 

[1] [2] [3] [4] Next page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.