Skip to content

Commit

Permalink
rename to service_event_publisher & use pimpl
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
  • Loading branch information
ihasdapie committed Aug 10, 2022
1 parent 7a2988d commit b40a655
Show file tree
Hide file tree
Showing 10 changed files with 360 additions and 245 deletions.
2 changes: 1 addition & 1 deletion rcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ set(${PROJECT_NAME}_sources
src/rcl/rmw_implementation_identifier_check.c
src/rcl/security.c
src/rcl/service.c
src/rcl/service_event_publisher.c
src/rcl/subscription.c
src/rcl/time.c
src/rcl/timer.c
src/rcl/validate_enclave_name.c
src/rcl/validate_topic_name.c
src/rcl/wait.c
src/rcl/introspection.c
)

add_library(${PROJECT_NAME} ${${PROJECT_NAME}_sources})
Expand Down
51 changes: 51 additions & 0 deletions rcl/include/rcl/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,57 @@ rcl_client_set_on_new_response_callback(
rcl_event_callback_t callback,
const void * user_data);

/// Enables service introspection features for the client
/*
* This function is a thin wrapper around rcl_service_introspection_enable
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | TODO(ihasdapie): Fill this out
* Uses Atomics |
* Lock-Free |
* \param[in] client The client on which to enable service introspection
* \param[in] node The node for which the service event publisher is to be associated to
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_service_introspection_enable_client_service_events(
rcl_client_t * client,
rcl_node_t * node);

/// Disables service introspection features for the client
/*
* This function is a thin wrapper around rcl_service_introspection_disable
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | TODO(ihasdapie): Fill this out
* Uses Atomics |
* Lock-Free |
* \param[in] client The client on which to disable service introspection
* \param[in] node The node for which the service event publisher is associated with
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_service_introspection_disable_client_service_events(
rcl_client_t * client,
rcl_node_t * node);

RCL_PUBLIC
void
rcl_service_introspection_enable_client_service_event_message_payload( rcl_client_t * client);

RCL_PUBLIC
void
rcl_service_introspection_disable_client_service_event_message_payload( rcl_client_t * client);


#ifdef __cplusplus
}
#endif
Expand Down
56 changes: 52 additions & 4 deletions rcl/include/rcl/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extern "C"
#include "rcl/macros.h"
#include "rcl/node.h"
#include "rcl/visibility_control.h"
// #include "rcl/introspection.h" // TODO(ihasdapie): Dependency cycle. Instead let's just put the clock into service_options.

/// Internal rcl implementation struct.
typedef struct rcl_service_impl_s rcl_service_impl_t;
Expand All @@ -51,7 +50,6 @@ typedef struct rcl_service_options_s
rcl_allocator_t allocator;
/// Enable/Disable service introspection features
bool enable_service_introspection;

/// The clock to use for service introspection message timestampes
rcl_clock_t * clock;
} rcl_service_options_t;
Expand Down Expand Up @@ -112,7 +110,7 @@ rcl_get_zero_initialized_service(void);
*
* The options struct allows the user to set the quality of service settings as
* well as a custom allocator which is used when initializing/finalizing the
* client to allocate space for incidentals, e.g. the service name string.
* server to allocate space for incidentals, e.g. the service name string.
*
* Expected usage (for C services):
*
Expand Down Expand Up @@ -289,7 +287,7 @@ rcl_take_request(
rmw_request_id_t * request_header,
void * ros_request);

/// Send a ROS response to a client using a service.
/// Send a ROS response to a server using a service.
/**
* It is the job of the caller to ensure that the type of the `ros_response`
* parameter and the type associate with the service (via the type support)
Expand Down Expand Up @@ -542,6 +540,56 @@ rcl_service_set_on_new_request_callback(
rcl_event_callback_t callback,
const void * user_data);

/// Enables service introspection features for the service
/*
* This function is a thin wrapper around rcl_service_introspection_enable
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | TODO(ihasdapie): Fill this out
* Uses Atomics |
* Lock-Free |
* \param[in] server The server on which to enable service introspection
* \param[in] node The node for which the service event publisher is to be associated to
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_service_introspection_enable_server_service_events(
rcl_service_t * service,
rcl_node_t * node);

/// Disables service introspection features for the service
/*
* This function is a thin wrapper around rcl_service_introspection_disable
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | TODO(ihasdapie): Fill this out
* Uses Atomics |
* Lock-Free |
* \param[in] server The server on which to disable service introspection
* \param[in] node The node for which the service event publisher is associated with
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_service_introspection_disable_server_service_events(
rcl_service_t * service,
rcl_node_t * node);

RCL_PUBLIC
void
rcl_service_introspection_enable_server_service_event_message_payload(rcl_service_t * service);

RCL_PUBLIC
void
rcl_service_introspection_disable_server_service_event_message_payload(rcl_service_t * service);

#ifdef __cplusplus
}
#endif
Expand Down
24 changes: 24 additions & 0 deletions rcl/include/rcl/service_introspection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2022 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef RCL__SERVICE_INTROSPECTION_H_
#define RCL__SERVICE_INTROSPECTION_H_

#define RCL_SERVICE_INTROSPECTION_TOPIC_POSTFIX "/_service_event"
#define RCL_SERVICE_INTROSPECTION_PUBLISH_CLIENT_PARAMETER "publish_client_events"
#define RCL_SERVICE_INTROSPECTION_PUBLISH_SERVICE_PARAMETER "publish_service_events"
#define RCL_SERVICE_INTROSPECTION_PUBLISH_CLIENT_EVENT_CONTENT_PARAMETER "publish_client_content"
#define RCL_SERVICE_INTROSPECTION_PUBLISH_SERVICE_EVENT_CONTENT_PARAMETER "publish_service_content"

#endif // RCL__SERVICE_INTROSPECTION_H_
77 changes: 61 additions & 16 deletions rcl/src/rcl/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern "C"
#include "service_msgs/msg/service_event_info.h"


#include "rcl/introspection.h"
#include "service_event_publisher.h"

#include "./common.h"
#include "./client_impl.h"
Expand Down Expand Up @@ -109,17 +109,15 @@ rcl_client_init(
goto fail;
}

client->impl->introspection_utils = NULL;
client->impl->service_event_publisher = NULL;
if (options->enable_service_introspection) {
client->impl->introspection_utils = (rcl_service_event_publisher_t *) allocator->allocate(
sizeof(rcl_service_event_publisher_t), allocator->state);
*client->impl->introspection_utils = rcl_get_zero_initialized_introspection_utils();
ret = rcl_service_introspection_init(
client->impl->introspection_utils, type_support, remapped_service_name, node,
client->impl->service_event_publisher = allocator->zero_allocate(
1, sizeof(rcl_service_event_publisher_t), allocator->state);
*client->impl->service_event_publisher = rcl_get_zero_initialized_service_event_publisher();
ret = rcl_service_event_publisher_init(
client->impl->service_event_publisher, type_support, remapped_service_name, node,
options->clock, allocator);
}


// get actual qos, and store it
rmw_ret_t rmw_ret = rmw_client_request_publisher_get_actual_qos(
client->impl->rmw_handle,
Expand Down Expand Up @@ -159,9 +157,9 @@ rcl_client_init(
remapped_service_name);
goto cleanup;
fail:
if (client->impl->introspection_utils) {
allocator->deallocate(client->impl->introspection_utils, allocator->state);
client->impl->introspection_utils = NULL;
if (client->impl->service_event_publisher) {
allocator->deallocate(client->impl->service_event_publisher, allocator->state);
client->impl->service_event_publisher = NULL;
}
if (client->impl) {
allocator->deallocate(client->impl, allocator->state);
Expand Down Expand Up @@ -267,8 +265,8 @@ rcl_send_request(const rcl_client_t * client, const void * ros_request, int64_t


if (rcl_client_get_options(client)->enable_service_introspection) {
rcl_ret_t ret = rcl_introspection_send_message(
client->impl->introspection_utils,
rcl_ret_t ret = rcl_send_service_event_message(
client->impl->service_event_publisher,
service_msgs__msg__ServiceEventInfo__REQUEST_SENT,
ros_request,
*sequence_number,
Expand Down Expand Up @@ -314,8 +312,8 @@ rcl_take_response_with_info(
}

if (rcl_client_get_options(client)->enable_service_introspection) {
rcl_ret_t ret = rcl_introspection_send_message(
client->impl->introspection_utils,
rcl_ret_t ret = rcl_send_service_event_message(
client->impl->service_event_publisher,
service_msgs__msg__ServiceEventInfo__RESPONSE_RECEIVED,
ros_response,
request_header->request_id.sequence_number,
Expand Down Expand Up @@ -390,6 +388,53 @@ rcl_client_set_on_new_response_callback(
user_data);
}

rcl_ret_t
rcl_service_introspection_enable_client_service_events(
rcl_client_t * client,
rcl_node_t * node)
{
rcl_service_event_publisher_t * introspection_utils = client->impl->service_event_publisher;
if (introspection_utils->impl->_enabled) {
return RCL_RET_OK;
}
rcl_ret_t ret = rcl_service_introspection_enable(
introspection_utils, node, &client->impl->options.allocator);
if (RCL_RET_OK != ret) {
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
return RCL_RET_ERROR;
}
return RCL_RET_OK;
}

rcl_ret_t
rcl_service_introspection_disable_client_service_events(
rcl_client_t * client,
rcl_node_t * node)
{
rcl_service_event_publisher_t * introspection_utils = client->impl->service_event_publisher;
if (introspection_utils->impl->_enabled) {
return RCL_RET_OK;
}
rcl_ret_t ret = rcl_service_introspection_disable(
introspection_utils, node, &client->impl->options.allocator);
if (RCL_RET_OK != ret) {
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
return RCL_RET_ERROR;
}
return RCL_RET_OK;
}

void
rcl_service_introspection_enable_client_service_event_message_payload(rcl_client_t * client)
{
client->impl->service_event_publisher->impl->_content_enabled = true;
}

void
rcl_service_introspection_disable_client_service_event_message_payload(rcl_client_t * client){
client->impl->service_event_publisher->impl->_content_enabled = false;
}

#ifdef __cplusplus
}
#endif
4 changes: 2 additions & 2 deletions rcl/src/rcl/client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "rcl/client.h"

#include "rcutils/stdatomic_helper.h"
#include "rcl/introspection.h"
#include "service_event_publisher.h"

struct rcl_client_impl_s
{
Expand All @@ -29,7 +29,7 @@ struct rcl_client_impl_s
rmw_qos_profile_t actual_response_subscription_qos;
rmw_client_t * rmw_handle;
atomic_int_least64_t sequence_number;
rcl_service_event_publisher_t * introspection_utils;
rcl_service_event_publisher_t * service_event_publisher;
};

#endif // RCL__CLIENT_IMPL_H_
Loading

0 comments on commit b40a655

Please sign in to comment.