* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_BASE_BASE_OBJECT_H
#define OHOS_ABILITY_BASE_BASE_OBJECT_H
#include "base_interfaces.h"
#include "refbase.h"
namespace OHOS {
namespace AAFwk {
INTERFACE(IObject, 8321f710 - a0c0 - 4cbe-bfbc - 5a78f1312b1b)
{
inline static IObject *Query(IInterface & object)
{
return static_cast<IObject *>(object.Query(g_IID_IObject));
}
virtual ClassID GetClassID() = 0;
virtual int GetHashCode() = 0;
virtual bool Equals(IObject & other) = 0;
virtual std::string ToString() = 0;
};
INTERFACE(IWeakReference, 26ab1978 - 1d11 - 4a4f - 826d - 61785c048cca)
{
inline static IWeakReference *Query(IInterface * object)
{
if (object == nullptr) {
return nullptr;
}
return static_cast<IWeakReference *>(object->Query(g_IID_IWeakReference));
}
virtual ErrCode Resolve(const InterfaceID &iid,
IInterface **object) = 0;
};
INTERFACE(IWeakReferenceSource, bc3f5250 - 34d7 - 42d2 - 9b40 - ffce83fd4061)
{
inline static IWeakReferenceSource *Query(IInterface * object)
{
if (object == nullptr) {
return nullptr;
}
return static_cast<IWeakReferenceSource *>(object->Query(g_IID_IWeakReferenceSource));
}
virtual ErrCode GetWeakReference(sptr<IWeakReference> & weakRef) = 0;
};
class Object : public virtual RefBase, public IObject, public IWeakReferenceSource {
public:
void IncStrongRef(const void *id = nullptr) override;
void DecStrongRef(const void *id = nullptr) override;
IInterface *Query(const InterfaceID &iid) override;
InterfaceID GetInterfaceID(IInterface *object) override;
ClassID GetClassID() override;
int GetHashCode() override;
bool Equals(IObject &other) override;
ErrCode GetWeakReference(sptr<IWeakReference> &weakRef) override;
std::string ToString() override;
static bool Equals(IInterface &obj1,
IInterface &obj2);
static std::string ToString(IInterface &object);
};
}
}
#endif