Skip to content

Commit 94964d2

Browse files
committed
doc: robotkernel bridge
1 parent 5c68b8b commit 94964d2

1 file changed

Lines changed: 170 additions & 41 deletions

File tree

include/robotkernel/bridge_base.h

Lines changed: 170 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@
2424
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2525
*/
2626

27+
/**
28+
* @file bridge_base.h
29+
* @brief Base definitions for robotkernel bridge components.
30+
*
31+
* This header defines the fundamental types and base class used
32+
* by *bridge* modules in robotkernel. A *bridge* is a plugin-style
33+
* component that can be dynamically configured from C code,
34+
* exposes services, and interacts with the robotkernel runtime.
35+
*
36+
* The header provides:
37+
* - A C-ABI for configuring/unconfiguring bridges
38+
* - Function pointer typedefs for common bridge operations
39+
* - A C++ abstract base class `robotkernel::bridge_base`
40+
* for implementing concrete bridge logic
41+
*
42+
* The C ABI is intended for foreign language bindings or dynamic
43+
* loading of bridge modules via shared objects.
44+
*
45+
* @note
46+
* - The C interface uses opaque bridge handles (`void*`).
47+
* - Concrete bridge classes must derive from `bridge_base`
48+
* and implement service registration methods.
49+
*/
50+
2751
#ifndef ROBOTKERNEL_BRIDGE_BASE_H
2852
#define ROBOTKERNEL_BRIDGE_BASE_H
2953

@@ -47,31 +71,69 @@
4771
#define EXPORT_C
4872
#endif
4973

74+
/**
75+
* @typedef BRIDGE_HANDLE
76+
* @brief Opaque pointer representing a configured bridge instance.
77+
*
78+
* This type is used in the C-ABI to refer to a bridge object
79+
* without exposing C++ types.
80+
*/
5081
#define BRIDGE_HANDLE void*
5182

52-
//! bridge configure
53-
/*!
54-
* \param name bridge name
55-
* \param config bridge config
56-
* \return bridge handle
83+
/**
84+
* @brief Signature for the bridge configuration function.
85+
*
86+
* This function is called to construct and initialize a bridge
87+
* instance. It receives a name and a YAML configuration string.
88+
*
89+
* @param name
90+
* Null-terminated string identifying the bridge instance.
91+
*
92+
* @param config
93+
* Null-terminated YAML configuration.
94+
*
95+
* @return
96+
* A handle to the newly created bridge instance,
97+
* or nullptr on failure.
5798
*/
5899
typedef BRIDGE_HANDLE (*bridge_configure_t)(const char* name, const char* config);
59100

60-
//! bridge unconfigure
61-
/*!
62-
* \param hdl bridge handle
101+
/**
102+
* @brief Signature for the bridge unconfigure function.
103+
*
104+
* This function is called to destroy and clean up a bridge.
105+
*
106+
* @param hdl
107+
* The bridge handle returned from bridge_configure().
108+
*
109+
* @return
110+
* Zero on success or a negative error code.
63111
*/
64112
typedef int (*bridge_unconfigure_t)(BRIDGE_HANDLE hdl);
65113

66-
//! create and register ln service
67-
/*!
68-
* \param svc robotkernel service struct
114+
/**
115+
* @brief Signature for adding a robotkernel service.
116+
*
117+
* Allows the bridge to register a service with robotkernel.
118+
*
119+
* @param hdl
120+
* The bridge handle.
121+
*
122+
* @param svc
123+
* A `service_t` struct defining the service to add.
69124
*/
70125
typedef void (*bridge_add_service_t)(BRIDGE_HANDLE hdl, const robotkernel::service_t &svc);
71126

72-
//! unregister and remove ln service
73-
/*!
74-
* \param svc robotkernel service struct
127+
/**
128+
* @brief Signature for removing a robotkernel service.
129+
*
130+
* Allows the bridge to unregister a service.
131+
*
132+
* @param hdl
133+
* The bridge handle.
134+
*
135+
* @param svc
136+
* A `service_t` struct identifying the service to remove.
75137
*/
76138
typedef void (*bridge_remove_service_t)(BRIDGE_HANDLE hdl, const robotkernel::service_t &svc);
77139

@@ -84,6 +146,35 @@ typedef void (*bridge_remove_service_t)(BRIDGE_HANDLE hdl, const robotkernel::se
84146
throw std::runtime_error(string("["#bridgename"] invalid bridge " \
85147
"handle to <"#bridgeclass" *>\n"));
86148

149+
/**
150+
* @def BRIDGE_DEF
151+
* @brief Define the C interface entry points for a robotkernel bridge.
152+
*
153+
* This macro generates the required C symbols that allow the
154+
* robotkernel runtime to load and manage a bridge implemented
155+
* in C++.
156+
*
157+
* It defines:
158+
* - bridge_configure(): creates a bridge instance
159+
* - bridge_unconfigure(): destroys the bridge instance
160+
* - bridge_add_service(): register a robotkernel service
161+
* - bridge_remove_service(): unregister a robotkernel service
162+
*
163+
* The macro binds a C++ class to the C ABI expected by robotkernel.
164+
*
165+
* @param class_name
166+
* Name of the C++ class implementing the bridge.
167+
*
168+
* @param impl_name
169+
* String identifying the bridge implementation type.
170+
*
171+
* @note
172+
* - The class must derive from robotkernel::bridge_base
173+
* - The constructor must accept:
174+
* (const std::string&, const std::string&, const YAML::Node&)
175+
* - The returned object is owned by the kernel and deleted
176+
* via bridge_unconfigure()
177+
*/
87178
#define BRIDGE_DEF(bridgename, bridgeclass) \
88179
struct instance_name ## _wrapper { \
89180
std::shared_ptr<bridgeclass> sp; \
@@ -123,47 +214,85 @@ EXPORT_C BRIDGE_HANDLE bridge_configure(const char* name, const char* config) {
123214

124215
namespace robotkernel {
125216

217+
/**
218+
* @class bridge_base
219+
* @brief Abstract base class for a robotkernel bridge implementation.
220+
*
221+
* Concrete bridge modules should derive from this class and
222+
* implement service registration methods. The bridge participates
223+
* in robotkernel logging via `log_base` (inherited).
224+
*
225+
* The bridge lifecycle involves:
226+
* - Construction with a name, implementation type, and config
227+
* - Optional `init()`/`deinit()` calls
228+
* - Service registration via `add_service()`
229+
* - Cleanup via `remove_service()`
230+
*
231+
* Instances are typically wrapped in a shared pointer.
232+
*/
126233
class bridge_base :
127234
public log_base
128235
{
129236
private:
130-
bridge_base(); //!< prevent default construction
237+
// Prevent default construction
238+
bridge_base();
131239

132240
public:
133-
//! construction
134-
/*!
135-
* \param instance_name bridge name
136-
* \param name instance name
241+
/**
242+
* @brief Construct a bridge with the given names.
243+
*
244+
* @param name
245+
* The configured instance name.
246+
* @param impl
247+
* The implementation type string.
248+
* @param node
249+
* Parsed YAML node for configuration.
250+
*/
251+
bridge_base(const std::string& name,
252+
const std::string& impl,
253+
const YAML::Node& node = YAML::Node())
254+
: log_base(name, impl, "", node)
255+
{}
256+
257+
/**
258+
* @brief Virtual destructor.
137259
*/
138-
bridge_base(const std::string& name, const std::string& impl,
139-
const YAML::Node& node = YAML::Node()) :
140-
log_base(name, impl, "", node)
141-
{
142-
}
143-
144260
virtual ~bridge_base() {};
145-
146-
//! optional initiazation methon
147-
/*
148-
* usefull to call shared_from_this() at construction time
261+
262+
/**
263+
* @brief Optional initialization method.
264+
*
265+
* Called after construction to perform any additional setup.
266+
* Useful when the implementation needs to use `shared_from_this()`
267+
* during initialization.
149268
*/
150269
void init() {};
151-
152-
//! optional deinitiazation methon
153-
/*
154-
* usefull to call shared_from_this() at construction time
270+
271+
/**
272+
* @brief Optional deinitialization method.
273+
*
274+
* Called before destruction to perform cleanup that
275+
* depends on shared ownership.
155276
*/
156277
void deinit() {};
157-
158-
//! create and register service
159-
/*!
160-
* \param svc robotkernel service struct
278+
279+
/**
280+
* @brief Register a service with the robotkernel runtime.
281+
*
282+
* Derived classes must implement this to expose functionality.
283+
*
284+
* @param svc
285+
* The service descriptor to register.
161286
*/
162287
virtual void add_service(const robotkernel::service_t &svc) = 0;
163-
164-
//! unregister and remove service
165-
/*!
166-
* \param svc robotkernel service struct
288+
289+
/**
290+
* @brief Unregister a previously registered service.
291+
*
292+
* Derived classes implement this to clean up.
293+
*
294+
* @param svc
295+
* The service descriptor to unregister.
167296
*/
168297
virtual void remove_service(const robotkernel::service_t &svc) = 0;
169298
};

0 commit comments

Comments
 (0)