• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef NAPI_PRINT_TASK_H
17 #define NAPI_PRINT_TASK_H
18 
19 #include <string>
20 #include "ability.h"
21 #include "ability_context.h"
22 #include "napi/native_api.h"
23 #include "napi/native_common.h"
24 
25 namespace OHOS::Print {
26 struct PrintTaskContext : public PrintAsyncCall::Context {
27     napi_ref ref = nullptr;
PrintTaskContextPrintTaskContext28     PrintTaskContext() : Context(nullptr, nullptr) {}
PrintTaskContextPrintTaskContext29     PrintTaskContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) {};
~PrintTaskContextPrintTaskContext30     virtual ~PrintTaskContext() {}
31 };
32 class NapiPrintTask {
33 public:
34     static napi_value Print(napi_env env, napi_callback_info info);
35 
36 private:
37     static napi_value GetCtor(napi_env env);
38     static napi_value Initialize(napi_env env, napi_callback_info info);
39     static bool IsValidFile(const std::string &fileName);
40     static napi_value GetAbilityContext(
41         napi_env env, napi_value value, std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> &abilityContext);
42     static napi_value WrapVoidToJS(napi_env env);
43     static napi_status VerifyParameters(napi_env env, size_t argc, napi_value *argv,
44         const std::shared_ptr<PrintTaskContext> context);
45 
46 private:
47     static __thread napi_ref globalCtor;
48 };
49 }  // namespace OHOS::Print
50 #endif  // _NAPI_PRINT_TASK_H
51