• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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 "devhost_service_clnt.h"
10 #include "device_token_clnt.h"
11 #include "devmgr_service_start.h"
12 #include "hdf_base.h"
13 #include "hdf_driver_installer.h"
14 #include "hdf_log.h"
15 #include "osal_mem.h"
16 
17 #define HDF_LOG_TAG devhost_service_clnt
18 
DevHostServiceClntInstallDriver(struct DevHostServiceClnt * hostClnt)19 int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt)
20 {
21     int ret;
22     struct HdfSListIterator it;
23     struct HdfDeviceInfo *deviceInfo = NULL;
24     struct IDevHostService *devHostSvcIf = NULL;
25     if (hostClnt == NULL) {
26         HDF_LOGE("failed to install driver, hostClnt is null");
27         return HDF_FAILURE;
28     }
29 
30     devHostSvcIf = (struct IDevHostService *)hostClnt->hostService;
31     if (devHostSvcIf == NULL || devHostSvcIf->AddDevice == NULL) {
32         HDF_LOGE("devHostSvcIf or devHostSvcIf->AddDevice is null");
33         return HDF_FAILURE;
34     }
35     HdfSListIteratorInit(&it, &hostClnt->unloadDevInfos);
36     while (HdfSListIteratorHasNext(&it)) {
37         deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&it);
38         if ((deviceInfo == NULL) || (deviceInfo->preload == DEVICE_PRELOAD_DISABLE)) {
39             continue;
40         }
41         /*
42          * If quick start feature enable, the device which 'preload' attribute set as
43          * DEVICE_PRELOAD_ENABLE_STEP2 will be loaded later
44          */
45         if (DeviceManagerIsQuickLoad() == DEV_MGR_QUICK_LOAD &&
46             deviceInfo->preload == DEVICE_PRELOAD_ENABLE_STEP2) {
47             continue;
48         }
49         ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
50         if (ret != HDF_SUCCESS) {
51             HDF_LOGE("failed to install driver %s, ret = %d", deviceInfo->svcName, ret);
52             continue;
53         }
54 #ifndef __USER__
55         HdfSListIteratorRemove(&it);
56 #endif
57     }
58     return HDF_SUCCESS;
59 }
60 
DevHostServiceClntConstruct(struct DevHostServiceClnt * hostClnt)61 static void DevHostServiceClntConstruct(struct DevHostServiceClnt *hostClnt)
62 {
63     HdfSListInit(&hostClnt->devices);
64     hostClnt->deviceHashMap = (Map *)OsalMemCalloc(sizeof(Map));
65     if (hostClnt->deviceHashMap == NULL) {
66         HDF_LOGE("%s:failed to malloc deviceHashMap", __func__);
67         return;
68     }
69     MapInit(hostClnt->deviceHashMap);
70 }
71 
DevHostServiceClntNewInstance(uint16_t hostId,const char * hostName)72 struct DevHostServiceClnt *DevHostServiceClntNewInstance(uint16_t hostId, const char *hostName)
73 {
74     struct DevHostServiceClnt *hostClnt =
75         (struct DevHostServiceClnt *)OsalMemCalloc(sizeof(struct DevHostServiceClnt));
76     if (hostClnt != NULL) {
77         hostClnt->hostId = hostId;
78         hostClnt->hostName = hostName;
79         hostClnt->devCount = 0;
80         hostClnt->hostPid = -1;
81         hostClnt->stopFlag = false;
82         DevHostServiceClntConstruct(hostClnt);
83     }
84     return hostClnt;
85 }
86 
DevHostServiceClntFreeInstance(struct DevHostServiceClnt * hostClnt)87 void DevHostServiceClntFreeInstance(struct DevHostServiceClnt *hostClnt)
88 {
89     if (hostClnt != NULL) {
90         HdfSListFlush(&hostClnt->devices, DeviceTokenClntDelete);
91         HdfSListFlush(&hostClnt->unloadDevInfos, HdfDeviceInfoDelete);
92         HdfSListFlush(&hostClnt->dynamicDevInfos, HdfDeviceInfoDelete);
93         OsalMemFree(hostClnt->deviceHashMap);
94         OsalMemFree(hostClnt);
95     }
96 }
97 
DevHostServiceClntDelete(struct DevHostServiceClnt * hostClnt)98 void DevHostServiceClntDelete(struct DevHostServiceClnt *hostClnt)
99 {
100     if (hostClnt != NULL) {
101         DevHostServiceClntFreeInstance(hostClnt);
102     }
103 }
104 
105