Skip to content

Commit 79e7dce

Browse files
committed
Add naming conventions to c-patterns.
1 parent 791a47e commit 79e7dce

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

documents/c_patterns.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ The naming scheme used for the object struct is `<celix_object_name>`, typically
3838
`<celix_object_name>_t`. For the object functions, the following naming scheme is
3939
used: `<celix_objectName>_<functionName>`. Note the camelCase for the object name and function name.
4040

41-
An Apache Celix C object should always have a create and a destroy function. The create function is used to create
42-
a new object, and the destroy function is used to destroy the object. The destroy function should also free the
43-
object's memory.
41+
An Apache Celix C object should always have a constructor and a destructor. If memory allocation is involved,
42+
a `celix_<objectName>_create` function is used to create and return a new object, and a `celix_<objectName>_destroy`
43+
function is used to destroy the object and free the object's memory. Otherwise, use a `celix_<objectName>_init` function
44+
with `celix_status_t` return value to initialize the object's provided memory and use a `celix_<objectName>_deinit`
45+
function to deinitialize the object. The `celix_<objectName>_deinit` function should not free the object's memory.
4446

4547
An Apache Celix C object can also have additional functions to access object information or to manipulate the object.
4648
If an object contains properties, it should provide a getter and setter function for each property.
@@ -53,8 +55,8 @@ different element types. Refer to the header files for more information.
5355

5456
## Apache Celix C Scope-Based Resource Management
5557

56-
Apache Celix offers several macros to support scope-based resource management (SBRM). These macros are
57-
inspired by [Scoped-based Resource Management for the Kernel](https://lwn.net/Articles/934838/).
58+
Apache Celix offers several macros to add support for scope-based resource management (SBRM) to existing types.
59+
These macros are inspired by [Scoped-based Resource Management for the Kernel](https://lwn.net/Articles/934838/).
5860

5961
The main macros used for SBRM are:
6062
- `celix_autofree`: Automatically frees memory with `free` when the variable goes out of scope.
@@ -65,13 +67,14 @@ The main macros used for SBRM are:
6567

6668
These macros can be found in the Apache Celix utils headers `celix_cleanup.h` and `celix_stdlib_cleanup.h`.
6769

68-
In Apache Celix, C objects must opt into SBRM. This is done by using a "define" macro, which determines the
70+
In Apache Celix, C objects must opt into SBRM. This is done by using a `CELIX_DEFINE_AUTO` macro, which determines the
6971
expected C functions to clean up the object.
7072

7173
## Support for Resource Allocation Is Initialization (RAII)-like Structures
7274

73-
Based on the previously mentioned SBRM, Apache Celix also offers support for structures that resemble RAII. These can be
74-
used to guard locks, manage service registration, etc. Support for RAII-like structures is facilitated by providing
75+
Based on the previously mentioned SBRM, Apache Celix also offers support for structures that resemble RAII.
76+
These can be used to guard locks, manage service registration, etc. These guards should follow the naming convention
77+
`celix_<obj_to_guard>_guard_t`. Support for RAII-like structures is facilitated by providing
7578
additional cleanup functions that work with either the `celix_auto` or `celix_autoptr` macros.
7679

7780
Examples include:

libs/framework/include/celix_bundle_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ typedef struct celix_service_registration_guard {
283283
} celix_service_registration_guard_t;
284284

285285
/**
286-
* @brief Initialize a a scode guard for an existing service registration.
286+
* @brief Initialize a a scope guard for an existing service registration.
287287
* @param [in] ctx The bundle context associated with the service registration.
288288
* @param [in] serviceId The service id.
289289
* @return An initialized service registration guard.

0 commit comments

Comments
 (0)