• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DEF_H
16 #define OHOS_ABILITY_BASE_BASE_DEF_H
17 
18 #include "base_types.h"
19 #include "errors.h"
20 
21 namespace OHOS {
22 namespace AAFwk {
23 #define INTERFACE_INNER struct
24 
25 #define VALIDATE_NOT_NULL(i)      \
26     if ((i) == nullptr) {         \
27         return ERR_INVALID_VALUE; \
28     }
29 
30 #define INTERFACEID(id) extern const InterfaceID g_IID_##id;
31 
32 #define INTERFACE(id, x)                 \
33     extern const InterfaceID g_IID_##id; \
34     INTERFACE_INNER id : public IInterface
35 
36 #define CLASS(id, x)                   \
37     do {                               \
38         extern const ClassID CID_##id; \
39         class id : public Object       \
40     } while (0);
41 
42 #define INTERFACE_ID(x)
43 #define CLASS_ID(x)
44 
45 #ifndef IINTERFACE_DECL
46 #define IINTERFACE_DECL()                                 \
47     void IncStrongRef(const void *id = nullptr) override; \
48                                                           \
49     void DecStrongRef(const void *id = nullptr) override; \
50                                                           \
51     IInterface *Query(const InterfaceID & iid) override;  \
52                                                           \
53     InterfaceID GetInterfaceID(IInterface *object) override;
54 
55 #endif
56 
57 #ifndef IINTERFACE_IMPL_1
58 #define IINTERFACE_IMPL_1(ClassName, SuperclassName, InterfaceName) \
59     void ClassName::IncStrongRef(const void *id)                    \
60     {                                                               \
61         Object::IncStrongRef(id);                                   \
62     }                                                               \
63                                                                     \
64     void ClassName::DecStrongRef(const void *id)                    \
65     {                                                               \
66         Object::DecStrongRef(id);                                   \
67     }                                                               \
68                                                                     \
69     IInterface *ClassName::Query(const InterfaceID & iid)           \
70     {                                                               \
71         if (iid == g_IID_##InterfaceName) {                         \
72             return static_cast<InterfaceName *>(this);              \
73         }                                                           \
74         if (iid == g_IID_IInterface) {                              \
75             return static_cast<InterfaceName *>(this);              \
76         }                                                           \
77         return SuperclassName::Query(iid);                          \
78     }                                                               \
79                                                                     \
80     InterfaceID ClassName::GetInterfaceID(IInterface *object)       \
81     {                                                               \
82         if (object == static_cast<InterfaceName *>(this)) {         \
83             return g_IID_##InterfaceName;                           \
84         }                                                           \
85         return SuperclassName::GetInterfaceID(object);              \
86     }
87 #endif
88 
89 #ifndef OBJECT_DECL
90 #define OBJECT_DECL() ClassID GetClassID() override;
91 #endif
92 
93 #ifndef OBJECT_IMPL
94 #define OBJECT_IMPL(ClassName)           \
95     do {                                 \
96         ClassID(ClassName)::GetClassID() \
97         {                                \
98             return CID_##ClassName;      \
99         }                                \
100     } while (0);
101 #endif
102 }  // namespace AAFwk
103 }  // namespace OHOS
104 #endif  // OHOS_ABILITY_BASE_BASE_DEF_H
105