Skip to content

Commit

Permalink
Merge pull request #389 from gazebosim/11-to-12-20230309
Browse files Browse the repository at this point in the history
Forward port 11 to 12
  • Loading branch information
nkoenig authored Mar 9, 2023
2 parents ec25fe9 + 2e3cec0 commit c31134a
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 16 deletions.
35 changes: 33 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,33 @@

## Gazebo Transport 11.X

### Gazebo Transport 11.4.0 (2023-03-08)

1. Added Node::RequestRaw
* [Pull request #351](https://github.com/gazebosim/gz-transport/pull/351)

1. Suppress some Windows warnings.
* [Pull request #367](https://github.com/gazebosim/gz-transport/pull/367)

1. All changes up to version 8.2.0.

### Gazebo Transport 11.3.2 (2022-12-08)

1. Fix include/ignition/.../parameters header files
* [Pull request #374](https://github.com/gazebosim/gz-transport/pull/374)

### Gazebo Transport 11.3.1 (2022-12-01)

1. Fix CLI configuration install path to ignition
* [Pull request #372](https://github.com/gazebosim/gz-transport/pull/372)

### Gazebo Transport 11.3.0 (2022-10-31)

1. Add parameters component
* [Pull request #305](https://github.com/gazebosim/ign-transport/pull/305)
* [Pull request #305](https://github.com/gazebosim/gz-transport/pull/305)

1. Fix build for Debian Bullseye
* [Pull request #363](https://github.com/gazebosim/ign-transport/pull/363)
* [Pull request #363](https://github.com/gazebosim/gz-transport/pull/363)

### Gazebo Transport 11.2.0 (2022-08-16)

Expand Down Expand Up @@ -339,6 +359,17 @@
and publication, age, and reception statistics.
* [Pull request 205](https://github.com/gazebosim/gz-transport/pull/205)

### Gazebo Transport 8.4.0 (2022-11-17)

1. ign -> gz : Remove redundant namespace references.
* [Pull request #345](https://github.com/gazebosim/gz-transport/pull/345)

1. Backport Windows fix from main branch.
* [Pull request #350](https://github.com/gazebosim/gz-transport/pull/350)

1. ign -> gz Migrate Ignition Headers : gz-transport.
* [Pull request #347](https://github.com/gazebosim/gz-transport/pull/347)

### Gazebo Transport 8.3.0 (2022-07-27)

1. Ignition -> Gazebo
Expand Down
6 changes: 6 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ if (EXISTS "${CMAKE_SOURCE_DIR}/requester_oneway.cc")
gz-transport${GZ_TRANSPORT_VER}::core)
endif()

if (EXISTS "${CMAKE_SOURCE_DIR}/requester_raw.cc")
add_executable(requester_raw requester_raw.cc)
target_link_libraries(requester_raw
gz-transport${GZ_TRANSPORT_VER}::core)
endif()

if (EXISTS "${CMAKE_SOURCE_DIR}/responser_no_input.cc")
add_executable(responser_no_input responser_no_input.cc)
target_link_libraries(responser_no_input
Expand Down
55 changes: 55 additions & 0 deletions example/requester_raw.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* 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.
*
*/

#include <iostream>
#include <gz/msgs.hh>
#include <gz/transport.hh>

//////////////////////////////////////////////////
int main(int argc, char **argv)
{
// Create a transport node.
gz::transport::Node node;

// Prepare the input parameters.
gz::msgs::StringMsg req;
req.set_data("HELLO");

bool result;
unsigned int timeout = 5000;

std::string reqStr, repStr;
req.SerializeToString(&reqStr);

// Request the "/echo" service.
bool executed = node.RequestRaw("/echo", reqStr, "gz.msgs.StringMsg",
"gz.msgs.StringMsg", timeout, repStr, result);

if (executed)
{
if (result)
{
gz::msgs::StringMsg rep;
rep.ParseFromString(repStr);
std::cout << "Response: [" << rep.data() << "]" << std::endl;
}
else
std::cout << "Service call failed" << std::endl;
}
else
std::cerr << "Service call timed out" << std::endl;
}
24 changes: 22 additions & 2 deletions include/gz/transport/Node.hh
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ namespace gz
public: template<typename MessageT>
bool Subscribe(
const std::string &_topic,
std::function<void(const MessageT &_msg)> &_callback,
std::function<void(const MessageT &_msg)> _callback,
const SubscribeOptions &_opts = SubscribeOptions());

/// \brief Subscribe to a topic registering a callback.
Expand Down Expand Up @@ -313,7 +313,7 @@ namespace gz
bool Subscribe(
const std::string &_topic,
std::function<void(const MessageT &_msg,
const MessageInfo &_info)> &_callback,
const MessageInfo &_info)> _callback,
const SubscribeOptions &_opts = SubscribeOptions());

/// \brief Subscribe to a topic registering a callback.
Expand Down Expand Up @@ -653,6 +653,26 @@ namespace gz
public: template<typename RequestT>
bool Request(const std::string &_topic, const RequestT &_request);

/// \brief Request a new service using a blocking call. This request
/// function expects a serialized protobuf message as the request and
/// returns a serialized protobuf message as the response.
/// \param[in] _topic Service name requested.
/// \param[in] _request Protobuf message serialized into a string
/// containing the request's parameters.
/// \param[in] _requestType Message type of the request.
/// \param[in] _responseType Message type of the response.
/// \param[in] _timeout The request will timeout after '_timeout' ms.
/// \param[out] _response Serialized protobuf message containing the
/// response.
/// \param[out] _result Result of the service call.
/// \return true when the request was executed or false if the timeout
/// expired.
public: bool RequestRaw(const std::string &_topic,
const std::string &_request, const std::string &_requestType,
const std::string &_responseType, unsigned int _timeout,
std::string &_response,
bool &_result);

/// \brief Unadvertise a service.
/// \param[in] _topic Service name to be unadvertised.
/// \return true if the service was successfully unadvertised.
Expand Down
11 changes: 6 additions & 5 deletions include/gz/transport/detail/Node.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <memory>
#include <string>
#include <utility>

namespace gz
{
Expand Down Expand Up @@ -57,14 +58,14 @@ namespace gz
template<typename MessageT>
bool Node::Subscribe(
const std::string &_topic,
std::function<void(const MessageT &_msg)> &_cb,
std::function<void(const MessageT &_msg)> _cb,
const SubscribeOptions &_opts)
{
std::function<void(const MessageT &, const MessageInfo &)> f =
[_cb](const MessageT & _internalMsg,
[cb = std::move(_cb)](const MessageT & _internalMsg,
const MessageInfo &/*_internalInfo*/)
{
_cb(_internalMsg);
cb(_internalMsg);
};

return this->Subscribe<MessageT>(_topic, f, _opts);
Expand Down Expand Up @@ -111,7 +112,7 @@ namespace gz
bool Node::Subscribe(
const std::string &_topic,
std::function<void(const MessageT &_msg,
const MessageInfo &_info)> &_cb,
const MessageInfo &_info)> _cb,
const SubscribeOptions &_opts)
{
// Topic remapping.
Expand All @@ -131,7 +132,7 @@ namespace gz
new SubscriptionHandler<MessageT>(this->NodeUuid(), _opts));

// Insert the callback into the handler.
subscrHandlerPtr->SetCallback(_cb);
subscrHandlerPtr->SetCallback(std::move(_cb));

std::lock_guard<std::recursive_mutex> lk(this->Shared()->mutex);

Expand Down
7 changes: 7 additions & 0 deletions log/test/integration/ChirpParams.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
#ifndef GZ_TRANSPORT_LOG_TEST_INTEGRATION_CHIRPPARAMS_HH_
#define GZ_TRANSPORT_LOG_TEST_INTEGRATION_CHIRPPARAMS_HH_

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
#include <gz/msgs/int32.pb.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include <test_config.hh>

#include <string>
Expand Down
12 changes: 10 additions & 2 deletions parameters/include/gz/transport/parameters/Client.hh
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,19 @@ namespace gz
public: gz::msgs::ParameterDeclarations
ListParameters() const final;

private:
#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
/// \brief Pointer to implementation.
private: std::unique_ptr<ParametersClientPrivate> dataPtr;
#ifdef _WIN32
#pragma warning(pop)
#endif

constexpr static inline unsigned int kDefaultTimeoutMs = 5000;
private: constexpr static inline unsigned int kDefaultTimeoutMs = 5000;
};
}
}
Expand Down
9 changes: 9 additions & 0 deletions parameters/include/gz/transport/parameters/Registry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,17 @@ namespace gz
const std::string & _parameterName,
std::unique_ptr<google::protobuf::Message> _value);

#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
/// \brief Pointer to implementation.
private: std::unique_ptr<ParametersRegistryPrivate> dataPtr;
#ifdef _WIN32
#pragma warning(pop)
#endif
};
}
}
Expand Down
7 changes: 7 additions & 0 deletions parameters/src/Utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@
#include "gz/transport/config.hh"
#include "gz/transport/parameters/Export.hh"

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4251) // Missing dll-interface
#endif // defined(_MSC_VER)
#include <google/protobuf/any.pb.h>
#if defined(_MSC_VER)
#pragma warning(pop)
#endif // defined(_MSC_VER)

namespace gz
{
Expand Down
28 changes: 28 additions & 0 deletions src/Node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1080,3 +1080,31 @@ bool NodePrivate::RemoveHandlersFromPubQueue(const std::string &_topic)
}
return true;
}

/////////////////////////////////////////////////
bool Node::RequestRaw(const std::string &_topic,
const std::string &_request, const std::string &_requestType,
const std::string &_responseType, unsigned int _timeout,
std::string &_response, bool &_result)
{
std::unique_ptr<google::protobuf::Message> req =
msgs::Factory::New(_requestType);
if (!req)
{
std::cerr << "Unable to create request of type[" << _requestType << "].\n";
return false;
}
req->ParseFromString(_request);

std::unique_ptr<google::protobuf::Message> res =
msgs::Factory::New(_responseType);
if (!res)
{
std::cerr << "Unable to create response of type["
<< _responseType << "].\n";
return false;
}

bool executed = this->Request(_topic, *req, _timeout, *res, _result);
return executed && res->SerializeToString(&_response);
}
12 changes: 12 additions & 0 deletions src/Node_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,18 @@ class MyTestClass

this->Reset();

// Request a valid service using RequestRaw.
std::string reqStr, repStr, repTypeName;
req.SerializeToString(&reqStr);
EXPECT_TRUE(this->node.RequestRaw(g_topic, reqStr, req.GetTypeName(),
rep.GetTypeName(), timeout, repStr, result));
rep.ParseFromString(repStr);
ASSERT_TRUE(result);
EXPECT_EQ(rep.data(), data);
EXPECT_TRUE(this->callbackSrvExecuted);

this->Reset();

// Service requests with wrong types.
EXPECT_FALSE(this->node.Request(g_topic, wrongReq, timeout, rep, result));
EXPECT_FALSE(this->node.Request(g_topic, req, timeout, wrongRep, result));
Expand Down
9 changes: 8 additions & 1 deletion src/cmd/gz_src_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@
* limitations under the License.
*
*/
#include <gz/msgs/int32.pb.h>

#include <future>
#include <string>
#include <iostream>
#include <sstream>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
#include <gz/msgs/int32.pb.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

#include "gtest/gtest.h"
#include "gz.hh"
Expand Down
9 changes: 8 additions & 1 deletion test/integration/authPubSub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@
* limitations under the License.
*
*/
#include <gz/msgs/int32.pb.h>

#include <chrono>
#include <string>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
#include <gz/msgs/int32.pb.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

#include "gtest/gtest.h"
#include "gz/transport/Node.hh"
Expand Down
12 changes: 11 additions & 1 deletion test/integration/authPubSubSubscriberInvalid_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@
* limitations under the License.
*
*/
#include <gz/msgs/int32.pb.h>

#include <chrono>
#include <string>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
#include <gz/msgs/int32.pb.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#ifdef _WIN32
#include <filesystem>
#endif

#include "gz/transport/Node.hh"
#include "gtest/gtest.h"
Expand Down
Loading

0 comments on commit c31134a

Please sign in to comment.