Skip to content
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
17 changes: 17 additions & 0 deletions rcldotnet/Publisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ internal delegate RCLRet NativeRCLPublishType(

internal static NativeRCLPublishType native_rcl_publish = null;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int NativeRCLGetSubscriptionCountType(SafePublisherHandle publisherHandle, out int count);

internal static NativeRCLGetSubscriptionCountType native_rcl_get_subscription_count = null;

static PublisherDelegates()
{
_dllLoadUtils = DllLoadUtilsFactory.GetDllLoadUtils();
Expand All @@ -37,6 +42,10 @@ static PublisherDelegates()
IntPtr native_rcl_publish_ptr = _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_publish");
PublisherDelegates.native_rcl_publish = (NativeRCLPublishType)Marshal.GetDelegateForFunctionPointer(
native_rcl_publish_ptr, typeof(NativeRCLPublishType));

IntPtr native_rcl_get_subscription_count_ptr = _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_get_subscription_count");
PublisherDelegates.native_rcl_get_subscription_count = (NativeRCLGetSubscriptionCountType)Marshal.GetDelegateForFunctionPointer(
native_rcl_get_subscription_count_ptr, typeof(NativeRCLGetSubscriptionCountType));
}
}

Expand Down Expand Up @@ -79,5 +88,13 @@ public void Publish(T message)
RCLExceptionHelper.CheckReturnValue(ret, $"{nameof(PublisherDelegates.native_rcl_publish)}() failed.");
}
}

public int GetSubscriptionCount()
{
int count;
int ret = PublisherDelegates.native_rcl_get_subscription_count(Handle, out count);
RCLExceptionHelper.CheckReturnValue((RCLRet)ret, $"{nameof(PublisherDelegates.native_rcl_get_subscription_count)}() failed.");
return count;
}
}
}
13 changes: 13 additions & 0 deletions rcldotnet/rcldotnet_publisher.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ int32_t native_rcl_publish(void * publisher_handle, void * raw_ros_message)

return ret;
}

int32_t native_rcl_get_subscription_count(void * publisher_handle, int32_t * count_out)
{
rcl_publisher_t * publisher = (rcl_publisher_t *)publisher_handle;

int32_t count = 0;
rcl_ret_t ret = rcl_publisher_get_subscription_count(publisher, &count);
if (ret != RCL_RET_OK) {
return ret;
}
*count_out = count;
return ret;
}
3 changes: 3 additions & 0 deletions rcldotnet/rcldotnet_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@
RCLDOTNET_EXPORT
int32_t RCLDOTNET_CDECL native_rcl_publish(void *, void *);

RCLDOTNET_EXPORT
int32_t RCLDOTNET_CDECL native_rcl_get_subscription_count(void* publisher_handle, int32_t* count_out);

#endif // RCLDOTNET_PUBLISHER_H