• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_PUSH_CALLBACK_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_PUSH_CALLBACK_H
18 #include <mutex>
19 #include <map>
20 #include "ani.h"
21 #include "push_callback_stub.h"
22 #include "notification_constant.h"
23 
24 namespace OHOS {
25 namespace NotificationManagerSts {
26 using namespace OHOS::Notification;
27 class StsPushCallBack : public PushCallBackStub {
28 public:
29     struct ResultParam {
30         int32_t code = -1;
31         std::string msg = "";
32     };
33 
34     StsPushCallBack(ani_env *env);
35     virtual ~StsPushCallBack();
36     int32_t OnCheckNotification(
37         const std::string &notificationData, const std::shared_ptr<PushCallBackParam> &pushCallBackParam) override;
38     void SetJsPushCallBackObject(ani_env *env, NotificationConstant::SlotType slotType, ani_ref pushCallBackObject);
39     void HandleCheckCallback(
40         ani_env *env, ani_fn_object fn, ani_object value, const std::shared_ptr<PushCallBackParam> &pushCallBackParam);
41 
42 private:
43     int32_t CheckNotification(
44         ani_env *env,
45         const std::string &notificationData,
46         const std::shared_ptr<PushCallBackParam> &pushCallBackParam);
47     static bool WarpFunctionResult(ani_env *env, ani_object funcResult, ResultParam &result);
48     ani_vm *vm_ = nullptr;
49     std::map<NotificationConstant::SlotType, ani_ref> pushCallBackObjects_;
50     std::mutex mutexlock;
51 };
52 
53 } // namespace NotificationManagerSts
54 } // namespace OHOS
55 #endif
56 
57