• 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 "hdf_device_info.h"
10 #include "hdf_log.h"
11 #include "osal_mem.h"
12 
13 #define HDF_LOG_TAG device_info
14 
HdfDeviceInfoConstruct(struct HdfDeviceInfo * deviceInfo)15 void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo)
16 {
17     if (deviceInfo == NULL) {
18         return;
19     }
20     deviceInfo->isDynamic = false;
21     deviceInfo->hostId = 0;
22     deviceInfo->status = HDF_SERVICE_UNUSABLE;
23     deviceInfo->deviceType = HDF_DEV_LOCAL_SERVICE;
24     deviceInfo->deviceId = 0;
25     deviceInfo->policy = SERVICE_POLICY_INVALID;
26     deviceInfo->priority = 0;
27     deviceInfo->preload = DEVICE_PRELOAD_ENABLE;
28     deviceInfo->permission = 0;
29     deviceInfo->svcName = NULL;
30     deviceInfo->moduleName = NULL;
31     deviceInfo->deviceMatchAttr = NULL;
32     deviceInfo->private = NULL;
33 }
34 
HdfDeviceInfoNewInstance()35 struct HdfDeviceInfo *HdfDeviceInfoNewInstance()
36 {
37     struct HdfDeviceInfo *deviceInfo =
38             (struct HdfDeviceInfo*)OsalMemCalloc(sizeof(struct HdfDeviceInfo));
39     if (deviceInfo != NULL) {
40         HdfDeviceInfoConstruct(deviceInfo);
41         return deviceInfo;
42     }
43     HDF_LOGE("Create device deviceInfo failed");
44     return NULL;
45 }
46 
HdfDeviceInfoFreeInstance(struct HdfDeviceInfo * deviceInfo)47 void HdfDeviceInfoFreeInstance(struct HdfDeviceInfo *deviceInfo)
48 {
49     if (deviceInfo != NULL) {
50         if (deviceInfo->isDynamic && deviceInfo->svcName != NULL) {
51             OsalMemFree((void *)deviceInfo->svcName);
52         }
53         if (deviceInfo->private != NULL) {
54             OsalMemFree((void *)deviceInfo->private);
55         }
56         OsalMemFree(deviceInfo);
57     }
58 }
59 
HdfDeviceInfoDelete(struct HdfSListNode * listEntry)60 void HdfDeviceInfoDelete(struct HdfSListNode *listEntry)
61 {
62     struct HdfDeviceInfo *deviceInfo = (struct HdfDeviceInfo *)listEntry;
63     HdfDeviceInfoFreeInstance(deviceInfo);
64 }
65 
66