Skip to content

Commit

Permalink
Merge pull request #342 from ithier/iox-240-integration-test-for-posh…
Browse files Browse the repository at this point in the history
…runtime

iox-#240 addedintegration test for posh runtime
  • Loading branch information
dkroenke authored Jan 6, 2021
2 parents 7a63513 + 5181fec commit 81144e9
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ class ServiceDescription
/// @brief Returns the scope of a ServiceDescription
Scope getScope() noexcept;

///@brief Returns true for valid ServiceDescription
/// false for ServiceDescription that contains either of InvalidID/InvalidIDString AnyService/AnyServiceString,
/// AnyInstance/AnyInstanceString, AnyEvent/AnyEventString.
bool isValid() const noexcept;

///@{
/// Getters for the integer and string IDs
uint16_t getInstanceID() const noexcept;
Expand Down
11 changes: 6 additions & 5 deletions iceoryx_posh/include/iceoryx_posh/runtime/posh_runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ class PoshRuntime

/// @brief find all services that match the provided service description
/// @param[in] serviceDescription service to search for
/// @param[out] instanceContainer container that is filled with all matching instances
/// @return cxx::expected<Error> Error, if any, encountered during the operation
/// @return cxx::expected<InstanceContainer,Error>
/// InstanceContainer: on success, container that is filled with all matching instances
/// Error: if any, encountered during the operation
/// Error::kPOSH__SERVICE_DISCOVERY_INSTANCE_CONTAINER_OVERFLOW : Number of instances can't fit in instanceContainer
/// Error::kMQ_INTERFACE__REG_UNABLE_TO_WRITE_TO_ROUDI_MQ : Find Service Request could not be sent to RouDi
cxx::expected<Error> findService(const capro::ServiceDescription& serviceDescription,
InstanceContainer& instanceContainer) noexcept;
cxx::expected<InstanceContainer, Error> findService(const capro::ServiceDescription& serviceDescription) noexcept;

/// @brief offer the provided service, sends the offer from application to RouDi daemon
/// @param[in] serviceDescription service to offer
void offerService(const capro::ServiceDescription& serviceDescription) noexcept;
/// @return bool, if service is offered returns true else false
bool offerService(const capro::ServiceDescription& serviceDescription) noexcept;

/// @brief stop offering the provided service
/// @param[in] serviceDescription of the service that shall be no more offered
Expand Down
15 changes: 15 additions & 0 deletions iceoryx_posh/source/capro/service_description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,21 @@ Interfaces ServiceDescription::getSourceInterface() const noexcept
return m_interfaceSource;
}

bool ServiceDescription::isValid() const noexcept
{
if (m_hasServiceOnlyDescription)
{
return !(m_serviceString == iox::capro::InvalidIDString || m_serviceID == iox::capro::AnyService
|| m_instanceString == iox::capro::InvalidIDString || m_instanceID == iox::capro::AnyInstance);
}
else
{
return !(m_serviceString == iox::capro::InvalidIDString || m_serviceID == iox::capro::AnyService
|| m_instanceString == iox::capro::InvalidIDString || m_instanceID == iox::capro::AnyInstance
|| m_eventString == iox::capro::InvalidIDString || m_eventID == iox::capro::AnyEvent);
}
}

bool serviceMatch(const ServiceDescription& first, const ServiceDescription& second) noexcept
{
return (first.getServiceID() == second.getServiceID());
Expand Down
22 changes: 16 additions & 6 deletions iceoryx_posh/source/runtime/posh_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ NodeData* PoshRuntime::createNode(const NodeProperty& nodeProperty) noexcept
return nullptr;
}

cxx::expected<Error> PoshRuntime::findService(const capro::ServiceDescription& serviceDescription,
InstanceContainer& instanceContainer) noexcept
cxx::expected<InstanceContainer, Error>
PoshRuntime::findService(const capro::ServiceDescription& serviceDescription) noexcept
{
MqMessage sendBuffer;
sendBuffer << mqMessageTypeToString(MqMessageType::FIND_SERVICE) << m_appName
Expand All @@ -399,6 +399,7 @@ cxx::expected<Error> PoshRuntime::findService(const capro::ServiceDescription& s
return cxx::error<Error>(Error::kMQ_INTERFACE__REG_UNABLE_TO_WRITE_TO_ROUDI_MQ);
}

InstanceContainer instanceContainer;
uint32_t numberOfElements = requestResponse.getNumberOfElements();
uint32_t capacity = static_cast<uint32_t>(instanceContainer.capacity());

Expand All @@ -417,13 +418,22 @@ cxx::expected<Error> PoshRuntime::findService(const capro::ServiceDescription& s
errorHandler(Error::kPOSH__SERVICE_DISCOVERY_INSTANCE_CONTAINER_OVERFLOW, nullptr, ErrorLevel::MODERATE);
return cxx::error<Error>(Error::kPOSH__SERVICE_DISCOVERY_INSTANCE_CONTAINER_OVERFLOW);
}
return {cxx::success<>()};
return {cxx::success<InstanceContainer>(instanceContainer)};
}

void PoshRuntime::offerService(const capro::ServiceDescription& serviceDescription) noexcept

bool PoshRuntime::offerService(const capro::ServiceDescription& serviceDescription) noexcept
{
capro::CaproMessage msg(capro::CaproMessageType::OFFER, serviceDescription, capro::CaproMessageSubType::SERVICE);
m_applicationPort.dispatchCaProMessage(msg);
if (serviceDescription.isValid())
{
capro::CaproMessage msg(
capro::CaproMessageType::OFFER, serviceDescription, capro::CaproMessageSubType::SERVICE);
m_applicationPort.dispatchCaProMessage(msg);
return true;
}
LogWarn() << "Could not offer service " << serviceDescription.getServiceIDString() << ","
<< " ServiceDescription is invalid\n";
return false;
}

void PoshRuntime::stopOfferService(const capro::ServiceDescription& serviceDescription) noexcept
Expand Down
Loading

0 comments on commit 81144e9

Please sign in to comment.