Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another idea to implement RPC based in more specific interfaces #50

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions ddspipe_core/include/ddspipe_core/interface/IClient.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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.

#pragma once

#include <cpp_utils/ReturnCode.hpp>

#include <ddspipe_core/interface/IRoutingData.hpp>

namespace eprosima {
namespace ddspipe {
namespace core {

/**
* Interface that represents a generic Writer as part of a DdsPipe.
*
* This class manages the sending of data to remote endpoints in a specific topic.
*
* @note In order to implement new Writers, create a subclass of this Interface and implement every method.
* @note Also it is needed to add the creation of the Writer in the Participant required.
*
* Writers will start being disabled.
*/
class IClient
{
public:

/**
* @brief Virtual dtor to allow inheritance.
*/
DDSPIPE_CORE_DllAPI
virtual ~IClient() = default;

/**
* @brief Enable Writer
*
* A Writer enabled can send messages.
*
* By default the Writer is disabled. Call this method to activate it.
*/
DDSPIPE_CORE_DllAPI
virtual void enable() noexcept = 0;

/**
* @brief Disable Writer
*
* A Writer disabled does not send data.
* @note Method \c write should never be called from a disabled writer
*/
DDSPIPE_CORE_DllAPI
virtual void disable() noexcept = 0;

DDSPIPE_CORE_DllAPI
virtual utils::ReturnCode send_request(
IRoutingData& data) noexcept = 0;

DDSPIPE_CORE_DllAPI
virtual void set_on_reply_callback(
std::function<void()> on_reply_lambda) noexcept = 0;

DDSPIPE_CORE_DllAPI
virtual void unset_on_reply_callback() noexcept = 0;

DDSPIPE_CORE_DllAPI
virtual utils::ReturnCode take(
std::unique_ptr<IRoutingData>& data) noexcept = 0;
};

} /* namespace core */
} /* namespace ddspipe */
} /* namespace eprosima */
15 changes: 10 additions & 5 deletions ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#include <ddspipe_core/interface/IReader.hpp>
#include <ddspipe_core/interface/IWriter.hpp>
#include <ddspipe_core/types/participant/ParticipantId.hpp>
#include <ddspipe_core/types/topic/Topic.hpp>
#include <ddspipe_core/interface/ITopic.hpp>
#include <ddspipe_core/interface/IRpcTopic.hpp>

namespace eprosima {
namespace ddspipe {
Expand Down Expand Up @@ -51,10 +52,6 @@ class IParticipant
DDSPIPE_CORE_DllAPI
virtual types::ParticipantId id() const noexcept = 0;

//! Whether this participant is RTPS
DDSPIPE_CORE_DllAPI
virtual bool is_rtps_kind() const noexcept = 0;

/**
* @brief Whether this Participant requires to connect ist own readers with its own writers.
*/
Expand Down Expand Up @@ -92,6 +89,14 @@ class IParticipant
DDSPIPE_CORE_DllAPI
virtual std::shared_ptr<IReader> create_reader(
const ITopic& topic) = 0;

DDSPIPE_CORE_DllAPI
virtual std::shared_ptr<IClient> create_client(
const IRpcTopic& topic) = 0;

DDSPIPE_CORE_DllAPI
virtual std::shared_ptr<IServer> create_server(
const IRpcTopic& topic) = 0;
};

} /* namespace core */
Expand Down
23 changes: 0 additions & 23 deletions ddspipe_core/include/ddspipe_core/interface/IReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,29 +110,6 @@ class IReader
virtual utils::ReturnCode take(
std::unique_ptr<IRoutingData>& data) noexcept = 0;

/////////////////////////
// RPC REQUIRED METHODS
/////////////////////////
// TODO remove these methods once the double reference is solved

//! Get GUID of internal RTPS reader
DDSPIPE_CORE_DllAPI
virtual core::types::Guid guid() const = 0;

//! Get internal RTPS reader mutex
DDSPIPE_CORE_DllAPI
virtual fastrtps::RecursiveTimedMutex& get_rtps_mutex() const = 0;

//! Get number of unread cache changes in internal RTPS reader
DDSPIPE_CORE_DllAPI
virtual uint64_t get_unread_count() const = 0;

DDSPIPE_CORE_DllAPI
virtual types::DdsTopic topic() const = 0;

DDSPIPE_CORE_DllAPI
virtual types::ParticipantId participant_id() const = 0;
/////////////////////////
};

} /* namespace core */
Expand Down
36 changes: 36 additions & 0 deletions ddspipe_core/include/ddspipe_core/interface/IRpcTopic.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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\.

#pragma once

#include <iostream>
#include <string>

#include <ddspipe_core/library/library_dll.h>
#include <ddspipe_core/interface/ITopic.hpp>

namespace eprosima {
namespace ddspipe {
namespace core {

/**
* Generic data struct that represents an ITopic of data flow in the Router.
*/
class IRpcTopic : public ITopic
{
};

} /* namespace core */
} /* namespace ddspipe */
} /* namespace eprosima */
82 changes: 82 additions & 0 deletions ddspipe_core/include/ddspipe_core/interface/IServer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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.

#pragma once

#include <cpp_utils/ReturnCode.hpp>

#include <ddspipe_core/interface/IRoutingData.hpp>

namespace eprosima {
namespace ddspipe {
namespace core {

/**
* Interface that represents a generic Writer as part of a DdsPipe.
*
* This class manages the sending of data to remote endpoints in a specific topic.
*
* @note In order to implement new Writers, create a subclass of this Interface and implement every method.
* @note Also it is needed to add the creation of the Writer in the Participant required.
*
* Writers will start being disabled.
*/
class IServer
{
public:

/**
* @brief Virtual dtor to allow inheritance.
*/
DDSPIPE_CORE_DllAPI
virtual ~IServer() = default;

/**
* @brief Enable Writer
*
* A Writer enabled can send messages.
*
* By default the Writer is disabled. Call this method to activate it.
*/
DDSPIPE_CORE_DllAPI
virtual void enable() noexcept = 0;

/**
* @brief Disable Writer
*
* A Writer disabled does not send data.
* @note Method \c write should never be called from a disabled writer
*/
DDSPIPE_CORE_DllAPI
virtual void disable() noexcept = 0;

DDSPIPE_CORE_DllAPI
virtual utils::ReturnCode send_reply(
IRoutingData& data) noexcept = 0;

DDSPIPE_CORE_DllAPI
virtual void set_on_request_callback(
std::function<void()> on_request_lambda) noexcept = 0;

DDSPIPE_CORE_DllAPI
virtual void unset_on_request_callback() noexcept = 0;

DDSPIPE_CORE_DllAPI
virtual utils::ReturnCode take(
std::unique_ptr<IRoutingData>& data) noexcept = 0;
};

} /* namespace core */
} /* namespace ddspipe */
} /* namespace eprosima */