mirror of
https://gitee.com/openharmony/communication_ipc
synced 2024-11-23 07:50:24 +00:00
fix crash
Signed-off-by: yanghuiqing <yanghuiqing6@huawei.com>
This commit is contained in:
parent
a579773458
commit
46c1af5ca8
@ -19,6 +19,10 @@
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
|
||||
constexpr uint32_t BEFORE_MAGIC = 0x5A5A5A5A;
|
||||
constexpr uint32_t AFTER_MAGIC = 0xA5A5A5A5;
|
||||
|
||||
class PeerHolder {
|
||||
protected:
|
||||
PeerHolder(const sptr<IRemoteObject> &object);
|
||||
@ -33,7 +37,19 @@ protected:
|
||||
sptr<IRemoteObject> Remote();
|
||||
|
||||
private:
|
||||
uint32_t beforeMagic_ = BEFORE_MAGIC;
|
||||
const sptr<IRemoteObject> remoteObject_;
|
||||
uint32_t afterMagic_ = AFTER_MAGIC;
|
||||
|
||||
uint32_t GetBeforeMagic()
|
||||
{
|
||||
return beforeMagic_;
|
||||
}
|
||||
|
||||
uint32_t GetAfterMagic()
|
||||
{
|
||||
return afterMagic_;
|
||||
}
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_IPC_PEER_HOLDER_H
|
||||
|
@ -15,14 +15,23 @@
|
||||
|
||||
#include "peer_holder.h"
|
||||
|
||||
#include "ipc_debug.h"
|
||||
#include "iremote_object.h"
|
||||
#include "log_tags.h"
|
||||
#include "refbase.h"
|
||||
|
||||
namespace OHOS {
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_PEER_HOLDER, "PeerHolder" };
|
||||
|
||||
PeerHolder::PeerHolder(const sptr<IRemoteObject> &object) : remoteObject_(object) {}
|
||||
|
||||
sptr<IRemoteObject> PeerHolder::Remote()
|
||||
{
|
||||
if (GetBeforeMagic() != BEFORE_MAGIC || GetAfterMagic() != AFTER_MAGIC) {
|
||||
ZLOGE(LOG_LABEL, "remoteObject invalid, beforeMagic:%{public}x afterMagic:%{public}x",
|
||||
beforeMagic_, afterMagic_);
|
||||
return nullptr;
|
||||
}
|
||||
return remoteObject_;
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
@ -43,5 +43,6 @@ const unsigned int LOG_ID_RPC_DBINDER_INVOKER = LOG_ID_IPC_BASE | 0x14;
|
||||
const unsigned int LOG_ID_RPC_REMOTE_LISTENER = LOG_ID_IPC_BASE | 0x15;
|
||||
const unsigned int LOG_ID_RPC_DBINDER_CB_STUB = LOG_ID_IPC_BASE | 0x16;
|
||||
const unsigned int LOG_ID_IPC_DBINDER_SOFTBUS_CLIENT = LOG_ID_IPC_BASE | 0x17;
|
||||
const unsigned int LOG_ID_IPC_PEER_HOLDER = LOG_ID_IPC_BASE | 0x18;
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_COMMUNICATION_LOG_TAGS_H
|
||||
|
Loading…
Reference in New Issue
Block a user