提交 43915871 编写于 作者: L l30043718

Description:add c++ exegesis

Feature or Bugfix:add c++ exegesis
Binary Source: No
Signed-off-by: NLixiaoying25 <lixiaoying25@huawei.com>
上级 0554a8bf
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -24,11 +24,45 @@ public:
IPCFileDescriptor();
explicit IPCFileDescriptor(int fd);
~IPCFileDescriptor();
/**
* @brief Marshal the object.
* @param parcel Indicates the Parcel object to which the sequenceable object will be marshaled.
* @return Returns <b>true</b> if the marshalling is successful; returns <b>false</b> otherwise.
* @since 9
*/
bool Marshalling(Parcel &parcel) const override;
/**
* @brief Marshal the object.
* @param Parcel Indicates the Parcel object to which the sequenceable object will be marshaled.
* @param object Indicates the IPCFileDescriptor pointer object.
* @return Returns <b>true</b> if the marshalling is successful; returns <b>false</b> otherwise.
* @since 9
*/
static bool Marshalling(Parcel &parcel, const sptr<IPCFileDescriptor> &object);
/**
* @brief Unmarshal the object.
* @param Parcel Indicates the Parcel object to which the sequenceable object will be marshaled.
* @return Returns <b>true</b> if the marshalling is successful; returns <b>false</b> otherwise.
* @since 9
*/
static IPCFileDescriptor *Unmarshalling(Parcel &parcel);
/**
* @brief Gets the file descriptor.
* @return Returns the file descriptor.
* @since 9
*/
int GetFd() const;
/**
* @brief Sets the file descriptor.
* @param fd Indicates the file descriptor.
* @return void
* @since 9
*/
void SetFd(int fd);
private:
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -28,29 +28,96 @@ public:
int proto = IRemoteObject::IF_PROT_DEFAULT);
~IPCObjectProxy();
/**
* @brief Sends message to the peer process in synchronous or asynchronous mode.
* @param code Indicates the message code, which is determined by both sides of the communication.
* @param data Indicates the object sent to the peer process.
* @param reply Indicates the object returned by the peer process.
* @param optionoption Indicates the synchronous or asynchronous mode to send messages.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &optionoption) override;
/**
* @brief Determine whether it is a Proxy Object.
* @return Returns <b>true</b> if it is Proxy Object; returns <b>false</b> otherwise.
* @since 9
*/
bool IsProxyObject() const override
{
return true;
};
/**
* @brief Checks whether an object is dead.
* @return Returns <b>true</b> if the object is dead; returns <b>false</b> otherwise.
* @since 9
*/
bool IsObjectDead() const override;
/**
* @brief Obtains the reference count of the object.
* @return Returns the reference count.
* @since 9
*/
int32_t GetObjectRefCount() override;
/**
* @brief Dump the contents.
* @param fd Indicates the file descriptor.
* @param args Indicates a vector containing u16string.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
int Dump(int fd, const std::vector<std::u16string> &args) override;
/**
* @brief The first strong reference provided.
* @param objectId Indicates the object Id.
* @return void
* @since 9
*/
void OnFirstStrongRef(const void *objectId) override;
/**
* @brief The last strong reference provided.
* @param objectId Indicates the object Id.
* @return void
* @since 9
*/
void OnLastStrongRef(const void *objectId) override;
/**
* @brief Registered a death recipient.
* @param recipient Indicates the recipient of the DeathRecipient pointer.
* @return Returns <b>true</b> if the callback is registered successfully; returns <b>false</b> otherwise.
* @since 9
*/
bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) override;
/**
* @brief Unregistered a death recipient.
* @param recipient Indicates the recipient of the DeathRecipient pointer.
* @return Returns <b>true</b> if the callback is registered successfully; returns <b>false</b> otherwise.
* @since 9
*/
bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) override;
/**
* @brief Send Obituary to agents who have registered for death notices.
* @return void
* @since 9
*/
void SendObituary();
/**
* @brief Check Subscribe to death notifications.
* @return Returns <b>true</b> if the recipients exists; returns <b>false</b> otherwise.
* @since 9
*/
bool IsSubscribeDeathNotice() const
{
if (recipients_.empty()) {
......@@ -59,19 +126,85 @@ public:
return true;
};
/**
* @brief Obtains the handle.
* @return Returns handle.
* @since 9
*/
uint32_t GetHandle() const
{
return handle_;
};
/**
* @brief Call the listening thread.
* @param data Indicates the object sent to the peer process.
* @param reply Indicates the object returned by the peer process.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
int InvokeListenThread(MessageParcel &data, MessageParcel &reply);
/**
* @brief Notification service death.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
int32_t NoticeServiceDie();
/**
* @brief Obtains the corresponding PID and UID.
* @param reply Indicates the object returned by the peer process.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
int GetPidUid(MessageParcel &reply);
/**
* @brief Obtains the session name.
* @return Returns the session name of type string.
* @since 9
*/
std::string GetSessionName();
/**
* @brief Obtains the session name for PID and UID.
* @param uid Indicates the UID value entered.
* @param pid Indicates the PID value entered.
* @return Returns the PID and UID session name of type string.
* @since 9
*/
std::string GetSessionNameForPidUid(uint32_t uid, uint32_t pid);
/**
* @brief Obtains the grant session name.
* @return Returns the grant session name of type string.
* @since 9
*/
std::string GetGrantedSessionName();
/**
* @brief Obtains the proxy protocol.
* @return Returns the obtained proxy protocol.
* @since 9
*/
int GetProto() const;
/**
* @brief Wait for initialization.
* @return void
* @since 9
*/
void WaitForInit();
/**
* @brief Obtains the interface descriptor.
* @return Returns the corresponding interface descriptor.
* @since 9
*/
std::u16string GetInterfaceDescriptor() override;
private:
......@@ -81,33 +214,93 @@ private:
void ClearDeathRecipients();
#ifndef CONFIG_IPC_SINGLE
/**
* @brief Set the proxy protocol.
* @param proto Indicates a proxy proto.
* @return void
* @since 9
*/
void SetProto(int proto);
/**
* @brief Update the proxy protocol.
* @return Returns the updated proxy protocol.
* @since 9
*/
int UpdateProto();
/**
* @brief Release the proxy protocol.
* @return void
* @since 9
*/
void ReleaseProto();
/**
* @brief Increase a reference to remote.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
int32_t IncRefToRemote();
/**
* @brief Obtain proxy protocol information.
* @return Returns the status code of the protocol.
* @since 9
*/
int GetProtoInfo();
/**
* @brief Register the Dbinder death recipient.
* @return Returns <b>true</b> if the current recipient is not empty; return <b>false</b> otherwise.
* @since 9
*/
bool AddDbinderDeathRecipient();
/**
* @brief Unregister the Dbinder death recipient.
* @return Returns <b>true</b> if the current recipient or callback result is not empty;
* return <b>false</b> otherwise.
* @since 9
*/
bool RemoveDbinderDeathRecipient();
/**
* @brief Release the databus(Dbinder) protocol.
* @return void
* @since 9
*/
void ReleaseDatabusProto();
/**
* @brief Release the binder protocol.
* @return void
* @since 9
*/
void ReleaseBinderProto();
/**
* @brief Update the databus(Dbinder) client session name.
* @param hadle Indicates a hadel that needs to update session information.
* @param reply Indicates the object returned by the peer process.
* @return Returns <b>true</b> if the update is successful; returns <b>false</b> Otherwise.
* @since 9
*/
bool UpdateDatabusClientSession(int handle, MessageParcel &reply);
/**
* @brief Check if there is a session.
* @return Returns <b>true</b> if there is currently a session; returns <b>false</b> otherwise.
* @since 9
*/
bool CheckHaveSession();
#endif
private:
std::mutex initMutex_;
std::recursive_mutex mutex_;
std::vector<sptr<DeathRecipient>> recipients_;
const uint32_t handle_;
int proto_;
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -28,6 +28,10 @@ struct RefCountNode {
class IPCObjectStub : public IRemoteObject {
public:
/**
* @brief Enumerates object types.
* @since 9
*/
enum {
OBJECT_TYPE_NATIVE,
OBJECT_TYPE_JAVA,
......@@ -37,49 +41,205 @@ public:
explicit IPCObjectStub(std::u16string descriptor = std::u16string());
~IPCObjectStub();
/**
* @brief Determine whether it is a Proxy Object.
* @return Returns <b>true</b> if it is a Proxy Object; returns <b>false</b> otherwise.
* @since 9
*/
bool IsProxyObject() const override
{
return false;
};
/**
* @brief Determine the reference count of the object.
* @return Returns the reference pointer count.
* @since 9
*/
int32_t GetObjectRefCount() override;
/**
* @brief Dump the contents.
* @param fd Indicates the file descriptor.
* @param args Indicates a vector containing u16string.
* @return Returns {@link ERR_NONE} if the dump is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
int Dump(int fd, const std::vector<std::u16string> &args) override;
/**
* @brief Sets an entry for receiving requests.
* @param code Indicates the service request code sent from the peer end.
* @param data Indicates the object sent from the peer end.
* @param reply Indicates the response message object sent from the remote service.
* @param option Indicates whether the operation is synchronous or asynchronous.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
/**
* @brief Sends a request to the peer object.
* @param code Indicates the message code of the request.
* @param data Indicates the object storing the data to be sent.
* @param reply Indicates the object receiving the response data.
* @param option Indicates a synchronous (default) or asynchronous request.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h}otherwise.
* @since 9
*/
int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
/**
* @brief The callback function that is strongly referenced for the first time.
* @param objectId Indicates the object Id.
* @return void
* @since 9
*/
void OnFirstStrongRef(const void *objectId) override;
/**
* @brief The callback function that is strongly referenced for the last time.
* @param objectId Indicates the object Id.
* @return void
* @since 9
*/
void OnLastStrongRef(const void *objectId) override;
/**
* @brief Register for callbacks to receive death notifications.
* @param recipient Indicates the DeathRecipient pointer callback to register.
* @return Returns <b>true</b> if register succeeds; returns <b>false</b> otherwise.
* @since 9
*/
bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) override;
/**
* @brief Unregister for callbacks to receive death notifications.
* @param recipient Indicates the DeathRecipient pointer callback to register.
* @return Returns <b>true</b> if unregister succeeds; returns <b>false</b> otherwise.
* @since 9
*/
bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) override;
/**
* @brief Obtains the PID of the object.
* @return Returns the PID of the object.
* @since 9
*/
int GetCallingPid();
/**
* @brief Obtains the UID of the object.
* @return Returns the UID of the object.
* @since 9
*/
int GetCallingUid();
/**
* @brief Obtains calling token ID of caller.
* @return Returns the TokenId of caller.
* @since 9
*/
uint32_t GetCallingTokenID();
/**
* @brief Obtains full calling token ID of caller.
* @return Returns the full TokenId of caller.
* @since 9
*/
uint64_t GetCallingFullTokenID();
/**
* @brief Obtains the first token ID.
* @return Returns the first TokenId.
* @since 9
*/
uint32_t GetFirstTokenID();
/**
* @brief Obtains the first full token ID.
* @return Returns the first full TokenId.
* @since 9
*/
uint64_t GetFirstFullTokenID();
/**
* @brief Take a remote dump.
* @param code Indicates the service request code sent from the peer end.
* @param data Indicates the object sent from the peer end.
* @param reply Indicates the response message object sent from the remote service.
* @param option Indicates whether the operation is synchronous or asynchronous.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
virtual int OnRemoteDump(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
/**
* @brief Obtains the process protocol.
* @param code Indicates the service request code sent from the peer end.
* @param data Indicates the object sent from the peer end.
* @param reply Indicates the response message object sent from the remote service.
* @param option Indicates whether the operation is synchronous or asynchronous.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
virtual int32_t ProcessProto(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
/**
* @brief Obtains the object type.
* @return Returns an enumeration value that represents the type of object.
* @since 9
*/
virtual int GetObjectType() const;
#ifndef CONFIG_IPC_SINGLE
/**
* @brief Invoker the calling thread.
* @param code Indicates the message code.
* @param data Indicates the object sent to the peer process.
* @param reply Indicates the object returned by the peer process.
* @param option Indicates the synchronous or asynchronous mode to send messages.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
int32_t InvokerThread(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
/**
* @brief Notification service death.
* @param data Indicates the object sent to the peer process.
* @param reply Indicates the object returned by the peer process.
* @param option Indicates the synchronous or asynchronous mode to send messages.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
int32_t NoticeServiceDie(MessageParcel &data, MessageParcel &reply, MessageOption &option);
/**
* @brief Invoke the data bus thread.
* @param data Indicates the object sent to the peer process.
* @param reply Indicates the object returned by the peer process.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
int32_t InvokerDataBusThread(MessageParcel &data, MessageParcel &reply);
/**
* @brief Add authentication information.
* @param data Indicates the object sent to the peer process.
* @param reply Indicates the object returned by the peer process.
* @param code Indicates the message code of this request.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
int32_t AddAuthInfo(MessageParcel &data, MessageParcel &reply, uint32_t code);
private:
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -24,45 +24,143 @@ public:
IPCSkeleton() = default;
~IPCSkeleton() = default;
// default max is 4, only if you need a customize value
/**
* @brief Set the maximum number of threads.
* @param maxThreadNum default max is 4, only if you need a customize value.
* @return Returns <b>true</b> if the operation succeeds; return <b>false</b> Otherwise.
* @since 9
*/
static bool SetMaxWorkThreadNum(int maxThreadNum);
// join current thread into work loop.
/**
* @brief Make current thread join to the IPC/RPC work thread pool.
* @return void
* @since 9
*/
static void JoinWorkThread();
// remove current thread from work loop.
/**
* @brief Exit current thread from IPC/RPC work thread pool.
* @return void
* @since 9
*/
static void StopWorkThread();
/**
* @brief Get calling process id of caller.
* @return Returns the PID of caller.
* @since 9
*/
static pid_t GetCallingPid();
/**
* @brief Get calling user id of caller.
* @return Returns the UID of the caller.
* @since 9
*/
static pid_t GetCallingUid();
/**
* @brief Get calling token ID of caller.
* @return Returns the TokenId of caller.
* @since 9
*/
static uint32_t GetCallingTokenID();
/**
* @brief Get full calling token ID of caller.
* @return Returns the full TokenId of caller.
* @since 9
*/
static uint64_t GetCallingFullTokenID();
/**
* @brief Get the first token ID.
* @return Returns the first TokenId.
* @since 9
*/
static uint32_t GetFirstTokenID();
/**
* @brief Get the first full token ID.
* @return Returns the first full TokenId.
* @since 9
*/
static uint64_t GetFirstFullTokenID();
/**
* @brief Get the token ID of the self.
* @return Returns the TokenId.
* @since 9
*/
static uint64_t GetSelfTokenID();
/**
* @brief Get local device ID.
* @return Returns the ID of the local device.
* @since 9
*/
static std::string GetLocalDeviceID();
/**
* @brief get calling device id.
* @return Returns the device ID of the caller process.
* @since 9
*/
static std::string GetCallingDeviceID();
/**
* @brief Determine whether it is a local call.
* @return Returns <b>true</b> if it is a local call; returns <b>false</b> otherwise.
* @since 9
*/
static bool IsLocalCalling();
/**
* @brief Get an IPCSkeleton instance.
* @return Returns an IPCSkeleton instance.
* @since 9
*/
static IPCSkeleton &GetInstance();
/**
* @brief Get the context object.
* @return Returns a context object of the IRemoteObject pointer.
* @since 9
*/
static sptr<IRemoteObject> GetContextObject();
/**
* @brief Set the context object.
* @param object Indicates the IRemoteObject pointer object.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link rpc_errno.h} otherwise.
* @since 9
*/
static bool SetContextObject(sptr<IRemoteObject> &object);
/**
* @brief Flush all pending commands.
* @param object Indicates the IRemoteObject object.
* @return Returns {@link ERR_NONE} if the operation is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
static int FlushCommands(IRemoteObject *object);
/**
* @brief reset calling identity.
* @return Returns a string containing the UID and PID of the remote user.
* @since 9
*/
static std::string ResetCallingIdentity();
/**
* @brief Set calling identity.
* @param identity Indicates the string containing the UID and PID of the remote user.
* @return Returns <b>true</b> if the operation succeeds; returns <b>false</b> otherwise.
* @since 9
*/
static bool SetCallingIdentity(std::string &identity);
};
} // namespace OHOS
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -25,6 +25,10 @@ namespace OHOS {
constexpr int REGISTRY_HANDLE = 0;
/**
* @brief Enumerates the commands and identifiers used in communication.
* @since 9
*/
enum {
FIRST_CALL_TRANSACTION = 0x00000001,
LAST_CALL_TRANSACTION = 0x00ffffff,
......@@ -48,6 +52,10 @@ enum {
TRANS_ASYNC = 1,
};
/**
* @brief Enumerates the error types of communication.
* @since 9
*/
enum {
NO_ERROR = 0,
TRANSACTION_ERR,
......@@ -64,6 +72,10 @@ constexpr int MIN_TRANSACTION_ID = 0x1;
constexpr int MAX_TRANSACTION_ID = 0x00ffffff;
constexpr int INVALID_FD = -1;
/**
* @brief Enumerate the correct error code returned.
* @since 9
*/
enum {
ERR_NONE = 0,
ERR_TRANSACTION_FAILED = 1,
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -41,6 +41,13 @@ class IRemoteBroker : public virtual RefBase {
public:
IRemoteBroker() = default;
virtual ~IRemoteBroker() override = default;
/**
* @brief Obtains a proxy or remote object.
* @return Returns the RemoteObject if the caller is a RemoteObject;
* returns the IRemoteObject if the caller is a RemoteProxy object.
* @since 9
*/
virtual sptr<IRemoteObject> AsObject() = 0;
};
......@@ -65,9 +72,38 @@ class BrokerRegistration {
using Constructor = std::function<sptr<IRemoteBroker>(const sptr<IRemoteObject> &object)>;
public:
/**
* @brief Get broker registered.
* @return Returns the BrokerRegistration instance.
* @since 9
*/
static BrokerRegistration &Get();
/**
* @brief Register the broker.
* @param descriptor Indicates a descriptor the type of string.
* @param creator Indicates the constructor.
* @param object Indicates an object of type BrokerDelegatorBase.
* @return Returns <b>true</b> if registration is successful; returns <b>false</b> otherwise.
* @since 9
*/
bool Register(const std::u16string &descriptor, const Constructor &creator, const BrokerDelegatorBase *object);
/**
* @brief Deregister the broker.
* @param descriptor Indicates a descriptor the type of string.
* @return void
* @since 9
*/
void Unregister(const std::u16string &descriptor);
/**
* @brief Obtains the new instance object.
* @param descriptor Indicates a descriptor the type of string.
* @param object Indicates an IRemoteObject pointer object.
* @return Returns an IRemoteBroker pointer object.
* @since 9
*/
sptr<IRemoteBroker> NewInstance(const std::u16string &descriptor, const sptr<IRemoteObject> &object);
protected:
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -32,6 +32,10 @@ inline std::u16string to_utf16(const std::string &str)
class IRemoteObject : public virtual Parcelable, public virtual RefBase {
public:
/**
* @brief Enumerates communication protocols.
* @since 9
*/
enum {
IF_PROT_DEFAULT, /* Invoker family. */
IF_PROT_BINDER = IF_PROT_DEFAULT,
......@@ -43,6 +47,10 @@ public:
};
class DeathRecipient : public RefBase {
public:
/**
* @brief Methods that enumerate death notifications.
* @since 9
*/
enum {
ADD_DEATH_RECIPIENT,
REMOVE_DEATH_RECIPIENT,
......@@ -50,37 +58,124 @@ public:
TEST_SERVICE_DEATH_RECIPIENT,
TEST_DEVICE_DEATH_RECIPIENT,
};
/**
* @brief Called to perform subsequent operations when a death notification of the remote object is received.
* @param object Indicates the IRemoteObject pointer object.
* @return void
* @since 9
*/
virtual void OnRemoteDied(const wptr<IRemoteObject> &object) = 0;
};
/**
* @brief Obtains the object reference count.
* @return Returns the resulting object reference count.
* @since 9
*/
virtual int32_t GetObjectRefCount() = 0;
/**
* @brief Sends message to the peer process in synchronous or asynchronous mode.
* @param code Indicates the message code of the request.
* @param data Indicates the object storing the data to be sent.
* @param reply Indicates the object receiving the response data.
* @param option Indicates a synchronous (default) or asynchronous request.
* @return Returns the result of the send request.
* @since 9
*/
virtual int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) = 0;
/**
* @brief Determine whether it is a proxy object.
* @return Returns <b>true</b> if as a proxy object; returns <b>false</b> otherwise.
* @since 9
*/
virtual bool IsProxyObject() const;
/**
* @brief Check the object is dead.
* @return Returns <b>true</b> if the object has dead; returns <b>false</b> otherwise.
* @since 9
*/
virtual bool IsObjectDead() const;
/**
* @brief Obtains the interface descriptor.
* @return Returns the resulting interface descriptor.
* @since 9
*/
virtual std::u16string GetInterfaceDescriptor();
/**
* @brief Check the legitimacy of the object.
* @return Returns <b>true</b> if the identity is legal; returns <b>false</b> otherwise.
* @since 9
*/
virtual bool CheckObjectLegality() const;
/**
* @brief Add a callback used to receive notifications of the death of a remote object.
* @return Returns <b>true</b> if the identity is legal; returns <b>false</b> otherwise.
* @since 9
*/
virtual bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) = 0;
/**
* @brief Remove a callback used to receive notifications of the death of a remote object.
* @return Returns <b>true</b> if the identity is legal; returns <b>false</b> otherwise.
* @since 9
*/
virtual bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) = 0;
/**
* @brief Marshal this object.
* @param parcel Indicates a marshaling parcel type object.
* @return Returns <b>true</b> if the marshalling is successful; returns <b>false</b> otherwise.
* @since 9
*/
virtual bool Marshalling(Parcel &parcel) const override;
/**
* @brief Unmarshal this object.
* @return Returns the IRemoteObject pointer object.
* @since 9
*/
static sptr<IRemoteObject> Unmarshalling(Parcel &parcel);
/**
* @brief Marshal this object.
* @param parcel Indicates a marshaling parcel type object.
* @param object Indicates an IRemoteObject pointer type object.
* @return Returns <b>true</b> if the marshalling is successful; returns <b>false</b> otherwise.
* @since 9
*/
static bool Marshalling(Parcel &parcel, const sptr<IRemoteObject> &object);
/**
* @brief Obtains the interface.
* @return Returns an IRemoteBroker pointer object.
* @since 9
*/
virtual sptr<IRemoteBroker> AsInterface();
/**
* @brief Dump the contents.
* @param fd Indicates the file descriptor.
* @param args Indicates a vector containing u16string.
* @return Returns {@link ERR_NONE} if the dump is successful; returns an error code
* defined in {@link ipc_types.h} otherwise.
* @since 9
*/
virtual int Dump(int fd, const std::vector<std::u16string> &args) = 0;
const std::u16string descriptor_;
/**
* @brief Obtains the object descriptor.
* @return Returns the object descriptor.
* @since 9
*/
std::u16string GetObjectDescriptor() const;
protected:
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -25,7 +25,19 @@ template <typename INTERFACE> class IRemoteStub : public IPCObjectStub, public I
public:
IRemoteStub();
virtual ~IRemoteStub() = default;
/**
* @brief Obtains the object.
* @return Returns the IRemoteObject pointer object.
* @since 9
*/
sptr<IRemoteObject> AsObject() override;
/**
* @brief Gets the interface.
* @return Returns the IRemoteBroker pointer interface.
* @since 9
*/
sptr<IRemoteBroker> AsInterface() override;
};
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -29,9 +29,35 @@ public:
};
MessageOption(int flags = TF_SYNC, int waitTime = TF_WAIT_TIME);
~MessageOption() = default;
/**
* @brief Sets flags.
* @param flags Indicates the identity to set.
* @return void
* @since 9
*/
void SetFlags(int flags);
/**
* @brief Gets flags.
* @return Returns the resulting flags.
* @since 9
*/
int GetFlags() const;
/**
* @brief Sets the wait time.
* @param waitTime Indicates the wait time to set.
* @return void
* @since 9
*/
void SetWaitTime(int waitTime);
/**
* @brief Gets the wait time.
* @return Returns the resulting wait time.
* @since 9
*/
int GetWaitTime() const;
private:
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -28,32 +28,171 @@ public:
MessageParcel();
~MessageParcel();
explicit MessageParcel(Allocator *allocator);
/**
* @brief Serializes the remote object and writes it.
* @param object Indicates the remote object to serialize.
* @return Returns <b>true</b> if it is successful; returns <b>false</b> otherwise.
* @since 9
*/
bool WriteRemoteObject(const sptr<IRemoteObject> &object);
/**
* @brief Reads a remote object.
* @return Returns the IRemoteObject pointer object.
* @since 9
*/
sptr<IRemoteObject> ReadRemoteObject();
/**
* @brief Writes an file descriptor into the object.
* @param fd Indicates file descriptor to write.
* @return Returns <b>true</b> if the write succeeds; return <b>false</b> otherwise.
* @since 9
*/
bool WriteFileDescriptor(int fd);
/**
* @brief Reads an file descriptor from the object.
* @return Returns the corresponding descriptor If the read is successful; returns {@code -1} otherwise.
* @since 9
*/
int ReadFileDescriptor();
/**
* @brief Check whether the file descriptor is included.
* @return Returns <b>true</b> if checking for inclusion; returns <b>false</b> Otherwise.
* @since 9
*/
bool ContainFileDescriptors() const;
/**
* @brief Writes an interface token into the object.
* @param name Indicates the string type name.
* @return Returns <b>true</b> if the write succeeds; returns <b>false</b> otherwise.
* @since 9
*/
bool WriteInterfaceToken(std::u16string name);
/**
* @brief Reads an interface token from the object.
* @return Returns a string value.
* @since 9
*/
std::u16string ReadInterfaceToken();
/**
* @brief Writes raw data to the object.
* @param data Indicates the original data written.
* @param size Indicates the size of the raw data sent.
* @return Returns <b>true</b> if the write succeeds; returns <b>false</b> otherwise.
* @since 9
*/
bool WriteRawData(const void *data, size_t size);
/**
* @brief Reads raw data from the object.
* @param size Indicates the size of the raw data to read.
* @return void
* @since 9
*/
const void *ReadRawData(size_t size);
/**
* @brief Restore raw data.
* @param rawData Indicates the original data to be recovered.
* @param size Indicates the size of the raw data to read.
* @return Returns <b>true</b> if recovery is successful; returns <b>false</b> Otherwise.
* @since 9
*/
bool RestoreRawData(std::shared_ptr<char> rawData, size_t size);
/**
* @brief Obtains raw data from the object.
* @return void
* @since 9
*/
const void *GetRawData() const;
/**
* @brief Gets the raw data size.
* @return Returns the resulting raw data size.
* @since 9
*/
size_t GetRawDataSize() const;
/**
* @brief Get raw data capacity.
* @return Returns the maximum value of the raw data capacity.
* @since 9
*/
size_t GetRawDataCapacity() const;
/**
* @brief writes information to the object indicating that no exception occurred.
* @return void
* @since 9
*/
void WriteNoException();
/**
* @brief Reads the exception information from the object.
* @return Returns the read error code.
* @since 9
*/
int32_t ReadException();
/**
* @brief Writes an anonymous shared memory object to the object.
* @param ashmem Indicates anonymous shared memory object to wrote.
* @return Returns <b>true</b> if the write succeeds; returns <b>false</b> otherwise.
* @since 9
*/
bool WriteAshmem(sptr<Ashmem> ashmem);
/**
* @brief Reads the anonymous shared memory object from the object.
* @return Returns anonymous share object obtained.
* @since 9
*/
sptr<Ashmem> ReadAshmem();
/**
* @brief Clear the file descriptor.
* @return void
* @since 9
*/
void ClearFileDescriptor();
/**
* @brief Sets the Clear specified file descriptor flag.
* @return void
* @since 9
*/
void SetClearFdFlag()
{
needCloseFd_ = true;
};
/**
* @brief Append a MessageParcel object to the end of the current MessageParcel.
* @param data Indicates the data to append.
* @return Returns <b>true</b> if append succeeds; returns <b>false</b> Otherwise.
* @since 9
*/
bool Append(MessageParcel &data);
private:
#ifndef CONFIG_IPC_SINGLE
/**
* @brief Write to the DBinder proxy object.
* @param object Indicates an IRemoteObject type object.
* @param handle Indicates the handle to write.
* @param stubIndex Indicates the stub index to write to.
* @return Returns <b>true</b> if the write succeeds; returns <b>false</b> otherwise.
* @since
*/
bool WriteDBinderProxy(const sptr<IRemoteObject> &object, uint32_t handle, uint64_t stubIndex);
#endif
static constexpr size_t MAX_RAWDATA_SIZE = 128 * 1024 * 1024; // 128M
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -24,7 +24,12 @@ protected:
PeerHolder(const sptr<IRemoteObject> &object);
~PeerHolder() = default;
/**
* @brief Gets the proxy object.
* @return Returns the IRemoteObject pointer object.
* @since 9
*/
sptr<IRemoteObject> Remote();
private:
......
......@@ -20,6 +20,7 @@
#include "refbase.h"
namespace OHOS {
//Description of caller information parameters.
struct CallingInfo {
pid_t callingPid;
pid_t callingUid;
......@@ -30,6 +31,7 @@ namespace OHOS {
int activeStatus;
};
//NAPI caller information parameter description.
struct NAPI_CallingInfo {
napi_value callingPid;
napi_value callingUid;
......@@ -41,19 +43,68 @@ namespace OHOS {
};
EXTERN_C_START
/**
* @brief Export NAPIRemote object.
* @param env Indicates the environment in which NAPI is called.
* @param exports Indicates the NAPI exporter.
* @return Returns the exporter of NAPI.
* @since 9
*/
napi_value NAPIRemoteObjectExport(napi_env env, napi_value exports);
EXTERN_C_END
/**
* @brief Create a JavaScript proxy object.
* @param env Indicates the environment in which NAPI is called.
* @param target Indicates the IRemoteObject pointer object.
* @return Returns the created proxy object.
* @since 9
*/
napi_value NAPI_ohos_rpc_CreateJsRemoteObject(napi_env env, const sptr<IRemoteObject> target);
/**
* @brief Get a native remote object.
* @param env Indicates the environment in which NAPI is called.
* @param object Indicates the object obtained.
* @return Returns the IRemoteObject point object.
* @since 9
*/
sptr<IRemoteObject> NAPI_ohos_rpc_getNativeRemoteObject(napi_env env, napi_value object);
/**
* @brief Gets remote proxy object caller information.
* @param newCallingInfoParam Indicates the caller information.
* @return void
* @since 9
*/
void NAPI_RemoteObject_getCallingInfo(CallingInfo &newCallingInfoParam);
/**
* @brief Saves caller information for the old remote proxy object.
* @param env Indicates the environment in which NAPI is called.
* @param oldCallingInfo Indicates the old caller information.
* @return void
* @since 9
*/
void NAPI_RemoteObject_saveOldCallingInfo(napi_env env, NAPI_CallingInfo &oldCallingInfo);
/**
* @brief Sats caller information for the new remote proxy object.
* @param env Indicates the environment in which NAPI is called.
* @param newCallingInfoParam Indicates the new caller information.
* @return void
* @since 9
*/
void NAPI_RemoteObject_setNewCallingInfo(napi_env env, const CallingInfo &newCallingInfoParam);
/**
* @brief Resets caller information for the old remote proxy object.
* @param env Indicates the environment in which NAPI is called.
* @param oldCallingInfo Indicates the old caller information.
* @return void
* @since 9
*/
void NAPI_RemoteObject_resetOldCallingInfo(napi_env env, NAPI_CallingInfo &oldCallingInfo);
}
#endif
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -46,17 +46,20 @@ constexpr int RPC_TOKENID_SUPPORT_VERSION = 2;
constexpr int ENCRYPT_HEAD_LEN = 28;
constexpr int ENCRYPT_LENGTH = 4;
//Description of the device identification information parameter.
struct DeviceIdInfo {
uint32_t tokenId;
char fromDeviceId[DEVICEID_LENGTH + 1];
char toDeviceId[DEVICEID_LENGTH + 1];
};
//Description of the DHandle entry head parameter.
struct DHandleEntryHead {
uint32_t len;
uint32_t version;
};
//Description of the DHandle entry TxRx parameter.
struct DHandleEntryTxRx {
struct DHandleEntryHead head;
uint32_t transType;
......@@ -74,6 +77,7 @@ struct DHandleEntryTxRx {
uint32_t uid;
};
//SessionInfo parameter description.
struct SessionInfo {
uint32_t seqNumber;
uint32_t type;
......@@ -85,6 +89,7 @@ struct SessionInfo {
struct DeviceIdInfo deviceIdInfo;
};
//Enumerate DBinder message codes.
enum DBinderCode {
MESSAGE_AS_INVOKER = 1,
MESSAGE_AS_REPLY = 2,
......@@ -93,6 +98,7 @@ enum DBinderCode {
MESSAGE_AS_REPLY_TOKENID = 5,
};
//Enumerate the returned DBinder error codes.
enum DBinderErrorCode {
DBINDER_OK = 100,
STUB_INVALID = 101,
......@@ -109,6 +115,7 @@ enum DBinderErrorCode {
SESSION_NAME_INVALID = 112,
};
//Description of thread locking information parameters.
struct ThreadLockInfo {
std::mutex mutex;
std::string networkId;
......@@ -121,27 +128,178 @@ public:
DBinderService();
virtual ~DBinderService();
public:
/**
* @brief Obtains an instance.
* @return Returns a DBinderService type pointer object.
* @since 9
*/
static sptr<DBinderService> GetInstance();
/**
* @brief Convert device ID to security string for printing.
* @param deviceID Indicates the device ID to be converted.
* @return Returns the converted security device ID.
* @since 9
*/
static std::string ConvertToSecureDeviceID(const std::string &deviceID);
/**
* @brief Start the DBinder service.
* @param callbackImpl Indicates a callback of type RpcSystemAbilityCallback.
* @return Returns <b>true</b> if the service started successfully; returns <b>false</b> otherwise.
* @since 9
*/
bool StartDBinderService(std::shared_ptr<RpcSystemAbilityCallback> &callbackImpl);
/**
* @brief Make a remote binding.
* @param serviceName Indicates the service name.
* @param deviceID Indicates the device ID.
* @param binderObject Indicates the object to be binder.
* @param pid Indicates the value of pid.
* @param uid Indicates the value of uid.
* @return Returns the DBinderServiceStuble pointer object.
* @since 9
*/
sptr<DBinderServiceStub> MakeRemoteBinder(const std::u16string &serviceName,
const std::string &deviceID, int32_t binderObject, uint32_t pid = 0, uint32_t uid = 0);
/**
* @brief Register the remote agent.
* @param serviceName Indicates the service name.
* @param binderObject Indicates the IRemoteObject pointer object to be binder.
* @return Returns <b>true</b> if the registration successful; returns <b>false</b> otherwise.
* @since 9
*/
bool RegisterRemoteProxy(std::u16string serviceName, sptr<IRemoteObject> binderObject);
/**
* @brief Register the remote agent.
* @param serviceName Indicates the service name.
* @param systemAbilityId Indicatesthe system ability ID.
* @return Returns <b>true</b> if the registration successful; returns <b>false</b> otherwise.
* @since 9
*/
bool RegisterRemoteProxy(std::u16string serviceName, int32_t systemAbilityId);
/**
* @brief Processing remote messaging tasks.
* @param message Indicates the delivered message belongs to the DHandleEntryTxR structure.
* @return Returns <b>true</b> if the processing is successful; returns <b>false</b> otherwise.
* @since 9
*/
bool OnRemoteMessageTask(std::shared_ptr<struct DHandleEntryTxRx> message);
/**
* @brief Register an asynchronous message task.
* @param message Indicates the delivered message belongs to the DHandleEntryTxR structure.
* @return void
* @since 9
*/
void AddAsynMessageTask(std::shared_ptr<struct DHandleEntryTxRx> message);
/**
* @brief Query the session object.
* @param stub Indicates a stub that can be used to query a session object.
* @return The returned result belongs to the SessionInfo structure.
* @since 9
*/
std::shared_ptr<struct SessionInfo> QuerySessionObject(binder_uintptr_t stub);
/**
* @brief Detach the remote object death notification.
* @param object Indicates the IRemoteObject pointer object.
* @return Returns <b>true</b> if the registration successful; returns <b>false</b> otherwise.
* @since 9
*/
bool DetachDeathRecipient(sptr<IRemoteObject> object);
/**
* @brief Attach the remote object death notification.
* @param object Indicates the IRemoteObject pointer object.
* @param deathRecipient Indicates the the callback to attach.
* @return Returns <b>true</b> if the operation succeeds; returns <b>false</b> otherwise.
* @since 9
*/
bool AttachDeathRecipient(sptr<IRemoteObject> object, sptr<IRemoteObject::DeathRecipient> deathRecipient);
/**
* @brief Query the remote object death notification.
* @param object Indicates the IRemoteObject pointer object.
* @return Returns the results of the found death notice.
* @since 9
*/
sptr<IRemoteObject::DeathRecipient> QueryDeathRecipient(sptr<IRemoteObject> object);
/**
* @brief Detach the callback proxy object.
* @param object Indicates the IRemoteObject pointer object.
* @return Returns <b>true</b> if the operation succeeds; returns <b>false</b> otherwise.
* @since 9
*/
bool DetachCallbackProxy(sptr<IRemoteObject> object);
/**
* @brief Attach the callback proxy object.
* @param object Indicates the IRemoteObject pointer object.
* @param dbStub Indicates a service communication stub across devices.
* @return Returns <b>true</b> if the operation succeeds; returns <b>false</b> otherwise.
* @since 9
*/
bool AttachCallbackProxy(sptr<IRemoteObject> object, DBinderServiceStub *dbStub);
/**
* @brief Notification service death.
* @param serviceName Indicates the service name.
* @param deviceID Indicates the device ID.
* @return Returns {@code ERR_NONE} if valid notifications; returns an error code if the operation fails.
* @since 9
*/
int32_t NoticeServiceDie(const std::u16string &serviceName, const std::string &deviceID);
/**
* @brief Notification device death.
* @param deviceID Indicates the device ID.
* @return Returns {@code ERR_NONE} if valid notifications; returns an error code if the operation fails.
* @since 9
*/
int32_t NoticeDeviceDie(const std::string &deviceID);
/**
* @brief Create a databus(Dbinder) name.
* @param uid Indicates the UID of databus(Dbinder).
* @param pid Indicates the PID of databus(Dbinder).
* @return Returns the corresponding sessionName.
* @since 9
*/
std::string CreateDatabusName(int uid, int pid);
/**
* @brief Detach the proxy object.
* @param binderObject Indicates the object to which it is bound.
* @return Returns <b>true</b> if the operation succeeds; returns <b>false</b> otherwise.
* @since 9
*/
bool DetachProxyObject(binder_uintptr_t binderObject);
/**
* @brief A callback when a system ability is loaded completely.
* @param srcNetworkId Indicates The network ID of the path.
* @param systemAbilityId Indicates system capability ID.
* @param remoteObject Indicates a remote object.
* @return void
* @since 9
*/
void LoadSystemAbilityComplete(const std::string& srcNetworkId, int32_t systemAbilityId,
const sptr<IRemoteObject>& remoteObject);
/**
* @brief Close the process session.
* @param session Indicates the session to close.
* @return Returns <b>true</b> if the shutdown is successful; returns <b>false</b> otherwise.
* @since 9
*/
bool ProcessOnSessionClosed(std::shared_ptr<Session> session);
private:
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2023 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
......@@ -32,11 +32,48 @@ public:
explicit DBinderServiceStub(const std::string &serviceName, const std::string &deviceID,
binder_uintptr_t binderObject);
~DBinderServiceStub();
/**
* @brief Gets the process protocol.
* @param code Indicates the message code of the request.
* @param data Indicates the object storing the data to be sent.
* @param reply Indicates the object receiving the response data.
* @param option Indicates a synchronous (default) or asynchronous request.
* @return Returns {@code 0} if valid notifications; returns an error code if the operation fails.
* @since 9
*/
int32_t ProcessProto(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
/**
* @brief Response processing of the request.
* @param code Indicates the service request code sent from the peer end.
* @param data Indicates the object sent from the peer end.
* @param reply Indicates the response message object sent from the remote service.
* @param options Indicates whether the operation is synchronous or asynchronous.
* @return Returns {@code 0} if the operation succeeds; returns an error code if the operation fails.
* @since 9
*/
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
/**
* @brief Obtains the service name.
* @return Returns the service name.
* @since 9
*/
const std::string &GetServiceName();
/**
* @brief Obtain the device ID.
* @return Returns the device ID.
* @since 9
*/
const std::string &GetDeviceID();
/**
* @brief Obtain the binder object.
* @return Returns the binder object.
* @since 9
*/
binder_uintptr_t GetBinderObject() const;
private:
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Copyright (C) 2022-2023 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
......@@ -21,7 +21,22 @@
namespace OHOS {
class RpcSystemAbilityCallback {
public:
/**
* @brief Obtains the specified system capability of the remote device.
* @param systemAbilityId Indicates system capability ID.
* @return Returns the IRemoteObject pointer object.
* @since 9
*/
virtual sptr<IRemoteObject> GetSystemAbilityFromRemote(int32_t systemAbilityId) = 0;
/**
* @brief Load the specified system capability of the remote device.
* @param srcNetworkId Indicates The network ID of the path.
* @param systemAbilityId Indicates system capability ID.
* @return Returns <b>true</b> if the operation succeeds; returns <b>false</b> otherwise.
* @since 9
*/
virtual bool LoadSystemAbilityFromRemote(const std::string& srcNetworkId, int32_t systemAbilityId)
{
return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册