text: // Copyright 2015 Twin Oaks Computing, Inc.
  // Modifications copyright (C) 2017-2018 Twin Oaks Computing, 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.
  
  #ifdef CoreDX_GLIBCXX_USE_CXX11_ABI_ZERO
  #define _GLIBCXX_USE_CXX11_ABI 0
  #endif
  
  #include <rmw/rmw.h>
  #include <rmw/types.h>
  #include <rmw/allocators.h>
  #include <rmw/error_handling.h>
  #include <rmw/impl/cpp/macros.hpp>
  
  #include <dds/dds.hh>
  #include <dds/dds_builtinDataReader.hh>
  
  #include "rmw_coredx_cpp/identifier.hpp"
  #include "rmw_coredx_types.hpp"
  #include "util.hpp"
  
  /* ************************************************
   */
  static rmw_ret_t
  _take( const rmw_subscription_t * subscription,
         void                     * ros_message,
         bool                     * taken,
         DDS::InstanceHandle_t    * sending_publication_handle )
  {
    if (!subscription) {
      RMW_SET_ERROR_MSG("subscription handle is null");
      return RMW_RET_ERROR;
    }
    RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
      subscription handle,
      subscription->implementation_identifier, toc_coredx_identifier,
      return RMW_RET_ERROR)
  
    if (!ros_message) {
      RMW_SET_ERROR_MSG("ros message handle is null");
      return RMW_RET_ERROR;
    }
    if (!taken) {
      RMW_SET_ERROR_MSG("taken handle is null");
      return RMW_RET_ERROR;
    }
  
    CoreDXStaticSubscriberInfo * subscriber_info =
      static_cast<CoreDXStaticSubscriberInfo *>(subscription->data);
    if (!subscriber_info) {
      RMW_SET_ERROR_MSG("subscriber info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::DataReader * topic_reader = subscriber_info->topic_reader_;
    if (!topic_reader) {
      RMW_SET_ERROR_MSG("topic reader handle is null");
      return RMW_RET_ERROR;
    }
    const message_type_support_callbacks_t * callbacks = subscriber_info->callbacks_;
    if (!callbacks) {
      RMW_SET_ERROR_MSG("callbacks handle is null");
      return RMW_RET_ERROR;
    }
  
    bool success = callbacks->take(
      topic_reader, subscriber_info->ignore_local_publications, ros_message, taken,
      sending_publication_handle);
  
    return success ? RMW_RET_OK : RMW_RET_ERROR;
  }
  