1 /*
2  * Copyright (c) 2021-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 #ifndef OHOS_ABILITY_BASE_BASE_IINTERFACES_H
16 #define OHOS_ABILITY_BASE_BASE_IINTERFACES_H
17 #include <memory>
18 #include <string>
19 
20 #include "base_def.h"
21 #include "refbase.h"
22 #include "user_object_base.h"
23 #include "iremote_object.h"
24 
25 namespace OHOS {
26 namespace AAFwk {
27 INTERFACEID(IInterface)
28 INTERFACE_ID(00000000 - 0000 - 0000 - 0000 - 000000000001)
29 INTERFACE_INNER IInterface
30 {
Query(IInterface * object)31     inline static IInterface *Query(IInterface * object) /* [in] */
32     {
33         if (object == nullptr) {
34             return nullptr;
35         }
36         return object->Query(g_IID_IInterface);
37     }
38 
39     virtual void IncStrongRef(const void *id = nullptr) = 0; /* [in] */
40 
41     virtual void DecStrongRef(const void *id = nullptr) = 0; /* [in] */
42 
43     virtual IInterface *Query(const InterfaceID &iid) = 0; /* [in] */
44 
45     virtual InterfaceID GetInterfaceID(IInterface * object) = 0; /* [in] */
46 
~IInterface()47     virtual ~IInterface() {}
48 };
49 
50 INTERFACE(IBoolean, 492ef6c0 - e122 - 401d - 80c4 - bb65e2325766)
51 {
Query(IInterface * object)52     inline static IBoolean *Query(IInterface * object) /* [in] */
53     {
54         if (object == nullptr) {
55             return nullptr;
56         }
57         return static_cast<IBoolean *>(object->Query(g_IID_IBoolean));
58     }
59 
60     virtual ErrCode GetValue(bool &value) = 0; /* [out] */
61 };
62 
63 INTERFACE(IChar, 6da72e7c - d353 - 4d7b - 85ef - 2146add34219)
64 {
Query(IInterface * object)65     inline static IChar *Query(IInterface * object) /* [in] */
66     {
67         if (object == nullptr) {
68             return nullptr;
69         }
70         return static_cast<IChar *>(object->Query(g_IID_IChar));
71     }
72 
73     virtual ErrCode GetValue(zchar & value) = 0; /* [out] */
74 };
75 
76 INTERFACE(IByte, 2c9fd6ff - 73f7 - 4a22 - 9ea8 - 1e37b2213ca1)
77 {
Query(IInterface * object)78     inline static IByte *Query(IInterface * object) /* [in] */
79     {
80         if (object == nullptr) {
81             return nullptr;
82         }
83         return static_cast<IByte *>(object->Query(g_IID_IByte));
84     }
85 
86     virtual ErrCode GetValue(byte & value) = 0; /* [out] */
87 };
88 
89 INTERFACE(IShort, 54fe1291 - 0813 - 43c9 - b6f7 - b008edef7f34)
90 {
Query(IInterface * object)91     inline static IShort *Query(IInterface * object) /* [in] */
92     {
93         if (object == nullptr) {
94             return nullptr;
95         }
96         return static_cast<IShort *>(object->Query(g_IID_IShort));
97     }
98 
99     virtual ErrCode GetValue(short &value) = 0; /* [out] */
100 };
101 
102 INTERFACE(IInteger, 0672d282 - 7cdb - 49b8 - 92c7 - 1af35e2d4949)
103 {
Query(IInterface * object)104     inline static IInteger *Query(IInterface * object) /* [in] */
105     {
106         if (object == nullptr) {
107             return nullptr;
108         }
109         return static_cast<IInteger *>(object->Query(g_IID_IInteger));
110     }
111 
112     virtual ErrCode GetValue(int &value) = 0; /* [out] */
113 };
114 
115 INTERFACE(ILong, d7550828 - 2eaf - 4281 - 8604 - 42a82ab9bcdc)
116 {
Query(IInterface * object)117     inline static ILong *Query(IInterface * object) /* [in] */
118     {
119         if (object == nullptr) {
120             return nullptr;
121         }
122         return static_cast<ILong *>(object->Query(g_IID_ILong));
123     }
124 
125     virtual ErrCode GetValue(long &value) = 0; /* [out] */
126 };
127 
128 INTERFACE(IFloat, b5428638 - ca53 - 4a27 - 95a0 - 3f24e54a58d5)
129 {
Query(IInterface * object)130     inline static IFloat *Query(IInterface * object) /* [in] */
131     {
132         if (object == nullptr) {
133             return nullptr;
134         }
135         return static_cast<IFloat *>(object->Query(g_IID_IFloat));
136     }
137 
138     virtual ErrCode GetValue(float &value) = 0; /* [out] */
139 };
140 
141 INTERFACE(IDouble, 596dc69a - ae7d - 42ad - b00f - 0d5eb01a2557)
142 {
Query(IInterface * object)143     inline static IDouble *Query(IInterface * object) /* [in] */
144     {
145         if (object == nullptr) {
146             return nullptr;
147         }
148         return static_cast<IDouble *>(object->Query(g_IID_IDouble));
149     }
150 
151     virtual ErrCode GetValue(double &value) = 0; /* [out] */
152 };
153 
154 INTERFACE(IString, 69644bf4 - dd20 - 417b - 9055 - 5a26e3e1793b)
155 {
Query(IInterface * object)156     inline static IString *Query(IInterface * object) /* [in] */
157     {
158         if (object == nullptr) {
159             return nullptr;
160         }
161         return static_cast<IString *>(object->Query(g_IID_IString));
162     }
163 
164     virtual ErrCode GetString(std::string & str) = 0; /* [out] */
165 };
166 
167 INTERFACE(IArray, 875b9da6 - 9913 - 4370 - 8847 - e1961be6e560)
168 {
Query(IInterface * object)169     inline static IArray *Query(IInterface * object) /* [in] */
170     {
171         if (object == nullptr) {
172             return nullptr;
173         }
174         return static_cast<IArray *>(object->Query(g_IID_IArray));
175     }
176 
177     virtual ErrCode Get(long index,   /* [in] */
178         sptr<IInterface> &value) = 0; /* [out] */
179 
180     virtual ErrCode GetLength(long &size) = 0; /* [out] */
181 
182     virtual ErrCode GetType(InterfaceID & id) = 0; /* [out] */
183 
184     virtual ErrCode Set(long index, /* [in] */
185         IInterface *value) = 0;     /* [in] */
186 };
187 
188 INTERFACE(IPacMap, f92066fd - fd0c - 401b - a3f6 - 626da3bac9d5)
189 {
Query(IInterface * object)190     inline static IPacMap *Query(IInterface * object)
191     {
192         if (object == nullptr) {
193             return nullptr;
194         }
195         return static_cast<IPacMap *>(object->Query(g_IID_IPacMap));
196     }
197 
198     virtual bool FromString(const std::string &str) = 0;
199 };
200 
201 INTERFACE(IUserObject, 4edb325d - 8532 - 4af7 - b42e - 82f4f29dfdea)
202 {
Query(IInterface * object)203     inline static IUserObject *Query(IInterface * object)
204     {
205         if (object == nullptr) {
206             return nullptr;
207         }
208         return static_cast<IUserObject *>(object->Query(g_IID_IUserObject));
209     }
210 
211     virtual ErrCode GetValue(std::shared_ptr<UserObjectBase> & value) = 0; /* [out] */
212 };
213 
214 INTERFACE(IRemoteObjectWrap, 520d74e7 - 9aff - 7191 - 31b5 - f60c47f25c41)
215 {
Query(IInterface * object)216     inline static IRemoteObjectWrap *Query(IInterface * object)
217     {
218         if (object == nullptr) {
219             return nullptr;
220         }
221         return static_cast<IRemoteObjectWrap *>(object->Query(g_IID_IRemoteObjectWrap));
222     }
223 
224     virtual sptr<IRemoteObject> GetValue() = 0;
225 };
226 }  // namespace AAFwk
227 }  // namespace OHOS
228 #endif  // OHOS_ABILITY_BASE_BASE_IINTERFACES_H
229