• 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 PRINT_CALLBACK_H
17 #define PRINT_CALLBACK_H
18 
19 #include <mutex>
20 #include <uv.h>
21 #include <functional>
22 #include "napi/native_api.h"
23 #include "print_callback_stub.h"
24 #include "print_log.h"
25 
26 namespace OHOS::Print {
27 struct CallbackParam {
28     napi_env env;
29     napi_ref ref;
30     std::mutex* mutexPtr;
31     uint32_t state;
32     PrinterInfo printerInfo;
33     PrintJob jobInfo;
34 
35     std::string extensionId;
36     std::string info;
37 };
38 
39 class PrintCallback : public PrintCallbackStub {
40 public:
41     PrintCallback(napi_env env, napi_ref ref);
42     virtual ~PrintCallback();
43     bool OnCallback() override;
44     bool OnCallback(uint32_t state, const PrinterInfo &info) override;
45     bool OnCallback(uint32_t state, const PrintJob &info) override;
46     bool OnCallback(const std::string &extensionId, const std::string &info) override;
47 
48 private:
49     bool onBaseCallback(std::function<void(CallbackParam*)> paramFun, uv_after_work_cb after_work_cb);
50 
51 private:
52     napi_env env_;
53     napi_ref ref_;
54     std::mutex mutex_;
55 };
56 }  // namespace OHOS::Print
57 #endif  // IPRINT_CALLBACK_H
58