• 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_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SUBSCRIBER_INFO_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SUBSCRIBER_INFO_H
18 
19 #include "parcel.h"
20 
21 namespace OHOS {
22 namespace Notification {
23 class NotificationSubscribeInfo final : public Parcelable {
24 public:
25     NotificationSubscribeInfo();
26 
27     ~NotificationSubscribeInfo();
28 
29     /**
30      * @brief A constructor used to create a NotificationSubscribeInfo instance by copying parameters from an existing
31      * one.
32      *
33      * @param subscribeInfo Indicates the NotificationSubscribeInfo object.
34      */
35     NotificationSubscribeInfo(const NotificationSubscribeInfo &subscribeInfo);
36 
37     /**
38      * @brief Sets a single application name as the filter criterion,
39      * which means to subscribe to notifications of this application.
40      *
41      * @param appName Indicates the application name.
42      **/
43     void AddAppName(const std::string appName);
44 
45     /**
46      * @brief Sets multiple application names as the filter criteria,
47      * which means to subscribe to notifications of these applications.
48      *
49      * @param appNames Indicates the set of application names.
50      **/
51     void AddAppNames(const std::vector<std::string> &appNames);
52 
53     /**
54      * @brief Obtains the application names in the current NotificationSubscribeInfo object.
55      * The application names can be set by calling AddAppNames.
56      *
57      * @return Returns the set of application names.
58      **/
59     std::vector<std::string> GetAppNames() const;
60 
61     /**
62      * @brief Adds application userid.
63      *
64      * @param appNames Indicates the userid of application.
65      **/
66     void AddAppUserId(const int32_t userId);
67 
68     /**
69      * @brief Obtains the userid of application.
70      *
71      * @return Returns the userid of application.
72      **/
73     int32_t GetAppUserId() const;
74 
75     /**
76      * @brief Marshals a NotificationSubscribeInfo object into a Parcel.
77      *
78      * @param parcel Indicates the Parcel object for marshalling.
79      * @return Returns true if the marshalling is successful; returns false otherwise.
80      */
81     bool Marshalling(Parcel &parcel) const override;
82 
83     /**
84      * @brief Unmarshals a NotificationSubscribeInfo object from a Parcel.
85      *
86      * @param parcel Indicates the Parcel object for unmarshalling.
87      * @return Returns the NotificationSubscribeInfo object.
88      */
89     static NotificationSubscribeInfo *Unmarshalling(Parcel &parcel);
90 
91     /**
92      * @brief Dumps subscribe info.
93      *
94      * @return Returns subscribe info.
95      */
96     std::string Dump();
97 
98 private:
99     bool ReadFromParcel(Parcel &parcel);
100 
101 private:
102     std::vector<std::string> appNames_ {};
103     int32_t userId_ {-1};
104 };
105 }  // namespace Notification
106 }  // namespace OHOS
107 
108 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SUBSCRIBER_INFO_H