Add 0906 code

Signed-off-by: @chuangda_1 <fangwanning@huawei.com>
This commit is contained in:
@chuangda_1 2022-09-06 11:10:06 +08:00
parent be3e4ae398
commit 7f6c4a62ce
97 changed files with 2787 additions and 1184 deletions

View File

@ -1,4 +1,4 @@
# Copyright (C) 2022 Huawei Device Co., Ltd. # Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd. <!-- Copyright (c) 2022 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,36 +0,0 @@
# miscservices_print
#### Description
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
#### Software Architecture
Software architecture description
#### Installation
1. xxxx
2. xxxx
3. xxxx
#### Instructions
1. xxxx
2. xxxx
3. xxxx
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

View File

@ -1,39 +0,0 @@
# miscservices_print
#### 介绍
{**以下是 Gitee 平台说明,您可以替换此简介**
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN。专为开发者提供稳定、高效、安全的云端软件开发协作平台
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

View File

@ -13,7 +13,7 @@
"name": "print", "name": "print",
"subsystem": "print", "subsystem": "print",
"syscap": [ "syscap": [
"SystemCapability.MiscServices.Download" "SystemCapability.Print.Print"
], ],
"features": [ "features": [
], ],

View File

@ -1,4 +1,4 @@
# Copyright (C) 2022 Huawei Device Co., Ltd. # Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at

View File

@ -1,16 +1,9 @@
{ {
"jobs" : [{
"name" : "boot",
"cmds" : [
"start print_service"
]
}
],
"services" : [{ "services" : [{
"name" : "print_service", "name" : "print_service",
"path" : ["/system/bin/sa_main", "/system/profile/print_service.xml"], "path" : ["/system/bin/sa_main", "/system/profile/print_service.xml"],
"uid" : "print", "uid" : "system",
"gid" : ["print", "shell"], "gid" : ["system", "shell"],
"secon" : "u:r:print_service:s0" "secon" : "u:r:print_service:s0"
} }
] ]

View File

@ -1,4 +1,4 @@
# Copyright (C) 2022 Huawei Device Co., Ltd. # Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at

View File

@ -40,24 +40,26 @@ ohos_shared_library("print_client") {
public_configs = [ ":print_interfaces_kits_napi_config" ] public_configs = [ ":print_interfaces_kits_napi_config" ]
sources = [ sources = [
"src/print_manager_client.cpp", "src/napi_print_utils.cpp",
"src/print_notify_stub.cpp",
"src/print_service_proxy.cpp",
"src/printer_capability.cpp",
"src/print_margin.cpp",
"src/print_page_size.cpp",
"src/print_resolution.cpp",
"src/print_extension_info.cpp",
"src/printer_info.cpp",
"src/print_range.cpp",
"src/preview_attribute.cpp",
"src/print_job.cpp",
"src/print_base_notify.cpp", "src/print_base_notify.cpp",
"src/print_callback_stub.cpp",
"src/print_extension_callback_stub.cpp",
"src/print_extension_info.cpp",
"src/print_fail_notify.cpp", "src/print_fail_notify.cpp",
"src/print_job.cpp",
"src/print_manager_client.cpp",
"src/print_margin.cpp",
"src/print_notify.cpp", "src/print_notify.cpp",
"src/print_page_size.cpp",
"src/print_preview_attribute.cpp",
"src/print_progress_notify.cpp", "src/print_progress_notify.cpp",
"src/print_extcb_stub.cpp", "src/print_range.cpp",
"src/print_napi_utils.cpp", "src/print_resolution.cpp",
"src/print_sa_death_recipient.cpp",
"src/print_service_proxy.cpp",
"src/print_sync_load_callback.cpp",
"src/printer_capability.cpp",
"src/printer_info.cpp",
] ]
deps = [ deps = [
"//foundation/arkui/napi:ace_napi", "//foundation/arkui/napi:ace_napi",

View File

@ -13,16 +13,16 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef PRINT_NOTIFY_INTERFACE_H #ifndef IPRINT_CALLBACK_H
#define PRINT_NOTIFY_INTERFACE_H #define IPRINT_CALLBACK_H
#include "iremote_broker.h" #include "iremote_broker.h"
#include "iremote_object.h" #include "iremote_object.h"
namespace OHOS::Print { namespace OHOS::Print {
class PrintNotifyInterface : public IRemoteBroker { class IPrintCallback : public IRemoteBroker {
public: public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Print.PrintNotifyInterface"); DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Print.IPrintCallback");
virtual void OnCallBack(MessageParcel &data) = 0; virtual void OnCallBack(MessageParcel &data) = 0;
}; };
@ -30,4 +30,4 @@ enum {
PRINT_NOTIFY, PRINT_NOTIFY,
}; };
} // namespace OHOS::Print } // namespace OHOS::Print
#endif // PRINT_NOTIFY_INTERFACE_H #endif // IPRINT_CALLBACK_H

View File

@ -13,26 +13,28 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef PRINT_EXTCB_INTERFACE_H #ifndef IPRINT_EXTENSION_CALLBACK_H
#define PRINT_EXTCB_INTERFACE_H #define IPRINT_EXTENSION_CALLBACK_H
#include "iremote_broker.h" #include "iremote_broker.h"
#include "iremote_object.h" #include "iremote_object.h"
#include "print_job.h" #include "print_job.h"
namespace OHOS::Print { namespace OHOS::Print {
class PrintExtcbInterface : public IRemoteBroker { class IPrintExtensionCallback : public IRemoteBroker {
public: public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Print.PrintExtcbInterface"); DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Print.IPrintExtensionCallback");
virtual bool OnCallback() = 0; virtual bool OnCallback() = 0;
virtual bool OnCallback(uint32_t printerId) = 0; virtual bool OnCallback(uint32_t printerId) = 0;
virtual bool OnCallback(const PrintJob &job) = 0; virtual bool OnCallback(const PrintJob &job) = 0;
virtual bool OnCallback(uint32_t printerId, MessageParcel &reply) = 0;
}; };
enum { enum {
PRINT_EXTCB, PRINT_EXTCB,
PRINT_EXTCB_PRINTER, PRINT_EXTCB_PRINTER,
PRINT_EXTCB_PRINTJOB, PRINT_EXTCB_PRINTJOB,
PRINT_EXTCB_PRINTCAPABILITY,
}; };
enum { enum {
@ -47,4 +49,4 @@ enum {
PRINT_EXTCB_MAX, PRINT_EXTCB_MAX,
}; };
} // namespace OHOS::Print } // namespace OHOS::Print
#endif // PRINT_EXTCB_INTERFACE_H #endif // IPRINT_EXTCB_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -18,17 +18,17 @@
#include <string> #include <string>
#include "iprint_callback.h"
#include "iprint_extension_callback.h"
#include "iremote_broker.h" #include "iremote_broker.h"
#include "print_extcb_interface.h"
#include "print_extension_info.h" #include "print_extension_info.h"
#include "print_job.h" #include "print_job.h"
#include "print_notify_interface.h"
#include "printer_info.h" #include "printer_info.h"
namespace OHOS::Print { namespace OHOS::Print {
class PrintServiceInterface : public IRemoteBroker { class IPrintService : public IRemoteBroker {
public: public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Print.PrintServiceInterface"); DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Print. IPrintService");
virtual int32_t StartPrint() = 0; virtual int32_t StartPrint() = 0;
virtual bool ConnectPrinter(uint32_t printerId) = 0; virtual bool ConnectPrinter(uint32_t printerId) = 0;
virtual bool DisconnectPrinter(uint32_t printerId) = 0; virtual bool DisconnectPrinter(uint32_t printerId) = 0;
@ -45,9 +45,9 @@ public:
virtual bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability) = 0; virtual bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability) = 0;
virtual bool CheckPermission() = 0; virtual bool CheckPermission() = 0;
virtual bool On( virtual bool On(
const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<PrintNotifyInterface> &listener) = 0; const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<IPrintCallback> &listener) = 0;
virtual bool Off(const std::string &type) = 0; virtual bool Off(const std::string &type) = 0;
virtual bool RegisterExtCallback(uint32_t callbackId, const sptr<PrintExtcbInterface> &listener) = 0; virtual bool RegisterExtCallback(uint32_t callbackId, const sptr<IPrintExtensionCallback> &listener) = 0;
virtual bool UnregisterAllExtCallback() = 0; virtual bool UnregisterAllExtCallback() = 0;
}; };

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef PRINT_NAPI_UTILS_H #ifndef NAPI_PRINT_UTILS_H
#define PRINT_NAPI_UTILS_H #define NAPI_PRINT_UTILS_H
#include <string> #include <string>
#include <vector> #include <vector>
@ -79,4 +79,4 @@ public:
static napi_value Convert2JsObj(napi_env env, const PrintJob &job); static napi_value Convert2JsObj(napi_env env, const PrintJob &job);
}; };
} // namespace OHOS::Print } // namespace OHOS::Print
#endif /* PRINT_NAPI_UTILS_H */ #endif /* NAPI_PRINT_UTILS_H */

View File

@ -1,5 +1,5 @@
/*NotifyHandler /*NotifyHandler
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -20,11 +20,10 @@
#include "napi/native_api.h" #include "napi/native_api.h"
#include "noncopyable.h" #include "noncopyable.h"
#include "print_callback_stub.h"
#include "print_job.h" #include "print_job.h"
#include "print_notify_stub.h"
#include "printer_info.h" #include "printer_info.h"
namespace OHOS::Print { namespace OHOS::Print {
struct NotifyData { struct NotifyData {
napi_env env; napi_env env;
@ -36,7 +35,7 @@ struct NotifyData {
PrintJob thirdArgv; PrintJob thirdArgv;
}; };
class PrintBaseNotify : public PrintNotifyStub { class PrintBaseNotify : public PrintCallbackStub {
public: public:
ACE_DISALLOW_COPY_AND_MOVE(PrintBaseNotify); ACE_DISALLOW_COPY_AND_MOVE(PrintBaseNotify);
explicit PrintBaseNotify(napi_env env, const std::string &type, napi_ref ref); explicit PrintBaseNotify(napi_env env, const std::string &type, napi_ref ref);

View File

@ -13,20 +13,20 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef PRINT_NOTIFY_STUB_H #ifndef PRINT_CALLBACK_STUB_H
#define PRINT_NOTIFY_STUB_H #define PRINT_CALLBACK_STUB_H
#include <memory> #include <memory>
#include "iprint_callback.h"
#include "iremote_stub.h" #include "iremote_stub.h"
#include "print_notify_interface.h"
namespace OHOS::Print { namespace OHOS::Print {
class PrintNotifyStub : public IRemoteStub<PrintNotifyInterface> { class PrintCallbackStub : public IRemoteStub<IPrintCallback> {
public: public:
PrintNotifyStub() = default; PrintCallbackStub() = default;
virtual ~PrintNotifyStub() {} virtual ~PrintCallbackStub() {}
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
}; };
} // namespace OHOS::Print } // namespace OHOS::Print
#endif // PRINT_NOTIFY_STUB_H #endif // PRINT_CALLBACK_STUB_H

View File

@ -39,11 +39,11 @@ public:
[[nodiscard]] uint32_t GetVendorId() const; [[nodiscard]] uint32_t GetVendorId() const;
[[nodiscard]] std::string &GetVendorName(); [[nodiscard]] const std::string &GetVendorName() const;
[[nodiscard]] uint32_t GetVendorIcon() const; [[nodiscard]] uint32_t GetVendorIcon() const;
[[nodiscard]] std::string &GetVersion(); [[nodiscard]] const std::string &GetVersion() const;
void Dump(); void Dump();

View File

@ -13,44 +13,51 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef PRINT_EXTCB_STUB_H #ifndef PRINT_EXTENSION_CALLBACK_STUB_H
#define PRINT_EXTCB_STUB_H #define PRINT_EXTENSION_CALLBACK_STUB_H
#include <memory> #include <memory>
#include "iprint_extension_callback.h"
#include "iremote_stub.h" #include "iremote_stub.h"
#include "print_extcb_interface.h"
#include "print_job.h" #include "print_job.h"
#include "printer_capability.h"
namespace OHOS::Print { namespace OHOS::Print {
using PrintExtCallback = bool (*)(); using PrintExtCallback = bool (*)();
using PrintJobCallback = bool (*)(const PrintJob &); using PrintJobCallback = bool (*)(const PrintJob &);
using PrinterCallback = bool (*)(uint32_t); using PrinterCallback = bool (*)(uint32_t);
using PrinterCapabilityCallback = bool (*)(uint32_t, PrinterCapability &cap);
class PrintExtcbStub : public IRemoteStub<PrintExtcbInterface> { class PrintExtensionCallbackStub : public IRemoteStub<IPrintExtensionCallback> {
public: public:
explicit PrintExtcbStub(); explicit PrintExtensionCallbackStub();
virtual ~PrintExtcbStub() = default; virtual ~PrintExtensionCallbackStub() = default;
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
bool OnCallback() override; bool OnCallback() override;
bool OnCallback(uint32_t printerId) override; bool OnCallback(uint32_t printerId) override;
bool OnCallback(const PrintJob &job) override; bool OnCallback(const PrintJob &job) override;
bool OnCallback(uint32_t printerId, MessageParcel &reply) override;
void SetExtCallback(PrintExtCallback cb); void SetExtCallback(PrintExtCallback cb);
void SetPrintJobCallback(PrintJobCallback cb); void SetPrintJobCallback(PrintJobCallback cb);
void SetPrinterCallback(PrinterCallback cb); void SetPrinterCallback(PrinterCallback cb);
void SetCapabilityCallback(PrinterCapabilityCallback cb);
private: private:
bool HandleExtCallback(MessageParcel &data); bool HandleExtCallback(MessageParcel &data, MessageParcel &reply);
bool HandlePrinterCallback(MessageParcel &data); bool HandlePrinterCallback(MessageParcel &data, MessageParcel &reply);
bool HandlePrintJobCallback(MessageParcel &data); bool HandlePrintJobCallback(MessageParcel &data, MessageParcel &reply);
bool HandleCapabilityCallback(MessageParcel &data, MessageParcel &reply);
void dataReadJob(MessageParcel &data, PrintJob &job);
private: private:
using PRINT_EXT_HANDLER = bool (PrintExtcbStub::*)(MessageParcel &); using PRINT_EXT_HANDLER = bool (PrintExtensionCallbackStub::*)(MessageParcel &, MessageParcel &);
PrintExtCallback extCb_; PrintExtCallback extCb_;
PrintJobCallback jobCb_; PrintJobCallback jobCb_;
PrinterCallback cb_; PrinterCallback cb_;
PrinterCapabilityCallback capability_;
std::map<uint32_t, PRINT_EXT_HANDLER> cmdMap_; std::map<uint32_t, PRINT_EXT_HANDLER> cmdMap_;
}; };
} // namespace OHOS::Print } // namespace OHOS::Print

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -19,9 +19,12 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "preview_attribute.h" #include "iremote_broker.h"
#include "iremote_proxy.h"
#include "napi/native_api.h"
#include "print_margin.h" #include "print_margin.h"
#include "print_page_size.h" #include "print_page_size.h"
#include "print_preview_attribute.h"
#include "print_range.h" #include "print_range.h"
namespace OHOS::Print { namespace OHOS::Print {
@ -42,21 +45,21 @@ public:
void SetCopyNumber(uint32_t copyNumber); void SetCopyNumber(uint32_t copyNumber);
void SetPageRange(PrintRange pageRange_); void SetPageRange(const PrintRange &pageRange);
void SetIsSequential(bool isSequential_); void SetIsSequential(bool isSequential);
void SetPageSize(PrintPageSize pageSize_); void SetPageSize(const PrintPageSize &pageSize);
void SetIsLandscape(bool isLandscape_); void SetIsLandscape(bool isLandscape);
void SetColorMode(uint32_t colorMode_); void SetColorMode(uint32_t colorMode);
void SetDuplexMode(uint32_t duplexmode); void SetDuplexMode(uint32_t duplexmode);
void SetMargin(PrintMargin margin_); void SetMargin(const PrintMargin &margin);
void SetPreview(PreviewAttribute preview_); void SetPreview(const PreviewAttribute &preview);
void GetFiles(std::vector<std::string> &fileList) const; void GetFiles(std::vector<std::string> &fileList) const;
@ -84,8 +87,20 @@ public:
void GetPreview(PreviewAttribute &previewAttr) const; void GetPreview(PreviewAttribute &previewAttr) const;
void ConvertToParcel(MessageParcel &reply) const;
void BuildFromParcel(MessageParcel &data);
void ConvertToJs(napi_env env, napi_value *result) const;
void BuildFromJs(napi_env env, napi_value capValue);
void Dump(); void Dump();
private:
bool ParseJob(napi_env env, napi_value jobValue, PrintJob &printJob);
bool ParseJobParam(napi_env env, napi_value jobValue, PrintJob &printJob);
private: private:
std::vector<std::string> files_; std::vector<std::string> files_;
uint32_t jobId_; uint32_t jobId_;
@ -100,27 +115,6 @@ private:
int32_t duplexMode_; int32_t duplexMode_;
PrintMargin margin_; PrintMargin margin_;
PreviewAttribute preview_; PreviewAttribute preview_;
/*
enum PrintJobState {
PRINT_JOB_CREATED = 1,
PRINT_JOB_QUEUED = 2,
PRINT_JOB_PRINTING = 3,
PRINT_JOB_BLOCKED = 4,
PRINT_JOB_SUCCESS = 5,
PRINT_JOB_FAILED = 6,
PRINT_JOB_cancelled = 7,
};
enum PrintState{
PRINT_CREATED = 1,
PRINT_QUEUED = 2,
PRINT_PRINTING = 3,
PRINT_BLOCKED = 4,
PRINT_SUCCESS = 5,
PRINT_FAILED = 6,
PRINT_cancelled = 7,
};
*/
}; };
} // namespace OHOS::Print } // namespace OHOS::Print
#endif /* PRINT_PRINT_JOB_H */ #endif /* PRINT_PRINT_JOB_H */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -13,36 +13,27 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef PRINT_MANAGER_H #ifndef PRINT_MANAGER_CLIENT_H
#define PRINT_MANAGER_H #define PRINT_MANAGER_CLIENT_H
#include <condition_variable> #include <condition_variable>
#include <map> #include <map>
#include <mutex> #include <mutex>
#include "iprint_callback.h"
#include "iprint_service.h"
#include "iremote_object.h" #include "iremote_object.h"
#include "print_extcb_stub.h" #include "print_extension_callback_stub.h"
#include "print_extension_info.h" #include "print_extension_info.h"
#include "print_job.h" #include "print_job.h"
#include "print_notify_interface.h" #include "print_sa_death_recipient.h"
#include "print_service_interface.h"
#include "printer_info.h" #include "printer_info.h"
#include "refbase.h" #include "refbase.h"
namespace OHOS::Print { namespace OHOS::Print {
class PrintSaDeathRecipient : public IRemoteObject::DeathRecipient {
public:
explicit PrintSaDeathRecipient();
~PrintSaDeathRecipient() = default;
void OnRemoteDied(const wptr<IRemoteObject> &object) override;
};
class PrintManagerClient : public RefBase { class PrintManagerClient : public RefBase {
public: public:
PrintManagerClient(); PrintManagerClient();
bool LoadPrintServer();
void LoadServerSuccess();
void LoadServerFail();
~PrintManagerClient(); ~PrintManagerClient();
static sptr<PrintManagerClient> GetInstance(); static sptr<PrintManagerClient> GetInstance();
bool CheckPermission(); bool CheckPermission();
@ -58,31 +49,41 @@ public:
bool RemovePrinters(std::vector<PrinterInfo> arrayPrintInfo); bool RemovePrinters(std::vector<PrinterInfo> arrayPrintInfo);
bool ConnectPrinter(uint32_t printerId); bool ConnectPrinter(uint32_t printerId);
bool DisconnectPrinter(uint32_t printerId); bool DisconnectPrinter(uint32_t printerId);
bool StartPrintJob(PrintJob jobinfo); bool StartPrintJob(const PrintJob &jobinfo);
bool CancelPrintJob(PrintJob jobinfo); bool CancelPrintJob(const PrintJob &jobinfo);
bool UpdatePrinterState(uint32_t printerId, uint32_t state); bool UpdatePrinterState(uint32_t printerId, uint32_t state);
bool UpdatePrinterJobState(uint32_t jobId, uint32_t state); bool UpdatePrinterJobState(uint32_t jobId, uint32_t state);
bool RequestPreview(PrintJob jobinfo, std::string &previewResult); bool RequestPreview(const PrintJob &jobinfo, std::string &previewResult);
bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability); bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability);
bool On(const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<PrintNotifyInterface> &listener); bool On(const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<IPrintCallback> &listener);
bool Off(const std::string &type); bool Off(const std::string &type);
bool RegisterExtCallback(uint32_t callbackId, PrintExtCallback cb); bool RegisterExtCallback(uint32_t callbackId, PrintExtCallback cb);
bool RegisterExtCallback(uint32_t callbackId, PrintJobCallback cb); bool RegisterExtCallback(uint32_t callbackId, PrintJobCallback cb);
bool RegisterExtCallback(uint32_t callbackId, PrinterCallback cb); bool RegisterExtCallback(uint32_t callbackId, PrinterCallback cb);
bool RegisterExtCallback(uint32_t callbackId, PrinterCapabilityCallback cb);
bool UnregisterAllExtCallback(); bool UnregisterAllExtCallback();
bool LoadServer();
void LoadServerSuccess();
void LoadServerFail();
private: private:
sptr<PrintServiceInterface> GetPrintServiceProxy(); sptr<IPrintService> GetPrintServiceProxy();
private: private:
static std::mutex instanceLock_; static std::mutex instanceLock_;
static sptr<PrintManagerClient> instance_; static sptr<PrintManagerClient> instance_;
sptr<PrintServiceInterface> printServiceProxy_; sptr<IPrintService> printServiceProxy_;
sptr<PrintSaDeathRecipient> deathRecipient_; sptr<PrintSaDeathRecipient> deathRecipient_;
std::map<uint32_t, sptr<PrintExtcbStub>> extCallbackMap_; std::map<uint32_t, sptr<PrintExtensionCallbackStub>> extCallbackMap_;
std::mutex loadMutex_;
std::mutex conditionMutex_;
std::condition_variable syncCon_;
bool ready_ = false;
static constexpr int LOAD_SA_TIMEOUT_MS = 15000;
}; };
} // namespace OHOS::Print } // namespace OHOS::Print
#endif // PRINT_MANAGER_H #endif // PRINT_MANAGER_CLIENT_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -20,10 +20,10 @@
#include "napi/native_api.h" #include "napi/native_api.h"
#include "noncopyable.h" #include "noncopyable.h"
#include "print_notify_stub.h" #include "print_callback_stub.h"
namespace OHOS::Print { namespace OHOS::Print {
class PrintNotify final : public PrintNotifyStub { class PrintNotify final : public PrintCallbackStub {
public: public:
ACE_DISALLOW_COPY_AND_MOVE(PrintNotify); ACE_DISALLOW_COPY_AND_MOVE(PrintNotify);
explicit PrintNotify(); explicit PrintNotify();

View File

@ -21,14 +21,200 @@
#include <string> #include <string>
namespace OHOS::Print { namespace OHOS::Print {
enum PageSizeId {
ISO_A0,
ISO_A1,
ISO_A2,
ISO_A3,
ISO_A4,
ISO_A5,
ISO_A6,
ISO_A7,
ISO_A8,
ISO_A9,
ISO_A10,
ISO_B0,
ISO_B1,
ISO_B2,
ISO_B3,
ISO_B4,
ISO_B5,
ISO_B6,
ISO_B7,
ISO_B8,
ISO_B9,
ISO_B10,
ISO_C0,
ISO_C1,
ISO_C2,
ISO_C3,
ISO_C4,
ISO_C5,
ISO_C6,
ISO_C7,
ISO_C8,
ISO_C9,
ISO_C10,
NA_LETTER,
NA_GOVT_LETTER,
NA_LEGAL,
NA_JUNIOR_LEGAL,
NA_LEDGER,
NA_TABLOID,
NA_INDEX_3X5,
NA_INDEX_4X6,
NA_INDEX_5X8,
NA_MONARCH,
NA_QUARTO,
NA_FOOLSCAP,
ROC_8K,
ROC_16K,
PRC_1,
PRC_2,
PRC_3,
PRC_4,
PRC_5,
PRC_6,
PRC_7,
PRC_8,
PRC_9,
PRC_10,
PRC_16K,
OM_PA_KAI,
OM_DAI_PA_KAI,
OM_JUURO_KU_KAI,
JIS_B10,
JIS_B9,
JIS_B8,
JIS_B7,
JIS_B6,
JIS_B5,
JIS_B4,
JIS_B3,
JIS_B2,
JIS_B1,
JIS_B0,
JIS_EXEC,
JPN_CHOU4,
JPN_CHOU3,
JPN_CHOU2,
JPN_HAGAKI,
JPN_OUFUKU,
JPN_KAHU,
JPN_KAKU2,
JPN_YOU4,
};
const std::string PAGE_SIZE_TABLE[] = {
"ISO_A0",
"ISO_A1",
"ISO_A2",
"ISO_A3",
"ISO_A4",
"ISO_A5",
"ISO_A6",
"ISO_A7",
"ISO_A8",
"ISO_A9",
"ISO_A10",
"ISO_B0",
"ISO_B1",
"ISO_B2",
"ISO_B3",
"ISO_B4",
"ISO_B5",
"ISO_B6",
"ISO_B7",
"ISO_B8",
"ISO_B9",
"ISO_B10",
"ISO_C0",
"ISO_C1",
"ISO_C2",
"ISO_C3",
"ISO_C4",
"ISO_C5",
"ISO_C6",
"ISO_C7",
"ISO_C8",
"ISO_C9",
"ISO_C10",
"NA_LETTER",
"NA_GOVT_LETTER",
"NA_LEGAL",
"NA_JUNIOR_LEGAL",
"NA_LEDGER",
"NA_TABLOID",
"NA_INDEX_3X5",
"NA_INDEX_4X6",
"NA_INDEX_5X8",
"NA_MONARCH",
"NA_QUARTO",
"NA_FOOLSCAP",
"ROC_8K",
"ROC_16K",
"PRC_1",
"PRC_2",
"PRC_3",
"PRC_4",
"PRC_5",
"PRC_6",
"PRC_7",
"PRC_8",
"PRC_9",
"PRC_10",
"PRC_16K",
"OM_PA_KAI",
"OM_DAI_PA_KAI",
"OM_JUURO_KU_KAI",
"JIS_B10",
"JIS_B9",
"JIS_B8",
"JIS_B7",
"JIS_B6",
"JIS_B5",
"JIS_B4",
"JIS_B3",
"JIS_B2",
"JIS_B1",
"JIS_B0",
"JIS_EXEC",
"JPN_CHOU4",
"JPN_CHOU3",
"JPN_CHOU2",
"JPN_HAGAKI",
"JPN_OUFUKU",
"JPN_KAHU",
"JPN_KAKU2",
"JPN_YOU4",
};
using DiscreteId = std::string;
using DiscretePageName = std::string;
using PAGE_SIZE_ID = std::string;
class PrintPageSize { class PrintPageSize {
public: public:
static void BuildPageSizeMap();
static PrintPageSize GetPageSize(PageSizeId id);
explicit PrintPageSize(); explicit PrintPageSize();
PrintPageSize(PAGE_SIZE_ID id, DiscretePageName name, uint32_t width, uint32_t height);
PrintPageSize(const PrintPageSize &right); PrintPageSize(const PrintPageSize &right);
PrintPageSize &operator=(const PrintPageSize &right); PrintPageSize &operator=(const PrintPageSize &right);
~PrintPageSize(); ~PrintPageSize();
void SetId(uint32_t id); void SetId(const std::string &id);
void SetName(const std::string &name); void SetName(const std::string &name);
@ -36,7 +222,7 @@ public:
void SetHeight(uint32_t height); void SetHeight(uint32_t height);
[[nodiscard]] uint32_t GetId() const; [[nodiscard]] const std::string &GetId() const;
[[nodiscard]] const std::string &GetName() const; [[nodiscard]] const std::string &GetName() const;
@ -47,10 +233,11 @@ public:
void Dump(); void Dump();
private: private:
uint32_t id_; std::string id_;
std::string name_; std::string name_;
uint32_t width_; uint32_t width_;
uint32_t height_; uint32_t height_;
static std::map<PAGE_SIZE_ID, std::shared_ptr<PrintPageSize>> pageSize_;
}; };
} // namespace OHOS::Print } // namespace OHOS::Print
#endif // PRINT_PAGESIZE_H #endif // PRINT_PAGESIZE_H

View File

@ -12,8 +12,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifndef PRINT_RESUME_H #ifndef PRINT_PREVIEW_ATTRIBUTE_H
#define PRINT_RESUME_H #define PRINT_PREVIEW_ATTRIBUTE_H
#include <cstdint> #include <cstdint>
#include <string> #include <string>
@ -42,4 +42,4 @@ private:
PrintRange previewRange_; PrintRange previewRange_;
}; };
} // namespace OHOS::Print } // namespace OHOS::Print
#endif // PRINT_RESUME_H #endif // PRINT_PREVIEW_ATTRIBUTE_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2022 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.
*/
#ifndef PRINT_SA_DEATH_RECIPIENT_H
#define PRINT_SA_DEATH_RECIPIENT_H
#include "iremote_object.h"
#include "refbase.h"
namespace OHOS::Print {
class PrintSaDeathRecipient : public IRemoteObject::DeathRecipient {
public:
explicit PrintSaDeathRecipient();
~PrintSaDeathRecipient() = default;
void OnRemoteDied(const wptr<IRemoteObject> &object) override;
};
} // namespace OHOS::Print
#endif // PRINT_SA_DEATH_RECIPIENT_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -16,11 +16,11 @@
#ifndef PRINT_SERVICE_PROXY_H #ifndef PRINT_SERVICE_PROXY_H
#define PRINT_SERVICE_PROXY_H #define PRINT_SERVICE_PROXY_H
#include "iprint_service.h"
#include "iremote_proxy.h" #include "iremote_proxy.h"
#include "print_service_interface.h"
namespace OHOS::Print { namespace OHOS::Print {
class PrintServiceProxy : public IRemoteProxy<PrintServiceInterface> { class PrintServiceProxy : public IRemoteProxy<IPrintService> {
public: public:
explicit PrintServiceProxy(const sptr<IRemoteObject> &object); explicit PrintServiceProxy(const sptr<IRemoteObject> &object);
~PrintServiceProxy() = default; ~PrintServiceProxy() = default;
@ -40,10 +40,9 @@ public:
bool RequestPreview(const PrintJob &jobinfo, std::string &previewResult) override; bool RequestPreview(const PrintJob &jobinfo, std::string &previewResult) override;
bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability) override; bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability) override;
bool CheckPermission() override; bool CheckPermission() override;
bool On(const std::string &type, uint32_t &state, PrinterInfo &info, bool On(const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<IPrintCallback> &listener) override;
const sptr<PrintNotifyInterface> &listener) override;
bool Off(const std::string &type) override; bool Off(const std::string &type) override;
bool RegisterExtCallback(uint32_t callbackId, const sptr<PrintExtcbInterface> &listener) override; bool RegisterExtCallback(uint32_t callbackId, const sptr<IPrintExtensionCallback> &listener) override;
bool UnregisterAllExtCallback() override; bool UnregisterAllExtCallback() override;
private: private:

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2022 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.
*/
#ifndef PRINT_SYNC_LOAD_CALLBACK_H
#define PRINT_SYNC_LOAD_CALLBACK_H
#include "system_ability_load_callback_stub.h"
namespace OHOS::Print {
class PrintSyncLoadCallback : public SystemAbilityLoadCallbackStub {
public:
void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override;
void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
};
} // namespace OHOS::Print
#endif // PRINT_SYNC_LOAD_CALLBACK_H

View File

@ -19,6 +19,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "iremote_broker.h"
#include "iremote_proxy.h"
#include "napi/native_api.h"
#include "print_margin.h" #include "print_margin.h"
#include "print_page_size.h" #include "print_page_size.h"
#include "print_resolution.h" #include "print_resolution.h"
@ -31,7 +34,7 @@ public:
PrinterCapability &operator=(const PrinterCapability &right); PrinterCapability &operator=(const PrinterCapability &right);
~PrinterCapability(); ~PrinterCapability();
void SetMinMargin(PrintMargin &minMargin); void SetMinMargin(const PrintMargin &minMargin);
void SetPageSize(const std::vector<PrintPageSize> &pageSizeList); void SetPageSize(const std::vector<PrintPageSize> &pageSizeList);
@ -51,8 +54,33 @@ public:
[[nodiscard]] uint32_t GetDuplexMode() const; [[nodiscard]] uint32_t GetDuplexMode() const;
void ConvertToParcel(MessageParcel &reply) const;
void BuildFromParcel(MessageParcel &data);
void ConvertToJs(napi_env env, napi_value *result) const;
void BuildFromJs(napi_env env, napi_value capValue);
void Dump(); void Dump();
private:
bool ParseResolution(napi_env env, napi_value reValue, PrintResolution &resolution);
bool ParseResolutionParam(napi_env env, napi_value reValue, PrintResolution &resolution);
bool ParsePageSize(napi_env env, napi_value capValue, PrintPageSize &pageSize);
bool ParseMargin(napi_env env, napi_value marginValue, PrintMargin &margin);
bool ParseMarginParam(napi_env env, napi_value marginValue, PrintMargin &margin);
bool ParseCapabilityParam(napi_env env, napi_value capValue);
bool ParseCapability(napi_env env, napi_value capValue);
bool ParsePageSizeParam(napi_env env, napi_value capValue, PrintPageSize &pageSize);
private: private:
PrintMargin minMargin_; PrintMargin minMargin_;
std::vector<PrintPageSize> pageSizeList_; std::vector<PrintPageSize> pageSizeList_;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -57,6 +57,10 @@ public:
void Dump(); void Dump();
private:
bool ParseInfo(napi_env env, napi_value InfoValue, PrinterInfo &Info);
bool ParseInfoParam(napi_env env, napi_value InfoValue, PrinterInfo &info);
private: private:
uint32_t printerId_; uint32_t printerId_;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "print_napi_utils.h" #include "napi_print_utils.h"
#include <cstring> #include <cstring>
#include <initializer_list> #include <initializer_list>
@ -360,7 +360,7 @@ napi_value PrintNapiUtils::Convert2JsObj(napi_env env, const PrintJob &job)
napi_value pageSize; napi_value pageSize;
NAPI_CALL(env, napi_create_object(env, &pageSize)); NAPI_CALL(env, napi_create_object(env, &pageSize));
SetUint32Property(env, pageSize, "id", nativePageSize.GetId()); SetStringPropertyUtf8(env, pageSize, "id", nativePageSize.GetId().c_str());
SetStringPropertyUtf8(env, pageSize, "name", nativePageSize.GetName().c_str()); SetStringPropertyUtf8(env, pageSize, "name", nativePageSize.GetName().c_str());
SetUint32Property(env, pageSize, "width", nativePageSize.GetWidth()); SetUint32Property(env, pageSize, "width", nativePageSize.GetWidth());
SetUint32Property(env, pageSize, "height", nativePageSize.GetHeight()); SetUint32Property(env, pageSize, "height", nativePageSize.GetHeight());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -17,12 +17,12 @@
#include <uv.h> #include <uv.h>
#include "napi_print_utils.h"
#include "print_log.h" #include "print_log.h"
#include "print_napi_utils.h"
namespace OHOS::Print { namespace OHOS::Print {
PrintBaseNotify::PrintBaseNotify(napi_env env, const std::string &type, napi_ref ref) PrintBaseNotify::PrintBaseNotify(napi_env env, const std::string &type, napi_ref ref)
: PrintNotifyStub(), env_(env), type_(type), ref_(ref) : PrintCallbackStub(), env_(env), type_(type), ref_(ref)
{} {}
PrintBaseNotify::~PrintBaseNotify() PrintBaseNotify::~PrintBaseNotify()

View File

@ -13,13 +13,13 @@
* limitations under the License. * limitations under the License.
*/ */
#include "print_notify_stub.h" #include "print_callback_stub.h"
#include "print_common.h" #include "print_common.h"
#include "print_log.h" #include "print_log.h"
namespace OHOS::Print { namespace OHOS::Print {
int32_t PrintNotifyStub::OnRemoteRequest( int32_t PrintCallbackStub::OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{ {
auto descriptorToken = data.ReadInterfaceToken(); auto descriptorToken = data.ReadInterfaceToken();
@ -27,7 +27,7 @@ int32_t PrintNotifyStub::OnRemoteRequest(
PRINT_HILOGE("Remote descriptor not the same as local descriptor."); PRINT_HILOGE("Remote descriptor not the same as local descriptor.");
return E_PRINT_IPC_ERROR; return E_PRINT_IPC_ERROR;
} }
PRINT_HILOGD("PrintNotifyStub code----> %{public}u", code); PRINT_HILOGD("PrintCallbackStub code----> %{public}u", code);
switch (code) { switch (code) {
case PRINT_NOTIFY: { case PRINT_NOTIFY: {
OnCallBack(data); OnCallBack(data);

View File

@ -1,104 +0,0 @@
/*
* Copyright (c) 2022 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.
*/
#include "print_extcb_stub.h"
#include "print_common.h"
#include "print_log.h"
namespace OHOS::Print {
PrintExtcbStub::PrintExtcbStub() : extCb_(nullptr), jobCb_(nullptr), cb_(nullptr)
{
cmdMap_[PRINT_EXTCB] = &PrintExtcbStub::HandleExtCallback;
cmdMap_[PRINT_EXTCB_PRINTER] = &PrintExtcbStub::HandlePrinterCallback;
cmdMap_[PRINT_EXTCB_PRINTJOB] = &PrintExtcbStub::HandlePrintJobCallback;
}
int32_t PrintExtcbStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
PRINT_HILOGD("OnRemoteRequest started, code = %{public}d", code);
auto descriptorToken = data.ReadInterfaceToken();
if (descriptorToken != GetDescriptor()) {
PRINT_HILOGE("Remote descriptor not the same as local descriptor.");
return E_PRINT_IPC_ERROR;
}
auto itFunc = cmdMap_.find(code);
if (itFunc != cmdMap_.end()) {
auto requestFunc = itFunc->second;
if (requestFunc != nullptr) {
return (this->*requestFunc)(data);
}
}
PRINT_HILOGW("default case, need check.");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
bool PrintExtcbStub::OnCallback()
{
if (extCb_ != nullptr) {
return extCb_();
}
return false;
}
bool PrintExtcbStub::OnCallback(uint32_t printerId)
{
if (cb_ != nullptr) {
return cb_(printerId);
}
return false;
}
bool PrintExtcbStub::OnCallback(const PrintJob &job)
{
if (jobCb_ != nullptr) {
return jobCb_(job);
}
return false;
}
void PrintExtcbStub::SetExtCallback(PrintExtCallback cb)
{
extCb_ = cb;
}
void PrintExtcbStub::SetPrintJobCallback(PrintJobCallback cb)
{
jobCb_ = cb;
}
void PrintExtcbStub::SetPrinterCallback(PrinterCallback cb)
{
cb_ = cb;
}
bool PrintExtcbStub::HandleExtCallback(MessageParcel &data)
{
return OnCallback();
}
bool PrintExtcbStub::HandlePrinterCallback(MessageParcel &data)
{
uint32_t printerId = data.ReadUint32();
return OnCallback(printerId);
}
bool PrintExtcbStub::HandlePrintJobCallback(MessageParcel &data)
{
PrintJob job; // = data.readuint32();
return OnCallback(job);
}
} // namespace OHOS::Print

View File

@ -58,7 +58,7 @@ uint32_t PrinterExtensionInfo::GetVendorId() const
return vendorId_; return vendorId_;
} }
std::string &PrinterExtensionInfo::GetVendorName() const std::string &PrinterExtensionInfo::GetVendorName() const
{ {
return vendorName_; return vendorName_;
} }
@ -68,7 +68,7 @@ uint32_t PrinterExtensionInfo::GetVendorIcon() const
return vendorIcon_; return vendorIcon_;
} }
std::string &PrinterExtensionInfo::GetVersion() const std::string &PrinterExtensionInfo::GetVersion() const
{ {
return version_; return version_;
} }

View File

@ -0,0 +1,188 @@
/*
* Copyright (c) 2022 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.
*/
#include "print_extension_callback_stub.h"
#include "print_common.h"
#include "print_log.h"
#include "print_resolution.h"
namespace OHOS::Print {
PrintExtensionCallbackStub::PrintExtensionCallbackStub() : extCb_(nullptr), jobCb_(nullptr), cb_(nullptr)
{
cmdMap_[PRINT_EXTCB] = &PrintExtensionCallbackStub::HandleExtCallback;
cmdMap_[PRINT_EXTCB_PRINTER] = &PrintExtensionCallbackStub::HandlePrinterCallback;
cmdMap_[PRINT_EXTCB_PRINTJOB] = &PrintExtensionCallbackStub::HandlePrintJobCallback;
cmdMap_[PRINT_EXTCB_PRINTCAPABILITY] = &PrintExtensionCallbackStub::HandleCapabilityCallback;
}
int32_t PrintExtensionCallbackStub::OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
PRINT_HILOGD("OnRemoteRequest started, code = %{public}d", code);
auto descriptorToken = data.ReadInterfaceToken();
if (descriptorToken != GetDescriptor()) {
PRINT_HILOGE("Remote descriptor not the same as local descriptor.");
return E_PRINT_IPC_ERROR;
}
auto itFunc = cmdMap_.find(code);
if (itFunc != cmdMap_.end()) {
auto requestFunc = itFunc->second;
if (requestFunc != nullptr) {
return (this->*requestFunc)(data, reply);
}
}
PRINT_HILOGW("default case, need check.");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
bool PrintExtensionCallbackStub::OnCallback()
{
if (extCb_ != nullptr) {
return extCb_();
}
return false;
}
bool PrintExtensionCallbackStub::OnCallback(uint32_t printerId)
{
if (cb_ != nullptr) {
return cb_(printerId);
}
return false;
}
bool PrintExtensionCallbackStub::OnCallback(const PrintJob &job)
{
if (jobCb_ != nullptr) {
return jobCb_(job);
}
return false;
}
bool PrintExtensionCallbackStub::OnCallback(uint32_t printerId, MessageParcel &reply) // PrinterCapability& reply
{
PrinterCapability capability;
capability.ConvertToParcel(reply);
return true;
}
void PrintExtensionCallbackStub::SetExtCallback(PrintExtCallback cb)
{
extCb_ = cb;
}
void PrintExtensionCallbackStub::SetPrintJobCallback(PrintJobCallback cb)
{
jobCb_ = cb;
}
void PrintExtensionCallbackStub::SetPrinterCallback(PrinterCallback cb)
{
cb_ = cb;
}
void PrintExtensionCallbackStub::SetCapabilityCallback(PrinterCapabilityCallback cb)
{
capability_ = cb;
}
bool PrintExtensionCallbackStub::HandleExtCallback(MessageParcel &data, MessageParcel &reply)
{
return OnCallback();
}
bool PrintExtensionCallbackStub::HandlePrinterCallback(MessageParcel &data, MessageParcel &reply)
{
uint32_t printerId = data.ReadUint32();
return OnCallback(printerId);
}
void PrintExtensionCallbackStub::dataReadJob(MessageParcel &data, PrintJob &job)
{
uint32_t fileLength = data.ReadUint32();
std::vector<std::string> files;
for (uint32_t i = 0; i < fileLength; i++) {
files.push_back(data.ReadString());
}
job.SetFiles(files);
job.SetJobId(data.ReadUint32());
job.SetPrintId(data.ReadUint32());
job.SetJobState(data.ReadUint32());
job.SetCopyNumber(data.ReadUint32());
PrintRange range;
std::vector<uint32_t> pages;
range.SetStartPage(data.ReadUint32());
range.SetEndPage(data.ReadUint32());
uint32_t pageLength = data.ReadUint32();
for (uint32_t i = 0; i < pageLength; i++) {
pages.push_back(data.ReadUint32());
}
range.SetPages(pages);
job.SetPageRange(range);
job.SetIsSequential(data.ReadUint32());
PrintPageSize pageSize;
pageSize.SetId(data.ReadString());
pageSize.SetName(data.ReadString());
pageSize.SetWidth(data.ReadUint32());
pageSize.SetHeight(data.ReadUint32());
job.SetPageSize(pageSize);
job.SetIsLandscape(data.ReadUint32());
job.SetColorMode(data.ReadUint32());
job.SetDuplexMode(data.ReadUint32());
PrintMargin margin;
margin.SetTop(data.ReadUint32());
margin.SetBottom(data.ReadUint32());
margin.SetLeft(data.ReadUint32());
margin.SetRight(data.ReadUint32());
job.SetMargin(margin);
PreviewAttribute previewAttr;
PrintRange previewRange;
previewAttr.SetResult(data.ReadString());
previewRange.SetStartPage(data.ReadUint32());
previewRange.SetEndPage(data.ReadUint32());
uint32_t previewPageLength = data.ReadUint32();
std::vector<uint32_t> arrayPages;
for (uint32_t i = 0; i < previewPageLength; i++) {
arrayPages.push_back(data.ReadUint32());
}
previewRange.SetPages(arrayPages);
previewAttr.SetPreviewRange(previewRange);
job.SetPreview(previewAttr);
}
bool PrintExtensionCallbackStub::HandlePrintJobCallback(MessageParcel &data, MessageParcel &reply)
{
PrintJob job;
job.BuildFromParcel(data);
// dataReadJob(data, job);
return OnCallback(job);
}
bool PrintExtensionCallbackStub::HandleCapabilityCallback(MessageParcel &data, MessageParcel &reply)
{
uint32_t printerId = data.ReadUint32();
// PrinterCapability cap;
// OnCallabck(printerId, cap);
// cap.BuildParcel(reply);
return OnCallback(printerId, reply);
}
} // namespace OHOS::Print

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -17,8 +17,8 @@
#include <uv.h> #include <uv.h>
#include "napi_print_utils.h"
#include "print_log.h" #include "print_log.h"
#include "print_napi_utils.h"
namespace OHOS::Print { namespace OHOS::Print {
PrintFailNotify::PrintFailNotify(napi_env env, const std::string &type, napi_ref ref) : PrintBaseNotify(env, type, ref) PrintFailNotify::PrintFailNotify(napi_env env, const std::string &type, napi_ref ref) : PrintBaseNotify(env, type, ref)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,19 +14,20 @@
*/ */
#include "print_job.h" #include "print_job.h"
#include "napi_print_utils.h"
#include "print_log.h" #include "print_log.h"
namespace OHOS::Print{ namespace OHOS::Print {
PrintJob::PrintJob() : jobId_(0), jobState_(1), copyNumber_(1), isSequential_(true), PrintJob::PrintJob()
isLandscape_(1), colorMode_(1), duplexMode_(1) : jobId_(0), jobState_(1), copyNumber_(1), isSequential_(true), isLandscape_(1), colorMode_(1), duplexMode_(1)
{ {}
}
PrintJob::PrintJob(const PrintJob& right) PrintJob::PrintJob(const PrintJob &right)
{ {
files_.clear(); files_.clear();
files_.assign(right.files_.begin(), right.files_.end()); files_.assign(right.files_.begin(), right.files_.end());
printerId_ = right.printerId_; printerId_ = right.printerId_;
jobId_ = right.jobId_; jobId_ = right.jobId_;
jobState_ = right.jobState_; jobState_ = right.jobState_;
@ -41,9 +42,9 @@ PrintJob::PrintJob(const PrintJob& right)
preview_ = right.preview_; preview_ = right.preview_;
} }
PrintJob& PrintJob::operator=(PrintJob& right) PrintJob &PrintJob::operator=(PrintJob &right)
{ {
if(this != &right){ if (this != &right) {
files_.clear(); files_.clear();
files_.assign(right.files_.begin(), right.files_.end()); files_.assign(right.files_.begin(), right.files_.end());
@ -63,12 +64,9 @@ PrintJob& PrintJob::operator=(PrintJob& right)
return *this; return *this;
} }
PrintJob::~PrintJob() {}
PrintJob::~PrintJob() void PrintJob::SetFiles(const std::vector<std::string> &files)
{
}
void PrintJob::SetFiles(const std::vector<std::string>& files)
{ {
files_.clear(); files_.clear();
files_.assign(files.begin(), files.end()); files_.assign(files.begin(), files.end());
@ -94,7 +92,7 @@ void PrintJob::SetCopyNumber(uint32_t copyNumber)
copyNumber_ = copyNumber; copyNumber_ = copyNumber;
} }
void PrintJob::SetPageRange(PrintRange pageRange) void PrintJob::SetPageRange(const PrintRange &pageRange)
{ {
pageRange_ = pageRange; pageRange_ = pageRange;
} }
@ -104,7 +102,7 @@ void PrintJob::SetIsSequential(bool isSequential)
isSequential_ = isSequential; isSequential_ = isSequential;
} }
void PrintJob::SetPageSize(PrintPageSize pageSize) void PrintJob::SetPageSize(const PrintPageSize &pageSize)
{ {
pageSize_ = pageSize; pageSize_ = pageSize;
} }
@ -124,17 +122,17 @@ void PrintJob::SetDuplexMode(uint32_t duplexmode)
duplexMode_ = duplexmode; duplexMode_ = duplexmode;
} }
void PrintJob::SetMargin(PrintMargin margin) void PrintJob::SetMargin(const PrintMargin &margin)
{ {
margin_ = margin; margin_ = margin;
} }
void PrintJob::SetPreview(PreviewAttribute preview) void PrintJob::SetPreview(const PreviewAttribute &preview)
{ {
preview_ = preview; preview_ = preview;
} }
void PrintJob::GetFiles(std::vector<std::string>& files) const void PrintJob::GetFiles(std::vector<std::string> &files) const
{ {
files.clear(); files.clear();
files.assign(files_.begin(), files_.end()); files.assign(files_.begin(), files_.end());
@ -160,7 +158,7 @@ uint32_t PrintJob::GetCopyNumber() const
return copyNumber_; return copyNumber_;
} }
void PrintJob::GetPageRange(PrintRange& range) const void PrintJob::GetPageRange(PrintRange &range) const
{ {
range = pageRange_; range = pageRange_;
} }
@ -169,7 +167,7 @@ bool PrintJob::GetIsSequential() const
{ {
return isSequential_; return isSequential_;
} }
void PrintJob::GetPageSize(PrintPageSize& pageSize) const void PrintJob::GetPageSize(PrintPageSize &pageSize) const
{ {
pageSize = pageSize_; pageSize = pageSize_;
} }
@ -189,21 +187,234 @@ uint32_t PrintJob::GetDuplexMode() const
return duplexMode_; return duplexMode_;
} }
void PrintJob::GetMargin(PrintMargin& margin) const void PrintJob::GetMargin(PrintMargin &margin) const
{ {
margin = margin_; margin = margin_;
} }
void PrintJob::GetPreview(PreviewAttribute& previewAttr) const void PrintJob::GetPreview(PreviewAttribute &previewAttr) const
{ {
previewAttr = preview_; previewAttr = preview_;
} }
void PrintJob::ConvertToParcel(MessageParcel &reply) const
{
std::vector<std::string> files;
GetFiles(files);
uint32_t fileLength = files.size();
reply.WriteUint32(fileLength);
for (uint32_t i = 0; i < fileLength; i++) {
reply.WriteString(files[i]);
}
reply.WriteUint32(GetJobId());
reply.WriteUint32(GetPrinterId());
reply.WriteUint32(GetJobState());
reply.WriteUint32(GetCopyNumber());
PrintRange range;
GetPageRange(range);
reply.WriteUint32(range.GetStartPage());
reply.WriteUint32(range.GetEndPage());
std::vector<uint32_t> pages;
range.GetPages(pages);
uint32_t pageLength = pages.size();
reply.WriteUint32(pageLength);
for (uint32_t i = 0; i < pageLength; i++) {
reply.WriteUint32(pages[i]);
}
reply.WriteUint32(GetIsSequential());
PrintPageSize pageSize;
GetPageSize(pageSize);
reply.WriteString(pageSize.GetId());
reply.WriteString(pageSize.GetName());
reply.WriteUint32(pageSize.GetWidth());
reply.WriteUint32(pageSize.GetHeight());
reply.WriteUint32(GetIsLandscape());
reply.WriteUint32(GetColorMode());
reply.WriteUint32(GetDuplexMode());
PrintMargin margin;
GetMargin(margin);
reply.WriteUint32(margin.GetTop());
reply.WriteUint32(margin.GetBottom());
reply.WriteUint32(margin.GetLeft());
reply.WriteUint32(margin.GetRight());
PreviewAttribute preview;
GetPreview(preview);
reply.WriteString(preview.GetResult());
range.Reset();
preview.GetPreviewRange(range);
reply.WriteUint32(range.GetStartPage());
reply.WriteUint32(range.GetEndPage());
range.GetPages(pages);
uint32_t previewPageLength = pages.size();
reply.WriteUint32(previewPageLength);
for (uint32_t i = 0; i < previewPageLength; i++) {
reply.WriteUint32(pages[i]);
}
}
void PrintJob::BuildFromParcel(MessageParcel &data)
{
uint32_t fileLength = data.ReadUint32();
std::vector<std::string> files;
uint32_t index = 0;
for (index = 0; index < fileLength; index++) {
files.push_back(data.ReadString());
}
SetFiles(files);
SetJobId(data.ReadUint32());
SetPrintId(data.ReadUint32());
SetJobState(data.ReadUint32());
SetCopyNumber(data.ReadUint32());
PrintRange range;
range.SetStartPage(data.ReadUint32());
range.SetEndPage(data.ReadUint32());
uint32_t pageLength = data.ReadUint32();
if (pageLength > 0) {
std::vector<uint32_t> rangePages;
for (index = 0; index < pageLength; index++) {
rangePages.push_back(data.ReadUint32());
}
range.SetPages(rangePages);
}
SetPageRange(range);
SetIsSequential(data.ReadUint32());
PrintPageSize pageSize;
pageSize.SetId(data.ReadString());
pageSize.SetName(data.ReadString());
pageSize.SetWidth(data.ReadUint32());
pageSize.SetHeight(data.ReadUint32());
SetPageSize(pageSize);
SetIsLandscape(data.ReadUint32());
SetColorMode(data.ReadUint32());
SetDuplexMode(data.ReadUint32());
PrintMargin minMargin;
minMargin.SetTop(data.ReadUint32());
minMargin.SetBottom(data.ReadUint32());
minMargin.SetLeft(data.ReadUint32());
minMargin.SetRight(data.ReadUint32());
SetMargin(minMargin);
PreviewAttribute previewAttr;
previewAttr.SetResult(data.ReadString());
range.Reset();
range.SetStartPage(data.ReadUint32());
range.SetEndPage(data.ReadUint32());
uint32_t previewPageLength = data.ReadUint32();
if (previewPageLength > 0) {
std::vector<uint32_t> previewRangePages;
for (index = 0; index < previewPageLength; index++) {
previewRangePages.push_back(data.ReadUint32());
}
range.SetPages(previewRangePages);
}
previewAttr.SetPreviewRange(range);
SetPreview(previewAttr);
Dump();
}
void PrintJob::ConvertToJs(napi_env env, napi_value *result) const
{
napi_create_object(env, result);
napi_value arrFiles;
napi_status status = napi_create_array(env, &arrFiles);
uint32_t arrFilesLength = files_.size();
for (uint32_t i = 0; i < arrFilesLength; i++) {
napi_value value;
status = napi_create_string_utf8(env, files_[i].c_str(), NAPI_AUTO_LENGTH, &value);
status = napi_set_element(env, arrFiles, i, value);
}
napi_set_named_property(env, *result, "files", arrFiles);
PrintNapiUtils::SetUint32Property(env, *result, "jobId", GetJobId());
PrintNapiUtils::SetUint32Property(env, *result, "printerId", GetPrinterId());
PrintNapiUtils::SetUint32Property(env, *result, "jobState", GetJobState());
PrintNapiUtils::SetUint32Property(env, *result, "copyNumber", GetCopyNumber());
napi_value pageRange;
napi_create_object(env, &pageRange);
PrintNapiUtils::SetUint32Property(env, pageRange, "startPage", pageRange_.GetStartPage());
PrintNapiUtils::SetUint32Property(env, pageRange, "endPage", pageRange_.GetEndPage());
napi_value arrPages;
status = napi_create_array(env, &arrPages);
std::vector<uint32_t> pages;
pageRange_.GetPages(pages);
uint32_t arrPagesLength = pages.size();
for (uint32_t i = 0; i < arrPagesLength; i++) {
napi_value value;
napi_create_uint32(env, pages[i], &value);
status = napi_set_element(env, arrPages, i, value);
}
napi_set_named_property(env, pageRange, "files", arrPages);
PrintNapiUtils::SetUint32Property(env, *result, "isSequential", GetIsSequential());
napi_value pageSize;
napi_create_object(env, &pageSize);
PrintNapiUtils::SetStringPropertyUtf8(env, pageSize, "id", pageSize_.GetId());
PrintNapiUtils::SetStringPropertyUtf8(env, pageSize, "name", pageSize_.GetName().c_str());
PrintNapiUtils::SetUint32Property(env, pageSize, "width", pageSize_.GetWidth());
PrintNapiUtils::SetUint32Property(env, pageSize, "height", pageSize_.GetHeight());
PrintNapiUtils::SetUint32Property(env, *result, "isLandscape", GetIsLandscape());
PrintNapiUtils::SetUint32Property(env, *result, "colorMode", GetColorMode());
PrintNapiUtils::SetUint32Property(env, *result, "duplexMode", GetDuplexMode());
napi_value margin;
napi_create_object(env, &margin);
PrintNapiUtils::SetUint32Property(env, margin, "top", margin_.GetTop());
PrintNapiUtils::SetUint32Property(env, margin, "bottom", margin_.GetBottom());
PrintNapiUtils::SetUint32Property(env, margin, "left", margin_.GetLeft());
PrintNapiUtils::SetUint32Property(env, margin, "right", margin_.GetRight());
napi_value preview;
napi_create_object(env, &preview);
PrintNapiUtils::SetStringPropertyUtf8(env, preview, "result", preview_.GetResult().c_str());
napi_value subPageRange;
napi_create_object(env, &subPageRange);
PrintNapiUtils::SetUint32Property(env, subPageRange, "startPage", pageRange_.GetStartPage());
PrintNapiUtils::SetUint32Property(env, subPageRange, "endPage", pageRange_.GetEndPage());
napi_value arrPreviewPages;
status = napi_create_array(env, &arrPreviewPages);
PrintRange previewPrintRange;
std::vector<uint32_t> previewRangePages;
preview_.GetPreviewRange(previewPrintRange);
previewPrintRange.GetPages(previewRangePages);
uint32_t arrPreviewPagesLength = previewRangePages.size();
for (uint32_t i = 0; i < arrPreviewPagesLength; i++) {
napi_value value;
napi_create_uint32(env, previewRangePages[i], &value);
status = napi_set_element(env, arrPreviewPages, i, value);
}
napi_set_named_property(env, subPageRange, "files", arrPreviewPages);
napi_set_named_property(env, preview, "pageRange", subPageRange);
napi_set_named_property(env, *result, "pageRange", pageRange);
napi_set_named_property(env, *result, "pageSize", pageSize);
napi_set_named_property(env, *result, "margin", margin);
napi_set_named_property(env, *result, "preview", preview);
}
void PrintJob::BuildFromJs(napi_env env, napi_value capValue) {}
void PrintJob::Dump() void PrintJob::Dump()
{ {
uint32_t fileLength = files_.size(); uint32_t fileLength = files_.size();
for(uint32_t i = 0; i < fileLength; i++) for (uint32_t i = 0; i < fileLength; i++) {
{
PRINT_HILOGD("files_ = %{public}s", files_[i].c_str()); PRINT_HILOGD("files_ = %{public}s", files_[i].c_str());
} }
@ -221,4 +432,4 @@ void PrintJob::Dump()
margin_.Dump(); margin_.Dump();
preview_.Dump(); preview_.Dump();
} }
} } // namespace OHOS::Print

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -16,8 +16,9 @@
#include "print_manager_client.h" #include "print_manager_client.h"
#include "iservice_registry.h" #include "iservice_registry.h"
#include "print_extcb_stub.h" #include "print_extension_callback_stub.h"
#include "print_log.h" #include "print_log.h"
#include "print_sync_load_callback.h"
#include "system_ability_definition.h" #include "system_ability_definition.h"
namespace OHOS::Print { namespace OHOS::Print {
@ -40,7 +41,7 @@ sptr<PrintManagerClient> PrintManagerClient::GetInstance()
} }
bool PrintManagerClient::On( bool PrintManagerClient::On(
const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<PrintNotifyInterface> &listener) const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<IPrintCallback> &listener)
{ {
if (printServiceProxy_ == nullptr) { if (printServiceProxy_ == nullptr) {
PRINT_HILOGW("Redo GetPrintServiceProxy"); PRINT_HILOGW("Redo GetPrintServiceProxy");
@ -52,7 +53,6 @@ bool PrintManagerClient::On(
} }
PRINT_HILOGD("PrintManagerClient On succeeded."); PRINT_HILOGD("PrintManagerClient On succeeded.");
return true; return true;
// return printServiceProxy_->On(type, state, info);
} }
bool PrintManagerClient::Off(const std::string &type) bool PrintManagerClient::Off(const std::string &type)
@ -84,10 +84,10 @@ bool PrintManagerClient::RegisterExtCallback(uint32_t callbackId, PrintExtCallba
PRINT_HILOGE("Invalid callback id [%{public}d].", callbackId); PRINT_HILOGE("Invalid callback id [%{public}d].", callbackId);
return false; return false;
} }
sptr<PrintExtcbStub> callbackStub = nullptr; sptr<PrintExtensionCallbackStub> callbackStub = nullptr;
auto it = extCallbackMap_.find(callbackId); auto it = extCallbackMap_.find(callbackId);
if (it == extCallbackMap_.end()) { if (it == extCallbackMap_.end()) {
callbackStub = new PrintExtcbStub; callbackStub = new PrintExtensionCallbackStub;
if (callbackStub == nullptr) { if (callbackStub == nullptr) {
PRINT_HILOGE("Invalid callback stub object."); PRINT_HILOGE("Invalid callback stub object.");
return false; return false;
@ -119,10 +119,10 @@ bool PrintManagerClient::RegisterExtCallback(uint32_t callbackId, PrintJobCallba
PRINT_HILOGE("Invalid callback id [%{public}d].", callbackId); PRINT_HILOGE("Invalid callback id [%{public}d].", callbackId);
return false; return false;
} }
sptr<PrintExtcbStub> callbackStub = nullptr; sptr<PrintExtensionCallbackStub> callbackStub = nullptr;
auto it = extCallbackMap_.find(callbackId); auto it = extCallbackMap_.find(callbackId);
if (it == extCallbackMap_.end()) { if (it == extCallbackMap_.end()) {
callbackStub = new PrintExtcbStub; callbackStub = new PrintExtensionCallbackStub;
if (callbackStub == nullptr) { if (callbackStub == nullptr) {
PRINT_HILOGE("Invalid callback stub object."); PRINT_HILOGE("Invalid callback stub object.");
return false; return false;
@ -139,6 +139,41 @@ bool PrintManagerClient::RegisterExtCallback(uint32_t callbackId, PrintJobCallba
return ret; return ret;
} }
bool PrintManagerClient::RegisterExtCallback(uint32_t callbackId, PrinterCapabilityCallback cb)
{
if (printServiceProxy_ == nullptr) {
PRINT_HILOGW("Redo GetPrintServiceProxy");
printServiceProxy_ = GetPrintServiceProxy();
}
if (printServiceProxy_ == nullptr) {
PRINT_HILOGE("Resume quit because redoing GetPrintServiceProxy failed.");
return false;
}
if (callbackId >= PRINT_EXTCB_MAX) {
PRINT_HILOGE("Invalid callback id [%{public}d].", callbackId);
return false;
}
sptr<PrintExtensionCallbackStub> callbackStub = nullptr;
auto it = extCallbackMap_.find(callbackId);
if (it == extCallbackMap_.end()) {
callbackStub = new PrintExtensionCallbackStub;
if (callbackStub == nullptr) {
PRINT_HILOGE("Invalid callback stub object.");
return false;
}
callbackStub->SetCapabilityCallback(cb);
extCallbackMap_.insert(std::make_pair(callbackId, callbackStub));
} else {
callbackStub = it->second;
callbackStub->SetCapabilityCallback(cb);
}
bool ret = printServiceProxy_->RegisterExtCallback(callbackId, callbackStub);
PRINT_HILOGD("PrintManagerClient RegisterExtCallback %{public}s.", ret ? "success" : "failed");
return ret;
}
bool PrintManagerClient::RegisterExtCallback(uint32_t callbackId, PrinterCallback cb) bool PrintManagerClient::RegisterExtCallback(uint32_t callbackId, PrinterCallback cb)
{ {
if (printServiceProxy_ == nullptr) { if (printServiceProxy_ == nullptr) {
@ -154,10 +189,10 @@ bool PrintManagerClient::RegisterExtCallback(uint32_t callbackId, PrinterCallbac
PRINT_HILOGE("Invalid callback id [%{public}d].", callbackId); PRINT_HILOGE("Invalid callback id [%{public}d].", callbackId);
return false; return false;
} }
sptr<PrintExtcbStub> callbackStub = nullptr; sptr<PrintExtensionCallbackStub> callbackStub = nullptr;
auto it = extCallbackMap_.find(callbackId); auto it = extCallbackMap_.find(callbackId);
if (it == extCallbackMap_.end()) { if (it == extCallbackMap_.end()) {
callbackStub = new PrintExtcbStub; callbackStub = new PrintExtensionCallbackStub;
if (callbackStub == nullptr) { if (callbackStub == nullptr) {
PRINT_HILOGE("Invalid callback stub object."); PRINT_HILOGE("Invalid callback stub object.");
return false; return false;
@ -193,7 +228,7 @@ bool PrintManagerClient::UnregisterAllExtCallback()
return ret; return ret;
} }
sptr<PrintServiceInterface> PrintManagerClient::GetPrintServiceProxy() sptr<IPrintService> PrintManagerClient::GetPrintServiceProxy()
{ {
sptr<ISystemAbilityManager> systemAbilityManager = sptr<ISystemAbilityManager> systemAbilityManager =
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
@ -208,7 +243,7 @@ sptr<PrintServiceInterface> PrintManagerClient::GetPrintServiceProxy()
} }
deathRecipient_ = new PrintSaDeathRecipient(); deathRecipient_ = new PrintSaDeathRecipient();
systemAbility->AddDeathRecipient(deathRecipient_); systemAbility->AddDeathRecipient(deathRecipient_);
sptr<PrintServiceInterface> serviceProxy = iface_cast<PrintServiceInterface>(systemAbility); sptr<IPrintService> serviceProxy = iface_cast<IPrintService>(systemAbility);
if (serviceProxy == nullptr) { if (serviceProxy == nullptr) {
PRINT_HILOGE("Get PrintManagerClientProxy from SA failed."); PRINT_HILOGE("Get PrintManagerClientProxy from SA failed.");
return nullptr; return nullptr;
@ -222,14 +257,6 @@ void PrintManagerClient::OnRemoteSaDied(const wptr<IRemoteObject> &remote)
printServiceProxy_ = GetPrintServiceProxy(); printServiceProxy_ = GetPrintServiceProxy();
} }
PrintSaDeathRecipient::PrintSaDeathRecipient() {}
void PrintSaDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &object)
{
PRINT_HILOGE("PrintSaDeathRecipient on remote systemAbility died.");
PrintManagerClient::GetInstance()->OnRemoteSaDied(object);
}
int32_t PrintManagerClient::StartPrint() int32_t PrintManagerClient::StartPrint()
{ {
PRINT_HILOGD("PrintManagerClient EnqueueTask start."); PRINT_HILOGD("PrintManagerClient EnqueueTask start.");
@ -239,10 +266,10 @@ int32_t PrintManagerClient::StartPrint()
printServiceProxy_ = GetPrintServiceProxy(); printServiceProxy_ = GetPrintServiceProxy();
} }
if (printServiceProxy_ == nullptr) { if (printServiceProxy_ == nullptr) {
PRINT_HILOGE("AddPrinters quit because redoing GetPrintServiceProxy failed."); PRINT_HILOGE("StartPrint quit because redoing GetPrintServiceProxy failed.");
return false; return false;
} }
PRINT_HILOGD("PrintManagerClient AddPrinters succeeded."); PRINT_HILOGD("PrintManagerClient StartPrint succeeded.");
return printServiceProxy_->StartPrint(); return printServiceProxy_->StartPrint();
} }
@ -316,7 +343,7 @@ bool PrintManagerClient::StopDiscoverPrinter()
return printServiceProxy_->StopDiscoverPrinter(); return printServiceProxy_->StopDiscoverPrinter();
} }
bool PrintManagerClient::StartPrintJob(PrintJob jobinfo) bool PrintManagerClient::StartPrintJob(const PrintJob &jobinfo)
{ {
if (printServiceProxy_ == nullptr) { if (printServiceProxy_ == nullptr) {
PRINT_HILOGW("Redo GetPrintServiceProxy"); PRINT_HILOGW("Redo GetPrintServiceProxy");
@ -330,7 +357,7 @@ bool PrintManagerClient::StartPrintJob(PrintJob jobinfo)
return printServiceProxy_->StartPrintJob(jobinfo); return printServiceProxy_->StartPrintJob(jobinfo);
} }
bool PrintManagerClient::CancelPrintJob(PrintJob jobinfo) bool PrintManagerClient::CancelPrintJob(const PrintJob &jobinfo)
{ {
if (printServiceProxy_ == nullptr) { if (printServiceProxy_ == nullptr) {
PRINT_HILOGW("Redo GetPrintServiceProxy"); PRINT_HILOGW("Redo GetPrintServiceProxy");
@ -342,7 +369,7 @@ bool PrintManagerClient::CancelPrintJob(PrintJob jobinfo)
} }
PRINT_HILOGD("PrintManagerClient CancelPrintJob succeeded."); PRINT_HILOGD("PrintManagerClient CancelPrintJob succeeded.");
return printServiceProxy_->CancelPrintJob(jobinfo); return printServiceProxy_->CancelPrintJob(jobinfo);
} //// }
bool PrintManagerClient::AddPrinters(std::vector<PrinterInfo> arrayPrintInfo) bool PrintManagerClient::AddPrinters(std::vector<PrinterInfo> arrayPrintInfo)
{ {
@ -400,7 +427,7 @@ bool PrintManagerClient::UpdatePrinterJobState(uint32_t jobId, uint32_t state)
return printServiceProxy_->UpdatePrinterJobState(jobId, state); return printServiceProxy_->UpdatePrinterJobState(jobId, state);
} }
bool PrintManagerClient::RequestPreview(PrintJob jobinfo, std::string &previewResult) bool PrintManagerClient::RequestPreview(const PrintJob &jobinfo, std::string &previewResult)
{ {
if (printServiceProxy_ == nullptr) { if (printServiceProxy_ == nullptr) {
PRINT_HILOGW("Redo GetPrintServiceProxy"); PRINT_HILOGW("Redo GetPrintServiceProxy");
@ -442,4 +469,58 @@ bool PrintManagerClient::CheckPermission()
PRINT_HILOGD("Check Permission enable"); PRINT_HILOGD("Check Permission enable");
return printServiceProxy_->CheckPermission(); return printServiceProxy_->CheckPermission();
} }
bool PrintManagerClient::LoadServer()
{
if (ready_) {
return true;
}
std::lock_guard<std::mutex> lock(loadMutex_);
if (ready_) {
return true;
}
auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sm == nullptr) {
PRINT_HILOGE("GetSystemAbilityManager return null");
return false;
}
sptr<PrintSyncLoadCallback> loadCallback_ = new (std::nothrow) PrintSyncLoadCallback();
if (loadCallback_ == nullptr) {
PRINT_HILOGE("new PrintSyncLoadCallback fail");
return false;
}
int32_t result = sm->LoadSystemAbility(PRINT_SERVICE_ID, loadCallback_);
if (result != ERR_OK) {
PRINT_HILOGE("LoadSystemAbility %{public}d failed, result: %{public}d", PRINT_SERVICE_ID, result);
return false;
}
{
std::unique_lock<std::mutex> conditionLock(conditionMutex_);
auto waitStatus = syncCon_.wait_for(
conditionLock, std::chrono::milliseconds(LOAD_SA_TIMEOUT_MS), [this]() { return ready_; });
if (!waitStatus) {
PRINT_HILOGE("print server load sa timeout");
return false;
}
}
return true;
}
void PrintManagerClient::LoadServerSuccess()
{
std::unique_lock<std::mutex> lock(conditionMutex_);
ready_ = true;
syncCon_.notify_one();
PRINT_HILOGE("load print server success");
}
void PrintManagerClient::LoadServerFail()
{
ready_ = false;
PRINT_HILOGE("load print server fail");
}
} // namespace OHOS::Print } // namespace OHOS::Print

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -17,8 +17,8 @@
#include <uv.h> #include <uv.h>
#include "napi_print_utils.h"
#include "print_log.h" #include "print_log.h"
#include "print_napi_utils.h"
namespace OHOS::Print { namespace OHOS::Print {
PrintNotify::PrintNotify() {} PrintNotify::PrintNotify() {}

View File

@ -18,7 +18,135 @@
#include "print_log.h" #include "print_log.h"
namespace OHOS::Print { namespace OHOS::Print {
PrintPageSize::PrintPageSize() : id_(0), name_("PrintPageSize"), width_(0), height_(0) {} std::map<PAGE_SIZE_ID, std::shared_ptr<PrintPageSize>> PrintPageSize::pageSize_;
void PrintPageSize::BuildPageSizeMap()
{
pageSize_.insert(std::make_pair("ISO_A0", std::make_shared<PrintPageSize>("ISO_A0", "Harmony", 33110, 46810)));
pageSize_.insert(std::make_pair("ISO_A1", std::make_shared<PrintPageSize>("ISO_A1", "Harmony", 23390, 33110)));
pageSize_.insert(std::make_pair("ISO_A2", std::make_shared<PrintPageSize>("ISO_A2", "Harmony", 16540, 23390)));
pageSize_.insert(std::make_pair("ISO_A3", std::make_shared<PrintPageSize>("ISO_A3", "Harmony", 11690, 16540)));
pageSize_.insert(std::make_pair("ISO_A4", std::make_shared<PrintPageSize>("ISO_A4", "Harmony", 8270, 11690)));
pageSize_.insert(std::make_pair("ISO_A5", std::make_shared<PrintPageSize>("ISO_A5", "Harmony", 5830, 8270)));
pageSize_.insert(std::make_pair("ISO_A6", std::make_shared<PrintPageSize>("ISO_A6", "Harmony", 4130, 5830)));
pageSize_.insert(std::make_pair("ISO_A7", std::make_shared<PrintPageSize>("ISO_A7", "Harmony", 2910, 4130)));
pageSize_.insert(std::make_pair("ISO_A8", std::make_shared<PrintPageSize>("ISO_A8", "Harmony", 2050, 2910)));
pageSize_.insert(std::make_pair("ISO_A9", std::make_shared<PrintPageSize>("ISO_A9", "Harmony", 1460, 2050)));
pageSize_.insert(std::make_pair("ISO_A10", std::make_shared<PrintPageSize>("ISO_A10", "Harmony", 1020, 1460)));
pageSize_.insert(std::make_pair("ISO_B0", std::make_shared<PrintPageSize>("ISO_B0", "Harmony", 39370, 55670)));
pageSize_.insert(std::make_pair("ISO_B1", std::make_shared<PrintPageSize>("ISO_B1", "Harmony", 27830, 39370)));
pageSize_.insert(std::make_pair("ISO_B2", std::make_shared<PrintPageSize>("ISO_B2", "Harmony", 19690, 27830)));
pageSize_.insert(std::make_pair("ISO_B3", std::make_shared<PrintPageSize>("ISO_B3", "Harmony", 13900, 19690)));
pageSize_.insert(std::make_pair("ISO_B4", std::make_shared<PrintPageSize>("ISO_B4", "Harmony", 39840, 13900)));
pageSize_.insert(std::make_pair("ISO_B5", std::make_shared<PrintPageSize>("ISO_B5", "Harmony", 6930, 9840)));
pageSize_.insert(std::make_pair("ISO_B6", std::make_shared<PrintPageSize>("ISO_B6", "Harmony", 4920, 6930)));
pageSize_.insert(std::make_pair("ISO_B7", std::make_shared<PrintPageSize>("ISO_B7", "Harmony", 3460, 4920)));
pageSize_.insert(std::make_pair("ISO_B8", std::make_shared<PrintPageSize>("ISO_B8", "Harmony", 2440, 3460)));
pageSize_.insert(std::make_pair("ISO_B9", std::make_shared<PrintPageSize>("ISO_B9", "Harmony", 1730, 2440)));
pageSize_.insert(std::make_pair("ISO_B10", std::make_shared<PrintPageSize>("ISO_B10", "Harmony", 1220, 1730)));
pageSize_.insert(std::make_pair("ISO_C0", std::make_shared<PrintPageSize>("ISO_C0", "Harmony", 36100, 51060)));
pageSize_.insert(std::make_pair("ISO_C1", std::make_shared<PrintPageSize>("ISO_C1", "Harmony", 25510, 36100)));
pageSize_.insert(std::make_pair("ISO_C2", std::make_shared<PrintPageSize>("ISO_C2", "Harmony", 18030, 25510)));
pageSize_.insert(std::make_pair("ISO_C3", std::make_shared<PrintPageSize>("ISO_C3", "Harmony", 12760, 18030)));
pageSize_.insert(std::make_pair("ISO_C4", std::make_shared<PrintPageSize>("ISO_C4", "Harmony", 9020, 12760)));
pageSize_.insert(std::make_pair("ISO_C5", std::make_shared<PrintPageSize>("ISO_C5", "Harmony", 6380, 9020)));
pageSize_.insert(std::make_pair("ISO_C6", std::make_shared<PrintPageSize>("ISO_C6", "Harmony", 4490, 6380)));
pageSize_.insert(std::make_pair("ISO_C7", std::make_shared<PrintPageSize>("ISO_C7", "Harmony", 3190, 4490)));
pageSize_.insert(std::make_pair("ISO_C8", std::make_shared<PrintPageSize>("ISO_C8", "Harmony", 2240, 3190)));
pageSize_.insert(std::make_pair("ISO_C9", std::make_shared<PrintPageSize>("ISO_C9", "Harmony", 1570, 2240)));
pageSize_.insert(std::make_pair("ISO_C10", std::make_shared<PrintPageSize>("ISO_C10", "Harmony", 1100, 1570)));
// North America
pageSize_.insert(std::make_pair("NA_LETTER", std::make_shared<PrintPageSize>("NA_LETTER", "Harmony", 8500, 11000)));
pageSize_.insert(
std::make_pair("NA_GOVT_LETTER", std::make_shared<PrintPageSize>("NA_GOVT_LETTER", "Harmony", 8000, 10500)));
pageSize_.insert(std::make_pair("NA_LEGAL", std::make_shared<PrintPageSize>("NA_LEGAL", "Harmony", 8500, 14000)));
pageSize_.insert(
std::make_pair("NA_JUNIOR_LEGAL", std::make_shared<PrintPageSize>("NA_JUNIOR_LEGAL", "Harmony", 8000, 5000)));
pageSize_.insert(
std::make_pair("NA_LEDGER", std::make_shared<PrintPageSize>("NA_LEDGER", "Harmony", 17000, 11000)));
pageSize_.insert(
std::make_pair("NA_TABLOID", std::make_shared<PrintPageSize>("NA_TABLOID", "Harmony", 11000, 17000)));
pageSize_.insert(
std::make_pair("NA_INDEX_3X5", std::make_shared<PrintPageSize>("NA_INDEX_3X5", "Harmony", 3000, 5000)));
pageSize_.insert(
std::make_pair("NA_INDEX_4X6", std::make_shared<PrintPageSize>("NA_INDEX_4X6", "Harmony", 4000, 6000)));
pageSize_.insert(
std::make_pair("NA_INDEX_5X8", std::make_shared<PrintPageSize>("NA_INDEX_5X8", "Harmony", 5000, 8000)));
pageSize_.insert(std::make_pair("NA_QUARTO", std::make_shared<PrintPageSize>("NA_QUARTO", "Harmony", 8000, 10000)));
pageSize_.insert(
std::make_pair("NA_FOOLSCAP", std::make_shared<PrintPageSize>("NA_FOOLSCAP", "Harmony", 8000, 13000)));
// Chinese
pageSize_.insert(std::make_pair("ROC_8K", std::make_shared<PrintPageSize>("ROC_8K", "Harmony", 10629, 15354)));
pageSize_.insert(std::make_pair("ROC_16K", std::make_shared<PrintPageSize>("ROC_16K", "Harmony", 7677, 10629)));
pageSize_.insert(std::make_pair("PRC_1", std::make_shared<PrintPageSize>("PRC_1", "Harmony", 4015, 6496)));
pageSize_.insert(std::make_pair("PRC_2", std::make_shared<PrintPageSize>("PRC_2", "Harmony", 4015, 6929)));
pageSize_.insert(std::make_pair("PRC_3", std::make_shared<PrintPageSize>("PRC_3", "Harmony", 4921, 6929)));
pageSize_.insert(std::make_pair("PRC_4", std::make_shared<PrintPageSize>("PRC_4", "Harmony", 4330, 8189)));
pageSize_.insert(std::make_pair("PRC_5", std::make_shared<PrintPageSize>("PRC_5", "Harmony", 4330, 8661)));
pageSize_.insert(std::make_pair("PRC_6", std::make_shared<PrintPageSize>("PRC_6", "Harmony", 4724, 12599)));
pageSize_.insert(std::make_pair("PRC_7", std::make_shared<PrintPageSize>("PRC_7", "Harmony", 6299, 9055)));
pageSize_.insert(std::make_pair("PRC_8", std::make_shared<PrintPageSize>("PRC_8", "Harmony", 4724, 12165)));
pageSize_.insert(std::make_pair("PRC_9", std::make_shared<PrintPageSize>("PRC_9", "Harmony", 9016, 12756)));
pageSize_.insert(std::make_pair("PRC_10", std::make_shared<PrintPageSize>("PRC_10", "Harmony", 12756, 18032)));
pageSize_.insert(std::make_pair("PRC_16K", std::make_shared<PrintPageSize>("PRC_16K", "Harmony", 5749, 8465)));
pageSize_.insert(
std::make_pair("OM_PA_KAI", std::make_shared<PrintPageSize>("OM_PA_KAI", "Harmony", 10512, 15315)));
pageSize_.insert(
std::make_pair("OM_DAI_PA_KAI", std::make_shared<PrintPageSize>("OM_DAI_PA_KAI", "Harmony", 10827, 15551)));
pageSize_.insert(
std::make_pair("OM_JUURO_KU_KAI", std::make_shared<PrintPageSize>("OM_JUURO_KU_KAI", "Harmony", 7796, 10827)));
// Japanese
pageSize_.insert(std::make_pair("JIS_B10", std::make_shared<PrintPageSize>("JIS_B10", "Harmony", 1259, 1772)));
pageSize_.insert(std::make_pair("JIS_B9", std::make_shared<PrintPageSize>("JIS_B9", "Harmony", 1772, 2520)));
pageSize_.insert(std::make_pair("JIS_B8", std::make_shared<PrintPageSize>("JIS_B8", "Harmony", 2520, 3583)));
pageSize_.insert(std::make_pair("JIS_B7", std::make_shared<PrintPageSize>("JIS_B7", "Harmony", 3583, 5049)));
pageSize_.insert(std::make_pair("JIS_B6", std::make_shared<PrintPageSize>("JIS_B6", "Harmony", 5049, 7165)));
pageSize_.insert(std::make_pair("JIS_B5", std::make_shared<PrintPageSize>("JIS_B5", "Harmony", 7165, 10118)));
pageSize_.insert(std::make_pair("JIS_B4", std::make_shared<PrintPageSize>("JIS_B4", "Harmony", 10118, 14331)));
pageSize_.insert(std::make_pair("JIS_B3", std::make_shared<PrintPageSize>("JIS_B3", "Harmony", 14331, 20276)));
pageSize_.insert(std::make_pair("JIS_B2", std::make_shared<PrintPageSize>("JIS_B2", "Harmony", 20276, 28661)));
pageSize_.insert(std::make_pair("JIS_B1", std::make_shared<PrintPageSize>("JIS_B1", "Harmony", 28661, 40551)));
pageSize_.insert(std::make_pair("JIS_B0", std::make_shared<PrintPageSize>("JIS_B0", "Harmony", 40551, 57323)));
pageSize_.insert(std::make_pair("JIS_EXEC", std::make_shared<PrintPageSize>("JIS_EXEC", "Harmony", 8504, 12992)));
pageSize_.insert(std::make_pair("JPN_CHOU4", std::make_shared<PrintPageSize>("JPN_CHOU4", "Harmony", 3543, 8071)));
pageSize_.insert(std::make_pair("JPN_CHOU3", std::make_shared<PrintPageSize>("JPN_CHOU3", "Harmony", 4724, 9252)));
pageSize_.insert(std::make_pair("JPN_CHOU2", std::make_shared<PrintPageSize>("JPN_CHOU2", "Harmony", 4374, 5748)));
pageSize_.insert(
std::make_pair("JPN_HAGAKI", std::make_shared<PrintPageSize>("JPN_HAGAKI", "Harmony", 3937, 5827)));
pageSize_.insert(
std::make_pair("JPN_OUFUKU", std::make_shared<PrintPageSize>("JPN_OUFUKU", "Harmony", 5827, 7874)));
pageSize_.insert(std::make_pair("JPN_KAHU", std::make_shared<PrintPageSize>("JPN_KAHU", "Harmony", 9449, 12681)));
pageSize_.insert(std::make_pair("JPN_KAKU2", std::make_shared<PrintPageSize>("JPN_KAKU2", "Harmony", 9449, 13071)));
pageSize_.insert(std::make_pair("JPN_YOU4", std::make_shared<PrintPageSize>("JPN_YOU4", "Harmony", 4134, 9252)));
}
PrintPageSize::PrintPageSize() : id_(""), name_("PrintPageSize"), width_(0), height_(0) {}
PrintPageSize::PrintPageSize(PAGE_SIZE_ID id, DiscretePageName name, uint32_t width, uint32_t height)
{
id_ = id;
name_ = name;
width_ = width;
height_ = height;
}
PrintPageSize PrintPageSize::GetPageSize(PageSizeId id)
{
uint32_t pageSizeId = (uint32_t)id;
if (pageSizeId < (uint32_t)sizeof(PAGE_SIZE_TABLE)) {
std::map<PAGE_SIZE_ID, std::shared_ptr<PrintPageSize>>::iterator iter;
iter = pageSize_.find(PAGE_SIZE_TABLE[pageSizeId]);
if (iter != pageSize_.end()) {
return *(iter->second);
}
}
PrintPageSize printPageSize;
return printPageSize;
}
PrintPageSize::PrintPageSize(const PrintPageSize &right) PrintPageSize::PrintPageSize(const PrintPageSize &right)
{ {
@ -41,7 +169,7 @@ PrintPageSize &PrintPageSize::operator=(const PrintPageSize &right)
PrintPageSize::~PrintPageSize() {} PrintPageSize::~PrintPageSize() {}
void PrintPageSize::SetId(uint32_t id) void PrintPageSize::SetId(const std::string &id)
{ {
id_ = id; id_ = id;
} }
@ -61,7 +189,7 @@ void PrintPageSize::SetHeight(uint32_t height)
height_ = height; height_ = height;
} }
uint32_t PrintPageSize::GetId() const const std::string &PrintPageSize::GetId() const
{ {
return id_; return id_;
} }
@ -83,7 +211,7 @@ uint32_t PrintPageSize::GetHeight() const
void PrintPageSize::Dump() void PrintPageSize::Dump()
{ {
PRINT_HILOGD("top_ = %{public}d", id_); PRINT_HILOGD("top_ = %{public}s", id_.c_str());
PRINT_HILOGD("name_ = %{public}s", name_.c_str()); PRINT_HILOGD("name_ = %{public}s", name_.c_str());
PRINT_HILOGD("width_ = %{public}d", width_); PRINT_HILOGD("width_ = %{public}d", width_);
PRINT_HILOGD("height_ = %{public}d", height_); PRINT_HILOGD("height_ = %{public}d", height_);

View File

@ -1,4 +1,4 @@
#include "preview_attribute.h" #include "print_preview_attribute.h"
#include <cstdint> #include <cstdint>
#include <string> #include <string>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -17,9 +17,9 @@
#include <uv.h> #include <uv.h>
#include "napi_print_utils.h"
#include "print_job.h" #include "print_job.h"
#include "print_log.h" #include "print_log.h"
#include "print_napi_utils.h"
#include "print_page_size.h" #include "print_page_size.h"
#include "print_resolution.h" #include "print_resolution.h"
#include "printer_capability.h" #include "printer_capability.h"

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2022 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.
*/
#include "print_sa_death_recipient.h"
#include "print_log.h"
#include "print_manager_client.h"
namespace OHOS::Print {
PrintSaDeathRecipient::PrintSaDeathRecipient() {}
void PrintSaDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &object)
{
PRINT_HILOGE("PrintSaDeathRecipient on remote systemAbility died.");
PrintManagerClient::GetInstance()->OnRemoteSaDied(object);
}
} // namespace OHOS::Print

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -28,7 +28,7 @@
namespace OHOS::Print { namespace OHOS::Print {
using namespace OHOS::HiviewDFX; using namespace OHOS::HiviewDFX;
PrintServiceProxy::PrintServiceProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<PrintServiceInterface>(object) {} PrintServiceProxy::PrintServiceProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IPrintService>(object) {}
int32_t PrintServiceProxy::StartPrint() int32_t PrintServiceProxy::StartPrint()
{ {
@ -289,7 +289,7 @@ bool PrintServiceProxy::QueryPrinterCapability(uint32_t printerId, PrinterCapabi
std::vector<PrintPageSize> pageSizeList; std::vector<PrintPageSize> pageSizeList;
for (uint32_t i = 0; i < arraypageSizeLength; i++) { for (uint32_t i = 0; i < arraypageSizeLength; i++) {
PrintPageSize pageSize; PrintPageSize pageSize;
pageSize.SetId(reply.ReadUint32()); pageSize.SetId(reply.ReadString());
pageSize.SetName(reply.ReadString()); pageSize.SetName(reply.ReadString());
pageSize.SetWidth(reply.ReadUint32()); pageSize.SetWidth(reply.ReadUint32());
pageSize.SetHeight(reply.ReadUint32()); pageSize.SetHeight(reply.ReadUint32());
@ -339,7 +339,7 @@ bool PrintServiceProxy::CheckPermission()
} }
bool PrintServiceProxy::On( bool PrintServiceProxy::On(
const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<PrintNotifyInterface> &listener) const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<IPrintCallback> &listener)
{ {
PRINT_HILOGD("PrintServiceProxy::On listener=%{public}p", listener.GetRefPtr()); PRINT_HILOGD("PrintServiceProxy::On listener=%{public}p", listener.GetRefPtr());
MessageParcel data, reply; MessageParcel data, reply;
@ -412,7 +412,7 @@ bool PrintServiceProxy::Off(const std::string &type)
return true; return true;
} }
bool PrintServiceProxy::RegisterExtCallback(uint32_t callbackId, const sptr<PrintExtcbInterface> &listener) bool PrintServiceProxy::RegisterExtCallback(uint32_t callbackId, const sptr<IPrintExtensionCallback> &listener)
{ {
PRINT_HILOGD("PrintServiceProxy::RegisterExtCallback in"); PRINT_HILOGD("PrintServiceProxy::RegisterExtCallback in");
MessageParcel data, reply; MessageParcel data, reply;
@ -493,7 +493,7 @@ void PrintServiceProxy::BuildParcelFromPrintJob(MessageParcel &data, const Print
PrintPageSize pageSize; PrintPageSize pageSize;
jobinfo.GetPageSize(pageSize); jobinfo.GetPageSize(pageSize);
data.WriteUint32(pageSize.GetId()); data.WriteString(pageSize.GetId());
data.WriteString(pageSize.GetName()); data.WriteString(pageSize.GetName());
data.WriteUint32(pageSize.GetWidth()); data.WriteUint32(pageSize.GetWidth());
data.WriteUint32(pageSize.GetHeight()); data.WriteUint32(pageSize.GetHeight());
@ -554,7 +554,7 @@ void PrintServiceProxy::BuildParcelFromPrinterInfo(MessageParcel &data, const Pr
data.WriteUint32(margin.GetRight()); data.WriteUint32(margin.GetRight());
for (uint32_t i = 0; i < pageSizeLength; i++) { for (uint32_t i = 0; i < pageSizeLength; i++) {
data.WriteUint32(pageSizeList[i].GetId()); data.WriteString(pageSizeList[i].GetId());
data.WriteString(pageSizeList[i].GetName()); data.WriteString(pageSizeList[i].GetName());
data.WriteUint32(pageSizeList[i].GetWidth()); data.WriteUint32(pageSizeList[i].GetWidth());
data.WriteUint32(pageSizeList[i].GetHeight()); data.WriteUint32(pageSizeList[i].GetHeight());

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2022 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.
*/
#include "print_sync_load_callback.h"
#include "iservice_registry.h"
#include "isystem_ability_load_callback.h"
#include "print_log.h"
#include "print_manager_client.h"
#include "system_ability_definition.h"
namespace OHOS::Print {
void PrintSyncLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject)
{
if (systemAbilityId != PRINT_SERVICE_ID) {
PRINT_HILOGE("start systemAbilityId is not print server");
return;
}
PrintManagerClient::GetInstance()->LoadServerSuccess();
}
void PrintSyncLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId)
{
if (systemAbilityId != PRINT_SERVICE_ID) {
PRINT_HILOGE("start systemAbilityId is not print server");
return;
}
PrintManagerClient::GetInstance()->LoadServerFail();
}
} // namespace OHOS::Print

View File

@ -15,9 +15,30 @@
#include "printer_capability.h" #include "printer_capability.h"
#include "napi_print_utils.h"
#include "print_log.h" #include "print_log.h"
namespace OHOS::Print { namespace OHOS::Print {
static constexpr const char *PARAM_CAPABILITY_MINMARGIN = "minMargin";
static constexpr const char *PARAM_CAPABILITY_PAGESIZE = "pageSize";
static constexpr const char *PARAM_CAPABILITY_RESOLUTION = "resolution";
static constexpr const char *PARAM_CAPABILITY_COLORMODE = "colorMode";
static constexpr const char *PARAM_CAPABILITY_DUPLEXMODE = "duplexMode";
static constexpr const char *PARAM_PAGESIZE_ID = "id";
static constexpr const char *PARAM_PAGESIZE_NAME = "name";
static constexpr const char *PARAM_PAGESIZE_WIDTH = "width";
static constexpr const char *PARAM_PAGESIZE_HEIGHT = "height";
static constexpr const char *PARAM_RESOLUTION_ID = "id";
static constexpr const char *PARAM_RESOLUTION_HORIZONTALDPI = "horizontalDpi";
static constexpr const char *PARAM_RESOLUTION_VERTICALDPI = "verticalDpi";
static constexpr const char *PARAM_MARGIN_TOP = "top";
static constexpr const char *PARAM_MARGIN_BOTTOM = "bottom";
static constexpr const char *PARAM_MARGIN_LEFT = "left";
static constexpr const char *PARAM_MARGIN_RIGHT = "right";
PrinterCapability::PrinterCapability() : minMargin_(), colorMode_(0), duplexMode_(0) PrinterCapability::PrinterCapability() : minMargin_(), colorMode_(0), duplexMode_(0)
{ {
pageSizeList_.clear(); pageSizeList_.clear();
@ -47,7 +68,7 @@ PrinterCapability &PrinterCapability::operator=(const PrinterCapability &right)
PrinterCapability::~PrinterCapability() {} PrinterCapability::~PrinterCapability() {}
void PrinterCapability::SetMinMargin(PrintMargin &minMargin) void PrinterCapability::SetMinMargin(const PrintMargin &minMargin)
{ {
minMargin_ = minMargin; minMargin_ = minMargin;
} }
@ -101,6 +122,367 @@ uint32_t PrinterCapability::GetDuplexMode() const
return duplexMode_; return duplexMode_;
} }
void PrinterCapability::ConvertToParcel(MessageParcel &reply) const
{
std::vector<PrintPageSize> pageSizeList;
std::vector<PrintResolution> resolutionList;
GetPageSize(pageSizeList);
GetResolution(resolutionList);
uint32_t arraypageSizeLength = pageSizeList.size();
reply.WriteUint32(arraypageSizeLength);
uint32_t resolutionLength = resolutionList.size();
reply.WriteUint32(resolutionLength);
PrintMargin minMargin;
GetMinMargin(minMargin);
reply.WriteUint32(minMargin.GetTop());
reply.WriteUint32(minMargin.GetBottom());
reply.WriteUint32(minMargin.GetLeft());
reply.WriteUint32(minMargin.GetRight());
for (uint32_t i = 0; i < arraypageSizeLength; i++) {
reply.WriteString(pageSizeList[i].GetId());
reply.WriteString(pageSizeList[i].GetName());
reply.WriteUint32(pageSizeList[i].GetWidth());
reply.WriteUint32(pageSizeList[i].GetHeight());
}
for (uint32_t i = 0; i < resolutionLength; i++) {
reply.WriteUint32(resolutionList[i].GetId());
reply.WriteUint32(resolutionList[i].GetHorizontalDpi());
reply.WriteUint32(resolutionList[i].GetVerticalDpi());
}
reply.WriteUint32(GetColorMode());
reply.WriteUint32(GetDuplexMode());
}
void PrinterCapability::BuildFromParcel(MessageParcel &data)
{
uint32_t arraypageSizeLength = data.ReadUint32();
uint32_t resolutionLength = data.ReadUint32();
PRINT_HILOGD("PrintServiceProxy, arraypageSizeLength = %{public}d", arraypageSizeLength);
PRINT_HILOGD("PrintServiceProxy, resolutionLength = %{public}d", resolutionLength);
PrintMargin margin;
margin.SetTop(data.ReadUint32());
margin.SetBottom(data.ReadUint32());
margin.SetLeft(data.ReadUint32());
margin.SetRight(data.ReadUint32());
SetMinMargin(margin);
if (arraypageSizeLength > 0) {
std::vector<PrintPageSize> pageSizeList;
for (uint32_t i = 0; i < arraypageSizeLength; i++) {
PrintPageSize pageSize;
pageSize.SetId(data.ReadString());
pageSize.SetName(data.ReadString());
pageSize.SetWidth(data.ReadUint32());
pageSize.SetHeight(data.ReadUint32());
pageSizeList.push_back(pageSize);
}
SetPageSize(pageSizeList);
}
if (resolutionLength > 0) {
std::vector<PrintResolution> resolutionList;
for (uint32_t i = 0; i < resolutionLength; i++) {
PrintResolution res;
res.SetId(data.ReadUint32());
res.SetHorizontalDpi(data.ReadUint32());
res.SetVerticalDpi(data.ReadUint32());
resolutionList.push_back(res);
}
SetResolution(resolutionList);
}
SetColorMode(data.ReadUint32());
SetDuplexMode(data.ReadUint32());
Dump();
}
void PrinterCapability::ConvertToJs(napi_env env, napi_value *result) const
{
PRINT_HILOGD("Enter ConvertToJs---->");
napi_value resultPrintMargin;
napi_create_object(env, result);
napi_create_object(env, &resultPrintMargin);
napi_value arrPageSize, arrResolution;
napi_status status = napi_create_array(env, &arrPageSize);
status = napi_create_array(env, &arrResolution);
PrintNapiUtils::SetUint32Property(env, *result, "colorMode", GetColorMode());
PrintNapiUtils::SetUint32Property(env, *result, "duplexMode", GetDuplexMode());
PrintMargin margin;
GetMinMargin(margin);
PrintNapiUtils::SetUint32Property(env, resultPrintMargin, "top", margin.GetTop());
PrintNapiUtils::SetUint32Property(env, resultPrintMargin, "bottom", margin.GetBottom());
PrintNapiUtils::SetUint32Property(env, resultPrintMargin, "left", margin.GetLeft());
PrintNapiUtils::SetUint32Property(env, resultPrintMargin, "right", margin.GetRight());
std::vector<PrintPageSize> pageSize;
GetPageSize(pageSize);
uint32_t printerCapabilityLength = pageSize.size();
for (uint32_t i = 0; i < printerCapabilityLength; i++) {
napi_value resultPrinterPageSize;
napi_create_object(env, &resultPrinterPageSize);
PrintNapiUtils::SetStringPropertyUtf8(env, resultPrinterPageSize, "id", pageSize[i].GetId().c_str());
PrintNapiUtils::SetStringPropertyUtf8(env, resultPrinterPageSize, "name", pageSize[i].GetName().c_str());
PrintNapiUtils::SetUint32Property(env, resultPrinterPageSize, "width", pageSize[i].GetWidth());
PrintNapiUtils::SetUint32Property(env, resultPrinterPageSize, "height", pageSize[i].GetHeight());
status = napi_set_element(env, arrPageSize, i, resultPrinterPageSize);
}
std::vector<PrintResolution> resolutionList;
GetResolution(resolutionList);
uint32_t printerCapabilityresolutionLength = resolutionList.size();
for (uint32_t i = 0; i < printerCapabilityresolutionLength; i++) {
napi_value resultPrinterResolution;
napi_create_object(env, &resultPrinterResolution);
PrintNapiUtils::SetUint32Property(env, resultPrinterResolution, "id", resolutionList[i].GetId());
PrintNapiUtils::SetUint32Property(
env, resultPrinterResolution, "horizontalDpi", resolutionList[i].GetHorizontalDpi());
PrintNapiUtils::SetUint32Property(
env, resultPrinterResolution, "verticalDpi", resolutionList[i].GetVerticalDpi());
status = napi_set_element(env, arrResolution, i, resultPrinterResolution);
}
status = napi_set_named_property(env, *result, "minMargin", resultPrintMargin);
PRINT_HILOGD("output ---- status[%{public}d]", status);
napi_set_named_property(env, *result, "pageSize", arrPageSize);
napi_set_named_property(env, *result, "resolution", arrResolution);
PRINT_HILOGD("ouput over---->");
}
void PrinterCapability::BuildFromJs(napi_env env, napi_value capValue)
{
ParseCapability(env, capValue);
}
bool PrinterCapability::ParseCapability(napi_env env, napi_value capValue)
{
if (!ParseCapabilityParam(env, capValue)) {
PRINT_HILOGD("ParseCapabilityParam is error!");
return false;
}
SetColorMode(PrintNapiUtils::GetUint32Property(env, capValue, PARAM_CAPABILITY_COLORMODE));
SetDuplexMode(PrintNapiUtils::GetUint32Property(env, capValue, PARAM_CAPABILITY_DUPLEXMODE));
PRINT_HILOGD("capability_value colorMode value is %{public}d", GetColorMode());
PRINT_HILOGD("capability_value duplexMode value is %{public}d", GetDuplexMode());
return true;
}
bool PrinterCapability::ParseCapabilityParam(napi_env env, napi_value capValue)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_MINMARGIN);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_object) {
PRINT_HILOGD("error param_one");
return false;
} else {
PrintMargin margin;
if (!ParseMargin(env, param_one, margin)) {
PRINT_HILOGD("ParseCapability type error!");
return false;
}
SetMinMargin(margin);
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_PAGESIZE);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_object) {
PRINT_HILOGD("error param_two");
return false;
} else {
bool isArray = false;
napi_is_array(env, param_two, &isArray);
if (!isArray) {
PRINT_HILOGD("ParsePageSize type error!");
return false;
}
std::vector<PrintPageSize> pageSizeList;
uint32_t arrayLength = 0;
napi_get_array_length(env, param_two, &arrayLength);
for (uint32_t i = 0; i < arrayLength; i++) {
napi_value pageSizeValue;
PrintPageSize pageSize;
napi_get_element(env, param_two, i, &pageSizeValue);
if (!ParsePageSize(env, pageSizeValue, pageSize)) {
PRINT_HILOGD("ParsePageSize type error!");
return false;
}
pageSizeList.push_back(pageSize);
}
SetPageSize(pageSizeList);
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_RESOLUTION);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_object) {
PRINT_HILOGD("error param_three");
return false;
} else {
bool isReArray = false;
napi_is_array(env, param_three, &isReArray);
if (!isReArray) {
PRINT_HILOGD("PrintResolution type error!");
return false;
}
std::vector<PrintResolution> resolutionList;
uint32_t arrayReLength = 0;
napi_get_array_length(env, param_three, &arrayReLength);
for (uint32_t i = 0; i < arrayReLength; i++) {
napi_value reValue;
PrintResolution resolution;
napi_get_element(env, param_three, i, &reValue);
if (!ParseResolution(env, reValue, resolution)) {
PRINT_HILOGD("PrintResolution type error!");
return false;
}
resolutionList.push_back(resolution);
}
SetResolution(resolutionList);
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_COLORMODE);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
napi_value param_five = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_DUPLEXMODE);
if (PrintNapiUtils::GetValueType(env, param_five) != napi_number) {
PRINT_HILOGD("error param_five");
return false;
}
auto names = PrintNapiUtils::GetPropertyNames(env, capValue);
return true;
}
bool PrinterCapability::ParseMargin(napi_env env, napi_value marginValue, PrintMargin &margin)
{
if (!ParseMarginParam(env, marginValue, margin)) {
PRINT_HILOGD("ParseResolutionParam is error!");
return false;
}
margin.SetTop(PrintNapiUtils::GetUint32Property(env, marginValue, PARAM_MARGIN_TOP));
margin.SetBottom(PrintNapiUtils::GetUint32Property(env, marginValue, PARAM_MARGIN_BOTTOM));
margin.SetLeft(PrintNapiUtils::GetUint32Property(env, marginValue, PARAM_MARGIN_LEFT));
margin.SetRight(PrintNapiUtils::GetUint32Property(env, marginValue, PARAM_MARGIN_RIGHT));
PRINT_HILOGD("printerMargin_value GetTop value is %{public}d", margin.GetTop());
PRINT_HILOGD("printerMargin_value GetBottom value is %{public}d", margin.GetBottom());
PRINT_HILOGD("printerMargin_value GetLeft value is %{public}d", margin.GetLeft());
PRINT_HILOGD("printerMargin_value GetRight value is %{public}d", margin.GetRight());
return true;
}
bool PrinterCapability::ParseMarginParam(napi_env env, napi_value marginValue, PrintMargin &margin)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, marginValue, PARAM_MARGIN_TOP);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_number) {
PRINT_HILOGD("error param_one");
return false;
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, marginValue, PARAM_MARGIN_BOTTOM);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_number) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, marginValue, PARAM_MARGIN_LEFT);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, marginValue, PARAM_MARGIN_RIGHT);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
auto names = PrintNapiUtils::GetPropertyNames(env, marginValue);
PRINT_HILOGD("current margin paramster name list size = %{public}zu", names.size());
return true;
}
bool PrinterCapability::ParsePageSize(napi_env env, napi_value capValue, PrintPageSize &pageSize)
{
if (!ParsePageSizeParam(env, capValue, pageSize)) {
PRINT_HILOGD("ParsePageSizeParam is error!");
return false;
}
pageSize.SetId(PrintNapiUtils::GetStringPropertyUtf8(env, capValue, PARAM_PAGESIZE_ID));
pageSize.SetName(PrintNapiUtils::GetStringPropertyUtf8(env, capValue, PARAM_PAGESIZE_NAME));
pageSize.SetWidth(PrintNapiUtils::GetUint32Property(env, capValue, PARAM_PAGESIZE_WIDTH));
pageSize.SetHeight(PrintNapiUtils::GetUint32Property(env, capValue, PARAM_PAGESIZE_HEIGHT));
PRINT_HILOGD("printerPageSize_value GetId value is %{public}s", pageSize.GetId().c_str());
PRINT_HILOGD("printerPageSize_value GetName value is %{public}s", pageSize.GetName().c_str());
PRINT_HILOGD("printerPageSize_value GetWidth value is %{public}d", pageSize.GetWidth());
PRINT_HILOGD("printerPageSize_value GetHeight value is %{public}d", pageSize.GetHeight());
return true;
}
bool PrinterCapability::ParsePageSizeParam(napi_env env, napi_value capValue, PrintPageSize &pageSize)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_PAGESIZE_ID);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_number) {
PRINT_HILOGD("error param_one");
return false;
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_PAGESIZE_NAME);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_string) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_PAGESIZE_WIDTH);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_PAGESIZE_HEIGHT);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
return true;
}
bool PrinterCapability::ParseResolution(napi_env env, napi_value reValue, PrintResolution &resolution)
{
if (!ParseResolutionParam(env, reValue, resolution)) {
PRINT_HILOGD("ParseResolutionParam is error!");
return false;
}
resolution.SetId(PrintNapiUtils::GetUint32Property(env, reValue, PARAM_RESOLUTION_ID));
resolution.SetHorizontalDpi(PrintNapiUtils::GetUint32Property(env, reValue, PARAM_RESOLUTION_HORIZONTALDPI));
resolution.SetVerticalDpi(PrintNapiUtils::GetUint32Property(env, reValue, PARAM_RESOLUTION_VERTICALDPI));
PRINT_HILOGD("printerResolution_value GetId value is %{public}d", resolution.GetId());
PRINT_HILOGD("printerResolution_value GetHorizontalDpi value is %{public}d", resolution.GetHorizontalDpi());
PRINT_HILOGD("printerResolution_value GetVerticalDpi value is %{public}d", resolution.GetVerticalDpi());
return true;
}
bool PrinterCapability::ParseResolutionParam(napi_env env, napi_value reValue, PrintResolution &resolution)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, reValue, PARAM_RESOLUTION_ID);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_number) {
PRINT_HILOGD("error param_one");
return false;
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, reValue, PARAM_RESOLUTION_HORIZONTALDPI);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_number) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, reValue, PARAM_RESOLUTION_VERTICALDPI);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
return true;
}
void PrinterCapability::Dump() void PrinterCapability::Dump()
{ {
PRINT_HILOGD("colorMode_ = %{public}d", colorMode_); PRINT_HILOGD("colorMode_ = %{public}d", colorMode_);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -18,7 +18,6 @@
#include "print_constant.h" #include "print_constant.h"
#include "print_log.h" #include "print_log.h"
namespace OHOS::Print { namespace OHOS::Print {
PrinterInfo::PrinterInfo() PrinterInfo::PrinterInfo()
: printerId_(0), printerName_(""), printerIcon_(0), printerState_(PRINTER_UNKNOWN), description_("") : printerId_(0), printerName_(""), printerIcon_(0), printerState_(PRINTER_UNKNOWN), description_("")

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021 Huawei Device Co., Ltd. # Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
@ -92,10 +92,11 @@ ohos_shared_library("print_extension") {
] ]
sources = [ sources = [
"//base/print/print/frameworks/kits/extension/src/js_print_extension.cpp", "src/js_print_extension.cpp",
"//base/print/print/frameworks/kits/extension/src/js_print_extension_context.cpp", "src/js_print_extension_context.cpp",
"//base/print/print/frameworks/kits/extension/src/print_extension.cpp", "src/print_extension.cpp",
"//base/print/print/frameworks/kits/extension/src/print_extension_context.cpp", "src/print_extension_context.cpp",
"src/js_print_callback.cpp",
] ]
configs = [ ":ability_config" ] configs = [ ":ability_config" ]
public_configs = [ public_configs = [

View File

@ -0,0 +1,63 @@
/*
* Copyright (c) 2022 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.
*/
#ifndef JS_PRINT_CALLBACK_H
#define JS_PRINT_CALLBACK_H
#include <memory>
#include <mutex>
#include <uv.h>
#include <vector>
#include "napi/native_api.h"
class NativeValue;
class NativeEngine;
namespace OHOS {
namespace AbilityRuntime {
class JsRuntime;
class JsPrintCallback : public std::enable_shared_from_this<JsPrintCallback> {
public:
explicit JsPrintCallback(JsRuntime &jsRutime);
~JsPrintCallback() = default;
NativeValue *Exec(NativeValue *jsObj, const std::string &name, NativeValue *const *argv = nullptr, size_t argc = 0,
bool isSync = true);
private:
struct Container {
std::shared_ptr<JsPrintCallback> self;
NativeEngine *nativeEngine;
NativeValue *jsObj;
NativeValue *jsMethod;
NativeValue *const *argv;
size_t argc;
NativeValue *jsResult;
bool isSync;
bool isCompleted;
};
JsRuntime &jsRuntime_;
uv_work_t *jsWorker_;
JsPrintCallback::Container container_;
std::mutex conditionMutex_;
std::condition_variable syncCon_;
static constexpr int SYNC_TIME_OUT = 1000;
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // JS_PRINT_CALLBACK_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -108,6 +108,7 @@ public:
private: private:
NativeValue *CallObjectMethod(const char *name, NativeValue *const *argv = nullptr, size_t argc = 0); NativeValue *CallObjectMethod(const char *name, NativeValue *const *argv = nullptr, size_t argc = 0);
void RegisterAllCallback();
void GetSrcPath(std::string &srcPath); void GetSrcPath(std::string &srcPath);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -0,0 +1,111 @@
/*
* Copyright (c) 2022 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.
*/
#include "js_print_callback.h"
#include "ability_info.h"
#include "iprint_extension_callback.h"
#include "js_print_extension_context.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "napi_common_util.h"
#include "napi_common_want.h"
#include "napi_print_utils.h"
#include "napi_remote_object.h"
#include "print_log.h"
#include "print_manager_client.h"
namespace OHOS {
namespace AbilityRuntime {
using namespace OHOS::AppExecFwk;
using namespace OHOS::Print;
JsPrintCallback::JsPrintCallback(JsRuntime &jsRuntime) : jsRuntime_(jsRuntime) {}
NativeValue *JsPrintCallback::Exec(
NativeValue *jsObj, const std::string &name, NativeValue *const *argv, size_t argc, bool isSync)
{
HandleScope handleScope(jsRuntime_);
NativeObject *obj = ConvertNativeValueTo<NativeObject>(jsObj);
if (obj == nullptr) {
PRINT_HILOGE("Failed to get PrintExtension object");
return nullptr;
}
NativeValue *method = obj->GetProperty(name.c_str());
if (method == nullptr) {
PRINT_HILOGE("Failed to get '%{public}s' from PrintExtension object", name.c_str());
return nullptr;
}
PRINT_HILOGD("%{public}s callback in", name.c_str());
NativeEngine *nativeEngine = &jsRuntime_.GetNativeEngine();
uv_loop_s *loop = nullptr;
napi_get_uv_event_loop(reinterpret_cast<napi_env>(nativeEngine), &loop);
if (loop == nullptr) {
PRINT_HILOGE("Failed to get uv event loop");
return nullptr;
}
jsWorker_ = new (std::nothrow) uv_work_t;
if (jsWorker_ == nullptr) {
PRINT_HILOGE("Failed to create uv work");
return nullptr;
}
container_.self = shared_from_this();
container_.nativeEngine = nativeEngine;
container_.jsObj = jsObj;
container_.jsMethod = method;
container_.argv = argv;
container_.argc = argc;
container_.jsResult = nullptr;
container_.isSync = isSync;
container_.isCompleted = false;
jsWorker_->data = &container_;
uv_queue_work(
loop, jsWorker_, [](uv_work_t *work) {},
[](uv_work_t *work, int statusInt) {
auto container = reinterpret_cast<JsPrintCallback::Container *>(work->data);
if (container != nullptr) {
container->jsResult = container->nativeEngine->CallFunction(
container->jsObj, container->jsMethod, container->argv, container->argc);
container->isCompleted = true;
if (container->isSync) {
container->self = nullptr;
} else {
std::unique_lock<std::mutex> lock(container->self->conditionMutex_);
container->self->syncCon_.notify_one();
}
}
});
if (isSync) {
std::unique_lock<std::mutex> conditionLock(conditionMutex_);
auto waitStatus = syncCon_.wait_for(
conditionLock, std::chrono::milliseconds(SYNC_TIME_OUT), [this]() { return container_.isCompleted; });
if (!waitStatus) {
PRINT_HILOGE("print server load sa timeout");
return nullptr;
}
return container_.jsResult;
}
return nullptr;
}
} // namespace AbilityRuntime
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -16,6 +16,8 @@
#include "js_print_extension.h" #include "js_print_extension.h"
#include "ability_info.h" #include "ability_info.h"
#include "iprint_extension_callback.h"
#include "js_print_callback.h"
#include "js_print_extension_context.h" #include "js_print_extension_context.h"
#include "js_runtime.h" #include "js_runtime.h"
#include "js_runtime_utils.h" #include "js_runtime_utils.h"
@ -23,11 +25,10 @@
#include "napi/native_node_api.h" #include "napi/native_node_api.h"
#include "napi_common_util.h" #include "napi_common_util.h"
#include "napi_common_want.h" #include "napi_common_want.h"
#include "napi_print_utils.h"
#include "napi_remote_object.h" #include "napi_remote_object.h"
#include "print_extcb_interface.h"
#include "print_log.h" #include "print_log.h"
#include "print_manager_client.h" #include "print_manager_client.h"
#include "print_napi_utils.h"
namespace OHOS { namespace OHOS {
namespace AbilityRuntime { namespace AbilityRuntime {
@ -123,88 +124,7 @@ void JsPrintExtension::OnStart(const AAFwk::Want &want)
NativeValue *argv[] = { nativeWant }; NativeValue *argv[] = { nativeWant };
CallObjectMethod("onCreated", argv, ARGC_ONE); CallObjectMethod("onCreated", argv, ARGC_ONE);
PRINT_HILOGD("%{public}s end.", __func__); PRINT_HILOGD("%{public}s end.", __func__);
PrintManagerClient::GetInstance()->RegisterExtCallback(PRINT_EXTCB_START_DISCOVERY, []() -> bool { RegisterAllCallback();
PRINT_HILOGD("jsExtension_->CallObjectMethod");
HandleScope handleScope(jsExtension_->jsRuntime_);
jsExtension_->CallObjectMethod("onStartDiscoverPrinter");
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(PRINT_EXTCB_STOP_DISCOVERY, []() -> bool {
PRINT_HILOGD("jsExtension_->CallObjectMethod");
HandleScope handleScope(jsExtension_->jsRuntime_);
jsExtension_->CallObjectMethod("onStopDiscoverPrinter");
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(PRINT_EXTCB_CONNECT_PRINTER, [](uint32_t printId) -> bool {
PRINT_HILOGD("jsExtension_->CallObjectMethod");
HandleScope handleScope(jsExtension_->jsRuntime_);
NativeEngine *nativeEng = &(jsExtension_->jsRuntime_).GetNativeEngine();
napi_value jsPrintId =
OHOS::AppExecFwk::WrapInt32ToJS(reinterpret_cast<napi_env>(nativeEng), static_cast<int32_t>(printId));
NativeValue *nativePrintId = reinterpret_cast<NativeValue *>(jsPrintId);
NativeValue *arg[] = { nativePrintId };
jsExtension_->CallObjectMethod("onConnectPrinter", arg, ARGC_ONE);
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(
PRINT_EXTCB_DISCONNECT_PRINTER, [](uint32_t printId) -> bool {
PRINT_HILOGD("jsExtension_->CallObjectMethod");
HandleScope handleScope(jsExtension_->jsRuntime_);
NativeEngine *nativeEng = &(jsExtension_->jsRuntime_).GetNativeEngine();
napi_value jsPrintId =
OHOS::AppExecFwk::WrapInt32ToJS(reinterpret_cast<napi_env>(nativeEng), static_cast<int32_t>(printId));
NativeValue *nativePrintId = reinterpret_cast<NativeValue *>(jsPrintId);
NativeValue *arg[] = { nativePrintId };
jsExtension_->CallObjectMethod("onDisconnectPrinter", arg, ARGC_ONE);
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(PRINT_EXTCB_START_PRINT, [](const PrintJob &job) -> bool {
PRINT_HILOGD("jsExtension_->CallObjectMethod");
HandleScope handleScope(jsExtension_->jsRuntime_);
NativeEngine *nativeEng = &(jsExtension_->jsRuntime_).GetNativeEngine();
napi_value jobObject = PrintNapiUtils::Convert2JsObj(reinterpret_cast<napi_env>(nativeEng), job);
NativeValue *nativeJob = reinterpret_cast<NativeValue *>(jobObject);
NativeValue *arg[] = { nativeJob };
jsExtension_->CallObjectMethod("onConnectPrinter", arg, ARGC_ONE);
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(PRINT_EXTCB_CANCEL_PRINT, [](const PrintJob &job) -> bool {
PRINT_HILOGD("jsExtension_->CallObjectMethod");
HandleScope handleScope(jsExtension_->jsRuntime_);
NativeEngine *nativeEng = &(jsExtension_->jsRuntime_).GetNativeEngine();
napi_value jobObject = PrintNapiUtils::Convert2JsObj(reinterpret_cast<napi_env>(nativeEng), job);
NativeValue *nativeJob = reinterpret_cast<NativeValue *>(jobObject);
NativeValue *arg[] = { nativeJob };
jsExtension_->CallObjectMethod("onCancelPrintJob", arg, ARGC_ONE);
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(PRINT_EXTCB_REQUEST_CAP, [](uint32_t printId) -> bool {
PRINT_HILOGD("jsExtension_->CallObjectMethod");
HandleScope handleScope(jsExtension_->jsRuntime_);
NativeEngine *nativeEng = &(jsExtension_->jsRuntime_).GetNativeEngine();
napi_value jsPrintId =
OHOS::AppExecFwk::WrapInt32ToJS(reinterpret_cast<napi_env>(nativeEng), static_cast<int32_t>(printId));
NativeValue *nativePrintId = reinterpret_cast<NativeValue *>(jsPrintId);
NativeValue *arg[] = { nativePrintId };
jsExtension_->CallObjectMethod("onRequestPrinterCapability", arg, ARGC_ONE);
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(
PRINT_EXTCB_REQUEST_PREVIEW, [](const PrintJob &job) -> bool {
PRINT_HILOGD("jsExtension_->CallObjectMethod");
HandleScope handleScope(jsExtension_->jsRuntime_);
NativeEngine *nativeEng = &(jsExtension_->jsRuntime_).GetNativeEngine();
napi_value jobObject = PrintNapiUtils::Convert2JsObj(reinterpret_cast<napi_env>(nativeEng), job);
NativeValue *nativeJob = reinterpret_cast<NativeValue *>(jobObject);
NativeValue *arg[] = { nativeJob };
jsExtension_->CallObjectMethod("onRequestPreview", arg, ARGC_ONE);
return true;
});
} }
void JsPrintExtension::OnStop() void JsPrintExtension::OnStop()
@ -217,6 +137,7 @@ void JsPrintExtension::OnStop()
PRINT_HILOGD("The Print extension connection is not disconnected."); PRINT_HILOGD("The Print extension connection is not disconnected.");
} }
PRINT_HILOGD("%{public}s end.", __func__); PRINT_HILOGD("%{public}s end.", __func__);
RegisterAllCallback();
} }
sptr<IRemoteObject> JsPrintExtension::OnConnect(const AAFwk::Want &want) sptr<IRemoteObject> JsPrintExtension::OnConnect(const AAFwk::Want &want)
@ -348,5 +269,106 @@ void JsPrintExtension::GetSrcPath(std::string &srcPath)
srcPath.append(".abc"); srcPath.append(".abc");
} }
} }
void JsPrintExtension::RegisterAllCallback()
{
PRINT_HILOGD("Register Print Extension Callback");
PrintManagerClient::GetInstance()->RegisterExtCallback(PRINT_EXTCB_START_DISCOVERY, []() -> bool {
PRINT_HILOGD("Start Print Discovery");
HandleScope handleScope(jsExtension_->jsRuntime_);
auto callback = std::make_shared<JsPrintCallback>(jsExtension_->jsRuntime_);
NativeValue *value = jsExtension_->jsObj_->Get();
callback->Exec(value, "onStartDiscoverPrinter");
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(PRINT_EXTCB_STOP_DISCOVERY, []() -> bool {
PRINT_HILOGD("Stop Print Discovery");
HandleScope handleScope(jsExtension_->jsRuntime_);
auto callback = std::make_shared<JsPrintCallback>(jsExtension_->jsRuntime_);
NativeValue *value = jsExtension_->jsObj_->Get();
callback->Exec(value, "onStopDiscoverPrinter");
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(PRINT_EXTCB_CONNECT_PRINTER, [](uint32_t printId) -> bool {
PRINT_HILOGD("Connect Printer");
HandleScope handleScope(jsExtension_->jsRuntime_);
NativeEngine *nativeEng = &(jsExtension_->jsRuntime_).GetNativeEngine();
napi_value jsPrintId =
OHOS::AppExecFwk::WrapInt32ToJS(reinterpret_cast<napi_env>(nativeEng), static_cast<int32_t>(printId));
NativeValue *nativePrintId = reinterpret_cast<NativeValue *>(jsPrintId);
NativeValue *arg[] = { nativePrintId };
auto callback = std::make_shared<JsPrintCallback>(jsExtension_->jsRuntime_);
NativeValue *value = jsExtension_->jsObj_->Get();
callback->Exec(value, "onConnectPrinter", arg, ARGC_ONE);
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(
PRINT_EXTCB_DISCONNECT_PRINTER, [](uint32_t printId) -> bool {
PRINT_HILOGD("Disconnect Printer");
HandleScope handleScope(jsExtension_->jsRuntime_);
NativeEngine *nativeEng = &(jsExtension_->jsRuntime_).GetNativeEngine();
napi_value jsPrintId =
OHOS::AppExecFwk::WrapInt32ToJS(reinterpret_cast<napi_env>(nativeEng), static_cast<int32_t>(printId));
NativeValue *nativePrintId = reinterpret_cast<NativeValue *>(jsPrintId);
NativeValue *arg[] = { nativePrintId };
auto callback = std::make_shared<JsPrintCallback>(jsExtension_->jsRuntime_);
NativeValue *value = jsExtension_->jsObj_->Get();
callback->Exec(value, "onDisconnectPrinter", arg, ARGC_ONE);
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(PRINT_EXTCB_START_PRINT, [](const PrintJob &job) -> bool {
PRINT_HILOGD("Start Print Job");
HandleScope handleScope(jsExtension_->jsRuntime_);
NativeEngine *nativeEng = &(jsExtension_->jsRuntime_).GetNativeEngine();
napi_value jobObject = PrintNapiUtils::Convert2JsObj(reinterpret_cast<napi_env>(nativeEng), job);
NativeValue *nativeJob = reinterpret_cast<NativeValue *>(jobObject);
NativeValue *arg[] = { nativeJob };
auto callback = std::make_shared<JsPrintCallback>(jsExtension_->jsRuntime_);
NativeValue *value = jsExtension_->jsObj_->Get();
callback->Exec(value, "onStartPrint", arg, ARGC_ONE);
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(PRINT_EXTCB_CANCEL_PRINT, [](const PrintJob &job) -> bool {
PRINT_HILOGD("Cancel Print Job");
HandleScope handleScope(jsExtension_->jsRuntime_);
NativeEngine *nativeEng = &(jsExtension_->jsRuntime_).GetNativeEngine();
napi_value jobObject = PrintNapiUtils::Convert2JsObj(reinterpret_cast<napi_env>(nativeEng), job);
NativeValue *nativeJob = reinterpret_cast<NativeValue *>(jobObject);
NativeValue *arg[] = { nativeJob };
auto callback = std::make_shared<JsPrintCallback>(jsExtension_->jsRuntime_);
NativeValue *value = jsExtension_->jsObj_->Get();
callback->Exec(value, "onCancelPrintJob", arg, ARGC_ONE);
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(PRINT_EXTCB_REQUEST_CAP, [](uint32_t printId) -> bool {
PRINT_HILOGD("Request Capability");
HandleScope handleScope(jsExtension_->jsRuntime_);
NativeEngine *nativeEng = &(jsExtension_->jsRuntime_).GetNativeEngine();
napi_value jsPrintId =
OHOS::AppExecFwk::WrapInt32ToJS(reinterpret_cast<napi_env>(nativeEng), static_cast<int32_t>(printId));
NativeValue *nativePrintId = reinterpret_cast<NativeValue *>(jsPrintId);
NativeValue *arg[] = { nativePrintId };
auto callback = std::make_shared<JsPrintCallback>(jsExtension_->jsRuntime_);
NativeValue *value = jsExtension_->jsObj_->Get();
callback->Exec(value, "onRequestPrinterCapability", arg, ARGC_ONE);
return true;
});
PrintManagerClient::GetInstance()->RegisterExtCallback(
PRINT_EXTCB_REQUEST_PREVIEW, [](const PrintJob &job) -> bool {
PRINT_HILOGD("Requet preview");
HandleScope handleScope(jsExtension_->jsRuntime_);
NativeEngine *nativeEng = &(jsExtension_->jsRuntime_).GetNativeEngine();
napi_value jobObject = PrintNapiUtils::Convert2JsObj(reinterpret_cast<napi_env>(nativeEng), job);
NativeValue *nativeJob = reinterpret_cast<NativeValue *>(jobObject);
NativeValue *arg[] = { nativeJob };
auto callback = std::make_shared<JsPrintCallback>(jsExtension_->jsRuntime_);
NativeValue *value = jsExtension_->jsObj_->Get();
callback->Exec(value, "onRequestPreview", arg, ARGC_ONE);
return true;
});
}
} // namespace AbilityRuntime } // namespace AbilityRuntime
} // namespace OHOS } // namespace OHOS

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021 Huawei Device Co., Ltd. # Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -20,8 +20,7 @@ extern const char _binary_print_extension_js_end[];
extern const char _binary_print_extension_abc_start[]; extern const char _binary_print_extension_abc_start[];
extern const char _binary_print_extension_abc_end[]; extern const char _binary_print_extension_abc_end[];
extern "C" __attribute__((constructor)) extern "C" __attribute__((constructor)) void NAPI_PrintExtension_AutoRegister()
void NAPI_PrintExtension_AutoRegister()
{ {
auto moduleManager = NativeModuleManager::GetInstance(); auto moduleManager = NativeModuleManager::GetInstance();
NativeModule newModuleInfo = { NativeModule newModuleInfo = {
@ -32,8 +31,7 @@ void NAPI_PrintExtension_AutoRegister()
moduleManager->Register(&newModuleInfo); moduleManager->Register(&newModuleInfo);
} }
extern "C" __attribute__((visibility("default"))) extern "C" __attribute__((visibility("default"))) void NAPI_PrintExtension_GetJSCode(const char **buf, int *bufLen)
void NAPI_PrintExtension_GetJSCode(const char **buf, int *bufLen)
{ {
if (buf != nullptr) { if (buf != nullptr) {
*buf = _binary_print_extension_js_start; *buf = _binary_print_extension_js_start;
@ -45,8 +43,7 @@ void NAPI_PrintExtension_GetJSCode(const char **buf, int *bufLen)
} }
// print_extension JS register // print_extension JS register
extern "C" __attribute__((visibility("default"))) extern "C" __attribute__((visibility("default"))) void NAPI_PrintExtension_GetABCCode(const char **buf, int *buflen)
void NAPI_PrintExtension_GetABCCode(const char **buf, int *buflen)
{ {
if (buf != nullptr) { if (buf != nullptr) {
*buf = _binary_print_extension_abc_start; *buf = _binary_print_extension_abc_start;

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021 Huawei Device Co., Ltd. # Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -20,8 +20,7 @@ extern const char _binary_print_extension_context_js_end[];
extern const char _binary_print_extension_context_abc_start[]; extern const char _binary_print_extension_context_abc_start[];
extern const char _binary_print_extension_context_abc_end[]; extern const char _binary_print_extension_context_abc_end[];
extern "C" __attribute__((constructor)) extern "C" __attribute__((constructor)) void NAPI_PrintExtensionContext_AutoRegister()
void NAPI_PrintExtensionContext_AutoRegister()
{ {
auto moduleManager = NativeModuleManager::GetInstance(); auto moduleManager = NativeModuleManager::GetInstance();
NativeModule newModuleInfo = { NativeModule newModuleInfo = {
@ -32,8 +31,8 @@ void NAPI_PrintExtensionContext_AutoRegister()
moduleManager->Register(&newModuleInfo); moduleManager->Register(&newModuleInfo);
} }
extern "C" __attribute__((visibility("default"))) extern "C" __attribute__((visibility("default"))) void NAPI_PrintExtensionContext_GetJSCode(
void NAPI_PrintExtensionContext_GetJSCode(const char **buf, int *bufLen) const char **buf, int *bufLen)
{ {
if (buf != nullptr) { if (buf != nullptr) {
*buf = _binary_print_extension_context_js_start; *buf = _binary_print_extension_context_js_start;
@ -45,8 +44,8 @@ void NAPI_PrintExtensionContext_GetJSCode(const char **buf, int *bufLen)
} }
// print_extension_context JS register // print_extension_context JS register
extern "C" __attribute__((visibility("default"))) extern "C" __attribute__((visibility("default"))) void NAPI_PrintExtensionContext_GetABCCode(
void NAPI_PrintExtensionContext_GetABCCode(const char **buf, int *buflen) const char **buf, int *buflen)
{ {
if (buf != nullptr) { if (buf != nullptr) {
*buf = _binary_print_extension_context_abc_start; *buf = _binary_print_extension_context_abc_start;

View File

@ -47,6 +47,7 @@ ohos_shared_library("print_napi") {
"src/napi_print_ext.cpp", "src/napi_print_ext.cpp",
"src/async_call.cpp", "src/async_call.cpp",
"src/print_task.cpp", "src/print_task.cpp",
"src/print_parse_type.cpp",
] ]
deps = [ deps = [
"//foundation/arkui/napi:ace_napi", "//foundation/arkui/napi:ace_napi",

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -28,7 +28,6 @@ typedef void (*AsyncWorkExecutor)(napi_env env, void *data);
typedef void (*AsyncWorkCallback)(napi_env env, napi_status status, void *data); typedef void (*AsyncWorkCallback)(napi_env env, napi_status status, void *data);
// support no argument
class BaseContext { class BaseContext {
public: public:
ACE_DISALLOW_COPY_AND_MOVE(BaseContext); ACE_DISALLOW_COPY_AND_MOVE(BaseContext);

View File

@ -20,12 +20,12 @@
#include <vector> #include <vector>
#include "async_call.h" #include "async_call.h"
#include "iprint_callback.h"
#include "napi/native_api.h" #include "napi/native_api.h"
#include "napi_print_ext.h" #include "napi_print_ext.h"
#include "noncopyable.h" #include "noncopyable.h"
#include "print_extension_info.h" #include "print_extension_info.h"
#include "print_job.h" #include "print_job.h"
#include "print_notify_stub.h"
#include "print_page_size.h" #include "print_page_size.h"
#include "print_resolution.h" #include "print_resolution.h"
#include "print_task.h" #include "print_task.h"
@ -50,18 +50,16 @@ public:
static napi_value StopDiscovery(napi_env env, napi_callback_info info); static napi_value StopDiscovery(napi_env env, napi_callback_info info);
static napi_value ConnectPrint(napi_env env, napi_callback_info info); static napi_value ConnectPrint(napi_env env, napi_callback_info info);
static napi_value DisconnectPrint(napi_env env, napi_callback_info info); static napi_value DisconnectPrint(napi_env env, napi_callback_info info);
static napi_value StartPrint(napi_env env, napi_callback_info info); static napi_value StartPrintJob(napi_env env, napi_callback_info info);
static napi_value CancelPrint(napi_env env, napi_callback_info info); static napi_value CancelPrintJob(napi_env env, napi_callback_info info);
static napi_value RequestPreview(napi_env env, napi_callback_info info); static napi_value RequestPreview(napi_env env, napi_callback_info info);
static napi_value QueryCapability(napi_env env, napi_callback_info info); static napi_value QueryCapability(napi_env env, napi_callback_info info);
static napi_value On(napi_env env, napi_callback_info info); static napi_value On(napi_env env, napi_callback_info info);
static napi_value Off(napi_env env, napi_callback_info info); static napi_value Off(napi_env env, napi_callback_info info);
static int32_t GetEventType(const std::string &type); static int32_t GetEventType(const std::string &type);
static bool ParseJob(napi_env env, napi_value jobValue, PrintJob &printJob);
static bool ParseJobParam(napi_env env, napi_value jobValue, PrintJob &printJob);
private: private:
static sptr<PrintNotifyInterface> CreateNotify(napi_env env, const std::string &type, napi_ref callbackRef); static sptr<IPrintCallback> CreateNotify(napi_env env, const std::string &type, napi_ref callbackRef);
struct OperationContext : public AsyncCall::Context { struct OperationContext : public AsyncCall::Context {
int32_t dummy = 0; int32_t dummy = 0;

View File

@ -33,16 +33,6 @@ public:
static napi_value RemovePrinters(napi_env env, napi_callback_info info); static napi_value RemovePrinters(napi_env env, napi_callback_info info);
static napi_value UpdatePrinterState(napi_env env, napi_callback_info info); static napi_value UpdatePrinterState(napi_env env, napi_callback_info info);
static napi_value UpdatePrintJobState(napi_env env, napi_callback_info info); static napi_value UpdatePrintJobState(napi_env env, napi_callback_info info);
static bool ParseInfo(napi_env env, napi_value InfoValue, PrinterInfo &Info);
static bool ParseInfoParam(napi_env env, napi_value InfoValue, PrinterInfo &info);
static bool ParseCapability(napi_env env, napi_value InfoValue, PrinterCapability &capability);
static bool ParseCapabilityParam(napi_env env, napi_value InfoValue, PrinterCapability &capability);
static bool ParsePageSize(napi_env env, napi_value capValue, PrintPageSize &PrintPageSize);
static bool ParsePageSizeParam(napi_env env, napi_value capValue, PrintPageSize &PrintPageSize);
static bool ParseResolution(napi_env env, napi_value reValue, PrintResolution &PrintResolution);
static bool ParseResolutionParam(napi_env env, napi_value reValue, PrintResolution &PrintResolution);
static bool ParseMargin(napi_env env, napi_value marginValue, PrintMargin &PrintMargin);
static bool ParseMarginParam(napi_env env, napi_value marginValue, PrintMargin &PrintMargin);
private: private:
struct NapiPrintExtContext : public AsyncCall::Context { struct NapiPrintExtContext : public AsyncCall::Context {

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2022 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.
*/
#ifndef PARSE_TYPE_H
#define PARSE_TYPE_H
#include <string>
#include <vector>
#include "async_call.h"
#include "napi/native_api.h"
#include "noncopyable.h"
#include "print_job.h"
#include "print_page_size.h"
#include "print_resolution.h"
#include "print_task.h"
#include "printer_capability.h"
#include "printer_info.h"
namespace OHOS::Print {
class ParseType {
public:
static bool ParseInfo(napi_env env, napi_value InfoValue, PrinterInfo &Info);
static bool ParseCapability(napi_env env, napi_value InfoValue, PrinterCapability &capability);
static bool ParsePageSize(napi_env env, napi_value capValue, PrintPageSize &PrintPageSize);
static bool ParseResolution(napi_env env, napi_value reValue, PrintResolution &PrintResolution);
static bool ParseMargin(napi_env env, napi_value marginValue, PrintMargin &PrintMargin);
static bool ParseJob(napi_env env, napi_value jobValue, PrintJob &printJob);
static bool ParsePreviewAttribute(napi_env env, napi_value preAttValue, PreviewAttribute &preAtt);
static bool ParseRange(napi_env env, napi_value preAttValue, PrintRange &range);
static bool ParseInfoParam(napi_env env, napi_value InfoValue, PrinterInfo &info);
static bool ParseCapabilityParam(napi_env env, napi_value InfoValue, PrinterCapability &capability);
static bool ParsePageSizeParam(napi_env env, napi_value capValue, PrintPageSize &PrintPageSize);
static bool ParseResolutionParam(napi_env env, napi_value reValue, PrintResolution &PrintResolution);
static bool ParseMarginParam(napi_env env, napi_value marginValue, PrintMargin &PrintMargin);
static bool ParseJobParam(napi_env env, napi_value jobValue, PrintJob &printJob);
static bool ParsePreviewAttributeParam(napi_env env, napi_value preAttValue, PreviewAttribute &preAtt);
static bool ParseRangeParam(napi_env env, napi_value preAttValue, PrintRange &range);
private:
struct ParseTypeContext : public AsyncCall::Context {};
};
} // namespace OHOS::Print
#endif // PARSE_TYPE_H

View File

@ -53,10 +53,6 @@ public:
static napi_value On(napi_env env, napi_callback_info info); static napi_value On(napi_env env, napi_callback_info info);
static napi_value Off(napi_env env, napi_callback_info info); static napi_value Off(napi_env env, napi_callback_info info);
// bool AddListener(const std::string &type, sptr<PrintNotifyInterface> listener);
// void RemoveListener(const std::string &type, sptr<PrintNotifyInterface> listener);
// void RemoveListener(const std::string &type);
bool IsSupportType(const std::string &type); bool IsSupportType(const std::string &type);
bool IsSupportPrinterStateType(const std::string &type); bool IsSupportPrinterStateType(const std::string &type);
bool IsSupportJobStateType(const std::string &type); bool IsSupportJobStateType(const std::string &type);
@ -64,7 +60,6 @@ public:
private: private:
int taskId_; int taskId_;
std::mutex mutex_; std::mutex mutex_;
// std::map<std::string, sptr<PrintNotifyInterface>> listenerMap_;
std::map<std::string, bool> supportEvents_; std::map<std::string, bool> supportEvents_;
std::map<std::string, bool> supportPrinterState_; std::map<std::string, bool> supportPrinterState_;
std::map<std::string, bool> supportJobState_; std::map<std::string, bool> supportJobState_;

View File

@ -15,8 +15,8 @@
#include "async_call.h" #include "async_call.h"
#include "napi_print_utils.h"
#include "print_log.h" #include "print_log.h"
#include "print_napi_utils.h"
namespace OHOS::Print { namespace OHOS::Print {
AsyncCall::AsyncCall(napi_env env, napi_callback_info info, std::shared_ptr<Context> context, size_t pos) : env_(env) AsyncCall::AsyncCall(napi_env env, napi_callback_info info, std::shared_ptr<Context> context, size_t pos) : env_(env)

View File

@ -16,24 +16,22 @@
#include "napi_inner_print.h" #include "napi_inner_print.h"
#include "async_call.h" #include "async_call.h"
#include "napi_print_utils.h"
#include "print_log.h" #include "print_log.h"
#include "print_manager_client.h" #include "print_manager_client.h"
#include "print_napi_utils.h" #include "print_parse_type.h"
#include "print_task.h" #include "print_task.h"
static constexpr const char *PARAM_JOB_FILES = "files";
static constexpr const char *PARAM_JOB_JOBID = "jobId";
static constexpr const char *PARAM_JOB_PRINTERID = "printerId";
static constexpr const char *PARAM_JOB_JOBSTATE = "jobState";
static constexpr const char *PARAM_JOB_COPYNUMBER = "copyNumber";
// static constexpr const char *PARAM_JOB_PAGERANGE = "pageRange";
namespace OHOS::Print { namespace OHOS::Print {
napi_value NapiInnerPrint::QueryExtensionInfo(napi_env env, napi_callback_info info) napi_value NapiInnerPrint::QueryExtensionInfo(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter ---->"); PRINT_HILOGD("Enter ---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -92,8 +90,12 @@ napi_value NapiInnerPrint::QueryExtensionInfo(napi_env env, napi_callback_info i
napi_value NapiInnerPrint::StartDiscovery(napi_env env, napi_callback_info info) napi_value NapiInnerPrint::StartDiscovery(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter StartDiscovery---->"); PRINT_HILOGD("Enter StartDiscovery---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -122,10 +124,6 @@ napi_value NapiInnerPrint::StartDiscovery(napi_env env, napi_callback_info info)
return status; return status;
}; };
auto exec = [context](AsyncCall::Context *ctx) { auto exec = [context](AsyncCall::Context *ctx) {
/*context->extensionList.push_back(5);
context->extensionList.push_back(55);
context->extensionList.push_back(555);
context->extensionList.push_back(5555);*/
context->result = PrintManagerClient::GetInstance()->StartDiscoverPrinter(context->extensionVector); context->result = PrintManagerClient::GetInstance()->StartDiscoverPrinter(context->extensionVector);
if (context->result == true) { if (context->result == true) {
context->status = napi_ok; context->status = napi_ok;
@ -139,8 +137,12 @@ napi_value NapiInnerPrint::StartDiscovery(napi_env env, napi_callback_info info)
napi_value NapiInnerPrint::StopDiscovery(napi_env env, napi_callback_info info) napi_value NapiInnerPrint::StopDiscovery(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter StopDiscovery---->"); PRINT_HILOGD("Enter StopDiscovery---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -168,8 +170,12 @@ napi_value NapiInnerPrint::StopDiscovery(napi_env env, napi_callback_info info)
napi_value NapiInnerPrint::ConnectPrint(napi_env env, napi_callback_info info) napi_value NapiInnerPrint::ConnectPrint(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter ConnectPrint---->"); PRINT_HILOGD("Enter ConnectPrint---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -204,8 +210,12 @@ napi_value NapiInnerPrint::ConnectPrint(napi_env env, napi_callback_info info)
napi_value NapiInnerPrint::DisconnectPrint(napi_env env, napi_callback_info info) napi_value NapiInnerPrint::DisconnectPrint(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter DisconnectPrint---->"); PRINT_HILOGD("Enter DisconnectPrint---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -237,11 +247,15 @@ napi_value NapiInnerPrint::DisconnectPrint(napi_env env, napi_callback_info info
return asyncCall.Call(env, exec); return asyncCall.Call(env, exec);
} }
napi_value NapiInnerPrint::StartPrint(napi_env env, napi_callback_info info) napi_value NapiInnerPrint::StartPrintJob(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter StartPrint---->"); PRINT_HILOGD("Enter StartPrintJob---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -250,8 +264,8 @@ napi_value NapiInnerPrint::StartPrint(napi_env env, napi_callback_info info)
NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg); NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg);
napi_value value = argv[PrintNapiUtils::FIRST_ARGV]; napi_value value = argv[PrintNapiUtils::FIRST_ARGV];
PrintJob printJob; PrintJob printJob;
if (!ParseJob(env, value, printJob)) { if (!ParseType::ParseJob(env, value, printJob)) {
PRINT_HILOGD("PrintResolution type error!"); PRINT_HILOGD("ParseJob type error!");
} }
context->printStartJob = printJob; context->printStartJob = printJob;
return napi_ok; return napi_ok;
@ -262,10 +276,6 @@ napi_value NapiInnerPrint::StartPrint(napi_env env, napi_callback_info info)
return status; return status;
}; };
auto exec = [context](AsyncCall::Context *ctx) { auto exec = [context](AsyncCall::Context *ctx) {
PrintRange range;
range.SetStartPage(1);
range.SetEndPage(2);
context->printStartJob.SetPageRange(range);
context->result = PrintManagerClient::GetInstance()->StartPrintJob(context->printStartJob); context->result = PrintManagerClient::GetInstance()->StartPrintJob(context->printStartJob);
if (context->result == true) { if (context->result == true) {
context->status = napi_ok; context->status = napi_ok;
@ -276,11 +286,15 @@ napi_value NapiInnerPrint::StartPrint(napi_env env, napi_callback_info info)
return asyncCall.Call(env, exec); return asyncCall.Call(env, exec);
} }
napi_value NapiInnerPrint::CancelPrint(napi_env env, napi_callback_info info) napi_value NapiInnerPrint::CancelPrintJob(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter ---->"); PRINT_HILOGD("Enter CancelPrintJob---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -289,8 +303,8 @@ napi_value NapiInnerPrint::CancelPrint(napi_env env, napi_callback_info info)
NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg); NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg);
napi_value value = argv[PrintNapiUtils::FIRST_ARGV]; napi_value value = argv[PrintNapiUtils::FIRST_ARGV];
PrintJob printJob; PrintJob printJob;
if (!ParseJob(env, value, printJob)) { if (!ParseType::ParseJob(env, value, printJob)) {
PRINT_HILOGD("PrintResolution type error!"); PRINT_HILOGD("ParseJob type error!");
} }
context->printCancelJob = printJob; context->printCancelJob = printJob;
return napi_ok; return napi_ok;
@ -301,10 +315,6 @@ napi_value NapiInnerPrint::CancelPrint(napi_env env, napi_callback_info info)
return status; return status;
}; };
auto exec = [context](AsyncCall::Context *ctx) { auto exec = [context](AsyncCall::Context *ctx) {
PrintRange range;
range.SetStartPage(1);
range.SetEndPage(2);
context->printCancelJob.SetPageRange(range);
context->result = PrintManagerClient::GetInstance()->CancelPrintJob(context->printCancelJob); context->result = PrintManagerClient::GetInstance()->CancelPrintJob(context->printCancelJob);
if (context->result == true) { if (context->result == true) {
context->status = napi_ok; context->status = napi_ok;
@ -318,8 +328,12 @@ napi_value NapiInnerPrint::CancelPrint(napi_env env, napi_callback_info info)
napi_value NapiInnerPrint::RequestPreview(napi_env env, napi_callback_info info) napi_value NapiInnerPrint::RequestPreview(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter ---->"); PRINT_HILOGD("Enter ---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -328,8 +342,8 @@ napi_value NapiInnerPrint::RequestPreview(napi_env env, napi_callback_info info)
NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg); NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg);
napi_value value = argv[PrintNapiUtils::FIRST_ARGV]; napi_value value = argv[PrintNapiUtils::FIRST_ARGV];
PrintJob printJob; PrintJob printJob;
if (!ParseJob(env, value, printJob)) { if (!ParseType::ParseJob(env, value, printJob)) {
PRINT_HILOGD("PrintResolution type error!"); PRINT_HILOGD("ParseJob type error!");
} }
context->printReqPreviewJob = printJob; context->printReqPreviewJob = printJob;
return napi_ok; return napi_ok;
@ -340,10 +354,6 @@ napi_value NapiInnerPrint::RequestPreview(napi_env env, napi_callback_info info)
return status; return status;
}; };
auto exec = [context](AsyncCall::Context *ctx) { auto exec = [context](AsyncCall::Context *ctx) {
PrintRange range;
range.SetStartPage(1);
range.SetEndPage(2);
context->printReqPreviewJob.SetPageRange(range);
context->result = context->result =
PrintManagerClient::GetInstance()->RequestPreview(context->printReqPreviewJob, context->previewResult); PrintManagerClient::GetInstance()->RequestPreview(context->printReqPreviewJob, context->previewResult);
if (context->result == true) { if (context->result == true) {
@ -358,8 +368,12 @@ napi_value NapiInnerPrint::RequestPreview(napi_env env, napi_callback_info info)
napi_value NapiInnerPrint::QueryCapability(napi_env env, napi_callback_info info) napi_value NapiInnerPrint::QueryCapability(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter QueryCapability---->"); PRINT_HILOGD("Enter QueryCapability---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -377,59 +391,7 @@ napi_value NapiInnerPrint::QueryCapability(napi_env env, napi_callback_info info
return napi_ok; return napi_ok;
}; };
auto output = [context](napi_env env, napi_value *result) -> napi_status { auto output = [context](napi_env env, napi_value *result) -> napi_status {
PRINT_HILOGD("ouput enter---->"); context->printerCapability.ConvertToJs(env, result);
napi_value resultPrintMargin;
napi_create_object(env, result);
napi_create_object(env, &resultPrintMargin);
napi_value arrPageSize, arrResolution;
napi_status status = napi_create_array(env, &arrPageSize);
status = napi_create_array(env, &arrResolution);
PrintNapiUtils::SetUint32Property(env, *result, "colorMode", context->printerCapability.GetColorMode());
PrintNapiUtils::SetUint32Property(env, *result, "duplexMode", context->printerCapability.GetDuplexMode());
PrintMargin margin;
context->printerCapability.GetMinMargin(margin);
PrintNapiUtils::SetUint32Property(env, resultPrintMargin, "top", margin.GetTop());
PrintNapiUtils::SetUint32Property(env, resultPrintMargin, "bottom", margin.GetBottom());
PrintNapiUtils::SetUint32Property(env, resultPrintMargin, "left", margin.GetLeft());
PrintNapiUtils::SetUint32Property(env, resultPrintMargin, "right", margin.GetRight());
std::vector<PrintPageSize> pageSize;
context->printerCapability.GetPageSize(pageSize);
uint32_t printerCapabilityLength = pageSize.size();
for (uint32_t i = 0; i < printerCapabilityLength; i++) {
napi_value resultPrinterPageSize;
napi_create_object(env, &resultPrinterPageSize);
PrintNapiUtils::SetUint32Property(env, resultPrinterPageSize, "id", pageSize[i].GetId());
PrintNapiUtils::SetStringPropertyUtf8(env, resultPrinterPageSize, "name", pageSize[i].GetName().c_str());
PrintNapiUtils::SetUint32Property(env, resultPrinterPageSize, "width", pageSize[i].GetWidth());
PrintNapiUtils::SetUint32Property(env, resultPrinterPageSize, "height", pageSize[i].GetHeight());
status = napi_set_element(env, arrPageSize, i, resultPrinterPageSize);
}
std::vector<PrintResolution> resolutionList;
context->printerCapability.GetResolution(resolutionList);
uint32_t printerCapabilityresolutionLength = resolutionList.size();
for (uint32_t i = 0; i < printerCapabilityresolutionLength; i++) {
napi_value resultPrinterResolution;
napi_create_object(env, &resultPrinterResolution);
PrintNapiUtils::SetUint32Property(env, resultPrinterResolution, "id", resolutionList[i].GetId());
PrintNapiUtils::SetUint32Property(
env, resultPrinterResolution, "horizontalDpi", resolutionList[i].GetHorizontalDpi());
PrintNapiUtils::SetUint32Property(
env, resultPrinterResolution, "verticalDpi", resolutionList[i].GetVerticalDpi());
status = napi_set_element(env, arrResolution, i, resultPrinterResolution);
}
status = napi_set_named_property(env, *result, "minMargin", resultPrintMargin);
PRINT_HILOGD("output ---- status[%{public}d]", status);
napi_set_named_property(env, *result, "pageSize", arrPageSize);
napi_set_named_property(env, *result, "resolution", arrResolution);
PRINT_HILOGD("ouput over---->");
return napi_ok; return napi_ok;
}; };
auto exec = [context](AsyncCall::Context *ctx) { auto exec = [context](AsyncCall::Context *ctx) {
@ -447,8 +409,12 @@ napi_value NapiInnerPrint::QueryCapability(napi_env env, napi_callback_info info
napi_value NapiInnerPrint::On(napi_env env, napi_callback_info info) napi_value NapiInnerPrint::On(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter ---->"); PRINT_HILOGD("Enter ---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -487,21 +453,18 @@ napi_value NapiInnerPrint::On(napi_env env, napi_callback_info info)
PRINT_HILOGD("state judge end."); PRINT_HILOGD("state judge end.");
napi_ref callbackRef = nullptr; napi_ref callbackRef = nullptr;
napi_create_reference(env, argv[argc - 1], 1, &callbackRef); napi_create_reference(env, argv[argc - 1], 1, &callbackRef);
// sptr<PrintNotifyInterface> listener = CreateNotify(env, type, callbackRef);
// if (listener == nullptr) {
// PRINT_HILOGD("PrintPause create callback object fail");
// return result;
// }
// return result;
return nullptr; return nullptr;
} }
napi_value NapiInnerPrint::Off(napi_env env, napi_callback_info info) napi_value NapiInnerPrint::Off(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter Off---->"); PRINT_HILOGD("Enter Off---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -544,21 +507,18 @@ int32_t NapiInnerPrint::GetEventType(const std::string &type)
return NO_ARG_EVENT; return NO_ARG_EVENT;
} }
sptr<PrintNotifyInterface> NapiInnerPrint::CreateNotify(napi_env env, const std::string &type, napi_ref callbackRef) sptr<IPrintCallback> NapiInnerPrint::CreateNotify(napi_env env, const std::string &type, napi_ref callbackRef)
{ {
sptr<PrintNotifyInterface> listener = nullptr; sptr<IPrintCallback> listener = nullptr;
int32_t eventType = GetEventType(type); int32_t eventType = GetEventType(type);
switch (eventType) { switch (eventType) {
case NO_ARG_EVENT: case NO_ARG_EVENT:
// listener = new PrintBaseNotify(env, type, callbackRef);
break; break;
case ONE_ARG_EVENT: case ONE_ARG_EVENT:
// listener = new PrintPrinterStateNotify(env, type, callbackRef);
break; break;
case TWO_ARG_EVENT: case TWO_ARG_EVENT:
// listener = new PrintPrintJobNotify(env, type, callbackRef);
break; break;
default: default:
@ -567,72 +527,4 @@ sptr<PrintNotifyInterface> NapiInnerPrint::CreateNotify(napi_env env, const std:
} }
return listener; return listener;
} }
bool NapiInnerPrint::ParseJob(napi_env env, napi_value jobValue, PrintJob &printJob)
{
if (!ParseJobParam(env, jobValue, printJob)) {
PRINT_HILOGD("ParseJobParam is error!");
return false;
}
printJob.SetJobId(PrintNapiUtils::GetUint32Property(env, jobValue, PARAM_JOB_JOBID));
printJob.SetPrintId(PrintNapiUtils::GetUint32Property(env, jobValue, PARAM_JOB_PRINTERID));
printJob.SetJobState(PrintNapiUtils::GetUint32Property(env, jobValue, PARAM_JOB_JOBSTATE));
printJob.SetCopyNumber(PrintNapiUtils::GetUint32Property(env, jobValue, PARAM_JOB_COPYNUMBER));
// printJob.SetPageRange(PrintNapiUtils::GetUint32Property(env, jobValue, PARAM_JOB_PAGERANGE));
PRINT_HILOGD("printJob_value GetJobId value is %{public}d", printJob.GetJobId());
PRINT_HILOGD("printJob_value GetPrinterId value is %{public}d", printJob.GetPrinterId());
PRINT_HILOGD("printJob_value GetJobState value is %{public}d", printJob.GetJobState());
PRINT_HILOGD("printJob_value GetCopyNumber value is %{public}d", printJob.GetCopyNumber());
// PRINT_HILOGD("printJob_value GetPageRange value is %{public}d", printJob.GetPageRange());
return true;
}
bool NapiInnerPrint::ParseJobParam(napi_env env, napi_value jobValue, PrintJob &printJob)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_FILES);
bool isFileArray = false;
napi_is_array(env, param_one, &isFileArray);
if (!isFileArray) {
PRINT_HILOGD("PrinterJobFile type error!");
return false;
}
std::vector<std::string> printfiles;
uint32_t arrayReLength = 0;
napi_get_array_length(env, param_one, &arrayReLength);
for (uint32_t i = 0; i < arrayReLength; i++) {
napi_value filesValue;
napi_get_element(env, param_one, i, &filesValue);
std::string files = PrintNapiUtils::GetStringFromValueUtf8(env, filesValue);
PRINT_HILOGD("printJob_value param_one %{public}s", files.c_str());
printfiles.push_back(files);
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_JOBID);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_number) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_PRINTERID);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_JOBSTATE);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
napi_value param_five = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_COPYNUMBER);
if (PrintNapiUtils::GetValueType(env, param_five) != napi_number) {
PRINT_HILOGD("error param_five");
return false;
}
// napi_value param_six = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_PAGERANGE);
// if (PrintNapiUtils::GetValueType(env, param_six) != napi_number) {
// PRINT_HILOGD("error param_six");
// return false;
// }
return true;
}
} // namespace OHOS::Print } // namespace OHOS::Print

View File

@ -16,43 +16,21 @@
#include "napi_print_ext.h" #include "napi_print_ext.h"
#include "async_call.h" #include "async_call.h"
#include "napi_print_utils.h"
#include "print_log.h" #include "print_log.h"
#include "print_manager_client.h" #include "print_manager_client.h"
#include "print_napi_utils.h" #include "print_parse_type.h"
static constexpr const char *PARAM_INFO_PRINTID = "printerId";
static constexpr const char *PARAM_INFO_PRINTERNAME = "printerName";
static constexpr const char *PARAM_INFO_PRINTERICON = "printerIcon";
static constexpr const char *PARAM_INFO_PRINTERSTATE = "printerState";
static constexpr const char *PARAM_INFO_DESCRIPTION = "description";
static constexpr const char *PARAM_INFO_CAPABILITY = "capability";
static constexpr const char *PARAM_CAPABILITY_MINMARGIN = "minMargin";
static constexpr const char *PARAM_CAPABILITY_PAGESIZE = "pageSize";
static constexpr const char *PARAM_CAPABILITY_RESOLUTION = "resolution";
static constexpr const char *PARAM_CAPABILITY_COLORMODE = "colorMode";
static constexpr const char *PARAM_CAPABILITY_DUPLEXMODE = "duplexMode";
static constexpr const char *PARAM_PAGESIZE_ID = "id";
static constexpr const char *PARAM_PAGESIZE_NAME = "name";
static constexpr const char *PARAM_PAGESIZE_WIDTH = "width";
static constexpr const char *PARAM_PAGESIZE_HEIGHT = "height";
static constexpr const char *PARAM_RESOLUTION_ID = "id";
static constexpr const char *PARAM_RESOLUTION_HORIZONTALDPI = "horizontalDpi";
static constexpr const char *PARAM_RESOLUTION_VERTICALDPI = "verticalDpi";
static constexpr const char *PARAM_MARGIN_TOP = "top";
static constexpr const char *PARAM_MARGIN_BOTTOM = "bottom";
static constexpr const char *PARAM_MARGIN_LEFT = "left";
static constexpr const char *PARAM_MARGIN_RIGHT = "right";
namespace OHOS::Print { namespace OHOS::Print {
napi_value NapiPrintExt::AddPrinters(napi_env env, napi_callback_info info) napi_value NapiPrintExt::AddPrinters(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter ---->"); PRINT_HILOGD("Enter ---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -71,7 +49,7 @@ napi_value NapiPrintExt::AddPrinters(napi_env env, napi_callback_info info)
for (uint32_t i = 0; i < result_size; i++) { for (uint32_t i = 0; i < result_size; i++) {
napi_value value; napi_value value;
napi_get_element(env, array, i, &value); napi_get_element(env, array, i, &value);
if (!ParseInfo(env, value, info_)) { if (!ParseType::ParseInfo(env, value, info_)) {
PRINT_HILOGD("PrinterInfo is format error!"); PRINT_HILOGD("PrinterInfo is format error!");
} }
context->printAddInfoVector.push_back(info_); context->printAddInfoVector.push_back(info_);
@ -97,6 +75,15 @@ napi_value NapiPrintExt::AddPrinters(napi_env env, napi_callback_info info)
napi_value NapiPrintExt::RemovePrinters(napi_env env, napi_callback_info info) napi_value NapiPrintExt::RemovePrinters(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter ---->"); PRINT_HILOGD("Enter ---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGW("no permission to access print service");
return nullptr;
}
auto context = std::make_shared<NapiPrintExtContext>(); auto context = std::make_shared<NapiPrintExtContext>();
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
NAPI_ASSERT_BASE(env, argc == PrintNapiUtils::ONE_ARG, " should 1 parameter!", napi_invalid_arg); NAPI_ASSERT_BASE(env, argc == PrintNapiUtils::ONE_ARG, " should 1 parameter!", napi_invalid_arg);
@ -112,7 +99,7 @@ napi_value NapiPrintExt::RemovePrinters(napi_env env, napi_callback_info info)
for (uint32_t i = 0; i < result_size; i++) { for (uint32_t i = 0; i < result_size; i++) {
napi_value value; napi_value value;
napi_get_element(env, array, i, &value); napi_get_element(env, array, i, &value);
if (!ParseInfo(env, value, info_)) { if (!ParseType::ParseInfo(env, value, info_)) {
PRINT_HILOGD("PrinterInfo is format error!"); PRINT_HILOGD("PrinterInfo is format error!");
} }
context->printRemoveInfoVector.push_back(info_); context->printRemoveInfoVector.push_back(info_);
@ -137,8 +124,12 @@ napi_value NapiPrintExt::RemovePrinters(napi_env env, napi_callback_info info)
napi_value NapiPrintExt::UpdatePrinterState(napi_env env, napi_callback_info info) napi_value NapiPrintExt::UpdatePrinterState(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter ---->"); PRINT_HILOGD("Enter ---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -180,8 +171,12 @@ napi_value NapiPrintExt::UpdatePrinterState(napi_env env, napi_callback_info inf
napi_value NapiPrintExt::UpdatePrintJobState(napi_env env, napi_callback_info info) napi_value NapiPrintExt::UpdatePrintJobState(napi_env env, napi_callback_info info)
{ {
PRINT_HILOGD("Enter ---->"); PRINT_HILOGD("Enter ---->");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
if (!PrintManagerClient::GetInstance()->CheckPermission()) { if (!PrintManagerClient::GetInstance()->CheckPermission()) {
PRINT_HILOGD("no permission to access print service"); PRINT_HILOGW("no permission to access print service");
return nullptr; return nullptr;
} }
@ -220,315 +215,4 @@ napi_value NapiPrintExt::UpdatePrintJobState(napi_env env, napi_callback_info in
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context)); AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
return asyncCall.Call(env, exec); return asyncCall.Call(env, exec);
} }
bool NapiPrintExt::ParseInfo(napi_env env, napi_value InfoValue, PrinterInfo &info)
{
if (!ParseInfoParam(env, InfoValue, info)) {
PRINT_HILOGD("ParseInfoParam is error!");
return false;
}
info.SetPrinterName(PrintNapiUtils::GetStringPropertyUtf8(env, InfoValue, PARAM_INFO_PRINTERNAME));
info.SetPrinterIcon(PrintNapiUtils::GetUint32Property(env, InfoValue, PARAM_INFO_PRINTERICON));
info.SetPrinterState(PrintNapiUtils::GetUint32Property(env, InfoValue, PARAM_INFO_PRINTERSTATE));
info.SetDescription(PrintNapiUtils::GetStringPropertyUtf8(env, InfoValue, PARAM_INFO_DESCRIPTION));
PRINT_HILOGD("info_value printId value is: %{public}d", info.GetPrintId());
PRINT_HILOGD("info_value printerName value is %{public}s", info.GetPrinterName().c_str());
PRINT_HILOGD("info_value printerIcon value is %{public}d", info.GetPrinterIcon());
PRINT_HILOGD("info_value printerState value is %{public}d", info.GetPrinterState());
PRINT_HILOGD("info_value description value is %{public}s", info.GetDescription().c_str());
return true;
}
bool NapiPrintExt::ParseInfoParam(napi_env env, napi_value InfoValue, PrinterInfo &info)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_PRINTID);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_number) {
PRINT_HILOGD("error param_one");
return false;
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_PRINTERNAME);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_string) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_PRINTERICON);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_PRINTERSTATE);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
napi_value param_five = PrintNapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_DESCRIPTION);
if (PrintNapiUtils::GetValueType(env, param_five) != napi_string) {
PRINT_HILOGD("error param_five");
return false;
}
napi_value param_six = PrintNapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_CAPABILITY);
if (PrintNapiUtils::GetValueType(env, param_six) != napi_object) {
PRINT_HILOGD("error param_six");
return false;
} else {
PrinterCapability capability;
if (!ParseCapability(env, param_six, capability)) {
PRINT_HILOGD("ParseCapability type error!");
}
info.SetCapability(capability);
}
auto names = PrintNapiUtils::GetPropertyNames(env, InfoValue);
std::vector<std::string>::iterator iter;
PRINT_HILOGD("current name list size = %{public}zu", names.size());
for (iter = names.begin(); iter != names.end(); ++iter) {
uint32_t value = PrintNapiUtils::GetUint32Property(env, param_one, *iter);
if (value) {
info.SetPrinterId(value);
}
}
return true;
}
bool NapiPrintExt::ParseCapability(napi_env env, napi_value capValue, PrinterCapability &capability)
{
if (!ParseCapabilityParam(env, capValue, capability)) {
PRINT_HILOGD("ParseCapabilityParam is error!");
return false;
}
// capability.SetMinMargin(PrintNapiUtils::GetStringPropertyUtf8(env, capValue, PARAM_CAPABILITY_MINMARGIN));
capability.SetColorMode(PrintNapiUtils::GetUint32Property(env, capValue, PARAM_CAPABILITY_COLORMODE));
capability.SetDuplexMode(PrintNapiUtils::GetUint32Property(env, capValue, PARAM_CAPABILITY_DUPLEXMODE));
PRINT_HILOGD("capability_value colorMode value is %{public}d", capability.GetColorMode());
PRINT_HILOGD("capability_value duplexMode value is %{public}d", capability.GetDuplexMode());
return true;
}
bool NapiPrintExt::ParseCapabilityParam(napi_env env, napi_value capValue, PrinterCapability &capability)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_MINMARGIN);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_object) {
PRINT_HILOGD("error param_one");
return false;
} else {
PrintMargin margin;
if (!ParseMargin(env, param_one, margin)) {
PRINT_HILOGD("ParseCapability type error!");
}
capability.SetMinMargin(margin);
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_PAGESIZE);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_object) {
PRINT_HILOGD("error param_two");
return false;
} else {
bool isArray = false;
napi_is_array(env, param_two, &isArray);
if (!isArray) {
PRINT_HILOGD("ParsePageSize type error!");
return false;
}
std::vector<PrintPageSize> pageSizeList;
uint32_t arrayLength = 0;
napi_get_array_length(env, param_two, &arrayLength);
for (uint32_t i = 0; i < arrayLength; i++) {
napi_value pageSizeValue;
PrintPageSize pageSize;
napi_get_element(env, param_two, i, &pageSizeValue);
// status = napi_get_property(env, result, param_six, &pageResult);
if (!ParsePageSize(env, pageSizeValue, pageSize)) {
PRINT_HILOGD("ParsePageSize type error!");
return false;
}
pageSizeList.push_back(pageSize);
}
capability.SetPageSize(pageSizeList);
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_RESOLUTION);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_object) {
PRINT_HILOGD("error param_three");
return false;
} else {
bool isReArray = false;
napi_is_array(env, param_three, &isReArray);
if (!isReArray) {
PRINT_HILOGD("PrintResolution type error!");
return false;
}
std::vector<PrintResolution> resolutionList;
uint32_t arrayReLength = 0;
napi_get_array_length(env, param_three, &arrayReLength);
for (uint32_t i = 0; i < arrayReLength; i++) {
napi_value reValue;
PrintResolution resolution;
napi_get_element(env, param_three, i, &reValue);
if (!ParseResolution(env, reValue, resolution)) {
PRINT_HILOGD("PrintResolution type error!");
return false;
}
resolutionList.push_back(resolution);
}
capability.SetResolution(resolutionList);
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_COLORMODE);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
napi_value param_five = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_DUPLEXMODE);
if (PrintNapiUtils::GetValueType(env, param_five) != napi_number) {
// ParseCapabilityParam()
PRINT_HILOGD("error param_five");
return false;
}
auto names = PrintNapiUtils::GetPropertyNames(env, capValue);
std::vector<std::string>::iterator iter;
PRINT_HILOGD("current name list size = %{public}zu", names.size());
for (iter = names.begin(); iter != names.end(); ++iter) {
uint32_t value = PrintNapiUtils::GetUint32Property(env, param_four, *iter);
if (value) {
capability.SetColorMode(value);
}
}
return true;
}
bool NapiPrintExt::ParsePageSize(napi_env env, napi_value capValue, PrintPageSize &pageSize)
{
if (!ParsePageSizeParam(env, capValue, pageSize)) {
PRINT_HILOGD("ParsePageSizeParam is error!");
return false;
}
pageSize.SetName(PrintNapiUtils::GetStringPropertyUtf8(env, capValue, PARAM_PAGESIZE_NAME));
pageSize.SetWidth(PrintNapiUtils::GetUint32Property(env, capValue, PARAM_PAGESIZE_WIDTH));
pageSize.SetHeight(PrintNapiUtils::GetUint32Property(env, capValue, PARAM_PAGESIZE_HEIGHT));
PRINT_HILOGD("printerPageSize_value GetId value is %{public}d", pageSize.GetId());
PRINT_HILOGD("printerPageSize_value GetName value is %{public}s", pageSize.GetName().c_str());
PRINT_HILOGD("printerPageSize_value GetWidth value is %{public}d", pageSize.GetWidth());
PRINT_HILOGD("printerPageSize_value GetHeight value is %{public}d", pageSize.GetHeight());
return true;
}
bool NapiPrintExt::ParsePageSizeParam(napi_env env, napi_value capValue, PrintPageSize &pageSize)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_PAGESIZE_ID);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_number) {
PRINT_HILOGD("error param_one");
return false;
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_PAGESIZE_NAME);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_string) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_PAGESIZE_WIDTH);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_PAGESIZE_HEIGHT);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
auto names = PrintNapiUtils::GetPropertyNames(env, capValue);
std::vector<std::string>::iterator iter;
PRINT_HILOGD("current name list size = %{public}zu", names.size());
for (iter = names.begin(); iter != names.end(); ++iter) {
uint32_t value = PrintNapiUtils::GetUint32Property(env, param_four, *iter);
if (value) {
pageSize.SetId(value);
}
}
return true;
}
bool NapiPrintExt::ParseResolution(napi_env env, napi_value reValue, PrintResolution &resolution)
{
if (!ParseResolutionParam(env, reValue, resolution)) {
PRINT_HILOGD("ParseResolutionParam is error!");
return false;
}
resolution.SetId(PrintNapiUtils::GetUint32Property(env, reValue, PARAM_RESOLUTION_ID));
resolution.SetHorizontalDpi(PrintNapiUtils::GetUint32Property(env, reValue, PARAM_RESOLUTION_HORIZONTALDPI));
resolution.SetVerticalDpi(PrintNapiUtils::GetUint32Property(env, reValue, PARAM_RESOLUTION_VERTICALDPI));
PRINT_HILOGD("printerResolution_value GetId value is %{public}d", resolution.GetId());
PRINT_HILOGD("printerResolution_value GetHorizontalDpi value is %{public}d", resolution.GetHorizontalDpi());
PRINT_HILOGD("printerResolution_value GetVerticalDpi value is %{public}d", resolution.GetVerticalDpi());
return true;
}
bool NapiPrintExt::ParseResolutionParam(napi_env env, napi_value reValue, PrintResolution &resolution)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, reValue, PARAM_RESOLUTION_ID);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_number) {
PRINT_HILOGD("error param_one");
return false;
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, reValue, PARAM_RESOLUTION_HORIZONTALDPI);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_number) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, reValue, PARAM_RESOLUTION_VERTICALDPI);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
auto names = PrintNapiUtils::GetPropertyNames(env, reValue);
PRINT_HILOGD("current resolution paramster name list size = %{public}zu", names.size());
return true;
}
bool NapiPrintExt::ParseMargin(napi_env env, napi_value marginValue, PrintMargin &margin)
{
if (!ParseMarginParam(env, marginValue, margin)) {
PRINT_HILOGD("ParseResolutionParam is error!");
return false;
}
margin.SetTop(PrintNapiUtils::GetUint32Property(env, marginValue, PARAM_MARGIN_TOP));
margin.SetBottom(PrintNapiUtils::GetUint32Property(env, marginValue, PARAM_MARGIN_BOTTOM));
margin.SetLeft(PrintNapiUtils::GetUint32Property(env, marginValue, PARAM_MARGIN_LEFT));
margin.SetRight(PrintNapiUtils::GetUint32Property(env, marginValue, PARAM_MARGIN_RIGHT));
PRINT_HILOGD("printerMargin_value GetTop value is %{public}d", margin.GetTop());
PRINT_HILOGD("printerMargin_value GetBottom value is %{public}d", margin.GetBottom());
PRINT_HILOGD("printerMargin_value GetLeft value is %{public}d", margin.GetLeft());
PRINT_HILOGD("printerMargin_value GetRight value is %{public}d", margin.GetRight());
return true;
}
bool NapiPrintExt::ParseMarginParam(napi_env env, napi_value marginValue, PrintMargin &margin)
{
//±ØÒªÊôÐÔУÑé
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, marginValue, PARAM_MARGIN_TOP);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_number) {
PRINT_HILOGD("error param_one");
return false;
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, marginValue, PARAM_MARGIN_BOTTOM);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_number) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, marginValue, PARAM_MARGIN_LEFT);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, marginValue, PARAM_MARGIN_RIGHT);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
auto names = PrintNapiUtils::GetPropertyNames(env, marginValue);
PRINT_HILOGD("current margin paramster name list size = %{public}zu", names.size());
return true;
}
} // namespace OHOS::Print } // namespace OHOS::Print

View File

@ -18,9 +18,9 @@
#include <mutex> #include <mutex>
#include "async_call.h" #include "async_call.h"
#include "napi_print_utils.h"
#include "print_log.h" #include "print_log.h"
#include "print_manager_client.h" #include "print_manager_client.h"
#include "print_napi_utils.h"
#include "print_task.h" #include "print_task.h"
static constexpr const char *FUNCTION_ON = "on"; static constexpr const char *FUNCTION_ON = "on";
@ -32,6 +32,10 @@ std::mutex mutex_;
napi_value NapiPrintTask::Print(napi_env env, napi_callback_info info) // PrintTask napi_value NapiPrintTask::Print(napi_env env, napi_callback_info info) // PrintTask
{ {
PRINT_HILOGD("Enter print JsMain."); PRINT_HILOGD("Enter print JsMain.");
if (!PrintManagerClient::GetInstance()->LoadServer()) {
PRINT_HILOGE("load print server fail");
return nullptr;
}
struct ContextInfo { struct ContextInfo {
napi_ref ref = nullptr; napi_ref ref = nullptr;
}; };

View File

@ -54,8 +54,8 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_METHOD(FUNCTION_STOP_DISCOVERY, NapiInnerPrint::StopDiscovery), DECLARE_NAPI_METHOD(FUNCTION_STOP_DISCOVERY, NapiInnerPrint::StopDiscovery),
DECLARE_NAPI_METHOD(FUNCTION_CONNECT_PRINT, NapiInnerPrint::ConnectPrint), DECLARE_NAPI_METHOD(FUNCTION_CONNECT_PRINT, NapiInnerPrint::ConnectPrint),
DECLARE_NAPI_METHOD(FUNCTION_DISCONNECT_PRINT, NapiInnerPrint::DisconnectPrint), DECLARE_NAPI_METHOD(FUNCTION_DISCONNECT_PRINT, NapiInnerPrint::DisconnectPrint),
DECLARE_NAPI_METHOD(FUNCTION_START_PRINT, NapiInnerPrint::StartPrint), DECLARE_NAPI_METHOD(FUNCTION_START_PRINT, NapiInnerPrint::StartPrintJob),
DECLARE_NAPI_METHOD(FUNCTION_CANCEL_PRINT, NapiInnerPrint::CancelPrint), DECLARE_NAPI_METHOD(FUNCTION_CANCEL_PRINT, NapiInnerPrint::CancelPrintJob),
DECLARE_NAPI_METHOD(FUNCTION_REQUEST_PREVIEW, NapiInnerPrint::RequestPreview), DECLARE_NAPI_METHOD(FUNCTION_REQUEST_PREVIEW, NapiInnerPrint::RequestPreview),
DECLARE_NAPI_METHOD(FUNCTION_QUERY_CAPABILITY, NapiInnerPrint::QueryCapability), DECLARE_NAPI_METHOD(FUNCTION_QUERY_CAPABILITY, NapiInnerPrint::QueryCapability),
DECLARE_NAPI_METHOD(FUNCTION_REGISTER_EVENT, NapiInnerPrint::On), DECLARE_NAPI_METHOD(FUNCTION_REGISTER_EVENT, NapiInnerPrint::On),

View File

@ -0,0 +1,616 @@
/*
* Copyright (c) 2022 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.
*/
#include "print_parse_type.h"
#include "async_call.h"
#include "napi_print_ext.h"
#include "napi_print_utils.h"
#include "print_log.h"
#include "print_manager_client.h"
namespace OHOS::Print {
static constexpr const char *PARAM_INFO_PRINTID = "printerId";
static constexpr const char *PARAM_INFO_PRINTERNAME = "printerName";
static constexpr const char *PARAM_INFO_PRINTERICON = "printerIcon";
static constexpr const char *PARAM_INFO_PRINTERSTATE = "printerState";
static constexpr const char *PARAM_INFO_DESCRIPTION = "description";
static constexpr const char *PARAM_INFO_CAPABILITY = "capability";
static constexpr const char *PARAM_CAPABILITY_MINMARGIN = "minMargin";
static constexpr const char *PARAM_CAPABILITY_PAGESIZE = "pageSize";
static constexpr const char *PARAM_CAPABILITY_RESOLUTION = "resolution";
static constexpr const char *PARAM_CAPABILITY_COLORMODE = "colorMode";
static constexpr const char *PARAM_CAPABILITY_DUPLEXMODE = "duplexMode";
static constexpr const char *PARAM_PAGESIZE_ID = "id";
static constexpr const char *PARAM_PAGESIZE_NAME = "name";
static constexpr const char *PARAM_PAGESIZE_WIDTH = "width";
static constexpr const char *PARAM_PAGESIZE_HEIGHT = "height";
static constexpr const char *PARAM_RESOLUTION_ID = "id";
static constexpr const char *PARAM_RESOLUTION_HORIZONTALDPI = "horizontalDpi";
static constexpr const char *PARAM_RESOLUTION_VERTICALDPI = "verticalDpi";
static constexpr const char *PARAM_MARGIN_TOP = "top";
static constexpr const char *PARAM_MARGIN_BOTTOM = "bottom";
static constexpr const char *PARAM_MARGIN_LEFT = "left";
static constexpr const char *PARAM_MARGIN_RIGHT = "right";
static constexpr const char *PARAM_JOB_FILES = "files";
static constexpr const char *PARAM_JOB_JOBID = "jobId";
static constexpr const char *PARAM_JOB_PRINTERID = "printerId";
static constexpr const char *PARAM_JOB_JOBSTATE = "jobState";
static constexpr const char *PARAM_JOB_COPYNUMBER = "copyNumber";
static constexpr const char *PARAM_JOB_PAGERANGE = "pageRange";
static constexpr const char *PARAM_JOB_ISSEQUENTIAL = "isSequential";
static constexpr const char *PARAM_JOB_PAGESIZE = "pageSize";
static constexpr const char *PARAM_JOB_ISLANDSCAPE = "isLandscape";
static constexpr const char *PARAM_JOB_COLORMODE = "colorMode";
static constexpr const char *PARAM_JOB_DUPLEXMODE = "duplexMode";
static constexpr const char *PARAM_JOB_MARGIN = "margin";
static constexpr const char *PARAM_JOB_PREVIEW = "preview";
static constexpr const char *PARAM_PREATTRIBUTE_RANGE = "previewRange";
static constexpr const char *PARAM_PREATTRIBUTE_RESULT = "result";
static constexpr const char *PARAM_RANGE_STARTPAGE = "startPage";
static constexpr const char *PARAM_RANGE_ENDPAGE = "endPage";
static constexpr const char *PARAM_RANGE_PAGES = "pages";
bool ParseType::ParseInfo(napi_env env, napi_value InfoValue, PrinterInfo &info)
{
if (!ParseInfoParam(env, InfoValue, info)) {
PRINT_HILOGD("ParseInfoParam is error!");
return false;
}
info.SetPrinterId(PrintNapiUtils::GetUint32Property(env, InfoValue, PARAM_INFO_PRINTID));
info.SetPrinterName(PrintNapiUtils::GetStringPropertyUtf8(env, InfoValue, PARAM_INFO_PRINTERNAME));
info.SetPrinterIcon(PrintNapiUtils::GetUint32Property(env, InfoValue, PARAM_INFO_PRINTERICON));
info.SetPrinterState(PrintNapiUtils::GetUint32Property(env, InfoValue, PARAM_INFO_PRINTERSTATE));
info.SetDescription(PrintNapiUtils::GetStringPropertyUtf8(env, InfoValue, PARAM_INFO_DESCRIPTION));
PRINT_HILOGD("info_value printId value is: %{public}d", info.GetPrintId());
PRINT_HILOGD("info_value printerName value is %{public}s", info.GetPrinterName().c_str());
PRINT_HILOGD("info_value printerIcon value is %{public}d", info.GetPrinterIcon());
PRINT_HILOGD("info_value printerState value is %{public}d", info.GetPrinterState());
PRINT_HILOGD("info_value description value is %{public}s", info.GetDescription().c_str());
return true;
}
bool ParseType::ParseCapability(napi_env env, napi_value capValue, PrinterCapability &capability)
{
if (!ParseCapabilityParam(env, capValue, capability)) {
PRINT_HILOGD("ParseCapabilityParam is error!");
return false;
}
// capability.SetMinMargin(PrintNapiUtils::GetStringPropertyUtf8(env, capValue, PARAM_CAPABILITY_MINMARGIN));
capability.SetColorMode(PrintNapiUtils::GetUint32Property(env, capValue, PARAM_CAPABILITY_COLORMODE));
capability.SetDuplexMode(PrintNapiUtils::GetUint32Property(env, capValue, PARAM_CAPABILITY_DUPLEXMODE));
PRINT_HILOGD("capability_value colorMode value is %{public}d", capability.GetColorMode());
PRINT_HILOGD("capability_value duplexMode value is %{public}d", capability.GetDuplexMode());
return true;
}
bool ParseType::ParsePageSize(napi_env env, napi_value capValue, PrintPageSize &pageSize)
{
if (!ParsePageSizeParam(env, capValue, pageSize)) {
PRINT_HILOGD("ParsePageSizeParam is error!");
return false;
}
pageSize.SetId(PrintNapiUtils::GetStringPropertyUtf8(env, capValue, PARAM_PAGESIZE_ID));
pageSize.SetName(PrintNapiUtils::GetStringPropertyUtf8(env, capValue, PARAM_PAGESIZE_NAME));
pageSize.SetWidth(PrintNapiUtils::GetUint32Property(env, capValue, PARAM_PAGESIZE_WIDTH));
pageSize.SetHeight(PrintNapiUtils::GetUint32Property(env, capValue, PARAM_PAGESIZE_HEIGHT));
PRINT_HILOGD("printerPageSize_value GetId value is %{public}s", pageSize.GetId().c_str());
PRINT_HILOGD("printerPageSize_value GetName value is %{public}s", pageSize.GetName().c_str());
PRINT_HILOGD("printerPageSize_value GetWidth value is %{public}d", pageSize.GetWidth());
PRINT_HILOGD("printerPageSize_value GetHeight value is %{public}d", pageSize.GetHeight());
return true;
}
bool ParseType::ParseResolution(napi_env env, napi_value reValue, PrintResolution &resolution)
{
if (!ParseResolutionParam(env, reValue, resolution)) {
PRINT_HILOGD("ParseResolutionParam is error!");
return false;
}
resolution.SetId(PrintNapiUtils::GetUint32Property(env, reValue, PARAM_RESOLUTION_ID));
resolution.SetHorizontalDpi(PrintNapiUtils::GetUint32Property(env, reValue, PARAM_RESOLUTION_HORIZONTALDPI));
resolution.SetVerticalDpi(PrintNapiUtils::GetUint32Property(env, reValue, PARAM_RESOLUTION_VERTICALDPI));
PRINT_HILOGD("printerResolution_value GetId value is %{public}d", resolution.GetId());
PRINT_HILOGD("printerResolution_value GetHorizontalDpi value is %{public}d", resolution.GetHorizontalDpi());
PRINT_HILOGD("printerResolution_value GetVerticalDpi value is %{public}d", resolution.GetVerticalDpi());
return true;
}
bool ParseType::ParseMargin(napi_env env, napi_value marginValue, PrintMargin &margin)
{
if (!ParseMarginParam(env, marginValue, margin)) {
PRINT_HILOGD("ParseResolutionParam is error!");
return false;
}
margin.SetTop(PrintNapiUtils::GetUint32Property(env, marginValue, PARAM_MARGIN_TOP));
margin.SetBottom(PrintNapiUtils::GetUint32Property(env, marginValue, PARAM_MARGIN_BOTTOM));
margin.SetLeft(PrintNapiUtils::GetUint32Property(env, marginValue, PARAM_MARGIN_LEFT));
margin.SetRight(PrintNapiUtils::GetUint32Property(env, marginValue, PARAM_MARGIN_RIGHT));
PRINT_HILOGD("printerMargin_value GetTop value is %{public}d", margin.GetTop());
PRINT_HILOGD("printerMargin_value GetBottom value is %{public}d", margin.GetBottom());
PRINT_HILOGD("printerMargin_value GetLeft value is %{public}d", margin.GetLeft());
PRINT_HILOGD("printerMargin_value GetRight value is %{public}d", margin.GetRight());
return true;
}
bool ParseType::ParseJob(napi_env env, napi_value jobValue, PrintJob &printJob)
{
if (!ParseJobParam(env, jobValue, printJob)) {
PRINT_HILOGD("ParseJobParam is error!");
return false;
}
printJob.SetJobId(PrintNapiUtils::GetUint32Property(env, jobValue, PARAM_JOB_JOBID));
printJob.SetPrintId(PrintNapiUtils::GetUint32Property(env, jobValue, PARAM_JOB_PRINTERID));
printJob.SetJobState(PrintNapiUtils::GetUint32Property(env, jobValue, PARAM_JOB_JOBSTATE));
printJob.SetCopyNumber(PrintNapiUtils::GetUint32Property(env, jobValue, PARAM_JOB_COPYNUMBER));
PRINT_HILOGD("printJob_value GetJobId value is %{public}d", printJob.GetJobId());
PRINT_HILOGD("printJob_value GetPrinterId value is %{public}d", printJob.GetPrinterId());
PRINT_HILOGD("printJob_value GetJobState value is %{public}d", printJob.GetJobState());
PRINT_HILOGD("printJob_value GetCopyNumber value is %{public}d", printJob.GetCopyNumber());
return true;
}
bool ParseType::ParsePreviewAttribute(napi_env env, napi_value preAttValue, PreviewAttribute &preAtt)
{
if (!ParsePreviewAttributeParam(env, preAttValue, preAtt)) {
PRINT_HILOGD("ParsePreviewAttributeParam is error!");
return false;
}
preAtt.SetResult(PrintNapiUtils::GetStringPropertyUtf8(env, preAttValue, PARAM_PREATTRIBUTE_RESULT));
PRINT_HILOGD("preAtt_value GetResult value is %{public}s", preAtt.GetResult().c_str());
return true;
}
bool ParseType::ParseRange(napi_env env, napi_value rangeValue, PrintRange &range)
{
if (!ParseRangeParam(env, rangeValue, range)) {
PRINT_HILOGD("ParseRangeParam is error!");
return false;
}
range.SetStartPage(PrintNapiUtils::GetUint32Property(env, rangeValue, PARAM_RANGE_STARTPAGE));
range.SetEndPage(PrintNapiUtils::GetUint32Property(env, rangeValue, PARAM_RANGE_ENDPAGE));
PRINT_HILOGD("printRange_value GetStartPage value is %{public}d", range.GetStartPage());
PRINT_HILOGD("printRange_value GetEndPage value is %{public}d", range.GetEndPage());
return true;
}
bool ParseType::ParseInfoParam(napi_env env, napi_value InfoValue, PrinterInfo &info)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_PRINTID);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_number) {
PRINT_HILOGD("error param_one");
return false;
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_PRINTERNAME);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_string) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_PRINTERICON);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_PRINTERSTATE);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
napi_value param_five = PrintNapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_DESCRIPTION);
if (PrintNapiUtils::GetValueType(env, param_five) != napi_string) {
PRINT_HILOGD("error param_five");
return false;
}
napi_value param_six = PrintNapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_CAPABILITY);
if (PrintNapiUtils::GetValueType(env, param_six) != napi_object) {
PRINT_HILOGD("error param_six");
return false;
} else {
PrinterCapability capability;
if (!ParseCapability(env, param_six, capability)) {
PRINT_HILOGD("ParseCapability type error!");
return false;
}
info.SetCapability(capability);
}
return true;
}
bool ParseType::ParseCapabilityParam(napi_env env, napi_value capValue, PrinterCapability &capability)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_MINMARGIN);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_object) {
PRINT_HILOGD("error param_one");
return false;
} else {
PrintMargin margin;
if (!ParseMargin(env, param_one, margin)) {
PRINT_HILOGD("ParseCapability type error!");
return false;
}
capability.SetMinMargin(margin);
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_PAGESIZE);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_object) {
PRINT_HILOGD("error param_two");
return false;
} else {
bool isArray = false;
napi_is_array(env, param_two, &isArray);
if (!isArray) {
PRINT_HILOGD("ParsePageSize type error!");
return false;
}
std::vector<PrintPageSize> pageSizeList;
uint32_t arrayLength = 0;
napi_get_array_length(env, param_two, &arrayLength);
for (uint32_t i = 0; i < arrayLength; i++) {
napi_value pageSizeValue;
PrintPageSize pageSize;
napi_get_element(env, param_two, i, &pageSizeValue);
if (!ParsePageSize(env, pageSizeValue, pageSize)) {
PRINT_HILOGD("ParsePageSize type error!");
return false;
}
pageSizeList.push_back(pageSize);
}
capability.SetPageSize(pageSizeList);
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_RESOLUTION);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_object) {
PRINT_HILOGD("error param_three");
return false;
} else {
bool isReArray = false;
napi_is_array(env, param_three, &isReArray);
if (!isReArray) {
PRINT_HILOGD("PrintResolution type error!");
return false;
}
std::vector<PrintResolution> resolutionList;
uint32_t arrayReLength = 0;
napi_get_array_length(env, param_three, &arrayReLength);
for (uint32_t i = 0; i < arrayReLength; i++) {
napi_value reValue;
PrintResolution resolution;
napi_get_element(env, param_three, i, &reValue);
if (!ParseResolution(env, reValue, resolution)) {
PRINT_HILOGD("PrintResolution type error!");
return false;
}
resolutionList.push_back(resolution);
}
capability.SetResolution(resolutionList);
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_COLORMODE);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
napi_value param_five = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_CAPABILITY_DUPLEXMODE);
if (PrintNapiUtils::GetValueType(env, param_five) != napi_number) {
// ParseCapabilityParam()
PRINT_HILOGD("error param_five");
return false;
}
auto names = PrintNapiUtils::GetPropertyNames(env, capValue);
return true;
}
bool ParseType::ParsePageSizeParam(napi_env env, napi_value capValue, PrintPageSize &pageSize)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_PAGESIZE_ID);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_number) {
PRINT_HILOGD("error param_one");
return false;
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_PAGESIZE_NAME);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_string) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_PAGESIZE_WIDTH);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, capValue, PARAM_PAGESIZE_HEIGHT);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
return true;
}
bool ParseType::ParseResolutionParam(napi_env env, napi_value reValue, PrintResolution &resolution)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, reValue, PARAM_RESOLUTION_ID);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_number) {
PRINT_HILOGD("error param_one");
return false;
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, reValue, PARAM_RESOLUTION_HORIZONTALDPI);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_number) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, reValue, PARAM_RESOLUTION_VERTICALDPI);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
return true;
}
bool ParseType::ParseMarginParam(napi_env env, napi_value marginValue, PrintMargin &margin)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, marginValue, PARAM_MARGIN_TOP);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_number) {
PRINT_HILOGD("error param_one");
return false;
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, marginValue, PARAM_MARGIN_BOTTOM);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_number) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, marginValue, PARAM_MARGIN_LEFT);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, marginValue, PARAM_MARGIN_RIGHT);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
auto names = PrintNapiUtils::GetPropertyNames(env, marginValue);
PRINT_HILOGD("current margin paramster name list size = %{public}zu", names.size());
return true;
}
bool ParseType::ParseJobParam(napi_env env, napi_value jobValue, PrintJob &printJob)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_FILES);
bool isFileArray = false;
napi_is_array(env, param_one, &isFileArray);
if (!isFileArray) {
PRINT_HILOGD("PrinterJobFile type error!");
return false;
}
std::vector<std::string> printfiles;
uint32_t arrayReLength = 0;
napi_get_array_length(env, param_one, &arrayReLength);
for (uint32_t i = 0; i < arrayReLength; i++) {
napi_value filesValue;
napi_get_element(env, param_one, i, &filesValue);
std::string files = PrintNapiUtils::GetStringFromValueUtf8(env, filesValue);
PRINT_HILOGD("printJob_value param_one %{public}s", files.c_str());
printfiles.push_back(files);
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_JOBID);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_number) {
PRINT_HILOGD("error param_two");
return false;
}
napi_value param_three = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_PRINTERID);
if (PrintNapiUtils::GetValueType(env, param_three) != napi_number) {
PRINT_HILOGD("error param_three");
return false;
}
napi_value param_four = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_JOBSTATE);
// napi_value jobState = PrintNapiUtils::GetNamedProperty(env, param_four, PARAM_JOB_PRINTERSTATE);
if (PrintNapiUtils::GetValueType(env, param_four) != napi_number) {
PRINT_HILOGD("error param_four");
return false;
}
napi_value param_five = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_COPYNUMBER);
if (PrintNapiUtils::GetValueType(env, param_five) != napi_number) {
PRINT_HILOGD("error param_five");
return false;
}
napi_value param_six = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_PAGERANGE);
if (PrintNapiUtils::GetValueType(env, param_six) != napi_object) {
PRINT_HILOGD("error param_six");
return false;
} else {
PrintRange range;
if (!ParseRange(env, param_six, range)) {
PRINT_HILOGD("ParseRange type error!");
return false;
}
printJob.SetPageRange(range);
}
PRINT_HILOGD("param_six END");
// ·Ç±ØÒª²ÎÊý
if (!PrintNapiUtils::HasNamedProperty(env, jobValue, PARAM_JOB_ISSEQUENTIAL)) {
PRINT_HILOGD("No isSequential present, ignore it");
} else {
napi_value param_seven = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_ISSEQUENTIAL);
if (PrintNapiUtils::GetValueType(env, param_seven) != napi_boolean) {
PRINT_HILOGD("error param_seven");
return false;
} else {
printJob.SetIsSequential(PrintNapiUtils::GetUint32Property(env, jobValue, PARAM_JOB_ISSEQUENTIAL));
PRINT_HILOGD(
"printJob_value IsSequential value is %{public}s", printJob.GetIsSequential() ? "true" : "false");
}
}
if (!PrintNapiUtils::HasNamedProperty(env, jobValue, PARAM_JOB_PAGESIZE)) {
PRINT_HILOGD("No pageSize present, ignore it");
} else {
napi_value param_eight = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_PAGESIZE);
if (PrintNapiUtils::GetValueType(env, param_eight) != napi_object) {
PRINT_HILOGD("error param_eight");
return false;
} else {
PrintPageSize pagesize;
if (!ParsePageSize(env, param_eight, pagesize)) {
PRINT_HILOGD("ParsePageSize type error!");
return false;
}
printJob.SetPageSize(pagesize);
}
}
if (!PrintNapiUtils::HasNamedProperty(env, jobValue, PARAM_JOB_ISLANDSCAPE)) {
PRINT_HILOGD("No isLandscape present, ignore it");
} else {
napi_value param_nine = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_ISLANDSCAPE);
if (PrintNapiUtils::GetValueType(env, param_nine) != napi_boolean) {
PRINT_HILOGD("error param_nine");
return false;
} else {
printJob.SetIsLandscape(PrintNapiUtils::GetBooleanProperty(env, jobValue, PARAM_JOB_ISLANDSCAPE));
PRINT_HILOGD(
"printJob_value SetIsLandscape value is %{public}s", printJob.GetIsLandscape() ? "true" : "false");
}
}
if (!PrintNapiUtils::HasNamedProperty(env, jobValue, PARAM_JOB_COLORMODE)) {
PRINT_HILOGD("No colorMode present, ignore it");
} else {
napi_value param_ten = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_COLORMODE);
if (PrintNapiUtils::GetValueType(env, param_ten) != napi_number) {
PRINT_HILOGD("error param_ten");
return false;
} else {
printJob.SetColorMode(PrintNapiUtils::GetUint32Property(env, jobValue, PARAM_JOB_COLORMODE));
PRINT_HILOGD("printJob_value ColorMode value is %{public}d", printJob.GetIsSequential());
}
}
if (!PrintNapiUtils::HasNamedProperty(env, jobValue, PARAM_JOB_DUPLEXMODE)) {
PRINT_HILOGD("No duplexMode present, ignore it");
} else {
napi_value param_eleven = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_DUPLEXMODE);
if (PrintNapiUtils::GetValueType(env, param_eleven) != napi_number) {
PRINT_HILOGD("error param_eleven");
return false;
} else {
printJob.SetDuplexMode(PrintNapiUtils::GetUint32Property(env, jobValue, PARAM_JOB_DUPLEXMODE));
PRINT_HILOGD("printJob_value DuplexMode value is %{public}d", printJob.GetDuplexMode());
}
}
if (!PrintNapiUtils::HasNamedProperty(env, jobValue, PARAM_JOB_MARGIN)) {
PRINT_HILOGD("No isSequential present, ignore it");
} else {
napi_value param_twelve = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_MARGIN);
if (PrintNapiUtils::GetValueType(env, param_twelve) != napi_object) {
PRINT_HILOGD("error param_twelve");
return false;
} else {
PrintMargin margin;
if (!ParseMargin(env, param_twelve, margin)) {
PRINT_HILOGD("PrintMargin type error!");
}
printJob.SetMargin(margin);
}
}
if (!PrintNapiUtils::HasNamedProperty(env, jobValue, PARAM_JOB_PREVIEW)) {
PRINT_HILOGD("No PreviewAttribute present, ignore it");
} else {
napi_value param_thirteen = PrintNapiUtils::GetNamedProperty(env, jobValue, PARAM_JOB_PREVIEW);
PreviewAttribute previewAttribute;
if (!ParsePreviewAttribute(env, param_thirteen, previewAttribute)) {
PRINT_HILOGD("ParsePreviewAttribute type error!");
return false;
}
printJob.SetPreview(previewAttribute);
}
return true;
}
bool ParseType::ParsePreviewAttributeParam(napi_env env, napi_value preAttValue, PreviewAttribute &preAtt)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, preAttValue, PARAM_PREATTRIBUTE_RANGE);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_object) {
PRINT_HILOGD("error param_one");
return false;
} else {
PrintRange range;
if (!ParseRange(env, param_one, range)) {
PRINT_HILOGD("ParseRange type error!");
return false;
}
preAtt.SetPreviewRange(range);
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, preAttValue, PARAM_PREATTRIBUTE_RESULT);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_string) {
PRINT_HILOGD("error param_two");
return false;
}
return true;
}
bool ParseType::ParseRangeParam(napi_env env, napi_value rangeValue, PrintRange &range)
{
napi_value param_one = PrintNapiUtils::GetNamedProperty(env, rangeValue, PARAM_RANGE_STARTPAGE);
if (PrintNapiUtils::GetValueType(env, param_one) != napi_number) {
PRINT_HILOGD("error param_one");
return false;
}
napi_value param_two = PrintNapiUtils::GetNamedProperty(env, rangeValue, PARAM_RANGE_ENDPAGE);
if (PrintNapiUtils::GetValueType(env, param_two) != napi_number) {
PRINT_HILOGD("error param_two");
return false;
}
PRINT_HILOGD("Set startPage, endPage value begin.");
napi_value startPage, endPage, param_three = PrintNapiUtils::GetNamedProperty(env, rangeValue, PARAM_RANGE_PAGES);
bool isArray = false;
napi_is_array(env, param_three, &isArray);
uint32_t arrayLength = 0, startPageNum, endPageNum;
napi_get_array_length(env, param_three, &arrayLength);
if (!isArray || arrayLength != 2) {
PRINT_HILOGD("ParseRangeParam pages array error!");
return false;
}
PRINT_HILOGD("Set startPageNum value begin.");
napi_get_element(env, param_three, 0, &startPage);
napi_get_element(env, param_three, 1, &endPage);
napi_get_value_uint32(env, startPage, &startPageNum);
napi_get_value_uint32(env, endPage, &endPageNum);
if (startPageNum > endPageNum) {
PRINT_HILOGD("startPage is less than endPage, Param Pages is illegal!");
return false;
}
PRINT_HILOGD("Set page value begin.");
std::vector<uint32_t> page = { startPageNum, endPageNum };
range.SetPages(page);
PRINT_HILOGD("SetPage value is : %{public}d, %{public}d.", startPageNum, endPageNum);
return true;
}
} // namespace OHOS::Print

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 Huawei Device Co., Ltd. <!-- Copyright (c) 2022 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
@ -17,7 +17,7 @@
<systemability> <systemability>
<name>3707</name> <name>3707</name>
<libpath>libprint_service.z.so</libpath> <libpath>libprint_service.z.so</libpath>
<run-on-create>true</run-on-create> <run-on-create>false</run-on-create>
<distributed>false</distributed> <distributed>false</distributed>
<dump-level>1</dump-level> <dump-level>1</dump-level>
</systemability> </systemability>

View File

@ -1,4 +1,4 @@
# Copyright (C) 2022 Huawei Device Co., Ltd. # Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at

View File

@ -1,4 +1,4 @@
# Copyright (C) 2022 Huawei Device Co., Ltd. # Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
@ -26,9 +26,9 @@ ohos_shared_library("print_service") {
sources = [ sources = [
"src/print_service_ability.cpp", "src/print_service_ability.cpp",
"src/print_service_stub.cpp", "src/print_service_stub.cpp",
"src/print_notify_proxy.cpp", "src/print_callback_proxy.cpp",
"src/print_service_manager.cpp", "src/print_service_manager.cpp",
"src/print_extcb_proxy.cpp", "src/print_extension_callback_proxy.cpp",
] ]
public_configs = [ public_configs = [

View File

@ -16,18 +16,18 @@
#ifndef PRINT_NOTIFY_PROXY_H #ifndef PRINT_NOTIFY_PROXY_H
#define PRINT_NOTIFY_PROXY_H #define PRINT_NOTIFY_PROXY_H
#include "iprint_callback.h"
#include "iremote_proxy.h" #include "iremote_proxy.h"
#include "print_notify_interface.h"
namespace OHOS::Print { namespace OHOS::Print {
class PrintNotifyProxy : public IRemoteProxy<PrintNotifyInterface> { class PrintCallbackProxy : public IRemoteProxy<IPrintCallback> {
public: public:
explicit PrintNotifyProxy(const sptr<IRemoteObject> &impl); explicit PrintCallbackProxy(const sptr<IRemoteObject> &impl);
~PrintNotifyProxy() = default; ~PrintCallbackProxy() = default;
void OnCallBack(MessageParcel &data) override; void OnCallBack(MessageParcel &data) override;
private: private:
static inline BrokerDelegator<PrintNotifyProxy> delegator_; static inline BrokerDelegator<PrintCallbackProxy> delegator_;
}; };
} // namespace OHOS::Print } // namespace OHOS::Print

View File

@ -13,24 +13,25 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef PRINT_EXTCB_PROXY_H #ifndef PRINT_EXTENSION_CALLBACK_PROXY_H
#define PRINT_EXTCB_PROXY_H #define PRINT_EXTENSION_CALLBACK_PROXY_H
#include "iprint_extension_callback.h"
#include "iremote_proxy.h" #include "iremote_proxy.h"
#include "print_extcb_interface.h"
namespace OHOS::Print { namespace OHOS::Print {
class PrintExtcbProxy : public IRemoteProxy<PrintExtcbInterface> { class PrintExtensionCallbackProxy : public IRemoteProxy<IPrintExtensionCallback> {
public: public:
explicit PrintExtcbProxy(const sptr<IRemoteObject> &impl); explicit PrintExtensionCallbackProxy(const sptr<IRemoteObject> &impl);
~PrintExtcbProxy() = default; ~PrintExtensionCallbackProxy() = default;
bool OnCallback() override; bool OnCallback() override;
bool OnCallback(uint32_t printerId) override; bool OnCallback(uint32_t printerId) override;
bool OnCallback(const PrintJob &job) override; bool OnCallback(const PrintJob &job) override;
bool OnCallback(uint32_t printerId, MessageParcel &reply) override;
private: private:
static inline BrokerDelegator<PrintExtcbProxy> delegator_; static inline BrokerDelegator<PrintExtensionCallbackProxy> delegator_;
}; };
} // namespace OHOS::Print } // namespace OHOS::Print
#endif // PRINT_EXTCB_PROXY_H #endif // PRINT_EXTENSION_CALLBACK_PROXY_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -21,8 +21,8 @@
#include <vector> #include <vector>
#include "event_handler.h" #include "event_handler.h"
#include "iprint_callback.h"
#include "iremote_object.h" #include "iremote_object.h"
#include "print_notify_interface.h"
#include "print_service_stub.h" #include "print_service_stub.h"
#include "system_ability.h" #include "system_ability.h"
@ -40,8 +40,7 @@ public:
~PrintServiceAbility(); ~PrintServiceAbility();
static sptr<PrintServiceAbility> GetInstance(); static sptr<PrintServiceAbility> GetInstance();
int32_t StartPrint() override; int32_t StartPrint() override;
bool On(const std::string &type, uint32_t &state, PrinterInfo &info, bool On(const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<IPrintCallback> &listener) override;
const sptr<PrintNotifyInterface> &listener) override;
bool Off(const std::string &type) override; bool Off(const std::string &type) override;
bool AddPrinters(const std::vector<PrinterInfo> &arrayPrintInfo) override; bool AddPrinters(const std::vector<PrinterInfo> &arrayPrintInfo) override;
bool RemovePrinters(const std::vector<PrinterInfo> &arrayPrintInfo) override; bool RemovePrinters(const std::vector<PrinterInfo> &arrayPrintInfo) override;
@ -57,7 +56,7 @@ public:
bool RequestPreview(const PrintJob &jobinfo, std::string &previewResult) override; bool RequestPreview(const PrintJob &jobinfo, std::string &previewResult) override;
bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability) override; bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability) override;
bool CheckPermission() override; bool CheckPermission() override;
bool RegisterExtCallback(uint32_t callbackId, const sptr<PrintExtcbInterface> &listener) override; bool RegisterExtCallback(uint32_t callbackId, const sptr<IPrintExtensionCallback> &listener) override;
bool UnregisterAllExtCallback() override; bool UnregisterAllExtCallback() override;
static void DataWriteInfo(PrinterInfo info, MessageParcel &data); static void DataWriteInfo(PrinterInfo info, MessageParcel &data);
@ -80,9 +79,9 @@ private:
static std::mutex instanceLock_; static std::mutex instanceLock_;
static sptr<PrintServiceAbility> instance_; static sptr<PrintServiceAbility> instance_;
static std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_; static std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
std::map<std::string, sptr<PrintNotifyInterface>> registeredListeners_; std::map<std::string, sptr<IPrintCallback>> registeredListeners_;
std::map<uint32_t, sptr<PrintExtcbInterface>> extCallbackMap_; std::map<uint32_t, sptr<IPrintExtensionCallback>> extCallbackMap_;
std::vector<sptr<PrintNotifyInterface>> unlockVecListeners_; std::vector<sptr<IPrintCallback>> unlockVecListeners_;
std::mutex listenerMapMutex_; std::mutex listenerMapMutex_;
std::mutex lock_; std::mutex lock_;
const int32_t startTime_ = 1900; const int32_t startTime_ = 1900;

View File

@ -25,10 +25,10 @@
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
#include "iprint_callback.h"
#include "print_constant.h" #include "print_constant.h"
#include "print_extension_info.h" #include "print_extension_info.h"
#include "print_job.h" #include "print_job.h"
#include "print_notify_interface.h"
#include "printer_capability.h" #include "printer_capability.h"
#include "printer_info.h" #include "printer_info.h"
@ -38,7 +38,7 @@ using PrintTaskCallback = void (*)(const std::string &type, uint32_t taskId, uin
class PrintServiceManager final { class PrintServiceManager final {
public: public:
static PrintServiceManager *GetInstance(); static PrintServiceManager *GetInstance();
bool On(const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<PrintNotifyInterface> &listener); bool On(const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<IPrintCallback> &listener);
bool Off(const std::string &type); bool Off(const std::string &type);
bool ConnectPrinter(uint32_t printerId); bool ConnectPrinter(uint32_t printerId);
bool DisconnectPrinter(uint32_t printerId); bool DisconnectPrinter(uint32_t printerId);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -16,11 +16,11 @@
#ifndef PRINT_SERVICE_STUB_H #ifndef PRINT_SERVICE_STUB_H
#define PRINT_SERVICE_STUB_H #define PRINT_SERVICE_STUB_H
#include "iprint_service.h"
#include "iremote_stub.h" #include "iremote_stub.h"
#include "print_service_interface.h"
namespace OHOS::Print { namespace OHOS::Print {
class PrintServiceStub : public IRemoteStub<PrintServiceInterface> { class PrintServiceStub : public IRemoteStub<IPrintService> {
public: public:
explicit PrintServiceStub(); explicit PrintServiceStub();
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -12,23 +12,23 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "print_notify_proxy.h" #include "print_callback_proxy.h"
#include "message_parcel.h" #include "message_parcel.h"
#include "print_log.h" #include "print_log.h"
namespace OHOS::Print { namespace OHOS::Print {
PrintNotifyProxy::PrintNotifyProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<PrintNotifyInterface>(impl) {} PrintCallbackProxy::PrintCallbackProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IPrintCallback>(impl) {}
void PrintNotifyProxy::OnCallBack(MessageParcel &data) void PrintCallbackProxy::OnCallBack(MessageParcel &data)
{ {
PRINT_HILOGD("PrintNotifyProxy::OnCallBack Start"); PRINT_HILOGD("PrintCallbackProxy::OnCallBack Start");
PRINT_HILOGD("data should be filled within service module"); PRINT_HILOGD("data should be filled within service module");
MessageParcel realData; MessageParcel realData;
MessageParcel reply; MessageParcel reply;
MessageOption option; MessageOption option;
if (!realData.WriteInterfaceToken(PrintNotifyProxy::GetDescriptor())) { if (!realData.WriteInterfaceToken(PrintCallbackProxy::GetDescriptor())) {
PRINT_HILOGE("write descriptor failed"); PRINT_HILOGE("write descriptor failed");
return; return;
} }
@ -42,6 +42,6 @@ void PrintNotifyProxy::OnCallBack(MessageParcel &data)
if (error != 0) { if (error != 0) {
PRINT_HILOGE("SendRequest failed, error %{public}d", error); PRINT_HILOGE("SendRequest failed, error %{public}d", error);
} }
PRINT_HILOGD("PrintNotifyProxy::OnCallBack End"); PRINT_HILOGD("PrintCallbackProxy::OnCallBack End");
} }
} // namespace OHOS::Print } // namespace OHOS::Print

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -12,17 +12,19 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "print_extcb_proxy.h" #include "print_extension_callback_proxy.h"
#include "message_parcel.h" #include "message_parcel.h"
#include "print_log.h" #include "print_log.h"
namespace OHOS::Print { namespace OHOS::Print {
PrintExtcbProxy::PrintExtcbProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<PrintExtcbInterface>(impl) {} PrintExtensionCallbackProxy::PrintExtensionCallbackProxy(const sptr<IRemoteObject> &impl)
: IRemoteProxy<IPrintExtensionCallback>(impl)
{}
bool PrintExtcbProxy::OnCallback() bool PrintExtensionCallbackProxy::OnCallback()
{ {
PRINT_HILOGD("PrintExtcbProxy::OnCallBack Start"); PRINT_HILOGD("PrintExtensionCallbackProxy::OnCallBack Start");
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
MessageOption option; MessageOption option;
@ -33,13 +35,13 @@ bool PrintExtcbProxy::OnCallback()
PRINT_HILOGE("SendRequest failed, error %{public}d", error); PRINT_HILOGE("SendRequest failed, error %{public}d", error);
return false; return false;
} }
PRINT_HILOGD("PrintExtcbProxy::OnCallBack End"); PRINT_HILOGD("PrintExtensionCallbackProxy::OnCallBack End");
return true; return true;
} }
bool PrintExtcbProxy::OnCallback(uint32_t printerId) bool PrintExtensionCallbackProxy::OnCallback(uint32_t printerId)
{ {
PRINT_HILOGD("PrintExtcbProxy::OnCallBack Start"); PRINT_HILOGD("PrintExtensionCallbackProxy::OnCallBack Start");
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
MessageOption option; MessageOption option;
@ -51,23 +53,38 @@ bool PrintExtcbProxy::OnCallback(uint32_t printerId)
PRINT_HILOGE("SendRequest failed, error %{public}d", error); PRINT_HILOGE("SendRequest failed, error %{public}d", error);
return false; return false;
} }
PRINT_HILOGD("PrintExtcbProxy::OnCallBack End"); PRINT_HILOGD("PrintExtensionCallbackProxy::OnCallBack End");
return true; return true;
} }
bool PrintExtcbProxy::OnCallback(const PrintJob &job) bool PrintExtensionCallbackProxy::OnCallback(const PrintJob &job)
{ {
PRINT_HILOGD("PrintExtcbProxy::OnCallBack Start"); PRINT_HILOGD("PrintExtensionCallbackProxy::OnCallBack Start");
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
MessageOption option; MessageOption option;
data.WriteInterfaceToken(GetDescriptor()); data.WriteInterfaceToken(GetDescriptor());
job.ConvertToParcel(data);
int error = Remote()->SendRequest(PRINT_EXTCB_PRINTJOB, data, reply, option); int error = Remote()->SendRequest(PRINT_EXTCB_PRINTJOB, data, reply, option);
if (error != 0) { if (error != 0) {
PRINT_HILOGE("SendRequest failed, error %{public}d", error); PRINT_HILOGE("SendRequest failed, error %{public}d", error);
return false; return false;
} }
PRINT_HILOGD("PrintExtensionCallbackProxy::OnCallBack End");
return true;
}
bool PrintExtensionCallbackProxy::OnCallback(uint32_t printerId, MessageParcel &reply)
{
PRINT_HILOGD("PrintExtcbProxy::OnCallBack Start");
MessageParcel data;
MessageOption option;
data.WriteInterfaceToken(GetDescriptor());
int error = Remote()->SendRequest(PRINT_EXTCB_PRINTCAPABILITY, data, reply, option);
if (error != 0) {
PRINT_HILOGE("SendRequest failed, error %{public}d", error);
return false;
}
PRINT_HILOGD("PrintExtcbProxy::OnCallBack End"); PRINT_HILOGD("PrintExtcbProxy::OnCallBack End");
return true; return true;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -98,7 +98,6 @@ void PrintServiceAbility::OnStart()
return; return;
} }
InitServiceHandler(); InitServiceHandler();
int32_t ret = Init(); int32_t ret = Init();
if (ret != ERR_OK) { if (ret != ERR_OK) {
auto callback = [=]() { Init(); }; auto callback = [=]() { Init(); };
@ -322,11 +321,14 @@ bool PrintServiceAbility::QueryPrinterCapability(uint32_t printerId, PrinterCapa
ManualStart(); ManualStart();
PRINT_HILOGD("QueryPrinterCapability started."); PRINT_HILOGD("QueryPrinterCapability started.");
auto it = extCallbackMap_.find(PRINT_EXTCB_REQUEST_CAP); auto it = extCallbackMap_.find(PRINT_EXTCB_REQUEST_CAP);
bool result = false;
MessageParcel reply;
if (it != extCallbackMap_.end()) { if (it != extCallbackMap_.end()) {
return it->second->OnCallback(printerId); result = it->second->OnCallback(printerId, reply);
printerCapability.BuildFromParcel(reply);
} }
PRINT_HILOGW("QueryPrinterCapability Not Register Yet!!!"); PRINT_HILOGW("QueryPrinterCapability Not Register Yet!!!");
return false; return result;
} }
bool PrintServiceAbility::CheckPermission() bool PrintServiceAbility::CheckPermission()
@ -334,7 +336,7 @@ bool PrintServiceAbility::CheckPermission()
return true; return true;
} }
bool PrintServiceAbility::RegisterExtCallback(uint32_t callbackId, const sptr<PrintExtcbInterface> &listener) bool PrintServiceAbility::RegisterExtCallback(uint32_t callbackId, const sptr<IPrintExtensionCallback> &listener)
{ {
PRINT_HILOGD("PrintServiceAbility::RegisterExtCallback started. callbackId=%{public}d", callbackId); PRINT_HILOGD("PrintServiceAbility::RegisterExtCallback started. callbackId=%{public}d", callbackId);
if (callbackId >= PRINT_EXTCB_MAX) { if (callbackId >= PRINT_EXTCB_MAX) {
@ -364,14 +366,14 @@ bool PrintServiceAbility::UnregisterAllExtCallback()
} }
bool PrintServiceAbility::On( bool PrintServiceAbility::On(
const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<PrintNotifyInterface> &listener) const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<IPrintCallback> &listener)
{ {
std::string combineType = type + "-"; std::string combineType = type + "-";
PRINT_HILOGI("PrintServiceAbility::On started. type=%{public}s", combineType.c_str()); PRINT_HILOGI("PrintServiceAbility::On started. type=%{public}s", combineType.c_str());
/*auto iter = registeredListeners_.find(combineType); /*auto iter = registeredListeners_.find(combineType);
if (iter == registeredListeners_.end()) { if (iter == registeredListeners_.end()) {
std::lock_guard<std::mutex> lck(listenerMapMutex_); std::lock_guard<std::mutex> lck(listenerMapMutex_);
std::pair<std::string, sptr<PrintNotifyInterface>> newObj(combineType, listener); std::pair<std::string, sptr<IPrintCallback>> newObj(combineType, listener);
const auto temp = registeredListeners_.insert(newObj); const auto temp = registeredListeners_.insert(newObj);
if (!temp.second) { if (!temp.second) {
PRINT_HILOGE("PrintServiceAbility::On insert type=%{public}s object fail.", combineType.c_str()); PRINT_HILOGE("PrintServiceAbility::On insert type=%{public}s object fail.", combineType.c_str());

View File

@ -56,7 +56,7 @@ PrintServiceManager *PrintServiceManager::GetInstance()
} }
bool PrintServiceManager::On( bool PrintServiceManager::On(
const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<PrintNotifyInterface> &listener) const std::string &type, uint32_t &state, PrinterInfo &info, const sptr<IPrintCallback> &listener)
{ {
PRINT_HILOGE("PrintServiceManager on started."); PRINT_HILOGE("PrintServiceManager on started.");
return true; return true;
@ -171,7 +171,7 @@ bool PrintServiceManager::QueryPrinterCapability(uint32_t printerId, PrinterCapa
std::vector<PrintPageSize> pageSizeList; std::vector<PrintPageSize> pageSizeList;
PrintPageSize pageSize; PrintPageSize pageSize;
pageSize.SetId(6); pageSize.SetId("6");
pageSize.SetName("name"); pageSize.SetName("name");
pageSize.SetWidth(6); pageSize.SetWidth(6);
pageSize.SetHeight(6); pageSize.SetHeight(6);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -18,12 +18,12 @@
#include <vector> #include <vector>
#include "ipc_skeleton.h" #include "ipc_skeleton.h"
#include "iprint_service.h"
#include "message_parcel.h" #include "message_parcel.h"
#include "print_common.h" #include "print_common.h"
#include "print_extension_info.h" #include "print_extension_info.h"
#include "print_job.h" #include "print_job.h"
#include "print_log.h" #include "print_log.h"
#include "print_service_interface.h"
namespace OHOS::Print { namespace OHOS::Print {
using namespace OHOS::HiviewDFX; using namespace OHOS::HiviewDFX;
@ -175,9 +175,8 @@ bool PrintServiceStub::OnStartPrintJob(MessageParcel &data, MessageParcel &reply
{ {
PRINT_HILOGD("PrintServiceStub::OnStartPrintJob in"); PRINT_HILOGD("PrintServiceStub::OnStartPrintJob in");
PrintJob jobinfo; PrintJob jobinfo;
MakePrintJob(data, jobinfo); jobinfo.BuildFromParcel(data);
jobinfo.Dump(); jobinfo.Dump();
bool result = StartPrintJob(jobinfo); bool result = StartPrintJob(jobinfo);
if (!reply.WriteBool(result)) { if (!reply.WriteBool(result)) {
PRINT_HILOGD("WriteBool failed"); PRINT_HILOGD("WriteBool failed");
@ -191,7 +190,7 @@ bool PrintServiceStub::OnCancelPrintJob(MessageParcel &data, MessageParcel &repl
{ {
PRINT_HILOGD("PrintServiceStub::OnCancelPrintJob in"); PRINT_HILOGD("PrintServiceStub::OnCancelPrintJob in");
PrintJob jobinfo; PrintJob jobinfo;
MakePrintJob(data, jobinfo); jobinfo.BuildFromParcel(data);
jobinfo.Dump(); jobinfo.Dump();
bool result = CancelPrintJob(jobinfo); bool result = CancelPrintJob(jobinfo);
@ -302,8 +301,8 @@ bool PrintServiceStub::OnQueryPrinterCapability(MessageParcel &data, MessageParc
PRINT_HILOGD("PrintServiceStub::OnQueryPrinterCapability in"); PRINT_HILOGD("PrintServiceStub::OnQueryPrinterCapability in");
PrinterCapability printerCapability; PrinterCapability printerCapability;
bool result = QueryPrinterCapability(data.ReadUint32(), printerCapability); bool result = QueryPrinterCapability(data.ReadUint32(), printerCapability);
printerCapability.Dump(); printerCapability.ConvertToParcel(reply);
/*
std::vector<PrintPageSize> pageSizeList; std::vector<PrintPageSize> pageSizeList;
std::vector<PrintResolution> resolutionList; std::vector<PrintResolution> resolutionList;
@ -321,21 +320,21 @@ bool PrintServiceStub::OnQueryPrinterCapability(MessageParcel &data, MessageParc
reply.WriteUint32(minMargin.GetLeft()); reply.WriteUint32(minMargin.GetLeft());
reply.WriteUint32(minMargin.GetRight()); reply.WriteUint32(minMargin.GetRight());
for (uint32_t i = 0; i < arraypageSizeLength; i++) { for(uint32_t i = 0; i < arraypageSizeLength; i++) {
reply.WriteUint32(pageSizeList[i].GetId()); reply.WriteString(pageSizeList[i].GetId());
reply.WriteString(pageSizeList[i].GetName()); reply.WriteString(pageSizeList[i].GetName());
reply.WriteUint32(pageSizeList[i].GetWidth()); reply.WriteUint32(pageSizeList[i].GetWidth());
reply.WriteUint32(pageSizeList[i].GetHeight()); reply.WriteUint32(pageSizeList[i].GetHeight());
} }
for (uint32_t i = 0; i < resolutionLength; i++) { for(uint32_t i = 0; i < resolutionLength; i++) {
reply.WriteUint32(resolutionList[i].GetId()); reply.WriteUint32(resolutionList[i].GetId());
reply.WriteUint32(resolutionList[i].GetHorizontalDpi()); reply.WriteUint32(resolutionList[i].GetHorizontalDpi());
reply.WriteUint32(resolutionList[i].GetVerticalDpi()); reply.WriteUint32(resolutionList[i].GetVerticalDpi());
} }
reply.WriteUint32(printerCapability.GetColorMode()); reply.WriteUint32(printerCapability.GetColorMode());
reply.WriteUint32(printerCapability.GetDuplexMode()); reply.WriteUint32(printerCapability.GetDuplexMode());*/
if (!reply.WriteBool(result)) { if (!reply.WriteBool(result)) {
PRINT_HILOGD("WriteBool failed"); PRINT_HILOGD("WriteBool failed");
return false; return false;
@ -372,7 +371,7 @@ bool PrintServiceStub::OnEventOn(MessageParcel &data, MessageParcel &reply)
} }
return true; return true;
} }
sptr<PrintNotifyInterface> listener = iface_cast<PrintNotifyInterface>(remote); sptr<IPrintCallback> listener = iface_cast<IPrintCallback>(remote);
if (listener.GetRefPtr() == nullptr) { if (listener.GetRefPtr() == nullptr) {
PRINT_HILOGD("PrintServiceStub::OnEventOn listener is null"); PRINT_HILOGD("PrintServiceStub::OnEventOn listener is null");
return false; return false;
@ -413,7 +412,7 @@ bool PrintServiceStub::OnRegisterExtCallback(MessageParcel &data, MessageParcel
} }
return true; return true;
} }
sptr<PrintExtcbInterface> listener = iface_cast<PrintExtcbInterface>(remote); sptr<IPrintExtensionCallback> listener = iface_cast<IPrintExtensionCallback>(remote);
if (listener.GetRefPtr() == nullptr) { if (listener.GetRefPtr() == nullptr) {
PRINT_HILOGD("PrintServiceStub::OnRegisterExtCallback listener is null"); PRINT_HILOGD("PrintServiceStub::OnRegisterExtCallback listener is null");
return false; return false;
@ -439,7 +438,7 @@ bool PrintServiceStub::OnUnregisterAllExtCallback(MessageParcel &data, MessagePa
} }
return true; return true;
} }
sptr<PrintExtcbInterface> listener = iface_cast<PrintExtcbInterface>(remote); sptr<IPrintExtensionCallback> listener = iface_cast<IPrintExtensionCallback>(remote);
if (listener.GetRefPtr() == nullptr) { if (listener.GetRefPtr() == nullptr) {
PRINT_HILOGD("PrintServiceStub::OnUnregisterAllExtCallback listener is null"); PRINT_HILOGD("PrintServiceStub::OnUnregisterAllExtCallback listener is null");
return false; return false;
@ -484,7 +483,7 @@ void PrintServiceStub::MakePrintJob(MessageParcel &data, PrintJob &printJob)
printJob.SetIsSequential(data.ReadUint32()); printJob.SetIsSequential(data.ReadUint32());
PrintPageSize pageSize; PrintPageSize pageSize;
pageSize.SetId(data.ReadUint32()); pageSize.SetId(data.ReadString());
pageSize.SetName(data.ReadString()); pageSize.SetName(data.ReadString());
pageSize.SetWidth(data.ReadUint32()); pageSize.SetWidth(data.ReadUint32());
pageSize.SetHeight(data.ReadUint32()); pageSize.SetHeight(data.ReadUint32());
@ -543,7 +542,7 @@ void PrintServiceStub::MakePrinterInfo(MessageParcel &data, PrinterInfo &printer
std::vector<PrintPageSize> pageSizeList; std::vector<PrintPageSize> pageSizeList;
for (uint32_t i = 0; i < pageSizeLength; i++) { for (uint32_t i = 0; i < pageSizeLength; i++) {
PrintPageSize pageSize; PrintPageSize pageSize;
pageSize.SetId(data.ReadUint32()); pageSize.SetId(data.ReadString());
pageSize.SetName(data.ReadString()); pageSize.SetName(data.ReadString());
pageSize.SetWidth(data.ReadUint32()); pageSize.SetWidth(data.ReadUint32());
pageSize.SetHeight(data.ReadUint32()); pageSize.SetHeight(data.ReadUint32());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -19,23 +19,23 @@
namespace OHOS::Print { namespace OHOS::Print {
enum PrinterState { enum PrinterState {
PRINTER_ADD = 1, // new printers arrival PRINTER_ADD = 1, // new printers arrival
PRINTER_REMOVED = 2, // printers lost PRINTER_REMOVED = 2, // printers lost
PRINTER_IDLE = 3, // printer idle PRINTER_IDLE = 3, // printer idle
PRINTER_PRINTING = 4, // printer is working PRINTER_PRINTING = 4, // printer is working
PRINTER_BLOCK = 5, // printer has been blocked PRINTER_BLOCK = 5, // printer has been blocked
PRINTER_BUSY = 6, // printer is busy PRINTER_BUSY = 6, // printer is busy
PRINTER_FAULT = 7, // printer failure PRINTER_FAULT = 7, // printer failure
PRINTER_UNKNOWN, PRINTER_UNKNOWN,
}; };
enum PrintJobState { enum PrintJobState {
PRINT_JOB_INIT = 1, // initial state of print job PRINT_JOB_INIT = 1, // initial state of print job
PRINT_JOB_START = 2, // start print job PRINT_JOB_START = 2, // start print job
PRINT_JOB_PRINTING = 3, // printing PRINT_JOB_PRINTING = 3, // printing
PRINT_JOB_BLOCK = 4, // print job has been blocked PRINT_JOB_BLOCK = 4, // print job has been blocked
PRINT_JOB_COMPLETE = 5, // print completed PRINT_JOB_COMPLETE = 5, // print completed
PRINT_JOB_CANCEL = 6, // print job has been cancelled PRINT_JOB_CANCEL = 6, // print job has been cancelled
}; };
} // namespace OHOS::Print } // namespace OHOS::Print

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -42,29 +42,29 @@
#define PRINT_LOG_TAG "printkit" #define PRINT_LOG_TAG "printkit"
#define PRINT_LOG_DOMAIN 0xD001C00 #define PRINT_LOG_DOMAIN 0xD001C00
static constexpr OHOS::HiviewDFX::HiLogLabel PRINT_LOG_LABEL = { LOG_CORE, PRINT_LOG_DOMAIN, PRINT_LOG_TAG }; static constexpr OHOS::HiviewDFX::HiLogLabel PRINT_LOG_LABEL = {LOG_CORE, PRINT_LOG_DOMAIN, PRINT_LOG_TAG};
#define MAKE_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) #define MAKE_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define PRINT_HILOGF(fmt, ...) \ #define PRINT_HILOGF(fmt, ...) \
(void)OHOS::HiviewDFX::HiLog::Fatal(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, MAKE_FILE_NAME, \ (void)OHOS::HiviewDFX::HiLog::Fatal(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, \
__FUNCTION__, __LINE__, ##__VA_ARGS__) MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define PRINT_HILOGE(fmt, ...) \ #define PRINT_HILOGE(fmt, ...) \
(void)OHOS::HiviewDFX::HiLog::Error(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, MAKE_FILE_NAME, \ (void)OHOS::HiviewDFX::HiLog::Error(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, \
__FUNCTION__, __LINE__, ##__VA_ARGS__) MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define PRINT_HILOGW(fmt, ...) \ #define PRINT_HILOGW(fmt, ...) \
(void)OHOS::HiviewDFX::HiLog::Warn(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, MAKE_FILE_NAME, \ (void)OHOS::HiviewDFX::HiLog::Warn(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, \
__FUNCTION__, __LINE__, ##__VA_ARGS__) MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define PRINT_HILOGD(fmt, ...) \ #define PRINT_HILOGD(fmt, ...) \
(void)OHOS::HiviewDFX::HiLog::Debug(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, MAKE_FILE_NAME, \ (void)OHOS::HiviewDFX::HiLog::Debug(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, \
__FUNCTION__, __LINE__, ##__VA_ARGS__) MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define PRINT_HILOGI(fmt, ...) \ #define PRINT_HILOGI(fmt, ...) \
(void)OHOS::HiviewDFX::HiLog::Info(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, MAKE_FILE_NAME, \ (void)OHOS::HiviewDFX::HiLog::Info(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, \
__FUNCTION__, __LINE__, ##__VA_ARGS__) MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#else #else