【架构分析】Fuchsia IPC 详解
目录
Fuchsia IPC Architecture Overview
概述
Fuchsia使用Fuchsia Interface Definition Language (FIDL) 作为进程IPC的接口描述语言,本文旨在详细分析基于FIDL的IPC原理
Fuchsia IPC Architecture Overview
- 通过FIDL描述IPC接口Interface
- Client 进程使用InterfacePtr<Interface>来调用Interface中的接口获得服务
- Service进程实现Interface中的接口来提供服务
- 为了描述更具体清晰,本文使用view_provider.fidl 作为Interface的具体例子来分析IPC的原理和过程
[Discoverable]
interface ViewProvider {
// Creates a new View under the control of the ViewProvider.
//
// |token| is one half of the shared eventpair which will bind the new View
// to its associated ViewHolder. The ViewProvider will use |token| to
// create its internal View representation. The caller is expected to use
// its half to create corresponding ViewHolder object.
//
// |incoming_services| allows clients to request services from the
// ViewProvider implementation. |outgoing_services| allows clients to
// provide services of their own to the ViewProvider implementation.
//
// Clients can embed a ViewHolder (and by proxy the paired View) into their
// scene graph by using |Node.AddChild()|. The ViewHolder cannot itself
// have any children. A ViewProvider implementation can nest scene objects
// within its View by using |View.AddChild()|. The View itself
// cannot be a child of anything.
//
// Modules can use these mechanisms to establish a distributed,
// inter-process scene graph.
CreateView(handle<eventpair> token,
request<fuchsia.sys.ServiceProvider>? incoming_services,
fuchsia.sys.ServiceProvider? outgoing_services);
};
FIDL IPC 详解
FIDL IPC中涉及的Class大致可以分为4种
- Client端使用的Class
- Service端使用的Class
- FIDL自动代码生成的Class
- Client和Service都会使用到的Class(包括访问Zircon微内核channel的Class)
下面依然以FIDL view_provider.fidl 中定义的interface ViewProvider作为具体的例子说明Client与Service的IPC时序
Tips
- Fuchsia FIDL文件的位置: fuchsia/garnet/public/fidl/<fuchsia.package.name>
- 编译FIDL后自动生成的代码位置:fuchsia/out/arm64/fidling/gen/fuchsia/<package>/<name>