Skip to content

Commit bdc97f6

Browse files
Kimeek42gangatp
andauthored
Add C++ binding/implementation thread safety options (#220)
* Add c++ binding/implementation thread safety options * Add c++ binding/implementation thread safety options * Dont generate lock/unlock instance in cbase class * Add thread safety option example * Add exeample readme for threadsafetyoption parameter: * Return string not throw exception * Fix formatting * Add class hierarchy restriction for threadsafetyoption parameter * Fix typo * Fix gitignore * Add libthreadsafe to example.cpp --------- Co-authored-by: gangatp <[email protected]>
1 parent 7ecda46 commit bdc97f6

29 files changed

+3963
-28
lines changed

Examples/ThreadSafety/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LibThreadSafe_component
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
/*++
2+
3+
Copyright (C) 2025 Thread-safe library developers
4+
5+
All rights reserved.
6+
7+
This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop.
8+
9+
Abstract: This is an autogenerated C++-Header file in order to allow an easy
10+
use of Thread-safe library
11+
12+
Interface version: 1.0.0
13+
14+
*/
15+
16+
#ifndef __LIBTHREADSAFE_DYNAMICHEADER_CPPTYPES
17+
#define __LIBTHREADSAFE_DYNAMICHEADER_CPPTYPES
18+
19+
#include "libthreadsafe_types.hpp"
20+
21+
22+
23+
/*************************************************************************************************************************
24+
Class definition for Base
25+
**************************************************************************************************************************/
26+
27+
/**
28+
* Get Class Type Id
29+
*
30+
* @param[in] pBase - Base instance.
31+
* @param[out] pClassTypeId - Class type as a 64 bits integer
32+
* @return error code or 0 (success)
33+
*/
34+
typedef LibThreadSafeResult (*PLibThreadSafeBase_ClassTypeIdPtr) (LibThreadSafe_Base pBase, LibThreadSafe_uint64 * pClassTypeId);
35+
36+
/**
37+
* If thread safety for class in library is enabled it should lock object for calling thread
38+
*
39+
* @param[in] pBase - Base instance.
40+
* @return error code or 0 (success)
41+
*/
42+
typedef LibThreadSafeResult (*PLibThreadSafeBase__lockInstancePtr) (LibThreadSafe_Base pBase);
43+
44+
/**
45+
* If thread safety for class in library is enabled it should unlock object for other threads
46+
*
47+
* @param[in] pBase - Base instance.
48+
* @return error code or 0 (success)
49+
*/
50+
typedef LibThreadSafeResult (*PLibThreadSafeBase__unlockInstancePtr) (LibThreadSafe_Base pBase);
51+
52+
/*************************************************************************************************************************
53+
Class definition for StringReturner
54+
**************************************************************************************************************************/
55+
56+
/**
57+
* Returns a string
58+
*
59+
* @param[in] pStringReturner - StringReturner instance.
60+
* @param[in] nValueBufferSize - size of the buffer (including trailing 0)
61+
* @param[out] pValueNeededChars - will be filled with the count of the written bytes, or needed buffer size.
62+
* @param[out] pValueBuffer - buffer of , may be NULL
63+
* @return error code or 0 (success)
64+
*/
65+
typedef LibThreadSafeResult (*PLibThreadSafeStringReturner_GetStringPtr) (LibThreadSafe_StringReturner pStringReturner, const LibThreadSafe_uint32 nValueBufferSize, LibThreadSafe_uint32* pValueNeededChars, char * pValueBuffer);
66+
67+
/**
68+
* Function that may crash when called from different threads at the same time
69+
*
70+
* @param[in] pStringReturner - StringReturner instance.
71+
* @return error code or 0 (success)
72+
*/
73+
typedef LibThreadSafeResult (*PLibThreadSafeStringReturner_ThreadSafetyCheckPtr) (LibThreadSafe_StringReturner pStringReturner);
74+
75+
/*************************************************************************************************************************
76+
Class definition for SoftStringReturner
77+
**************************************************************************************************************************/
78+
79+
/**
80+
* Returns a string
81+
*
82+
* @param[in] pSoftStringReturner - SoftStringReturner instance.
83+
* @param[in] nValueBufferSize - size of the buffer (including trailing 0)
84+
* @param[out] pValueNeededChars - will be filled with the count of the written bytes, or needed buffer size.
85+
* @param[out] pValueBuffer - buffer of , may be NULL
86+
* @return error code or 0 (success)
87+
*/
88+
typedef LibThreadSafeResult (*PLibThreadSafeSoftStringReturner_GetStringPtr) (LibThreadSafe_SoftStringReturner pSoftStringReturner, const LibThreadSafe_uint32 nValueBufferSize, LibThreadSafe_uint32* pValueNeededChars, char * pValueBuffer);
89+
90+
/**
91+
* Function that may crash when called from different threads at the same time
92+
*
93+
* @param[in] pSoftStringReturner - SoftStringReturner instance.
94+
* @return error code or 0 (success)
95+
*/
96+
typedef LibThreadSafeResult (*PLibThreadSafeSoftStringReturner_ThreadSafetyCheckPtr) (LibThreadSafe_SoftStringReturner pSoftStringReturner);
97+
98+
/*************************************************************************************************************************
99+
Class definition for StrictStringReturner
100+
**************************************************************************************************************************/
101+
102+
/**
103+
* Returns a string
104+
*
105+
* @param[in] pStrictStringReturner - StrictStringReturner instance.
106+
* @param[in] nValueBufferSize - size of the buffer (including trailing 0)
107+
* @param[out] pValueNeededChars - will be filled with the count of the written bytes, or needed buffer size.
108+
* @param[out] pValueBuffer - buffer of , may be NULL
109+
* @return error code or 0 (success)
110+
*/
111+
typedef LibThreadSafeResult (*PLibThreadSafeStrictStringReturner_GetStringPtr) (LibThreadSafe_StrictStringReturner pStrictStringReturner, const LibThreadSafe_uint32 nValueBufferSize, LibThreadSafe_uint32* pValueNeededChars, char * pValueBuffer);
112+
113+
/**
114+
* Function that shouldn't crash when called from different threads at the same time
115+
*
116+
* @param[in] pStrictStringReturner - StrictStringReturner instance.
117+
* @return error code or 0 (success)
118+
*/
119+
typedef LibThreadSafeResult (*PLibThreadSafeStrictStringReturner_ThreadSafetyCheckPtr) (LibThreadSafe_StrictStringReturner pStrictStringReturner);
120+
121+
/*************************************************************************************************************************
122+
Global functions
123+
**************************************************************************************************************************/
124+
125+
/**
126+
* retrieves the binary version of this library.
127+
*
128+
* @param[out] pMajor - returns the major version of this library
129+
* @param[out] pMinor - returns the minor version of this library
130+
* @param[out] pMicro - returns the micro version of this library
131+
* @return error code or 0 (success)
132+
*/
133+
typedef LibThreadSafeResult (*PLibThreadSafeGetVersionPtr) (LibThreadSafe_uint32 * pMajor, LibThreadSafe_uint32 * pMinor, LibThreadSafe_uint32 * pMicro);
134+
135+
/**
136+
* Returns the last error recorded on this object
137+
*
138+
* @param[in] pInstance - Instance Handle
139+
* @param[in] nErrorMessageBufferSize - size of the buffer (including trailing 0)
140+
* @param[out] pErrorMessageNeededChars - will be filled with the count of the written bytes, or needed buffer size.
141+
* @param[out] pErrorMessageBuffer - buffer of Message of the last error, may be NULL
142+
* @param[out] pHasError - Is there a last error to query
143+
* @return error code or 0 (success)
144+
*/
145+
typedef LibThreadSafeResult (*PLibThreadSafeGetLastErrorPtr) (LibThreadSafe_Base pInstance, const LibThreadSafe_uint32 nErrorMessageBufferSize, LibThreadSafe_uint32* pErrorMessageNeededChars, char * pErrorMessageBuffer, bool * pHasError);
146+
147+
/**
148+
* Acquire shared ownership of an Instance
149+
*
150+
* @param[in] pInstance - Instance Handle
151+
* @return error code or 0 (success)
152+
*/
153+
typedef LibThreadSafeResult (*PLibThreadSafeAcquireInstancePtr) (LibThreadSafe_Base pInstance);
154+
155+
/**
156+
* Releases shared ownership of an Instance
157+
*
158+
* @param[in] pInstance - Instance Handle
159+
* @return error code or 0 (success)
160+
*/
161+
typedef LibThreadSafeResult (*PLibThreadSafeReleaseInstancePtr) (LibThreadSafe_Base pInstance);
162+
163+
/**
164+
* Creates a new StringReturner instance
165+
*
166+
* @param[out] pInstance - New StringReturner instance
167+
* @return error code or 0 (success)
168+
*/
169+
typedef LibThreadSafeResult (*PLibThreadSafeCreateStringReturnerPtr) (LibThreadSafe_StringReturner * pInstance);
170+
171+
/**
172+
* Creates a new SoftStringReturner instance
173+
*
174+
* @param[out] pInstance - New SoftStringReturner instance
175+
* @return error code or 0 (success)
176+
*/
177+
typedef LibThreadSafeResult (*PLibThreadSafeCreateSoftStringReturnerPtr) (LibThreadSafe_SoftStringReturner * pInstance);
178+
179+
/**
180+
* Creates a new StrictStringReturner instance
181+
*
182+
* @param[out] pInstance - New StrictStringReturner instance
183+
* @return error code or 0 (success)
184+
*/
185+
typedef LibThreadSafeResult (*PLibThreadSafeCreateStrictStringReturnerPtr) (LibThreadSafe_StrictStringReturner * pInstance);
186+
187+
/*************************************************************************************************************************
188+
Function Table Structure
189+
**************************************************************************************************************************/
190+
191+
typedef struct {
192+
void * m_LibraryHandle;
193+
PLibThreadSafeBase_ClassTypeIdPtr m_Base_ClassTypeId;
194+
PLibThreadSafeBase__lockInstancePtr m_Base__lockInstance;
195+
PLibThreadSafeBase__unlockInstancePtr m_Base__unlockInstance;
196+
PLibThreadSafeStringReturner_GetStringPtr m_StringReturner_GetString;
197+
PLibThreadSafeStringReturner_ThreadSafetyCheckPtr m_StringReturner_ThreadSafetyCheck;
198+
PLibThreadSafeSoftStringReturner_GetStringPtr m_SoftStringReturner_GetString;
199+
PLibThreadSafeSoftStringReturner_ThreadSafetyCheckPtr m_SoftStringReturner_ThreadSafetyCheck;
200+
PLibThreadSafeStrictStringReturner_GetStringPtr m_StrictStringReturner_GetString;
201+
PLibThreadSafeStrictStringReturner_ThreadSafetyCheckPtr m_StrictStringReturner_ThreadSafetyCheck;
202+
PLibThreadSafeGetVersionPtr m_GetVersion;
203+
PLibThreadSafeGetLastErrorPtr m_GetLastError;
204+
PLibThreadSafeAcquireInstancePtr m_AcquireInstance;
205+
PLibThreadSafeReleaseInstancePtr m_ReleaseInstance;
206+
PLibThreadSafeCreateStringReturnerPtr m_CreateStringReturner;
207+
PLibThreadSafeCreateSoftStringReturnerPtr m_CreateSoftStringReturner;
208+
PLibThreadSafeCreateStrictStringReturnerPtr m_CreateStrictStringReturner;
209+
} sLibThreadSafeDynamicWrapperTable;
210+
211+
#endif // __LIBTHREADSAFE_DYNAMICHEADER_CPPTYPES
212+

0 commit comments

Comments
 (0)