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_device_info.h"
10 #include "hdf_device_desc.h"
11 #include "hdf_log.h"
12 #include "osal_mem.h"
13 
14 #define HDF_LOG_TAG device_info
15 
HdfDeviceInfoConstruct(struct HdfDeviceInfo * deviceInfo)16 void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo)
17 {
18     if (deviceInfo == NULL) {
19         return;
20     }
21     deviceInfo->isDynamic = false;
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->deviceName = NULL;
33 }
34 
HdfDeviceInfoNewInstance(void)35 struct HdfDeviceInfo *HdfDeviceInfoNewInstance(void)
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("failed to create deviceInfo, oom");
44     return NULL;
45 }
46 
HdfDeviceInfoFreeInstance(struct HdfDeviceInfo * deviceInfo)47 void HdfDeviceInfoFreeInstance(struct HdfDeviceInfo *deviceInfo)
48 {
49     if (deviceInfo != NULL) {
50         OsalMemFree(deviceInfo);
51     }
52 }
53 
HdfDeviceInfoDelete(struct HdfSListNode * listEntry)54 void HdfDeviceInfoDelete(struct HdfSListNode *listEntry)
55 {
56     struct HdfDeviceInfo *deviceInfo = (struct HdfDeviceInfo *)listEntry;
57     HdfDeviceInfoFreeInstance(deviceInfo);
58 }
59 
60