Skip to content

Commit

Permalink
Update gid API return codes. (#440)
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
hidmic authored and ahcorde committed Oct 15, 2020
1 parent 585366d commit a2e3bfb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 45 deletions.
40 changes: 15 additions & 25 deletions rmw_fastrtps_shared_cpp/src/rmw_compare_gids_equal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

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

#include "rmw/rmw.h"
#include "rmw/error_handling.h"
#include "rmw/impl/cpp/macros.hpp"
#include "rmw/rmw.h"
#include "rmw/types.h"

#include "rmw_fastrtps_shared_cpp/rmw_common.hpp"
Expand All @@ -29,30 +30,19 @@ __rmw_compare_gids_equal(
const rmw_gid_t * gid2,
bool * result)
{
if (!gid1) {
RMW_SET_ERROR_MSG("gid1 is null");
return RMW_RET_ERROR;
}

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

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

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

if (!result) {
RMW_SET_ERROR_MSG("result is null");
return RMW_RET_ERROR;
}
RMW_CHECK_ARGUMENT_FOR_NULL(gid1, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
gid1,
gid1->implementation_identifier,
identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_CHECK_ARGUMENT_FOR_NULL(gid2, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
gid2,
gid2->implementation_identifier,
identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_CHECK_ARGUMENT_FOR_NULL(result, RMW_RET_INVALID_ARGUMENT);

*result =
memcmp(gid1->data, gid2->data, sizeof(eprosima::fastrtps::rtps::GUID_t)) == 0;
Expand Down
28 changes: 8 additions & 20 deletions rmw_fastrtps_shared_cpp/src/rmw_get_gid_for_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "rmw/error_handling.h"
#include "rmw/impl/cpp/macros.hpp"
#include "rmw/rmw.h"
#include "rmw/types.h"

Expand All @@ -27,28 +28,15 @@ __rmw_get_gid_for_publisher(
const rmw_publisher_t * publisher,
rmw_gid_t * gid)
{
if (!publisher) {
RMW_SET_ERROR_MSG("publisher is null");
return RMW_RET_ERROR;
}

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

if (!gid) {
RMW_SET_ERROR_MSG("gid is null");
return RMW_RET_ERROR;
}
RMW_CHECK_ARGUMENT_FOR_NULL(publisher, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
publisher,
publisher->implementation_identifier,
identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_CHECK_ARGUMENT_FOR_NULL(gid, RMW_RET_INVALID_ARGUMENT);

auto info = static_cast<const CustomPublisherInfo *>(publisher->data);

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

*gid = info->publisher_gid;
return RMW_RET_OK;
}
Expand Down

0 comments on commit a2e3bfb

Please sign in to comment.