Registry

Overview

Provides APIs for registering and discovering inter-process communication (IPC) capabilities.

Based on the Samgr development framework, this module helps you to develop system capabilities and implement cross-process calls. This module is used when system capabilities need to be provided across processes.

Since:

1.0

Version:

1.0

Summary

Files

File Name

Description

iproxy_client.h

Provides the client proxy class.

iproxy_server.h

Provides the server proxy.

registry.h

Provides basic APIs for remote service registration and discovery.

Data Structures

Data Structure Name

Description

IClientProxy

Defines the client proxy object.

IServerProxy

Defines the base class of the server proxy object.

Macros

Macro Name and Value

Description

INHERIT_CLIENT_IPROXY

Indicates the inherited macro of the client proxy.

INHERIT_IPROXY_ENTRY(T)   INHERIT_IUNKNOWNENTRY(T)

Inherits the server proxy class.

IPROXY_END   IUNKNOWN_ENTRY_END

Defines the end of the default initialization for the server proxy class.

SERVER_PROXY_VER   0x80

Defines the default version number of the server proxy.

INHERIT_SERVER_IPROXY

Inherits the server proxy function.

SERVER_IPROXY_BEGIN   IUNKNOWN_ENTRY_BEGIN(SERVER_PROXY_VER)

Defines the beginning of the default initialization for the server proxy class.

Typedefs

Typedef Name

Description

INotify) (IOwner owner, int code, IpcIo reply)

typedef int( 

Called when a client request is responded.

Creator) (const char service, const char feature, uint32 size)

typedef void ( 

Indicates the creator of the customized client proxy.

Destroyer) (const char service, const char feature, void iproxy)

typedef void( 

Indicates the destroyer of the customized client proxy.

Functions

Function Name

Description

SAMGR_GetRemoteIdentity (const char service, const char feature)

SvcIdentity 

Obtains the IPC address of a remote service and feature based on the service name and feature name.

SAMGR_RegisterFactory (const char service, const char feature, Creator creator, Destroyer destroyer)

int 

Registers the factory method of the client proxy object with the Samgr.

Details

Macro Definition Documentation

INHERIT_CLIENT_IPROXY

  1. #define INHERIT_CLIENT_IPROXY
  1. Values:[INHERIT_IUNKNOWN](Samgr.md#gab74532a22d6993d0ffc014d36253397f); \
  2. int(*Invoke)([IClientProxy]($api-api-SmartVision-Devices-IClientProxy.md)*proxy,int funcId,IpcIo*request,IOwner owner,[INotify]($api-api-SmartVision-Devices-Registry.md#ga362a17c1bda1aace88d42dcbc88bdfac) notify)

Description:

Indicates the inherited macro of the client proxy.

This constant is used when a client proxy needs to be customized or generated by a tool.

INHERIT_IPROXY_ENTRY

  1. #define INHERIT_IPROXY_ENTRY( T)[INHERIT_IUNKNOWNENTRY]($api-api-SmartVision-Devices-Samgr.md#gad6324fd90dd636180efa2a59b377e65c)(T)

Description:

Inherits the server proxy class.

When the server provides cross-process system capabilities, it uses INHERIT_IPROXY_ENTRY to define the server proxy class.

INHERIT_SERVER_IPROXY

  1. #define INHERIT_SERVER_IPROXY
  1. Values:[INHERIT_IUNKNOWN](Samgr.md#gab74532a22d6993d0ffc014d36253397f); \
  2. int32 (*Invoke)([IServerProxy]($api-api-SmartVision-Devices-IServerProxy.md)*iProxy,int funcId,void*origin,IpcIo*req,IpcIo*reply)

Description:

Inherits the server proxy function.

When the server provides cross-process system capabilities, it uses INHERIT_SERVER_IPROXY to define the server proxy function.

IPROXY_END

  1. #define IPROXY_END [IUNKNOWN_ENTRY_END]($api-api-SmartVision-Devices-Samgr.md#ga4ef734474ece49aa938d8ebd5b54bdb3)

Description:

Defines the end of the default initialization for the server proxy class.

This macro is used for developing the server proxy class. You can inherit this macro to reduce the code amount and prevent class definition inconsistency.

SERVER_IPROXY_BEGIN

  1. #define SERVER_IPROXY_BEGIN [IUNKNOWN_ENTRY_BEGIN]($api-api-SmartVision-Devices-Samgr.md#ga52ec6b5b03d56b0dfe7277785246bda1)([SERVER_PROXY_VER]($api-api-SmartVision-Devices-Registry.md#gad513d97bfb873f27c9b8f69a5a418d55))

Description:

Defines the beginning of the default initialization for the server proxy class.

This macro is used for developing the server proxy class. You can inherit this macro to reduce the code amount and prevent class definition inconsistency.

SERVER_PROXY_VER

  1. #define SERVER_PROXY_VER 0x80

Description:

Defines the default version number of the server proxy.

The cross-process system capabilities are registered when Samgr uses SERVER_PROXY_VER to query the registered server proxy.

Typedef Documentation

Creator

  1. typedefvoid*(*Creator)(constchar*service,constchar*feature, uint32 size)

Description:

Indicates the creator of the customized client proxy.

This macro creates a local client proxy for remote service APIs. If you want to call the remote APIs in the way that local APIs are called, implement this macro to encapsulate serialized data into the proxy. The system automatically calls this macro when creating a proxy object.

Parameters:

Name

Description

serviceIndicates the pointer to the name of the service to which the function belongs.
featureIndicates the pointer to the name of the feature to which the function belongs.
sizeIndicates the size of the head to be added when a client proxy is created. The required memory capacity is the head size plus the object size.

Returns:

void * Returns the applied memory capacity and initialize the memory for the client proxy.

Destroyer

  1. typedefvoid(*Destroyer)(constchar*service,constchar*feature,void*iproxy)

Description:

Indicates the destroyer of the customized client proxy.

This macro destroys local client proxy for remote service APIs. If you want to call the remote APIs in the way that local APIs are called, implement this macro to encapsulate serialized data into the proxy. The system automatically calls this macro when destroying a proxy object.

Parameters:

Name

Description

serviceIndicates the pointer to the name of the service to which the function belongs.
featureIndicates the pointer to the name of the feature to which the function belongs.
iproxyIndicates the pointer to the start address of the memory that is applied by Creator.

INotify

  1. typedefint(*INotify)(IOwner owner,int code,IpcIo*reply)

Description:

Called when a client request is responded.

The client implements this INotify callback to receive response data from the server. owner indicates the client proxy that receives the response data; code indicates the error code of the response data from the server; reply indicates the response data.

Function Documentation

SAMGR_GetRemoteIdentity()

  1. SvcIdentity SAMGR_GetRemoteIdentity (constchar* service,constchar* feature )

Description:

Obtains the IPC address of a remote service and feature based on the service name and feature name.

This function is used when IClientProxy cannot meet your requirements for calling IPCs. For example, if you need to receive the death notification of a remote service or feature, you can call this function to obtain the address of the remote service or feature and subscribe to the death notification from the IPC.

Parameters:

Name

Description

serviceIndicates the pointer to the name of the remote service.
featureIndicates the pointer to the name of the remote feature.

Returns:

Returns the IPC address of the remote service or feature. When the handle of the obtained address structure SvcIdentity is 0xFFFFFFFF, the address is invalid.

Attention:

This function can be called only after GetFeatureApi in SamgrLite is successfully called. Otherwise, an invalid address is returned. When the service or feature does not support IPC communication, an invalid address will be returned.

SAMGR_RegisterFactory()

  1. int SAMGR_RegisterFactory (constchar* service,constchar* feature,[Creator]($api-api-SmartVision-Devices-Registry.md#ga0c8aa2ef9883bd97b4f1309895adaa4c) creator, [Destroyer]($api-api-SmartVision-Devices-Registry.md#ga1e6298b1246357f70ad0b581e0eb9305) destroyer )

Description:

Registers the factory method of the client proxy object with the Samgr.

If you want to call the remote APIs in the way that local APIs are called, implement this function to encapsulate serialized data into the proxy. During system initialization, the module that uses the remote proxy calls the function as required.

Parameters:

Name

Description

serviceIndicates the pointer to the service name of the client proxy.
featureIndicates the pointer to the feature name of the client proxy.
creatorIndicates the Creator function of the client proxy.
destroyerIndicates the Destroyer function of the client proxy.

Returns:

Returns EC_SUCCESS if the registration is successful; returns other error codes if the registration fails.