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 BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_PROXY_H
17 #define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_PROXY_H
18 
19 #include "ans_subscriber_local_live_view_interface.h"
20 #include "distributed_notification_service_ipc_interface_code.h"
21 #include "iremote_proxy.h"
22 
23 namespace OHOS {
24 namespace Notification {
25 class AnsSubscriberLocalLiveViewProxy : public IRemoteProxy<AnsSubscriberLocalLiveViewInterface> {
26 public:
27     AnsSubscriberLocalLiveViewProxy() = delete;
28     explicit AnsSubscriberLocalLiveViewProxy(const sptr<IRemoteObject> &impl);
29     ~AnsSubscriberLocalLiveViewProxy() override;
30     DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalLiveViewProxy);
31 
32     /**
33      * @brief The callback function for the subscriber to establish a connection.
34      */
35     void OnConnected() override;
36 
37     /**
38      * @brief The callback function for subscriber disconnected.
39      */
40     void OnDisconnected() override;
41 
42     void OnResponse(int32_t notificationId, sptr<NotificationButtonOption> buttonOption) override;
43 
44 private:
45     ErrCode InnerTransact(NotificationInterfaceCode code,
46         MessageOption &flags, MessageParcel &data, MessageParcel &reply);
47     static inline BrokerDelegator<AnsSubscriberLocalLiveViewProxy> delegator_;
48 
49     template<typename T>
WriteParcelableVector(const std::vector<sptr<T>> & parcelableVector,MessageParcel & data)50     bool WriteParcelableVector(const std::vector<sptr<T>> &parcelableVector, MessageParcel &data)
51     {
52         if (!data.WriteInt32(parcelableVector.size())) {
53             ANS_LOGE("write ParcelableVector size failed");
54             return false;
55         }
56 
57         for (auto &parcelable : parcelableVector) {
58             if (!data.WriteStrongParcelable(parcelable)) {
59                 ANS_LOGE("write ParcelableVector failed");
60                 return false;
61             }
62         }
63         return true;
64     }
65 };
66 }  // namespace Notification
67 }  // namespace OHOS
68 
69 #endif  // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_PROXY_H
70