• 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_service_subscriber.h"
10 #include "hdf_device.h"
11 #include "osal_mem.h"
12 
HdfServiceSubscriberObtain(struct SubscriberCallback callback,devid_t devid)13 struct HdfServiceSubscriber *HdfServiceSubscriberObtain(struct SubscriberCallback callback, devid_t devid)
14 {
15     struct HdfServiceSubscriber *serviceSubscriber =
16         (struct HdfServiceSubscriber *)OsalMemCalloc(sizeof(struct HdfServiceSubscriber));
17     if (serviceSubscriber != NULL) {
18         serviceSubscriber->state = HDF_SUBSCRIBER_STATE_PENDING;
19         serviceSubscriber->devId = devid;
20         serviceSubscriber->callback = callback;
21     }
22     return serviceSubscriber;
23 }
24 
HdfServiceSubscriberRecycle(struct HdfServiceSubscriber * subscriber)25 void HdfServiceSubscriberRecycle(struct HdfServiceSubscriber *subscriber)
26 {
27     if (subscriber != NULL) {
28         OsalMemFree(subscriber);
29     }
30 }
31 
HdfServiceSubscriberDelete(struct HdfSListNode * listEntry)32 void HdfServiceSubscriberDelete(struct HdfSListNode *listEntry)
33 {
34     struct HdfServiceSubscriber *serviceSubscriber = (struct HdfServiceSubscriber *)listEntry;
35     if (serviceSubscriber != NULL) {
36         HdfServiceSubscriberRecycle(serviceSubscriber);
37     }
38 }
39