• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_base.h"
10 #include "hdf_device_desc.h"
11 #include "hdf_log.h"
12 #include "module_manager.h"
13 
14 #define HDF_LOG_TAG "hdf_dsoftbus"
15 
16 static struct HdfDeviceObject *g_hdfDevObj = NULL;
17 
HdfSoftbusBroadcastEvent(uint32_t moudleId,const struct HdfSBuf * data)18 int32_t HdfSoftbusBroadcastEvent(uint32_t moudleId, const struct HdfSBuf *data)
19 {
20     if (g_hdfDevObj == NULL) {
21         return HDF_FAILURE;
22     }
23     return HdfDeviceSendEvent(g_hdfDevObj, moudleId, data);
24 }
25 
DispatchCommand(struct HdfDeviceIoClient * client,int moduleId,struct HdfSBuf * reqData,struct HdfSBuf * rspData)26 static int32_t DispatchCommand(struct HdfDeviceIoClient *client, int moduleId,
27     struct HdfSBuf *reqData, struct HdfSBuf *rspData)
28 {
29     (void)client;
30     SoftbusDispatchModuleCommand(moduleId, reqData, rspData);
31     return HDF_SUCCESS;
32 }
33 
HdfSoftbusDriverBind(struct HdfDeviceObject * dev)34 static int32_t HdfSoftbusDriverBind(struct HdfDeviceObject *dev)
35 {
36     static struct IDeviceIoService softbusService = {
37         .object.objectId = 1,
38         .Dispatch = DispatchCommand,
39     };
40 
41     if (dev == NULL) {
42         HDF_LOGE("hdf device object is null");
43         return HDF_FAILURE;
44     }
45     dev->service = &softbusService;
46     HDF_LOGE("softbus driver bind success");
47     return HDF_SUCCESS;
48 }
49 
HdfSoftbusDriverInit(struct HdfDeviceObject * device)50 static int32_t HdfSoftbusDriverInit(struct HdfDeviceObject *device)
51 {
52     if (device == NULL) {
53         HDF_LOGE("device object is null");
54         return HDF_ERR_INVALID_PARAM;
55     }
56     g_hdfDevObj = device;
57     return SoftbusModuleManagerInit(device);
58 }
59 
HdfSoftbusDriverRelease(struct HdfDeviceObject * object)60 static void HdfSoftbusDriverRelease(struct HdfDeviceObject *object)
61 {
62     (void)object;
63     HDF_LOGE("softbus driver release success");
64 }
65 
66 static struct HdfDriverEntry g_hdfSoftbusEntry = {
67     .moduleVersion = 1,
68     .Bind = HdfSoftbusDriverBind,
69     .Init = HdfSoftbusDriverInit,
70     .Release = HdfSoftbusDriverRelease,
71     .moduleName = "HDF_DSOFTBUS"
72 };
73 
74 HDF_INIT(g_hdfSoftbusEntry);