/* * Copyright (c) 2020 Amlogic, Inc. All rights reserved. * * This source code is subject to the terms and conditions defined in the * file 'LICENSE' which is part of this source code package. * * Description: */ #ifndef _AML_MP_HANDLE_H_ #define _AML_MP_HANDLE_H_ #include #include "AmlMpRefBase.h" #include namespace aml_mp { struct AmlMpHandle : AmlMpRefBase { AmlMpHandle() : mMagicID(kMagicID) { } virtual ~AmlMpHandle() { mMagicID = ~kMagicID; } operator bool() const { return mMagicID == kMagicID; } private: static constexpr uint32_t kMagicID = 0x5A6B7C8D; uint32_t mMagicID; AmlMpHandle(const AmlMpHandle&) = delete; AmlMpHandle& operator= (const AmlMpHandle&) = delete; }; static inline void* aml_handle_cast(const sptr& amlMpHandle) { if (!(amlMpHandle && *amlMpHandle)) { if (amlMpHandle) { ALOG(LOG_INFO, "AmlMpHandle", "[%d] AmlMpHandle CHECK failed!", __LINE__); } return AML_MP_INVALID_HANDLE; } return amlMpHandle.get(); } template sptr aml_handle_cast(void* h) { AmlMpHandle* amlMpHandle = static_cast(h); if (!(amlMpHandle && *amlMpHandle)) { if (amlMpHandle) { ALOG(LOG_INFO, "AmlMpHandle", "[%d] AmlMpHandle CHECK failed!", __LINE__); } return nullptr; } T* t = static_cast(h); return sptr(t); } } #endif