1 /* 2 * Copyright (c) 2020 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup Registry 18 * @{ 19 * 20 * @brief Provides APIs for registering and discovering inter-process communication (IPC) 21 * capabilities. 22 * 23 * Based on the Samgr development framework, this module helps you to develop system capabilities 24 * and implement cross-process calls. \n 25 * This module is used when system capabilities need to be provided across processes. \n 26 * 27 * @since 1.0 28 * @version 1.0 29 */ 30 31 /** 32 * @file iproxy_server.h 33 * 34 * @brief Provides the server proxy. 35 * 36 * This feature is required for providing cross-process system capabilities. \n 37 * 38 * @since 1.0 39 * @version 1.0 40 */ 41 42 #ifndef LITE_IPROXY_SERVER_H 43 #define LITE_IPROXY_SERVER_H 44 45 #include "iunknown.h" 46 #include "message.h" 47 #include "serializer.h" 48 49 #ifdef __cplusplus 50 #if __cplusplus 51 extern "C" { 52 #endif 53 #endif 54 55 /** 56 * @brief Defines the default version number of the server proxy. 57 * 58 * The cross-process system capabilities are registered when Samgr uses <b>SERVER_PROXY_VER</b> 59 * to query the registered server proxy. \n 60 * 61 */ 62 #define SERVER_PROXY_VER 0x80 63 #define SERVER_IMPL_PROXY_VER ((uint16)SERVER_PROXY_VER | (uint16)DEFAULT_VERSION) 64 65 /** 66 * @brief Inherits the server proxy function. 67 * 68 * When the server provides cross-process system capabilities, it uses <b>INHERIT_SERVER_IPROXY</b> 69 * to define the server proxy function. \n 70 * 71 */ 72 #define INHERIT_SERVER_IPROXY \ 73 INHERIT_IUNKNOWN; \ 74 int32 (*Invoke)(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply) 75 76 typedef struct IServerProxy IServerProxy; 77 78 /** 79 * @brief Defines the base class of the server proxy object. 80 * 81 * When the server provides cross-process system capabilities, it uses <b>INHERIT_SERVER_IPROXY</b> 82 * to define the server proxy. \n 83 */ 84 struct IServerProxy { 85 /** This class inherits from <b>IUnknown</b>. */ 86 INHERIT_IUNKNOWN; 87 /** 88 * @brief Unmarshals the IPC message received by the server. 89 * 90 * This function is implemented by developers and called by the system. \n 91 * This function runs in the message processing thread of the service. Do not block the message 92 * processing thread; otherwise, the function may fail to be executed. \n 93 * 94 * @param Proxy Indicates the pointer to the server proxy object. 95 * @param funcId Indicates the ID of the server function to be invoked by the client. 96 * @param origin Indicates the original IPC message, from which the header information can be 97 * obtained. 98 * @param req ipc Indicates the message body, from which data can be obtained. 99 * @param reply Indicates the output parameter, which is used to respond to the message. 100 * The value can contain a maximum of five objects and 200 bytes. 101 * @return Returns <b>EC_SUCCESS</b> if the unmarshalling is successful; returns other error 102 * codes if the unmarshalling fails. 103 * @since 1.0 104 * @version 1.0 105 */ 106 int32 (*Invoke)(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply); 107 }; 108 109 /** 110 * @brief Inherits the server proxy class. 111 * 112 * When the server provides cross-process system capabilities, it uses <b>INHERIT_IPROXY_ENTRY</b> 113 * to define the server proxy class. \n 114 * 115 */ 116 #define INHERIT_IPROXY_ENTRY(T) INHERIT_IUNKNOWNENTRY(T) 117 118 /** 119 * @brief Defines the beginning of the default initialization for the server proxy class. 120 * 121 * This macro is used for developing the server proxy class. You can inherit this macro to 122 * reduce the code amount and prevent class definition inconsistency. \n 123 * 124 */ 125 #define SERVER_IPROXY_BEGIN IUNKNOWN_ENTRY_BEGIN(SERVER_PROXY_VER) 126 127 #define SERVER_IPROXY_IMPL_BEGIN IUNKNOWN_ENTRY_BEGIN(SERVER_IMPL_PROXY_VER) 128 129 /** 130 * @brief Defines the end of the default initialization for the server proxy class. 131 * 132 * This macro is used for developing the server proxy class. You can inherit this macro to 133 * reduce the code amount and prevent class definition inconsistency. \n 134 * 135 */ 136 #define IPROXY_END IUNKNOWN_ENTRY_END 137 138 #ifdef __cplusplus 139 #if __cplusplus 140 } 141 #endif 142 #endif 143 #endif // LITE_IPROXY_SERVER_H 144 /** @} */ 145