• 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     CommonEventData();
29 
30     /**
31      * Creates a CommonEventData instance based on the want parameter to set
32      * the content of a common want.
33      *
34      * @param want Indicates the want of a common event.
35      */
36     explicit CommonEventData(const Want &want);
37 
38     /**
39      * Creates a CommonEventData instance based on the parameters want, code,
40      * and data to set the content of the common event.
41      *
42      * @param want Indicates the want of a common event.
43      * @param code Indicates the code of a common event.
44      * @param data Indicates the data of a common event.
45      */
46     CommonEventData(const Want &want, const int32_t &code, const std::string &data);
47 
48     ~CommonEventData();
49 
50     /**
51      * Sets the want attribute of a common event.
52      *
53      * @param want Indicates the want of a common event.
54      */
55     void SetWant(const Want &want);
56 
57     /**
58      * Obtains the Want attribute of a common event.
59      *
60      * @return Returns the want of a common event.
61      */
62     const Want &GetWant() const;
63 
64     /**
65      * Sets the result code of the common event.
66      *
67      * @param code Indicates the code of a common event.
68      */
69     void SetCode(const int32_t &code);
70 
71     /**
72      * Obtains the result code of a common event.
73      *
74      * @return Returns the code of a common event.
75      */
76     int32_t GetCode() const;
77 
78     /**
79      * Sets the result data of a common event.
80      *
81      * @param data Indicates the data of a common event.
82      */
83     void SetData(const std::string &data);
84 
85     /**
86      * Obtains the result data of a common event
87      *
88      * @return Returns the data of a common event.
89      */
90     std::string GetData() const;
91 
92     /**
93      * Marshals a common event data object into a Parcel.
94      *
95      * @param parcel Indicates specified Parcel object.
96      * @return Returns true if success; false otherwise.
97      */
98     virtual bool Marshalling(Parcel &parcel) const override;
99 
100     /**
101      * Unmarshals this common event data object from a Parcel.
102      * @return Returns the common event data.
103      */
104     static CommonEventData *Unmarshalling(Parcel &parcel);
105 
106 private:
107     /**
108      * Reads a CommonEventData object from a Parcel.
109      *
110      * @param parcel Indicates specified Parcel object.
111      * @return Returns true if success; false otherwise.
112      */
113     bool ReadFromParcel(Parcel &parcel);
114 
115 private:
116     Want want_;
117     int32_t code_;
118     std::string data_;
119     static constexpr int VALUE_NULL = -1;
120     static constexpr int VALUE_OBJECT = 1;
121 };
122 }  // namespace EventFwk
123 }  // namespace OHOS
124 
125 #endif  // FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_DATA_H