• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PUSH_CALLBACK_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PUSH_CALLBACK_H
18 
19 #include <chrono>
20 #include <iremote_object.h>
21 
22 #include "native_engine/native_engine.h"
23 #include "native_engine/native_value.h"
24 #include "parcel.h"
25 #include "push_callback_stub.h"
26 #include "want.h"
27 #include "notification_constant.h"
28 #include "ffrt.h"
29 
30 class NativeReference;
31 
32 namespace OHOS {
33 namespace Notification {
34 /**
35  * @class JSPushCallBack
36  */
37 class JSPushCallBack : public PushCallBackStub {
38 public:
39     JSPushCallBack(napi_env env);
40     virtual ~JSPushCallBack();
41     int32_t OnCheckNotification(
42         const std::string &notificationData, const std::shared_ptr<PushCallBackParam> &pushCallBackParam) override;
43     void SetJsPushCallBackObject(NotificationConstant::SlotType slotType, napi_value pushCallBackObject);
44     bool IsEqualPushCallBackObject(napi_value pushCallBackObject);
45     void HandleCheckPromise(
46         napi_value funcResult, const std::shared_ptr<PushCallBackParam> &pushCallBackParam);
47     static napi_value CheckPromiseCallback(napi_env env, napi_callback_info info);
48 
49 private:
50     static int32_t ConvertFunctionResult(napi_env env, napi_value funcResult);
51     void SetJsPropertyString(std::string key, std::string value, napi_value& jsResult);
52     void SetJsPropertyInt32(std::string key, int32_t value, napi_value& jsResult);
53     void SetJsPropertyWantParams(std::string key, std::shared_ptr<AAFwk::WantParams> wantParams, napi_value& jsResult);
54     napi_env env_ = nullptr;
55     napi_ref pushCallBackObject_ = nullptr;
56     std::map<NotificationConstant::SlotType, napi_ref> pushCallBackObjects_;
57     ffrt::mutex mutexlock;
58 };
59 } // namespace Notification
60 } // namespace OHOS
61 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PUSH_CALLBACK_H
62