From 121d4f0a49fe8d0a8e6c4991751d3bac1ddc6f72 Mon Sep 17 00:00:00 2001 From: hmilylmk Date: Thu, 15 Sep 2022 16:38:31 +0800 Subject: [PATCH] dsoftbus: remove ipc module * remove ipc module source files. * remove ipc module compile content. Signed-off-by: hmilylmk --- dsoftbus/depend/BUILD.gn | 29 --- dsoftbus/depend/ipc/include/ipc_base.h | 56 ------ dsoftbus/depend/ipc/include/ipc_center.h | 24 --- dsoftbus/depend/ipc/include/ipc_object_stub.h | 17 -- dsoftbus/depend/ipc/include/ipc_skeleton.h | 34 ---- dsoftbus/depend/ipc/include/ipc_types.h | 1 - dsoftbus/depend/ipc/include/iremote_broker.h | 15 -- dsoftbus/depend/ipc/include/iremote_object.h | 42 ----- dsoftbus/depend/ipc/include/iremote_parcel.h | 1 - dsoftbus/depend/ipc/include/iremote_proxy.h | 42 ----- dsoftbus/depend/ipc/include/iremote_stub.h | 27 --- dsoftbus/depend/ipc/include/message_option.h | 10 - dsoftbus/depend/ipc/include/message_parcel.h | 33 ---- dsoftbus/depend/ipc/include/system_ability.h | 44 ----- .../ipc/include/system_ability_definition.h | 15 -- dsoftbus/depend/ipc/ipc_center.cpp | 99 ---------- dsoftbus/depend/ipc/ipc_object_stub.cpp | 16 -- dsoftbus/depend/ipc/ipc_skeleton.cpp | 174 ------------------ dsoftbus/depend/ipc/iremote_object.cpp | 70 ------- dsoftbus/depend/ipc/message_parcel.cpp | 88 --------- dsoftbus/depend/ohos.build | 19 -- 21 files changed, 856 deletions(-) delete mode 100644 dsoftbus/depend/ipc/include/ipc_base.h delete mode 100644 dsoftbus/depend/ipc/include/ipc_center.h delete mode 100644 dsoftbus/depend/ipc/include/ipc_object_stub.h delete mode 100644 dsoftbus/depend/ipc/include/ipc_skeleton.h delete mode 100644 dsoftbus/depend/ipc/include/ipc_types.h delete mode 100644 dsoftbus/depend/ipc/include/iremote_broker.h delete mode 100644 dsoftbus/depend/ipc/include/iremote_object.h delete mode 100644 dsoftbus/depend/ipc/include/iremote_parcel.h delete mode 100644 dsoftbus/depend/ipc/include/iremote_proxy.h delete mode 100644 dsoftbus/depend/ipc/include/iremote_stub.h delete mode 100644 dsoftbus/depend/ipc/include/message_option.h delete mode 100644 dsoftbus/depend/ipc/include/message_parcel.h delete mode 100644 dsoftbus/depend/ipc/include/system_ability.h delete mode 100644 dsoftbus/depend/ipc/include/system_ability_definition.h delete mode 100644 dsoftbus/depend/ipc/ipc_center.cpp delete mode 100644 dsoftbus/depend/ipc/ipc_object_stub.cpp delete mode 100644 dsoftbus/depend/ipc/ipc_skeleton.cpp delete mode 100644 dsoftbus/depend/ipc/iremote_object.cpp delete mode 100644 dsoftbus/depend/ipc/message_parcel.cpp diff --git a/dsoftbus/depend/BUILD.gn b/dsoftbus/depend/BUILD.gn index 72bf2893..14a5b0e7 100644 --- a/dsoftbus/depend/BUILD.gn +++ b/dsoftbus/depend/BUILD.gn @@ -17,35 +17,6 @@ ohos_shared_library("libhilog") { ] } -config("ipc_config") { - include_dirs = [ "ipc/include", "//utils/native/base/include" ] -} - -group("ipc_single") { - deps = [ "//depend:ipc_core" ] - public_configs = [ ":ipc_config" ] -} - -ohos_shared_library("ipc_core") { - include_dirs = [ - "ipc/include", - ] - - sources = [ - "ipc/ipc_center.cpp", - "ipc/ipc_object_stub.cpp", - "ipc/ipc_skeleton.cpp", - "ipc/iremote_object.cpp", - "ipc/message_parcel.cpp", - ] - - deps = [ - "//utils/native/base:utils", - ] - - public_configs = [ ":ipc_config" ] -} - group("system_ability_fwk") { } diff --git a/dsoftbus/depend/ipc/include/ipc_base.h b/dsoftbus/depend/ipc/include/ipc_base.h deleted file mode 100644 index d289e510..00000000 --- a/dsoftbus/depend/ipc/include/ipc_base.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _IPC_BASE_H_ -#define _IPC_BASE_H_ - -#include -#include -#include -#include -#include -#include - -#define IPC_LOG(fmt, args...) \ - printf("[IPC LOG %s:%u]" fmt, __FILE__, __LINE__, ##args); - -extern key_t g_send_shm_key; -extern key_t g_receive_shm_key; - -const int IPC_SHM_FLAG = IPC_CREAT | 0666; - -const size_t DATA_SIZE = 0x20000; - -struct IpcShmData { - size_t inputSz; - size_t outputSz; - char inputData[DATA_SIZE]; - char outputData[DATA_SIZE]; - volatile bool needReply; - uint32_t requestCode; - volatile bool containFd; -}; - -static inline IpcShmData *OpenShmCommon(key_t shmKey, int flag) -{ - int shmFd = shmget(shmKey, sizeof(IpcShmData), flag); - if (shmFd < 0) { - IPC_LOG("Get shm failed\n"); - return nullptr; - } - void *shmPtr = shmat(shmFd, 0, 0); - if (shmPtr == (void *)-1) { - IPC_LOG("Map shm failed\n"); - return nullptr; - } - return (IpcShmData *)shmPtr; -} - -static inline IpcShmData *OpenShm(key_t shmKey) -{ - return OpenShmCommon(shmKey, IPC_SHM_FLAG); -} - -static inline IpcShmData *OpenShmExcl(key_t shmKey) -{ - return OpenShmCommon(shmKey, IPC_SHM_FLAG | IPC_EXCL); -} - -#endif // _IPC_BASE_H_ diff --git a/dsoftbus/depend/ipc/include/ipc_center.h b/dsoftbus/depend/ipc/include/ipc_center.h deleted file mode 100644 index ebf9891c..00000000 --- a/dsoftbus/depend/ipc/include/ipc_center.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _IPC_CENTER_H_ -#define _IPC_CENTER_H_ - -#include "iremote_object.h" -#include "ipc_object_stub.h" - -namespace OHOS { - -class IpcCenter { -public: - IpcCenter(); - bool Init(bool isServer, IPCObjectStub *stub); - bool ThreadCreate(); - void ProcessHandle(); -private: - bool ShmInit(key_t ShmKey); - size_t threadNum_; - IPCObjectStub *ipcStub_; - bool needStop_; -}; - -} // namespace OHOS - -#endif //_IPC_CENTER_H_ diff --git a/dsoftbus/depend/ipc/include/ipc_object_stub.h b/dsoftbus/depend/ipc/include/ipc_object_stub.h deleted file mode 100644 index ec93b6d7..00000000 --- a/dsoftbus/depend/ipc/include/ipc_object_stub.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _IPC_OBJECT_STUB_H_ -#define _IPC_OBJECT_STUB_H_ - -#include "iremote_object.h" - -namespace OHOS { - -class IPCObjectStub : public IRemoteObject { -public: - IPCObjectStub(); - ~IPCObjectStub(); - virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); -}; - -} // namespace OHOS - -#endif // _IPC_OBJECT_STUB_H_ \ No newline at end of file diff --git a/dsoftbus/depend/ipc/include/ipc_skeleton.h b/dsoftbus/depend/ipc/include/ipc_skeleton.h deleted file mode 100644 index 45260cbf..00000000 --- a/dsoftbus/depend/ipc/include/ipc_skeleton.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _IPC_SKELETON_H_ -#define _IPC_SKELETON_H_ - -#include -#include - -#include "parcel.h" -#include "refbase.h" - -namespace OHOS { - -class IRemoteObject; - -class IPCSkeleton { -public: - IPCSkeleton() = default; - ~IPCSkeleton() = default; - static pid_t GetCallingPid(); - static uid_t GetCallingUid(); - static sptr< IRemoteObject > GetContextObject(); - static bool SetContextObject(sptr< IRemoteObject > &object); - static bool SocketListening(bool isServer); - static int SocketReadFd(); - static bool SocketWriteFd(int fd); - -private: - static sptr< IRemoteObject > obj_; - static int socketFd_; - static bool isServer_; -}; - -} // namespace OHOS - -#endif // _IPC_SKELETON_H_ diff --git a/dsoftbus/depend/ipc/include/ipc_types.h b/dsoftbus/depend/ipc/include/ipc_types.h deleted file mode 100644 index 80f50cef..00000000 --- a/dsoftbus/depend/ipc/include/ipc_types.h +++ /dev/null @@ -1 +0,0 @@ -/* empty head files for compile */ diff --git a/dsoftbus/depend/ipc/include/iremote_broker.h b/dsoftbus/depend/ipc/include/iremote_broker.h deleted file mode 100644 index e6f54250..00000000 --- a/dsoftbus/depend/ipc/include/iremote_broker.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _IREMOTE_BROKER_H -#define _IREMOTE_BROKER_H - -#ifdef __cplusplus - -namespace OHOS { - -template class BrokerDelegator { -}; - -}; - -#endif - -#endif diff --git a/dsoftbus/depend/ipc/include/iremote_object.h b/dsoftbus/depend/ipc/include/iremote_object.h deleted file mode 100644 index a955172e..00000000 --- a/dsoftbus/depend/ipc/include/iremote_object.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _IPC_REMOTE_OBJECT_H_ -#define _IPC_REMOTE_OBJECT_H_ - -#include "message_parcel.h" -#include "message_option.h" - -namespace OHOS { - -class IRemoteBroker : public virtual RefBase { -public: - IRemoteBroker() = default; - virtual ~IRemoteBroker() override = default; - virtual sptr< IRemoteObject > AsObject() = 0; - static inline sptr< IRemoteBroker > AsImplement(const sptr< IRemoteObject > &object) - { - return nullptr; - } -}; - -#define DECLARE_INTERFACE_DESCRIPTOR(DESCRIPTOR) \ - static inline const std::u16string metaDescriptor_ = {DESCRIPTOR} ; \ - static inline const std::u16string &GetDescriptor() \ - { \ - return metaDescriptor_; \ - } - -class IRemoteObject : public virtual Parcelable { -public: - class DeathRecipient : public RefBase { - public: - virtual void OnRemoteDied(const wptr< IRemoteObject > &object) {} - }; - - virtual int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); - virtual bool AddDeathRecipient(const sptr< DeathRecipient > &recipient); - virtual bool RemoveDeathRecipient(const sptr< DeathRecipient > &recipient); - virtual bool Marshalling(Parcel &parcel) const override; -}; - -} // namespace OHOS - -#endif // _IPC_REMOTE_OBJECT_H_ diff --git a/dsoftbus/depend/ipc/include/iremote_parcel.h b/dsoftbus/depend/ipc/include/iremote_parcel.h deleted file mode 100644 index 80f50cef..00000000 --- a/dsoftbus/depend/ipc/include/iremote_parcel.h +++ /dev/null @@ -1 +0,0 @@ -/* empty head files for compile */ diff --git a/dsoftbus/depend/ipc/include/iremote_proxy.h b/dsoftbus/depend/ipc/include/iremote_proxy.h deleted file mode 100644 index 4078c356..00000000 --- a/dsoftbus/depend/ipc/include/iremote_proxy.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef OHOS_IPC_IREMOTE_PROXY_H -#define OHOS_IPC_IREMOTE_PROXY_H - -#include "ipc_skeleton.h" - -namespace OHOS { -template class IRemoteProxy : public INTERFACE { -public: - explicit IRemoteProxy(const sptr &object); - ~IRemoteProxy() override = default; - sptr Remote(); - -protected: - sptr AsObject() override; - -private: - const sptr remoteObj_; -}; - -template -sptr IRemoteProxyremoteObj_ = nullptr; - -template -IRemoteProxy::IRemoteProxy(const sptr &object) : remoteObj_(object) {} - -template -sptr IRemoteProxy::AsObject() -{ - if (remoteObj_ != nullptr) { - return remoteObj_; - } - return IPCSkeleton::GetContextObject(); -} - -template -sptr IRemoteProxy::Remote() -{ - return AsObject(); -} - -} // namespece OHOS -#endif // OHOS_IPC_IREMOTE_PROXY_H \ No newline at end of file diff --git a/dsoftbus/depend/ipc/include/iremote_stub.h b/dsoftbus/depend/ipc/include/iremote_stub.h deleted file mode 100644 index 3b5184f9..00000000 --- a/dsoftbus/depend/ipc/include/iremote_stub.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _IPC_IREMOTE_STUB_H_ -#define _IPC_IREMOTE_STUB_H_ - -#include "ipc_object_stub.h" - -namespace OHOS { - -template< typename INTERFACE > -class IRemoteStub : public IPCObjectStub, public INTERFACE { -public: - IRemoteStub(); - virtual ~IRemoteStub() = default; - sptr< IRemoteObject > AsObject() override; -}; - -template< typename INTERFACE > -IRemoteStub< INTERFACE >::IRemoteStub() : IPCObjectStub() {} - -template< typename INTERFACE > -sptr< IRemoteObject > IRemoteStub< INTERFACE >::AsObject() -{ - return this; -} - -} // namespace OHOS - -#endif // _IPC_IREMOTE_STUB_H_ \ No newline at end of file diff --git a/dsoftbus/depend/ipc/include/message_option.h b/dsoftbus/depend/ipc/include/message_option.h deleted file mode 100644 index e5904b92..00000000 --- a/dsoftbus/depend/ipc/include/message_option.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _MESSAGE_OPTION_H_ -#define _MESSAGE_OPTION_H_ - -namespace OHOS { - -class MessageOption {}; - -} - -#endif // _MESSAGE_OPTION_H_ \ No newline at end of file diff --git a/dsoftbus/depend/ipc/include/message_parcel.h b/dsoftbus/depend/ipc/include/message_parcel.h deleted file mode 100644 index e3ed991b..00000000 --- a/dsoftbus/depend/ipc/include/message_parcel.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _MESSAGE_PARCEL_H_ -#define _MESSAGE_PARCEL_H_ - -#include -#include "parcel.h" -#include "refbase.h" - -namespace OHOS { - -class IRemoteObject; -class MessageParcel : public Parcel { -public: - MessageParcel(); - ~MessageParcel(); - bool WriteFileDescriptor(int fd); - int ReadFileDescriptor(); - bool WriteRawData(const void *data, size_t size); - const void *ReadRawData(size_t size); - bool ContainFileDescriptors() const; - sptr< IRemoteObject > ReadRemoteObject(); - bool WriteRemoteObject(const sptr< IRemoteObject > &object); - bool WriteInterfaceToken(std::u16string name); - std::u16string ReadInterfaceToken(); - size_t GetRawDataSize() const; -private: - static constexpr size_t MAX_RAWDATA_SIZE = 128 * 1024 * 1024; // 128M - int fd_; - size_t rawDataSize_; -}; - -} //namespace OHOS - -#endif // _MESSAGE_PARCEL_H_ diff --git a/dsoftbus/depend/ipc/include/system_ability.h b/dsoftbus/depend/ipc/include/system_ability.h deleted file mode 100644 index 8d893481..00000000 --- a/dsoftbus/depend/ipc/include/system_ability.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _SYSTEM_ABILITY_H -#define _SYSTEM_ABILITY_H - -#ifdef __cplusplus -//#include -//#include -#include -//#include -#include "parcel.h" - -#define DECLARE_SYSTEM_ABILITY(className) \ - public: \ - virtual std::string GetClassName() override { \ - return #className; \ - } - -#define DECLARE_BASE_SYSTEM_ABILITY(className) \ - public: \ - virtual std::string GetClassName() = 0; - -namespace OHOS { - -#define REGISTER_SYSTEM_ABILITY_BY_ID(abilityClassName, systemAbilityId, runOnCreate) \ - const bool abilityClassName##_##RegisterResult = \ - SystemAbility::MakeAndRegisterAbility(new abilityClassName(systemAbilityId, runOnCreate)); - -class IRemoteObject; - -class SystemAbility { - DECLARE_BASE_SYSTEM_ABILITY(SystemAbility); - public: - static bool MakeAndRegisterAbility(SystemAbility* systemAbility) {return true;} - bool Publish(sptr systemAbility) {return true;} - protected: - SystemAbility(bool runOnCreate = false) {} - SystemAbility(int32_t systemAbilityId, bool runOnCreate = false) {} - virtual void OnStart() = 0; - virtual void OnStop() = 0; -}; - -}; -#endif - -#endif diff --git a/dsoftbus/depend/ipc/include/system_ability_definition.h b/dsoftbus/depend/ipc/include/system_ability_definition.h deleted file mode 100644 index 5634882e..00000000 --- a/dsoftbus/depend/ipc/include/system_ability_definition.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _SYSTEM_ABILITY_DEF_H -#define _SYSTEM_ABILITY_DEF_H - -#ifdef __cplusplus - -namespace OHOS { - -enum { - SOFTBUS_SERVER_SA_ID = 4700, -}; - -}; -#endif - -#endif diff --git a/dsoftbus/depend/ipc/ipc_center.cpp b/dsoftbus/depend/ipc/ipc_center.cpp deleted file mode 100644 index b51f39d1..00000000 --- a/dsoftbus/depend/ipc/ipc_center.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include -#include - -#include "ipc_base.h" -#include "ipc_center.h" -#include "ipc_skeleton.h" - -namespace OHOS { - -IpcCenter::IpcCenter() : threadNum_(0), needStop_(false) {} - -bool IpcCenter::ShmInit(key_t shmKey) -{ - IpcShmData *shmPtr = OpenShm(shmKey); - if (shmPtr == nullptr) { - IPC_LOG("Create shm with key=0x%x\n", shmKey); - return false; - } - shmPtr->needReply = false; - shmPtr->containFd = false; - shmdt((void *)shmPtr); - return true; -} - -bool IpcCenter::Init(bool isServer, IPCObjectStub *stub) -{ - if (stub == nullptr) { - IPC_LOG("Invalid stub\n"); - return false; - } - - if (isServer && (!ShmInit(g_send_shm_key) || !ShmInit(g_receive_shm_key))) { - IPC_LOG("Shm inti failed\n"); - return false; - } - - if (isServer) { - std::swap(g_send_shm_key, g_receive_shm_key); - } - - ipcStub_ = stub; - - if (!IPCSkeleton::SocketListening(isServer)) { - IPC_LOG("Starting socket listen failed\n"); - return false; - } - - return ThreadCreate(); -} - -void IpcCenter::ProcessHandle() -{ - do { - IpcShmData *shmPtr = OpenShm(g_receive_shm_key); - if (shmPtr == nullptr) { - return; - } - while (!shmPtr->needReply) { - usleep(10); - } - MessageParcel data, reply; - MessageOption option; - data.WriteUnpadBuffer(shmPtr->inputData, shmPtr->inputSz); - if (shmPtr->containFd) { - shmPtr->containFd = false; - if (!data.WriteFileDescriptor(IPCSkeleton::SocketReadFd())) { - IPC_LOG("Process file descriptor failed"); - shmdt((void *)shmPtr); - return; - } - } - ipcStub_->OnRemoteRequest(shmPtr->requestCode, data, reply, option); - shmPtr->outputSz = reply.GetDataSize(); - memcpy(shmPtr->outputData, (void*)reply.GetData(), shmPtr->outputSz); - if (reply.ContainFileDescriptors()) { - if (!IPCSkeleton::SocketWriteFd(reply.ReadFileDescriptor())) { - IPC_LOG("Send file descriptor in reply failed\n") - shmdt((void *)shmPtr); - return; - } - shmPtr->containFd = true; - } - shmPtr->needReply = false; - shmdt((void*)shmPtr); - } while (!needStop_); -} - -bool IpcCenter::ThreadCreate() -{ - if (!threadNum_) { - ++threadNum_; - std::thread new_thread(std::bind(&IpcCenter::ProcessHandle, this)); - new_thread.detach(); - return true; - } - return false; -} - -} // namespace OHOS diff --git a/dsoftbus/depend/ipc/ipc_object_stub.cpp b/dsoftbus/depend/ipc/ipc_object_stub.cpp deleted file mode 100644 index 7cae93f1..00000000 --- a/dsoftbus/depend/ipc/ipc_object_stub.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "ipc_base.h" -#include "ipc_object_stub.h" - -namespace OHOS { - -IPCObjectStub::IPCObjectStub() {} - -IPCObjectStub::~IPCObjectStub() {} - -int IPCObjectStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - IPC_LOG("IPCObjectStub::OnRemoteRequest Called\n"); - return -1; -} - -} // namespace OHOS diff --git a/dsoftbus/depend/ipc/ipc_skeleton.cpp b/dsoftbus/depend/ipc/ipc_skeleton.cpp deleted file mode 100644 index 9f70d36d..00000000 --- a/dsoftbus/depend/ipc/ipc_skeleton.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include -#include -#include - -#include "ipc_base.h" -#include "iremote_object.h" -#include "ipc_skeleton.h" - -namespace OHOS { - -const char *IPC_SERVER_SOCKET_ADDR = "/tmp/ipc.socket.server"; -const char *IPC_CLIENT_SOCKET_ADDR = "/tmp/ipc.socket.client"; - -sptr< IRemoteObject > IPCSkeleton::obj_ = nullptr; -int IPCSkeleton::socketFd_ = -1; -bool IPCSkeleton::isServer_ = true; - -pid_t IPCSkeleton::GetCallingPid() -{ - return getpid(); -} - -uid_t IPCSkeleton::GetCallingUid() -{ - return getuid(); -} - -bool IPCSkeleton::SetContextObject(sptr< IRemoteObject > &object) -{ - obj_ = object; - return true; -} - -sptr< IRemoteObject > IPCSkeleton::GetContextObject() -{ - if (obj_ == nullptr) { - obj_ = new IRemoteObject(); - } - return obj_; -} - -bool IPCSkeleton::SocketListening(bool isServer) -{ - if (socketFd_ >= 0) { - IPC_LOG("Socket is opened\n"); - return false; - } - - isServer_ = isServer; - - const char *ipcPath = isServer ? IPC_SERVER_SOCKET_ADDR : IPC_CLIENT_SOCKET_ADDR; - unlink(ipcPath); - - socketFd_ = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0); - if (socketFd_ < 0) { - IPC_LOG("Socket failed errno=%d\n", errno); - return false; - } - - struct sockaddr_un socketAddr; - memset(&socketAddr, 0, sizeof(socketAddr)); - socketAddr.sun_family = AF_UNIX; - strcpy(socketAddr.sun_path, ipcPath); - int ret = bind(socketFd_, (struct sockaddr *)&socketAddr, sizeof(socketAddr)); - if (ret < 0) { - IPC_LOG("Bind socket failed errno=%d\n", errno); - close(socketFd_); - socketFd_ = -1; - return false; - } - - ret = listen(socketFd_, 3); - if (ret < 0) { - IPC_LOG("listen socket failed errno=%d\n", errno); - close(socketFd_); - socketFd_ = -1; - return false; - } - return true; -} - -int IPCSkeleton::SocketReadFd() -{ - if (socketFd_ < 0) { - IPC_LOG("Read fd from an uninitialized socket\n"); - return -1; - } - - struct sockaddr_un acceptAddr; - socklen_t sockLen = sizeof(acceptAddr); - int recvFd = accept(socketFd_, (struct sockaddr *)&acceptAddr, &sockLen); - if (recvFd < 0) { - IPC_LOG("Accept failed errno=%d\n", errno); - return -1; - } - - struct msghdr msg; - struct iovec iov[1]; - char buf[100] = ""; - msg.msg_name = nullptr; - msg.msg_namelen = 0; - iov[0].iov_base = buf; - iov[0].iov_len = 100; - msg.msg_iov = iov; - msg.msg_iovlen = 1; - msg.msg_flags = 0; - char cm[CMSG_LEN(sizeof(int))]; - msg.msg_control = cm; - msg.msg_controllen = CMSG_LEN(sizeof(int)); - int ret = recvmsg(recvFd, &msg, 0); - if (ret < 0) { - IPC_LOG("Receive error, errno=%d\n", errno); - close(recvFd); - return -1; - } - - struct cmsghdr *cmsgPtr = CMSG_FIRSTHDR(&msg); - if (cmsgPtr == nullptr || cmsgPtr->cmsg_len != CMSG_LEN(sizeof(int)) || - cmsgPtr->cmsg_level != SOL_SOCKET || - cmsgPtr->cmsg_type != SCM_RIGHTS) { - IPC_LOG("Received wrong data\n"); - close(recvFd); - return -1; - } - close(recvFd); - return *((int *)CMSG_DATA(cmsgPtr)); -} - -bool IPCSkeleton::SocketWriteFd(int fd) -{ - int socketFd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0); - if (socketFd < 0) { - IPC_LOG("Socket failed errno=%d\n", errno); - return false; - } - - struct sockaddr_un socketAddr; - memset(&socketAddr, 0, sizeof(socketAddr)); - socketAddr.sun_family = AF_UNIX; - strcpy(socketAddr.sun_path, isServer_ ? IPC_CLIENT_SOCKET_ADDR : IPC_SERVER_SOCKET_ADDR); - int ret = connect(socketFd, (struct sockaddr *)&socketAddr, sizeof(socketAddr)); - if (ret < 0) { - IPC_LOG("Connect failed errno=%d\n", errno); - close(socketFd); - return false; - } - - struct msghdr msg; - struct iovec iov[1]; - char buf[100] = "IPC Socket Data with File Descriptor"; - msg.msg_name = nullptr; - msg.msg_namelen = 0; - iov[0].iov_base = buf; - iov[0].iov_len = 100; - msg.msg_iov = iov; - msg.msg_iovlen = 1; - msg.msg_flags = 0; - char cm[CMSG_LEN(sizeof(int))]; - msg.msg_control = cm; - msg.msg_controllen = CMSG_LEN(sizeof(int)); - struct cmsghdr *cmsgPtr = CMSG_FIRSTHDR(&msg); - cmsgPtr->cmsg_len = CMSG_LEN(sizeof(int)); - cmsgPtr->cmsg_level = SOL_SOCKET; - cmsgPtr->cmsg_type = SCM_RIGHTS; - *((int *)CMSG_DATA(cmsgPtr)) = fd; - ret = sendmsg(socketFd, &msg, 0); - if (ret < 0) { - IPC_LOG("Send failed errno=%d\n", errno); - } - close(socketFd); - return ret >= 0; -} - -} //namespace OHOS diff --git a/dsoftbus/depend/ipc/iremote_object.cpp b/dsoftbus/depend/ipc/iremote_object.cpp deleted file mode 100644 index 055258d7..00000000 --- a/dsoftbus/depend/ipc/iremote_object.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "ipc_base.h" -#include "iremote_object.h" -#include "ipc_skeleton.h" - -key_t g_send_shm_key = 0x544F53; -key_t g_receive_shm_key = 0x52544F; - -namespace OHOS { - -const int32_t GET_SA_REQUEST_CODE = 2; - -bool IRemoteObject::AddDeathRecipient(const sptr< DeathRecipient > &recipient) -{ - return true; -} - -bool IRemoteObject::RemoveDeathRecipient(const sptr< DeathRecipient > &recipient) -{ - return true; -} - -int IRemoteObject::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - IpcShmData *shmPtr = NULL; - - if (code == GET_SA_REQUEST_CODE) { - return 0; - } - - shmPtr = OpenShm(g_send_shm_key); - if (shmPtr == nullptr) { - return -1; - } - - // waiting previous ipc - while (shmPtr->needReply); - - shmPtr->requestCode = code; - shmPtr->inputSz = data.GetDataSize(); - memcpy(shmPtr->inputData, (void *)data.GetData(), shmPtr->inputSz); - if (data.ContainFileDescriptors()) { - shmPtr->containFd = true; - if (!IPCSkeleton::SocketWriteFd(data.ReadFileDescriptor())) { - IPC_LOG("Send File Descriptor failed\n"); - shmdt((void*)shmPtr); - return -1; - } - } - shmPtr->needReply = true; - - while (shmPtr->needReply); - reply.WriteUnpadBuffer(shmPtr->outputData, shmPtr->outputSz); - if (shmPtr->containFd) { - if (!reply.WriteFileDescriptor(IPCSkeleton::SocketReadFd())) { - IPC_LOG("Reveive reply fd failed"); - shmdt((void *)shmPtr); - return -1; - } - shmPtr->containFd = false; - } - shmdt((void *)shmPtr); - return 0; -} - -bool IRemoteObject::Marshalling(Parcel &parcel) const -{ - return true; -} - -} // namespace OHOS diff --git a/dsoftbus/depend/ipc/message_parcel.cpp b/dsoftbus/depend/ipc/message_parcel.cpp deleted file mode 100644 index 0dba88e0..00000000 --- a/dsoftbus/depend/ipc/message_parcel.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include -#include -#include -#include -#include "ipc_base.h" -#include "message_parcel.h" -#include "ipc_skeleton.h" -#include "iremote_object.h" - -namespace OHOS { - -MessageParcel::MessageParcel() : Parcel(), fd_(-1) {} - -MessageParcel::~MessageParcel() {} - -bool MessageParcel::WriteFileDescriptor(int fd) -{ - if (fd < 0) { - return false; - } - - int dupFd = dup(fd); - if (dupFd < 0) { - return false; - } - - fd_ = dupFd; - - return true; -} - -int MessageParcel::ReadFileDescriptor() -{ - return fd_; -} - -bool MessageParcel::ContainFileDescriptors() const -{ - return fd_ >= 0; -} - -bool MessageParcel::WriteRawData(const void *data, size_t size) -{ - if (data == nullptr || size > MAX_RAWDATA_SIZE) { - return false; - } - if (!WriteInt32(size)) { - return false; - } - rawDataSize_ = size; - return WriteUnpadBuffer(data, size); -} - -const void *MessageParcel::ReadRawData(size_t size) -{ - int32_t bufferSize = ReadInt32(); - if (static_cast< unsigned int >(bufferSize) != size) { - return nullptr; - } - rawDataSize_ = size; - return ReadUnpadBuffer(size); -} - -sptr< IRemoteObject > MessageParcel::ReadRemoteObject() -{ - return IPCSkeleton::GetContextObject(); -} - -bool MessageParcel::WriteRemoteObject(const sptr< IRemoteObject > &object) -{ - return true; -} - -bool MessageParcel::WriteInterfaceToken(std::u16string name) { - return WriteString16(name); -} - -std::u16string MessageParcel::ReadInterfaceToken() -{ - return ReadString16(); -} - -size_t MessageParcel::GetRawDataSize() const -{ - return rawDataSize_; -} - -} //namespace OHOS diff --git a/dsoftbus/depend/ohos.build b/dsoftbus/depend/ohos.build index 5a221cfc..67e63884 100644 --- a/dsoftbus/depend/ohos.build +++ b/dsoftbus/depend/ohos.build @@ -13,25 +13,6 @@ } ] }, - "ipc": { - "module_list": [ ], - "inner_kits": [ - { - "name": "//depend:ipc_single", - "header": { - "header_files": [ ], - "header_base": "//depend" - } - }, - { - "name":"//depend:ipc_core", - "header": { - "header_files": [ ], - "header_base": "//depend" - } - } - ] - }, "ces_standard": { "module_list": [ ], "inner_kits": [ -- Gitee