mirror of
https://gitee.com/openharmony/print_print_fwk
synced 2024-11-26 18:40:40 +00:00
Add 0828 code
Signed-off-by: @chuangda_1 <fangwanning@huawei.com>
This commit is contained in:
parent
71ee2051cf
commit
f631e65f8f
25
BUILD.gn
Normal file
25
BUILD.gn
Normal file
@ -0,0 +1,25 @@
|
||||
# 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
################################################################################
|
||||
group("print_packages") {
|
||||
if (is_standard_system) {
|
||||
deps = [
|
||||
"etc/init:printservice.rc",
|
||||
"profile:print_sa_profiles",
|
||||
"services:print_service",
|
||||
]
|
||||
}
|
||||
}
|
177
LICENSE
Normal file
177
LICENSE
Normal file
@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
67
OAT.xml
Normal file
67
OAT.xml
Normal file
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (c) 2021 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.
|
||||
|
||||
-->
|
||||
<!-- OAT(OSS Audit Tool) configuration guide:
|
||||
basedir: Root dir, the basedir + project path is the real source file location.
|
||||
licensefile:
|
||||
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
|
||||
|
||||
tasklist(only for batch mode):
|
||||
1. task: Define oat check thread, each task will start a new thread.
|
||||
2. task name: Only an name, no practical effect.
|
||||
3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist.
|
||||
4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist.
|
||||
5. task project: Projects to be checked, the path field define the source root dir of the project.
|
||||
|
||||
|
||||
policyList:
|
||||
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
|
||||
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
|
||||
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
|
||||
3. policyitem type:
|
||||
"compatibility" is used to check license compatibility in the specified path;
|
||||
"license" is used to check source license header in the specified path;
|
||||
"copyright" is used to check source copyright header in the specified path;
|
||||
"import" is used to check source dependency in the specified path, such as import ... ,include ...
|
||||
"filetype" is used to check file type in the specified path, supported file types: archive, binary
|
||||
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
|
||||
|
||||
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
|
||||
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
|
||||
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
|
||||
7. policyitem filefilter: Used to bind filefilter which define filter rules.
|
||||
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
|
||||
|
||||
Note:If the text contains special characters, please escape them according to the following rules:
|
||||
" == >
|
||||
& == >
|
||||
' == >
|
||||
< == >
|
||||
> == >
|
||||
-->
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<licensefile>LICENSE</licensefile>
|
||||
<filefilterlist>
|
||||
<filefilter name="defaultFilter" desc="Files that do not need to be scanned">
|
||||
<filteritem type="filename" name="*.cfg" desc="cfg no need to add policy"/>
|
||||
</filefilter>
|
||||
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies" >
|
||||
<filteritem type="filename" name="*.png" desc="png for hap"/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
58
bundle.json
Normal file
58
bundle.json
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "@ohos/print",
|
||||
"description": "Provide printer management and print ability for 3rd party app",
|
||||
"version": "3.1",
|
||||
"license": "Apache License 2.0",
|
||||
"publishAs": "code-segment",
|
||||
"segment": {
|
||||
"destPath": "base/print/print"
|
||||
},
|
||||
"dirs": {},
|
||||
"scripts": {},
|
||||
"component": {
|
||||
"name": "print",
|
||||
"subsystem": "print",
|
||||
"syscap": [
|
||||
"SystemCapability.MiscServices.Download"
|
||||
],
|
||||
"features": [
|
||||
],
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
],
|
||||
"rom":"2MB",
|
||||
"ram":"10MB",
|
||||
"deps": {
|
||||
"components": [
|
||||
"ability_manager",
|
||||
"aafwk_standard",
|
||||
"appexecfwk_standard",
|
||||
"common_event_service",
|
||||
"distributeddatamgr",
|
||||
"hisysevent_native",
|
||||
"hiviewdfx_hilog_native",
|
||||
"ipc",
|
||||
"safwk",
|
||||
"samgr_standard",
|
||||
"startup_l2",
|
||||
"utils_base"
|
||||
],
|
||||
"third_party": [
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//base/print/print/interfaces/kits/napi:print",
|
||||
"//base/print/print/frameworks/innerkitsimpl:printclient",
|
||||
"//base/print/print/services:print_service",
|
||||
"//base/print/print/etc/init:printservice.rc",
|
||||
"//base/print/print/profile:print_sa_profiles"
|
||||
],
|
||||
"test": [
|
||||
]
|
||||
},
|
||||
"hisysevent_config": [
|
||||
"//base/print/print/hisysevent.yaml"
|
||||
]
|
||||
}
|
||||
}
|
23
etc/init/BUILD.gn
Normal file
23
etc/init/BUILD.gn
Normal file
@ -0,0 +1,23 @@
|
||||
# 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
################################################################################
|
||||
|
||||
ohos_prebuilt_etc("printservice.rc") {
|
||||
source = "printservice.cfg"
|
||||
relative_install_dir = "init"
|
||||
part_name = "print"
|
||||
subsystem_name = "print"
|
||||
}
|
17
etc/init/printservice.cfg
Normal file
17
etc/init/printservice.cfg
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"jobs" : [{
|
||||
"name" : "boot",
|
||||
"cmds" : [
|
||||
"start print_service"
|
||||
]
|
||||
}
|
||||
],
|
||||
"services" : [{
|
||||
"name" : "print_service",
|
||||
"path" : ["/system/bin/sa_main", "/system/profile/print_service.xml"],
|
||||
"uid" : "print",
|
||||
"gid" : ["print", "shell"],
|
||||
"secon" : "u:r:print_service:s0"
|
||||
}
|
||||
]
|
||||
}
|
20
etc/init/printservice.rc
Normal file
20
etc/init/printservice.rc
Normal file
@ -0,0 +1,20 @@
|
||||
# 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.
|
||||
|
||||
on boot
|
||||
start print_service
|
||||
service print_service /system/bin/sa_main /system/profile/print_service.xml
|
||||
class z_core
|
||||
user system
|
||||
group system shell
|
||||
seclabel u:r:print_service:s0
|
80
frameworks/innerkitsimpl/BUILD.gn
Normal file
80
frameworks/innerkitsimpl/BUILD.gn
Normal file
@ -0,0 +1,80 @@
|
||||
# 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.
|
||||
import("//base/request/request/request_aafwk.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
config("print_interfaces_kits_napi_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
cflags_cc = [ "-fexceptions" ]
|
||||
}
|
||||
ohos_shared_library("printclient") {
|
||||
include_dirs = [
|
||||
"//foundation/arkui/ace_engine/frameworks/base/utils",
|
||||
"//foundation/arkui/napi",
|
||||
"//foundation/arkui/napi/interfaces/kits",
|
||||
"//foundation/arkui/napi/interfaces/inner_api",
|
||||
"//third_party/node/src",
|
||||
"//third_party/curl/include",
|
||||
"${ability_runtime_services_path}/common/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/app/",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
"${ability_runtime_services_path}/abilitymgr/include",
|
||||
"${ability_runtime_inner_api_path}/ability_manager/include",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/Isamgr",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"//base/print/print/utils/include",
|
||||
]
|
||||
public_configs = [ ":print_interfaces_kits_napi_config" ]
|
||||
|
||||
sources = [
|
||||
"src/print_manager.cpp",
|
||||
"src/print_notify_stub.cpp",
|
||||
"src/print_service_proxy.cpp",
|
||||
"src/print_cap_ability.cpp",
|
||||
"src/print_margin.cpp",
|
||||
"src/print_page_size.cpp",
|
||||
"src/print_resolution.cpp",
|
||||
"src/print_extension_Info.cpp",
|
||||
"src/print_info.cpp",
|
||||
"src/print_range.cpp",
|
||||
"src/preview_attribute.cpp",
|
||||
"src/print_job.cpp",
|
||||
]
|
||||
deps = [
|
||||
"//foundation/arkui/napi:ace_napi",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//third_party/curl:curl",
|
||||
]
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:data_ability_helper",
|
||||
"ability_runtime:napi_base_context",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"preferences:native_preferences",
|
||||
"relational_store:native_appdatafwk",
|
||||
"relational_store:native_dataability",
|
||||
"relational_store:native_rdb",
|
||||
]
|
||||
relative_install_dir = "module"
|
||||
subsystem_name = "print"
|
||||
part_name = "print"
|
||||
}
|
42
frameworks/innerkitsimpl/include/preview_attribute.h
Normal file
42
frameworks/innerkitsimpl/include/preview_attribute.h
Normal 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.
|
||||
*/
|
||||
#ifndef PRINT_RESUME_H
|
||||
#define PRINT_RESUME_H
|
||||
|
||||
#include <string>
|
||||
#include "print_range.h"
|
||||
#include <cstdint>
|
||||
namespace OHOS::Print {
|
||||
class PreviewAttribute {
|
||||
public:
|
||||
PreviewAttribute();
|
||||
|
||||
void SetResult(const std::string& result_);
|
||||
|
||||
void SetPreviewRange(PrinterRange previewRange);
|
||||
|
||||
[[nodiscard]] const std::string& GetResult() const;
|
||||
|
||||
[[nodiscard]] PrinterRange GetPreviewRange() const;
|
||||
|
||||
void Dump();
|
||||
|
||||
~PreviewAttribute();
|
||||
private:
|
||||
std::string result_;
|
||||
PrinterRange previewRange_;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_RESUME_H
|
62
frameworks/innerkitsimpl/include/print_cap_ability.h
Normal file
62
frameworks/innerkitsimpl/include/print_cap_ability.h
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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_CAP_ABILITY_H
|
||||
#define PRINT_CAP_ABILITY_H
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "print_margin.h"
|
||||
#include "print_page_size.h"
|
||||
#include "print_resolution.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrinterCapability {
|
||||
public:
|
||||
PrinterCapability ();
|
||||
|
||||
void SetMinMargin(PrintMargin &minMargin);
|
||||
|
||||
void SetPageSize(PrinterPageSize pageSize);
|
||||
|
||||
void SetResolution(PrinterResolution resolution);
|
||||
|
||||
void SetColorMode(uint32_t colorMode);
|
||||
|
||||
void SetDuplexMode(uint32_t duplexMode);
|
||||
|
||||
[[nodiscard]] PrintMargin &GetMinMargin();
|
||||
|
||||
[[nodiscard]] std::vector<PrinterPageSize> &GetPageSize();
|
||||
|
||||
[[nodiscard]] std::vector<PrinterResolution> &GetResolution();
|
||||
|
||||
[[nodiscard]] uint32_t GetColorMode();
|
||||
|
||||
[[nodiscard]] uint32_t GetDuplexMode();
|
||||
|
||||
void Dump();
|
||||
|
||||
~PrinterCapability();
|
||||
|
||||
private:
|
||||
PrintMargin minMargin_;
|
||||
std::vector<PrinterPageSize> pageSize_;
|
||||
std::vector<PrinterResolution> resolution_;
|
||||
uint32_t colorMode_;
|
||||
uint32_t duplexMode_;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_CAP_ABILITY_H
|
60
frameworks/innerkitsimpl/include/print_extension_Info.h
Normal file
60
frameworks/innerkitsimpl/include/print_extension_Info.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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_EXTENSION_INFO_H
|
||||
#define PRINT_EXTENSION_INFO_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrinterExtensionInfo {
|
||||
public:
|
||||
PrinterExtensionInfo();
|
||||
|
||||
void SetExtensionId(uint32_t extensionId);
|
||||
|
||||
void SetVendorId(uint32_t vendorId);
|
||||
|
||||
void SetVendorName(const std::string &vendorName);
|
||||
|
||||
void SetVendorIcon(uint32_t vendorIcon);
|
||||
|
||||
void SetVersion(const std::string &version);
|
||||
|
||||
[[nodiscard]] uint32_t GetExtensionId() const;
|
||||
|
||||
[[nodiscard]] uint32_t GetVendorId() const;
|
||||
|
||||
[[nodiscard]] std::string &GetVendorName();
|
||||
|
||||
[[nodiscard]] uint32_t GetVendorIcon() const;
|
||||
|
||||
[[nodiscard]] std::string & GetVersion();
|
||||
|
||||
void Dump();
|
||||
|
||||
~PrinterExtensionInfo();
|
||||
|
||||
private:
|
||||
uint32_t extensionId_;
|
||||
uint32_t vendorId_;
|
||||
std::string vendorName_;
|
||||
uint32_t vendorIcon_;
|
||||
std::string version_;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_EXTENSION_INFO_H
|
80
frameworks/innerkitsimpl/include/print_info.h
Normal file
80
frameworks/innerkitsimpl/include/print_info.h
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2021-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_INFO_H
|
||||
#define PRINT_INFO_H
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include <iosfwd>
|
||||
#include "constant.h"
|
||||
#include "print_cap_ability.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrintInfo final {
|
||||
public:
|
||||
PrintInfo();
|
||||
void SetPrinterId(uint32_t printerId);
|
||||
|
||||
void SetPrinterName(std::string printerName);
|
||||
|
||||
void SetPrinterIcon(uint32_t printIcon);
|
||||
|
||||
void SetPrinterState(uint32_t printerState);
|
||||
|
||||
void SetDescription(std::string description);
|
||||
|
||||
void SetCapability(PrinterCapability capability);
|
||||
|
||||
[[nodiscard]] uint32_t GetPrintId() const;
|
||||
|
||||
[[nodiscard]] std::string &GetPrinterName();
|
||||
|
||||
[[nodiscard]] uint32_t GetPrinterIcon() const;
|
||||
|
||||
[[nodiscard]] uint32_t GetPrinterState() const;
|
||||
|
||||
[[nodiscard]] std::string &GetDescription();
|
||||
|
||||
[[nodiscard]] PrinterCapability &GetCapability();
|
||||
|
||||
enum PrinterState
|
||||
{
|
||||
PRINTER_ADDED = 1,
|
||||
PRINTER_REMOVED = 2,
|
||||
PRINTER_IDLE = 3,
|
||||
PRINTER_PRINTING = 4,
|
||||
PRINTER_BLOCKED = 5,
|
||||
PRINTER_BUSY = 6,
|
||||
PRINTER_FAILED = 7,
|
||||
};
|
||||
|
||||
void Dump();
|
||||
|
||||
private:
|
||||
uint32_t printerId_;
|
||||
|
||||
std::string printerName_;
|
||||
|
||||
uint32_t printerIcon_;
|
||||
|
||||
uint32_t printerState_;
|
||||
|
||||
std::string description_;
|
||||
|
||||
PrinterCapability capability_;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif /* PRINT_INFO_H */
|
122
frameworks/innerkitsimpl/include/print_job.h
Normal file
122
frameworks/innerkitsimpl/include/print_job.h
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2021-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_PRINT_JOB_H
|
||||
#define PRINT_PRINT_JOB_H
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "print_range.h"
|
||||
#include "print_page_size.h"
|
||||
#include "print_margin.h"
|
||||
#include "preview_attribute.h"
|
||||
|
||||
namespace OHOS::Print{
|
||||
class PrintJob {
|
||||
public:
|
||||
PrintJob();
|
||||
|
||||
void SetFiles(std::string files);
|
||||
|
||||
void SetJobId(uint32_t jobId);
|
||||
|
||||
void SetPrintId(uint32_t printerid);
|
||||
|
||||
void SetJobState(uint32_t jobState);
|
||||
|
||||
void SetCopyNumber(uint32_t copyNumber);
|
||||
|
||||
void SetPageRange(PrinterRange pageRange_);
|
||||
|
||||
void SetIsSequential(bool isSequential_);
|
||||
|
||||
void SetPageSize(PrinterPageSize pageSize_);
|
||||
|
||||
void SetIsLandscape(bool isLandscape_);
|
||||
|
||||
void SetColorMode(uint32_t colorMode_);
|
||||
|
||||
void SetDuplexMode(uint32_t duplexmode);
|
||||
|
||||
void SetMargin(PrintMargin margin_);
|
||||
|
||||
void SetPreview(PreviewAttribute preview_);
|
||||
|
||||
std::vector<std::string>&GetFiles();
|
||||
|
||||
uint32_t GetJobId();
|
||||
|
||||
uint32_t GetPrinterId();
|
||||
|
||||
uint32_t GetJobState();
|
||||
|
||||
uint32_t GetCopyNumber();
|
||||
|
||||
PrinterRange &GetPageRange();
|
||||
|
||||
bool GetIsSequential();
|
||||
|
||||
PrinterPageSize &GetPageSize();
|
||||
|
||||
bool GetIsLandscape();
|
||||
|
||||
uint32_t GetColorMode();
|
||||
|
||||
uint32_t GetDuplexMode();
|
||||
|
||||
PrintMargin &GetMargin();
|
||||
|
||||
PreviewAttribute &GetPreview();
|
||||
|
||||
void Dump();
|
||||
|
||||
~PrintJob();
|
||||
private:
|
||||
std::vector<std::string> files_;
|
||||
uint32_t jobId_;
|
||||
uint32_t printerId_;
|
||||
uint32_t jobState_;
|
||||
uint32_t copyNumber_;
|
||||
PrinterRange pageRange_;
|
||||
bool isSequential_;
|
||||
PrinterPageSize pageSize_;
|
||||
bool isLandscape_;
|
||||
int32_t colorMode_;
|
||||
int32_t duplexMode_;
|
||||
PrintMargin margin_;
|
||||
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::Request::Print
|
||||
#endif /* PRINT_PRINT_JOB_H */
|
80
frameworks/innerkitsimpl/include/print_manager.h
Normal file
80
frameworks/innerkitsimpl/include/print_manager.h
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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_MANAGER_H
|
||||
#define PRINT_MANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include "iremote_object.h"
|
||||
#include "refbase.h"
|
||||
#include "print_extension_Info.h"
|
||||
#include "print_notify_stub.h"
|
||||
#include "print_job.h"
|
||||
#include "print_service_interface.h"
|
||||
#include "print_info.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrintSaDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
explicit PrintSaDeathRecipient();
|
||||
~PrintSaDeathRecipient() = default;
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &object) override;
|
||||
};
|
||||
|
||||
class PrintManager : public RefBase {
|
||||
public:
|
||||
PrintManager();
|
||||
bool LoadPrintServer();
|
||||
void LoadServerSuccess();
|
||||
void LoadServerFail();
|
||||
~PrintManager();
|
||||
static sptr<PrintManager> GetInstance();
|
||||
bool CheckPermission();
|
||||
|
||||
void OnRemoteSaDied(const wptr<IRemoteObject> &object);
|
||||
|
||||
//Client Napi
|
||||
int32_t Dummy();
|
||||
bool Print(uint32_t taskId);
|
||||
bool QueryAllExtension(std::vector<PrinterExtensionInfo> &arrayExtensionInfo);
|
||||
bool StartDiscoverPrinter(std::vector<uint32_t> extensionList);
|
||||
bool StopDiscoverPrinter();
|
||||
bool AddPrinters(std::vector<PrintInfo> arrayPrintInfo);
|
||||
bool RemovePrinters(std::vector<PrintInfo> arrayPrintInfo);
|
||||
bool ConnectPrinter(uint32_t printerId);
|
||||
bool DisconnectPrinter(uint32_t printerId);
|
||||
bool StartPrintJob(PrintJob jobinfo);
|
||||
bool CancelPrintJob(PrintJob jobinfo);
|
||||
bool UpdatePrinterState(uint32_t printerId, uint32_t state);
|
||||
bool UpdatePrinterJobState(uint32_t jobId, uint32_t state);
|
||||
bool RequestPreview(PrintJob jobinfo, std::string &previewResult);
|
||||
bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability);
|
||||
|
||||
bool On(uint32_t taskId, const std::string& type, const sptr<PrintNotifyInterface>& listener);
|
||||
bool Off(uint32_t taskId, const std::string& type);
|
||||
|
||||
private:
|
||||
sptr<PrintServiceInterface> GetPrintServiceProxy();
|
||||
|
||||
private:
|
||||
static std::mutex instanceLock_;
|
||||
static sptr<PrintManager> instance_;
|
||||
sptr<PrintServiceInterface> printServiceProxy_;
|
||||
sptr<PrintSaDeathRecipient> deathRecipient_;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_MANAGER_H
|
57
frameworks/innerkitsimpl/include/print_margin.h
Normal file
57
frameworks/innerkitsimpl/include/print_margin.h
Normal 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 PRINT_MARGIN_H
|
||||
#define PRINT_MARGIN_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrintMargin {
|
||||
public:
|
||||
PrintMargin();
|
||||
|
||||
void SetTop(uint32_t top);
|
||||
|
||||
void SetBottom(uint32_t bottom);
|
||||
|
||||
void SetLeft(uint32_t left);
|
||||
|
||||
void SetRight(uint32_t right);
|
||||
|
||||
[[nodiscard]] uint32_t GetTop() const;
|
||||
|
||||
[[nodiscard]] uint32_t GetBottom() const;
|
||||
|
||||
[[nodiscard]] uint32_t GetLeft() const;
|
||||
|
||||
[[nodiscard]] uint32_t GetRight() const;
|
||||
|
||||
PrintMargin &operator=(const PrintMargin &printMargin);
|
||||
|
||||
void Dump();
|
||||
|
||||
~PrintMargin ();
|
||||
|
||||
private:
|
||||
uint32_t top_;
|
||||
uint32_t bottom_;
|
||||
uint32_t left_;
|
||||
uint32_t right_;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_MARGIN_H
|
33
frameworks/innerkitsimpl/include/print_notify_interface.h
Normal file
33
frameworks/innerkitsimpl/include/print_notify_interface.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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_NOTIFY_INTERFACE_H
|
||||
#define PRINT_NOTIFY_INTERFACE_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrintNotifyInterface : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Print.PrintNotifyInterface");
|
||||
virtual void OnCallBack(MessageParcel &data) = 0;
|
||||
};
|
||||
|
||||
enum {
|
||||
PRINT_NOTIFY,
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_NOTIFY_INTERFACE_H
|
33
frameworks/innerkitsimpl/include/print_notify_stub.h
Normal file
33
frameworks/innerkitsimpl/include/print_notify_stub.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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_NOTIFY_STUB_H
|
||||
#define PRINT_NOTIFY_STUB_H
|
||||
|
||||
#include <memory>
|
||||
#include "iremote_stub.h"
|
||||
#include "print_notify_interface.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrintNotifyStub : public IRemoteStub<PrintNotifyInterface> {
|
||||
public:
|
||||
PrintNotifyStub() = default;
|
||||
virtual ~PrintNotifyStub()
|
||||
{
|
||||
}
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_NOTIFY_STUB_H
|
57
frameworks/innerkitsimpl/include/print_page_size.h
Normal file
57
frameworks/innerkitsimpl/include/print_page_size.h
Normal 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 PRINT_PAGESIZE_H
|
||||
#define PRINT_PAGESIZE_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrinterPageSize {
|
||||
public:
|
||||
PrinterPageSize();
|
||||
|
||||
void SetId(uint32_t id);
|
||||
|
||||
void SetName(const std::string &name);
|
||||
|
||||
void SetWidth(uint32_t width);
|
||||
|
||||
void SetHeight(uint32_t height);
|
||||
|
||||
[[nodiscard]] uint32_t GetId() const;
|
||||
|
||||
[[nodiscard]] std::string &GetName();
|
||||
|
||||
[[nodiscard]] uint32_t GetWidth() const;
|
||||
|
||||
[[nodiscard]] uint32_t GetHeight() const;
|
||||
|
||||
PrinterPageSize &operator=(const PrinterPageSize &printerPageSize);
|
||||
|
||||
void Dump();
|
||||
|
||||
~PrinterPageSize ();
|
||||
|
||||
private:
|
||||
uint32_t id_;
|
||||
std::string name_;
|
||||
uint32_t width_;
|
||||
uint32_t height_;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_PAGESIZE_H
|
48
frameworks/innerkitsimpl/include/print_range.h
Normal file
48
frameworks/innerkitsimpl/include/print_range.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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_RANGE_H
|
||||
#define PRINT_RANGE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrinterRange{
|
||||
public:
|
||||
PrinterRange();
|
||||
|
||||
void SetStartPage(uint32_t startPage);
|
||||
|
||||
void SetEndPage(uint32_t endPage);
|
||||
|
||||
void SetPages(uint32_t pages);
|
||||
|
||||
[[nodiscard]]uint32_t GetStartPage() const;
|
||||
|
||||
[[nodiscard]]uint32_t GetEndPage() const;
|
||||
|
||||
[[nodiscard]]std::vector<uint32_t> &GetPages();
|
||||
|
||||
void Dump();
|
||||
|
||||
~PrinterRange();
|
||||
private:
|
||||
uint32_t startPage_;
|
||||
uint32_t endPage_;
|
||||
std::vector<uint32_t> pages_;
|
||||
};
|
||||
}// namespace OHOS::Print
|
||||
#endif // PRINT_RANGE_H
|
52
frameworks/innerkitsimpl/include/print_resolution.h
Normal file
52
frameworks/innerkitsimpl/include/print_resolution.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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_RESOLUTION_H
|
||||
#define PRINT_RESOLUTION_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrinterResolution {
|
||||
public:
|
||||
PrinterResolution();
|
||||
|
||||
void SetId(uint32_t id);
|
||||
|
||||
void SetHorizontalDpi(uint32_t horizontalDpi);
|
||||
|
||||
void SetVerticalDpi(uint32_t verticalDpi);
|
||||
|
||||
[[nodiscard]] uint32_t GetId() const;
|
||||
|
||||
[[nodiscard]] uint32_t GetHorizontalDpi() const;
|
||||
|
||||
[[nodiscard]] uint32_t GetVerticalDpi() const;
|
||||
|
||||
PrinterResolution &operator=(const PrinterResolution &printerResolution);
|
||||
|
||||
void Dump();
|
||||
|
||||
~PrinterResolution ();
|
||||
|
||||
private:
|
||||
uint32_t id_;
|
||||
uint32_t horizontalDpi_;
|
||||
uint32_t verticalDpi_;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_RESOLUTION_H
|
69
frameworks/innerkitsimpl/include/print_service_interface.h
Normal file
69
frameworks/innerkitsimpl/include/print_service_interface.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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_SERVICE_INTERFACE_H
|
||||
#define PRINT_SERVICE_INTERFACE_H
|
||||
|
||||
#include <string>
|
||||
#include "print_notify_interface.h"
|
||||
#include "print_extension_Info.h"
|
||||
#include "print_info.h"
|
||||
#include "print_job.h"
|
||||
#include "iremote_broker.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrintServiceInterface : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Print.PrintServiceInterface");
|
||||
virtual int32_t Dummy() = 0;
|
||||
virtual bool ConnectPrinter(uint32_t printerId) = 0;
|
||||
virtual bool DisconnectPrinter(uint32_t printerId) = 0;
|
||||
virtual bool StartDiscoverPrinter(std::vector<uint32_t> extensionList) = 0;
|
||||
virtual bool StopDiscoverPrinter() = 0;
|
||||
virtual bool QueryAllExtension(std::vector<PrinterExtensionInfo> &arrayExtensionInfo) = 0;
|
||||
virtual bool StartPrintJob(PrintJob jobinfo) = 0;
|
||||
virtual bool CancelPrintJob(PrintJob jobinfo) = 0;
|
||||
virtual bool AddPrinters(std::vector<PrintInfo> arrayPrintInfo) = 0;
|
||||
virtual bool RemovePrinters(std::vector<PrintInfo> arrayPrintInfo) = 0;
|
||||
virtual bool UpdatePrinterState(uint32_t printerId, uint32_t state) = 0;
|
||||
virtual bool UpdatePrinterJobState(uint32_t jobId, uint32_t state) = 0;
|
||||
virtual bool RequestPreview(PrintJob jobinfo, std::string &previewResult) = 0;
|
||||
virtual bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability) = 0;
|
||||
virtual bool CheckPermission() = 0;
|
||||
virtual bool On(uint32_t taskId, const std::string &type, const sptr<PrintNotifyInterface> &listener) = 0;
|
||||
virtual bool Off(uint32_t taskId, const std::string &type) = 0;
|
||||
};
|
||||
|
||||
enum {
|
||||
CMD_DUMMY,
|
||||
CMD_CONNECTPRINTER,
|
||||
CMD_DISCONNECTPRINTER,
|
||||
CMD_STARTDISCOVERPRINTER,
|
||||
CMD_STOPDISCOVERPRINTER,
|
||||
CMD_QUERYALLEXTENSION,
|
||||
CMD_STARTPRINTJOB,
|
||||
CMD_CANCELPRINTJOB,
|
||||
CMD_ADDPRINTERS,
|
||||
CMD_REMOVEPRINTERS,
|
||||
CMD_UPDATEPRINTERSTATE,
|
||||
CMD_UPDATEPRINTERJOBSTATE,
|
||||
CMD_REQUESTPREVIEW,
|
||||
CMD_QUERYPRINTERCAPABILITY,
|
||||
CMD_CHECKPERMISSION,
|
||||
CMD_ON,
|
||||
CMD_OFF,
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_SERVICE_INTERFACE_H
|
51
frameworks/innerkitsimpl/include/print_service_proxy.h
Normal file
51
frameworks/innerkitsimpl/include/print_service_proxy.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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_SERVICE_PROXY_H
|
||||
#define PRINT_SERVICE_PROXY_H
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
#include "print_notify_interface.h"
|
||||
#include "print_service_interface.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrintServiceProxy : public IRemoteProxy<PrintServiceInterface> {
|
||||
public:
|
||||
explicit PrintServiceProxy(const sptr<IRemoteObject> &object);
|
||||
~PrintServiceProxy() = default;
|
||||
DISALLOW_COPY_AND_MOVE(PrintServiceProxy);
|
||||
int32_t Dummy() override;
|
||||
bool ConnectPrinter(uint32_t printerId) override;
|
||||
bool DisconnectPrinter(uint32_t printerId) override;
|
||||
bool QueryAllExtension(std::vector<PrinterExtensionInfo> &arrayExtensionInfo) override;
|
||||
bool StartDiscoverPrinter(std::vector<uint32_t> extensionList) override;
|
||||
bool StopDiscoverPrinter() override;
|
||||
bool StartPrintJob(PrintJob jobinfo) override;
|
||||
bool CancelPrintJob(PrintJob jobinfo) override;
|
||||
bool AddPrinters(std::vector<PrintInfo> arrayPrintInfo) override;
|
||||
bool RemovePrinters(std::vector<PrintInfo> arrayPrintInfo) override;
|
||||
bool UpdatePrinterState(uint32_t printerId, uint32_t state) override;
|
||||
bool UpdatePrinterJobState(uint32_t jobId, uint32_t state) override;
|
||||
bool RequestPreview(PrintJob jobinfo, std::string &previewResult) override;
|
||||
bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability) override;
|
||||
bool CheckPermission() override;
|
||||
bool On(uint32_t taskId, const std::string &type, const sptr<PrintNotifyInterface> &listener) override;
|
||||
bool Off(uint32_t taskId, const std::string &type) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<PrintServiceProxy> delegator_;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_SERVICE_PROXY_H
|
41
frameworks/innerkitsimpl/src/preview_attribute.cpp
Normal file
41
frameworks/innerkitsimpl/src/preview_attribute.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include "preview_attribute.h"
|
||||
#include "log.h"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
namespace OHOS::Print{
|
||||
PreviewAttribute::PreviewAttribute()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PreviewAttribute::~PreviewAttribute()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PreviewAttribute::SetResult(const std::string& result)
|
||||
{
|
||||
result_ = result;
|
||||
}
|
||||
|
||||
void PreviewAttribute::SetPreviewRange(PrinterRange previewRange)
|
||||
{
|
||||
previewRange_ = previewRange;
|
||||
}
|
||||
|
||||
const std::string& PreviewAttribute::GetResult() const
|
||||
{
|
||||
return result_;
|
||||
}
|
||||
|
||||
PrinterRange PreviewAttribute::GetPreviewRange() const
|
||||
{
|
||||
return previewRange_;
|
||||
}
|
||||
|
||||
void PreviewAttribute::Dump()
|
||||
{
|
||||
PRINT_HILOGD("result_: %{public}s", result_.c_str());
|
||||
}
|
||||
}
|
||||
|
86
frameworks/innerkitsimpl/src/print_cap_ability.cpp
Normal file
86
frameworks/innerkitsimpl/src/print_cap_ability.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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_cap_ability.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
PrinterCapability::PrinterCapability ()
|
||||
: colorMode_(1), duplexMode_(1) {
|
||||
|
||||
}
|
||||
|
||||
void PrinterCapability::SetMinMargin(PrintMargin &minMargin)
|
||||
{
|
||||
minMargin_ = minMargin;
|
||||
}
|
||||
|
||||
void PrinterCapability::SetPageSize(PrinterPageSize pageSize)
|
||||
{
|
||||
pageSize_.push_back(pageSize);
|
||||
}
|
||||
|
||||
void PrinterCapability::SetResolution(PrinterResolution resolution)
|
||||
{
|
||||
resolution_.push_back(resolution);
|
||||
}
|
||||
|
||||
void PrinterCapability::SetColorMode(uint32_t colorMode)
|
||||
{
|
||||
colorMode_ = colorMode;
|
||||
}
|
||||
|
||||
void PrinterCapability::SetDuplexMode(uint32_t duplexMode)
|
||||
{
|
||||
duplexMode_ = duplexMode;
|
||||
}
|
||||
|
||||
PrintMargin &PrinterCapability::GetMinMargin()
|
||||
{
|
||||
return minMargin_;
|
||||
}
|
||||
|
||||
std::vector<PrinterPageSize> &PrinterCapability::GetPageSize()
|
||||
{
|
||||
return pageSize_;
|
||||
}
|
||||
|
||||
std::vector<PrinterResolution> &PrinterCapability::GetResolution()
|
||||
{
|
||||
return resolution_;
|
||||
}
|
||||
|
||||
uint32_t PrinterCapability::GetColorMode()
|
||||
{
|
||||
return colorMode_;
|
||||
}
|
||||
|
||||
uint32_t PrinterCapability::GetDuplexMode()
|
||||
{
|
||||
return duplexMode_;
|
||||
}
|
||||
|
||||
void PrinterCapability::Dump()
|
||||
{
|
||||
PRINT_HILOGD("colorMode_ = %{public}d", colorMode_);
|
||||
PRINT_HILOGD("duplexMode_ = %{public}d", duplexMode_);
|
||||
}
|
||||
|
||||
PrinterCapability ::~PrinterCapability ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace OHOS::Print
|
89
frameworks/innerkitsimpl/src/print_extension_Info.cpp
Normal file
89
frameworks/innerkitsimpl/src/print_extension_Info.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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_Info.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
PrinterExtensionInfo::PrinterExtensionInfo ()
|
||||
: extensionId_(0), vendorId_(0), vendorName_("PrinterExtensionInfo"),
|
||||
vendorIcon_(0), version_("PrinterExtensionInfo") {
|
||||
|
||||
}
|
||||
|
||||
void PrinterExtensionInfo::SetExtensionId(uint32_t extensionId)
|
||||
{
|
||||
extensionId_ = extensionId;
|
||||
}
|
||||
|
||||
void PrinterExtensionInfo::SetVendorId(uint32_t vendorId)
|
||||
{
|
||||
vendorId_ = vendorId;
|
||||
}
|
||||
|
||||
void PrinterExtensionInfo::SetVendorName(const std::string &vendorName)
|
||||
{
|
||||
vendorName_ = vendorName;
|
||||
}
|
||||
|
||||
void PrinterExtensionInfo::SetVendorIcon(uint32_t vendorIcon)
|
||||
{
|
||||
vendorIcon_ = vendorIcon;
|
||||
}
|
||||
|
||||
void PrinterExtensionInfo::SetVersion(const std::string &version)
|
||||
{
|
||||
version_ = version;
|
||||
}
|
||||
|
||||
uint32_t PrinterExtensionInfo::GetExtensionId() const
|
||||
{
|
||||
return extensionId_;
|
||||
}
|
||||
|
||||
uint32_t PrinterExtensionInfo::GetVendorId() const
|
||||
{
|
||||
return vendorId_;
|
||||
}
|
||||
|
||||
std::string &PrinterExtensionInfo::GetVendorName()
|
||||
{
|
||||
return vendorName_;
|
||||
}
|
||||
|
||||
uint32_t PrinterExtensionInfo::GetVendorIcon() const
|
||||
{
|
||||
return vendorIcon_;
|
||||
}
|
||||
|
||||
std::string &PrinterExtensionInfo::GetVersion()
|
||||
{
|
||||
return version_;
|
||||
}
|
||||
|
||||
void PrinterExtensionInfo::Dump()
|
||||
{
|
||||
PRINT_HILOGD("extensionId = %{public}d", extensionId_);
|
||||
PRINT_HILOGD("vendorId_ = %{public}d", vendorId_);
|
||||
PRINT_HILOGD("vendorName_ = %{public}s", vendorName_.c_str());
|
||||
PRINT_HILOGD("vendorIcon_ = %{public}d", vendorIcon_);
|
||||
PRINT_HILOGD("version_ = %{public}s", version_.c_str());
|
||||
}
|
||||
|
||||
PrinterExtensionInfo::~PrinterExtensionInfo()
|
||||
{
|
||||
|
||||
}
|
||||
} // namespace OHOS::Print
|
84
frameworks/innerkitsimpl/src/print_info.cpp
Normal file
84
frameworks/innerkitsimpl/src/print_info.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2021-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_info.h"
|
||||
#include "log.h"
|
||||
#include "constant.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
PrintInfo::PrintInfo()
|
||||
: printerId_(0), printerName_(""), printerIcon_(0), printerState_(ERROR_UNKNOWN), description_("") {
|
||||
}
|
||||
|
||||
void PrintInfo::SetPrinterId(uint32_t printerId)
|
||||
{
|
||||
printerId_ = printerId;
|
||||
}
|
||||
void PrintInfo::SetPrinterName(std::string printerName)
|
||||
{
|
||||
printerName_ = printerName;
|
||||
}
|
||||
void PrintInfo::SetPrinterIcon(uint32_t printIcon)
|
||||
{
|
||||
printerIcon_ = printIcon;
|
||||
}
|
||||
void PrintInfo::SetPrinterState(uint32_t printerState)
|
||||
{
|
||||
printerState_ = printerState;
|
||||
}
|
||||
void PrintInfo::SetDescription(std::string description)
|
||||
{
|
||||
description_ = description;
|
||||
}
|
||||
void PrintInfo::SetCapability(PrinterCapability capability)
|
||||
{
|
||||
capability_ = capability;
|
||||
}
|
||||
|
||||
uint32_t PrintInfo::GetPrintId() const
|
||||
{
|
||||
return printerId_;
|
||||
}
|
||||
std::string &PrintInfo::GetPrinterName()
|
||||
{
|
||||
return printerName_;
|
||||
}
|
||||
|
||||
uint32_t PrintInfo::GetPrinterIcon() const
|
||||
{
|
||||
return printerIcon_;
|
||||
}
|
||||
uint32_t PrintInfo::GetPrinterState() const
|
||||
{
|
||||
return printerState_;
|
||||
}
|
||||
std::string &PrintInfo::GetDescription()
|
||||
{
|
||||
return description_;
|
||||
}
|
||||
PrinterCapability &PrintInfo::GetCapability()
|
||||
{
|
||||
return capability_;
|
||||
}
|
||||
|
||||
void PrintInfo::Dump()
|
||||
{
|
||||
PRINT_HILOGD("printerId: %{public}d", printerId_);
|
||||
PRINT_HILOGD("printerName: %{public}s", printerName_.c_str());
|
||||
PRINT_HILOGD("printerIcon: %{public}d", printerIcon_);
|
||||
PRINT_HILOGD("printerState: %{public}d", printerState_);
|
||||
PRINT_HILOGD("description: %{public}s", description_.c_str());
|
||||
}
|
||||
} // namespace OHOS::Print
|
160
frameworks/innerkitsimpl/src/print_job.cpp
Normal file
160
frameworks/innerkitsimpl/src/print_job.cpp
Normal file
@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (C) 2021-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_job.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS::Print{
|
||||
PrintJob::PrintJob()
|
||||
: jobId_(0), jobState_(1), copyNumber_(1), isSequential_(true),
|
||||
isLandscape_(1), colorMode_(1), duplexMode_(1) {
|
||||
|
||||
}
|
||||
|
||||
PrintJob::~PrintJob()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PrintJob::SetFiles(std::string files)
|
||||
{
|
||||
files_.push_back(files);
|
||||
}
|
||||
|
||||
void PrintJob::SetJobId(uint32_t jobId)
|
||||
{
|
||||
jobId_ = jobId;
|
||||
}
|
||||
|
||||
void PrintJob::SetPrintId(uint32_t printerid)
|
||||
{
|
||||
printerId_ = printerid;
|
||||
}
|
||||
|
||||
void PrintJob::SetJobState(uint32_t jobState)
|
||||
{
|
||||
jobState_ = jobState;
|
||||
}
|
||||
void PrintJob::SetCopyNumber(uint32_t copyNumber)
|
||||
{
|
||||
copyNumber_ = copyNumber;
|
||||
}
|
||||
void PrintJob::SetPageRange(PrinterRange pageRange)
|
||||
{
|
||||
pageRange_ = pageRange;
|
||||
}
|
||||
void PrintJob::SetIsSequential(bool isSequential)
|
||||
{
|
||||
isSequential_ = isSequential;
|
||||
}
|
||||
void PrintJob::SetPageSize(PrinterPageSize pageSize)
|
||||
{
|
||||
pageSize_ = pageSize;
|
||||
}
|
||||
void PrintJob::SetIsLandscape(bool isLandscape)
|
||||
{
|
||||
isLandscape_ = isLandscape;
|
||||
}
|
||||
void PrintJob::SetColorMode(uint32_t colorMode)
|
||||
{
|
||||
colorMode_ = colorMode;
|
||||
}
|
||||
void PrintJob::SetDuplexMode(uint32_t duplexmode)
|
||||
{
|
||||
duplexMode_ = duplexmode;
|
||||
}
|
||||
void PrintJob::SetMargin(PrintMargin margin)
|
||||
{
|
||||
margin_ = margin;
|
||||
}
|
||||
void PrintJob::SetPreview(PreviewAttribute preview)
|
||||
{
|
||||
preview_ = preview;
|
||||
}
|
||||
|
||||
std::vector<std::string> &PrintJob::GetFiles()
|
||||
{
|
||||
return files_;
|
||||
}
|
||||
uint32_t PrintJob::GetJobId()
|
||||
{
|
||||
return jobId_;
|
||||
}
|
||||
|
||||
uint32_t PrintJob::GetPrinterId()
|
||||
{
|
||||
return printerId_;
|
||||
}
|
||||
|
||||
uint32_t PrintJob::GetJobState()
|
||||
{
|
||||
return jobState_;
|
||||
}
|
||||
|
||||
uint32_t PrintJob::GetCopyNumber()
|
||||
{
|
||||
return copyNumber_;
|
||||
}
|
||||
PrinterRange &PrintJob::GetPageRange()
|
||||
{
|
||||
return pageRange_;
|
||||
}
|
||||
bool PrintJob::GetIsSequential()
|
||||
{
|
||||
return isSequential_;
|
||||
}
|
||||
PrinterPageSize &PrintJob::GetPageSize()
|
||||
{
|
||||
return pageSize_;
|
||||
}
|
||||
bool PrintJob::GetIsLandscape()
|
||||
{
|
||||
return isLandscape_;
|
||||
}
|
||||
uint32_t PrintJob::GetColorMode()
|
||||
{
|
||||
return colorMode_;
|
||||
}
|
||||
uint32_t PrintJob::GetDuplexMode()
|
||||
{
|
||||
return duplexMode_;
|
||||
}
|
||||
PrintMargin &PrintJob::GetMargin()
|
||||
{
|
||||
return margin_;
|
||||
}
|
||||
PreviewAttribute &PrintJob::GetPreview()
|
||||
{
|
||||
return preview_;
|
||||
}
|
||||
|
||||
void PrintJob::Dump()
|
||||
{
|
||||
uint32_t fileLength = files_.size();
|
||||
for(uint32_t i = 0; i < fileLength; i++)
|
||||
{
|
||||
PRINT_HILOGD("files_ = %{public}s", files_[i].c_str());
|
||||
}
|
||||
|
||||
PRINT_HILOGD("jobId_ = %{public}d", jobId_);
|
||||
PRINT_HILOGD("printerId_ = %{public}d", printerId_);
|
||||
PRINT_HILOGD("jobState_ = %{public}d", jobState_);
|
||||
PRINT_HILOGD("copyNumber_ = %{public}d", copyNumber_);
|
||||
PRINT_HILOGD("isSequential_ = %{public}d", isSequential_);
|
||||
PRINT_HILOGD("isLandscape_ = %{public}d", isLandscape_);
|
||||
PRINT_HILOGD("colorMode_ = %{public}d", colorMode_);
|
||||
PRINT_HILOGD("duplexMode_ = %{public}d", duplexMode_);
|
||||
}
|
||||
}
|
325
frameworks/innerkitsimpl/src/print_manager.cpp
Normal file
325
frameworks/innerkitsimpl/src/print_manager.cpp
Normal file
@ -0,0 +1,325 @@
|
||||
/*
|
||||
* 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_manager.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
std::mutex PrintManager::instanceLock_;
|
||||
sptr<PrintManager> PrintManager::instance_ = nullptr;
|
||||
|
||||
PrintManager::PrintManager() : printServiceProxy_(nullptr), deathRecipient_(nullptr) {
|
||||
}
|
||||
|
||||
PrintManager::~PrintManager()
|
||||
{
|
||||
}
|
||||
|
||||
sptr<PrintManager> PrintManager::GetInstance()
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
std::lock_guard<std::mutex> autoLock(instanceLock_);
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new PrintManager;
|
||||
}
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
bool PrintManager::On(uint32_t taskId, const std::string &type, const sptr<PrintNotifyInterface> &listener)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("Resume quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager On succeeded.");
|
||||
return printServiceProxy_->On(taskId, type, listener);
|
||||
}
|
||||
|
||||
bool PrintManager::Off(uint32_t taskId, const std::string &type)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("Resume quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager Off succeeded.");
|
||||
return printServiceProxy_->Off(taskId, type);
|
||||
}
|
||||
|
||||
sptr<PrintServiceInterface> PrintManager::GetPrintServiceProxy()
|
||||
{
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemAbilityManager == nullptr) {
|
||||
PRINT_HILOGE("Getting SystemAbilityManager failed.");
|
||||
return nullptr;
|
||||
}
|
||||
auto systemAbility = systemAbilityManager->GetSystemAbility(PRINT_SERVICE_ID, "");
|
||||
if (systemAbility == nullptr) {
|
||||
PRINT_HILOGE("Get SystemAbility failed.");
|
||||
return nullptr;
|
||||
}
|
||||
deathRecipient_ = new PrintSaDeathRecipient();
|
||||
systemAbility->AddDeathRecipient(deathRecipient_);
|
||||
sptr<PrintServiceInterface> serviceProxy = iface_cast<PrintServiceInterface>(systemAbility);
|
||||
if (serviceProxy == nullptr) {
|
||||
PRINT_HILOGE("Get PrintManagerProxy from SA failed.");
|
||||
return nullptr;
|
||||
}
|
||||
PRINT_HILOGD("Getting PrintManagerProxy succeeded.");
|
||||
return serviceProxy;
|
||||
}
|
||||
|
||||
void PrintManager::OnRemoteSaDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
|
||||
PrintSaDeathRecipient::PrintSaDeathRecipient()
|
||||
{
|
||||
}
|
||||
|
||||
void PrintSaDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &object)
|
||||
{
|
||||
PRINT_HILOGE("PrintSaDeathRecipient on remote systemAbility died.");
|
||||
PrintManager::GetInstance()->OnRemoteSaDied(object);
|
||||
}
|
||||
|
||||
int32_t PrintManager::Dummy()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool PrintManager::ConnectPrinter(uint32_t printerId)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("AddPrinters quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager AddPrinters succeeded.");
|
||||
return printServiceProxy_->ConnectPrinter(printerId);
|
||||
}
|
||||
|
||||
bool PrintManager::DisconnectPrinter(uint32_t printerId)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("DisconnectPrinter quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager DisconnectPrinter succeeded.");
|
||||
return printServiceProxy_->DisconnectPrinter(printerId);
|
||||
}
|
||||
|
||||
bool PrintManager::QueryAllExtension(std::vector<PrinterExtensionInfo> &arrayExtensionInfo)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("QueryAllExtension quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager QueryAllExtension succeeded.");
|
||||
return printServiceProxy_->QueryAllExtension(arrayExtensionInfo);
|
||||
}
|
||||
|
||||
bool PrintManager::StartDiscoverPrinter(std::vector<uint32_t> extensionList)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("StartDiscoverPrinter quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager StartDiscoverPrinter succeeded.");
|
||||
return printServiceProxy_->StartDiscoverPrinter(extensionList);
|
||||
}
|
||||
|
||||
bool PrintManager::StopDiscoverPrinter()
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("StopDiscoverPrinter quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager StopDiscoverPrint succeeded.");
|
||||
return printServiceProxy_->StopDiscoverPrinter();
|
||||
}
|
||||
|
||||
bool PrintManager::StartPrintJob(PrintJob jobinfo)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("StartPrintJob quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager StartPrintJob succeeded.");
|
||||
return printServiceProxy_->StartPrintJob(jobinfo);
|
||||
}
|
||||
|
||||
bool PrintManager::CancelPrintJob(PrintJob jobinfo)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("CancelPrintJob quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager CancelPrintJob succeeded.");
|
||||
return printServiceProxy_->CancelPrintJob(jobinfo);
|
||||
}////
|
||||
|
||||
bool PrintManager::AddPrinters(std::vector<PrintInfo> arrayPrintInfo)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("AddPrinters quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager AddPrinters succeeded.");
|
||||
return printServiceProxy_->AddPrinters(arrayPrintInfo);
|
||||
}
|
||||
|
||||
bool PrintManager::RemovePrinters(std::vector<PrintInfo> arrayPrintInfo)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("RemovePrinters quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager RemovePrinters succeeded.");
|
||||
return printServiceProxy_->RemovePrinters(arrayPrintInfo);
|
||||
}
|
||||
|
||||
bool PrintManager::UpdatePrinterState(uint32_t printerId, uint32_t state)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("UpdatePrinterState quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager UpdatePrinterState succeeded.");
|
||||
return printServiceProxy_->UpdatePrinterState(printerId, state);
|
||||
}
|
||||
|
||||
bool PrintManager::UpdatePrinterJobState(uint32_t jobId, uint32_t state)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("UpdatePrinterJobState quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager UpdatePrinterJobState succeeded.");
|
||||
return printServiceProxy_->UpdatePrinterJobState(jobId, state);
|
||||
}
|
||||
|
||||
bool PrintManager::RequestPreview(PrintJob jobinfo, std::string &previewResult)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("RequestPreview quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager RequestPreview succeeded.");
|
||||
return printServiceProxy_->RequestPreview(jobinfo, previewResult);
|
||||
}
|
||||
|
||||
bool PrintManager::QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("QueryPrinterCapability quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager QueryPrinterCapability succeeded.");
|
||||
return printServiceProxy_->QueryPrinterCapability(printerId, printerCapability);
|
||||
}
|
||||
|
||||
bool PrintManager::CheckPermission()
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("Resume quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager CheckPermission succeeded.");
|
||||
PRINT_HILOGD("Check Permission enable");
|
||||
return printServiceProxy_->CheckPermission();
|
||||
}
|
||||
|
||||
bool PrintManager::Print(uint32_t taskId)
|
||||
{
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGW("Redo GetPrintServiceProxy");
|
||||
printServiceProxy_ = GetPrintServiceProxy();
|
||||
}
|
||||
if (printServiceProxy_ == nullptr) {
|
||||
PRINT_HILOGE("Print quit because redoing GetPrintServiceProxy failed.");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintManager Print succeeded.");
|
||||
return true;
|
||||
}
|
||||
} // namespace OHOS::Print
|
89
frameworks/innerkitsimpl/src/print_margin.cpp
Normal file
89
frameworks/innerkitsimpl/src/print_margin.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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_margin.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
PrintMargin::PrintMargin ()
|
||||
: top_(0), bottom_(0), left_(0), right_(0) {
|
||||
|
||||
}
|
||||
|
||||
void PrintMargin::SetTop(uint32_t top)
|
||||
{
|
||||
top_ = top;
|
||||
}
|
||||
|
||||
void PrintMargin::SetBottom(uint32_t bottom)
|
||||
{
|
||||
bottom_ = bottom;
|
||||
}
|
||||
|
||||
void PrintMargin::SetLeft(uint32_t left)
|
||||
{
|
||||
left_ = left;
|
||||
}
|
||||
|
||||
void PrintMargin::SetRight(uint32_t right)
|
||||
{
|
||||
right_ = right;
|
||||
}
|
||||
|
||||
uint32_t PrintMargin::GetTop() const
|
||||
{
|
||||
return top_;
|
||||
}
|
||||
|
||||
uint32_t PrintMargin::GetBottom() const
|
||||
{
|
||||
return bottom_;
|
||||
}
|
||||
|
||||
uint32_t PrintMargin::GetLeft() const
|
||||
{
|
||||
return left_;
|
||||
}
|
||||
|
||||
uint32_t PrintMargin::GetRight() const
|
||||
{
|
||||
return right_;
|
||||
}
|
||||
|
||||
PrintMargin &PrintMargin::operator=(const PrintMargin &printMargin)
|
||||
{
|
||||
if(this != &printMargin){
|
||||
this->top_ = printMargin.top_;
|
||||
this->bottom_ = printMargin.bottom_;
|
||||
this->left_ = printMargin.left_;
|
||||
this->right_ = printMargin.right_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void PrintMargin::Dump()
|
||||
{
|
||||
PRINT_HILOGD("top_ = %{public}d", top_);
|
||||
PRINT_HILOGD("bottom_ = %{public}d", bottom_);
|
||||
PRINT_HILOGD("left_ = %{public}d", left_);
|
||||
PRINT_HILOGD("right_ = %{public}d", right_);
|
||||
}
|
||||
|
||||
PrintMargin ::~PrintMargin ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace OHOS::Print
|
41
frameworks/innerkitsimpl/src/print_notify_stub.cpp
Normal file
41
frameworks/innerkitsimpl/src/print_notify_stub.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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_notify_stub.h"
|
||||
#include "print_common.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
int32_t PrintNotifyStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
auto descriptorToken = data.ReadInterfaceToken();
|
||||
if (descriptorToken != GetDescriptor()) {
|
||||
PRINT_HILOGE("Remote descriptor not the same as local descriptor.");
|
||||
return E_PRINT_TRANSACT_ERROR;
|
||||
}
|
||||
PRINT_HILOGD("PrintNotifyStub code----> %{public}u", code);
|
||||
switch (code) {
|
||||
case PRINT_NOTIFY: {
|
||||
OnCallBack(data);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return OHOS::UNKNOWN_TRANSACTION;
|
||||
}
|
||||
}
|
||||
return E_PRINT_OK;
|
||||
}
|
||||
} // namespace OHOS::Print
|
89
frameworks/innerkitsimpl/src/print_page_size.cpp
Normal file
89
frameworks/innerkitsimpl/src/print_page_size.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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_page_size.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
PrinterPageSize::PrinterPageSize ()
|
||||
: id_(0), name_("PrinterPageSize"), width_(0), height_(0) {
|
||||
|
||||
}
|
||||
|
||||
void PrinterPageSize::SetId(uint32_t id)
|
||||
{
|
||||
id_ = id;
|
||||
}
|
||||
|
||||
void PrinterPageSize::SetName(const std::string &name)
|
||||
{
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
void PrinterPageSize::SetWidth(uint32_t width)
|
||||
{
|
||||
width_ = width;
|
||||
}
|
||||
|
||||
void PrinterPageSize::SetHeight(uint32_t height)
|
||||
{
|
||||
height_ = height;
|
||||
}
|
||||
|
||||
uint32_t PrinterPageSize::GetId() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
std::string &PrinterPageSize::GetName()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
uint32_t PrinterPageSize::GetWidth() const
|
||||
{
|
||||
return width_;
|
||||
}
|
||||
|
||||
uint32_t PrinterPageSize::GetHeight() const
|
||||
{
|
||||
return height_;
|
||||
}
|
||||
|
||||
PrinterPageSize &PrinterPageSize::operator=(const PrinterPageSize &printerPageSize)
|
||||
{
|
||||
if(this != &printerPageSize){
|
||||
this->id_ = printerPageSize.id_;
|
||||
this->name_ = printerPageSize.name_;
|
||||
this->width_ = printerPageSize.width_;
|
||||
this->height_ = printerPageSize.height_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void PrinterPageSize::Dump()
|
||||
{
|
||||
PRINT_HILOGD("top_ = %{public}d", id_);
|
||||
PRINT_HILOGD("name_ = %{public}s", name_.c_str());
|
||||
PRINT_HILOGD("width_ = %{public}d", width_);
|
||||
PRINT_HILOGD("height_ = %{public}d", height_);
|
||||
}
|
||||
|
||||
PrinterPageSize ::~PrinterPageSize ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace OHOS::Print
|
71
frameworks/innerkitsimpl/src/print_range.cpp
Normal file
71
frameworks/innerkitsimpl/src/print_range.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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_range.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
PrinterRange::PrinterRange()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PrinterRange::~PrinterRange()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PrinterRange::SetStartPage(uint32_t startpage)
|
||||
{
|
||||
startPage_ = startpage;
|
||||
}
|
||||
|
||||
void PrinterRange::SetEndPage(uint32_t endpage)
|
||||
{
|
||||
endPage_ = endpage;
|
||||
}
|
||||
|
||||
void PrinterRange::SetPages(uint32_t pages)
|
||||
{
|
||||
pages_.push_back(pages);
|
||||
}
|
||||
|
||||
uint32_t PrinterRange::GetStartPage() const
|
||||
{
|
||||
return startPage_;
|
||||
}
|
||||
|
||||
uint32_t PrinterRange::GetEndPage() const
|
||||
{
|
||||
return endPage_;
|
||||
}
|
||||
|
||||
std::vector<uint32_t> &PrinterRange::GetPages()
|
||||
{
|
||||
return pages_;
|
||||
}
|
||||
|
||||
void PrinterRange::Dump()
|
||||
{
|
||||
PRINT_HILOGD("startPage_ = %{public}d", startPage_);
|
||||
PRINT_HILOGD("endPage_ = %{public}d", endPage_);
|
||||
uint32_t pageLength = pages_.size();
|
||||
for(uint32_t i = 0; i < pageLength; i++)
|
||||
{
|
||||
PRINT_HILOGD("pages_ = %{public}d", pages_[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
76
frameworks/innerkitsimpl/src/print_resolution.cpp
Normal file
76
frameworks/innerkitsimpl/src/print_resolution.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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_resolution.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
PrinterResolution::PrinterResolution()
|
||||
: id_(0), horizontalDpi_(0), verticalDpi_(0) {
|
||||
|
||||
}
|
||||
|
||||
void PrinterResolution::SetId(uint32_t id)
|
||||
{
|
||||
id_ = id;
|
||||
}
|
||||
|
||||
void PrinterResolution::SetHorizontalDpi(uint32_t horizontalDpi)
|
||||
{
|
||||
horizontalDpi_ = horizontalDpi;
|
||||
}
|
||||
|
||||
void PrinterResolution::SetVerticalDpi(uint32_t verticalDpi)
|
||||
{
|
||||
verticalDpi_ = verticalDpi;
|
||||
}
|
||||
|
||||
uint32_t PrinterResolution::GetId() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
uint32_t PrinterResolution::GetHorizontalDpi() const
|
||||
{
|
||||
return horizontalDpi_;
|
||||
}
|
||||
|
||||
uint32_t PrinterResolution::GetVerticalDpi() const
|
||||
{
|
||||
return verticalDpi_;
|
||||
}
|
||||
|
||||
PrinterResolution &PrinterResolution::operator=(const PrinterResolution &printerResolution)
|
||||
{
|
||||
if(this != &printerResolution){
|
||||
this->id_ = printerResolution.id_;
|
||||
this->horizontalDpi_ = printerResolution.horizontalDpi_;
|
||||
this->verticalDpi_ = printerResolution.verticalDpi_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void PrinterResolution::Dump()
|
||||
{
|
||||
PRINT_HILOGD("id_ = %{public}d", id_);
|
||||
PRINT_HILOGD("horizontalDpi_ = %{public}d", horizontalDpi_);
|
||||
PRINT_HILOGD("verticalDpi_ = %{public}d", verticalDpi_);
|
||||
}
|
||||
|
||||
PrinterResolution ::~PrinterResolution ()
|
||||
{
|
||||
|
||||
}
|
||||
} // namespace OHOS::Print
|
614
frameworks/innerkitsimpl/src/print_service_proxy.cpp
Normal file
614
frameworks/innerkitsimpl/src/print_service_proxy.cpp
Normal file
@ -0,0 +1,614 @@
|
||||
/*
|
||||
* 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_service_proxy.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include "print_info.h"
|
||||
#include "iremote_broker.h"
|
||||
#include "log.h"
|
||||
#include "print_job.h"
|
||||
#include "print_common.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
PrintServiceProxy::PrintServiceProxy(const sptr<IRemoteObject> &object)
|
||||
: IRemoteProxy<PrintServiceInterface>(object)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t PrintServiceProxy::Dummy()
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
PRINT_HILOGD("PrintServiceProxy Dummy started.");
|
||||
bool ret = Remote()->SendRequest(CMD_DUMMY, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGE("Dummy, ret = %{public}d", ret);
|
||||
return -1;
|
||||
}
|
||||
int32_t taskId = reply.ReadInt32();
|
||||
PRINT_HILOGD("PrintServiceProxy Dummy succeeded. TaskId = %{public}d", taskId);
|
||||
return taskId;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::ConnectPrinter(uint32_t printerId)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
data.WriteUint32(printerId);
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_CONNECTPRINTER, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy ConnectPrinter succeeded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::DisconnectPrinter(uint32_t printerId)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
data.WriteUint32(printerId);
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_DISCONNECTPRINTER, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy DisconnectPrinter succeeded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::QueryAllExtension(std::vector<PrinterExtensionInfo> &arrayExtensionInfo)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
data.WriteUint32(5);
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_QUERYALLEXTENSION, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
uint32_t replyArrayLength = reply.ReadUint32();
|
||||
for(uint32_t i = 0; i < replyArrayLength; i++)
|
||||
{
|
||||
PrinterExtensionInfo printerExtensionInfo;
|
||||
printerExtensionInfo.SetExtensionId(reply.ReadUint32());
|
||||
printerExtensionInfo.SetVendorId(reply.ReadUint32());
|
||||
printerExtensionInfo.SetVendorName(reply.ReadString());
|
||||
printerExtensionInfo.SetVendorIcon(reply.ReadUint32());
|
||||
printerExtensionInfo.SetVersion(reply.ReadString());
|
||||
arrayExtensionInfo.push_back(printerExtensionInfo);
|
||||
arrayExtensionInfo[i].Dump();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::StartDiscoverPrinter(std::vector<uint32_t> extensionList)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
data.WriteUint32(extensionList.size());
|
||||
PRINT_HILOGD("OnStartDiscoverPrinter extensionList.size() = %{public}lu", extensionList.size());
|
||||
for(uint32_t i = 0; i < extensionList.size(); i++)
|
||||
{
|
||||
data.WriteUint32(extensionList[i]);
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_STARTDISCOVERPRINTER, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy StartDiscoverPrinter succeeded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::StopDiscoverPrinter()
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_STOPDISCOVERPRINTER, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy StopDiscoverPrinter succeeded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::StartPrintJob(PrintJob jobinfo)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
|
||||
uint32_t fileLength = jobinfo.GetFiles().size();
|
||||
data.WriteUint32(fileLength);
|
||||
for(uint32_t i = 0; i < fileLength; i++)
|
||||
{
|
||||
data.WriteString(jobinfo.GetFiles()[i]);
|
||||
|
||||
}
|
||||
data.WriteUint32(jobinfo.GetJobId());
|
||||
data.WriteUint32(jobinfo.GetPrinterId());
|
||||
data.WriteUint32(jobinfo.GetJobState());
|
||||
data.WriteUint32(jobinfo.GetCopyNumber());
|
||||
|
||||
data.WriteUint32(jobinfo.GetPageRange().GetStartPage());
|
||||
data.WriteUint32(jobinfo.GetPageRange().GetEndPage());
|
||||
uint32_t pageLength = jobinfo.GetPageRange().GetPages().size();
|
||||
data.WriteUint32(pageLength);
|
||||
for(uint32_t i = 0; i < pageLength; i++)
|
||||
{
|
||||
data.WriteUint32(jobinfo.GetPageRange().GetPages()[i]);
|
||||
}
|
||||
|
||||
data.WriteUint32(jobinfo.GetIsSequential());
|
||||
|
||||
data.WriteUint32(jobinfo.GetPageSize().GetId());
|
||||
data.WriteString(jobinfo.GetPageSize().GetName());
|
||||
data.WriteUint32(jobinfo.GetPageSize().GetWidth());
|
||||
data.WriteUint32(jobinfo.GetPageSize().GetHeight());
|
||||
|
||||
data.WriteUint32(jobinfo.GetIsLandscape());
|
||||
data.WriteUint32(jobinfo.GetColorMode());
|
||||
data.WriteUint32(jobinfo.GetDuplexMode());
|
||||
|
||||
data.WriteUint32(jobinfo.GetMargin().GetTop());
|
||||
data.WriteUint32(jobinfo.GetMargin().GetBottom());
|
||||
data.WriteUint32(jobinfo.GetMargin().GetLeft());
|
||||
data.WriteUint32(jobinfo.GetMargin().GetRight());
|
||||
|
||||
data.WriteString(jobinfo.GetPreview().GetResult());
|
||||
data.WriteUint32(jobinfo.GetPreview().GetPreviewRange().GetStartPage());
|
||||
data.WriteUint32(jobinfo.GetPreview().GetPreviewRange().GetEndPage());
|
||||
uint32_t previewPageLength = jobinfo.GetPreview().GetPreviewRange().GetPages().size();
|
||||
data.WriteUint32(previewPageLength);
|
||||
for(uint32_t i = 0; i < previewPageLength; i++)
|
||||
{
|
||||
data.WriteUint32(jobinfo.GetPreview().GetPreviewRange().GetPages()[i]);
|
||||
}
|
||||
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_STARTPRINTJOB, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy StartPrintJob succeeded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::CancelPrintJob(PrintJob jobinfo)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
|
||||
uint32_t fileLength = jobinfo.GetFiles().size();
|
||||
data.WriteUint32(fileLength);
|
||||
for(uint32_t i = 0; i < fileLength; i++)
|
||||
{
|
||||
data.WriteString(jobinfo.GetFiles()[i]);
|
||||
|
||||
}
|
||||
data.WriteUint32(jobinfo.GetJobId());
|
||||
data.WriteUint32(jobinfo.GetPrinterId());
|
||||
data.WriteUint32(jobinfo.GetJobState());
|
||||
data.WriteUint32(jobinfo.GetCopyNumber());
|
||||
|
||||
data.WriteUint32(jobinfo.GetPageRange().GetStartPage());
|
||||
data.WriteUint32(jobinfo.GetPageRange().GetEndPage());
|
||||
uint32_t pageLength = jobinfo.GetPageRange().GetPages().size();
|
||||
data.WriteUint32(pageLength);
|
||||
for(uint32_t i = 0; i < pageLength; i++)
|
||||
{
|
||||
data.WriteUint32(jobinfo.GetPageRange().GetPages()[i]);
|
||||
}
|
||||
|
||||
data.WriteUint32(jobinfo.GetIsSequential());
|
||||
|
||||
data.WriteUint32(jobinfo.GetPageSize().GetId());
|
||||
data.WriteString(jobinfo.GetPageSize().GetName());
|
||||
data.WriteUint32(jobinfo.GetPageSize().GetWidth());
|
||||
data.WriteUint32(jobinfo.GetPageSize().GetHeight());
|
||||
|
||||
data.WriteUint32(jobinfo.GetIsLandscape());
|
||||
data.WriteUint32(jobinfo.GetColorMode());
|
||||
data.WriteUint32(jobinfo.GetDuplexMode());
|
||||
|
||||
data.WriteUint32(jobinfo.GetMargin().GetTop());
|
||||
data.WriteUint32(jobinfo.GetMargin().GetBottom());
|
||||
data.WriteUint32(jobinfo.GetMargin().GetLeft());
|
||||
data.WriteUint32(jobinfo.GetMargin().GetRight());
|
||||
|
||||
data.WriteString(jobinfo.GetPreview().GetResult());
|
||||
data.WriteUint32(jobinfo.GetPreview().GetPreviewRange().GetStartPage());
|
||||
data.WriteUint32(jobinfo.GetPreview().GetPreviewRange().GetEndPage());
|
||||
uint32_t previewPageLength = jobinfo.GetPreview().GetPreviewRange().GetPages().size();
|
||||
data.WriteUint32(previewPageLength);
|
||||
for(uint32_t i = 0; i < previewPageLength; i++)
|
||||
{
|
||||
data.WriteUint32(jobinfo.GetPreview().GetPreviewRange().GetPages()[i]);
|
||||
}
|
||||
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_CANCELPRINTJOB, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy CancelPrintJob succeeded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::AddPrinters(std::vector<PrintInfo> arrayPrintInfo)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
data.WriteUint32(arrayPrintInfo.size());
|
||||
PRINT_HILOGD("OnStartDiscoverPrinter arrayPrintInfo.size() = %{public}lu", arrayPrintInfo.size());
|
||||
for(uint32_t i = 0; i < arrayPrintInfo.size(); i++)
|
||||
{
|
||||
data.WriteUint32(arrayPrintInfo[i].GetPrintId());
|
||||
data.WriteString(arrayPrintInfo[i].GetPrinterName());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetPrinterIcon());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetPrinterState());
|
||||
data.WriteString(arrayPrintInfo[i].GetDescription());
|
||||
arrayPrintInfo[i].Dump();
|
||||
uint32_t pageSizeLength = arrayPrintInfo[i].GetCapability().GetPageSize().size();
|
||||
uint32_t resolutionLength = arrayPrintInfo[i].GetCapability().GetResolution().size();
|
||||
data.WriteUint32(pageSizeLength);
|
||||
data.WriteUint32(resolutionLength);
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetMinMargin().GetTop());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetMinMargin().GetBottom());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetMinMargin().GetLeft());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetMinMargin().GetRight());
|
||||
arrayPrintInfo[i].GetCapability().GetMinMargin().Dump();
|
||||
for(uint32_t i = 0; i < pageSizeLength; i++)
|
||||
{
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetPageSize()[i].GetId());
|
||||
data.WriteString(arrayPrintInfo[i].GetCapability().GetPageSize()[i].GetName());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetPageSize()[i].GetWidth());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetPageSize()[i].GetHeight());
|
||||
arrayPrintInfo[i].GetCapability().GetPageSize()[i].Dump();
|
||||
}
|
||||
for(uint32_t i = 0; i < resolutionLength; i++)
|
||||
{
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetResolution()[i].GetId());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetResolution()[i].GetHorizontalDpi());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetResolution()[i].GetVerticalDpi());
|
||||
arrayPrintInfo[i].GetCapability().GetResolution()[i].Dump();
|
||||
}
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetColorMode());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetDuplexMode());
|
||||
arrayPrintInfo[i].GetCapability().Dump();
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_ADDPRINTERS, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy AddPrinters succeeded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::RemovePrinters(std::vector<PrintInfo> arrayPrintInfo)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
data.WriteUint32(arrayPrintInfo.size());
|
||||
PRINT_HILOGD("OnStartDiscoverPrinter arrayPrintInfo.size() = %{public}lu", arrayPrintInfo.size());
|
||||
for(uint32_t i = 0; i < arrayPrintInfo.size(); i++)
|
||||
{
|
||||
data.WriteUint32(arrayPrintInfo[i].GetPrintId());
|
||||
data.WriteString(arrayPrintInfo[i].GetPrinterName());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetPrinterIcon());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetPrinterState());
|
||||
data.WriteString(arrayPrintInfo[i].GetDescription());
|
||||
arrayPrintInfo[i].Dump();
|
||||
uint32_t pageSizeLength = arrayPrintInfo[i].GetCapability().GetPageSize().size();
|
||||
uint32_t resolutionLength = arrayPrintInfo[i].GetCapability().GetResolution().size();
|
||||
data.WriteUint32(pageSizeLength);
|
||||
data.WriteUint32(resolutionLength);
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetMinMargin().GetTop());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetMinMargin().GetBottom());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetMinMargin().GetLeft());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetMinMargin().GetRight());
|
||||
arrayPrintInfo[i].GetCapability().GetMinMargin().Dump();
|
||||
for(uint32_t i = 0; i < pageSizeLength; i++)
|
||||
{
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetPageSize()[i].GetId());
|
||||
data.WriteString(arrayPrintInfo[i].GetCapability().GetPageSize()[i].GetName());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetPageSize()[i].GetWidth());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetPageSize()[i].GetHeight());
|
||||
arrayPrintInfo[i].GetCapability().GetPageSize()[i].Dump();
|
||||
}
|
||||
for(uint32_t i = 0; i < resolutionLength; i++)
|
||||
{
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetResolution()[i].GetId());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetResolution()[i].GetHorizontalDpi());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetResolution()[i].GetVerticalDpi());
|
||||
arrayPrintInfo[i].GetCapability().GetResolution()[i].Dump();
|
||||
}
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetColorMode());
|
||||
data.WriteUint32(arrayPrintInfo[i].GetCapability().GetDuplexMode());
|
||||
arrayPrintInfo[i].GetCapability().Dump();
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_REMOVEPRINTERS, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy RemovePrinters succeeded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::UpdatePrinterState(uint32_t printerId, uint32_t state)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
data.WriteUint32(printerId);
|
||||
data.WriteUint32(state);
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_UPDATEPRINTERSTATE, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy UpdatePrinterState succeeded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::UpdatePrinterJobState(uint32_t jobId, uint32_t state)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
data.WriteInt32(jobId);
|
||||
data.WriteUint32(state);
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_UPDATEPRINTERJOBSTATE, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceProxy UpdatePrinterJobState succeeded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::RequestPreview(PrintJob jobinfo, std::string &previewResult)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
uint32_t fileLength = jobinfo.GetFiles().size();
|
||||
data.WriteUint32(fileLength);
|
||||
for(uint32_t i = 0; i < fileLength; i++)
|
||||
{
|
||||
data.WriteString(jobinfo.GetFiles()[i]);
|
||||
|
||||
}
|
||||
data.WriteUint32(jobinfo.GetJobId());
|
||||
data.WriteUint32(jobinfo.GetPrinterId());
|
||||
data.WriteUint32(jobinfo.GetJobState());
|
||||
data.WriteUint32(jobinfo.GetCopyNumber());
|
||||
|
||||
data.WriteUint32(jobinfo.GetPageRange().GetStartPage());
|
||||
data.WriteUint32(jobinfo.GetPageRange().GetEndPage());
|
||||
uint32_t pageLength = jobinfo.GetPageRange().GetPages().size();
|
||||
data.WriteUint32(pageLength);
|
||||
for(uint32_t i = 0; i < pageLength; i++)
|
||||
{
|
||||
data.WriteUint32(jobinfo.GetPageRange().GetPages()[i]);
|
||||
}
|
||||
|
||||
data.WriteUint32(jobinfo.GetIsSequential());
|
||||
|
||||
data.WriteUint32(jobinfo.GetPageSize().GetId());
|
||||
data.WriteString(jobinfo.GetPageSize().GetName());
|
||||
data.WriteUint32(jobinfo.GetPageSize().GetWidth());
|
||||
data.WriteUint32(jobinfo.GetPageSize().GetHeight());
|
||||
|
||||
data.WriteUint32(jobinfo.GetIsLandscape());
|
||||
data.WriteUint32(jobinfo.GetColorMode());
|
||||
data.WriteUint32(jobinfo.GetDuplexMode());
|
||||
|
||||
data.WriteUint32(jobinfo.GetMargin().GetTop());
|
||||
data.WriteUint32(jobinfo.GetMargin().GetBottom());
|
||||
data.WriteUint32(jobinfo.GetMargin().GetLeft());
|
||||
data.WriteUint32(jobinfo.GetMargin().GetRight());
|
||||
|
||||
data.WriteString(jobinfo.GetPreview().GetResult());
|
||||
data.WriteUint32(jobinfo.GetPreview().GetPreviewRange().GetStartPage());
|
||||
data.WriteUint32(jobinfo.GetPreview().GetPreviewRange().GetEndPage());
|
||||
uint32_t previewPageLength = jobinfo.GetPreview().GetPreviewRange().GetPages().size();
|
||||
data.WriteUint32(previewPageLength);
|
||||
for(uint32_t i = 0; i < previewPageLength; i++)
|
||||
{
|
||||
data.WriteUint32(jobinfo.GetPreview().GetPreviewRange().GetPages()[i]);
|
||||
}
|
||||
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_REQUESTPREVIEW, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
previewResult = reply.ReadString();
|
||||
PRINT_HILOGD("PrintServiceProxy RequestPreview succeeded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(PrintServiceProxy::GetDescriptor());
|
||||
data.WriteUint32(printerId);
|
||||
PRINT_HILOGD("PrintServiceProxy ChangeTaskPriority started.");
|
||||
bool ret = Remote()->SendRequest(CMD_QUERYPRINTERCAPABILITY, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
PRINT_HILOGD("PrintServiceProxy, ret = %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
uint32_t arraypageSizeLength = reply.ReadUint32();
|
||||
uint32_t resolutionLength = reply.ReadUint32();
|
||||
PRINT_HILOGD("PrintServiceProxy, arraypageSizeLength = %{public}d", arraypageSizeLength);
|
||||
PRINT_HILOGD("PrintServiceProxy, resolutionLength = %{public}d", resolutionLength);
|
||||
printerCapability.GetMinMargin().SetTop(reply.ReadUint32());
|
||||
printerCapability.GetMinMargin().SetBottom(reply.ReadUint32());
|
||||
printerCapability.GetMinMargin().SetLeft(reply.ReadUint32());
|
||||
printerCapability.GetMinMargin().SetRight(reply.ReadUint32());
|
||||
printerCapability.GetMinMargin().Dump();
|
||||
for(uint32_t i = 0; i < arraypageSizeLength; i++)
|
||||
{
|
||||
PrinterPageSize printerPageSize;
|
||||
printerPageSize.SetId(reply.ReadUint32());
|
||||
printerPageSize.SetName(reply.ReadString());
|
||||
printerPageSize.SetWidth(reply.ReadUint32());
|
||||
printerPageSize.SetHeight(reply.ReadUint32());
|
||||
printerCapability.SetPageSize(printerPageSize);
|
||||
printerCapability.GetPageSize()[i].Dump();
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < resolutionLength; i++)
|
||||
{
|
||||
PrinterResolution printerResolution;
|
||||
printerResolution.SetId(reply.ReadUint32());
|
||||
printerResolution.SetHorizontalDpi(reply.ReadUint32());
|
||||
printerResolution.SetVerticalDpi(reply.ReadUint32());
|
||||
printerCapability.SetResolution(printerResolution);
|
||||
printerCapability.GetResolution()[i].Dump();
|
||||
}
|
||||
|
||||
printerCapability.SetColorMode(reply.ReadUint32());
|
||||
printerCapability.SetDuplexMode(reply.ReadUint32());
|
||||
printerCapability.Dump();
|
||||
|
||||
PRINT_HILOGD("PrintServiceProxy QueryPrinterCapability succeeded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::CheckPermission()
|
||||
{
|
||||
PRINT_HILOGD("PrintServiceProxy::CheckPermission in");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
PRINT_HILOGE(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t result = Remote()->SendRequest(CMD_CHECKPERMISSION, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
PRINT_HILOGE(" PrintServiceProxy::CheckPermission fail, ret = %{public}d ", result);
|
||||
return false;
|
||||
}
|
||||
bool ret = reply.ReadBool();
|
||||
PRINT_HILOGD("PrintServiceProxy::CheckPermission out [ret: %{public}d]", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::On(uint32_t taskId, const std::string &type, const sptr<PrintNotifyInterface> &listener)
|
||||
{
|
||||
PRINT_HILOGD("PrintServiceProxy::On listener=%{public}p", listener.GetRefPtr());
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
PRINT_HILOGE(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
if (listener == nullptr) {
|
||||
PRINT_HILOGE("listener is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(taskId)) {
|
||||
PRINT_HILOGE("write taskId=%{public}d fail", taskId);
|
||||
return false;
|
||||
}
|
||||
|
||||
PRINT_HILOGD("PrintServiceProxy::On type=%{public}s", type.c_str());
|
||||
if (type.empty()) {
|
||||
PRINT_HILOGE("PrintServiceProxy::On type is null.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString(type)) {
|
||||
PRINT_HILOGE("write type failed.");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteRemoteObject(listener->AsObject().GetRefPtr())) {
|
||||
PRINT_HILOGE("write parcel failed.");
|
||||
return false;
|
||||
}
|
||||
int32_t result = Remote()->SendRequest(CMD_ON, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
PRINT_HILOGE(" PrintServiceProxy::On fail, result = %{public}d ", result);
|
||||
return false;
|
||||
}
|
||||
bool ret = reply.ReadBool();
|
||||
PRINT_HILOGD("PrintServiceProxy::On out [result: %{public}d]", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool PrintServiceProxy::Off(uint32_t taskId, const std::string &type)
|
||||
{
|
||||
PRINT_HILOGD("PrintServiceProxy::Off in");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
PRINT_HILOGE(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(taskId)) {
|
||||
PRINT_HILOGE("write taskId=%{public}d fail", taskId);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data.WriteString(type)) {
|
||||
PRINT_HILOGE("write type=%{public}s fail", type.c_str());
|
||||
return false;
|
||||
}
|
||||
int32_t result = Remote()->SendRequest(CMD_OFF, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
PRINT_HILOGE(" PrintServiceProxy::Off fail, ret = %{public}d ", result);
|
||||
return false;
|
||||
}
|
||||
bool ret = reply.ReadBool();
|
||||
PRINT_HILOGD("PrintServiceProxy::Off out [ret: %{public}d]", ret);
|
||||
return ret;
|
||||
}
|
||||
} // namespace OHOS::Print
|
55
hisysevent.yaml
Normal file
55
hisysevent.yaml
Normal file
@ -0,0 +1,55 @@
|
||||
# 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.
|
||||
|
||||
#####################################################
|
||||
# below is the format of defining event #
|
||||
#####################################################
|
||||
#domain: domain name. [Only one domain name can be defined at the top]
|
||||
#
|
||||
#author: the author name who defined this event.
|
||||
#date: the date when this event was defined, format is YYYY-MM-DD.
|
||||
#logged: source file which refer to this event.
|
||||
#usage: the usage of this event.
|
||||
#//Define event name and event properties.
|
||||
#@EVENT_NAME: the event definition part begin.
|
||||
# // __BASE is used for defining the basic info of the event.
|
||||
# // "type" optional values are: FAULT, STATISTICS, SECURITY, BEHAVIOR.
|
||||
# // "level" optional values are: CRITICAL, MINOR.
|
||||
# // "tag" set tags with may used by subscriber of this event, multiple tags devided by space.
|
||||
# // "desc" full description of this event.
|
||||
# @PARAMETER: {type: parameter type, arrsize: array length(optional), desc: parameter description}.
|
||||
# // follow the __BASE block, each line defines a parameter of this event.
|
||||
# // "type" optional values are: INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, FLOAT, DOUBLE, STRING.
|
||||
# // "arrsize" of the parameter is an array, set a non-zero value.
|
||||
# // "desc" full description of this parameter.
|
||||
|
||||
#####################################################
|
||||
# Example of some hiviewdfx events definition #
|
||||
#####################################################
|
||||
|
||||
domain: PRINT
|
||||
|
||||
SERVICE_FAULT:
|
||||
__BASE: {type: FAULT, level: CRITICAL, desc: The event is service fault }
|
||||
FAULT_TYPE: {type: INT32, desc: fault id }
|
||||
MODULE_NAME: {type: STRING, desc: module name }
|
||||
ERROR_TYPE: {type: INT32, desc: error type }
|
||||
|
||||
RUNTIME_FAULT:
|
||||
__BASE: {type: FAULT, level: CRITICAL, desc: The event is runtime fault }
|
||||
FAULT_TYPE: {type: INT32, desc: fault id }
|
||||
ERROR_TYPE: {type: INT32, desc: error type }
|
||||
|
||||
USAGETIME_STATISTIC:
|
||||
__BASE: {type: STATISTIC, level: MINOR, desc: The event is usagetime statistic }
|
||||
PRINT_INFO: {type: STRING, desc: print infomation }
|
137
interfaces/kits/jskits/@ohos.PrintExtensionAbility.d.ts
vendored
Normal file
137
interfaces/kits/jskits/@ohos.PrintExtensionAbility.d.ts
vendored
Normal file
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* class of print extension.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Print.print
|
||||
* @StageModelOnly
|
||||
*/
|
||||
declare class PrintExtensionAbility {
|
||||
|
||||
/**
|
||||
* Called once to initialize the extension.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Print.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onCreated(want: Want): void;
|
||||
|
||||
/**
|
||||
* Called once to start to discover the printers connected with the device.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Print.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onStartDiscoverPrinter(): void;
|
||||
|
||||
/**
|
||||
* Called once to stop discovering the printer.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Print.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onStopDiscoverPrinter(): void;
|
||||
|
||||
/**
|
||||
* Called once to connect to the specific printer.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Print.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onConnectPrinter(printerId: number): void;
|
||||
|
||||
/**
|
||||
* Called once to disconnect the specific printer.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Print.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onDisconnectPrinter(printerId: number): void;
|
||||
|
||||
/**
|
||||
* Called once to start print job.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Print.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onStartPrintJob(jobInfo: PrintJob): void;
|
||||
|
||||
/**
|
||||
* Called once to remove the print job has been started.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Print.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onCancelPrintJob(jobInfo: PrintJob): void;
|
||||
|
||||
/**
|
||||
* Called once to request the capability of the printer.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Print.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onRequestPrinterCapability(printerId: number): PrinterCapability;
|
||||
|
||||
/**
|
||||
* Called once to request preview and send result to Print SA.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Print.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onRequestPreview(jobInfo: PrintJob): Uri;
|
||||
|
||||
/**
|
||||
* Called once to finalize the extension.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Print.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onDestroy(): void;
|
||||
}
|
||||
|
||||
export default PrintExtensionAbility;
|
329
interfaces/kits/jskits/@ohos.print.d.ts
vendored
Normal file
329
interfaces/kits/jskits/@ohos.print.d.ts
vendored
Normal file
@ -0,0 +1,329 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
import {AsyncCallback} from './basic';
|
||||
|
||||
/**
|
||||
* System print
|
||||
* @sysCap SystemCapability.Print.print
|
||||
* @import import print from '@ohos.app.print';
|
||||
* @since 9
|
||||
*/
|
||||
declare namespace print {
|
||||
|
||||
interface PrintTask {
|
||||
/**
|
||||
* Register event callback when the current print task is in process.
|
||||
* @since 9
|
||||
* @param type block Indicates the print task has been blocked.
|
||||
* type success Indicates the print task succeed. .
|
||||
* type fail Indicates the print task has completed with failure.
|
||||
* type cancel Indicates the print task has been cancelled.
|
||||
* @param callback The callback function for print task change event
|
||||
* @permission {@code ohos.permission.PRINT}
|
||||
* @return -
|
||||
*/
|
||||
on(type:'block'| 'success'| 'fail' | 'cancel', callback:() => void): void;
|
||||
|
||||
/**
|
||||
* Unregister event callback when the current print task is in process.
|
||||
* @since 9
|
||||
* @param type block Indicates the print task has been blocked.
|
||||
* type success Indicates the print task succeed. .
|
||||
* type fail Indicates the print task has completed with failure.
|
||||
* type cancel Indicates the print task has been cancelled.
|
||||
* @param callback The callback function for print task change event
|
||||
* @permission {@code ohos.permission.PRINT}
|
||||
* @return -
|
||||
*/
|
||||
off(type:'block'| 'success'| 'fail' | 'cancel', callback?:() => void): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start new print task for App.
|
||||
* @since 9
|
||||
* @param files Indicates the document list to be printed.
|
||||
* @param callback The callback function for print task
|
||||
* @permission {@code ohos.permission.PRINT}
|
||||
* @return -
|
||||
*/
|
||||
function print(files: Array<string>, callback: AsyncCallback<PrintTask>): void;
|
||||
function print(files: Array<string>): Promise<PrintTask>;
|
||||
|
||||
interface PrintMargin {
|
||||
top: number; // top margin
|
||||
bottom: number; // bottom margin
|
||||
left: number; // left side margin
|
||||
right: number; // right side margin
|
||||
}
|
||||
|
||||
interface PrinterRange {
|
||||
startPage: number; // start page of sequence
|
||||
endPage: number; // end page of sequence
|
||||
pages: Array<number>; // discrete page of sequence
|
||||
}
|
||||
interface PreviewAttribute {
|
||||
previewRange: PrinterRange; // preview page range
|
||||
result: string; // preview file
|
||||
}
|
||||
|
||||
interface PrinterResolution {
|
||||
id: number; // resolution id
|
||||
horizontalDpi: number // horizontal DPI
|
||||
verticalDpi: number; // vertical DPI
|
||||
}
|
||||
|
||||
interface PrinterPageSize {
|
||||
id: number; // page size id
|
||||
name: string; // page size name
|
||||
width: number; // unit: milimeter
|
||||
height: number; // unit: milimeter
|
||||
}
|
||||
|
||||
interface PrinterCapability {
|
||||
/* Printer Capability */
|
||||
minMargin: PrintMargin; // min margin of printer
|
||||
pageSize: Array<PrinterPageSize>; // the page size list supported by the printer
|
||||
resolution: Array<PrinterResolution>; // the resolution list supported by the printer
|
||||
colorMode: number; // color mode
|
||||
duplexMode: number; // duplex mode
|
||||
}
|
||||
|
||||
interface PrinterInfo {
|
||||
printerId: number; // printer id
|
||||
printerName: string; // printer name
|
||||
printerIcon: number; // resource id of printer icon
|
||||
printerState: PrinterState; // current printer state
|
||||
description: string; // printer description
|
||||
capability: PrinterCapability; // printer capability
|
||||
}
|
||||
|
||||
interface PrintJob {
|
||||
files: Array<string>; // document list to be printed
|
||||
/* job attributes */
|
||||
printerId: number; // printer id to take charge of printing
|
||||
jobState: PrintJobState; // current print job state
|
||||
copyNumber: number; // copies of document list
|
||||
pageRange: PrinterRange; // range size to be printed
|
||||
isSequential?: boolean; // sequential print
|
||||
pageSize?: PrinterPageSize; // the selected page size
|
||||
isLandscape?: boolean; // vertical printing
|
||||
colorMode?: number; // color mode
|
||||
duplexMode?: number; // duplex mode
|
||||
margin?: PrintMargin; // current margin setting
|
||||
preview?: PreviewAttribute; // preview setting
|
||||
}
|
||||
|
||||
enum PrinterState {
|
||||
PRINTER_ADD = 1, // new printers arrival
|
||||
PRINTER_REMOVED = 2, // printers lost
|
||||
PRINTER_IDLE = 3, // printer idle
|
||||
PRINTER_PRINTING = 4, // printer is working
|
||||
PRINTER_BLOCK = 5, // printer has been blocked
|
||||
PRINTER_BUSY = 6, // printer is busy
|
||||
PRINTER_FAULT = 7 // printer failure
|
||||
}
|
||||
|
||||
enum PrintJobState {
|
||||
PRINT_JOB_INIT = 1, // initial state of print job
|
||||
PRINT_JOB_START = 2, // start print job
|
||||
PRINT_JOB_PRINTING = 3, // printing
|
||||
PRINT_JOB_BLOCK = 4, // print job has been blocked
|
||||
PRINT_JOB_COMPLETE = 5, // print completed
|
||||
PRINT_JOB_CANCEL = 6 // print job has been cancelled
|
||||
}
|
||||
|
||||
interface PrinterExtensionInfo extends ExtensionAbilityInfo{
|
||||
extensionId: number; // extesion id of printer extension
|
||||
vendorId: number; // vendor id of extension
|
||||
vendorName: string; // vendor name
|
||||
vendorIcon: number; // resource id of vendor
|
||||
version: string; // version of current printer extension
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all printer extensin installed.
|
||||
*
|
||||
* @since 9
|
||||
* @param callback The callback function for handling the extension list found
|
||||
* @permission {@code ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
function queryExtensionAbilityInfos(callback: AsyncCallback<Array<PrinterExtensionInfo>>): void;
|
||||
function queryExtensionAbilityInfos(): Promise<Array<PrinterExtensionInfo>>;
|
||||
|
||||
/**
|
||||
* Load the specific printer extension and start to discover printer.
|
||||
*
|
||||
* @since 9
|
||||
* @param extensionList Indicates the list of printer extension
|
||||
* empty list of extensionList Indicates to find printer with all installed extension
|
||||
* @param callback The callback function for indcating the result of API execution
|
||||
* @permission {@code ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
function startDiscoverPrinter(extensionList:Array<number>, callback: AsyncCallback<boolean>): void;
|
||||
function startDiscoverPrinter(extensionList:Array<number>): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Stop discovering the printer with specific printer extension.
|
||||
*
|
||||
* @since 9
|
||||
* @param extensionList Indicates the list of printer extension
|
||||
* empty list of extensionList Indicates to find printer with all installed extension
|
||||
* @param callback The callback function for indcating the result of API execution
|
||||
* @permission {@ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
function stopDiscoverPrinter(callback: AsyncCallback<boolean>): void;
|
||||
function stopDiscoverPrinter(): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Start print job.
|
||||
*
|
||||
* @since 9
|
||||
* @param jobInfo Indicates the information of print job.
|
||||
* @param callback The callback function for indcating the result of API execution
|
||||
* @permission {@code ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
function startPrintJob(jobinfo:PrintJob, callback:AsyncCallback<boolean>):void;
|
||||
function startPrintJob(jobinfo:PrintJob): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Cancel the print job has been sent to printer.
|
||||
*
|
||||
* @since 9
|
||||
* @param jobInfo Indicates the information of print job.
|
||||
* @param callback The callback function for indcating the result of API execution
|
||||
* @permission {@code ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
function cancelPrintJob(jobinfo:PrintJob, callback:AsyncCallback<boolean>):void;
|
||||
function cancelPrintJob(jobinfo:PrintJob): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Request preview of the print job.
|
||||
*
|
||||
* @since 9
|
||||
* @param jobInfo Indicates the information of print job.
|
||||
* @param callback The callback function for preview result from printer
|
||||
* @permission {@code ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
function requestPrintPreview(jobinfo:PrintJob, callback:(result:string) => void): void;
|
||||
function requestPrintPreview(jobinfo:PrintJob): Promise<string>;
|
||||
|
||||
/**
|
||||
* Query capability for the specific printer.
|
||||
*
|
||||
* @since 9
|
||||
* @param printerId Indicates id of the printer
|
||||
* @param callback The callback function for capability from printer
|
||||
* @permission {@code ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
function queryPrinterCapability(printerId:number, callback:AsyncCallback<PrinterCapability>):void;
|
||||
function queryPrinterCapability(printerId:number): Promise<PrinterCapability>
|
||||
|
||||
/**
|
||||
* Register event callback for the state change of printer.
|
||||
*
|
||||
* @since 9
|
||||
* @param printerStateChange Indicates state change of printer
|
||||
* @param callback The callback function for state change of printer.
|
||||
* @permission {@code ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
on(type: 'printerStateChange', callback:(state: PrinterState, info: PrinterInfo) => void): void;
|
||||
off(type: 'printerStateChange', callback:(boolean) => void): void;
|
||||
|
||||
/**
|
||||
* Register event callback for the specific print job.
|
||||
*
|
||||
* @since 9
|
||||
* @param jobStateChange Indicates state change of print job
|
||||
* @param callback The callback function for state change of print job.
|
||||
* @permission {@code ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
on(type: 'jobStateChange', callback:(state: PrintJobState, job: PrintJob) => void): void;
|
||||
off(type: 'jobStateChange', callback:(boolean) => void): void;
|
||||
|
||||
/**
|
||||
* New printers have been found and notify Print SA.
|
||||
*
|
||||
* @since 9
|
||||
* @param printers Indicates new arrived printer lists.
|
||||
* @param callback The callback function for indcating the result of API execution
|
||||
* @permission {@code ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
function addPrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<boolean>): void;
|
||||
function addPrinters(printers: Array<PrinterInfo>): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Printers have been lost and notify Print SA.
|
||||
*
|
||||
* @since 9
|
||||
*
|
||||
* @param printerId Indicates id of the printer
|
||||
* @param callback The callback function for indcating the result of API execution
|
||||
* @permission {@code ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
function removePrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<boolean>): void;
|
||||
function removePrinters(printers: Array<PrinterInfo>): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Notify Print SA the state of printer has been changed.
|
||||
*
|
||||
* @since 9
|
||||
* @param state Indicates new printer state
|
||||
* @param printerId Indicates id of the printer
|
||||
* @param callback The callback function for indcating the result of API execution
|
||||
* @permission {@code ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
function updatePrinterState(state: PrinterState, printerId: number, callback: AsyncCallback<boolean>): void;
|
||||
function updatePrinterState(state: PrinterState, printerId: number): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Notify Print SA the state of print job has been changed.
|
||||
*
|
||||
* @since 9
|
||||
* @param state Indicates new printer state
|
||||
* @param jobId Indicates id of the print job
|
||||
* @param callback The callback function for indcating the result of API execution
|
||||
* @permission {@code ohos.permission.MANAGE_PRINT_JOB}
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return -
|
||||
*/
|
||||
function updatePrintJobState(state: PrintJobState, jobId: number, callback: AsyncCallback<boolean>): void;
|
||||
function updatePrintJobState(state: PrintJobState, jobId: number): Promise<boolean>;
|
||||
}
|
||||
|
||||
export default print;
|
137
interfaces/kits/jskits/@ohos.printextension.d.ts
vendored
Normal file
137
interfaces/kits/jskits/@ohos.printextension.d.ts
vendored
Normal file
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* class of print extension.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Miscservices.print
|
||||
* @StageModelOnly
|
||||
*/
|
||||
declare class printExtension {
|
||||
|
||||
/**
|
||||
* Called once to initialize the extension.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Miscservices.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onCreated(want: object): void;
|
||||
|
||||
/**
|
||||
* Called once to start to discover the printers connected with the device.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Miscservices.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onStartDiscoverPrinter(): void;
|
||||
|
||||
/**
|
||||
* Called once to stop discovering the printer.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Miscservices.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onStopDiscoverPrinter(): void;
|
||||
|
||||
/**
|
||||
* Called once to connect to the specific printer.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Miscservices.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onConnectPrinter(printerId: number): void;
|
||||
|
||||
/**
|
||||
* Called once to disconnect the specific printer.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Miscservices.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onDisconnectPrinter(printerId: number): void;
|
||||
|
||||
/**
|
||||
* Called once to start print job.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Miscservices.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onStartJob(jobInfo: PrintJob): void;
|
||||
|
||||
/**
|
||||
* Called once to remove the print job has been started.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Miscservices.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onCancelJob(jobInfo: PrintJob): void;
|
||||
|
||||
/**
|
||||
* Called once to request the capability of the printer.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Miscservices.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onRequestCapability(printerId: number): PrinterCapability;
|
||||
|
||||
/**
|
||||
* Called once to request preview and send result to Print SA.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Miscservices.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onRequestPreview(jobInfo: PrintJob): Uri;
|
||||
|
||||
/**
|
||||
* Called once to finalize the extension.
|
||||
*
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @since 9
|
||||
* @sysCap SystemCapability.Miscservices.print
|
||||
* @return -
|
||||
* @StageModelOnly
|
||||
*/
|
||||
onDestroy(): void;
|
||||
}
|
||||
|
||||
export default printExtension;
|
69
interfaces/kits/jskits/printextsample.js
Normal file
69
interfaces/kits/jskits/printextsample.js
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import Extension from '@ohos.PrintExtensionAbility'
|
||||
import print from '@ohos.print'
|
||||
|
||||
let MODULE_TAG = "hwprintext"
|
||||
export default class PrintExtAbility extends Extension {
|
||||
Array<PrinterInfo> printerList;
|
||||
onCreated(want) {
|
||||
console.info(MODULE_TAG + 'ability on created start');
|
||||
}
|
||||
|
||||
onStartDiscoverPrinter() {
|
||||
console.info(MODULE_TAG + "ability start to discover printer";
|
||||
if (hasFoundDevice) {
|
||||
print.addPrinters(printerList);
|
||||
}
|
||||
}
|
||||
|
||||
onStopDiscoverPrinter() {
|
||||
console.info(MODULE_TAG + 'ability stop discovering printer');
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
console.info(MODULE_TAG + 'ability on destroy');
|
||||
}
|
||||
|
||||
onConnectPrinter(printerId) {
|
||||
console.info(MODULE_TAG + 'ability connect the speci1 printer');
|
||||
}
|
||||
|
||||
onDisconnectPrinter(printerId) {
|
||||
console.info(MODULE_TAG + 'ability disconnect the speci1 printer');
|
||||
}
|
||||
|
||||
onStartPrintJob(jobInfo) {
|
||||
console.info(MODULE_TAG + 'ability start Print Job');
|
||||
}
|
||||
|
||||
onCancelPrintJob(jobInfo) {
|
||||
console.info(MODULE_TAG + 'ability cancel Print Job');
|
||||
}
|
||||
|
||||
onRequestPrinterCapability(printerId) {
|
||||
console.info(MODULE_TAG + 'ability request printer capability');
|
||||
var capability = GetDeviceCapability(printerId);
|
||||
return capability;
|
||||
}
|
||||
|
||||
onRequestPreview(jobInfo) {
|
||||
console.info(MODULE_TAG + 'ability request printer preview');
|
||||
FileDescriptor fd = print.OpenFile(jobInfo.preview.result);
|
||||
SavePreviewToFile(fd);
|
||||
return jobInfo.preview.result;
|
||||
}
|
||||
};
|
34
interfaces/kits/jskits/printsample.js
Normal file
34
interfaces/kits/jskits/printsample.js
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import printmanager from '@ohos.app.print';
|
||||
// start print
|
||||
export async function startPrint() {
|
||||
Array<string> fileList = ['./data/printsample.pdf', './data/photo.jpg'];
|
||||
await printmanager.print(fileList).then(async (task) => {
|
||||
task.on('block', () => {
|
||||
console.info('[block] event is called');
|
||||
});
|
||||
task.on('success', () => {
|
||||
console.info('[success] event is called');
|
||||
});
|
||||
task.on('fail', () => {
|
||||
console.info('[fail] event is called');
|
||||
});
|
||||
task.on('cancel', () => {
|
||||
console.info('[cancel] event is called');
|
||||
});
|
||||
});
|
||||
}
|
76
interfaces/kits/napi/BUILD.gn
Normal file
76
interfaces/kits/napi/BUILD.gn
Normal file
@ -0,0 +1,76 @@
|
||||
# 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.
|
||||
import("//base/request/request/request_aafwk.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
config("print_interfaces_kits_napi_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
cflags_cc = [ "-fexceptions" ]
|
||||
}
|
||||
ohos_shared_library("print") {
|
||||
include_dirs = [
|
||||
"//foundation/arkui/ace_engine/frameworks/base/utils",
|
||||
"//foundation/arkui/napi",
|
||||
"//foundation/arkui/napi/interfaces/kits",
|
||||
"//foundation/arkui/napi/interfaces/inner_api",
|
||||
"//third_party/node/src",
|
||||
"//third_party/curl/include",
|
||||
"${ability_runtime_services_path}/common/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/app/",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
"${ability_runtime_services_path}/abilitymgr/include",
|
||||
"${ability_runtime_inner_api_path}/ability_manager/include",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/Isamgr",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"//base/print/print/utils/include",
|
||||
"//base/print/print/frameworks/innerkitsimpl/include",
|
||||
]
|
||||
public_configs = [ ":print_interfaces_kits_napi_config" ]
|
||||
|
||||
sources = [
|
||||
"src/print_module.cpp",
|
||||
"src/napi_print_task.cpp",
|
||||
"src/napi_inner_print.cpp",
|
||||
"src/napi_print_ext.cpp",
|
||||
"src/async_call.cpp",
|
||||
"src/print_task.cpp",
|
||||
"src/napi_utils.cpp"
|
||||
]
|
||||
deps = [
|
||||
"//foundation/arkui/napi:ace_napi",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//base/print/print/frameworks/innerkitsimpl:printclient",
|
||||
]
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:data_ability_helper",
|
||||
"ability_runtime:napi_base_context",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"preferences:native_preferences",
|
||||
"relational_store:native_appdatafwk",
|
||||
"relational_store:native_dataability",
|
||||
"relational_store:native_rdb",
|
||||
]
|
||||
relative_install_dir = "module"
|
||||
subsystem_name = "print"
|
||||
part_name = "print"
|
||||
}
|
101
interfaces/kits/napi/include/async_call.h
Normal file
101
interfaces/kits/napi/include/async_call.h
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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_ASYNC_CALL_H
|
||||
#define PRINT_ASYNC_CALL_H
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class AsyncCall final {
|
||||
public:
|
||||
class Context {
|
||||
public:
|
||||
using InputAction = std::function<napi_status(napi_env, size_t, napi_value *, napi_value)>;
|
||||
using OutputAction = std::function<napi_status(napi_env, napi_value *)>;
|
||||
using ExecAction = std::function<void(Context *)>;
|
||||
Context(InputAction input, OutputAction output) : input_(std::move(input)), output_(std::move(output)) {};
|
||||
virtual ~Context() {};
|
||||
void SetAction(InputAction input, OutputAction output = nullptr)
|
||||
{
|
||||
input_ = input;
|
||||
output_ = output;
|
||||
}
|
||||
|
||||
void SetAction(OutputAction output)
|
||||
{
|
||||
SetAction(nullptr, std::move(output));
|
||||
}
|
||||
|
||||
virtual napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self)
|
||||
{
|
||||
if (input_ == nullptr) {
|
||||
return napi_ok;
|
||||
}
|
||||
return input_(env, argc, argv, self);
|
||||
}
|
||||
|
||||
virtual napi_status operator()(napi_env env, napi_value *result)
|
||||
{
|
||||
if (output_ == nullptr) {
|
||||
*result = nullptr;
|
||||
return napi_ok;
|
||||
}
|
||||
return output_(env, result);
|
||||
}
|
||||
|
||||
virtual void Exec()
|
||||
{
|
||||
if (exec_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
exec_(this);
|
||||
};
|
||||
|
||||
protected:
|
||||
friend class AsyncCall;
|
||||
InputAction input_ = nullptr;
|
||||
OutputAction output_ = nullptr;
|
||||
ExecAction exec_ = nullptr;
|
||||
};
|
||||
|
||||
// The default AsyncCallback in the parameters is at the end position.
|
||||
static constexpr size_t ASYNC_DEFAULT_POS = -1;
|
||||
AsyncCall(napi_env env, napi_callback_info info, std::shared_ptr<Context> context, size_t pos = ASYNC_DEFAULT_POS);
|
||||
~AsyncCall();
|
||||
napi_value Call(napi_env env, Context::ExecAction exec = nullptr);
|
||||
napi_value SyncCall(napi_env env, Context::ExecAction exec = nullptr);
|
||||
|
||||
private:
|
||||
enum { ARG_ERROR, ARG_DATA, ARG_BUTT };
|
||||
static void OnExecute(napi_env env, void *data);
|
||||
static void OnComplete(napi_env env, napi_status status, void *data);
|
||||
struct AsyncContext {
|
||||
std::shared_ptr<Context> ctx = nullptr;
|
||||
napi_ref callback = nullptr;
|
||||
napi_ref self = nullptr;
|
||||
napi_deferred defer = nullptr;
|
||||
napi_async_work work = nullptr;
|
||||
};
|
||||
static void DeleteContext(napi_env env, AsyncContext *context);
|
||||
|
||||
AsyncContext *context_ = nullptr;
|
||||
napi_env env_ = nullptr;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // REQUEST_ASYNC_CALL_H
|
102
interfaces/kits/napi/include/base_context.h
Normal file
102
interfaces/kits/napi/include/base_context.h
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2021-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_BASE_CONTEXT_H
|
||||
#define PRINT_BASE_CONTEXT_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "event_manager.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "noncopyable.h"
|
||||
|
||||
namespace OHOS::Request::Print {
|
||||
typedef void (*AsyncWorkExecutor)(napi_env env, void *data);
|
||||
|
||||
typedef void (*AsyncWorkCallback)(napi_env env, napi_status status, void *data);
|
||||
|
||||
// support no argument
|
||||
class BaseContext {
|
||||
public:
|
||||
ACE_DISALLOW_COPY_AND_MOVE(BaseContext);
|
||||
|
||||
BaseContext() = delete;
|
||||
|
||||
explicit BaseContext(napi_env env, napi_callback_info info, EventManager *manager);
|
||||
|
||||
virtual ~BaseContext();
|
||||
|
||||
virtual void ParseParams(napi_value *params, size_t paramsCount);
|
||||
|
||||
void SetParseOK(bool parseOK);
|
||||
|
||||
void SetExecOK(bool execOK);
|
||||
|
||||
void SetErrorCode(int32_t errorCode);
|
||||
|
||||
napi_status SetCallback(napi_value callback);
|
||||
|
||||
void DeleteCallback();
|
||||
|
||||
void CreateAsyncWork(const std::string &name, AsyncWorkExecutor executor, AsyncWorkCallback callback);
|
||||
|
||||
void DeleteAsyncWork();
|
||||
|
||||
napi_value CreatePromise();
|
||||
|
||||
[[nodiscard]] bool IsParseOK() const;
|
||||
|
||||
[[nodiscard]] bool IsExecOK() const;
|
||||
|
||||
[[nodiscard]] napi_env GetEnv() const;
|
||||
|
||||
[[nodiscard]] napi_callback_info GetInfo() const;
|
||||
|
||||
[[nodiscard]] int32_t GetErrorCode() const;
|
||||
|
||||
[[nodiscard]] napi_value GetCallback() const;
|
||||
|
||||
[[nodiscard]] napi_deferred GetDeferred() const;
|
||||
|
||||
[[nodiscard]] const std::string &GetAsyncWorkName() const;
|
||||
|
||||
void Emit(const std::string &type, const std::pair<napi_value, napi_value> &argv);
|
||||
|
||||
protected:
|
||||
EventManager *manager_;
|
||||
|
||||
private:
|
||||
napi_env env_;
|
||||
|
||||
napi_callback_info info_;
|
||||
|
||||
bool parseOK_;
|
||||
|
||||
bool execOK_;
|
||||
|
||||
int32_t errorCode_;
|
||||
|
||||
napi_ref callback_;
|
||||
|
||||
napi_async_work asyncWork_;
|
||||
|
||||
napi_deferred deferred_;
|
||||
|
||||
std::string asyncWorkName_;
|
||||
};
|
||||
} // namespace OHOS::Request::Print
|
||||
|
||||
#endif /* PRINT_BASE_CONTEXT_H */
|
78
interfaces/kits/napi/include/napi_inner_print.h
Normal file
78
interfaces/kits/napi/include/napi_inner_print.h
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 NAPI_INNER_PRINT_H
|
||||
#define NAPI_INNER_PRINT_H
|
||||
|
||||
#include "async_call.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "print_cap_ability.h"
|
||||
#include "print_extension_Info.h"
|
||||
#include "print_page_size.h"
|
||||
#include "print_resolution.h"
|
||||
#include "print_job.h"
|
||||
#include "print_task.h"
|
||||
#include "noncopyable.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS::Print {
|
||||
class NapiInnerPrint {
|
||||
public:
|
||||
explicit NapiInnerPrint(uint32_t taskId);
|
||||
~NapiInnerPrint();
|
||||
|
||||
static napi_value QueryExtensionInfo(napi_env env, napi_callback_info info);
|
||||
static napi_value StartDiscovery(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 DisconnectPrint(napi_env env, napi_callback_info info);
|
||||
static napi_value StartPrint(napi_env env, napi_callback_info info);
|
||||
static napi_value CancelPrint(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 On(napi_env env, napi_callback_info info);
|
||||
static napi_value Off(napi_env env, napi_callback_info info);
|
||||
private:
|
||||
struct OperationContext : public AsyncCall::Context {
|
||||
std::string info;
|
||||
std::vector<PrinterExtensionInfo> arrayPrinterExtensionInfo;
|
||||
std::vector<uint32_t> extensionList;
|
||||
std::string previewResult = "";
|
||||
PrintJob jobinfo;
|
||||
PrintTask *task_ = nullptr;
|
||||
std::string title_ = "";
|
||||
std::string description_ = "";
|
||||
std::string filePath_ = "";
|
||||
uint32_t speedLimit_ = 0;
|
||||
uint32_t priority_ = 0;
|
||||
PrinterCapability printerCapability;
|
||||
bool result = false;
|
||||
std::string stateType_ = "";
|
||||
uint32_t printStartJobNumber = 0;
|
||||
uint32_t printCancelJobNumber = 0;
|
||||
uint32_t printReqPreviewJobNumber = 0;
|
||||
uint32_t printCapacityId = 0;
|
||||
uint32_t printConnId = 0;
|
||||
uint32_t printDisConnId = 0;
|
||||
std::vector<uint32_t> extensionVector;
|
||||
napi_status status = napi_generic_failure;
|
||||
OperationContext() : Context(nullptr, nullptr) {};
|
||||
OperationContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) {};
|
||||
virtual ~OperationContext() {};
|
||||
};
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // NAPI_INNER_PRINT_H
|
53
interfaces/kits/napi/include/napi_print_ext.h
Normal file
53
interfaces/kits/napi/include/napi_print_ext.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 NAPI_PRINT_EXT_H
|
||||
#define NAPI_PRINT_EXT_H
|
||||
|
||||
#include "async_call.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "print_task.h"
|
||||
#include "print_info.h"
|
||||
#include "noncopyable.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class NapiPrintExt {
|
||||
public:
|
||||
static napi_value AddPrinters(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 UpdatePrintJobState(napi_env env, napi_callback_info info);
|
||||
static bool ParseInfo(napi_env env, napi_value InfoValue, PrintInfo &Info);
|
||||
static bool ParseInfoParam(napi_env env, napi_value InfoValue, PrintInfo &info);
|
||||
static bool ParseCapability(napi_env env, napi_value InfoValue, PrinterCapability &capability);
|
||||
private:
|
||||
struct NapiPrintExtContext : public AsyncCall::Context {
|
||||
PrintTask *task_ = nullptr;
|
||||
PrintInfo info_;
|
||||
std::vector<PrintInfo> arrayPrintInfo;
|
||||
bool result = false;
|
||||
uint32_t printerId = 0;
|
||||
uint32_t printerJobId = 0;
|
||||
uint32_t printerState = 0;
|
||||
uint32_t printerJobState = 0;
|
||||
napi_status status = napi_generic_failure;
|
||||
std::vector<PrintInfo> printInfoVector;
|
||||
NapiPrintExtContext() : Context(nullptr, nullptr) {};
|
||||
NapiPrintExtContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) {};
|
||||
virtual ~NapiPrintExtContext() {};
|
||||
};
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // NAPI_PRINT_EXT_H
|
34
interfaces/kits/napi/include/napi_print_task.h
Normal file
34
interfaces/kits/napi/include/napi_print_task.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 NAPI_PRINT_TASK_H
|
||||
#define NAPI_PRINT_TASK_H
|
||||
|
||||
#include "async_call.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class NapiPrintTask {
|
||||
public:
|
||||
static napi_value Print(napi_env env, napi_callback_info info);
|
||||
|
||||
private:
|
||||
static napi_value GetCtor(napi_env env);
|
||||
static napi_value Initialize(napi_env env, napi_callback_info info);
|
||||
|
||||
private:
|
||||
static __thread napi_ref globalCtor;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // NAPI_PRINT_TASK_H
|
119
interfaces/kits/napi/include/napi_utils.h
Normal file
119
interfaces/kits/napi/include/napi_utils.h
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (C) 2021-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_NAPI_UTILS_H
|
||||
#define PRINT_NAPI_UTILS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "print_info.h"
|
||||
#include "print_cap_ability.h"
|
||||
#include "print_resolution.h"
|
||||
|
||||
namespace OHOS::Print::NapiUtils {
|
||||
static constexpr int32_t MAX_ARGC = 6;
|
||||
static constexpr int32_t NO_ARG = 0;
|
||||
static constexpr int32_t ONE_ARG = 1;
|
||||
static constexpr int32_t TWO_ARG = 2;
|
||||
static constexpr int32_t THE_ARG = 3;
|
||||
|
||||
static constexpr int32_t FIRST_ARGV = 0;
|
||||
static constexpr int32_t SECOND_ARGV = 1;
|
||||
static constexpr int32_t THIRD_ARGV = 2;
|
||||
|
||||
static constexpr int32_t MAX_NUMBER_BYTES = 8;
|
||||
static constexpr int32_t MAX_LEN = 4096;
|
||||
|
||||
napi_valuetype GetValueType(napi_env env, napi_value value);
|
||||
|
||||
/* named property */
|
||||
bool HasNamedProperty(napi_env env, napi_value object, const std::string &propertyName);
|
||||
|
||||
napi_value GetNamedProperty(napi_env env, napi_value object, const std::string &propertyName);
|
||||
|
||||
void SetNamedProperty(napi_env env, napi_value object, const std::string &name, napi_value value);
|
||||
|
||||
std::vector<std::string> GetPropertyNames(napi_env env, napi_value object);
|
||||
|
||||
/* UINT32 */
|
||||
napi_value CreateUint32(napi_env env, uint32_t code);
|
||||
|
||||
uint32_t GetUint32FromValue(napi_env env, napi_value value);
|
||||
|
||||
uint32_t GetUint32Property(napi_env env, napi_value object, const std::string &propertyName);
|
||||
|
||||
void SetUint32Property(napi_env env, napi_value object, const std::string &name, uint32_t value);
|
||||
|
||||
/* INT32 */
|
||||
napi_value CreateInt32(napi_env env, int32_t code);
|
||||
|
||||
int32_t GetInt32FromValue(napi_env env, napi_value value);
|
||||
|
||||
int32_t GetInt32Property(napi_env env, napi_value object, const std::string &propertyName);
|
||||
|
||||
void SetInt32Property(napi_env env, napi_value object, const std::string &name, int32_t value);
|
||||
|
||||
/* String UTF8 */
|
||||
napi_value CreateStringUtf8(napi_env env, const std::string &str);
|
||||
|
||||
std::string GetStringFromValueUtf8(napi_env env, napi_value value);
|
||||
|
||||
std::string GetStringPropertyUtf8(napi_env env, napi_value object, const std::string &propertyName);
|
||||
|
||||
void SetStringPropertyUtf8(napi_env env, napi_value object, const std::string &name, const std::string &value);
|
||||
|
||||
std::string GetValueString(napi_env env, napi_value value);
|
||||
|
||||
/* array buffer */
|
||||
bool ValueIsArrayBuffer(napi_env env, napi_value value);
|
||||
|
||||
void *GetInfoFromArrayBufferValue(napi_env env, napi_value value, size_t *length);
|
||||
|
||||
napi_value CreateArrayBuffer(napi_env env, size_t length, void **data);
|
||||
|
||||
/* object */
|
||||
napi_value CreateObject(napi_env env);
|
||||
|
||||
/* undefined */
|
||||
napi_value GetUndefined(napi_env env);
|
||||
|
||||
/* function */
|
||||
napi_value CallFunction(napi_env env, napi_value recv, napi_value func, size_t argc, const napi_value *argv);
|
||||
|
||||
napi_value CreateFunction(napi_env env, const std::string &name, napi_callback func, void *arg);
|
||||
|
||||
/* reference */
|
||||
napi_ref CreateReference(napi_env env, napi_value callback);
|
||||
|
||||
napi_value GetReference(napi_env env, napi_ref callbackRef);
|
||||
|
||||
void DeleteReference(napi_env env, napi_ref callbackRef);
|
||||
|
||||
/* boolean */
|
||||
bool GetBooleanProperty(napi_env env, napi_value object, const std::string &propertyName);
|
||||
|
||||
void SetBooleanProperty(napi_env env, napi_value object, const std::string &name, bool value);
|
||||
|
||||
/* define properties */
|
||||
void DefineProperties(
|
||||
napi_env env, napi_value object, const std::initializer_list<napi_property_descriptor> &properties);
|
||||
|
||||
std::string ToLower(const std::string &s);
|
||||
|
||||
} // namespace OHOS::Print::NapiUtils
|
||||
#endif /* PRINT_NAPI_UTILS_H */
|
72
interfaces/kits/napi/include/print_task.h
Normal file
72
interfaces/kits/napi/include/print_task.h
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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_TASK_H
|
||||
#define PRINT_TASK_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "napi/native_api.h"
|
||||
|
||||
static constexpr const char *EVENT_BLOCK = "blocked";
|
||||
static constexpr const char *EVENT_SUCCESS = "success";
|
||||
static constexpr const char *EVENT_FAIL = "failed";
|
||||
static constexpr const char *EVENT_CANCEL = "cancelled";
|
||||
|
||||
static constexpr const char *PRINTER_STATE_ADD = "PRINTER_ADDED";
|
||||
static constexpr const char *PRINTER_STATE_REMOVED = "PRINTER_REMOVED";
|
||||
static constexpr const char *PRINTER_STATE_IDLE = "PRINTER_IDLE";
|
||||
static constexpr const char *PRINTER_STATE_PRINTING = "PRINTER_PRINTING";
|
||||
static constexpr const char *PRINTER_STATE_BLOCKED = "PRINTER_BLOCKED";
|
||||
static constexpr const char *PRINTER_STATE_BUSY = "PRINTER_BUSY";
|
||||
static constexpr const char *PRINTER_STATE_FAILED = "PRINTER_FAILED";
|
||||
|
||||
static constexpr const char *PRINTJOB_STATE_CREATED = "PRINT_JOB_CREATED";
|
||||
static constexpr const char *PRINTJOB_STATE_QUEUED = "PRINT_JOB_QUEUED";
|
||||
static constexpr const char *PRINTJOB_STATE_PRINTING = "PRINT_JOB_PRINTING";
|
||||
static constexpr const char *PRINTJOB_STATE_BLOCKED = "PRINT_JOB_BLOCKED";
|
||||
static constexpr const char *PRINTJOB_STATE_SUCCESS = "PRINT_JOB_SUCCESS";
|
||||
static constexpr const char *PRINTJOB_STATE_FAILED = "PRINT_JOB_FAILED";
|
||||
static constexpr const char *PRINTJOB_STATE_cancelled = "PRINT_JOB_cancelled";
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrintTask {
|
||||
public:
|
||||
explicit PrintTask(uint32_t taskId);
|
||||
~PrintTask();
|
||||
|
||||
uint32_t GetId() const;
|
||||
static napi_value On(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 IsSupportPrinterStateType(const std::string &type);
|
||||
bool IsSupportJobStateType(const std::string &type);
|
||||
private:
|
||||
int taskId_;
|
||||
std::mutex mutex_;
|
||||
//std::map<std::string, sptr<PrintNotifyInterface>> listenerMap_;
|
||||
std::map<std::string, bool> supportEvents_;
|
||||
std::map<std::string, bool> supportPrinterState_;
|
||||
std::map<std::string, bool> supportJobState_;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_TASK_H
|
147
interfaces/kits/napi/src/async_call.cpp
Normal file
147
interfaces/kits/napi/src/async_call.cpp
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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 "async_call.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "napi_utils.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
AsyncCall::AsyncCall(napi_env env, napi_callback_info info, std::shared_ptr<Context> context, size_t pos) : env_(env)
|
||||
{
|
||||
context_ = new AsyncContext();
|
||||
size_t argc = NapiUtils::MAX_ARGC;
|
||||
napi_value self = nullptr;
|
||||
napi_value argv[NapiUtils::MAX_ARGC] = {nullptr};
|
||||
NAPI_CALL_RETURN_VOID(env, napi_get_cb_info(env, info, &argc, argv, &self, nullptr));
|
||||
pos = ((pos == ASYNC_DEFAULT_POS) ? (argc - 1) : pos);
|
||||
if (pos >= 0 && pos < argc) {
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, argv[pos], &valueType);
|
||||
if (valueType == napi_function) {
|
||||
napi_create_reference(env, argv[pos], 1, &context_->callback);
|
||||
argc = pos;
|
||||
}
|
||||
}
|
||||
NAPI_CALL_RETURN_VOID(env, (*context)(env, argc, argv, self));
|
||||
context_->ctx = std::move(context);
|
||||
napi_create_reference(env, self, 1, &context_->self);
|
||||
}
|
||||
|
||||
AsyncCall::~AsyncCall()
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
DeleteContext(env_, context_);
|
||||
}
|
||||
|
||||
napi_value AsyncCall::Call(napi_env env, Context::ExecAction exec)
|
||||
{
|
||||
if ((context_ == nullptr) || (context_->ctx == nullptr)) {
|
||||
PRINT_HILOGD("context_ or context_->ctx is null");
|
||||
return nullptr;
|
||||
}
|
||||
PRINT_HILOGD("async call exec");
|
||||
context_->ctx->exec_ = std::move(exec);
|
||||
napi_value promise = nullptr;
|
||||
if (context_->callback == nullptr) {
|
||||
napi_create_promise(env, &context_->defer, &promise);
|
||||
} else {
|
||||
napi_get_undefined(env, &promise);
|
||||
}
|
||||
napi_async_work work = context_->work;
|
||||
napi_value resource = nullptr;
|
||||
napi_create_string_utf8(env, "AsyncCall", NAPI_AUTO_LENGTH, &resource);
|
||||
napi_create_async_work(env, nullptr, resource, AsyncCall::OnExecute, AsyncCall::OnComplete, context_, &work);
|
||||
context_->work = work;
|
||||
context_ = nullptr;
|
||||
napi_queue_async_work(env, work);
|
||||
PRINT_HILOGD("async call exec");
|
||||
return promise;
|
||||
}
|
||||
|
||||
napi_value AsyncCall::SyncCall(napi_env env, AsyncCall::Context::ExecAction exec)
|
||||
{
|
||||
if ((context_ == nullptr) || (context_->ctx == nullptr)) {
|
||||
PRINT_HILOGD("context_ or context_->ctx is null");
|
||||
return nullptr;
|
||||
}
|
||||
context_->ctx->exec_ = std::move(exec);
|
||||
napi_value promise = nullptr;
|
||||
if (context_->callback == nullptr) {
|
||||
napi_create_promise(env, &context_->defer, &promise);
|
||||
} else {
|
||||
napi_get_undefined(env, &promise);
|
||||
}
|
||||
AsyncCall::OnExecute(env, context_);
|
||||
AsyncCall::OnComplete(env, napi_ok, context_);
|
||||
return promise;
|
||||
}
|
||||
|
||||
void AsyncCall::OnExecute(napi_env env, void *data)
|
||||
{
|
||||
PRINT_HILOGD("run the async runnable");
|
||||
AsyncContext *context = reinterpret_cast<AsyncContext *>(data);
|
||||
context->ctx->Exec();
|
||||
}
|
||||
|
||||
void AsyncCall::OnComplete(napi_env env, napi_status status, void *data)
|
||||
{
|
||||
PRINT_HILOGD("run the js callback function");
|
||||
AsyncContext *context = reinterpret_cast<AsyncContext *>(data);
|
||||
napi_value output = nullptr;
|
||||
napi_status runStatus = (*context->ctx)(env, &output);
|
||||
napi_value result[ARG_BUTT] = {0};
|
||||
if (status == napi_ok && runStatus == napi_ok) {
|
||||
napi_get_undefined(env, &result[ARG_ERROR]);
|
||||
if (output != nullptr) {
|
||||
result[ARG_DATA] = output;
|
||||
} else {
|
||||
napi_get_undefined(env, &result[ARG_DATA]);
|
||||
}
|
||||
} else {
|
||||
napi_value message = nullptr;
|
||||
napi_create_string_utf8(env, "async call failed", NAPI_AUTO_LENGTH, &message);
|
||||
napi_create_error(env, nullptr, message, &result[ARG_ERROR]);
|
||||
napi_get_undefined(env, &result[ARG_DATA]);
|
||||
}
|
||||
if (context->defer != nullptr) {
|
||||
// promise
|
||||
if (status == napi_ok && runStatus == napi_ok) {
|
||||
napi_resolve_deferred(env, context->defer, result[ARG_DATA]);
|
||||
} else {
|
||||
napi_reject_deferred(env, context->defer, result[ARG_ERROR]);
|
||||
}
|
||||
} else {
|
||||
// callback
|
||||
napi_value callback = nullptr;
|
||||
napi_get_reference_value(env, context->callback, &callback);
|
||||
napi_value returnValue;
|
||||
napi_call_function(env, nullptr, callback, ARG_BUTT, result, &returnValue);
|
||||
}
|
||||
DeleteContext(env, context);
|
||||
}
|
||||
void AsyncCall::DeleteContext(napi_env env, AsyncContext *context)
|
||||
{
|
||||
if (env != nullptr) {
|
||||
napi_delete_reference(env, context->callback);
|
||||
napi_delete_reference(env, context->self);
|
||||
napi_delete_async_work(env, context->work);
|
||||
}
|
||||
delete context;
|
||||
}
|
||||
} // namespace OHOS::Print
|
517
interfaces/kits/napi/src/napi_inner_print.cpp
Normal file
517
interfaces/kits/napi/src/napi_inner_print.cpp
Normal file
@ -0,0 +1,517 @@
|
||||
/*
|
||||
* 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 "napi_inner_print.h"
|
||||
#include "print_manager.h"
|
||||
#include "async_call.h"
|
||||
#include "log.h"
|
||||
#include "napi_utils.h"
|
||||
#include "print_task.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
napi_value NapiInnerPrint::QueryExtensionInfo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter ---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<OperationContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == NapiUtils::NO_ARG, " should 0 parameter!", napi_invalid_arg);
|
||||
PRINT_HILOGD("input over---->");
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
PRINT_HILOGD("ouput enter---->");
|
||||
napi_status status = napi_create_array(env, result);
|
||||
uint32_t PrinterExtensionInfoLength = context->arrayPrinterExtensionInfo.size();
|
||||
for(uint32_t i = 0; i < PrinterExtensionInfoLength; i++)
|
||||
{
|
||||
PRINT_HILOGD("PrintServiceProxy, ExtensionId = %{public}d", context->arrayPrinterExtensionInfo[i].GetExtensionId());
|
||||
PRINT_HILOGD("PrintServiceProxy, VendorId = %{public}d", context->arrayPrinterExtensionInfo[i].GetVendorId());
|
||||
PRINT_HILOGD("PrintServiceProxy, VendorName = %{public}s", context->arrayPrinterExtensionInfo[i].GetVendorName().c_str());
|
||||
PRINT_HILOGD("PrintServiceProxy, VendorIcon = %{public}d", context->arrayPrinterExtensionInfo[i].GetVendorIcon());
|
||||
PRINT_HILOGD("PrintServiceProxy, Version = %{public}s", context->arrayPrinterExtensionInfo[i].GetVersion().c_str());
|
||||
napi_value PrinterInfo;
|
||||
napi_create_object(env, &PrinterInfo);
|
||||
NapiUtils::SetUint32Property(env, PrinterInfo, "extensionId", context->arrayPrinterExtensionInfo[i].GetExtensionId());
|
||||
NapiUtils::SetUint32Property(env, PrinterInfo, "vendorId", context->arrayPrinterExtensionInfo[i].GetVendorId());
|
||||
NapiUtils::SetStringPropertyUtf8(env, PrinterInfo, "vendorName", context->arrayPrinterExtensionInfo[i].GetVendorName().c_str());
|
||||
NapiUtils::SetUint32Property(env, PrinterInfo, "vendorIcon", context->arrayPrinterExtensionInfo[i].GetVendorIcon());
|
||||
NapiUtils::SetStringPropertyUtf8(env, PrinterInfo, "version", context->arrayPrinterExtensionInfo[i].GetVersion().c_str());
|
||||
status = napi_set_element(env, *result, i, PrinterInfo);
|
||||
}
|
||||
PRINT_HILOGD("output ---- status[%{public}d]", status);
|
||||
PRINT_HILOGD("ouput over---->");
|
||||
return napi_ok;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
PRINT_HILOGD("exec enter---->");
|
||||
context->result = PrintManager::GetInstance()->QueryAllExtension(context->arrayPrinterExtensionInfo);
|
||||
if (context->result == true) {
|
||||
PRINT_HILOGD("exec over---->");
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NapiInnerPrint::StartDiscovery(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter StartDiscovery---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<OperationContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg);
|
||||
uint32_t result_size = 0;
|
||||
napi_get_array_length(env, argv[NapiUtils::FIRST_ARGV], &result_size);
|
||||
napi_value array = argv[NapiUtils::FIRST_ARGV];
|
||||
bool isArray = false;
|
||||
napi_is_array(env, array, &isArray);
|
||||
NAPI_ASSERT_BASE(env, isArray, " is not array!", napi_invalid_arg);
|
||||
for (uint32_t i = 0; i < result_size; i++)
|
||||
{
|
||||
napi_value value;
|
||||
napi_get_element(env, array, i, &value);
|
||||
uint32_t valueNumber;
|
||||
napi_get_value_uint32(env, value, &valueNumber);
|
||||
PRINT_HILOGD("output for :---- extensionVector value is :[%{public}d]", valueNumber);
|
||||
context->extensionVector.push_back((int32_t)valueNumber);
|
||||
}
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_boolean(env, context->result, result);
|
||||
PRINT_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
|
||||
return status;
|
||||
};
|
||||
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 = PrintManager::GetInstance()->StartDiscoverPrinter(context->extensionList);
|
||||
if (context->result == true) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NapiInnerPrint::StopDiscovery(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter StopDiscovery---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<OperationContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 0, " should 0 parameter!", napi_invalid_arg);
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_boolean(env, context->result, result);
|
||||
PRINT_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
context->result = PrintManager::GetInstance()->StopDiscoverPrinter();
|
||||
if (context->result == true) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
|
||||
return asyncCall.Call(env, exec);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value NapiInnerPrint::ConnectPrint(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter ConnectPrint---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<OperationContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 1, "should 1 parameter!", napi_invalid_arg);
|
||||
napi_valuetype valuetype;
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, argv[NapiUtils::FIRST_ARGV], &valuetype), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, valuetype == napi_number, "printerId number is not a number", napi_invalid_arg);
|
||||
uint32_t printId;
|
||||
napi_get_value_uint32(env, argv[NapiUtils::FIRST_ARGV], &printId);
|
||||
PRINT_HILOGD("printId : %{public}d",printId);
|
||||
context->printConnId = printId;
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_boolean(env, context->result, result);
|
||||
PRINT_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
context->result = PrintManager::GetInstance()->ConnectPrinter(context->printConnId);
|
||||
if (context->result == true) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NapiInnerPrint::DisconnectPrint(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter DisconnectPrint---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<OperationContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg);
|
||||
napi_valuetype valuetype;
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, argv[NapiUtils::FIRST_ARGV], &valuetype), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, valuetype == napi_number, "printerId number is not a number", napi_invalid_arg);
|
||||
uint32_t printId;
|
||||
napi_get_value_uint32(env,argv[NapiUtils::FIRST_ARGV],&printId);
|
||||
PRINT_HILOGD("printId : %{public}d",printId);
|
||||
context->printDisConnId = printId;
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_boolean(env, context->result, result);
|
||||
PRINT_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
context->result = PrintManager::GetInstance()->DisconnectPrinter(context->printDisConnId);
|
||||
if (context->result == true) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
|
||||
return asyncCall.Call(env, exec);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value NapiInnerPrint::StartPrint(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter StartPrint---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<OperationContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg);
|
||||
napi_valuetype valuetype;
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, argv[NapiUtils::FIRST_ARGV], &valuetype), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, valuetype == napi_object, "printjob number is not a number", napi_invalid_arg);
|
||||
uint32_t printjobObject;
|
||||
napi_get_value_uint32(env,argv[NapiUtils::FIRST_ARGV],&printjobObject);
|
||||
PRINT_HILOGD("printjob : %{public}d",printjobObject);
|
||||
context->printStartJobNumber = printjobObject;
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_boolean(env, context->result, result);
|
||||
PRINT_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
uint32_t fileLength = 3;
|
||||
for(uint32_t i = 0; i < fileLength; i++)
|
||||
{
|
||||
context->jobinfo.GetFiles().push_back("JobInfo");
|
||||
}
|
||||
context->jobinfo.SetJobId(9);
|
||||
context->jobinfo.SetPrintId(99);
|
||||
context->jobinfo.SetJobState(5);
|
||||
context->jobinfo.SetCopyNumber(9);
|
||||
context->jobinfo.GetPageRange().SetStartPage(6);
|
||||
context->jobinfo.GetPageRange().SetEndPage(7);
|
||||
context->jobinfo.GetPageRange().SetPages(6);
|
||||
context->jobinfo.GetPageRange().SetPages(66);
|
||||
context->jobinfo.SetIsSequential(6);
|
||||
context->jobinfo.GetPageSize().SetId(6);
|
||||
context->jobinfo.GetPageSize().SetName("jobinfo.GetPageSize");
|
||||
context->jobinfo.GetPageSize().SetWidth(6);
|
||||
context->jobinfo.GetPageSize().SetHeight(6);
|
||||
context->jobinfo.SetIsLandscape(6);
|
||||
context->jobinfo.SetColorMode(6);
|
||||
context->jobinfo.SetDuplexMode(6);
|
||||
context->jobinfo.GetMargin().SetTop(6);
|
||||
context->jobinfo.GetMargin().SetBottom(6);
|
||||
context->jobinfo.GetMargin().SetLeft(6);
|
||||
context->jobinfo.GetMargin().SetRight(6);
|
||||
context->jobinfo.GetPreview().SetResult("data.ReadString()");
|
||||
context->jobinfo.GetPreview().GetPreviewRange().SetStartPage(6);
|
||||
context->jobinfo.GetPreview().GetPreviewRange().SetEndPage(6);
|
||||
context->jobinfo.GetPreview().GetPreviewRange().SetPages(6);
|
||||
context->jobinfo.GetPreview().GetPreviewRange().SetPages(66);
|
||||
context->result = PrintManager::GetInstance()->StartPrintJob(context->jobinfo);
|
||||
if (context->result == true) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NapiInnerPrint::CancelPrint(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter ---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<OperationContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg);
|
||||
napi_valuetype valuetype;
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, argv[NapiUtils::FIRST_ARGV], &valuetype), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, valuetype == napi_object, "printjob number is not a object", napi_invalid_arg);
|
||||
uint32_t printjobObject;
|
||||
napi_get_value_uint32(env,argv[NapiUtils::FIRST_ARGV],&printjobObject);
|
||||
PRINT_HILOGD("printjob : %{public}d",printjobObject);
|
||||
context->printCancelJobNumber = printjobObject;
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_boolean(env, context->result, result);
|
||||
PRINT_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
uint32_t fileLength = 3;
|
||||
for(uint32_t i = 0; i < fileLength; i++)
|
||||
{
|
||||
context->jobinfo.GetFiles().push_back("JobInfo");
|
||||
}
|
||||
context->jobinfo.SetJobId(9);
|
||||
context->jobinfo.SetPrintId(99);
|
||||
context->jobinfo.SetJobState(5);
|
||||
context->jobinfo.SetCopyNumber(9);
|
||||
context->jobinfo.GetPageRange().SetStartPage(6);
|
||||
context->jobinfo.GetPageRange().SetEndPage(7);
|
||||
context->jobinfo.GetPageRange().SetPages(6);
|
||||
context->jobinfo.GetPageRange().SetPages(66);
|
||||
context->jobinfo.SetIsSequential(6);
|
||||
context->jobinfo.GetPageSize().SetId(6);
|
||||
context->jobinfo.GetPageSize().SetName("jobinfo.GetPageSize");
|
||||
context->jobinfo.GetPageSize().SetWidth(6);
|
||||
context->jobinfo.GetPageSize().SetHeight(6);
|
||||
context->jobinfo.SetIsLandscape(6);
|
||||
context->jobinfo.SetColorMode(6);
|
||||
context->jobinfo.SetDuplexMode(6);
|
||||
context->jobinfo.GetMargin().SetTop(6);
|
||||
context->jobinfo.GetMargin().SetBottom(6);
|
||||
context->jobinfo.GetMargin().SetLeft(6);
|
||||
context->jobinfo.GetMargin().SetRight(6);
|
||||
context->jobinfo.GetPreview().SetResult("data.ReadString()");
|
||||
context->jobinfo.GetPreview().GetPreviewRange().SetStartPage(6);
|
||||
context->jobinfo.GetPreview().GetPreviewRange().SetEndPage(6);
|
||||
context->jobinfo.GetPreview().GetPreviewRange().SetPages(6);
|
||||
context->jobinfo.GetPreview().GetPreviewRange().SetPages(66);
|
||||
context->result = PrintManager::GetInstance()->CancelPrintJob(context->jobinfo);
|
||||
if (context->result == true) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context), 0);
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NapiInnerPrint::RequestPreview(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter ---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<OperationContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg);
|
||||
napi_valuetype valuetype;
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, argv[NapiUtils::FIRST_ARGV], &valuetype), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, valuetype == napi_object, "printjob number is not a object", napi_invalid_arg);
|
||||
uint32_t printjobObject;
|
||||
napi_get_value_uint32(env,argv[NapiUtils::FIRST_ARGV],&printjobObject);
|
||||
PRINT_HILOGD("printjob : %{public}d",printjobObject);
|
||||
context->printReqPreviewJobNumber = printjobObject;
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_create_string_utf8(env, context->previewResult.c_str(), NAPI_AUTO_LENGTH, result);
|
||||
PRINT_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
uint32_t fileLength = 3;
|
||||
for(uint32_t i = 0; i < fileLength; i++)
|
||||
{
|
||||
context->jobinfo.GetFiles().push_back("JobInfo");
|
||||
}
|
||||
context->jobinfo.SetJobId(9);
|
||||
context->jobinfo.SetPrintId(99);
|
||||
context->jobinfo.SetJobState(5);
|
||||
context->jobinfo.SetCopyNumber(9);
|
||||
context->jobinfo.GetPageRange().SetStartPage(6);
|
||||
context->jobinfo.GetPageRange().SetEndPage(7);
|
||||
context->jobinfo.GetPageRange().SetPages(6);
|
||||
context->jobinfo.GetPageRange().SetPages(66);
|
||||
context->jobinfo.SetIsSequential(6);
|
||||
context->jobinfo.GetPageSize().SetId(6);
|
||||
context->jobinfo.GetPageSize().SetName("jobinfo.GetPageSize");
|
||||
context->jobinfo.GetPageSize().SetWidth(6);
|
||||
context->jobinfo.GetPageSize().SetHeight(6);
|
||||
context->jobinfo.SetIsLandscape(6);
|
||||
context->jobinfo.SetColorMode(6);
|
||||
context->jobinfo.SetDuplexMode(6);
|
||||
context->jobinfo.GetMargin().SetTop(6);
|
||||
context->jobinfo.GetMargin().SetBottom(6);
|
||||
context->jobinfo.GetMargin().SetLeft(6);
|
||||
context->jobinfo.GetMargin().SetRight(6);
|
||||
context->jobinfo.GetPreview().SetResult("data.ReadString()");
|
||||
context->jobinfo.GetPreview().GetPreviewRange().SetStartPage(6);
|
||||
context->jobinfo.GetPreview().GetPreviewRange().SetEndPage(6);
|
||||
context->jobinfo.GetPreview().GetPreviewRange().SetPages(6);
|
||||
context->jobinfo.GetPreview().GetPreviewRange().SetPages(66);
|
||||
context->result = PrintManager::GetInstance()->RequestPreview(context->jobinfo, context->previewResult);
|
||||
if (context->result == true) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NapiInnerPrint::QueryCapability(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter QueryCapability---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<OperationContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg);
|
||||
napi_valuetype valuetype;
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, argv[NapiUtils::FIRST_ARGV], &valuetype), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, valuetype == napi_number, "number is not a number", napi_invalid_arg);
|
||||
uint32_t number;
|
||||
napi_get_value_uint32(env,argv[NapiUtils::FIRST_ARGV],&number);
|
||||
PRINT_HILOGD("printjob : %{public}d",number);
|
||||
context->printCapacityId = number;
|
||||
PRINT_HILOGD("input over---->");
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
PRINT_HILOGD("ouput enter---->");
|
||||
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);
|
||||
|
||||
NapiUtils::SetUint32Property(env, *result, "colorMode", context->printerCapability.GetColorMode());
|
||||
NapiUtils::SetUint32Property(env, *result, "duplexMode", context->printerCapability.GetDuplexMode());
|
||||
|
||||
NapiUtils::SetUint32Property(env, resultPrintMargin, "top", context->printerCapability.GetMinMargin().GetTop());
|
||||
NapiUtils::SetUint32Property(env, resultPrintMargin, "bottom", context->printerCapability.GetMinMargin().GetBottom());
|
||||
NapiUtils::SetUint32Property(env, resultPrintMargin, "left", context->printerCapability.GetMinMargin().GetLeft());
|
||||
NapiUtils::SetUint32Property(env, resultPrintMargin, "right", context->printerCapability.GetMinMargin().GetRight());
|
||||
uint32_t printerCapabilityLength = context->printerCapability.GetPageSize().size();
|
||||
|
||||
for(uint32_t i = 0; i < printerCapabilityLength; i++)
|
||||
{
|
||||
napi_value resultPrinterPageSize;
|
||||
napi_create_object(env, &resultPrinterPageSize);
|
||||
NapiUtils::SetUint32Property(env, resultPrinterPageSize, "id", context->printerCapability.GetPageSize()[i].GetId());
|
||||
NapiUtils::SetStringPropertyUtf8(env, resultPrinterPageSize, "name", context->printerCapability.GetPageSize()[i].GetName().c_str());
|
||||
NapiUtils::SetUint32Property(env, resultPrinterPageSize, "width", context->printerCapability.GetPageSize()[i].GetWidth());
|
||||
NapiUtils::SetUint32Property(env, resultPrinterPageSize, "height", context->printerCapability.GetPageSize()[i].GetHeight());
|
||||
status = napi_set_element(env, arrPageSize, i, resultPrinterPageSize);
|
||||
}
|
||||
|
||||
uint32_t printerCapabilityresolutionLength = context->printerCapability.GetResolution().size();
|
||||
|
||||
for(uint32_t i = 0; i < printerCapabilityresolutionLength; i++)
|
||||
{
|
||||
napi_value resultPrinterResolution;
|
||||
napi_create_object(env, &resultPrinterResolution);
|
||||
NapiUtils::SetUint32Property(env, resultPrinterResolution, "id", context->printerCapability.GetResolution()[i].GetId());
|
||||
NapiUtils::SetUint32Property(env, resultPrinterResolution, "horizontalDpi", context->printerCapability.GetResolution()[i].GetHorizontalDpi());
|
||||
NapiUtils::SetUint32Property(env, resultPrinterResolution, "verticalDpi", context->printerCapability.GetResolution()[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;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
context->result = PrintManager::GetInstance()->QueryPrinterCapability(5, context->printerCapability);
|
||||
if (context->result == true) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NapiInnerPrint::On(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter On---->");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value NapiInnerPrint::Off(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter Off---->");
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace OHOS::Print
|
||||
|
||||
|
339
interfaces/kits/napi/src/napi_print_ext.cpp
Normal file
339
interfaces/kits/napi/src/napi_print_ext.cpp
Normal file
@ -0,0 +1,339 @@
|
||||
/*
|
||||
* 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 "napi_print_ext.h"
|
||||
#include "async_call.h"
|
||||
#include "log.h"
|
||||
#include "napi_utils.h"
|
||||
#include "print_manager.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";
|
||||
|
||||
namespace OHOS::Print {
|
||||
napi_value NapiPrintExt::AddPrinters(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter ---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<NapiPrintExtContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == NapiUtils::ONE_ARG, " should 1 parameter!", napi_invalid_arg);
|
||||
napi_value array = argv[NapiUtils::FIRST_ARGV];
|
||||
bool isArray = false;
|
||||
napi_is_array(env, array, &isArray);
|
||||
NAPI_ASSERT_BASE(env, isArray, " is not array!", napi_invalid_arg);
|
||||
|
||||
uint32_t result_size;
|
||||
napi_get_array_length(env, argv[NapiUtils::FIRST_ARGV], &result_size);
|
||||
|
||||
PrintInfo info_;
|
||||
for(uint32_t i = 0; i < result_size; i++)
|
||||
{
|
||||
napi_value value;
|
||||
napi_get_element(env, array, i, &value);
|
||||
if(!ParseInfo(env, value, info_))
|
||||
{
|
||||
PRINT_HILOGD("PrintInfo is format error!");
|
||||
}
|
||||
context->printInfoVector.push_back(info_);
|
||||
}
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_boolean(env, context->result, result);
|
||||
PRINT_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
for(uint32_t i = 0; i < 3; i++)
|
||||
{
|
||||
PrintInfo printInfo;
|
||||
printInfo.SetPrinterId(1);
|
||||
printInfo.SetPrinterName("data.ReadString()");
|
||||
printInfo.SetPrinterIcon(1);
|
||||
printInfo.SetPrinterState(1);
|
||||
printInfo.SetDescription("data.ReadString()");
|
||||
printInfo.GetCapability().GetMinMargin().SetTop(1);
|
||||
printInfo.GetCapability().GetMinMargin().SetBottom(1);
|
||||
printInfo.GetCapability().GetMinMargin().SetLeft(1);
|
||||
printInfo.GetCapability().GetMinMargin().SetRight(1);
|
||||
for(uint32_t i = 0; i < 3; i++)
|
||||
{
|
||||
PrinterPageSize printerPageSize;
|
||||
printerPageSize.SetId(1);
|
||||
printerPageSize.SetName("data.ReadString()");
|
||||
printerPageSize.SetWidth(1);
|
||||
printerPageSize.SetHeight(1);
|
||||
printInfo.GetCapability().GetPageSize().push_back(printerPageSize);
|
||||
}
|
||||
for(uint32_t i = 0; i < 3; i++)
|
||||
{
|
||||
PrinterResolution printerResolution;
|
||||
printerResolution.SetId(1);
|
||||
printerResolution.SetHorizontalDpi(1);
|
||||
printerResolution.SetVerticalDpi(1);
|
||||
printInfo.GetCapability().GetResolution().push_back(printerResolution);
|
||||
}
|
||||
printInfo.GetCapability().SetColorMode(1);
|
||||
printInfo.GetCapability().SetDuplexMode(1);
|
||||
context->arrayPrintInfo.push_back(printInfo);
|
||||
|
||||
PRINT_HILOGD("AddPrinters = %{public}d", context->arrayPrintInfo[i].GetPrintId());
|
||||
PRINT_HILOGD("AddPrinters = %{public}s", context->arrayPrintInfo[i].GetPrinterName().c_str());
|
||||
PRINT_HILOGD("AddPrinters = %{public}d", context->arrayPrintInfo[i].GetPrinterIcon());
|
||||
PRINT_HILOGD("AddPrinters = %{public}d", context->arrayPrintInfo[i].GetPrinterState());
|
||||
PRINT_HILOGD("AddPrinters = %{public}s", context->arrayPrintInfo[i].GetDescription().c_str());
|
||||
}
|
||||
context->result = PrintManager::GetInstance()->AddPrinters(context->arrayPrintInfo);
|
||||
if (context->result == true) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NapiPrintExt::RemovePrinters(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter ---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<NapiPrintExtContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 1, " should 1 parameter!", napi_invalid_arg);
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_boolean(env, context->result, result);
|
||||
PRINT_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
for(uint32_t i = 0; i < 3; i++)
|
||||
{
|
||||
PrintInfo printInfo;
|
||||
printInfo.SetPrinterId(1);
|
||||
printInfo.SetPrinterName("data.ReadString()");
|
||||
printInfo.SetPrinterIcon(1);
|
||||
printInfo.SetPrinterState(1);
|
||||
printInfo.SetDescription("data.ReadString()");
|
||||
printInfo.GetCapability().GetMinMargin().SetTop(1);
|
||||
printInfo.GetCapability().GetMinMargin().SetBottom(1);
|
||||
printInfo.GetCapability().GetMinMargin().SetLeft(1);
|
||||
printInfo.GetCapability().GetMinMargin().SetRight(1);
|
||||
|
||||
for(uint32_t i = 0; i < 3; i++)
|
||||
{
|
||||
PrinterPageSize printerPageSize;
|
||||
printerPageSize.SetId(1);
|
||||
printerPageSize.SetName("data.ReadString()");
|
||||
printerPageSize.SetWidth(1);
|
||||
printerPageSize.SetHeight(1);
|
||||
printInfo.GetCapability().GetPageSize().push_back(printerPageSize);
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < 3; i++)
|
||||
{
|
||||
PrinterResolution printerResolution;
|
||||
printerResolution.SetId(1);
|
||||
printerResolution.SetHorizontalDpi(1);
|
||||
printerResolution.SetVerticalDpi(1);
|
||||
printInfo.GetCapability().GetResolution().push_back(printerResolution);
|
||||
}
|
||||
|
||||
printInfo.GetCapability().SetColorMode(1);
|
||||
printInfo.GetCapability().SetDuplexMode(1);
|
||||
context->arrayPrintInfo.push_back(printInfo);
|
||||
PRINT_HILOGD("AddPrinters = %{public}d", context->arrayPrintInfo[i].GetPrintId());
|
||||
PRINT_HILOGD("AddPrinters = %{public}s", context->arrayPrintInfo[i].GetPrinterName().c_str());
|
||||
PRINT_HILOGD("AddPrinters = %{public}d", context->arrayPrintInfo[i].GetPrinterIcon());
|
||||
PRINT_HILOGD("AddPrinters = %{public}d", context->arrayPrintInfo[i].GetPrinterState());
|
||||
PRINT_HILOGD("AddPrinters = %{public}s", context->arrayPrintInfo[i].GetDescription().c_str());
|
||||
}
|
||||
context->result = PrintManager::GetInstance()->RemovePrinters(context->arrayPrintInfo);
|
||||
if (context->result == true) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
napi_value NapiPrintExt::UpdatePrinterState(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter ---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<NapiPrintExtContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == NapiUtils::TWO_ARG, " should 2 parameter!", napi_invalid_arg);
|
||||
napi_valuetype valuetype;
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, argv[NapiUtils::FIRST_ARGV], &valuetype), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, valuetype == napi_number, "valuetype is not a number", napi_invalid_arg);
|
||||
uint32_t printerId = 0;
|
||||
napi_get_value_uint32(env, argv[NapiUtils::FIRST_ARGV], &printerId);
|
||||
PRINT_HILOGD("printerId : %{public}d", printerId);
|
||||
context->printerId = printerId;
|
||||
napi_valuetype valueSecondtype;
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, argv[NapiUtils::SECOND_ARGV], &valueSecondtype), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, valueSecondtype == napi_number, "valueSecondtype is not a string", napi_invalid_arg);
|
||||
uint32_t printerState = 0;
|
||||
napi_get_value_uint32(env, argv[NapiUtils::SECOND_ARGV], &printerState);
|
||||
PRINT_HILOGD("printerState : %{public}d", printerState);
|
||||
context->printerState = printerState;
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_boolean(env, context->result, result);
|
||||
PRINT_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
context->result = PrintManager::GetInstance()->UpdatePrinterState(context->printerId,context->printerState);
|
||||
if (context->result == true) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
napi_value NapiPrintExt::UpdatePrintJobState(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter ---->");
|
||||
if (!PrintManager::GetInstance()->CheckPermission()) {
|
||||
PRINT_HILOGD("no permission to access print service");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = std::make_shared<NapiPrintExtContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == NapiUtils::TWO_ARG, " should 2 parameter!", napi_invalid_arg);
|
||||
napi_valuetype valuetype;
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, argv[NapiUtils::FIRST_ARGV], &valuetype), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, valuetype == napi_number, "printerJobState is not a number", napi_invalid_arg);
|
||||
uint32_t printerJobId = 0;
|
||||
napi_get_value_uint32(env, argv[NapiUtils::FIRST_ARGV], &printerJobId);
|
||||
PRINT_HILOGD("printerJobId : %{public}d", printerJobId);
|
||||
context->printerJobId = printerJobId;
|
||||
napi_valuetype valueSecondtype;
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, argv[NapiUtils::SECOND_ARGV], &valueSecondtype), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, valueSecondtype == napi_number, "valueSecondtype is not a string", napi_invalid_arg);
|
||||
uint32_t printerJobState = 0;
|
||||
napi_get_value_uint32(env, argv[NapiUtils::SECOND_ARGV], &printerJobState);
|
||||
PRINT_HILOGD("printerJobState : %{public}d", printerJobState);
|
||||
context->printerJobState = printerJobState;
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_boolean(env, context->result, result);
|
||||
PRINT_HILOGD("output ---- [%{public}s], status[%{public}d]", context->result ? "true" : "false", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
context->result = PrintManager::GetInstance()->UpdatePrinterJobState(context->printerJobId,context->printerJobState);
|
||||
if (context->result == true) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context));
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
bool NapiPrintExt::ParseInfo(napi_env env, napi_value InfoValue, PrintInfo &info)
|
||||
{
|
||||
if (!ParseInfoParam(env, InfoValue, info)) {
|
||||
PRINT_HILOGD("ParseInfoParam is error!");
|
||||
return false;
|
||||
}
|
||||
info.SetPrinterName(NapiUtils::GetStringPropertyUtf8(env, InfoValue, PARAM_INFO_PRINTERNAME));
|
||||
info.SetPrinterIcon(NapiUtils::GetUint32Property(env, InfoValue, PARAM_INFO_PRINTERICON));
|
||||
info.SetPrinterState(NapiUtils::GetUint32Property(env, InfoValue, PARAM_INFO_PRINTERSTATE));
|
||||
info.SetDescription(NapiUtils::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, PrintInfo &info)
|
||||
{
|
||||
napi_value param_one = NapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_PRINTID);
|
||||
if (NapiUtils::GetValueType(env, param_one) != napi_number) {
|
||||
PRINT_HILOGD("error param_one");
|
||||
return false;
|
||||
}
|
||||
napi_value param_two = NapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_PRINTERNAME);
|
||||
if (NapiUtils::GetValueType(env, param_two) != napi_string) {
|
||||
PRINT_HILOGD("error param_two");
|
||||
return false;
|
||||
}
|
||||
napi_value param_three = NapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_PRINTERICON);
|
||||
if (NapiUtils::GetValueType(env, param_three) != napi_number) {
|
||||
PRINT_HILOGD("error param_three");
|
||||
return false;
|
||||
}
|
||||
napi_value param_four = NapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_PRINTERSTATE);
|
||||
if (NapiUtils::GetValueType(env, param_four) != napi_number) {
|
||||
PRINT_HILOGD("error param_four");
|
||||
return false;
|
||||
}
|
||||
napi_value param_five = NapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_DESCRIPTION);
|
||||
if (NapiUtils::GetValueType(env, param_five) != napi_number) {
|
||||
PRINT_HILOGD("error param_five");
|
||||
return false;
|
||||
}
|
||||
napi_value param_six = NapiUtils::GetNamedProperty(env, InfoValue, PARAM_INFO_CAPABILITY);
|
||||
if (NapiUtils::GetValueType(env, param_six) != napi_object) {
|
||||
PRINT_HILOGD("error param_six");
|
||||
return false;
|
||||
}
|
||||
auto names = NapiUtils::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 = NapiUtils::GetUint32Property(env, param_one, *iter);
|
||||
if (value) {
|
||||
info.SetPrinterId(value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NapiPrintExt::ParseCapability(napi_env env, napi_value CapValue, PrinterCapability &capability)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
} // namespace OHOS::Print
|
103
interfaces/kits/napi/src/napi_print_task.cpp
Normal file
103
interfaces/kits/napi/src/napi_print_task.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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 "napi_print_task.h"
|
||||
#include <mutex>
|
||||
#include "async_call.h"
|
||||
#include "log.h"
|
||||
#include "napi_utils.h"
|
||||
#include "print_task.h"
|
||||
#include "print_manager.h"
|
||||
|
||||
static constexpr const char *FUNCTION_ON = "on";
|
||||
static constexpr const char *FUNCTION_OFF = "off";
|
||||
|
||||
namespace OHOS::Print {
|
||||
__thread napi_ref NapiPrintTask::globalCtor = nullptr;
|
||||
std::mutex mutex_;
|
||||
napi_value NapiPrintTask::Print(napi_env env, napi_callback_info info)//PrintTask
|
||||
{
|
||||
PRINT_HILOGD("Enter print JsMain.");
|
||||
struct ContextInfo {
|
||||
napi_ref ref = nullptr;
|
||||
};
|
||||
auto ctxInfo = std::make_shared<ContextInfo>();
|
||||
auto input = [ctxInfo](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
PRINT_HILOGD("print parser to native params %{public}d!", static_cast<int>(argc));
|
||||
NAPI_ASSERT_BASE(env, (argc > 0) && (argc <= 3), " need 2 or 3 parameters!", napi_invalid_arg);
|
||||
napi_value proxy = nullptr;
|
||||
napi_status status = napi_new_instance(env, GetCtor(env), argc, argv, &proxy);
|
||||
if ((proxy == nullptr) || (status != napi_ok)) {
|
||||
PRINT_HILOGE("Failed to create print task");
|
||||
return napi_generic_failure;
|
||||
}
|
||||
napi_create_reference(env, proxy, 1, &(ctxInfo->ref));
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [ctxInfo](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_reference_value(env, ctxInfo->ref, result);
|
||||
napi_delete_reference(env, ctxInfo->ref);
|
||||
return status;
|
||||
};
|
||||
auto context = std::make_shared<AsyncCall::Context>(input, output);
|
||||
AsyncCall asyncCall(env, info, context);
|
||||
return asyncCall.Call(env);
|
||||
}
|
||||
|
||||
napi_value NapiPrintTask::GetCtor(napi_env env)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
napi_value cons;
|
||||
if (globalCtor != nullptr) {
|
||||
NAPI_CALL(env, napi_get_reference_value(env, globalCtor, &cons));
|
||||
return cons;
|
||||
}
|
||||
|
||||
napi_property_descriptor clzDes[] = {
|
||||
{FUNCTION_ON, 0, PrintTask::On, 0, 0, 0, napi_default, 0},
|
||||
{FUNCTION_OFF, 0, PrintTask::Off, 0, 0, 0, napi_default, 0},
|
||||
};
|
||||
NAPI_CALL(env, napi_define_class(env, "NapiPrintTask", NAPI_AUTO_LENGTH, Initialize, nullptr,
|
||||
sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons));
|
||||
NAPI_CALL(env, napi_create_reference(env, cons, 1, &globalCtor));
|
||||
return cons;
|
||||
}
|
||||
|
||||
napi_value NapiPrintTask::Initialize(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("constructor print task!");
|
||||
napi_value self = nullptr;
|
||||
size_t argc = NapiUtils::MAX_ARGC;
|
||||
napi_value argv[NapiUtils::MAX_ARGC] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &self, nullptr));
|
||||
|
||||
auto task = new PrintTask(PrintManager::GetInstance()->Dummy());
|
||||
if (task == nullptr) {
|
||||
PRINT_HILOGE("print task fail");
|
||||
return nullptr;
|
||||
}
|
||||
auto finalize = [](napi_env env, void *data, void *hint) {
|
||||
PRINT_HILOGD("destructed print task");
|
||||
PrintTask *task = reinterpret_cast<PrintTask *>(data);
|
||||
delete task;
|
||||
};
|
||||
if (napi_wrap(env, self, task, finalize, nullptr, nullptr) != napi_ok) {
|
||||
finalize(env, task, nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
PRINT_HILOGD("Succeed to allocate print task");
|
||||
return self;
|
||||
}
|
||||
} // namespace OHOS::Print
|
308
interfaces/kits/napi/src/napi_utils.cpp
Normal file
308
interfaces/kits/napi/src/napi_utils.cpp
Normal file
@ -0,0 +1,308 @@
|
||||
/*
|
||||
* Copyright (C) 2021-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 "napi_utils.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include "log.h"
|
||||
#include "securec.h"
|
||||
|
||||
namespace OHOS::Print::NapiUtils {
|
||||
static constexpr const int MAX_STRING_LENGTH = 65536;
|
||||
|
||||
napi_valuetype GetValueType(napi_env env, napi_value value)
|
||||
{
|
||||
if (value == nullptr) {
|
||||
return napi_undefined;
|
||||
}
|
||||
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, value, &valueType), napi_undefined);
|
||||
return valueType;
|
||||
}
|
||||
|
||||
/* named property */
|
||||
bool HasNamedProperty(napi_env env, napi_value object, const std::string &propertyName)
|
||||
{
|
||||
bool hasProperty = false;
|
||||
NAPI_CALL_BASE(env, napi_has_named_property(env, object, propertyName.c_str(), &hasProperty), false);
|
||||
return hasProperty;
|
||||
}
|
||||
|
||||
napi_value GetNamedProperty(napi_env env, napi_value object, const std::string &propertyName)
|
||||
{
|
||||
napi_value value = nullptr;
|
||||
bool hasProperty = false;
|
||||
NAPI_CALL(env, napi_has_named_property(env, object, propertyName.c_str(), &hasProperty));
|
||||
if (!hasProperty) {
|
||||
return value;
|
||||
}
|
||||
NAPI_CALL(env, napi_get_named_property(env, object, propertyName.c_str(), &value));
|
||||
return value;
|
||||
}
|
||||
|
||||
void SetNamedProperty(napi_env env, napi_value object, const std::string &name, napi_value value)
|
||||
{
|
||||
(void)napi_set_named_property(env, object, name.c_str(), value);
|
||||
}
|
||||
|
||||
std::vector<std::string> GetPropertyNames(napi_env env, napi_value object)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
napi_value names = nullptr;
|
||||
NAPI_CALL_BASE(env, napi_get_property_names(env, object, &names), ret);
|
||||
uint32_t length = 0;
|
||||
NAPI_CALL_BASE(env, napi_get_array_length(env, names, &length), ret);
|
||||
for (uint32_t index = 0; index < length; ++index) {
|
||||
napi_value name = nullptr;
|
||||
if (napi_get_element(env, names, index, &name) != napi_ok) {
|
||||
continue;
|
||||
}
|
||||
if (GetValueType(env, name) != napi_string) {
|
||||
continue;
|
||||
}
|
||||
ret.emplace_back(GetStringFromValueUtf8(env, name));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* UINT32 */
|
||||
napi_value CreateUint32(napi_env env, uint32_t code)
|
||||
{
|
||||
napi_value value = nullptr;
|
||||
if (napi_create_uint32(env, code, &value) != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
uint32_t GetUint32FromValue(napi_env env, napi_value value)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
NAPI_CALL_BASE(env, napi_get_value_uint32(env, value, &ret), 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t GetUint32Property(napi_env env, napi_value object, const std::string &propertyName)
|
||||
{
|
||||
if (!HasNamedProperty(env, object, propertyName)) {
|
||||
return 0;
|
||||
}
|
||||
napi_value value = GetNamedProperty(env, object, propertyName);
|
||||
return GetUint32FromValue(env, value);
|
||||
}
|
||||
|
||||
void SetUint32Property(napi_env env, napi_value object, const std::string &name, uint32_t value)
|
||||
{
|
||||
napi_value jsValue = CreateUint32(env, value);
|
||||
if (GetValueType(env, jsValue) != napi_number) {
|
||||
return;
|
||||
}
|
||||
|
||||
napi_set_named_property(env, object, name.c_str(), jsValue);
|
||||
}
|
||||
|
||||
/* INT32 */
|
||||
napi_value CreateInt32(napi_env env, int32_t code)
|
||||
{
|
||||
napi_value value = nullptr;
|
||||
if (napi_create_int32(env, code, &value) != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int32_t GetInt32FromValue(napi_env env, napi_value value)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
NAPI_CALL_BASE(env, napi_get_value_int32(env, value, &ret), 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t GetInt32Property(napi_env env, napi_value object, const std::string &propertyName)
|
||||
{
|
||||
if (!HasNamedProperty(env, object, propertyName)) {
|
||||
return 0;
|
||||
}
|
||||
napi_value value = GetNamedProperty(env, object, propertyName);
|
||||
return GetInt32FromValue(env, value);
|
||||
}
|
||||
|
||||
void SetInt32Property(napi_env env, napi_value object, const std::string &name, int32_t value)
|
||||
{
|
||||
napi_value jsValue = CreateInt32(env, value);
|
||||
if (GetValueType(env, jsValue) != napi_number) {
|
||||
return;
|
||||
}
|
||||
|
||||
napi_set_named_property(env, object, name.c_str(), jsValue);
|
||||
}
|
||||
|
||||
/* String UTF8 */
|
||||
napi_value CreateStringUtf8(napi_env env, const std::string &str)
|
||||
{
|
||||
napi_value value = nullptr;
|
||||
if (napi_create_string_utf8(env, str.c_str(), strlen(str.c_str()), &value) != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string GetStringFromValueUtf8(napi_env env, napi_value value)
|
||||
{
|
||||
std::string result;
|
||||
std::vector<char> str(MAX_STRING_LENGTH + 1, '\0');
|
||||
size_t length = 0;
|
||||
NAPI_CALL_BASE(env, napi_get_value_string_utf8(env, value, &str[0], MAX_STRING_LENGTH, &length), result);
|
||||
if (length > 0) {
|
||||
return result.append(&str[0], length);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string GetStringPropertyUtf8(napi_env env, napi_value object, const std::string &propertyName)
|
||||
{
|
||||
if (!HasNamedProperty(env, object, propertyName)) {
|
||||
return "";
|
||||
}
|
||||
napi_value value = GetNamedProperty(env, object, propertyName);
|
||||
return GetStringFromValueUtf8(env, value);
|
||||
}
|
||||
|
||||
void SetStringPropertyUtf8(napi_env env, napi_value object, const std::string &name, const std::string &value)
|
||||
{
|
||||
napi_value jsValue = CreateStringUtf8(env, value);
|
||||
if (GetValueType(env, jsValue) != napi_string) {
|
||||
return;
|
||||
}
|
||||
napi_set_named_property(env, object, name.c_str(), jsValue);
|
||||
}
|
||||
|
||||
/* array buffer */
|
||||
bool ValueIsArrayBuffer(napi_env env, napi_value value)
|
||||
{
|
||||
bool isArrayBuffer = false;
|
||||
NAPI_CALL_BASE(env, napi_is_arraybuffer(env, value, &isArrayBuffer), false);
|
||||
return isArrayBuffer;
|
||||
}
|
||||
|
||||
void *GetInfoFromArrayBufferValue(napi_env env, napi_value value, size_t *length)
|
||||
{
|
||||
if (length == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void *data = nullptr;
|
||||
NAPI_CALL(env, napi_get_arraybuffer_info(env, value, &data, length));
|
||||
return data;
|
||||
}
|
||||
|
||||
/* object */
|
||||
napi_value CreateObject(napi_env env)
|
||||
{
|
||||
napi_value object = nullptr;
|
||||
NAPI_CALL(env, napi_create_object(env, &object));
|
||||
return object;
|
||||
}
|
||||
|
||||
/* undefined */
|
||||
napi_value GetUndefined(napi_env env)
|
||||
{
|
||||
napi_value undefined = nullptr;
|
||||
NAPI_CALL(env, napi_get_undefined(env, &undefined));
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/* function */
|
||||
napi_value CallFunction(napi_env env, napi_value recv, napi_value func, size_t argc, const napi_value *argv)
|
||||
{
|
||||
napi_value res = nullptr;
|
||||
NAPI_CALL(env, napi_call_function(env, recv, func, argc, argv, &res));
|
||||
return res;
|
||||
}
|
||||
|
||||
/* reference */
|
||||
napi_ref CreateReference(napi_env env, napi_value callback)
|
||||
{
|
||||
napi_ref callbackRef = nullptr;
|
||||
NAPI_CALL(env, napi_create_reference(env, callback, 1, &callbackRef));
|
||||
return callbackRef;
|
||||
}
|
||||
|
||||
napi_value GetReference(napi_env env, napi_ref callbackRef)
|
||||
{
|
||||
napi_value callback = nullptr;
|
||||
NAPI_CALL(env, napi_get_reference_value(env, callbackRef, &callback));
|
||||
return callback;
|
||||
}
|
||||
|
||||
void DeleteReference(napi_env env, napi_ref callbackRef)
|
||||
{
|
||||
(void)napi_delete_reference(env, callbackRef);
|
||||
}
|
||||
|
||||
/* boolean */
|
||||
bool GetBooleanProperty(napi_env env, napi_value object, const std::string &propertyName)
|
||||
{
|
||||
if (!HasNamedProperty(env, object, propertyName)) {
|
||||
return false;
|
||||
}
|
||||
napi_value value = GetNamedProperty(env, object, propertyName);
|
||||
bool ret = false;
|
||||
NAPI_CALL_BASE(env, napi_get_value_bool(env, value, &ret), false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SetBooleanProperty(napi_env env, napi_value object, const std::string &name, bool value)
|
||||
{
|
||||
napi_value jsValue = nullptr;
|
||||
NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, value, &jsValue));
|
||||
if (GetValueType(env, jsValue) != napi_boolean) {
|
||||
return;
|
||||
}
|
||||
|
||||
napi_set_named_property(env, object, name.c_str(), jsValue);
|
||||
}
|
||||
|
||||
/* define properties */
|
||||
void DefineProperties(
|
||||
napi_env env, napi_value object, const std::initializer_list<napi_property_descriptor> &properties)
|
||||
{
|
||||
napi_property_descriptor descriptors[properties.size()];
|
||||
std::copy(properties.begin(), properties.end(), descriptors);
|
||||
|
||||
(void)napi_define_properties(env, object, properties.size(), descriptors);
|
||||
}
|
||||
|
||||
std::string ToLower(const std::string &s)
|
||||
{
|
||||
std::string res = s;
|
||||
std::transform(res.begin(), res.end(), res.begin(), tolower);
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string GetValueString(napi_env env, napi_value value)
|
||||
{
|
||||
std::string resultValue = "";
|
||||
char value_string[256];
|
||||
size_t value_size = 256;
|
||||
size_t result;
|
||||
napi_get_value_string_utf8(env, value, value_string, value_size, &result);
|
||||
resultValue = value_string;
|
||||
return resultValue;
|
||||
}
|
||||
} // namespace OHOS::Print::NapiUtils
|
84
interfaces/kits/napi/src/print_module.cpp
Normal file
84
interfaces/kits/napi/src/print_module.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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 "napi/native_api.h"
|
||||
//#include "napi/native_node_api.h"
|
||||
#include "napi_print_task.h"
|
||||
#include "napi_inner_print.h"
|
||||
#include "napi_print_ext.h"
|
||||
#include "log.h"
|
||||
#include "constant.h"
|
||||
|
||||
using namespace OHOS::Print;
|
||||
|
||||
static constexpr const char *FUNCTION_PRINT = "print";
|
||||
static constexpr const char *FUNCTION_QUERY_EXT = "queryExtensionAbilityInfos";
|
||||
static constexpr const char *FUNCTION_START_DISCOVERY = "startDiscoverPrinter";
|
||||
static constexpr const char *FUNCTION_STOP_DISCOVERY = "stopDiscoverPrinter";
|
||||
static constexpr const char *FUNCTION_CONNECT_PRINT = "connectPrinter";
|
||||
static constexpr const char *FUNCTION_DISCONNECT_PRINT = "disconnectPrinter";
|
||||
static constexpr const char *FUNCTION_START_PRINT = "startPrintJob";
|
||||
static constexpr const char *FUNCTION_CANCEL_PRINT = "cancelPrintJob";
|
||||
static constexpr const char *FUNCTION_REQUEST_PREVIEW = "requestPrintPreview";
|
||||
static constexpr const char *FUNCTION_QUERY_CAPABILITY = "queryPrinterCapability";
|
||||
static constexpr const char *FUNCTION_REGISTER_EVENT = "on";
|
||||
static constexpr const char *FUNCTION_UNREGISTER_EVENT = "off";
|
||||
static constexpr const char *FUNCTION_ADD_PRINTER = "addPrinters";
|
||||
static constexpr const char *FUNCTION_REMOVE_PRINTER = "removePrinters";
|
||||
static constexpr const char *FUNCTION_UPDATE_PRINTER_STATE = "updatePrinterState";
|
||||
static constexpr const char *FUNCTION_UPDATE_JOB_STATE = "updatePrintJobState";
|
||||
|
||||
#define DECLARE_NAPI_METHOD(name, func) { name, 0, func, 0, 0, 0, napi_default, 0 }
|
||||
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_METHOD(FUNCTION_PRINT, NapiPrintTask::Print),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_QUERY_EXT, NapiInnerPrint::QueryExtensionInfo),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_START_DISCOVERY, NapiInnerPrint::StartDiscovery),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_STOP_DISCOVERY, NapiInnerPrint::StopDiscovery),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_CONNECT_PRINT, NapiInnerPrint::ConnectPrint),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_DISCONNECT_PRINT, NapiInnerPrint::DisconnectPrint),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_START_PRINT, NapiInnerPrint::StartPrint),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_CANCEL_PRINT, NapiInnerPrint::CancelPrint),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_REQUEST_PREVIEW, NapiInnerPrint::RequestPreview),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_QUERY_CAPABILITY, NapiInnerPrint::QueryCapability),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_REGISTER_EVENT, NapiInnerPrint::On),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_UNREGISTER_EVENT, NapiInnerPrint::Off),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_ADD_PRINTER, NapiPrintExt::AddPrinters),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_REMOVE_PRINTER, NapiPrintExt::RemovePrinters),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_UPDATE_PRINTER_STATE, NapiPrintExt::UpdatePrinterState),
|
||||
DECLARE_NAPI_METHOD(FUNCTION_UPDATE_JOB_STATE, NapiPrintExt::UpdatePrintJobState),
|
||||
};
|
||||
|
||||
napi_status status = napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc);
|
||||
PRINT_HILOGD("init upload %{public}d", status);
|
||||
return exports;
|
||||
}
|
||||
|
||||
static __attribute__((constructor)) void RegisterModule()
|
||||
{
|
||||
static napi_module module = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "print",
|
||||
.nm_priv = ((void *)0),
|
||||
.reserved = { 0 }
|
||||
};
|
||||
napi_module_register(&module);
|
||||
PRINT_HILOGD("module register print");
|
||||
}
|
82
interfaces/kits/napi/src/print_task.cpp
Normal file
82
interfaces/kits/napi/src/print_task.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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_task.h"
|
||||
#include "async_call.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
PrintTask::PrintTask(uint32_t taskId) : taskId_(taskId)
|
||||
{
|
||||
supportEvents_[EVENT_BLOCK] = true;
|
||||
supportEvents_[EVENT_SUCCESS] = true;
|
||||
supportEvents_[EVENT_FAIL] = true;
|
||||
supportEvents_[EVENT_CANCEL] = true;
|
||||
|
||||
supportPrinterState_[PRINTER_STATE_ADD] = true;
|
||||
supportPrinterState_[PRINTER_STATE_REMOVED] = true;
|
||||
supportPrinterState_[PRINTER_STATE_IDLE] = true;
|
||||
supportPrinterState_[PRINTER_STATE_PRINTING] = true;
|
||||
supportPrinterState_[PRINTER_STATE_BLOCKED] = true;
|
||||
supportPrinterState_[PRINTER_STATE_BUSY] = true;
|
||||
supportPrinterState_[PRINTER_STATE_FAILED] = true;
|
||||
|
||||
supportJobState_[PRINTJOB_STATE_CREATED] = true;
|
||||
supportJobState_[PRINTJOB_STATE_QUEUED] = true;
|
||||
supportJobState_[PRINTJOB_STATE_PRINTING] = true;
|
||||
supportJobState_[PRINTJOB_STATE_BLOCKED] = true;
|
||||
supportJobState_[PRINTJOB_STATE_SUCCESS] = true;
|
||||
supportJobState_[PRINTJOB_STATE_FAILED] = true;
|
||||
supportJobState_[PRINTJOB_STATE_cancelled] = true;
|
||||
}
|
||||
|
||||
PrintTask::~PrintTask()
|
||||
{
|
||||
supportEvents_.clear();
|
||||
}
|
||||
|
||||
uint32_t PrintTask::GetId() const
|
||||
{
|
||||
return taskId_;
|
||||
}
|
||||
|
||||
napi_value PrintTask::On(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter ---->");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value PrintTask::Off(napi_env env, napi_callback_info info)
|
||||
{
|
||||
PRINT_HILOGD("Enter ---->");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PrintTask::IsSupportType(const std::string &type)
|
||||
{
|
||||
return supportEvents_.find(type) != supportEvents_.end();
|
||||
}
|
||||
|
||||
bool PrintTask::IsSupportPrinterStateType(const std::string &type)
|
||||
{
|
||||
return supportPrinterState_.find(type) != supportPrinterState_.end();
|
||||
}
|
||||
|
||||
bool PrintTask::IsSupportJobStateType(const std::string &type)
|
||||
{
|
||||
PRINT_HILOGD("Enter IsSupportJobStateType.");
|
||||
return supportJobState_.find(type) != supportJobState_.end();
|
||||
}
|
||||
} // namespace OHOS::Print
|
24
profile/3707.xml
Normal file
24
profile/3707.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
<info>
|
||||
<process>print_service</process>
|
||||
<systemability>
|
||||
<name>3707</name>
|
||||
<libpath>libprint_service.z.so</libpath>
|
||||
<run-on-create>true</run-on-create>
|
||||
<distributed>false</distributed>
|
||||
<dump-level>1</dump-level>
|
||||
</systemability>
|
||||
</info>
|
19
profile/BUILD.gn
Normal file
19
profile/BUILD.gn
Normal file
@ -0,0 +1,19 @@
|
||||
# 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.
|
||||
|
||||
import("//build/ohos/sa_profile/sa_profile.gni")
|
||||
|
||||
ohos_sa_profile("print_sa_profiles") {
|
||||
sources = [ "3707.xml" ]
|
||||
part_name = "print"
|
||||
}
|
84
services/BUILD.gn
Normal file
84
services/BUILD.gn
Normal file
@ -0,0 +1,84 @@
|
||||
# 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
config("print_service_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//third_party/curl/include",
|
||||
"//third_party/openssl/include",
|
||||
]
|
||||
|
||||
ldflags = [ "-Wl,--exclude-libs,libcrypto_static.a" ]
|
||||
ldflags += [ "-Wl,--exclude-libs,libcurl.a" ]
|
||||
|
||||
cflags_cc = [ "-fexceptions" ]
|
||||
cflags = [ "-DOPENSSL_ARM64_PLATFORM" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("print_service") {
|
||||
sources = [
|
||||
"src/print_service_ability.cpp",
|
||||
"src/print_service_stub.cpp",
|
||||
"src/print_notify_proxy.cpp",
|
||||
"src/print_service_manager.cpp",
|
||||
]
|
||||
|
||||
public_configs = [
|
||||
"//commonlibrary/c_utils/base:utils_config",
|
||||
":print_service_config",
|
||||
]
|
||||
include_dirs = [
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"//foundation/communication/netmanager_base/interfaces/innerkits/netconnclient/include",
|
||||
"//base/notification/distributed_notification_service/interfaces/inner_api",
|
||||
"//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include",
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"//base/print/print/frameworks/innerkitsimpl/include",
|
||||
"//base/print/print/utils/include",
|
||||
]
|
||||
deps = [
|
||||
"//base/notification/distributed_notification_service/frameworks/ans:ans_innerkits",
|
||||
"//base/telephony/core_service/interfaces/innerkits:tel_core_service_api",
|
||||
"//foundation/communication/netmanager_base/interfaces/innerkits/netconnclient:net_conn_manager_if",
|
||||
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//base/print/print/frameworks/innerkitsimpl:printclient",
|
||||
]
|
||||
|
||||
defines = [ "NO_SSL_CERTIFICATION=1" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"drivers_interface_ril:hril_innerkits",
|
||||
"eventhandler:libeventhandler",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hitrace_native:hitrace_meter",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"multimedia_image_standard:image_native",
|
||||
"os_account:os_account_innerkits",
|
||||
"relational_store:native_rdb",
|
||||
]
|
||||
subsystem_name = "print"
|
||||
part_name = "print"
|
||||
}
|
34
services/include/print_notify_proxy.h
Normal file
34
services/include/print_notify_proxy.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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_NOTIFY_PROXY_H
|
||||
#define PRINT_NOTIFY_PROXY_H
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
#include "print_notify_interface.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrintNotifyProxy : public IRemoteProxy<PrintNotifyInterface> {
|
||||
public:
|
||||
explicit PrintNotifyProxy(const sptr<IRemoteObject> &impl);
|
||||
~PrintNotifyProxy() = default;
|
||||
void OnCallBack(MessageParcel &data) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<PrintNotifyProxy> delegator_;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
|
||||
#endif // PRINT_NOTIFY_PROXY_H
|
83
services/include/print_service_ability.h
Normal file
83
services/include/print_service_ability.h
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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_SERVICE_ABILITY_H
|
||||
#define PRINT_SERVICE_ABILITY_H
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "event_handler.h"
|
||||
#include "iremote_object.h"
|
||||
#include "system_ability.h"
|
||||
#include "print_notify_interface.h"
|
||||
#include "print_service_stub.h"
|
||||
|
||||
|
||||
namespace OHOS::Print {
|
||||
enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
|
||||
class IKeyguardStateCallback;
|
||||
|
||||
class PrintServiceAbility : public SystemAbility, public PrintServiceStub {
|
||||
DECLARE_SYSTEM_ABILITY(PrintServiceAbility);
|
||||
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(PrintServiceAbility);
|
||||
PrintServiceAbility(int32_t systemAbilityId, bool runOnCreate);
|
||||
PrintServiceAbility();
|
||||
~PrintServiceAbility();
|
||||
static sptr<PrintServiceAbility> GetInstance();
|
||||
int32_t Dummy() override;
|
||||
bool On(uint32_t taskId, const std::string &type, const sptr<PrintNotifyInterface> &listener) override;
|
||||
bool Off(uint32_t taskId, const std::string &type) override;
|
||||
bool AddPrinters(std::vector<PrintInfo> arrayPrintInfo) override;
|
||||
bool RemovePrinters(std::vector<PrintInfo> arrayPrintInfo) override;
|
||||
bool ConnectPrinter(uint32_t printerId) override;
|
||||
bool DisconnectPrinter(uint32_t printerId) override;
|
||||
bool QueryAllExtension(std::vector<PrinterExtensionInfo> &arrayExtensionInfo) override;
|
||||
bool StartDiscoverPrinter(std::vector<uint32_t> extensionList) override;
|
||||
bool StopDiscoverPrinter() override;
|
||||
bool StartPrintJob(PrintJob jobinfo) override;
|
||||
bool CancelPrintJob(PrintJob jobinfo) override;
|
||||
bool UpdatePrinterState(uint32_t printerId, uint32_t state) override;
|
||||
bool UpdatePrinterJobState(uint32_t jobId, uint32_t state) override;
|
||||
bool RequestPreview(PrintJob jobinfo, std::string &previewResult) override;
|
||||
bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability) override;
|
||||
bool CheckPermission() override;
|
||||
static void NotifyHandler(const std::string& type, uint32_t taskId, uint32_t argv1, uint32_t argv2);
|
||||
|
||||
protected:
|
||||
void OnStart() override;
|
||||
void OnStop() override;
|
||||
|
||||
private:
|
||||
int32_t Init();
|
||||
void InitServiceHandler();
|
||||
void ManualStart();
|
||||
|
||||
private:
|
||||
ServiceRunningState state_;
|
||||
static std::mutex instanceLock_;
|
||||
static sptr<PrintServiceAbility> instance_;
|
||||
static std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
|
||||
std::map<std::string, sptr<PrintNotifyInterface>> registeredListeners_;
|
||||
std::vector<sptr<PrintNotifyInterface>> unlockVecListeners_;
|
||||
std::mutex listenerMapMutex_;
|
||||
std::mutex lock_;
|
||||
const int32_t startTime_ = 1900;
|
||||
const int32_t extraMonth_ = 1;
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_SYSTEM_ABILITY_H
|
64
services/include/print_service_manager.h
Normal file
64
services/include/print_service_manager.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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_SERVICE_MANAGER_H
|
||||
#define PRINT_SERVICE_MANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <stdint.h>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include "print_extension_Info.h"
|
||||
#include "print_cap_ability.h"
|
||||
#include "print_job.h"
|
||||
#include "print_info.h"
|
||||
|
||||
#include "constant.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrintServiceManager final {
|
||||
public:
|
||||
static PrintServiceManager *GetInstance();
|
||||
int32_t Dummy();
|
||||
bool ConnectPrinter(uint32_t printerId);
|
||||
bool DisconnectPrinter(uint32_t printerId);
|
||||
bool QueryExtensionAbilityInfos(std::vector<PrinterExtensionInfo> &arrayExtensionInfo);
|
||||
bool StartDiscoverPrinter(std::vector<uint32_t> extensionList);
|
||||
bool StopDiscoverPrinter();
|
||||
bool StartPrintJob(PrintJob jobinfo);
|
||||
bool CancelPrintJob(PrintJob jobinfo);
|
||||
bool AddPrinters(std::vector<PrintInfo> arrayPrintInfo);
|
||||
bool RemovePrinters(std::vector<PrintInfo> arrayPrintInfo);
|
||||
bool UpdatePrinterState(uint32_t printerId, uint32_t state);
|
||||
bool UpdatePrinterJobState(uint32_t jobId, uint32_t state);
|
||||
bool RequestPreview(PrintJob jobinfo, std::string &previewResult);
|
||||
bool QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability);
|
||||
|
||||
private:
|
||||
explicit PrintServiceManager();
|
||||
~PrintServiceManager();
|
||||
|
||||
private:
|
||||
static std::mutex instanceLock_;
|
||||
static PrintServiceManager* instance_;
|
||||
|
||||
};
|
||||
} // namespace OHOS::Request::Print
|
||||
#endif // PRINT_SERVICE_MANAGER_H
|
51
services/include/print_service_stub.h
Normal file
51
services/include/print_service_stub.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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_SERVICE_STUB_H
|
||||
#define PRINT_SERVICE_STUB_H
|
||||
|
||||
#include "iremote_stub.h"
|
||||
#include "print_service_interface.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
class PrintServiceStub : public IRemoteStub<PrintServiceInterface> {
|
||||
public:
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
private:
|
||||
bool OnDummy(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnEventOn(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnEventOff(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnCheckPermission(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnFindPrinterExtension(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnRegisterEvent(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnQueryAllExtension(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnLoadExtension (MessageParcel &data, MessageParcel &reply);
|
||||
bool OnStartDiscoverPrinter(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnStopDiscoverPrint(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnAddPrinters(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnRemovePrinters(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnConnectPrinter(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnDisconnectPrinter(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnRequestCapability(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnStartPrintJob(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnCancelPrintJob(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnUpdatePrinterState(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnUpdatePrinterJobState(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnRequestPreview(MessageParcel &data, MessageParcel &reply);
|
||||
bool OnQueryPrinterCapability(MessageParcel &data, MessageParcel &reply);
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
#endif // PRINT_SERVICE_STUB_H
|
48
services/src/print_notify_proxy.cpp
Normal file
48
services/src/print_notify_proxy.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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_notify_proxy.h"
|
||||
#include "log.h"
|
||||
#include "message_parcel.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
PrintNotifyProxy::PrintNotifyProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<PrintNotifyInterface>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
void PrintNotifyProxy::OnCallBack(MessageParcel &data)
|
||||
{
|
||||
PRINT_HILOGD("PrintNotifyProxy::OnCallBack Start");
|
||||
PRINT_HILOGD("data should be filled within service module");
|
||||
MessageParcel realData;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!realData.WriteInterfaceToken(PrintNotifyProxy::GetDescriptor())) {
|
||||
PRINT_HILOGE("write descriptor failed");
|
||||
return;
|
||||
}
|
||||
uint32_t argv1 = data.ReadUint32();
|
||||
uint32_t argv2 = data.ReadUint32();
|
||||
PRINT_HILOGD("notification's argument:[%{public}d, %{public}d]", argv1, argv2);
|
||||
realData.WriteUint32(argv1);
|
||||
realData.WriteUint32(argv2);
|
||||
|
||||
int error = Remote()->SendRequest(PRINT_NOTIFY, realData, reply, option);
|
||||
if (error != 0) {
|
||||
PRINT_HILOGE("SendRequest failed, error %{public}d", error);
|
||||
}
|
||||
PRINT_HILOGD("PrintNotifyProxy::OnCallBack End");
|
||||
}
|
||||
} // namespace OHOS::Print
|
357
services/src/print_service_ability.cpp
Normal file
357
services/src/print_service_ability.cpp
Normal file
@ -0,0 +1,357 @@
|
||||
/*
|
||||
* 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_service_ability.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "core_service_client.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "print_service_manager.h"
|
||||
#include "print_common.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS::Print {
|
||||
using namespace std;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace Security::AccessToken;
|
||||
|
||||
static const std::string PRINT_PERMISSION_NAME_INTERNET = "ohos.permission.PRINT";
|
||||
static const std::string PRINT_PERMISSION_NAME_SESSION = "ohos.permission.PRINT_SESSION_MANAGER";
|
||||
|
||||
|
||||
REGISTER_SYSTEM_ABILITY_BY_ID(PrintServiceAbility, PRINT_SERVICE_ID, true);
|
||||
const std::int64_t INIT_INTERVAL = 5000L;
|
||||
std::mutex PrintServiceAbility::instanceLock_;
|
||||
sptr<PrintServiceAbility> PrintServiceAbility::instance_;
|
||||
std::shared_ptr<AppExecFwk::EventHandler> PrintServiceAbility::serviceHandler_;
|
||||
|
||||
PrintServiceAbility::PrintServiceAbility(int32_t systemAbilityId, bool runOnCreate)
|
||||
: SystemAbility(systemAbilityId, runOnCreate), state_(ServiceRunningState::STATE_NOT_START)
|
||||
{
|
||||
}
|
||||
|
||||
PrintServiceAbility::~PrintServiceAbility()
|
||||
{
|
||||
PRINT_HILOGE("~PrintServiceAbility state_ is %{public}d.", static_cast<int>(state_));
|
||||
}
|
||||
|
||||
sptr<PrintServiceAbility> PrintServiceAbility::GetInstance()
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
std::lock_guard<std::mutex> autoLock(instanceLock_);
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new PrintServiceAbility(PRINT_SERVICE_ID, true);
|
||||
PRINT_HILOGE("PrintServiceAbility instance_ create,addr=%{public}p", instance_.GetRefPtr());
|
||||
}
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
int32_t PrintServiceAbility::Init()
|
||||
{
|
||||
bool ret = Publish(PrintServiceAbility::GetInstance());
|
||||
if (!ret) {
|
||||
PRINT_HILOGE("PrintServiceAbility Publish failed.");
|
||||
return E_PRINT_PUBLISH_FAIL;
|
||||
}
|
||||
state_ = ServiceRunningState::STATE_RUNNING;
|
||||
uint32_t threadNum = 4;
|
||||
PRINT_HILOGI("Start Print Service Manager with %{public}d threas", threadNum);
|
||||
PRINT_HILOGE("state_ is %{public}d.", static_cast<int>(state_));
|
||||
PRINT_HILOGI("Init PrintServiceAbility success.");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void PrintServiceAbility::OnStart()
|
||||
{
|
||||
PRINT_HILOGI("PrintServiceAbility::Enter OnStart.");
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = this;
|
||||
}
|
||||
if (state_ == ServiceRunningState::STATE_RUNNING) {
|
||||
PRINT_HILOGI("PrintServiceAbility is already running.");
|
||||
return;
|
||||
}
|
||||
InitServiceHandler();
|
||||
|
||||
int32_t ret = Init();
|
||||
if (ret != ERR_OK) {
|
||||
auto callback = [=]() { Init(); };
|
||||
serviceHandler_->PostTask(callback, INIT_INTERVAL);
|
||||
PRINT_HILOGE("PrintServiceAbility Init failed. Try again 5s la00ter");
|
||||
return;
|
||||
}
|
||||
state_ = ServiceRunningState::STATE_RUNNING;
|
||||
return;
|
||||
}
|
||||
|
||||
void PrintServiceAbility::InitServiceHandler()
|
||||
{
|
||||
PRINT_HILOGI("InitServiceHandler started.");
|
||||
if (serviceHandler_ != nullptr) {
|
||||
PRINT_HILOGI("InitServiceHandler already init.");
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("PrintServiceAbility");
|
||||
serviceHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
PRINT_HILOGI("InitServiceHandler succeeded.");
|
||||
}
|
||||
|
||||
void PrintServiceAbility::ManualStart()
|
||||
{
|
||||
if (state_ != ServiceRunningState::STATE_RUNNING) {
|
||||
PRINT_HILOGI("PrintServiceAbility restart.");
|
||||
OnStart();
|
||||
}
|
||||
}
|
||||
|
||||
void PrintServiceAbility::OnStop()
|
||||
{
|
||||
PRINT_HILOGI("OnStop started.");
|
||||
if (state_ != ServiceRunningState::STATE_RUNNING) {
|
||||
return;
|
||||
}
|
||||
serviceHandler_ = nullptr;
|
||||
state_ = ServiceRunningState::STATE_NOT_START;
|
||||
PRINT_HILOGI("OnStop end.");
|
||||
}
|
||||
|
||||
int32_t PrintServiceAbility::Dummy()
|
||||
{
|
||||
ManualStart();
|
||||
int32_t taskId = -1;
|
||||
return taskId;
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::ConnectPrinter(uint32_t printerId)
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("PrintServiceAbility ConnectPrinter started.");
|
||||
return instance->ConnectPrinter(printerId);
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::DisconnectPrinter(uint32_t printerId)
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("DisconnectPrinter ConnectPrinter started.");
|
||||
return instance->DisconnectPrinter(printerId);
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::StartDiscoverPrinter(std::vector<uint32_t> extensionList)
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("StartDiscoverPrinter ConnectPrinter started.");
|
||||
return instance->StartDiscoverPrinter(extensionList);
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::StopDiscoverPrinter()
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("StopDiscoverPrinter ConnectPrinter started.");
|
||||
return instance->StopDiscoverPrinter();
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::QueryAllExtension(std::vector<PrinterExtensionInfo> &arrayExtensionInfo)
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("QueryAllExtension ConnectPrinter started.");
|
||||
return instance->QueryExtensionAbilityInfos(arrayExtensionInfo);
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::StartPrintJob(PrintJob jobinfo)
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("StartPrintJob ConnectPrinter started.");
|
||||
return instance->StartPrintJob(jobinfo);
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::CancelPrintJob(PrintJob jobinfo)
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("CancelPrintJob ConnectPrinter started.");
|
||||
return instance->CancelPrintJob(jobinfo);
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::AddPrinters(std::vector<PrintInfo> arrayPrintInfo)
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("CancelPrintJob ConnectPrinter started.");
|
||||
return instance->AddPrinters(arrayPrintInfo);
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::RemovePrinters(std::vector<PrintInfo> arrayPrintInfo)
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("CancelPrintJob ConnectPrinter started.");
|
||||
return instance->RemovePrinters(arrayPrintInfo);
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::UpdatePrinterState(uint32_t printerId, uint32_t state)
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("CancelPrintJob ConnectPrinter started.");
|
||||
return instance->UpdatePrinterState(printerId, state);
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::UpdatePrinterJobState(uint32_t jobId, uint32_t state)
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("CancelPrintJob ConnectPrinter started.");
|
||||
return instance->UpdatePrinterJobState(jobId, state);
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::RequestPreview(PrintJob jobinfo, std::string &previewResult)
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("CancelPrintJob RequestPreview started.");
|
||||
return instance->RequestPreview(jobinfo, previewResult);
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability)
|
||||
{
|
||||
ManualStart();
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGE("CancelPrintJob RequestPreview started.");
|
||||
return instance->QueryPrinterCapability(printerId, printerCapability);
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::CheckPermission()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::On(uint32_t taskId, const std::string &type, const sptr<PrintNotifyInterface> &listener)
|
||||
{
|
||||
std::string combineType = type + "-" + std::to_string(taskId);
|
||||
PRINT_HILOGI("PrintServiceAbility::On started. type=%{public}s", combineType.c_str());
|
||||
auto iter = registeredListeners_.find(combineType);
|
||||
if (iter == registeredListeners_.end()) {
|
||||
std::lock_guard<std::mutex> lck(listenerMapMutex_);
|
||||
std::pair<std::string, sptr<PrintNotifyInterface>> newObj(combineType, listener);
|
||||
const auto temp = registeredListeners_.insert(newObj);
|
||||
if (!temp.second) {
|
||||
PRINT_HILOGE("PrintServiceAbility::On insert type=%{public}s object fail.", combineType.c_str());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
std::lock_guard<std::mutex> lck(listenerMapMutex_);
|
||||
PRINT_HILOGI("PrintServiceAbility::On Replace listener.");
|
||||
registeredListeners_[combineType] = listener;
|
||||
}
|
||||
PRINT_HILOGI("PrintServiceAbility::On end.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::Off(uint32_t taskId, const std::string &type)
|
||||
{
|
||||
std::string combineType = type + "-" + std::to_string(taskId);
|
||||
PRINT_HILOGI("PrintServiceAbility::Off started.");
|
||||
auto iter = registeredListeners_.find(combineType);
|
||||
if (iter != registeredListeners_.end()) {
|
||||
PRINT_HILOGE("PrintServiceAbility::Off delete type=%{public}s object message.", combineType.c_str());
|
||||
std::lock_guard<std::mutex> lck(listenerMapMutex_);
|
||||
registeredListeners_.erase(iter);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PrintServiceAbility::NotifyHandler(const std::string& type, uint32_t taskId, uint32_t argv1, uint32_t argv2)
|
||||
{
|
||||
std::string combineType = type + "-" + std::to_string(taskId);
|
||||
PRINT_HILOGI("PrintServiceAbility::NotifyHandler started %{public}s [%{public}d, %{public}d].",
|
||||
combineType.c_str(), argv1, argv2);
|
||||
auto iter = PrintServiceAbility::GetInstance()->registeredListeners_.find(combineType);
|
||||
if (iter != PrintServiceAbility::GetInstance()->registeredListeners_.end()) {
|
||||
PRINT_HILOGE("PrintServiceAbility::NotifyHandler type=%{public}s object message.", combineType.c_str());
|
||||
MessageParcel data;
|
||||
data.WriteUint32(argv1);
|
||||
data.WriteUint32(argv2);
|
||||
iter->second->OnCallBack(data);
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Request::Print
|
188
services/src/print_service_manager.cpp
Normal file
188
services/src/print_service_manager.cpp
Normal 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_service_manager.h"
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include "unistd.h"
|
||||
#include "log.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
namespace OHOS::Print {
|
||||
std::mutex PrintServiceManager::instanceLock_;
|
||||
PrintServiceManager *PrintServiceManager::instance_ = nullptr;
|
||||
PrintServiceManager::PrintServiceManager()
|
||||
{
|
||||
}
|
||||
|
||||
PrintServiceManager::~PrintServiceManager()
|
||||
{
|
||||
}
|
||||
|
||||
PrintServiceManager *PrintServiceManager::GetInstance()
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
std::lock_guard<std::mutex> lock(instanceLock_);
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new (std::nothrow) PrintServiceManager;
|
||||
}
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
int32_t PrintServiceManager::Dummy()
|
||||
{
|
||||
int32_t taskId = -1;
|
||||
return taskId;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::ConnectPrinter(uint32_t printerId)
|
||||
{
|
||||
PRINT_HILOGE("PrintServiceManager ConnectPrinter started.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::DisconnectPrinter(uint32_t printerId)
|
||||
{
|
||||
PRINT_HILOGE("PrintServiceManager DisconnectPrinter started.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::StartDiscoverPrinter(std::vector<uint32_t> extensionList)
|
||||
{
|
||||
PRINT_HILOGE("PrintServiceManager StartDiscoverPrinter started.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::StopDiscoverPrinter()
|
||||
{
|
||||
PRINT_HILOGE("PrintServiceManager StopDiscoverPrinter started.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::QueryExtensionAbilityInfos(std::vector<PrinterExtensionInfo> &arrayExtensionInfo)
|
||||
{
|
||||
PRINT_HILOGE("PrintServiceManager QueryAllExtension enter.");
|
||||
PrinterExtensionInfo printerExtensionInfo;
|
||||
arrayExtensionInfo.push_back(printerExtensionInfo);
|
||||
arrayExtensionInfo[0].SetExtensionId(5);
|
||||
arrayExtensionInfo[0].SetVendorId(55);
|
||||
std::string vendorName = "vendorName = print 1.0";
|
||||
std::string version = "version = 1.0.0";
|
||||
arrayExtensionInfo[0].SetVendorName(vendorName);
|
||||
arrayExtensionInfo[0].SetVendorIcon(555);
|
||||
arrayExtensionInfo[0].SetVersion(version);
|
||||
PRINT_HILOGE("PrintServiceManager QueryAllExtension started.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::StartPrintJob(PrintJob jobinfo)
|
||||
{
|
||||
PRINT_HILOGE("PrintServiceManager StartPrintJob started.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::CancelPrintJob(PrintJob jobinfo)
|
||||
{
|
||||
PRINT_HILOGE("PrintServiceManager CancelPrintJob started.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::AddPrinters(std::vector<PrintInfo> arrayPrintInfo)
|
||||
{
|
||||
PRINT_HILOGE("PrintServiceManager AddPrinters started.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::RemovePrinters(std::vector<PrintInfo> arrayPrintInfo)
|
||||
{
|
||||
PRINT_HILOGE("PrintServiceManager RemovePrinters started.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::UpdatePrinterState(uint32_t printerId, uint32_t state)
|
||||
{
|
||||
PRINT_HILOGE("PrintServiceManager UpdatePrinterState started.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::UpdatePrinterJobState(uint32_t jobId, uint32_t state)
|
||||
{
|
||||
PRINT_HILOGE("PrintServiceManager UpdatePrinterJobState started.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::RequestPreview(PrintJob jobinfo, std::string &previewResult)
|
||||
{
|
||||
previewResult = "Preview OK!";
|
||||
PRINT_HILOGE("PrintServiceManager RequestPreview started.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceManager::QueryPrinterCapability(uint32_t printerId, PrinterCapability &printerCapability)
|
||||
{
|
||||
auto instance = PrintServiceManager::GetInstance();
|
||||
if (instance == nullptr) {
|
||||
PRINT_HILOGE("PrintServiceManager is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
printerCapability.SetColorMode(10);
|
||||
printerCapability.SetDuplexMode(11);
|
||||
|
||||
PrintMargin printMargin;
|
||||
printMargin.SetTop(5);
|
||||
printMargin.SetBottom(5);
|
||||
printMargin.SetLeft(5);
|
||||
printMargin.SetRight(5);
|
||||
printerCapability.SetMinMargin(printMargin);
|
||||
|
||||
PrinterPageSize printerPageSize;
|
||||
printerPageSize.SetId(6);
|
||||
printerPageSize.SetName("name");
|
||||
printerPageSize.SetWidth(6);
|
||||
printerPageSize.SetHeight(6);
|
||||
printerCapability.SetPageSize(printerPageSize);
|
||||
|
||||
PrinterResolution printerResolution;
|
||||
printerResolution.SetId(6);
|
||||
printerResolution.SetHorizontalDpi(6);
|
||||
printerResolution.SetVerticalDpi(6);
|
||||
printerCapability.SetResolution(printerResolution);
|
||||
|
||||
printerCapability.Dump();
|
||||
printerCapability.GetMinMargin().Dump();
|
||||
printerCapability.GetPageSize()[0].Dump();
|
||||
printerCapability.GetResolution()[0].Dump();
|
||||
PRINT_HILOGE("PrintServiceManager RequestPreview started.");
|
||||
return true;
|
||||
}
|
||||
} // namespace OHOS::Request::Print
|
614
services/src/print_service_stub.cpp
Normal file
614
services/src/print_service_stub.cpp
Normal file
@ -0,0 +1,614 @@
|
||||
/*
|
||||
* 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_service_stub.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "message_parcel.h"
|
||||
#include "print_extension_Info.h"
|
||||
#include "print_common.h"
|
||||
#include "print_job.h"
|
||||
#include "print_service_interface.h"
|
||||
#include "log.h"
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS::Print {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
int32_t PrintServiceStub::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_TRANSACT_ERROR;
|
||||
}
|
||||
switch (code) {
|
||||
case CMD_DUMMY:
|
||||
return OnDummy(data, reply);
|
||||
case CMD_CONNECTPRINTER:
|
||||
return OnConnectPrinter(data, reply);
|
||||
case CMD_DISCONNECTPRINTER:
|
||||
return OnDisconnectPrinter(data, reply);
|
||||
case CMD_STARTDISCOVERPRINTER:
|
||||
return OnStartDiscoverPrinter(data, reply);
|
||||
case CMD_STOPDISCOVERPRINTER:
|
||||
return OnStopDiscoverPrint(data, reply);
|
||||
case CMD_QUERYALLEXTENSION:
|
||||
return OnQueryAllExtension(data, reply);
|
||||
case CMD_STARTPRINTJOB:
|
||||
return OnStartPrintJob(data, reply);
|
||||
case CMD_CANCELPRINTJOB:
|
||||
return OnCancelPrintJob(data, reply);
|
||||
case CMD_ADDPRINTERS:
|
||||
return OnAddPrinters(data, reply);
|
||||
case CMD_REMOVEPRINTERS:
|
||||
return OnRemovePrinters(data, reply);
|
||||
case CMD_UPDATEPRINTERSTATE:
|
||||
return OnUpdatePrinterState(data, reply);
|
||||
case CMD_UPDATEPRINTERJOBSTATE:
|
||||
return OnUpdatePrinterJobState(data, reply);
|
||||
case CMD_REQUESTPREVIEW:
|
||||
return OnRequestPreview(data, reply);
|
||||
case CMD_QUERYPRINTERCAPABILITY:
|
||||
return OnQueryPrinterCapability(data, reply);
|
||||
case CMD_CHECKPERMISSION:
|
||||
return OnCheckPermission(data, reply);
|
||||
case CMD_ON:
|
||||
return OnEventOn(data, reply);
|
||||
case CMD_OFF:
|
||||
return OnEventOff(data, reply);
|
||||
default:
|
||||
PRINT_HILOGE("Default value received, check needed.");
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return E_PRINT_OK;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnDummy(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
int32_t fd = data.ReadFileDescriptor();
|
||||
PRINT_HILOGI("Get FD from client, fd [%{public}d]", fd);
|
||||
int32_t result = Dummy();
|
||||
if (!reply.WriteInt32(result)) {
|
||||
PRINT_HILOGE("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnConnectPrinter(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
bool result = ConnectPrinter(data.ReadInt32());
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnDisconnectPrinter(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
bool result = DisconnectPrinter(data.ReadInt32());
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnStartDiscoverPrinter(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
std::vector<uint32_t> extensionList;
|
||||
uint32_t extensionListLength = data.ReadUint32();
|
||||
|
||||
for(uint32_t i = 0; i < extensionListLength; i++)
|
||||
{
|
||||
extensionList.push_back(data.ReadUint32());
|
||||
PRINT_HILOGD("OnStartDiscoverPrinter = %{public}d", extensionList[i]);
|
||||
}
|
||||
|
||||
bool result = StartDiscoverPrinter(extensionList);
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnStopDiscoverPrint(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
bool result = StopDiscoverPrinter();
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnQueryAllExtension(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
std::vector<PrinterExtensionInfo> printerInfo;
|
||||
bool result = QueryAllExtension(printerInfo);
|
||||
if (result) {
|
||||
uint32_t printerInfoLegth = printerInfo.size();
|
||||
reply.WriteUint32(printerInfoLegth);
|
||||
|
||||
for(uint32_t i = 0; i < printerInfoLegth; i++)
|
||||
{
|
||||
PRINT_HILOGI("PrintServiceProxy, ExtensionId = %{public}d", printerInfo[i].GetExtensionId());
|
||||
PRINT_HILOGI("PrintServiceProxy, VendorId = %{public}d", printerInfo[i].GetVendorId());
|
||||
PRINT_HILOGI("PrintServiceProxy, VendorName = %{public}s", printerInfo[i].GetVendorName().c_str());
|
||||
PRINT_HILOGI("PrintServiceProxy, VendorIcon = %{public}d", printerInfo[i].GetVendorIcon());
|
||||
PRINT_HILOGI("PrintServiceProxy, Version = %{public}s", printerInfo[i].GetVersion().c_str());
|
||||
|
||||
reply.WriteUint32(printerInfo[i].GetExtensionId());
|
||||
reply.WriteUint32(printerInfo[i].GetVendorId());
|
||||
reply.WriteString(printerInfo[i].GetVendorName());
|
||||
reply.WriteUint32(printerInfo[i].GetVendorIcon());
|
||||
reply.WriteString(printerInfo[i].GetVersion());
|
||||
}
|
||||
}
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnStartPrintJob(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
PrintJob jobinfo;
|
||||
uint32_t fileLength = data.ReadUint32();
|
||||
for(uint32_t i = 0; i < fileLength; i++)
|
||||
{
|
||||
jobinfo.GetFiles().push_back(data.ReadString());
|
||||
|
||||
}
|
||||
jobinfo.SetJobId(data.ReadUint32());
|
||||
jobinfo.SetPrintId(data.ReadUint32());
|
||||
jobinfo.SetJobState(data.ReadUint32());
|
||||
jobinfo.SetCopyNumber(data.ReadUint32());
|
||||
|
||||
jobinfo.GetPageRange().SetStartPage(data.ReadUint32());
|
||||
jobinfo.GetPageRange().SetEndPage(data.ReadUint32());
|
||||
uint32_t pageLength = data.ReadUint32();
|
||||
for(uint32_t i = 0; i < pageLength; i++)
|
||||
{
|
||||
jobinfo.GetPageRange().SetPages(data.ReadUint32());
|
||||
}
|
||||
|
||||
jobinfo.SetIsSequential(data.ReadUint32());
|
||||
|
||||
jobinfo.GetPageSize().SetId(data.ReadUint32());
|
||||
jobinfo.GetPageSize().SetName(data.ReadString());
|
||||
jobinfo.GetPageSize().SetWidth(data.ReadUint32());
|
||||
jobinfo.GetPageSize().SetHeight(data.ReadUint32());
|
||||
|
||||
jobinfo.SetIsLandscape(data.ReadUint32());
|
||||
jobinfo.SetColorMode(data.ReadUint32());
|
||||
jobinfo.SetDuplexMode(data.ReadUint32());
|
||||
|
||||
jobinfo.GetMargin().SetTop(data.ReadUint32());
|
||||
jobinfo.GetMargin().SetBottom(data.ReadUint32());
|
||||
jobinfo.GetMargin().SetLeft(data.ReadUint32());
|
||||
jobinfo.GetMargin().SetRight(data.ReadUint32());
|
||||
|
||||
jobinfo.GetPreview().SetResult(data.ReadString());
|
||||
jobinfo.GetPreview().GetPreviewRange().SetStartPage(data.ReadUint32());
|
||||
jobinfo.GetPreview().GetPreviewRange().SetEndPage(data.ReadUint32());
|
||||
uint32_t previewPageLength = data.ReadUint32();
|
||||
|
||||
for(uint32_t i = 0; i < previewPageLength; i++)
|
||||
{
|
||||
jobinfo.GetPreview().GetPreviewRange().SetPages(data.ReadUint32());
|
||||
}
|
||||
|
||||
jobinfo.Dump();
|
||||
jobinfo.GetPageRange().Dump();
|
||||
jobinfo.GetPageSize().Dump();
|
||||
jobinfo.GetMargin().Dump();
|
||||
jobinfo.GetPreview().Dump();
|
||||
jobinfo.GetPreview().GetPreviewRange().Dump();
|
||||
|
||||
bool result = StartPrintJob(jobinfo);
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnCancelPrintJob(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
PrintJob jobinfo;
|
||||
uint32_t fileLength = data.ReadUint32();
|
||||
|
||||
for(uint32_t i = 0; i < fileLength; i++)
|
||||
{
|
||||
jobinfo.GetFiles().push_back(data.ReadString());
|
||||
}
|
||||
|
||||
jobinfo.SetJobId(data.ReadUint32());
|
||||
jobinfo.SetPrintId(data.ReadUint32());
|
||||
jobinfo.SetJobState(data.ReadUint32());
|
||||
jobinfo.SetCopyNumber(data.ReadUint32());
|
||||
jobinfo.GetPageRange().SetStartPage(data.ReadUint32());
|
||||
jobinfo.GetPageRange().SetEndPage(data.ReadUint32());
|
||||
uint32_t pageLength = data.ReadUint32();
|
||||
|
||||
for(uint32_t i = 0; i < pageLength; i++)
|
||||
{
|
||||
jobinfo.GetPageRange().SetPages(data.ReadUint32());
|
||||
}
|
||||
|
||||
jobinfo.SetIsSequential(data.ReadUint32());
|
||||
jobinfo.GetPageSize().SetId(data.ReadUint32());
|
||||
jobinfo.GetPageSize().SetName(data.ReadString());
|
||||
jobinfo.GetPageSize().SetWidth(data.ReadUint32());
|
||||
jobinfo.GetPageSize().SetHeight(data.ReadUint32());
|
||||
jobinfo.SetIsLandscape(data.ReadUint32());
|
||||
jobinfo.SetColorMode(data.ReadUint32());
|
||||
jobinfo.SetDuplexMode(data.ReadUint32());
|
||||
jobinfo.GetMargin().SetTop(data.ReadUint32());
|
||||
jobinfo.GetMargin().SetBottom(data.ReadUint32());
|
||||
jobinfo.GetMargin().SetLeft(data.ReadUint32());
|
||||
jobinfo.GetMargin().SetRight(data.ReadUint32());
|
||||
jobinfo.GetPreview().SetResult(data.ReadString());
|
||||
jobinfo.GetPreview().GetPreviewRange().SetStartPage(data.ReadUint32());
|
||||
jobinfo.GetPreview().GetPreviewRange().SetEndPage(data.ReadUint32());
|
||||
uint32_t previewPageLength = data.ReadUint32();
|
||||
|
||||
for(uint32_t i = 0; i < previewPageLength; i++)
|
||||
{
|
||||
jobinfo.GetPreview().GetPreviewRange().SetPages(data.ReadUint32());
|
||||
}
|
||||
|
||||
jobinfo.Dump();
|
||||
jobinfo.GetPageRange().Dump();
|
||||
jobinfo.GetPageSize().Dump();
|
||||
jobinfo.GetMargin().Dump();
|
||||
jobinfo.GetPreview().Dump();
|
||||
jobinfo.GetPreview().GetPreviewRange().Dump();
|
||||
bool result = CancelPrintJob(jobinfo);
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnAddPrinters(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
std::vector<PrintInfo> arrayPrintInfo;
|
||||
uint32_t arrayPrintInfoLength = data.ReadUint32();
|
||||
PRINT_HILOGD("OnStartDiscoverPrinter arrayPrintInfoLength = %{public}d", arrayPrintInfoLength);
|
||||
|
||||
for(uint32_t i = 0; i < arrayPrintInfoLength; i++)
|
||||
{
|
||||
PrintInfo printInfo;
|
||||
printInfo.SetPrinterId(data.ReadUint32());
|
||||
printInfo.SetPrinterName(data.ReadString());
|
||||
printInfo.SetPrinterIcon(data.ReadUint32());
|
||||
printInfo.SetPrinterState(data.ReadUint32());
|
||||
printInfo.SetDescription(data.ReadString());
|
||||
uint32_t pageSizeLength = data.ReadUint32();
|
||||
uint32_t resolutionLength = data.ReadUint32();
|
||||
PRINT_HILOGI("OnStartDiscoverPrinter pageSizeLength = %{public}d", pageSizeLength);
|
||||
PRINT_HILOGI("OnStartDiscoverPrinter resolutionLength = %{public}d", resolutionLength);
|
||||
printInfo.GetCapability().GetMinMargin().SetTop(data.ReadUint32());
|
||||
printInfo.GetCapability().GetMinMargin().SetBottom(data.ReadUint32());
|
||||
printInfo.GetCapability().GetMinMargin().SetLeft(data.ReadUint32());
|
||||
printInfo.GetCapability().GetMinMargin().SetRight(data.ReadUint32());
|
||||
|
||||
for(uint32_t i = 0; i < pageSizeLength; i++)
|
||||
{
|
||||
PrinterPageSize printerPageSize;
|
||||
printerPageSize.SetId(data.ReadUint32());
|
||||
printerPageSize.SetName(data.ReadString());
|
||||
printerPageSize.SetWidth(data.ReadUint32());
|
||||
printerPageSize.SetHeight(data.ReadUint32());
|
||||
printInfo.GetCapability().GetPageSize().push_back(printerPageSize);
|
||||
printerPageSize.Dump();
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < resolutionLength; i++)
|
||||
{
|
||||
PrinterResolution printerResolution;
|
||||
printerResolution.SetId(data.ReadUint32());
|
||||
printerResolution.SetHorizontalDpi(data.ReadUint32());
|
||||
printerResolution.SetVerticalDpi(data.ReadUint32());
|
||||
printInfo.GetCapability().GetResolution().push_back(printerResolution);
|
||||
printerResolution.Dump();
|
||||
}
|
||||
|
||||
printInfo.GetCapability().SetColorMode(data.ReadUint32());
|
||||
printInfo.GetCapability().SetDuplexMode(data.ReadUint32());
|
||||
arrayPrintInfo.push_back(printInfo);
|
||||
arrayPrintInfo[i].Dump();
|
||||
arrayPrintInfo[i].GetCapability().GetMinMargin().Dump();
|
||||
}
|
||||
|
||||
bool result = AddPrinters(arrayPrintInfo);
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnRemovePrinters(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
std::vector<PrintInfo> arrayPrintInfo;
|
||||
uint32_t arrayPrintInfoLength = data.ReadUint32();
|
||||
PRINT_HILOGD("OnStartDiscoverPrinter arrayPrintInfoLength = %{public}d", arrayPrintInfoLength);
|
||||
|
||||
for(uint32_t i = 0; i < arrayPrintInfoLength; i++)
|
||||
{
|
||||
PrintInfo printInfo;
|
||||
printInfo.SetPrinterId(data.ReadUint32());
|
||||
printInfo.SetPrinterName(data.ReadString());
|
||||
printInfo.SetPrinterIcon(data.ReadUint32());
|
||||
printInfo.SetPrinterState(data.ReadUint32());
|
||||
printInfo.SetDescription(data.ReadString());
|
||||
uint32_t pageSizeLength = data.ReadUint32();
|
||||
uint32_t resolutionLength = data.ReadUint32();
|
||||
PRINT_HILOGI("OnStartDiscoverPrinter pageSizeLength = %{public}d", pageSizeLength);
|
||||
PRINT_HILOGI("OnStartDiscoverPrinter resolutionLength = %{public}d", resolutionLength);
|
||||
printInfo.GetCapability().GetMinMargin().SetTop(data.ReadUint32());
|
||||
printInfo.GetCapability().GetMinMargin().SetBottom(data.ReadUint32());
|
||||
printInfo.GetCapability().GetMinMargin().SetLeft(data.ReadUint32());
|
||||
printInfo.GetCapability().GetMinMargin().SetRight(data.ReadUint32());
|
||||
|
||||
for(uint32_t i = 0; i < pageSizeLength; i++)
|
||||
{
|
||||
PrinterPageSize printerPageSize;
|
||||
printerPageSize.SetId(data.ReadUint32());
|
||||
printerPageSize.SetName(data.ReadString());
|
||||
printerPageSize.SetWidth(data.ReadUint32());
|
||||
printerPageSize.SetHeight(data.ReadUint32());
|
||||
printInfo.GetCapability().GetPageSize().push_back(printerPageSize);
|
||||
|
||||
printerPageSize.Dump();
|
||||
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < resolutionLength; i++)
|
||||
{
|
||||
PrinterResolution printerResolution;
|
||||
printerResolution.SetId(data.ReadUint32());
|
||||
printerResolution.SetHorizontalDpi(data.ReadUint32());
|
||||
printerResolution.SetVerticalDpi(data.ReadUint32());
|
||||
printInfo.GetCapability().GetResolution().push_back(printerResolution);
|
||||
printerResolution.Dump();
|
||||
}
|
||||
|
||||
printInfo.GetCapability().SetColorMode(data.ReadUint32());
|
||||
printInfo.GetCapability().SetDuplexMode(data.ReadUint32());
|
||||
arrayPrintInfo.push_back(printInfo);
|
||||
arrayPrintInfo[i].Dump();
|
||||
arrayPrintInfo[i].GetCapability().GetMinMargin().Dump();
|
||||
}
|
||||
|
||||
bool result = RemovePrinters(arrayPrintInfo);
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnUpdatePrinterState(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
uint32_t printerId = data.ReadUint32();
|
||||
uint32_t state = data.ReadUint32();
|
||||
PRINT_HILOGD("OnStartDiscoverPrinter printerId = %{public}d", printerId);
|
||||
PRINT_HILOGD("OnStartDiscoverPrinter state = %{public}d", state);
|
||||
bool result = UpdatePrinterState(printerId, state);
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnUpdatePrinterJobState(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
uint32_t jobId = data.ReadUint32();
|
||||
uint32_t state = data.ReadUint32();
|
||||
PRINT_HILOGD("OnStartDiscoverPrinter printerId = %{public}d", jobId);
|
||||
PRINT_HILOGD("OnStartDiscoverPrinter state = %{public}d", state);
|
||||
bool result = UpdatePrinterJobState(jobId, state);
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnRequestPreview(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
PrintJob jobinfo;
|
||||
uint32_t fileLength = data.ReadUint32();
|
||||
|
||||
for(uint32_t i = 0; i < fileLength; i++)
|
||||
{
|
||||
jobinfo.GetFiles().push_back(data.ReadString());
|
||||
|
||||
}
|
||||
|
||||
jobinfo.SetJobId(data.ReadUint32());
|
||||
jobinfo.SetPrintId(data.ReadUint32());
|
||||
jobinfo.SetJobState(data.ReadUint32());
|
||||
jobinfo.SetCopyNumber(data.ReadUint32());
|
||||
jobinfo.GetPageRange().SetStartPage(data.ReadUint32());
|
||||
jobinfo.GetPageRange().SetEndPage(data.ReadUint32());
|
||||
uint32_t pageLength = data.ReadUint32();
|
||||
|
||||
for(uint32_t i = 0; i < pageLength; i++)
|
||||
{
|
||||
jobinfo.GetPageRange().SetPages(data.ReadUint32());
|
||||
}
|
||||
|
||||
jobinfo.SetIsSequential(data.ReadUint32());
|
||||
jobinfo.GetPageSize().SetId(data.ReadUint32());
|
||||
jobinfo.GetPageSize().SetName(data.ReadString());
|
||||
jobinfo.GetPageSize().SetWidth(data.ReadUint32());
|
||||
jobinfo.GetPageSize().SetHeight(data.ReadUint32());
|
||||
jobinfo.SetIsLandscape(data.ReadUint32());
|
||||
jobinfo.SetColorMode(data.ReadUint32());
|
||||
jobinfo.SetDuplexMode(data.ReadUint32());
|
||||
jobinfo.GetMargin().SetTop(data.ReadUint32());
|
||||
jobinfo.GetMargin().SetBottom(data.ReadUint32());
|
||||
jobinfo.GetMargin().SetLeft(data.ReadUint32());
|
||||
jobinfo.GetMargin().SetRight(data.ReadUint32());
|
||||
jobinfo.GetPreview().SetResult(data.ReadString());
|
||||
jobinfo.GetPreview().GetPreviewRange().SetStartPage(data.ReadUint32());
|
||||
jobinfo.GetPreview().GetPreviewRange().SetEndPage(data.ReadUint32());
|
||||
uint32_t previewPageLength = data.ReadUint32();
|
||||
|
||||
for(uint32_t i = 0; i < previewPageLength; i++)
|
||||
{
|
||||
jobinfo.GetPreview().GetPreviewRange().SetPages(data.ReadUint32());
|
||||
}
|
||||
|
||||
jobinfo.Dump();
|
||||
jobinfo.GetPageRange().Dump();
|
||||
jobinfo.GetPageSize().Dump();
|
||||
jobinfo.GetMargin().Dump();
|
||||
jobinfo.GetPreview().Dump();
|
||||
jobinfo.GetPreview().GetPreviewRange().Dump();
|
||||
std::string previewResult = "";
|
||||
bool result = RequestPreview(jobinfo, previewResult);
|
||||
reply.WriteString(previewResult);
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnQueryPrinterCapability(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("Receive request");
|
||||
PrinterCapability printerCapability;
|
||||
bool result = QueryPrinterCapability(data.ReadUint32(), printerCapability);
|
||||
printerCapability.Dump();
|
||||
printerCapability.GetMinMargin().Dump();
|
||||
printerCapability.GetPageSize()[0].Dump();
|
||||
printerCapability.GetResolution()[0].Dump();
|
||||
uint32_t arraypageSizeLength = printerCapability.GetPageSize().size();
|
||||
reply.WriteUint32(arraypageSizeLength);
|
||||
uint32_t resolutionLength = printerCapability.GetResolution().size();
|
||||
reply.WriteUint32(resolutionLength);
|
||||
reply.WriteUint32(printerCapability.GetMinMargin().GetTop());
|
||||
reply.WriteUint32(printerCapability.GetMinMargin().GetBottom());
|
||||
reply.WriteUint32(printerCapability.GetMinMargin().GetLeft());
|
||||
reply.WriteUint32(printerCapability.GetMinMargin().GetRight());
|
||||
|
||||
for(uint32_t i = 0; i < arraypageSizeLength; i++)
|
||||
{
|
||||
reply.WriteUint32(printerCapability.GetPageSize()[i].GetId());
|
||||
reply.WriteString(printerCapability.GetPageSize()[i].GetName());
|
||||
reply.WriteUint32(printerCapability.GetPageSize()[i].GetWidth());
|
||||
reply.WriteUint32(printerCapability.GetPageSize()[i].GetHeight());
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < resolutionLength; i++)
|
||||
{
|
||||
reply.WriteUint32(printerCapability.GetResolution()[i].GetId());
|
||||
reply.WriteUint32(printerCapability.GetResolution()[i].GetHorizontalDpi());
|
||||
reply.WriteUint32(printerCapability.GetResolution()[i].GetVerticalDpi());
|
||||
}
|
||||
|
||||
reply.WriteUint32(printerCapability.GetColorMode());
|
||||
reply.WriteUint32(printerCapability.GetDuplexMode());
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("WriteBool failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnCheckPermission(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("PrintServiceStub::OnCheckPermission in");
|
||||
|
||||
bool result = CheckPermission();
|
||||
if (!reply.WriteBool(result)) {
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceStub::OnCheckPermission out");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnEventOn(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
uint32_t taskId = data.ReadUint32();
|
||||
std::string type = data.ReadString();
|
||||
PRINT_HILOGD("PrintServiceStub::OnEventOn taskId = %{public}d type=%{public}s ", taskId, type.c_str());
|
||||
if (type.empty()) {
|
||||
PRINT_HILOGE("PrintServiceStub::OnEventOn type is null.");
|
||||
return false;
|
||||
}
|
||||
sptr<IRemoteObject> remote = data.ReadRemoteObject();
|
||||
if (remote == nullptr) {
|
||||
PRINT_HILOGD("PrintServiceStub::OnEventOn remote is nullptr");
|
||||
if (!reply.WriteInt32(ERR_NONE)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
sptr<PrintNotifyInterface> listener = iface_cast<PrintNotifyInterface>(remote);
|
||||
if (listener.GetRefPtr() == nullptr) {
|
||||
PRINT_HILOGD("PrintServiceStub::OnEventOn listener is null");
|
||||
return false;
|
||||
}
|
||||
bool result = On(taskId, type, listener);
|
||||
if (!reply.WriteBool(result)) {
|
||||
PRINT_HILOGD("PrintServiceStub::OnEventOn 4444");
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceStub::OnEventOn out");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintServiceStub::OnEventOff(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
PRINT_HILOGD("PrintServiceStub::OnEventOff in");
|
||||
uint32_t taskId = data.ReadUint32();
|
||||
std::string type = data.ReadString();
|
||||
PRINT_HILOGD("PrintServiceStub::OnEventOff taskId = %{public}d type=%{public}s ", taskId, type.c_str());
|
||||
bool result = Off(taskId, type);
|
||||
if (!reply.WriteBool(result)) {
|
||||
return false;
|
||||
}
|
||||
PRINT_HILOGD("PrintServiceStub::OnEventOff out");
|
||||
return true;
|
||||
}
|
||||
} // namespace OHOS::Print
|
31
utils/BUILD.gn
Normal file
31
utils/BUILD.gn
Normal file
@ -0,0 +1,31 @@
|
||||
# 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
ohos_shared_library("wallpaper_utils") {
|
||||
sources = [ "src/file_deal.cpp" ]
|
||||
include_dirs = [ "include" ]
|
||||
deps = [
|
||||
"//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
subsystem_name = "miscservices"
|
||||
part_name = "wallpaper_native"
|
||||
}
|
98
utils/include/constant.h
Normal file
98
utils/include/constant.h
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2021-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 CONSTANT_H
|
||||
#define CONSTANT_H
|
||||
|
||||
namespace OHOS::Print {
|
||||
enum NetworkType {
|
||||
NETWORK_INVALID = 0x00000000,
|
||||
NETWORK_MOBILE = 0x00000001,
|
||||
NETWORK_WIFI = 0x00010000,
|
||||
NETWORK_MASK = 0x00010001,
|
||||
};
|
||||
|
||||
enum ErrorCode {
|
||||
ERROR_CANNOT_RESUME,
|
||||
ERROR_DEVICE_NOT_FOUND,
|
||||
ERROR_FILE_ALREADY_EXISTS,
|
||||
ERROR_FILE_ERROR,
|
||||
ERROR_HTTP_DATA_ERROR,
|
||||
ERROR_INSUFFICIENT_SPACE,
|
||||
ERROR_TOO_MANY_REDIRECTS,
|
||||
ERROR_UNHANDLED_HTTP_CODE,
|
||||
ERROR_UNKNOWN,
|
||||
ERROR_NETWORK_FAIL,
|
||||
};
|
||||
|
||||
enum PausedReason {
|
||||
PAUSED_QUEUED_FOR_WIFI,
|
||||
PAUSED_WAITING_FOR_NETWORK,
|
||||
PAUSED_WAITING_TO_RETRY,
|
||||
PAUSED_BY_USER,
|
||||
PAUSED_UNKNOWN,
|
||||
};
|
||||
|
||||
enum PRINTStatus {
|
||||
SESSION_SUCCESS,
|
||||
SESSION_RUNNING,
|
||||
SESSION_PENDING,
|
||||
SESSION_PAUSED,
|
||||
SESSION_FAILED,
|
||||
SESSION_UNKNOWN,
|
||||
};
|
||||
|
||||
enum HttpErrorCode {
|
||||
HTTP_OK = 200,
|
||||
HTTP_PARIAL_FILE = 206,
|
||||
};
|
||||
|
||||
const uint32_t DEFAULT_READ_TIMEOUT = 60;
|
||||
const uint32_t DEFAULT_CONNECT_TIMEOUT = 60;
|
||||
const uint32_t HTTP_FORCE_STOP = 1;
|
||||
const uint32_t DEFAULT_LOW_SPEED_LIMIT = 30;
|
||||
|
||||
static constexpr const char *HTTP_METHOD_GET = "GET";
|
||||
static constexpr const char *HTTP_URL_PARAM_START = "?";
|
||||
static constexpr const char *HTTP_URL_PARAM_SEPARATOR = "&";
|
||||
static constexpr const char *HTTP_URL_NAME_VALUE_SEPARATOR = "=";
|
||||
static constexpr const char *HTTP_HEADER_SEPARATOR = ":";
|
||||
static constexpr const char *HTTP_LINE_SEPARATOR = "\r\n";
|
||||
|
||||
static constexpr const char *HTTP_DEFAULT_USER_AGENT = "libcurl-agent/1.0";
|
||||
static constexpr const char *HTTP_DEFAULT_CA_PATH = "/etc/ssl/certs/cacert.pem";
|
||||
|
||||
static constexpr const char *HTTP_CONTENT_TYPE = "content-type";
|
||||
static constexpr const char *HTTP_CONTENT_TYPE_TEXT = "text/plain";
|
||||
static constexpr const char *HTTP_CONTENT_TYPE_URL_ENCODE = "application/x-www-form-urlencoded";
|
||||
static constexpr const char *HTTP_CONTENT_TYPE_JSON = "application/json";
|
||||
|
||||
static constexpr int RDB_EXECUTE_OK = 0;
|
||||
static constexpr int RDB_EXECUTE_FAIL = -1;
|
||||
static constexpr int OPERATION_OK = 0;
|
||||
static constexpr int OPERATION_ERROR = -1;
|
||||
|
||||
static constexpr int RDB_OBJECT_EMPTY = -1;
|
||||
static constexpr int PARAMETER_EMPTY = -1;
|
||||
|
||||
static constexpr int TRANSACTION_COUNT = 100;
|
||||
|
||||
|
||||
constexpr int PRINT_INFO = 10000;
|
||||
|
||||
constexpr int REQUEST_PARAMS_NUM = 2;
|
||||
} // namespace OHOS::Print
|
||||
|
||||
#endif // CONSTANT_H
|
78
utils/include/log.h
Normal file
78
utils/include/log.h
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2021-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_LOG
|
||||
#define PRINT_LOG
|
||||
|
||||
#define CONFIG_PRINT_LOG
|
||||
#ifdef CONFIG_PRINT_LOG
|
||||
#include "hilog/log.h"
|
||||
|
||||
#ifdef PRINT_HILOGF
|
||||
#undef PRINT_HILOGF
|
||||
#endif
|
||||
|
||||
#ifdef PRINT_HILOGE
|
||||
#undef PRINT_HILOGE
|
||||
#endif
|
||||
|
||||
#ifdef PRINT_HILOGW
|
||||
#undef PRINT_HILOGW
|
||||
#endif
|
||||
|
||||
#ifdef PRINT_HILOGD
|
||||
#undef PRINT_HILOGD
|
||||
#endif
|
||||
|
||||
#ifdef PRINT_HILOGI
|
||||
#undef PRINT_HILOGI
|
||||
#endif
|
||||
|
||||
#define PRINT_LOG_TAG "printkit"
|
||||
#define PRINT_LOG_DOMAIN 0xD001C00
|
||||
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 PRINT_HILOGF(fmt, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Fatal(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, \
|
||||
MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
#define PRINT_HILOGE(fmt, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Error(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, \
|
||||
MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
#define PRINT_HILOGW(fmt, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Warn(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, \
|
||||
MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
#define PRINT_HILOGD(fmt, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Debug(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, \
|
||||
MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
#define PRINT_HILOGI(fmt, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Info(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt, \
|
||||
MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
#define PRINT_HILOGF(fmt, ...)
|
||||
#define PRINT_HILOGE(fmt, ...)
|
||||
#define PRINT_HILOGW(fmt, ...)
|
||||
#define PRINT_HILOGD(fmt, ...)
|
||||
#define PRINT_HILOGI(fmt, ...)
|
||||
#endif // CONFIG_PRINT_LOG
|
||||
|
||||
#endif /* PRINT_LOG */
|
35
utils/include/print_common.h
Normal file
35
utils/include/print_common.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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_COMMON_H
|
||||
#define PRINT_COMMON_H
|
||||
|
||||
namespace OHOS::Print {
|
||||
enum PrintError {
|
||||
E_PRINT_OK,
|
||||
E_PRINT_SA_DIED,
|
||||
E_PRINT_READ_PARCEL_ERROR,
|
||||
E_PRINT_WRITE_PARCEL_ERROR,
|
||||
E_PRINT_PUBLISH_FAIL,
|
||||
E_PRINT_TRANSACT_ERROR,
|
||||
E_PRINT_DEAL_FAILED,
|
||||
E_PRINT_PARAMETERS_INVALID,
|
||||
E_PRINT_SET_RTC_FAILED,
|
||||
E_PRINT_NOT_FOUND,
|
||||
E_PRINT_NO_PERMISSION,
|
||||
};
|
||||
} // namespace OHOS::Print
|
||||
|
||||
#endif // PRINT_COMMON_H
|
Loading…
Reference in New Issue
Block a user