Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose rcl shutdown function #135

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion rcldotnet/RCLdotnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ internal delegate void NativeRCLGetErrorStringType(

internal static NativeRCLOkType native_rcl_ok = null;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate RCLRet NativeRCLShutdownType();

internal static NativeRCLShutdownType native_rcl_shutdown = null;

[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal delegate RCLRet NativeRCLCreateNodeHandleType(
ref SafeNodeHandle nodeHandle, [MarshalAs(UnmanagedType.LPStr)] string nodeName, [MarshalAs(UnmanagedType.LPStr)] string nodeNamespace);
Expand Down Expand Up @@ -409,6 +414,12 @@ static RCLdotnetDelegates()
(NativeRCLOkType)Marshal.GetDelegateForFunctionPointer(
native_rcl_ok_ptr, typeof(NativeRCLOkType));

IntPtr native_rcl_shutdown_ptr =
_dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_shutdown");
RCLdotnetDelegates.native_rcl_shutdown =
(NativeRCLShutdownType)Marshal.GetDelegateForFunctionPointer(
native_rcl_shutdown_ptr, typeof(NativeRCLShutdownType));

IntPtr native_rcl_create_node_handle_ptr =
_dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_create_node_handle");
RCLdotnetDelegates.native_rcl_create_node_handle =
Expand Down Expand Up @@ -744,7 +755,8 @@ public static class RCLdotnet

public static bool Ok()
{
return RCLdotnetDelegates.native_rcl_ok() != 0;
bool ret = RCLdotnetDelegates.native_rcl_ok() != 0;
return ret;
}

public static Node CreateNode(string nodeName)
Expand Down Expand Up @@ -774,6 +786,12 @@ public static void Spin(Node node)
}
}

public static void Shutdown()
{
RCLRet ret = RCLdotnetDelegates.native_rcl_shutdown();
RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(RCLdotnetDelegates.native_rcl_shutdown)}() failed.");
}

public static Clock CreateClock(ClockType type = ClockType.RosTime)
{
var clockHandle = new SafeClockHandle();
Expand Down
9 changes: 9 additions & 0 deletions rcldotnet/rcldotnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ int32_t native_rcl_ok() {
return result ? 1 : 0;
}

int32_t native_rcl_shutdown() {
rcl_ret_t ret = rcl_shutdown(&context);
if (ret != RCL_RET_OK) {
return ret;
}

return rcl_context_fini(&context);
}

int32_t native_rcl_create_node_handle(void **node_handle, const char *name, const char *namespace) {
rcl_node_t *node = (rcl_node_t *)malloc(sizeof(rcl_node_t));
*node = rcl_get_zero_initialized_node();
Expand Down
3 changes: 3 additions & 0 deletions rcldotnet/rcldotnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void RCLDOTNET_CDECL native_rcl_reset_error(void);
RCLDOTNET_EXPORT
int32_t RCLDOTNET_CDECL native_rcl_ok();

RCLDOTNET_EXPORT
int32_t RCLDOTNET_CDECL native_rcl_shutdown();

RCLDOTNET_EXPORT
int32_t RCLDOTNET_CDECL native_rcl_create_node_handle(void **, const char *, const char *);

Expand Down
Loading