• 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 
29 class NativeReference;
30 
31 namespace OHOS {
32 namespace Notification {
33 /**
34  * @class JSPushCallBack
35  */
36 class JSPushCallBack : public PushCallBackStub {
37 public:
38     JSPushCallBack(napi_env env);
39     virtual ~JSPushCallBack();
40     int32_t OnCheckNotification(
41         const std::string &notificationData, const std::shared_ptr<PushCallBackParam> &pushCallBackParam) override;
42     void SetJsPushCallBackObject(NotificationConstant::SlotType slotType, napi_value pushCallBackObject);
43     bool IsEqualPushCallBackObject(napi_value pushCallBackObject);
44     void HandleCheckPromise(
45         napi_value funcResult, const std::shared_ptr<PushCallBackParam> &pushCallBackParam);
46     static napi_value CheckPromiseCallback(napi_env env, napi_callback_info info);
47 
48 private:
49     static int32_t ConvertFunctionResult(napi_env env, napi_value funcResult);
50     void SetJsPropertyString(std::string key, std::string value, napi_value& jsResult);
51     void SetJsPropertyInt32(std::string key, int32_t value, napi_value& jsResult);
52     void SetJsPropertyWantParams(std::string key, std::shared_ptr<AAFwk::WantParams> wantParams, napi_value& jsResult);
53     napi_env env_ = nullptr;
54     napi_ref pushCallBackObject_ = nullptr;
55     std::map<NotificationConstant::SlotType, napi_ref> pushCallBackObjects_;
56     std::mutex mutexlock;
57 };
58 } // namespace Notification
59 } // namespace OHOS
60 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PUSH_CALLBACK_H
61