• 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 FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_DATA_H
17 #define FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_DATA_H
18 
19 #include "parcel.h"
20 #include "want.h"
21 
22 namespace OHOS {
23 namespace EventFwk {
24 using Want = OHOS::AAFwk::Want;
25 
26 class CommonEventData : public Parcelable {
27 public:
28     /**
29      * Default constructor used to create an empty CommonEventData instance.
30      */
31     CommonEventData();
32 
33     /**
34      * Create a CommonEventData instance based on the want parameter to set
35      * the content of a common want.
36      *
37      * @param want the want of a common event
38      */
39     explicit CommonEventData(const Want &want);
40 
41     /**
42      * Create a CommonEventData instance based on the parameters want, code,
43      * and data to set the content of the common event.
44      *
45      * @param want the want of a common event
46      * @param code the code of a common event
47      * @param data the data of a common event
48      */
49     CommonEventData(const Want &want, const int &code, const std::string &data);
50 
51     /**
52      * Default deconstructor used to deconstruct.
53      *
54      */
55     ~CommonEventData();
56 
57     /**
58      * Set the want attribute of a common event.
59      *
60      * @param want the want of a common event
61      */
62     void SetWant(const Want &want);
63 
64     /**
65      * Obtain the Want attribute of a common event.
66      *
67      * @return the want of a common event
68      */
69     const Want &GetWant() const;
70 
71     /**
72      * Set the result code of the common event.
73      *
74      * @param code the code of a common event
75      */
76     void SetCode(const int &code);
77 
78     /**
79      * Obtain the result code of a common event.
80      *
81      * @return the code of a common event
82      */
83     int GetCode() const;
84 
85     /**
86      * Set the result data of a common event.
87      *
88      * @param data the data of a common event
89      */
90     void SetData(const std::string &data);
91 
92     /**
93      * Obtain the result data of a common event, which is set by
94      * setData(java.lang.String).
95      *
96      * @return the data of a common event
97      */
98     std::string GetData() const;
99 
100     /**
101      * Marshal a common event data object into a Parcel.
102      *
103      * @param parcel the common event data into the parcel
104      */
105     virtual bool Marshalling(Parcel &parcel) const override;
106 
107     /**
108      * Unmarshal this common event data object from a Parcel.
109      * @return the common event data
110      */
111     static CommonEventData *Unmarshalling(Parcel &parcel);
112 
113 private:
114     /**
115      * Read a CommonEventData object from a Parcel.
116      *
117      * @param parcel the parcel
118      */
119     bool ReadFromParcel(Parcel &parcel);
120 
121 private:
122     Want want_;
123     int code_;
124     std::string data_;
125 };
126 }  // namespace EventFwk
127 }  // namespace OHOS
128 
129 #endif  // FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_DATA_H