2 Star 0 Fork 101

深圳市南方硅谷半导体股份有限公司/hiviewdfx_hiview_lite

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
hiview_service.c 3.97 KB
一键复制 编辑 原始数据 按行查看 历史
stesen 提交于 2021-07-01 09:14 . fix init
/*
* Copyright (c) 2020 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ohos_init.h"
#include "samgr_lite.h"
#include "service.h"
#include "common.h"
#include "hiview_def.h"
#include "hiview_config.h"
#include "hiview_service.h"
#include "hiview_util.h"
static const char *GetName(Service *service);
static BOOL Initialize(Service *service, Identity identity);
static TaskConfig GetTaskConfig(Service *service);
static BOOL MessageHandle(Service *service, Request *request);
static void Output(IUnknown *iUnknown, int16 msgId, uint16 type);
static HiviewService g_hiviewService = {
.GetName = GetName,
.Initialize = Initialize,
.MessageHandle = MessageHandle,
.GetTaskConfig = GetTaskConfig,
DEFAULT_IUNKNOWN_ENTRY_BEGIN,
.Output = Output,
DEFAULT_IUNKNOWN_ENTRY_END,
};
static HiviewInitFunc g_hiviewInitFuncList[HIVIEW_CMP_TYPE_MAX] = { NULL };
static HiviewMsgHandle g_hiviewMsgHandleList[HIVIEW_MSG_MAX] = { NULL };
static void InitHiviewComponent(void);
static void Init(void)
{
SAMGR_GetInstance()->RegisterService((Service *)&g_hiviewService);
SAMGR_GetInstance()->RegisterDefaultFeatureApi(HIVIEW_SERVICE, GET_IUNKNOWN(g_hiviewService));
InitHiviewComponent();
}
SYS_SERVICE_INIT(Init);
static const char *GetName(Service *service)
{
(void)service;
return HIVIEW_SERVICE;
}
static BOOL Initialize(Service *service, Identity identity)
{
HiviewService *hiviewService = NULL;
if (service == NULL) {
return FALSE;
}
hiviewService = (HiviewService *)service;
hiviewService->identity = identity;
/* The communication of task can be use after the service is running. */
g_hiviewConfig.hiviewInited = TRUE;
HIVIEW_UartPrint("hiview init success.");
return TRUE;
}
static BOOL MessageHandle(Service *service, Request *request)
{
(void)service;
if ((request == NULL) || (request->msgId >= HIVIEW_MSG_MAX)) {
return TRUE;
}
if (g_hiviewMsgHandleList[request->msgId] != NULL) {
(*(g_hiviewMsgHandleList[request->msgId]))(request);
}
return TRUE;
}
static TaskConfig GetTaskConfig(Service *service)
{
(void)service;
TaskConfig config = { LEVEL_LOW, PRI_NORMAL, 0x800, 10, SINGLE_TASK };
return config;
}
static void Output(IUnknown *iUnknown, int16 msgId, uint16 type)
{
HiviewService *service = GET_OBJECT(iUnknown, HiviewService, iUnknown);
Request request = {
.msgId = msgId,
.msgValue = type,
.data = NULL,
.len = 0
};
SAMGR_SendRequest(&(service->identity), &request, NULL);
}
static void InitHiviewComponent(void)
{
uint8 i;
for (i = 0; i < HIVIEW_CMP_TYPE_MAX; i++) {
if (g_hiviewInitFuncList[i] != NULL) {
(*(g_hiviewInitFuncList[i]))();
}
}
}
void HiviewRegisterInitFunc(HiviewComponentType type, HiviewInitFunc func)
{
g_hiviewInitFuncList[type] = func;
}
void HiviewRegisterMsgHandle(HiviewInnerMessage type, HiviewMsgHandle func)
{
g_hiviewMsgHandleList[type] = func;
}
void HiviewSendMessage(const char *srvName, int16 msgId, uint16 msgValue)
{
static HiviewInterface *hiviewInfterface = NULL;
if (hiviewInfterface == NULL) {
IUnknown *hiviewDefApi = SAMGR_GetInstance()->GetDefaultFeatureApi(srvName);
if (hiviewDefApi == NULL) {
return;
}
hiviewDefApi->QueryInterface(hiviewDefApi, 0, (void **)&hiviewInfterface);
}
hiviewInfterface->Output((IUnknown *)hiviewInfterface, msgId, msgValue);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/icomm-semi/hiviewdfx_hiview_lite.git
git@gitee.com:icomm-semi/hiviewdfx_hiview_lite.git
icomm-semi
hiviewdfx_hiview_lite
hiviewdfx_hiview_lite
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385