diff --git a/print/print_fwk/BUILD.gn b/print/print_fwk/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fdd1ad03e7990e0ff0abf5b234c942793e244620 --- /dev/null +++ b/print/print_fwk/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (C) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") + +ohos_ndk_headers("ohprint_header") { + dest_dir = "$ndk_headers_out_dir/ohprint" + sources = [ + "include/native_print_base.h", + "include/native_print_capi.h", + ] +} + +ohos_ndk_library("libohprint_ndk") { + output_name = "ohprint" + output_extension = "so" + ndk_description_file = "./ohprint.ndk.json" + system_capability = "SystemCapability.Print.PrintFramework" + system_capability_headers = [ + "ohprint/native_print_base.h", + "ohprint/native_print_capi.h", + ] +} diff --git a/print/print_fwk/include/native_print_base.h b/print/print_fwk/include/native_print_base.h new file mode 100644 index 0000000000000000000000000000000000000000..471cc0e382067e53ef6d73f7f032e01edd4f1862 --- /dev/null +++ b/print/print_fwk/include/native_print_base.h @@ -0,0 +1,376 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup OH_Print + * @{ + * + * @brief Provide the definition of the C interface for the native print module. + * + * @syscap SystemCapability.Print.PrintFramework + * + * @since 12 + * @version 1.0 + */ + +/** + * @file native_print_base.h + * + * @brief Declare the native print data types. + * + * @library libohprint.so + * @syscap SystemCapability.Print.PrintFramework + * @since 12 + * @version 1.0 + */ + +#ifndef NATIVE_PRINT_BASE_H +#define NATIVE_PRINT_BASE_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines error codes. + * @since 12 + * @version 1.0 + */ +typedef enum { + /** The operation is successful. */ + PRINT_ERROR_NONE = 0, + /** Permission verification failed. */ + PRINT_ERROR_NO_PERMISSION = 201, + /** Invalid parameter. */ + PRINT_ERROR_INVALID_PARAMETER = 401, + /** General internal error. */ + PRINT_ERROR_GENERIC_FAILURE = 24300001, + /** RPC communication error. */ + PRINT_ERROR_RPC_FAILURE = 24300002, + /** Server error. */ + PRINT_ERROR_SERVER_FAILURE = 24300003, + /** Invalid extension. */ + PRINT_ERROR_INVALID_EXTENSION = 24300004, + /** Invalid printer. */ + PRINT_ERROR_INVALID_PRINTER = 24300005, + /** Invalid print job. */ + PRINT_ERROR_INVALID_PRINT_JOB = 24300006, + /** Failed to read or write files. */ + PRINT_ERROR_FILE_IO = 24300007, + /** Unknown error. */ + PRINT_ERROR_UNKNOWN = 24300255, +} Print_ErrorCode; + +/** + * @brief Indicates printer states. + * @since 12 + */ +typedef enum { + /** Printer idle. */ + PRINTER_IDLE, + /** Printer busy. */ + PRINTER_BUSY, + /** Printer not available. */ + PRINTER_UNAVAILABLE, +} Print_PrinterState; + +/** + * @brief Indicate printer discovery events. + * @since 12 + */ +typedef enum { + /** Printer discovered. */ + PRINTER_DISCOVERED = 0, + /** Printer lost. */ + PRINTER_LOST = 1, + /** Printer connecting. */ + PRINTER_CONNECTING = 2, + /** Printer connected. */ + PRINTER_CONNECTED = 3, +} Print_DiscoveryEvent; + +/** + * @brief Indicate printer change events. + * @since 12 + */ +typedef enum { + /** Printer added. */ + PRINTER_ADDED = 0, + /** Printer deleted. */ + PRINTER_DELETED = 1, + /** Printer state changed. */ + PRINTER_STATE_CHANGED = 2, + /** Printer info changed. */ + PRINTER_INFO_CHANGED = 3, +} Print_PrinterEvent; + +/** + * @brief Indicates paper size info. + * @since 12 + */ +typedef struct { + /** Paper id. */ + char *id; + /** Paper name. */ + char *name; + /** Paper width. */ + uint32_t width; + /** Paper height. */ + uint32_t height; + /** Paper left margin. */ + uint32_t leftMargin; + /** Paper top margin. */ + uint32_t topMargin; + /** Paper right margin. */ + uint32_t rightMargin; + /** Paper bottom margin. */ + uint32_t bottomMargin; +} Print_PageSize; + +/** + * @brief Indicates string list. + * @since 12 + */ +typedef struct { + /** Number of strings. */ + uint32_t count; + /** String pointer array */ + char **list; +} Print_StringList; + +/** + * @brief Indicates printer capabilities. + * @since 12 + */ +typedef struct { + bool supportedColorMode; + uint32_t *supportedDuplexModes; + uint32_t supportedDuplexModesCount; + Print_PageSize *supportedPageSizes; + uint32_t supportedPageSizesCount; + uint32_t *supportedMediaTypes; + uint32_t supportedMediaTypesCount; + uint32_t *supportedQualities; + uint32_t supportedQualitiesCount; + char *supportedDocumentHandling; + char *supportedMediaSource; + uint32_t supportedCopies; + char *supportedResolution; + uint32_t *supportedOrientation; + uint32_t supportedOrientationCount; + char *advanceCapability; +} Print_PrinterCapability; + +/** + * @brief Indicates current properties + * @since 12 + */ +typedef struct { + uint32_t defaultColorMode; + uint32_t defaultSides; + char *defaultMediaType; + char *defaultMediaSource; + uint32_t defaultPrintQuality; + uint32_t defaultCopies; + char *defaultPrinterResolution; + uint32_t defaultOrientation; + char *otherDefaultValues; +} Print_DefaultValue; + +/** + * @brief Indicates printer infomation. + * @since 12 + */ +typedef struct { + /** Printer state. */ + Print_PrinterState printerState; + /** Printer capabilities. */ + Print_PrinterCapability capability; + /** Printer current properties. */ + Print_DefaultValue defaultValue; + /** Default printer. */ + bool isDefaultPrinter; + /** Printer id. */ + char *printerId; + /** Printer name. */ + char *printerName; + /** Printer description. */ + char *description; + /** Printer location. */ + char *location; + /** Printer make and model infomation. */ + char *makeAndModel; + /** Printer Uri. */ + char *printerUri; + /** Detail infomation in json format. */ + char *detailInfo; +} Print_PrinterInfo; + +/** + * @brief Indicates printer property. + * @since 12 + */ +typedef struct { + /** Property keyword */ + char *key; + /** Property value. */ + char *value; +} Print_Property; + +/** + * @brief List of printer properties. + * @since 12 + */ +typedef struct { + /** Number of properties. */ + uint32_t count; + /** Property pointer array. */ + Print_Property *list; +} Print_PropertyList; + +/** + * @brief Indicates PaperSource Mode. + * @since 12 + */ +typedef enum { + OH_PAPERSOURCE_MODE_AUTO = 6, + OH_PAPERSOURCE_MODE_CASSETTE = 11, + OH_PAPERSOURCE_MODE_ENVELOPE = 4, + OH_PAPERSOURCE_MODE_ENVELOPE_MANUAL = 5, + OH_PAPERSOURCE_MODE_FORM_SOURCE = 12, + OH_PAPERSOURCE_MODE_LARGE_CAPACITY = 10, + OH_PAPERSOURCE_MODE_LARGE_FORMAT = 9, + OH_PAPERSOURCE_MODE_LOWER = 1, + OH_PAPERSOURCE_MODE_LAST_PAPER_SOURCE = 13, + OH_PAPERSOURCE_MODE_MIDDLE = 2, + OH_PAPERSOURCE_MODE_MANUAL = 3, + OH_PAPERSOURCE_MODE_ONLY_ONE = 0, + OH_PAPERSOURCE_MODE_TRACTOR = 7, + OH_PAPERSOURCE_MODE_SMALL_FORMAT = 8, + OH_PAPERSOURCE_MODE_CUSTOM_SOURCE = 14, +} PrintJob_PaperSource; + +/** + * @brief Indicates DuplexMode + * @since 12 + */ +typedef enum { + OH_DUPLEX_MODE_ONE_SIDED = 0, + OH_DUPLEX_MODE_TWO_SIDED_LONG_EDGE = 1, + OH_DUPLEX_MODE_TWO_SIDED_SHORT_EDGE = 2, +} PrintJob_DuplexMode; + +/** + * @brief Indicates ColorMode + * @since 12 + */ +typedef enum { + OH_COLOR_MODE_MONOCHROME = 0, + OH_COLOR_MODE_COLOR = 1, + OH_COLOR_MODE_AUTO = 2, +} PrintJob_ColorMode; + +/** + * @brief Indicates OrientationMode + * @since 12 + */ +typedef enum { + OH_ORIENTATION_MODE_PORTRAIT = 0, + OH_ORIENTATION_MODE_LANDSCAPE = 1, +} PrintJob_OrientationMode; + +/** + * @brief Indicates PageSize + * @since 12 + */ +typedef struct { + char *id; + char *name; + uint32_t width; + uint32_t height; +} PrintJob_PageSize; + +/** + * @brief Indicates PageRange + * @since 12 + */ +typedef struct { + uint32_t startPage; + uint32_t endPage; + uint32_t *pages; + uint32_t pagesCount; +} PrintJob_PageRange; + +/** + * @brief Indicates PrintMargin + * @since 12 + */ +typedef struct { + uint32_t topMargin; + uint32_t bottomMargin; + uint32_t leftMargin; + uint32_t rightMargin; +} PrintJob_PrintMargin; + +/** + * @brief Indicates PrintJob OptionObject. + * @since 12 + */ +typedef struct { + char *jobName; + char *mediaType; + uint32_t documentCategory; + char *printQuality; + char *printerName; + char *printerUri; + char *documentFormat; + char *advanceOptions; +} PrintJob_OptionObject; + +/** + * @brief Indicates PrintJob Structure. + * @since 12 + */ +typedef struct { + uint32_t *fdList; + uint32_t fdListCount; + char *printerId; + uint32_t dpi; + uint32_t copyNumber; + PrintJob_PaperSource paperSource; + PrintJob_PageSize pageSize; + PrintJob_ColorMode colorMode; + PrintJob_DuplexMode duplexMode; + PrintJob_PageRange pageRange; + PrintJob_PrintMargin printMargin; + PrintJob_OrientationMode orientationMode; + PrintJob_OptionObject printOption; +} Print_PrintJob; + +/** + * @brief Printer change callback. + * @since 12 + */ +typedef void (*Print_PrinterChangeCallback)(uint32_t event, const Print_PrinterInfo *printerInfo); + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_PRINT_BASE_H +/** @} */ diff --git a/print/print_fwk/include/native_print_capi.h b/print/print_fwk/include/native_print_capi.h new file mode 100644 index 0000000000000000000000000000000000000000..f5c230e451c97052177c4c14c6b2621ba40d4cd9 --- /dev/null +++ b/print/print_fwk/include/native_print_capi.h @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup OH_Print + * @{ + * + * @brief Provide the definition of the C interface for the native print module. + * + * @syscap SystemCapability.Print.PrintFramework + * + * @since 12 + * @version 1.0 + */ + +/** + * @file native_print_capi.h + * + * @brief Declare the native print functions. + * + * @library libohprint.so + * @syscap SystemCapability.Print.PrintFramework + * @since 12 + * @version 1.0 + */ + +#ifndef NATIVE_PRINT_CAPI_H +#define NATIVE_PRINT_CAPI_H + +#include "native_print_base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Initialize. + * @since 12 + */ +int32_t OH_Print_Init(); +// 反初始化 +/** + * @brief Release resources before exiting. + * @since 12 + */ +int32_t OH_Print_Release(); + +// 开始发现打印机 +/** + * @brief Start discovering printers. + * @since 12 + */ +int32_t OH_Print_StartPrinterDiscovery(Print_PrinterChangeCallback callback); + +// 停止发现打印机 +/** + * @brief Stop discovering printers. + * @since 12 + */ +int32_t OH_Print_StopPrinterDiscovery(); + +/** + * @brief Connect to a printer. + * @since 12 + */ +int32_t OH_Print_ConnectPrinter(const char *printerId); + +// 开始打印任务 +/** + * @brief Start print job. + * @since 12 + */ +int32_t OH_Print_StartPrintJob(const Print_PrintJob *printJob); + +// 注册打印机状态事件 +/** + * @brief Register printer change events. + * @since 12 + */ +int32_t OH_Print_RegisterPrinterChangeListener(Print_PrinterChangeCallback callback); + +/** + * @brief Unregister printer change event. + * @since 12 + */ +void OH_Print_UnregisterPrinterChangeListener(); + +// 获取打印机列表 +/** + * @brief Query the printer list. + * @since 12 + */ +int32_t OH_Print_QueryPrinterList(Print_StringList *printerIdList); + +/** + * @brief Free printer list memory. + * @since 12 + */ +void OH_Print_ReleasePrinterList(Print_StringList *printerIdList); + +/** + * @brief Query printer infomation. + * @since 12 + */ +int32_t OH_Print_QueryPrinterInfo(const char *printerId, Print_PrinterInfo **printerInfo); + +/** + * @brief Free printer infomation memory. + * @since 12 + */ +void OH_Print_ReleasePrinterInfo(Print_PrinterInfo *printerInfo); + +/** + * @brief Open the printer manager page. + * @since 12 + */ +int32_t OH_Print_LaunchPrinterManager(); + +/** + * @brief Query printer properties. + * @since 12 + */ +int32_t OH_Print_QueryPrinterProperties(const char *printerId, const Print_StringList propertyKeyList, + Print_PropertyList *propertyList); + +/** + * @brief Free printer properties memory. + * @since 12 + */ +void OH_Print_ReleasePrinterProperties(Print_PropertyList *propertyList); + +/** + * @brief Set printer properties. + * @since 12 + */ +int32_t OH_Print_UpdatePrinterProperties(const char *printerId, const Print_PropertyList *propertyList); + +/** + * @brief Restore printer properties to default settings. + * @since 12 + */ +int32_t OH_Print_RestorePrinterProperties(const char *printerId, const Print_StringList *propertyKeyList); + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_PRINT_CAPI_H +/** @} */ diff --git a/print/print_fwk/ohprint.ndk.json b/print/print_fwk/ohprint.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..cf7f7032ecbd31579947755ed51ecc11ca4cdec5 --- /dev/null +++ b/print/print_fwk/ohprint.ndk.json @@ -0,0 +1,70 @@ +[ + { + "first_introduced": "12", + "name": "OH_Print_Init" + }, + { + "first_introduced": "12", + "name": "OH_Print_Release" + }, + { + "first_introduced": "12", + "name": "OH_Print_StartPrinterDiscovery" + }, + { + "first_introduced": "12", + "name": "OH_Print_StopPrinterDiscovery" + }, + { + "first_introduced": "12", + "name": "OH_Print_ConnectPrinter" + }, + { + "first_introduced": "12", + "name": "OH_Print_StartPrintJob" + }, + { + "first_introduced": "12", + "name": "OH_Print_RegisterPrinterChangeListener" + }, + { + "first_introduced": "12", + "name": "OH_Print_UnregisterPrinterChangeListener" + }, + { + "first_introduced": "12", + "name": "OH_Print_QueryPrinterList" + }, + { + "first_introduced": "12", + "name": "OH_Print_ReleasePrinterList" + }, + { + "first_introduced": "12", + "name": "OH_Print_QueryPrinterInfo" + }, + { + "first_introduced": "12", + "name": "OH_Print_ReleasePrinterInfo" + }, + { + "first_introduced": "12", + "name": "OH_Print_LaunchPrinterManager" + }, + { + "first_introduced": "12", + "name": "OH_Print_QueryPrinterProperties" + }, + { + "first_introduced": "12", + "name": "OH_Print_ReleasePrinterProperties" + }, + { + "first_introduced": "12", + "name": "OH_Print_UpdatePrinterProperties" + }, + { + "first_introduced": "12", + "name": "OH_Print_RestorePrinterProperties" + } +]