• 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_OBJECT_H
16 #define OHOS_ABILITY_BASE_BASE_OBJECT_H
17 
18 #include "base_interfaces.h"
19 #include "refbase.h"
20 
21 namespace OHOS {
22 namespace AAFwk {
23 INTERFACE(IObject, 8321f710 - a0c0 - 4cbe-bfbc - 5a78f1312b1b)
24 {
Query(IInterface & object)25     inline static IObject *Query(IInterface & object) /* [in] */
26     {
27         return static_cast<IObject *>(object.Query(g_IID_IObject));
28     }
29 
30     virtual ClassID GetClassID() = 0;
31 
32     virtual int GetHashCode() = 0;
33 
34     virtual bool Equals(IObject & other) = 0; /* [in] */
35 
36     virtual std::string ToString() = 0;
37 };
38 
39 INTERFACE(IWeakReference, 26ab1978 - 1d11 - 4a4f - 826d - 61785c048cca)
40 {
Query(IInterface * object)41     inline static IWeakReference *Query(IInterface * object) /* [in] */
42     {
43         if (object == nullptr) {
44             return nullptr;
45         }
46         return static_cast<IWeakReference *>(object->Query(g_IID_IWeakReference));
47     }
48 
49     virtual ErrCode Resolve(const InterfaceID &iid, /* [in] */
50         IInterface **object) = 0;                   /* [out] */
51 };
52 
53 INTERFACE(IWeakReferenceSource, bc3f5250 - 34d7 - 42d2 - 9b40 - ffce83fd4061)
54 {
Query(IInterface * object)55     inline static IWeakReferenceSource *Query(IInterface * object) /* [in] */
56     {
57         if (object == nullptr) {
58             return nullptr;
59         }
60         return static_cast<IWeakReferenceSource *>(object->Query(g_IID_IWeakReferenceSource));
61     }
62 
63     virtual ErrCode GetWeakReference(sptr<IWeakReference> & weakRef) = 0; /* [out] */
64 };
65 
66 class Object : public virtual RefBase, public IObject, public IWeakReferenceSource {
67 public:
68     void IncStrongRef(const void *id = nullptr) override; /* [in] */
69 
70     void DecStrongRef(const void *id = nullptr) override; /* [in] */
71 
72     IInterface *Query(const InterfaceID &iid) override; /* [in] */
73 
74     InterfaceID GetInterfaceID(IInterface *object) override; /* [in] */
75 
76     ClassID GetClassID() override;
77 
78     int GetHashCode() override;
79 
80     bool Equals(IObject &other) override; /* [in] */
81 
82     ErrCode GetWeakReference(sptr<IWeakReference> &weakRef) override; /* [out] */
83 
84     std::string ToString() override;
85 
86     static bool Equals(IInterface &obj1, /* [in] */
87         IInterface &obj2);               /* [in] */
88 
89     static std::string ToString(IInterface &object); /* [in] */
90 };
91 }  // namespace AAFwk
92 }  // namespace OHOS
93 #endif  // OHOS_ABILITY_BASE_BASE_OBJECT_H
94