Skip to content

Commit

Permalink
Use macros RMW_CHECK_TYPE_IDENTIFIERS_MATCH, which is optimized for m…
Browse files Browse the repository at this point in the history
…emory allocation inside rmw_fastrtps_cpp.

- Include header necessary for using the above API.
- Bring about common comparion (identifier match) method within all the files.

Signed-off-by: Sriram Raghunathan <[email protected]>
  • Loading branch information
Sriram Raghunathan committed Oct 30, 2017
1 parent 5030f85 commit a6d2aba
Show file tree
Hide file tree
Showing 21 changed files with 163 additions and 113 deletions.
20 changes: 14 additions & 6 deletions rmw_fastrtps_cpp/src/get_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rmw/impl/cpp/macros.hpp"

#include "rmw_fastrtps_cpp/get_client.hpp"

#include "rmw_fastrtps_cpp/custom_client_info.hpp"
Expand All @@ -26,9 +28,12 @@ get_request_publisher(rmw_client_t * client)
if (!client) {
return nullptr;
}
if (client->implementation_identifier != eprosima_fastrtps_identifier) {
return nullptr;
}

RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
client handle,
client->implementation_identifier, eprosima_fastrtps_identifier,
return nullptr)

auto impl = static_cast<CustomClientInfo *>(client->data);
return impl->request_publisher_;
}
Expand All @@ -39,9 +44,12 @@ get_response_subscriber(rmw_client_t * client)
if (!client) {
return nullptr;
}
if (client->implementation_identifier != eprosima_fastrtps_identifier) {
return nullptr;
}

RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
client handle,
client->implementation_identifier, eprosima_fastrtps_identifier,
return nullptr)

auto impl = static_cast<CustomClientInfo *>(client->data);
return impl->response_subscriber_;
}
Expand Down
10 changes: 7 additions & 3 deletions rmw_fastrtps_cpp/src/get_participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// 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.
#include "rmw/impl/cpp/macros.hpp"

#include "rmw_fastrtps_cpp/get_participant.hpp"

Expand All @@ -26,9 +27,12 @@ get_participant(rmw_node_t * node)
if (!node) {
return nullptr;
}
if (node->implementation_identifier != eprosima_fastrtps_identifier) {
return nullptr;
}

RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node handle,
node->implementation_identifier, eprosima_fastrtps_identifier,
return nullptr)

auto impl = static_cast<CustomParticipantInfo *>(node->data);
return impl->participant;
}
Expand Down
11 changes: 8 additions & 3 deletions rmw_fastrtps_cpp/src/get_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rmw/impl/cpp/macros.hpp"

#include "rmw_fastrtps_cpp/get_publisher.hpp"

#include "rmw_fastrtps_cpp/custom_publisher_info.hpp"
Expand All @@ -26,9 +28,12 @@ get_publisher(rmw_publisher_t * publisher)
if (!publisher) {
return nullptr;
}
if (publisher->implementation_identifier != eprosima_fastrtps_identifier) {
return nullptr;
}

RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
publisher handle,
publisher->implementation_identifier, eprosima_fastrtps_identifier,
return nullptr)

auto impl = static_cast<CustomPublisherInfo *>(publisher->data);
return impl->publisher_;
}
Expand Down
20 changes: 14 additions & 6 deletions rmw_fastrtps_cpp/src/get_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rmw/impl/cpp/macros.hpp"

#include "rmw_fastrtps_cpp/get_service.hpp"

#include "rmw_fastrtps_cpp/custom_service_info.hpp"
Expand All @@ -26,9 +28,12 @@ get_request_subscriber(rmw_service_t * service)
if (!service) {
return nullptr;
}
if (service->implementation_identifier != eprosima_fastrtps_identifier) {
return nullptr;
}

RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
service handle,
service->implementation_identifier, eprosima_fastrtps_identifier,
return nullptr)

auto impl = static_cast<CustomServiceInfo *>(service->data);
return impl->request_subscriber_;
}
Expand All @@ -39,9 +44,12 @@ get_response_publisher(rmw_service_t * service)
if (!service) {
return nullptr;
}
if (service->implementation_identifier != eprosima_fastrtps_identifier) {
return nullptr;
}

RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
service handle,
service->implementation_identifier, eprosima_fastrtps_identifier,
return nullptr)

auto impl = static_cast<CustomServiceInfo *>(service->data);
return impl->response_publisher_;
}
Expand Down
11 changes: 8 additions & 3 deletions rmw_fastrtps_cpp/src/get_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rmw/impl/cpp/macros.hpp"

#include "rmw_fastrtps_cpp/get_subscriber.hpp"

#include "rmw_fastrtps_cpp/custom_subscriber_info.hpp"
Expand All @@ -26,9 +28,12 @@ get_subscriber(rmw_subscription_t * subscription)
if (!subscription) {
return nullptr;
}
if (subscription->implementation_identifier != eprosima_fastrtps_identifier) {
return nullptr;
}

RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
subscription handle,
subscription->implementation_identifier, eprosima_fastrtps_identifier,
return nullptr)

auto impl = static_cast<CustomSubscriberInfo *>(subscription->data);
return impl->subscriber_;
}
Expand Down
9 changes: 5 additions & 4 deletions rmw_fastrtps_cpp/src/rmw_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "rcutils/logging_macros.h"

#include "rmw/allocators.h"
#include "rmw/impl/cpp/macros.hpp"
#include "rmw/rmw.h"

#include "rosidl_typesupport_introspection_cpp/identifier.hpp"
Expand Down Expand Up @@ -45,10 +46,10 @@ rmw_create_client(
return nullptr;
}

if (node->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
return nullptr;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node handle,
node->implementation_identifier, eprosima_fastrtps_identifier,
return nullptr)

if (!service_name || strlen(service_name) == 0) {
RMW_SET_ERROR_MSG("client topic is null or empty string");
Expand Down
18 changes: 10 additions & 8 deletions rmw_fastrtps_cpp/src/rmw_compare_gids_equal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "fastrtps/rtps/common/Guid.h"


#include "rmw/impl/cpp/macros.hpp"
#include "rmw/rmw.h"
#include "rmw/error_handling.h"
#include "rmw/types.h"
Expand All @@ -30,20 +32,20 @@ rmw_compare_gids_equal(const rmw_gid_t * gid1, const rmw_gid_t * gid2, bool * re
return RMW_RET_ERROR;
}

if (gid1->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("guid1 handle not from this implementation");
return RMW_RET_ERROR;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
gid1 handle,
gid1->implementation_identifier, eprosima_fastrtps_identifier,
return RMW_RET_ERROR)

if (!gid2) {
RMW_SET_ERROR_MSG("gid2 is null");
return RMW_RET_ERROR;
}

if (gid2->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("gid1 handle not from this implementation");
return RMW_RET_ERROR;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
gid2 handle,
gid2->implementation_identifier, eprosima_fastrtps_identifier,
return RMW_RET_ERROR)

if (!result) {
RMW_SET_ERROR_MSG("result is null");
Expand Down
17 changes: 9 additions & 8 deletions rmw_fastrtps_cpp/src/rmw_count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "rcutils/logging_macros.h"

#include "rmw/impl/cpp/macros.hpp"
#include "rmw/error_handling.h"
#include "rmw/rmw.h"
#include "rmw/types.h"
Expand All @@ -41,10 +42,10 @@ rmw_count_publishers(
return RMW_RET_ERROR;
}
// Get participant pointer from node
if (node->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
return RMW_RET_ERROR;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node handle,
node->implementation_identifier, eprosima_fastrtps_identifier,
return RMW_RET_ERROR)

auto impl = static_cast<CustomParticipantInfo *>(node->data);

Expand Down Expand Up @@ -80,10 +81,10 @@ rmw_count_subscribers(
return RMW_RET_ERROR;
}
// Get participant pointer from node
if (node->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
return RMW_RET_ERROR;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node handle,
node->implementation_identifier, eprosima_fastrtps_identifier,
return RMW_RET_ERROR)

CustomParticipantInfo * impl = static_cast<CustomParticipantInfo *>(node->data);

Expand Down
9 changes: 5 additions & 4 deletions rmw_fastrtps_cpp/src/rmw_get_gid_for_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rmw/impl/cpp/macros.hpp"
#include "rmw/error_handling.h"
#include "rmw/rmw.h"
#include "rmw/types.h"
Expand All @@ -29,10 +30,10 @@ rmw_get_gid_for_publisher(const rmw_publisher_t * publisher, rmw_gid_t * gid)
return RMW_RET_ERROR;
}

if (publisher->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("publisher handle not from this implementation");
return RMW_RET_ERROR;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
publisher handle,
publisher->implementation_identifier, eprosima_fastrtps_identifier,
return RMW_RET_ERROR)

if (!gid) {
RMW_SET_ERROR_MSG("gid is null");
Expand Down
9 changes: 5 additions & 4 deletions rmw_fastrtps_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "rcutils/filesystem.h"
#include "rcutils/logging_macros.h"

#include "rmw/impl/cpp/macros.hpp"
#include "rmw/allocators.h"
#include "rmw/error_handling.h"
#include "rmw/rmw.h"
Expand Down Expand Up @@ -247,10 +248,10 @@ rmw_destroy_node(rmw_node_t * node)
return RMW_RET_ERROR;
}

if (node->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
return RMW_RET_ERROR;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node handle,
node->implementation_identifier, eprosima_fastrtps_identifier,
return RMW_RET_ERROR)

auto impl = static_cast<CustomParticipantInfo *>(node->data);
if (!impl) {
Expand Down
9 changes: 5 additions & 4 deletions rmw_fastrtps_cpp/src/rmw_node_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "rcutils/strdup.h"
#include "rcutils/types.h"

#include "rmw/impl/cpp/macros.hpp"
#include "rmw/allocators.h"
#include "rmw/convert_rcutils_ret_to_rmw_ret.h"
#include "rmw/error_handling.h"
Expand Down Expand Up @@ -45,10 +46,10 @@ rmw_get_node_names(
}

// Get participant pointer from node
if (node->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
return RMW_RET_ERROR;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node handle,
node->implementation_identifier, eprosima_fastrtps_identifier,
return RMW_RET_ERROR)

auto impl = static_cast<CustomParticipantInfo *>(node->data);
Participant * participant = impl->participant;
Expand Down
9 changes: 5 additions & 4 deletions rmw_fastrtps_cpp/src/rmw_publish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "fastcdr/Cdr.h"
#include "fastcdr/FastBuffer.h"

#include "rmw/impl/cpp/macros.hpp"
#include "rmw/allocators.h"
#include "rmw/error_handling.h"
#include "rmw/rmw.h"
Expand All @@ -32,10 +33,10 @@ rmw_publish(const rmw_publisher_t * publisher, const void * ros_message)
assert(ros_message);
rmw_ret_t returnedValue = RMW_RET_ERROR;

if (publisher->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("publisher handle not from this implementation");
return RMW_RET_ERROR;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
publisher handle,
publisher->implementation_identifier, eprosima_fastrtps_identifier,
return RMW_RET_ERROR)

auto info = static_cast<CustomPublisherInfo *>(publisher->data);
assert(info);
Expand Down
25 changes: 13 additions & 12 deletions rmw_fastrtps_cpp/src/rmw_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <string>

#include "rmw/impl/cpp/macros.hpp"
#include "rmw/allocators.h"
#include "rmw/error_handling.h"
#include "rmw/rmw.h"
Expand All @@ -39,10 +40,10 @@ rmw_create_publisher(
return nullptr;
}

if (node->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
return nullptr;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node handle,
node->implementation_identifier, eprosima_fastrtps_identifier,
return nullptr)

if (!topic_name || strlen(topic_name) == 0) {
RMW_SET_ERROR_MSG("publisher topic is null or empty string");
Expand Down Expand Up @@ -198,20 +199,20 @@ rmw_destroy_publisher(rmw_node_t * node, rmw_publisher_t * publisher)
return RMW_RET_ERROR;
}

if (node->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("publisher handle not from this implementation");
return RMW_RET_ERROR;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node handle,
node->implementation_identifier, eprosima_fastrtps_identifier,
return RMW_RET_ERROR)

if (!publisher) {
RMW_SET_ERROR_MSG("publisher handle is null");
return RMW_RET_ERROR;
}

if (publisher->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("publisher handle not from this implementation");
return RMW_RET_ERROR;
}
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
publisher handle,
publisher->implementation_identifier, eprosima_fastrtps_identifier,
return RMW_RET_ERROR)

auto info = static_cast<CustomPublisherInfo *>(publisher->data);
if (info != nullptr) {
Expand Down
Loading

0 comments on commit a6d2aba

Please sign in to comment.