• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_STUB_H
17 #define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_STUB_H
18 
19 #include "ans_subscriber_interface.h"
20 #include "distributed_notification_service_ipc_interface_code.h"
21 #include "iremote_stub.h"
22 
23 namespace OHOS {
24 namespace Notification {
25 class AnsSubscriberStub : public IRemoteStub<AnsSubscriberInterface> {
26 public:
27     AnsSubscriberStub();
28     ~AnsSubscriberStub() override;
29     DISALLOW_COPY_AND_MOVE(AnsSubscriberStub);
30 
31     /**
32      * @brief Handle remote request.
33      *
34      * @param data Indicates the input parcel.
35      * @param reply Indicates the output parcel.
36      * @param option Indicates the message option.
37      * @return Returns ERR_OK on success, others on failure.
38      */
39     virtual int32_t OnRemoteRequest(
40         uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
41 
42     /**
43      * @brief The callback function for the subscriber to establish a connection.
44      */
45     void OnConnected() override;
46 
47     /**
48      * @brief The callback function for subscriber disconnected.
49      */
50     void OnDisconnected() override;
51 
52     /**
53      * @brief The callback function on a notification published.
54      *
55      * @param notification Indicates the consumed notification.
56      * @param notificationMap Indicates the NotificationSortingMap object.
57      */
58     void OnConsumed(
59         const sptr<Notification> &notification, const sptr<NotificationSortingMap> &notificationMap) override;
60 
61     /**
62      * @brief The callback function on a notification canceled.
63      *
64      * @param notification Indicates the canceled notification.
65      * @param notificationMap Indicates the NotificationSortingMap object.
66      * @param deleteReason Indicates the delete reason.
67      */
68     void OnCanceled(const sptr<Notification> &notification, const sptr<NotificationSortingMap> &notificationMap,
69         int32_t deleteReason) override;
70 
71     void OnCanceledList(const std::vector<sptr<Notification>> &notifications,
72         const sptr<NotificationSortingMap> &notificationMap, int32_t deleteReason) override;
73 
74     /**
75      * @brief The callback function on the notifications updated.
76      *
77      * @param notificationMap Indicates the NotificationSortingMap object.
78      */
79     void OnUpdated(const sptr<NotificationSortingMap> &notificationMap) override;
80 
81     /**
82      * @brief The callback function on the do not disturb date changed.
83      *
84      * @param date Indicates the NotificationDoNotDisturbDate object.
85      */
86     void OnDoNotDisturbDateChange(const sptr<NotificationDoNotDisturbDate> &date) override;
87 
88     /**
89      * @brief The callback function on the notification enabled flag changed.
90      *
91      * @param callbackData Indicates the EnabledNotificationCallbackData object.
92      */
93     void OnEnabledNotificationChanged(const sptr<EnabledNotificationCallbackData> &callbackData) override;
94 
95     /**
96      * @brief The callback function on the badge number changed.
97      *
98      * @param badgeData Indicates the BadgeNumberCallbackData object.
99      */
100     void OnBadgeChanged(const sptr<BadgeNumberCallbackData> &badgeData) override;
101 
102 private:
103     std::map<NotificationInterfaceCode, std::function<ErrCode(MessageParcel &, MessageParcel &)>> interfaces_;
104 
105     ErrCode HandleOnConnected(MessageParcel &data, MessageParcel &reply);
106     ErrCode HandleOnDisconnected(MessageParcel &data, MessageParcel &reply);
107     ErrCode HandleOnConsumedMap(MessageParcel &data, MessageParcel &reply);
108     ErrCode HandleOnCanceledMap(MessageParcel &data, MessageParcel &reply);
109     ErrCode HandleOnCanceledListMap(MessageParcel &data, MessageParcel &reply);
110     ErrCode HandleOnUpdated(MessageParcel &data, MessageParcel &reply);
111     ErrCode HandleOnDoNotDisturbDateChange(MessageParcel &data, MessageParcel &reply);
112     ErrCode HandleOnEnabledNotificationChanged(MessageParcel &data, MessageParcel &reply);
113     ErrCode HandleOnBadgeChanged(MessageParcel &data, MessageParcel &reply);
114     template<typename T>
115     bool ReadParcelableVector(std::vector<sptr<T>> &parcelableInfos, MessageParcel &data);
116 };
117 }  // namespace Notification
118 }  // namespace OHOS
119 
120 #endif  // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_STUB_H
121