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 #ifndef LITE_ENDPOINT_H 16 #define LITE_ENDPOINT_H 17 18 #include <stddef.h> 19 #include "common.h" 20 #include "iproxy_server.h" 21 #include "default_client.h" 22 #include "token_bucket.h" 23 24 #ifdef __cplusplus 25 #if __cplusplus 26 extern "C" { 27 #endif 28 #endif 29 30 #define SAMGR_HANDLE 0 31 #define SAMGR_TOKEN 0 32 #define SAMGR_COOKIE 0 33 #define MAX_DATA_LEN 0x100 34 #define MIN_DATA_LEN 0x40 35 #ifndef MAX_SYSCAP_NUM 36 #define MAX_SYSCAP_NUM 512 37 #endif 38 39 #ifndef MAX_SYSCAP_NAME_LEN 40 #define MAX_SYSCAP_NAME_LEN 64 41 #endif 42 43 typedef enum ResourceID { 44 RES_ENDPOINT, 45 RES_FEATURE, 46 RES_SYSCAP, 47 RES_BUTT, 48 } ResourceID; 49 50 typedef enum OptionID { 51 OP_GET, 52 OP_POST, 53 OP_PUT, 54 OP_DELETE, 55 OP_ALL, 56 } OptionID; 57 typedef struct Endpoint Endpoint; 58 59 #ifndef MINI_SAMGR_LITE_RPC 60 typedef int (*RegisterEndpoint)(const IpcContext *context, SvcIdentity *identity); 61 #else 62 typedef int (*RegisterEndpoint)(SvcIdentity *identity, int token, const char *service, const char *feature); 63 #endif 64 65 struct Endpoint { 66 const char *name; 67 #ifndef MINI_SAMGR_LITE_RPC 68 IpcContext *context; 69 #endif 70 Vector routers; 71 ThreadId boss; 72 uint32 deadId; 73 int running; 74 SvcIdentity identity; 75 RegisterEndpoint registerEP; 76 TokenBucket bucket; 77 }; 78 79 Endpoint *SAMGR_CreateEndpoint(const char *name, RegisterEndpoint registry); 80 int SAMGR_AddRouter(Endpoint *endpoint, const SaName *saName, const Identity *id, IUnknown *proxy); 81 int SAMGR_ProcPolicy(const Endpoint *endpoint, const SaName *saName, int token); 82 int32 SAMGR_AddSysCap(const Endpoint *endpoint, const char *sysCap, BOOL isReg); 83 int32 SAMGR_GetSysCap(const Endpoint *endpoint, const char *sysCap, BOOL *isReg); 84 int32 SAMGR_GetSystemCapabilities(const Endpoint *endpoint, 85 char sysCaps[MAX_SYSCAP_NUM][MAX_SYSCAP_NAME_LEN], int32 *sysCapNum); 86 87 #ifdef __cplusplus 88 #if __cplusplus 89 } 90 #endif 91 #endif 92 #endif // LITE_ENDPOINT_H 93