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 "driver_installer_full.h"
17 #include "hdf_base.h"
18 #include "hdf_driver_installer.h"
19 #include "hdf_log.h"
20 #include "osal_mem.h"
21 #include "service_control.h"
22
23 #define HDF_LOG_TAG driver_installer_full
24 #define MAX_CMD_LEN 256
25 #define PARAM_CNT 2
26
27 static struct DriverInstaller *g_fullInstaller = NULL;
DriverInstallerFullStartDeviceHost(uint32_t devHostId,const char * devHostName,bool dynamic)28 int DriverInstallerFullStartDeviceHost(uint32_t devHostId, const char* devHostName, bool dynamic)
29 {
30 if (dynamic) {
31 int ret = ServiceControlWithExtra(devHostName, START, NULL, 0);
32 HDF_LOGD("%{public}s %{public}s %{public}d %{public}d", __func__, devHostName, devHostId, ret);
33 }
34
35 return HDF_SUCCESS;
36 }
37
DriverInstallerFullStopDeviceHost(uint32_t devHostId,const char * devHostName)38 int DriverInstallerFullStopDeviceHost(uint32_t devHostId, const char* devHostName)
39 {
40 int ret;
41 ret = ServiceControlWithExtra(devHostName, STOP, NULL, 0);
42 HDF_LOGI("%{public}s %{public}s %{public}d %{public}d", __func__, devHostName, devHostId, ret);
43 return ret;
44 }
DriverInstallerFullConstruct(struct DriverInstaller * inst)45 static void DriverInstallerFullConstruct(struct DriverInstaller *inst)
46 {
47 struct IDriverInstaller *pvtbl = (struct IDriverInstaller *)inst;
48 pvtbl->StartDeviceHost = DriverInstallerFullStartDeviceHost;
49 pvtbl->StopDeviceHost = DriverInstallerFullStopDeviceHost;
50 }
51
DriverInstallerFullCreate(void)52 struct HdfObject *DriverInstallerFullCreate(void)
53 {
54 if (g_fullInstaller == NULL) {
55 g_fullInstaller = (struct DriverInstaller *)OsalMemCalloc(sizeof(struct DriverInstaller));
56 if (g_fullInstaller != NULL) {
57 DriverInstallerFullConstruct(g_fullInstaller);
58 }
59 }
60
61 return (struct HdfObject *)g_fullInstaller;
62 }
63
DriverInstallerFullRelease(struct HdfObject * object)64 void DriverInstallerFullRelease(struct HdfObject *object)
65 {
66 struct DriverInstaller *installer = (struct DriverInstaller *)object;
67 if (g_fullInstaller == installer) {
68 g_fullInstaller = NULL;
69 }
70 if (installer != NULL) {
71 OsalMemFree(installer);
72 }
73 }
74