106f6ba60Sopenharmony_ci/* 206f6ba60Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License. 506f6ba60Sopenharmony_ci * You may obtain a copy of the License at 606f6ba60Sopenharmony_ci * 706f6ba60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 806f6ba60Sopenharmony_ci * 906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and 1306f6ba60Sopenharmony_ci * limitations under the License. 1406f6ba60Sopenharmony_ci */ 1506f6ba60Sopenharmony_ci 1606f6ba60Sopenharmony_ci#include "plugin_service_impl.h" 1706f6ba60Sopenharmony_ci#include "plugin_service.h" 1806f6ba60Sopenharmony_ci 1906f6ba60Sopenharmony_ciPluginServiceImpl::PluginServiceImpl(PluginService& p) 2006f6ba60Sopenharmony_ci{ 2106f6ba60Sopenharmony_ci pluginService = &p; 2206f6ba60Sopenharmony_ci} 2306f6ba60Sopenharmony_ci 2406f6ba60Sopenharmony_ciPluginServiceImpl::~PluginServiceImpl() {} 2506f6ba60Sopenharmony_ci 2606f6ba60Sopenharmony_cibool PluginServiceImpl::RegisterPlugin(SocketContext& context, 2706f6ba60Sopenharmony_ci ::RegisterPluginRequest& request, 2806f6ba60Sopenharmony_ci ::RegisterPluginResponse& response) 2906f6ba60Sopenharmony_ci{ 3006f6ba60Sopenharmony_ci PluginInfo pluginInfo; 3106f6ba60Sopenharmony_ci 3206f6ba60Sopenharmony_ci pluginInfo.name = request.name(); 3306f6ba60Sopenharmony_ci pluginInfo.path = request.path(); 3406f6ba60Sopenharmony_ci pluginInfo.sha256 = request.sha256(); 3506f6ba60Sopenharmony_ci pluginInfo.bufferSizeHint = request.buffer_size_hint(); 3606f6ba60Sopenharmony_ci pluginInfo.isStandaloneFileData = request.is_standalone_data(); 3706f6ba60Sopenharmony_ci pluginInfo.outFileName = request.out_file_name(); 3806f6ba60Sopenharmony_ci pluginInfo.pluginVersion = request.plugin_version(); 3906f6ba60Sopenharmony_ci pluginInfo.context = &context; 4006f6ba60Sopenharmony_ci 4106f6ba60Sopenharmony_ci int pluginId = pluginService->GetPluginIdByName(pluginInfo.name); 4206f6ba60Sopenharmony_ci if (pluginService->AddPluginInfo(pluginInfo)) { 4306f6ba60Sopenharmony_ci if (pluginId != 0) { // update plugin not need reply response 4406f6ba60Sopenharmony_ci PROFILER_LOG_DEBUG(LOG_CORE, "UpdatePlugin OK"); 4506f6ba60Sopenharmony_ci return false; 4606f6ba60Sopenharmony_ci } 4706f6ba60Sopenharmony_ci response.set_status(ResponseStatus::OK); 4806f6ba60Sopenharmony_ci response.set_plugin_id(pluginService->GetPluginIdByName(pluginInfo.name)); 4906f6ba60Sopenharmony_ci PROFILER_LOG_DEBUG(LOG_CORE, "RegisterPlugin OK"); 5006f6ba60Sopenharmony_ci return true; 5106f6ba60Sopenharmony_ci } 5206f6ba60Sopenharmony_ci response.set_status(ResponseStatus::ERR); 5306f6ba60Sopenharmony_ci PROFILER_LOG_DEBUG(LOG_CORE, "RegisterPlugin FAIL"); 5406f6ba60Sopenharmony_ci return false; 5506f6ba60Sopenharmony_ci} 5606f6ba60Sopenharmony_cibool PluginServiceImpl::UnregisterPlugin(SocketContext& context, 5706f6ba60Sopenharmony_ci ::UnregisterPluginRequest& request, 5806f6ba60Sopenharmony_ci ::UnregisterPluginResponse& response) 5906f6ba60Sopenharmony_ci{ 6006f6ba60Sopenharmony_ci PluginInfo pluginInfo; 6106f6ba60Sopenharmony_ci pluginInfo.id = request.plugin_id(); 6206f6ba60Sopenharmony_ci 6306f6ba60Sopenharmony_ci if (pluginService->RemovePluginInfo(pluginInfo)) { 6406f6ba60Sopenharmony_ci response.set_status(ResponseStatus::OK); 6506f6ba60Sopenharmony_ci PROFILER_LOG_DEBUG(LOG_CORE, "UnregisterPlugin OK"); 6606f6ba60Sopenharmony_ci return true; 6706f6ba60Sopenharmony_ci } 6806f6ba60Sopenharmony_ci response.set_status(ResponseStatus::ERR); 6906f6ba60Sopenharmony_ci PROFILER_LOG_DEBUG(LOG_CORE, "UnregisterPlugin FAIL"); 7006f6ba60Sopenharmony_ci return false; 7106f6ba60Sopenharmony_ci} 7206f6ba60Sopenharmony_ci 7306f6ba60Sopenharmony_cibool PluginServiceImpl::GetCommand(SocketContext& context, ::GetCommandRequest& request, ::GetCommandResponse& response) 7406f6ba60Sopenharmony_ci{ 7506f6ba60Sopenharmony_ci return false; 7606f6ba60Sopenharmony_ci} 7706f6ba60Sopenharmony_ci 7806f6ba60Sopenharmony_cibool PluginServiceImpl::NotifyResult(SocketContext& context, 7906f6ba60Sopenharmony_ci ::NotifyResultRequest& request, 8006f6ba60Sopenharmony_ci ::NotifyResultResponse& response) 8106f6ba60Sopenharmony_ci{ 8206f6ba60Sopenharmony_ci PROFILER_LOG_DEBUG(LOG_CORE, "NotifyResult"); 8306f6ba60Sopenharmony_ci if (pluginService->AppendResult(request)) { 8406f6ba60Sopenharmony_ci response.set_status(ResponseStatus::OK); 8506f6ba60Sopenharmony_ci return true; 8606f6ba60Sopenharmony_ci } 8706f6ba60Sopenharmony_ci response.set_status(ResponseStatus::ERR); 8806f6ba60Sopenharmony_ci return true; 8906f6ba60Sopenharmony_ci} 9006f6ba60Sopenharmony_ci 9106f6ba60Sopenharmony_cibool PluginServiceImpl::PushCommand(SocketContext& context, GetCommandResponsePtr command) 9206f6ba60Sopenharmony_ci{ 9306f6ba60Sopenharmony_ci SendResponseGetCommandResponse(context, *command.get()); 9406f6ba60Sopenharmony_ci return true; 9506f6ba60Sopenharmony_ci} 9606f6ba60Sopenharmony_ci 9706f6ba60Sopenharmony_cibool PluginServiceImpl::SendHeartBeat(SocketContext& context) 9806f6ba60Sopenharmony_ci{ 9906f6ba60Sopenharmony_ci return context.SendHeartBeat(); 10006f6ba60Sopenharmony_ci} 101