• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "plugin_service_impl.h"
17 #include "plugin_service.h"
18 
PluginServiceImpl(PluginService & p)19 PluginServiceImpl::PluginServiceImpl(PluginService& p)
20 {
21     pluginService = &p;
22 }
23 
~PluginServiceImpl()24 PluginServiceImpl::~PluginServiceImpl() {}
25 
RegisterPlugin(SocketContext & context,::RegisterPluginRequest & request,::RegisterPluginResponse & response)26 bool PluginServiceImpl::RegisterPlugin(SocketContext& context,
27                                        ::RegisterPluginRequest& request,
28                                        ::RegisterPluginResponse& response)
29 {
30     PluginInfo pluginInfo;
31 
32     pluginInfo.name = request.name();
33     pluginInfo.path = request.path();
34     pluginInfo.sha256 = request.sha256();
35     pluginInfo.bufferSizeHint = request.buffer_size_hint();
36     pluginInfo.context = &context;
37 
38     if (pluginService->AddPluginInfo(pluginInfo)) {
39         response.set_status(ResponseStatus::OK);
40         response.set_plugin_id(pluginService->GetPluginIdByName(pluginInfo.name));
41         HILOG_DEBUG(LOG_CORE, "RegisterPlugin OK");
42         return true;
43     }
44     response.set_status(ResponseStatus::ERR);
45     HILOG_DEBUG(LOG_CORE, "RegisterPlugin FAIL");
46     return false;
47 }
UnregisterPlugin(SocketContext & context,::UnregisterPluginRequest & request,::UnregisterPluginResponse & response)48 bool PluginServiceImpl::UnregisterPlugin(SocketContext& context,
49                                          ::UnregisterPluginRequest& request,
50                                          ::UnregisterPluginResponse& response)
51 {
52     PluginInfo pluginInfo;
53     pluginInfo.id = request.plugin_id();
54 
55     if (pluginService->RemovePluginInfo(pluginInfo)) {
56         response.set_status(ResponseStatus::OK);
57         HILOG_DEBUG(LOG_CORE, "UnregisterPlugin OK");
58         return true;
59     }
60     response.set_status(ResponseStatus::ERR);
61     HILOG_DEBUG(LOG_CORE, "UnregisterPlugin FAIL");
62     return false;
63 }
64 
GetCommand(SocketContext & context,::GetCommandRequest & request,::GetCommandResponse & response)65 bool PluginServiceImpl::GetCommand(SocketContext& context, ::GetCommandRequest& request, ::GetCommandResponse& response)
66 {
67     return false;
68 }
69 
NotifyResult(SocketContext & context,::NotifyResultRequest & request,::NotifyResultResponse & response)70 bool PluginServiceImpl::NotifyResult(SocketContext& context,
71                                      ::NotifyResultRequest& request,
72                                      ::NotifyResultResponse& response)
73 {
74     HILOG_DEBUG(LOG_CORE, "NotifyResult");
75     if (pluginService->AppendResult(request)) {
76         response.set_status(ResponseStatus::OK);
77         return true;
78     }
79     response.set_status(ResponseStatus::ERR);
80     return true;
81 }
82 
PushCommand(SocketContext & context,GetCommandResponsePtr command)83 bool PluginServiceImpl::PushCommand(SocketContext& context, GetCommandResponsePtr command)
84 {
85     SendResponseGetCommandResponse(context, *command.get());
86     return true;
87 }
88