From a2e3bfb69cec8b20f0d685614e006d3149703a71 Mon Sep 17 00:00:00 2001
From: Michel Hidalgo <michel@ekumenlabs.com>
Date: Tue, 22 Sep 2020 18:20:25 -0300
Subject: [PATCH] Update gid API return codes. (#440)

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
---
 .../src/rmw_compare_gids_equal.cpp            | 40 +++++++------------
 .../src/rmw_get_gid_for_publisher.cpp         | 28 ++++---------
 2 files changed, 23 insertions(+), 45 deletions(-)

diff --git a/rmw_fastrtps_shared_cpp/src/rmw_compare_gids_equal.cpp b/rmw_fastrtps_shared_cpp/src/rmw_compare_gids_equal.cpp
index 83886c621..d395bfa0f 100644
--- a/rmw_fastrtps_shared_cpp/src/rmw_compare_gids_equal.cpp
+++ b/rmw_fastrtps_shared_cpp/src/rmw_compare_gids_equal.cpp
@@ -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"
@@ -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;
diff --git a/rmw_fastrtps_shared_cpp/src/rmw_get_gid_for_publisher.cpp b/rmw_fastrtps_shared_cpp/src/rmw_get_gid_for_publisher.cpp
index 2164dd56d..83cd1f19d 100644
--- a/rmw_fastrtps_shared_cpp/src/rmw_get_gid_for_publisher.cpp
+++ b/rmw_fastrtps_shared_cpp/src/rmw_get_gid_for_publisher.cpp
@@ -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"
 
@@ -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;
 }