当前位置:网站首页>Openharmony module 2 file samgr_ Server parsing (4)
Openharmony module 2 file samgr_ Server parsing (4)
2022-07-18 07:23:00 【Pseudo procedural ape who loves fishing】
distributedschedule_samgr_lite/samgr_server/source/samgr_server.c
Process acquisition function , Used to obtain the characteristic value of the process
static int32 ProcGetFeature(SamgrServer *server, const void *origin, IpcIo *req, IpcIo *reply, SvcIdentity *identity)
{
size_t len = 0;
char *service = (char *)IpcIoPopString(req, &len);
if (service == NULL || len == 0) {
IpcIoPushInt32(reply, EC_INVALID);
return EC_INVALID;
}
char *feature = IpcIoPopBool(req) ? NULL : (char *)IpcIoPopString(req, &len);
MUTEX_Lock(server->mtx); // The mutex
*identity = SASTORA_Find(&server->store, service, feature);
// If the identity meets the following conditions , Prompt that the function cannot be found , Report errors
if (identity->handle == INVALID_INDEX) {
MUTEX_Unlock(server->mtx);
HILOG_DEBUG(HILOG_MODULE_SAMGR, "Cannot Find Feature<%s, %s> id<%d, %d> ret:%d",
service, feature, identity->handle, identity->token, EC_NOSERVICE);
return EC_NOSERVICE;
}
PidHandle providerPid = SASTORA_FindPidHandleByIpcHandle(&server->store, identity->handle);
MUTEX_Unlock(server->mtx);
// If provided pid For the following cases , Can't find pid To deal with the id
if (providerPid.pid == INVALID_INDEX || providerPid.uid == INVALID_INDEX) {
HILOG_DEBUG(HILOG_MODULE_SAMGR, "Cannot Find PidHandle<%s, %s> id<%d, %d> ret:%d",
service, feature, identity->handle, identity->token, EC_FAILURE);
return EC_FAILURE;
}
AuthParams authParams = {
.providerService = service,
.providerfeature = feature,
.consumerPid = GetCallingPid(origin),
.consumerUid = GetCallingUid(origin),
.providerPid = providerPid.pid,
.providerUid = providerPid.uid
};
int isAuth = g_server.ipcAuth->IsCommunicationAllowed(authParams);
HILOG_DEBUG(HILOG_MODULE_SAMGR, "Judge Auth<%s, %s> ret:%d", service, feature, isAuth);
int32 ret = (isAuth == EC_SUCCESS) ? AddServiceAccess(*identity, GetCallingTid(origin)) : EC_PERMISSION;
HILOG_DEBUG(HILOG_MODULE_SAMGR, "Find Feature<%s, %s> id<%d, %d> ret:%d",
service, feature, identity->handle, identity->token, ret);
return ret;
}
Process characteristics , This function is used to detect whether the characteristic value is set successfully
static int ProcFeature(SamgrServer *server, int32 option, void *origin, IpcIo *req, IpcIo *reply)
{
if (option != OP_PUT && option != OP_GET) {
IpcIoPushInt32(reply, EC_INVALID);
return EC_INVALID;
}
if (g_server.ipcAuth == NULL) {
g_server.ipcAuth = GetIpcAuthInterface();
}
if (g_server.ipcAuth == NULL) {
IpcIoPushInt32(reply, EC_NOINIT);
return EC_NOINIT;
}
int ret = EC_SUCCESS;
SvcIdentity identity = {
INVALID_INDEX, INVALID_INDEX, INVALID_INDEX};
if (option == OP_PUT) {
ret = ProcPutFeature(server, origin, req, reply, &identity);
}
if (ret != EC_SUCCESS) {
return ret;
}
if (option == OP_GET) {
ret = ProcGetFeature(server, origin, req, reply, &identity);
IpcIoPushInt32(reply, ret);
if (ret == EC_SUCCESS) {
IpcIoPushSvc(reply, &identity);
}
}
return ret;
}
Program adds system upper limit
static int32 ProcAddSysCap(SamgrServer *server, IpcIo *req)
{
size_t len = 0;
char *sysCap = (char *)IpcIoPopString(req, &len);
// If the following conditions are met , Then add the system program syscap Invalid
if (sysCap == NULL || len == 0 || len > MAX_SYSCAP_NAME_LEN) {
HILOG_ERROR(HILOG_MODULE_SAMGR, "ProcAddSysCap sysCap invalid");
return EC_INVALID;
}
MUTEX_Lock(server->sysCapMtx); // The mutex
Vector *sysCapablitys = &(server->sysCapabilitys);
// Check the position of the element with the specified key
int16 pos = VECTOR_FindByKey(sysCapablitys, (void *)sysCap); // This function is used to check the element according to the key value of the element
//vector Denotes the <b> The pointer .
//key Represents a pointer to the key value of the element to be checked .
if (pos < 0) {
MUTEX_Unlock(server->sysCapMtx); // Mutually exclusive unlock
return EC_FAILURE;
}
SysCapImpl *serviceImpl = (SysCapImpl *)VECTOR_At(sysCapablitys, pos);
if (serviceImpl == NULL || serviceImpl->name == NULL) {
MUTEX_Unlock(server->sysCapMtx);
return EC_FAILURE;
}
serviceImpl->isRegister = TRUE;
MUTEX_Unlock(server->sysCapMtx); // Mutually exclusive unlock
return EC_SUCCESS;
}
Get the upper limit of the system process
static BOOL ProcGetSysCap(const SamgrServer *server, IpcIo *req)
{
size_t len = 0;
char *sysCap = (char *)IpcIoPopString(req, &len);
// If the following conditions are met , Get invalid , Return error
if (sysCap == NULL || len == 0 || len > MAX_SYSCAP_NAME_LEN) {
HILOG_ERROR(HILOG_MODULE_SAMGR, "ProcGetSysCap sysCap invalid");
return FALSE;
}
MUTEX_Lock(server->sysCapMtx); // The mutex
Vector *sysCapablitys = &(server->sysCapabilitys);
int16 pos = VECTOR_FindByKey(sysCapablitys, (void *)sysCap); // Check the position of the element with the specified key
if (pos < 0) {
MUTEX_Unlock(server->sysCapMtx); // Mutually exclusive unlock
return FALSE;
}
SysCapImpl *serviceImpl = (SysCapImpl *)VECTOR_At(sysCapablitys, pos);
if (serviceImpl == NULL) {
MUTEX_Unlock(server->sysCapMtx);
return FALSE;
}
BOOL res = (serviceImpl->isRegister == TRUE);
MUTEX_Unlock(server->sysCapMtx);
return res;
}
The function of this function is to get the reply number and the next request Idx, It is used to get and reply to the current registered user , At the same time, get the information of the next registered user
static int32 GetReplyNumAndNextReqIdx(const Vector *sysCapablitys, int32 startIdx, int32 *nextRequestIdx)
{
int32 registerNum = 0;
// Get the number of valid elements in the vector , Exclude those that have been set to NULL The elements of .
int32 size = VECTOR_Num(sysCapablitys); // This function is used to check whether the number of elements reaches the upper limit
//vector Indicates the pointer to the vector
int32 i = startIdx;
for (; i < size && registerNum < MAX_SYSCAP_NUM_PER_REPLY; i++) {
SysCapImpl *serviceImpl = (SysCapImpl *)VECTOR_At(sysCapablitys, i);
if (serviceImpl->isRegister == FALSE) {
continue;
}
registerNum++;
}
*nextRequestIdx = i;
return registerNum;
}
Process gets all system caps
void ProcGetAllSysCap(const SamgrServer *server, IpcIo *req, IpcIo *reply)
{
uint32_t startIdx = IpcIoPopUint32(req);
MUTEX_Lock(server->sysCapMtx);
Vector *sysCapablitys = &(server->sysCapabilitys);
int32 size = VECTOR_Num(sysCapablitys);
if (size == INVALID_INDEX) {
IpcIoPushInt32(reply, EC_FAILURE);
IpcIoPushBool(reply, TRUE);
IpcIoPushUint32(reply, startIdx);
IpcIoPushUint32(reply, 0);
MUTEX_Unlock(server->sysCapMtx);
return;
}
int32 nextRequestIdx = startIdx;
int32 replyNum = GetReplyNumAndNextReqIdx(sysCapablitys, startIdx, &nextRequestIdx);
HILOG_DEBUG(HILOG_MODULE_SAMGR, "ProcGetAllSysCap replyNum: %d, size: %d, startIdx: %d, nextRequestIdx: %d",
replyNum, size, startIdx, nextRequestIdx);
IpcIoPushInt32(reply, EC_SUCCESS);
// indicate is the last reply
// This is the final answer
IpcIoPushBool(reply, nextRequestIdx == size);
// indicate is the next start idx
// The instruction is the next start idx
IpcIoPushUint32(reply, nextRequestIdx);
IpcIoPushUint32(reply, replyNum);
int32 cnt = 0;
int32 i = startIdx;
for (; i < size && cnt < replyNum; i++) {
SysCapImpl *serviceImpl = (SysCapImpl *)VECTOR_At(sysCapablitys, i);
if (serviceImpl->isRegister == FALSE) {
continue;
}
IpcIoPushString(reply, serviceImpl->name);
cnt++;
}
MUTEX_Unlock(server->sysCapMtx); // Mutually exclusive unlock
}
Test the system upper limit function of the process
static int ProcSysCap(SamgrServer *server, int32 option, void *origin, IpcIo *req, IpcIo *reply)
{
// If the following conditions are met , Do not give permission
if (CanRequest(origin) == FALSE) {
HILOG_ERROR(HILOG_MODULE_SAMGR, "ProcSysCap no permission");
IpcIoPushInt32(reply, EC_PERMISSION);
return EC_PERMISSION;
}
if (option != OP_PUT && option != OP_GET && option != OP_ALL) {
IpcIoPushInt32(reply, EC_INVALID);
return EC_INVALID;
}
// Start the system upper limit function of the acquisition process
HILOG_DEBUG(HILOG_MODULE_SAMGR, "ProcSysCap option: %d begin", option);
if (option == OP_PUT) {
int32 ret = ProcAddSysCap(server, req);
IpcIoPushInt32(reply, ret);
} else if (option == OP_GET) {
BOOL ret = ProcGetSysCap(server, req);
IpcIoPushInt32(reply, EC_SUCCESS);
IpcIoPushBool(reply, ret);
} else if (option == OP_ALL) {
ProcGetAllSysCap(server, req, reply);
} else {
HILOG_WARN(HILOG_MODULE_SAMGR, "ProcSysCap error option: %d", option);
IpcIoPushInt32(reply, EC_INVALID);
return EC_INVALID;
}
HILOG_DEBUG(HILOG_MODULE_SAMGR, "ProcSysCap end");
return EC_SUCCESS;
}
边栏推荐
- OpenHarmony相关知识学习
- makefile变量赋值
- vim中如何贪婪匹配
- 通达信开户安全吗? 开户哪个证券好
- Eight guidelines for modbus-rs485 wiring
- HTAP能力加速TPC-H执行前要怎么部署PolarDB for PostgreSQL?
- LINQ implements query string splicing: and and or
- LINQ implements dynamic orderby
- C语言:【位域操作】(结构体中使用冒号)
- In mysql, the decimal (10,2) format is written to Kafka through stream and becomes stri
猜你喜欢

“智慧工厂”上线,破局传统工厂数字化转型

用命令行登录并操作数据库

OpenHarmony模块二初分析(2)

Operation priority of self increasing (self decreasing) operator

MySQL MySQL Foundation

Eight guidelines for modbus-rs485 wiring

Getting started with OpenCV ----- vs how to install opencv Library

Redis introduction and installation

ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the

编程练习
随机推荐
Mmdetection record of win10 installation
COMS技术
The most important diagram of machine learning, how to select the model sklearn structure diagram
编程练习
请问通达信如何开户?请问手机开户股票开户安全吗?
If you don't want to step on those holes in SaaS, you must first understand the "SaaS architecture"
Makefile variable assignment
Creation of single linked list
Dictionary tree (trie tree)
Redis introduction and installation
C语言:代码规范浅谈&摘录(包含【华为代码规范】部分规则摘录)
头文件里面的ifndef /define/endif的作用
YYS鼠标连点器
服务端的那些事儿
The function of ifndef /define/endif in the header file
模块二interfaces下头文件解析(2)
布尔代数值
How to migrate the complex SQL statements used by applications developed for Oracle to polardb for POS
Operation priority of self increasing (self decreasing) operator
客户端那些事儿(2)