1 /*
2 * Copyright (c) 2020-2023 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 "device_resource_if.h"
10 #include "hcs_tree_if.h"
11 #include "hdf_log.h"
12
HcsIfaceConstruct(struct DeviceResourceIface * instance)13 static void HcsIfaceConstruct(struct DeviceResourceIface *instance)
14 {
15 instance->GetRootNode = HcsGetRootNode;
16 instance->GetBool = HcsGetBool;
17 instance->GetUint8 = HcsGetUint8;
18 instance->GetUint8ArrayElem = HcsGetUint8ArrayElem;
19 instance->GetUint8Array = HcsGetUint8Array;
20 instance->GetUint16 = HcsGetUint16;
21 instance->GetUint16ArrayElem = HcsGetUint16ArrayElem;
22 instance->GetUint16Array = HcsGetUint16Array;
23 instance->GetUint32 = HcsGetUint32;
24 instance->GetUint32ArrayElem = HcsGetUint32ArrayElem;
25 instance->GetUint32Array = HcsGetUint32Array;
26 instance->GetUint64 = HcsGetUint64;
27 instance->GetUint64ArrayElem = HcsGetUint64ArrayElem;
28 instance->GetUint64Array = HcsGetUint64Array;
29 instance->GetString = HcsGetString;
30 instance->GetStringArrayElem = HcsGetStringArrayElem;
31 instance->GetElemNum = HcsGetElemNum;
32 instance->GetNodeByMatchAttr = HcsGetNodeByMatchAttr;
33 instance->GetChildNode = HcsGetChildNode;
34 instance->GetNodeByRefAttr = HcsGetNodeByRefAttr;
35 }
36
DeviceResourceIfaceConstruct(struct DeviceResourceIface * instance,DeviceResourceType type)37 static bool DeviceResourceIfaceConstruct(struct DeviceResourceIface *instance, DeviceResourceType type)
38 {
39 if (type == HDF_CONFIG_SOURCE) {
40 HcsIfaceConstruct(instance);
41 } else {
42 HDF_LOGE("%s: Currently, this configuration type is not supported, the type is %d", __func__, type);
43 return false;
44 }
45 return true;
46 }
47
DeviceResourceGetIfaceInstance(DeviceResourceType type)48 struct DeviceResourceIface *DeviceResourceGetIfaceInstance(DeviceResourceType type)
49 {
50 static struct DeviceResourceIface *instance = NULL;
51 if (instance == NULL) {
52 static struct DeviceResourceIface singletonInstance;
53 if (!DeviceResourceIfaceConstruct(&singletonInstance, type)) {
54 return NULL;
55 }
56 instance = &singletonInstance;
57 }
58 return instance;
59 }
60