diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..51c63e29
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,15 @@
+*.tgz filter=lfs diff=lfs merge=lfs -text
+*.trp filter=lfs diff=lfs merge=lfs -text
+*.apk filter=lfs diff=lfs merge=lfs -text
+*.jar filter=lfs diff=lfs merge=lfs -text
+*.mp4 filter=lfs diff=lfs merge=lfs -text
+*.zip filter=lfs diff=lfs merge=lfs -text
+*.asm filter=lfs diff=lfs merge=lfs -text
+*.8svn filter=lfs diff=lfs merge=lfs -text
+*.9svn filter=lfs diff=lfs merge=lfs -text
+*.dylib filter=lfs diff=lfs merge=lfs -text
+*.exe filter=lfs diff=lfs merge=lfs -text
+*.a filter=lfs diff=lfs merge=lfs -text
+*.so filter=lfs diff=lfs merge=lfs -text
+*.bin filter=lfs diff=lfs merge=lfs -text
+*.dll filter=lfs diff=lfs merge=lfs -text
diff --git a/BUILD.gn b/BUILD.gn
new file mode 100755
index 00000000..3fa1dbc2
--- /dev/null
+++ b/BUILD.gn
@@ -0,0 +1,43 @@
+# Copyright (C) 2021 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.
+
+import("//build/ohos.gni")
+import("//build/ohos_var.gni")
+
+SUBSYSTEM_DIR = "//foundation/communication/ipc"
+IPC_CORE_ROOT = "$SUBSYSTEM_DIR/ipc/native"
+
+config("ipc_util_config") {
+ # header file path
+
+ include_dirs = [
+ "$SUBSYSTEM_DIR/interfaces/innerkits/ipc_core/include",
+ "$IPC_CORE_ROOT/src/core/include",
+ "$IPC_CORE_ROOT/src/mock/include",
+ "//utils/native/base/include",
+ ]
+
+ cflags = []
+ if (is_double_framework) {
+ cflags = [ "-DCONFIG_DUAL_FRAMEWORK" ]
+ }
+ if (target_cpu == "arm") {
+ cflags += [ "-DBINDER_IPC_32BIT" ]
+ }
+ if (is_standard_system) {
+ cflags += [ "-DCONFIG_STANDARD_SYSTEM" ]
+ }
+ if (defined(build_public_version) && build_public_version) {
+ cflags += [ "-DBUILD_PUBLIC_VERSION" ]
+ }
+}
diff --git a/LICENSE b/LICENSE
new file mode 100755
index 00000000..e454a525
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,178 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/README.en.md b/README.en.md
deleted file mode 100644
index ed5f1d72..00000000
--- a/README.en.md
+++ /dev/null
@@ -1,36 +0,0 @@
-# communication_ipc
-
-#### Description
-Inter-process communication (IPC) and Remote Procedure Call (RPC) | 跨进程通信与跨设备的远程过程调用
-
-#### Software Architecture
-Software architecture description
-
-#### Installation
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### Instructions
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### Contribution
-
-1. Fork the repository
-2. Create Feat_xxx branch
-3. Commit your code
-4. Create Pull Request
-
-
-#### Gitee Feature
-
-1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
-2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
-3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
-4. The most valuable open source project [GVP](https://gitee.com/gvp)
-5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
-6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
index b235630e..3c0a2c04
--- a/README.md
+++ b/README.md
@@ -1,37 +1,262 @@
-# communication_ipc
+# communication\_ipc
-#### 介绍
-Inter-process communication (IPC) and Remote Procedure Call (RPC) | 跨进程通信与跨设备的远程过程调用
+- [Introduction](#section11660541593)
+- [Architecture](#section1950291414611)
+- [Directory Structure](#section161941989596)
+- [Constraints](#section119744591305)
+- [Compilation and Building](#section137768191623)
+- [Usage](#section1312121216216)
+ - [Available APIs](#section1551164914237)
+ - [Usage Guidelines](#section129654513264)
-#### 软件架构
-软件架构说明
+- [Repositories Involved](#section1371113476307)
+## Introduction
-#### 安装教程
+The inter-process communication \(IPC\) and remote procedure call \(RPC\) mechanisms are used to implement cross-process communication. The difference between them lies in that IPC uses the Binder driver to implement cross-process communication within a device, whereas RPC uses the DSoftBus driver to implement cross-process communication across devices. IPC and RPC generally use a client-server model. The service requester \(client\) can obtain the proxy of the service provider \(server\) and use the proxy to read and write data, thus implementing data communication between processes. Generally, the server registers system abilities \(SAs\) with the system ability manager \(SAMgr\), which manages the SAs and provides APIs for the client. To communicate with a specific SA, the client must obtain the proxy of the SA from SAMgr. In this document, Proxy represents the service requester, and Stub represents the service provider.
-1. xxxx
-2. xxxx
-3. xxxx
+## Architecture
-#### 使用说明
+**Figure 1** IPC architecture
+![](figures/ipc-architecture.png "ipc-architecture")
-1. xxxx
-2. xxxx
-3. xxxx
+## Directory Structure
-#### 参与贡献
+```
+/foundation/communication/ipc
+├── interfaces # APIs exposed externally
+│ └── innerkits # Header files for internal subsystems
+│ ├── ipc_core # IPC APIs
+│ └── libdbinder # dbinder APIs
+├── ipc # IPC framework
+│ ├── native # IPC native implementation
+│ ├── src # IPC native source code
+│ └── test # IPC native unit test cases
+│ └── test # IPC native module test cases
+├── service # dbinder implementation
+│ └── dbinder # dbinder source code
+```
-1. Fork 本仓库
-2. 新建 Feat_xxx 分支
-3. 提交代码
-4. 新建 Pull Request
+## Constraints
+Currently, cross-device RPC communication is not supported.
-#### 特技
+## Compilation and Building
+
+**Native Dependency**
+
+SDK dependency:
+
+```
+external_deps = [
+ "ipc:ipc_core",
+]
+```
+
+In addition, the refbase implementation on which IPC/RPC depends is stored in **//utils**. Add the dependency on the Utils source code.
+
+```
+deps = [
+ "//utils/native/base:utils",
+]
+```
+
+## Usage
+
+The procedure for implementing cross-process communication using native APIs is similar to that using Java APIs.
+
+1. Define an interface.
+
+ The interface inherits **IRemoteBroker** and defines descriptors, functions, and message code.
+
+2. Implement the server provider \(stub\).
+
+ The stub inherits **IRemoteStub\(Native\)** or **RemoteObject\(Java\)** as well as **AsObject** and **OnRemoteRequest**.
+
+3. Implement the service requester \(proxy\).
+
+ The proxy inherits **IRemoteProxy\(Native\)** or **RemoteProxy\(Java\)**, encapsulates functions, and calls **SendRequest** to send requests to the stub.
+
+4. Register an SA.
+
+ After the process where the service provider resides starts, apply for the unique SA ID and register the stub with SAMgr.
+
+5. Obtain the SA.
+6. Obtain the proxy from the SAMgr based on the SA ID and device ID, and implement cross-process communication with the stub through the proxy.
+
+### Available APIs
+
+**Table 1** Native IPC APIs
+
+
+
Class/Interface
+ |
+Method
+ |
+Description
+ |
+
+
+IRemoteBroker
+ |
+sptr<IRemoteObject> AsObject()
+ |
+Obtains the holder of a remote proxy object. This method must be implemented by the derived classes of IRemoteBroker. If you call this method on the stub, the RemoteObject is returned; if you call this method on the proxy, the proxy object is returned.
+ |
+
+IRemoteStub
+ |
+virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
+ |
+Called to process a request from the proxy and return the result. Derived classes need to override this method.
+ |
+
+IRemoteProxy
+ |
+ |
+Service proxy classes are derived from the IRemoteProxy class.
+ |
+
+
+
+
+### Usage Guidelines
+
+**Native**
+
+Define the IPC interface **ITestAbility**.
+
+**ITestAbility** inherits the IPC base class **IRemoteBroker** and defines descriptors, functions, and message code. The functions need to be implemented on both the proxy and stub.
+
+```
+class ITestAbility : public IRemoteBroker {
+public:
+// DECLARE_INTERFACE_DESCRIPTOR is mandatory, and the input parameter is std::u16string.
+DECLARE_INTERFACE_DESCRIPTOR(u"test.ITestAbility");
+int TRANS_ID_PING_ABILITY = 1; // Define the message code.
+virtual int TestPingAbility(const std::u16string &dummy) = 0; // Define functions.
+};
+```
+
+Define and implement service provider **TestAbilityStub**.
+
+This class is related to the IPC framework and needs to inherit **IRemoteStub**. You need to override **OnRemoteRequest** on the stub to receive requests from the proxy.
+
+```
+class TestAbilityStub : public IRemoteStub {
+public:
+ virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
+ int TestPingAbility(const std::u16string &dummy) override;
+};
+
+int TestServiceStub::OnRemoteRequest(uint32_t code,
+ MessageParcel &data, MessageParcel &reply, MessageOption &option)
+{
+ switch (code) {
+ case TRANS_ID_PING_ABILITY: {
+ std::u16string dummy = data.ReadString16();
+ int result = TestPingAbility(dummy);
+ reply.WriteInt32(result);
+ return 0;
+ }
+ default:
+ return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
+ }
+}
+```
+
+Define the **TestAbility** class that implements functions for the stub.
+
+```
+class TestAbility : public TestAbilityStub {
+public:
+ int TestPingAbility(const std::u16string &dummy);
+}
+
+int TestAbility::TestPingAbility(const std::u16string &dummy) {
+ return 0;
+}
+```
+
+Define and implement **TestAbilityProxy**.
+
+This class is implemented on the proxy and inherits **IRemoteProxy**. You can call **SendRequest** to send a request to the stub and expose the capabilities provided by the stub.
+
+```
+class TestAbilityProxy : public IRemoteProxy {
+public:
+ explicit TestAbilityProxy(const sptr &impl);
+ int TestPingService(const std::u16string &dummy) override;
+private:
+ static inline BrokerDelegator delegator_; // Use the iface_cast macro.
+}
+
+TestAbilityProxy::TestAbilityProxy(const sptr &impl)
+ : IRemoteProxy(impl)
+{
+}
+
+int TestAbilityProxy::TestPingService(const std::u16string &dummy) {
+ MessageOption option;
+ MessageParcel dataParcel, replyParcel;
+ dataParcel.WriteString16(dummy);
+ int error = Remote()->SendRequest(TRANS_ID_PING_ABILITY, dataParcel, replyParcel, option);
+ int result = (error == ERR_NONE) ? replyParcel.ReadInt32() : -1;
+ return result;
+}
+```
+
+Send a request synchronously or asynchronously.
+
+The **MessageOption** parameter for the **sendRequest\(\)** method can be set to **TF\_SYNC**, **TF\_ASYNC**, or **TF\_ACCEPT\_FDS** using the **MessageOption** constructor or **void SetFlags\(int flags\)**. The default value is **TF\_SYNC**.
+
+```
+int SendRequest(uint32_t code, MessageParcel &data,
+ MessageParcel &reply, MessageOption &option) override;
+MessageOption option = { MessageOption::TF_ASYNC };
+```
+
+Register and start an SA.
+
+Call **AddSystemAbility** to register the **TestAbilityStub** instance of the SA with **SystemAbilityManager**. The registration parameters vary depending on whether the **SystemAbilityManager** resides on the same device as the SA.
+
+```
+// Register the TestAbilityStub instance with the SystemAbilityManager on the same device as the SA.
+auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+samgr->AddSystemAbility(said, new TestAbility());
+
+// Register the TestAbilityStub instance with the SystemAbilityManager on a different device.
+auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+ISystemAbilityManager::SAExtraProp saExtra;
+saExtra.isDistributed = true; // Set a distributed SA.
+int result = samgr->AddSystemAbility(said, new TestAbility(), saExtra);
+```
+
+Obtain the SA.
+
+Call the **GetSystemAbility** function of the **SystemAbilityManager** class to obtain the **IRemoteObject** for the SA, and create a **TestAbilityProxy** instance.
+
+```
+// Obtain the proxy of the SA registered on the local device.
+sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+sptr remoteObject = samgr->GetSystemAbility(said);
+sptr testAbility = iface_cast(remoteObject); // Use the iface_cast macro to convert the proxy to a specific type.
+
+// Obtain the proxies of the SAs registered with other devices.
+sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+sptr remoteObject = samgr->GetSystemAbility(sdid, deviceId); // deviceId identifies a device.
+sptr proxy(new TestAbilityProxy(remoteObject)); // Construct a proxy.
+```
+
+## Repositories Involved
+
+DSoftBus subsystem
+
+**communication\_ipc**
+
+utils
+
+utils\_native
+
+distributedschedule\_samgr
-1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
-2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
-3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
-4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
-5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
-6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
diff --git a/README_zh.md b/README_zh.md
new file mode 100755
index 00000000..84d11bfe
--- /dev/null
+++ b/README_zh.md
@@ -0,0 +1,264 @@
+# IPC/RPC组件
+
+- [简介](#section11660541593)
+- [系统架构](#section1950291414611)
+- [目录](#section161941989596)
+- [约束](#section119744591305)
+- [编译构建](#section137768191623)
+- [说明](#section1312121216216)
+ - [接口说明](#section1551164914237)
+ - [使用说明](#section129654513264)
+
+- [相关仓](#section1371113476307)
+
+## 简介
+
+IPC(Inter-Process Communication)与RPC(Remote Procedure Call)机制用于实现跨进程通信,不同的是前者使用Binder驱动,用于设备内的跨进程通信,而后者使用软总线驱动,用于跨设备跨进程通信。IPC和RPC通常采用客户端-服务器(Client-Server)模型,服务请求方(Client)可获取提供服务提供方(Server)的代理 (Proxy),并通过此代理读写数据来实现进程间的数据通信。通常,Server会先注册系统能力(System Ability)到系统能力管理者(System Ability Manager,缩写SAMgr)中,SAMgr负责管理这些SA并向Client提供相关的接口。Client要和某个具体的SA通信,必须先从SAMgr中获取该SA的代理,然后使用代理和SA通信。下文使用Proxy表示服务请求方,Stub表示服务提供方。
+
+## 系统架构
+
+**图 1** IPC通信机制架构图
+![](figures/ipc-architecture.png "IPC通信机制架构图")
+
+## 目录
+
+```
+/foundation/communication/ipc
+├── interfaces # 对外接口存放目录
+│ └── innerkits # 对内部子系统暴露的头文件存放目录
+│ ├── ipc_core # ipc 接口存放目录
+│ └── libdbinder # dbinder 接口存放目录
+├── ipc # ipc 框架代码
+│ ├── native # ipc native 实现存放目录
+│ ├── src # ipc native 源代码存放目录
+│ └── test # ipc native 单元测试用例存放目录
+│ └── test # ipc native 模块测试用例存放目录
+├── service # dbinder 实现存放目录
+│ └── dbinder # dbinder 源代码存放目录
+```
+
+## 约束
+
+目前暂不支持的场景:
+
+跨设备RPC调用
+
+## 编译构建
+
+**Native侧编译依赖**
+
+sdk依赖:
+
+```
+external_deps = [
+ "ipc:ipc_core",
+]
+```
+
+此外, IPC/RPC依赖的refbase实现在公共基础库实现//utils下,请增加对utils的源码依赖:
+
+```
+deps = [
+ "//utils/native/base:utils",
+]
+```
+
+## 说明
+
+Native侧和Java侧实现跨进程通信的步骤基本相同。
+
+1. 定义接口类
+
+ 接口类继承IRemoteBroker,定义描述符、业务函数和消息码。
+
+2. 实现服务提供端\(Stub\)
+
+ Stub继承IRemoteStub\(Native\)或者RemoteObject\(Java\),除了接口类中未实现方法外,还需要实现AsObject方法及OnRemoteRequest方法。
+
+3. 实现服务请求端\(Proxy\)
+
+ Proxy继承IRemoteProxy\(Native\)或者RemoteProxy\(Java\),封装业务函数,调用SendRequest将请求发送到Stub。
+
+4. 注册SA
+
+ 服务提供方所在进程启动后,申请SA的唯一标识,将Stub注册到SAMgr。
+
+5. 获取SA
+6. 通过SA的标识和设备标识,从SAMgr获取Proxy,通过Proxy实现与Stub的跨进程通信。
+
+### 接口说明
+
+**表 1** Native侧IPC接口
+
+
+类/接口
+ |
+方法
+ |
+功能说明
+ |
+
+
+IRemoteBroker
+ |
+sptr<IRemoteObject> AsObject()
+ |
+返回通信对象。派生类需要实现,Stub端返回RemoteObject对象本身,Proxy端返回代理对象。
+ |
+
+IRemoteStub
+ |
+virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
+ |
+请求处理方法,派生类需要重写,处理Proxy的请求并返回结果。
+ |
+
+IRemoteProxy
+ |
+ |
+业务Proxy类派生自IRemoteProxy类。
+ |
+
+
+
+
+### 使用说明
+
+**Native侧使用说明**
+
+定义IPC接口ITestAbility
+
+IPC接口继承IPC基类接口IRemoteBroker,接口里定义描述符、业务函数和消息码,其中业务函数在Proxy端和Stub端都需要实现。
+
+```
+class ITestAbility : public IRemoteBroker {
+public:
+// DECLARE_INTERFACE_DESCRIPTOR是必须的, 入参需使用std::u16string;
+DECLARE_INTERFACE_DESCRIPTOR(u"test.ITestAbility");
+int TRANS_ID_PING_ABILITY = 1; // 定义消息码
+virtual int TestPingAbility(const std::u16string &dummy) = 0; // 定义业务函数
+};
+```
+
+定义和实现服务端TestAbilityStub
+
+该类是和IPC框架相关的实现,需要继承 IRemoteStub。Stub端作为接收请求的一端,需重写OnRemoteRequest方法用于接收客户端调用。
+
+```
+class TestAbilityStub : public IRemoteStub {
+public:
+ virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
+ int TestPingAbility(const std::u16string &dummy) override;
+};
+
+int TestServiceStub::OnRemoteRequest(uint32_t code,
+ MessageParcel &data, MessageParcel &reply, MessageOption &option)
+{
+ switch (code) {
+ case TRANS_ID_PING_ABILITY: {
+ std::u16string dummy = data.ReadString16();
+ int result = TestPingAbility(dummy);
+ reply.WriteInt32(result);
+ return 0;
+ }
+ default:
+ return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
+ }
+}
+```
+
+定义服务端业务函数具体实现类TestAbility
+
+```
+class TestAbility : public TestAbilityStub {
+public:
+ int TestPingAbility(const std::u16string &dummy);
+}
+
+int TestAbility::TestPingAbility(const std::u16string &dummy) {
+ return 0;
+}
+```
+
+定义和实现客户端TestAbilityProxy
+
+该类是Proxy端实现,继承IRemoteProxy,调用SendRequest接口向Stub端发送请求,对外暴露服务端提供的能力。
+
+```
+class TestAbilityProxy : public IRemoteProxy {
+public:
+ explicit TestAbilityProxy(const sptr &impl);
+ int TestPingService(const std::u16string &dummy) override;
+private:
+ static inline BrokerDelegator delegator_; // 方便使用iface_cast宏
+}
+
+TestAbilityProxy::TestAbilityProxy(const sptr &impl)
+ : IRemoteProxy(impl)
+{
+}
+
+int TestAbilityProxy::TestPingService(const std::u16string &dummy) {
+ MessageOption option;
+ MessageParcel dataParcel, replyParcel;
+ dataParcel.WriteString16(dummy);
+ int error = Remote()->SendRequest(TRANS_ID_PING_ABILITY, dataParcel, replyParcel, option);
+ int result = (error == ERR_NONE) ? replyParcel.ReadInt32() : -1;
+ return result;
+}
+```
+
+同步调用与异步调用
+
+MessageOption作为发送接口(原型如下)的入参,可设定同步(TF\_SYNC)、异步(TF\_ASYNC)、接收FD(TF\_ACCEPT\_FDS),默认情况下设定为同步,其余可通过MessageOption构造方法或void SetFlags\(int flags\)设定。
+
+```
+int SendRequest(uint32_t code, MessageParcel &data,
+ MessageParcel &reply, MessageOption &option) override;
+MessageOption option = { MessageOption::TF_ASYNC };
+```
+
+SA注册与启动
+
+SA需要将自己的TestAbilityStub实例通过AddSystemAbility接口注册到SystemAbilityManager,设备内与分布式的注册参数不同。
+
+```
+// 注册到本设备内
+auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+samgr->AddSystemAbility(said, new TestAbility());
+
+// 在组网场景下,会被同步到其他设备上
+auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+ISystemAbilityManager::SAExtraProp saExtra;
+saExtra.isDistributed = true; // 设置为分布式SA
+int result = samgr->AddSystemAbility(said, new TestAbility(), saExtra);
+```
+
+SA获取与调用
+
+通过SystemAbilityManager的GetSystemAbility方法可获取到对应SA的代理IRemoteObject,然后构造TestAbilityProxy即可。
+
+```
+// 获取本设备内注册的SA的proxy
+sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+sptr remoteObject = samgr->GetSystemAbility(said);
+sptr testAbility = iface_cast(remoteObject); // 使用iface_cast宏转换成具体类型
+
+// 获取其他设备注册的SA的Proxy
+sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+sptr remoteObject = samgr->GetSystemAbility(sdid, deviceId); // deviceId是指定设备的标识符
+sptr proxy(new TestAbilityProxy(remoteObject)); // 直接构造具体Proxy
+```
+
+## 相关仓
+
+分布式软总线子系统
+
+**communication\_ipc**
+
+utils
+
+utils\_native
+
+distributedschedule\_samgr
+
diff --git a/figures/ipc-architecture.png b/figures/ipc-architecture.png
new file mode 100755
index 00000000..0fd4beea
Binary files /dev/null and b/figures/ipc-architecture.png differ
diff --git a/interfaces/innerkits/ipc_core/BUILD.gn b/interfaces/innerkits/ipc_core/BUILD.gn
new file mode 100755
index 00000000..370a6aba
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/BUILD.gn
@@ -0,0 +1,67 @@
+# Copyright (C) 2021 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.
+
+import("//build/ohos.gni")
+
+SUBSYSTEM_DIR = "//foundation/communication/ipc"
+IPC_CORE_ROOT = "$SUBSYSTEM_DIR/ipc/native"
+
+config("libipc_core_private_config") {
+ cflags_cc = [ "-O2" ]
+}
+
+ohos_shared_library("ipc_core") {
+ include_dirs = [
+ "$SUBSYSTEM_DIR/utils/include",
+ ]
+ sources = [
+ "$IPC_CORE_ROOT/src/core/source/buffer_object.cpp",
+ "$IPC_CORE_ROOT/src/core/source/comm_auth_info.cpp",
+ "$IPC_CORE_ROOT/src/core/source/databus_session_callback.cpp",
+ "$IPC_CORE_ROOT/src/core/source/dbinder_session_object.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_file_descriptor.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_object_proxy.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_object_stub.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_process_skeleton.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_skeleton.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_thread_pool.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_thread_skeleton.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_workthread.cpp",
+ "$IPC_CORE_ROOT/src/core/source/iremote_broker.cpp",
+ "$IPC_CORE_ROOT/src/core/source/iremote_object.cpp",
+ "$IPC_CORE_ROOT/src/core/source/message_option.cpp",
+ "$IPC_CORE_ROOT/src/core/source/message_parcel.cpp",
+ "$IPC_CORE_ROOT/src/core/source/peer_holder.cpp",
+ "$IPC_CORE_ROOT/src/core/source/stub_refcount_object.cpp",
+ "$IPC_CORE_ROOT/src/mock/source/binder_connector.cpp",
+ "$IPC_CORE_ROOT/src/mock/source/binder_debug.cpp",
+ "$IPC_CORE_ROOT/src/mock/source/binder_invoker.cpp",
+ "$IPC_CORE_ROOT/src/mock/source/dbinder_databus_invoker.cpp",
+ "$IPC_CORE_ROOT/src/mock/source/invoker_factory.cpp",
+ "$IPC_CORE_ROOT/src/mock/source/invoker_rawdata.cpp",
+ ]
+
+ configs = [
+ "$SUBSYSTEM_DIR:ipc_util_config",
+ ":libipc_core_private_config",
+ ]
+ public_configs = [ "$SUBSYSTEM_DIR:ipc_util_config" ]
+ deps = [ "//utils/native/base:utils" ]
+
+ external_deps = [
+ "dsoftbus_standard:softbus_client",
+ "hiviewdfx_hilog_native:libhilog",
+ ]
+ subsystem_name = "communication"
+ part_name = "ipc"
+}
diff --git a/interfaces/innerkits/ipc_core/include/ipc_file_descriptor.h b/interfaces/innerkits/ipc_core/include/ipc_file_descriptor.h
new file mode 100755
index 00000000..6f0c242d
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/ipc_file_descriptor.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2021 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_IPC_IPC_FILE_DESCRIPTOR_H
+#define OHOS_IPC_IPC_FILE_DESCRIPTOR_H
+
+#include "parcel.h"
+
+namespace OHOS {
+class IPCFileDescriptor : public virtual Parcelable {
+public:
+ IPCFileDescriptor();
+ explicit IPCFileDescriptor(int fd);
+ ~IPCFileDescriptor();
+
+ bool Marshalling(Parcel &parcel) const override;
+ static bool Marshalling(Parcel &parcel, const sptr &object);
+ static IPCFileDescriptor *Unmarshalling(Parcel &parcel);
+ int GetFd() const;
+ void SetFd(int fd);
+
+private:
+ int fd_ = -1;
+};
+} // namespace OHOS
+#endif // OHOS_IPC_IPC_FILE_DESCRIPTOR_H
diff --git a/interfaces/innerkits/ipc_core/include/ipc_object_proxy.h b/interfaces/innerkits/ipc_core/include/ipc_object_proxy.h
new file mode 100755
index 00000000..1d66e4b6
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/ipc_object_proxy.h
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2021 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_IPC_IPC_OBJECT_PROXY_H
+#define OHOS_IPC_IPC_OBJECT_PROXY_H
+
+#include
+#include
+
+#include "iremote_object.h"
+
+namespace OHOS {
+class IPCObjectProxy : public IRemoteObject {
+public:
+ explicit IPCObjectProxy(int handle, std::u16string descriptor = std::u16string(),
+ int proto = IRemoteObject::IF_PROT_DEFAULT);
+ ~IPCObjectProxy();
+
+ int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &optionoption) override;
+
+ bool IsProxyObject() const override
+ {
+ return true;
+ };
+
+ bool IsObjectDead() const;
+
+ int32_t GetObjectRefCount() override;
+
+ int Dump(int fd, const std::vector &args) override;
+
+ void OnFirstStrongRef(const void *objectId) override;
+
+ void OnLastStrongRef(const void *objectId) override;
+
+ bool AddDeathRecipient(const sptr &recipient) override;
+
+ bool RemoveDeathRecipient(const sptr &recipient) override;
+
+ void SendObituary();
+
+ bool IsSubscribeDeathNotice() const
+ {
+ if (recipients_.empty()) {
+ return false;
+ }
+ return true;
+ };
+
+ uint32_t GetHandle() const
+ {
+ return handle_;
+ };
+
+ int InvokeListenThread(MessageParcel &data, MessageParcel &reply);
+ int32_t NoticeServiceDie();
+ std::string GetPidAndUidInfo();
+
+ std::string GetDataBusName();
+ int GetProto() const;
+ void WaitForInit();
+ std::u16string GetInterfaceDescriptor();
+
+private:
+ void MarkObjectDied();
+ int SendLocalRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &optionoption);
+ int SendRequestInner(bool isLocal, uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
+
+#ifndef CONFIG_IPC_SINGLE
+ void SetProto(int proto);
+
+ int UpdateProto();
+
+ void ReleaseProto();
+
+ void IncRefToRemote();
+
+ int GetSessionFromDBinderService();
+
+ bool AddDbinderDeathRecipient();
+
+ bool RemoveDbinderDeathRecipient();
+
+ void ReleaseDatabusProto();
+
+ void ReleaseBinderProto();
+
+ bool UpdateDatabusClientSession(int handle, MessageParcel &reply);
+
+ bool CheckHaveSession(uint32_t &type);
+#endif
+
+private:
+ std::mutex initMutex_;
+ std::recursive_mutex mutex_;
+
+ std::vector> recipients_;
+ const uint32_t handle_;
+ int proto_;
+ bool isFinishInit_;
+ bool isRemoteDead_;
+ std::u16string remoteDescriptor_;
+};
+} // namespace OHOS
+#endif // OHOS_IPC_IPC_OBJECT_PROXY_H
diff --git a/interfaces/innerkits/ipc_core/include/ipc_object_stub.h b/interfaces/innerkits/ipc_core/include/ipc_object_stub.h
new file mode 100755
index 00000000..91eed02a
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/ipc_object_stub.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2021 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_IPC_IPC_OBJECT_STUB_H
+#define OHOS_IPC_IPC_OBJECT_STUB_H
+
+#include "iremote_object.h"
+#include
+#include "ipc_object_proxy.h"
+
+namespace OHOS {
+struct RefCountNode {
+ int remotePid;
+ std::string deviceId;
+};
+
+class IPCObjectStub : public IRemoteObject {
+public:
+ explicit IPCObjectStub(std::u16string descriptor = nullptr);
+ ~IPCObjectStub();
+
+ bool IsProxyObject() const override
+ {
+ return false;
+ };
+
+ int32_t GetObjectRefCount() override;
+
+ int Dump(int fd, const std::vector &args) override;
+
+ virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
+
+ int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
+
+ void OnFirstStrongRef(const void *objectId) override;
+
+ void OnLastStrongRef(const void *objectId) override;
+
+ bool AddDeathRecipient(const sptr &recipient) override;
+
+ bool RemoveDeathRecipient(const sptr &recipient) override;
+
+ int GetCallingPid();
+
+ int GetCallingUid();
+
+ virtual int OnRemoteDump(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
+
+ virtual int32_t ProcessProto(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
+
+#ifndef CONFIG_IPC_SINGLE
+ int32_t InvokerThread(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
+
+ int32_t NoticeServiceDie(MessageParcel &data, MessageParcel &reply, MessageOption &option);
+
+ int32_t InvokerDataBusThread(MessageParcel &data, MessageParcel &reply);
+
+ int32_t IncStubRefs(MessageParcel &data, MessageParcel &reply);
+ int32_t DecStubRefs(MessageParcel &data, MessageParcel &reply);
+
+ int32_t AddAuthInfo(MessageParcel &data, MessageParcel &reply);
+
+private:
+ int32_t GrantDataBusName(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
+ std::string CreateDatabusName(int uid, int pid);
+ std::string GetDataBusName();
+#endif
+private:
+ bool IsDeviceIdIllegal(const std::string &deviceID);
+};
+} // namespace OHOS
+#endif // OHOS_IPC_IPC_OBJECT_STUB_H
diff --git a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h
new file mode 100755
index 00000000..fa59b085
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2021 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_IPC_IPC_SKELETON_H
+#define OHOS_IPC_IPC_SKELETON_H
+
+#include "iremote_object.h"
+
+namespace OHOS {
+class IPCSkeleton {
+public:
+ IPCSkeleton() = default;
+ ~IPCSkeleton() = default;
+
+ // default max is 4, only if you need a customize value
+ static bool SetMaxWorkThreadNum(int maxThreadNum);
+
+ // join current thread into work loop.
+ static void JoinWorkThread();
+
+ // remove current thread from work loop.
+ static void StopWorkThread();
+
+ static pid_t GetCallingPid();
+
+ static pid_t GetCallingUid();
+
+ static std::string GetLocalDeviceID();
+
+ static std::string GetCallingDeviceID();
+
+ static bool IsLocalCalling();
+
+ static IPCSkeleton &GetInstance();
+
+ static sptr GetContextObject();
+
+ static bool SetContextObject(sptr &object);
+
+ static int FlushCommands(IRemoteObject *object);
+
+ static std::string ResetCallingIdentity();
+
+ static bool SetCallingIdentity(std::string &identity);
+};
+} // namespace OHOS
+#endif // OHOS_IPC_IPC_SKELETON_H
diff --git a/interfaces/innerkits/ipc_core/include/ipc_types.h b/interfaces/innerkits/ipc_core/include/ipc_types.h
new file mode 100755
index 00000000..df3b3cb4
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/ipc_types.h
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2021 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_IPC_IPC_TYPES_H
+#define OHOS_IPC_IPC_TYPES_H
+
+#include
+#include
+#include "errors.h"
+
+namespace OHOS {
+#define ZIPC_PACK_CHARS(c1, c2, c3, c4) ((((c1) << 24)) | (((c2) << 16)) | (((c3) << 8)) | (c4))
+
+constexpr int REGISTRY_HANDLE = 0;
+
+enum {
+ FIRST_CALL_TRANSACTION = 0x00000001,
+ LAST_CALL_TRANSACTION = 0x00ffffff,
+ PING_TRANSACTION = ZIPC_PACK_CHARS('_', 'P', 'N', 'G'),
+ DUMP_TRANSACTION = ZIPC_PACK_CHARS('_', 'D', 'M', 'P'),
+ SHELL_COMMAND_TRANSACTION = ZIPC_PACK_CHARS('_', 'C', 'M', 'D'),
+ INTERFACE_TRANSACTION = ZIPC_PACK_CHARS('_', 'N', 'T', 'F'),
+ SYSPROPS_TRANSACTION = ZIPC_PACK_CHARS('_', 'S', 'P', 'R'),
+ SYNCHRONIZE_REFERENCE = ZIPC_PACK_CHARS('_', 'S', 'Y', 'C'),
+ INVOKE_LISTEN_THREAD = ZIPC_PACK_CHARS('_', 'I', 'L', 'T'),
+ GET_PROTO_INFO = ZIPC_PACK_CHARS('_', 'G', 'R', 'I'),
+ GET_UIDPID_INFO = ZIPC_PACK_CHARS('_', 'G', 'U', 'I'),
+ GRANT_DATABUS_NAME = ZIPC_PACK_CHARS('_', 'G', 'D', 'N'),
+ DBINDER_OBITUARY_TRANSACTION = ZIPC_PACK_CHARS('_', 'D', 'O', 'T'),
+ DBINDER_INCREFS_TRANSACTION = ZIPC_PACK_CHARS('_', 'D', 'I', 'T'),
+ DBINDER_DECREFS_TRANSACTION = ZIPC_PACK_CHARS('_', 'D', 'D', 'T'),
+ DBINDER_ADD_COMMAUTH = ZIPC_PACK_CHARS('_', 'D', 'A', 'C'),
+ TRANS_SYNC = 0,
+ TRANS_ASYNC = 1,
+};
+
+enum {
+ NO_ERROR = 0,
+ TRANSACTION_ERR,
+ FLATTEN_ERR = 3,
+ UNKNOWN_TRANSACTION = 4,
+ INVALID_DATA = 5,
+ OBJECT_NULL = 7,
+ INVALID_OPERATION = 8,
+ DEAD_OBJECT = -EPIPE,
+ UNKNOWN_ERROR,
+};
+
+constexpr int MIN_TRANSACTION_ID = 0x1;
+constexpr int MAX_TRANSACTION_ID = 0x00ffffff;
+constexpr int INVALID_FD = -1;
+
+enum {
+ ERR_NONE = 0,
+ ERR_TRANSACTION_FAILED = 1,
+ ERR_UNKNOWN_OBJECT = 2,
+ ERR_FLATTEN_OBJECT = 3,
+ ERR_UNKNOWN_TRANSACTION = 4,
+ ERR_INVALID_DATA = 5,
+ ERR_NULL_OBJECT = 7,
+ ERR_UNKNOWN_REASON,
+ ERR_INVALID_REPLY,
+ ERR_INVALID_STATE,
+ IPC_SKELETON_ERR = 100,
+ IPC_SKELETON_NULL_OBJECT_ERR,
+ IPC_PROXY_ERR = 200,
+ IPC_PROXY_DEAD_OBJECT_ERR,
+ IPC_PROXY_NULL_INVOKER_ERR,
+ IPC_PROXY_TRANSACTION_ERR,
+ IPC_PROXY_INVALID_CODE_ERR,
+ IPC_STUB_ERR = 300,
+ IPC_STUB_WRITE_PARCEL_ERR,
+ IPC_STUB_INVOKE_THREAD_ERR,
+ IPC_STUB_INVALID_DATA_ERR,
+ IPC_STUB_CURRENT_NULL_ERR,
+ IPC_STUB_UNKNOW_TRANS_ERR,
+ IPC_STUB_CREATE_BUS_SERVER_ERR,
+ IPC_INVOKER_ERR = 400,
+ IPC_INVOKER_WRITE_TRANS_ERR,
+ IPC_INVOKER_TRANSLATE_ERR,
+ IPC_INVOKER_CONNECT_ERR,
+ IPC_INVOKER_ON_TRANSACT_ERR,
+ IPC_INVOKER_INVALID_DATA_ERR,
+ IPC_INVOKER_INVALID_REPLY_ERR,
+ RPC_BASE_INVOKER_ERR = 500,
+ RPC_BASE_INVOKER_INVALID_REPLY_ERR,
+ RPC_BASE_INVOKER_WAIT_REPLY_ERR,
+ RPC_BASE_INVOKER_CURRENT_NULL_ERR,
+ RPC_BASE_INVOKER_INVALID_DATA_ERR,
+ RPC_BASE_INVOKER_WRITE_TRANS_ERR,
+ RPC_BASE_INVOKER_SEND_REPLY_ERR,
+ RPC_DATABUS_INVOKER_ERR = 600,
+ RPC_DATABUS_INVOKER_INVALID_DATA_ERR,
+ RPC_DATABUS_INVOKER_CLOSED_PEER_ERR,
+ RPC_DATABUS_INVOKER_INVALID_STUB_INDEX,
+ DBINDER_SERVICE_ERR = 700,
+ DBINDER_SERVICE_INVALID_DATA_ERR,
+ DBINDER_SERVICE_NOTICE_DIE_ERR,
+ DBINDER_SERVICE_PROCESS_PROTO_ERR,
+ DBINDER_SERVICE_UNKNOW_TRANS_ERR,
+ DBINDER_SERVICE_ADD_DEATH_ERR,
+ DBINDER_SERVICE_REMOVE_DEATH_ERR,
+ DBINDER_SERVICE_WRONG_SESSION,
+ SESSION_WRONG_FD_ERR = 800,
+ SESSION_INVOKER_NULL_ERR,
+ SESSION_UNAUTHENTICATED_ERR,
+ SESSION_UNOPEN_ERR = -1,
+};
+} // namespace OHOS
+#endif // OHOS_IPC_IPC_TYPES_H
diff --git a/interfaces/innerkits/ipc_core/include/iremote_broker.h b/interfaces/innerkits/ipc_core/include/iremote_broker.h
new file mode 100755
index 00000000..4251a993
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/iremote_broker.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2021 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_IPC_IREMOTE_BROKER_H
+#define OHOS_IPC_IREMOTE_BROKER_H
+
+#include
+#include
+#include "iremote_object.h"
+#include "refbase.h"
+
+namespace OHOS {
+template class BrokerCreator {
+public:
+ BrokerCreator() = default;
+ ~BrokerCreator() = default;
+ sptr operator () (const sptr &object)
+ {
+ return static_cast(new T(object));
+ };
+};
+
+class IRemoteBroker : public virtual RefBase {
+public:
+ IRemoteBroker() = default;
+ virtual ~IRemoteBroker() override = default;
+ virtual sptr AsObject() = 0;
+ static inline sptr AsImplement(const sptr &object)
+ {
+ return nullptr;
+ }
+};
+
+#define DECLARE_INTERFACE_DESCRIPTOR(DESCRIPTOR) \
+ static inline const std::u16string metaDescriptor_ = { DESCRIPTOR }; \
+ static inline const std::u16string &GetDescriptor() \
+ { \
+ return metaDescriptor_; \
+ }
+
+class BrokerRegistration {
+ using Constructor = std::function(const sptr &object)>;
+
+public:
+ static BrokerRegistration &Get();
+ bool Register(const std::u16string &descriptor, const Constructor &creator);
+ void Unregister(const std::u16string &descriptor);
+ sptr NewInstance(const std::u16string &descriptor, const sptr &object);
+
+protected:
+ BrokerRegistration() = default;
+ ~BrokerRegistration();
+
+private:
+ BrokerRegistration(const BrokerRegistration &) = delete;
+ BrokerRegistration(BrokerRegistration &&) = delete;
+ BrokerRegistration &operator = (const BrokerRegistration &) = delete;
+ BrokerRegistration &operator = (BrokerRegistration &&) = delete;
+ std::mutex creatorMutex_;
+ std::unordered_map creators_;
+};
+
+template class BrokerDelegator {
+public:
+ BrokerDelegator();
+ ~BrokerDelegator();
+
+private:
+ BrokerDelegator(const BrokerDelegator &) = delete;
+ BrokerDelegator(BrokerDelegator &&) = delete;
+ BrokerDelegator &operator = (const BrokerDelegator &) = delete;
+ BrokerDelegator &operator = (BrokerDelegator &&) = delete;
+};
+
+template BrokerDelegator::BrokerDelegator()
+{
+ const std::u16string descriptor = T::GetDescriptor();
+ BrokerRegistration ®istration = BrokerRegistration::Get();
+ registration.Register(descriptor, BrokerCreator());
+}
+
+template BrokerDelegator::~BrokerDelegator()
+{
+ const std::u16string descriptor = T::GetDescriptor();
+ BrokerRegistration ®istration = BrokerRegistration::Get();
+ registration.Unregister(descriptor);
+}
+
+template inline sptr iface_cast(const sptr &object)
+{
+ const std::u16string descriptor = INTERFACE::GetDescriptor();
+ BrokerRegistration ®istration = BrokerRegistration::Get();
+ sptr broker = registration.NewInstance(descriptor, object);
+ return static_cast(broker.GetRefPtr());
+}
+} // namespace OHOS
+#endif // OHOS_IPC_IREMOTE_BROKER_H
diff --git a/interfaces/innerkits/ipc_core/include/iremote_object.h b/interfaces/innerkits/ipc_core/include/iremote_object.h
new file mode 100755
index 00000000..3d73fa69
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/iremote_object.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2021 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_IPC_IREMOTE_OBJECT_H
+#define OHOS_IPC_IREMOTE_OBJECT_H
+
+#include
+#include
+#include
+#include
+#include "ipc_types.h"
+#include "message_parcel.h"
+#include "message_option.h"
+
+namespace OHOS {
+class IRemoteBroker;
+inline std::u16string to_utf16(const std::string &str)
+{
+ return std::wstring_convert, char16_t> {}.from_bytes(str);
+}
+
+class IRemoteObject : public virtual Parcelable, public virtual RefBase {
+public:
+ enum {
+ IF_PROT_DEFAULT, /* Invoker family. */
+ IF_PROT_BINDER = IF_PROT_DEFAULT,
+ IF_PROT_DATABUS,
+ };
+ enum {
+ DATABUS_TYPE,
+ };
+ class DeathRecipient : public RefBase {
+ public:
+ enum {
+ ADD_DEATH_RECIPIENT,
+ REMOVE_DEATH_RECIPIENT,
+ NOTICE_DEATH_RECIPIENT,
+ TEST_SERVICE_DEATH_RECIPIENT,
+ TEST_DEVICE_DEATH_RECIPIENT,
+ };
+ virtual void OnRemoteDied(const wptr &object) = 0;
+ };
+
+ virtual int32_t GetObjectRefCount() = 0;
+
+ virtual int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) = 0;
+
+ virtual bool IsProxyObject() const;
+
+ virtual bool CheckObjectLegality() const;
+
+ virtual bool AddDeathRecipient(const sptr &recipient) = 0;
+
+ virtual bool RemoveDeathRecipient(const sptr &recipient) = 0;
+
+ virtual bool Marshalling(Parcel &parcel) const override;
+
+ static IRemoteObject *Unmarshalling(Parcel &parcel);
+
+ static bool Marshalling(Parcel &parcel, const sptr &object);
+
+ virtual sptr AsInterface();
+
+ virtual int Dump(int fd, const std::vector &args) = 0;
+
+ const std::u16string descriptor_;
+
+ std::u16string GetObjectDescriptor() const;
+
+protected:
+ explicit IRemoteObject(std::u16string descriptor = nullptr);
+};
+} // namespace OHOS
+#endif // OHOS_IPC_IREMOTE_OBJECT_H
diff --git a/interfaces/innerkits/ipc_core/include/iremote_proxy.h b/interfaces/innerkits/ipc_core/include/iremote_proxy.h
new file mode 100755
index 00000000..fff5bc5f
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/iremote_proxy.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2021 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_IPC_IREMOTE_PROXY_H
+#define OHOS_IPC_IREMOTE_PROXY_H
+
+#include "iremote_broker.h"
+#include "peer_holder.h"
+#include "iremote_object.h"
+
+namespace OHOS {
+template class IRemoteProxy : public PeerHolder, public INTERFACE {
+public:
+ explicit IRemoteProxy(const sptr &object);
+ ~IRemoteProxy() override = default;
+
+protected:
+ sptr AsObject() override;
+};
+
+template
+IRemoteProxy::IRemoteProxy(const sptr &object) : PeerHolder(object)
+{
+}
+
+template sptr IRemoteProxy::AsObject()
+{
+ return Remote();
+}
+} // namespace OHOS
+#endif // OHOS_IPC_IREMOTE_PROXY_H
diff --git a/interfaces/innerkits/ipc_core/include/iremote_stub.h b/interfaces/innerkits/ipc_core/include/iremote_stub.h
new file mode 100755
index 00000000..3151a93a
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/iremote_stub.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2021 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_IPC_IREMOTE_STUB_H
+#define OHOS_IPC_IREMOTE_STUB_H
+
+#include
+#include "iremote_broker.h"
+#include "ipc_object_stub.h"
+
+namespace OHOS {
+template class IRemoteStub : public IPCObjectStub, public INTERFACE {
+public:
+ IRemoteStub();
+ virtual ~IRemoteStub() = default;
+ sptr AsObject() override;
+ sptr AsInterface() override;
+};
+
+template IRemoteStub::IRemoteStub() : IPCObjectStub(INTERFACE::GetDescriptor()) {}
+
+template sptr IRemoteStub::AsInterface()
+{
+ return this;
+}
+
+template sptr IRemoteStub::AsObject()
+{
+ return this;
+}
+} // namespace OHOS
+#endif // OHOS_IPC_IREMOTE_STUB_H
diff --git a/interfaces/innerkits/ipc_core/include/jni_help.h b/interfaces/innerkits/ipc_core/include/jni_help.h
new file mode 100755
index 00000000..fb286bfd
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/jni_help.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2021 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_IPC_JNI_HELP_H
+#define OHOS_IPC_JNI_HELP_H
+
+#include
+#include
+#include
+
+namespace OHOS {
+jobject JNIHelperGetJavaRemoteObject(JNIEnv *env, const sptr &target);
+} // namespace OHOS
+#endif // OHOS_IPC_JNI_HELP_H
diff --git a/interfaces/innerkits/ipc_core/include/message_option.h b/interfaces/innerkits/ipc_core/include/message_option.h
new file mode 100755
index 00000000..7aa96519
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/message_option.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2021 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_IPC_MESSAGE_OPTION_H
+#define OHOS_IPC_MESSAGE_OPTION_H
+
+#include
+namespace OHOS {
+class MessageOption {
+public:
+ enum {
+ TF_SYNC = 0x00,
+ TF_ASYNC = 0x01,
+ TF_STATUS_CODE = 0x08,
+ TF_ACCEPT_FDS = 0x10,
+ TF_WAIT_TIME = 0x4,
+ };
+ MessageOption(int flags = TF_SYNC, int waitTime = TF_WAIT_TIME);
+ ~MessageOption() = default;
+ void SetFlags(int flags);
+ int GetFlags() const;
+ void SetWaitTime(int waitTime);
+ int GetWaitTime() const;
+
+private:
+ uint32_t flags_;
+ int waitTime_;
+};
+using MessageOptionPtr = std::shared_ptr;
+} // namespace OHOS
+#endif // OHOS_IPC_MESSAGE_OPTION_H
\ No newline at end of file
diff --git a/interfaces/innerkits/ipc_core/include/message_parcel.h b/interfaces/innerkits/ipc_core/include/message_parcel.h
new file mode 100755
index 00000000..8542b860
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/message_parcel.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2021 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_IPC_MESSAGE_PARCEL_H
+#define OHOS_IPC_MESSAGE_PARCEL_H
+
+#include
+#include "parcel.h"
+#include "refbase.h"
+#include
+
+namespace OHOS {
+class IRemoteObject;
+class MessageParcel : public Parcel {
+public:
+ MessageParcel();
+ ~MessageParcel();
+ explicit MessageParcel(Allocator *allocator);
+ bool WriteRemoteObject(const sptr &object);
+ sptr ReadRemoteObject();
+ bool WriteFileDescriptor(int fd);
+ int ReadFileDescriptor();
+ bool ContainFileDescriptors() const;
+ bool WriteInterfaceToken(std::u16string name);
+ std::u16string ReadInterfaceToken();
+ bool WriteRawData(const void *data, size_t size);
+ const void *ReadRawData(size_t size);
+ bool RestoreRawData(std::shared_ptr rawData, size_t size);
+ const void *GetRawData() const;
+ size_t GetRawDataSize() const;
+ size_t GetRawDataCapacity() const;
+ void WriteNoException();
+ int32_t ReadException();
+ bool WriteAshmem(sptr ashmem);
+ sptr ReadAshmem();
+ void ClearFileDescriptor();
+ void SetClearFdFlag()
+ {
+ needCloseFd_ = true;
+ };
+
+private:
+ static constexpr size_t MAX_RAWDATA_SIZE = 128 * 1024 * 1024; // 128M
+ static constexpr size_t MIN_RAWDATA_SIZE = 32 * 1024; // 32k
+ bool needCloseFd_ = false;
+ std::vector> holders_;
+ int writeRawDataFd_;
+ int readRawDataFd_;
+ void *kernelMappedWrite_;
+ void *kernelMappedRead_;
+ std::shared_ptr rawData_;
+ size_t rawDataSize_;
+};
+} // namespace OHOS
+#endif // OHOS_IPC_MESSAGE_PARCEL_H
diff --git a/interfaces/innerkits/ipc_core/include/peer_holder.h b/interfaces/innerkits/ipc_core/include/peer_holder.h
new file mode 100755
index 00000000..9ca9c7bf
--- /dev/null
+++ b/interfaces/innerkits/ipc_core/include/peer_holder.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2021 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_IPC_PEER_HOLDER_H
+#define OHOS_IPC_PEER_HOLDER_H
+
+#include "iremote_object.h"
+
+namespace OHOS {
+class PeerHolder {
+protected:
+ PeerHolder(const sptr &object);
+
+ ~PeerHolder() = default;
+
+ sptr Remote();
+
+private:
+ const sptr remoteObject_;
+};
+} // namespace OHOS
+#endif // OHOS_IPC_PEER_HOLDER_H
diff --git a/interfaces/innerkits/ipc_single/BUILD.gn b/interfaces/innerkits/ipc_single/BUILD.gn
new file mode 100755
index 00000000..7e9610a2
--- /dev/null
+++ b/interfaces/innerkits/ipc_single/BUILD.gn
@@ -0,0 +1,58 @@
+# Copyright (C) 2021 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.
+
+import("//build/ohos.gni")
+
+SUBSYSTEM_DIR = "//foundation/communication/ipc"
+IPC_CORE_ROOT = "$SUBSYSTEM_DIR/ipc/native"
+
+config("libipc_single_private_config") {
+ cflags_cc = [
+ "-DCONFIG_IPC_SINGLE",
+ "-O2",
+ ]
+}
+ohos_shared_library("ipc_single") {
+ include_dirs = [ "$SUBSYSTEM_DIR/utils/include" ]
+ sources = [
+ "$IPC_CORE_ROOT/src/core/source/ipc_file_descriptor.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_object_proxy.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_object_stub.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_process_skeleton.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_skeleton.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_thread_pool.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_thread_skeleton.cpp",
+ "$IPC_CORE_ROOT/src/core/source/ipc_workthread.cpp",
+ "$IPC_CORE_ROOT/src/core/source/iremote_broker.cpp",
+ "$IPC_CORE_ROOT/src/core/source/iremote_object.cpp",
+ "$IPC_CORE_ROOT/src/core/source/message_option.cpp",
+ "$IPC_CORE_ROOT/src/core/source/message_parcel.cpp",
+ "$IPC_CORE_ROOT/src/core/source/peer_holder.cpp",
+ "$IPC_CORE_ROOT/src/mock/source/binder_connector.cpp",
+ "$IPC_CORE_ROOT/src/mock/source/binder_debug.cpp",
+ "$IPC_CORE_ROOT/src/mock/source/binder_invoker.cpp",
+ "$IPC_CORE_ROOT/src/mock/source/invoker_factory.cpp",
+ "$IPC_CORE_ROOT/src/mock/source/invoker_rawdata.cpp",
+ ]
+
+ configs = [
+ "$SUBSYSTEM_DIR:ipc_util_config",
+ ":libipc_single_private_config",
+ ]
+ public_configs = [ "$SUBSYSTEM_DIR:ipc_util_config" ]
+ deps = [ "//utils/native/base:utils" ]
+
+ external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
+ subsystem_name = "communication"
+ part_name = "ipc"
+}
diff --git a/interfaces/innerkits/libdbinder/BUILD.gn b/interfaces/innerkits/libdbinder/BUILD.gn
new file mode 100755
index 00000000..b059cdda
--- /dev/null
+++ b/interfaces/innerkits/libdbinder/BUILD.gn
@@ -0,0 +1,66 @@
+# Copyright (C) 2021 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.
+
+import("//build/ohos.gni")
+
+SUBSYSTEM_DIR = "//foundation/communication/ipc"
+DBINDER_ROOT = "$SUBSYSTEM_DIR/services/dbinder"
+
+config("libdbinder_config") {
+ visibility = [ ":*" ]
+ cflags = []
+ if (target_cpu == "arm") {
+ cflags = [ "-DBINDER_IPC_32BIT" ]
+ }
+ if (is_standard_system) {
+ cflags += [ "-DCONFIG_STANDARD_SYSTEM" ]
+ }
+ include_dirs = [
+ "//utils/native/base/include",
+ "$SUBSYSTEM_DIR/interfaces/innerkits/ipc_core/include",
+ "$SUBSYSTEM_DIR/interfaces/innerkits/libdbinder/include",
+ "$DBINDER_ROOT/dbinder_service/include",
+ ]
+}
+
+config("libdbinder_private_config") {
+ visibility = [ ":*" ]
+ cflags_cc = [
+ "-DLOG_TAG=\"libdbinder\"",
+ "-O2",
+ ]
+}
+
+ohos_shared_library("libdbinder") {
+ include_dirs = [ "$SUBSYSTEM_DIR/utils/include" ]
+ sources = [
+ "$DBINDER_ROOT/dbinder_service/src/dbinder_death_recipient.cpp",
+ "$DBINDER_ROOT/dbinder_service/src/dbinder_sa_death_recipient.cpp",
+ "$DBINDER_ROOT/dbinder_service/src/dbinder_service.cpp",
+ "$DBINDER_ROOT/dbinder_service/src/dbinder_service_stub.cpp",
+ "$DBINDER_ROOT/dbinder_service/src/socket/dbinder_remote_listener.cpp",
+ ]
+ public_configs = [ ":libdbinder_config" ]
+ configs = [ ":libdbinder_private_config" ]
+ deps = [
+ "$SUBSYSTEM_DIR/interfaces/innerkits/ipc_core:ipc_core",
+ "//utils/native/base:utils",
+ ]
+ external_deps = [
+ "dsoftbus_standard:softbus_client",
+ "hiviewdfx_hilog_native:libhilog",
+ "samgr_L2:samgr_proxy",
+ ]
+ subsystem_name = "communication"
+ part_name = "ipc"
+}
diff --git a/interfaces/innerkits/libdbinder/include/dbinder_service.h b/interfaces/innerkits/libdbinder/include/dbinder_service.h
new file mode 100755
index 00000000..0b09341c
--- /dev/null
+++ b/interfaces/innerkits/libdbinder/include/dbinder_service.h
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2021 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_IPC_SERVICES_DBINDER_DBINDER_SERVICE_H
+#define OHOS_IPC_SERVICES_DBINDER_DBINDER_SERVICE_H
+
+#include
+#include