1 /*
2 * Copyright (c) 2020-2022 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "hdf_driver_installer.h"
10 #include "devhost_service.h"
11 #include "hdf_log.h"
12 #include "hdf_object_manager.h"
13
14 #define HDF_LOG_TAG driver_installer
15
DriverInstallerStartDeviceHost(uint32_t devHostId,const char * devHostName,bool dynamic)16 static int DriverInstallerStartDeviceHost(uint32_t devHostId, const char *devHostName, bool dynamic)
17 {
18 struct IDevHostService *hostServiceIf = DevHostServiceNewInstance(devHostId, devHostName);
19 int ret;
20 (void)dynamic;
21 if ((hostServiceIf == NULL) || (hostServiceIf->StartService == NULL)) {
22 HDF_LOGE("hostServiceIf or hostServiceIf->StartService is null");
23 return HDF_FAILURE;
24 }
25 ret = hostServiceIf->StartService(hostServiceIf);
26 if (ret != HDF_SUCCESS) {
27 HDF_LOGE("failed to start host service, ret: %d", ret);
28 DevHostServiceFreeInstance(hostServiceIf);
29 }
30 return ret;
31 }
32
DriverInstallerConstruct(struct DriverInstaller * inst)33 static void DriverInstallerConstruct(struct DriverInstaller *inst)
34 {
35 struct IDriverInstaller *driverInstallIf = (struct IDriverInstaller *)inst;
36 driverInstallIf->StartDeviceHost = DriverInstallerStartDeviceHost;
37 }
38
DriverInstallerCreate(void)39 struct HdfObject *DriverInstallerCreate(void)
40 {
41 static bool isDriverInstInit = false;
42 static struct DriverInstaller driverInstaller;
43 if (!isDriverInstInit) {
44 DriverInstallerConstruct(&driverInstaller);
45 isDriverInstInit = true;
46 }
47 return (struct HdfObject *)&driverInstaller;
48 }
49
DriverInstallerGetInstance(void)50 struct IDriverInstaller *DriverInstallerGetInstance(void)
51 {
52 static struct IDriverInstaller *installer = NULL;
53 if (installer == NULL) {
54 installer = (struct IDriverInstaller *)HdfObjectManagerGetObject(HDF_OBJECT_ID_DRIVER_INSTALLER);
55 }
56 return installer;
57 }
58
59