• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef SOFTBUS_RC_OBJECT_H
16 #define SOFTBUS_RC_OBJECT_H
17 
18 #include <stdint.h>
19 
20 #include "common_list.h"
21 #include "softbus_adapter_thread.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 struct SoftBusRcObject;
28 typedef struct SoftBusRcObject SoftBusRcObject;
29 typedef void (*SoftBusRcFreeHook)(SoftBusRcObject *object);
30 
31 // name method pointer fields as upper camel case on purpose,
32 // as it will notice user that it is method, avoiding confusion and more readable
33 #define SOFT_BUS_RC_OBJECT_BASE                      \
34     /* public */                                     \
35     int32_t (*Lock)(SoftBusRcObject * self);         \
36     void (*Unlock)(SoftBusRcObject * self);          \
37     void (*Dereference)(SoftBusRcObject * *self);    \
38     int32_t (*Reference)(SoftBusRcObject * selfPtr); \
39                                                      \
40     /* private */                                    \
41     ListNode node;                                   \
42     uint32_t id;                                     \
43     SoftBusMutex mutex;                              \
44     int32_t objectRc;                                \
45     SoftBusRcFreeHook freehook;                      \
46                                                      \
47     /* concrete object identifier */                 \
48     const char *name
49 
50 struct SoftBusRcObject {
51     SOFT_BUS_RC_OBJECT_BASE;
52 };
53 
54 int32_t SoftBusRcObjectConstruct(const char *name, SoftBusRcObject *object, SoftBusRcFreeHook hook);
55 void SoftBusRcObjectDestruct(SoftBusRcObject *object);
56 
57 #ifdef __cplusplus
58 }
59 #endif
60 
61 #endif