Skip to content
Open
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
2 changes: 1 addition & 1 deletion Demos/api/Orchestration/SimStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using namespace std::chrono_literals;

std::ostream& operator<<(std::ostream& out, std::chrono::nanoseconds timestamp)
static std::ostream& operator<<(std::ostream& out, std::chrono::nanoseconds timestamp)
{
out << std::chrono::duration_cast<std::chrono::milliseconds>(timestamp).count() << "ms";
return out;
Expand Down
2 changes: 1 addition & 1 deletion Demos/api/Orchestration/SimStepAsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

using namespace std::chrono_literals;

std::ostream& operator<<(std::ostream& out, std::chrono::nanoseconds timestamp)
static std::ostream& operator<<(std::ostream& out, std::chrono::nanoseconds timestamp)
{
out << std::chrono::duration_cast<std::chrono::milliseconds>(timestamp).count() << "ms";
return out;
Expand Down
6 changes: 4 additions & 2 deletions Demos/communication/Can/CanDemoCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: MIT

#pragma once

#include "silkit/services/can/all.hpp"
#include "silkit/services/can/string_utils.hpp"
#include "silkit/services/logging/ILogger.hpp"
Expand All @@ -11,15 +13,15 @@ using namespace SilKit::Services::Can;
// This is the common behavior used in CanReaderDemo and CanWriterDemo
namespace CanDemoCommon {

void FrameTransmitHandler(const CanFrameTransmitEvent& canFrameAck, ILogger* logger)
inline void FrameTransmitHandler(const CanFrameTransmitEvent& canFrameAck, ILogger* logger)
{
std::stringstream ss;
ss << "Receive CAN frame transmit acknowledge: canId=" << canFrameAck.canId << ", status='" << canFrameAck.status
<< "'";
logger->Info(ss.str());
}

void FrameHandler(const CanFrameEvent& canFrameEvent, ILogger* logger, bool printHex)
inline void FrameHandler(const CanFrameEvent& canFrameEvent, ILogger* logger, bool printHex)
{
std::string frameTypeHint = "";
if ((canFrameEvent.frame.flags & static_cast<CanFrameFlagMask>(CanFrameFlag::Fdf)) != 0)
Expand Down
8 changes: 5 additions & 3 deletions Demos/communication/Ethernet/EthernetDemoCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: MIT

#pragma once

#include "silkit/services/ethernet/all.hpp"
#include "silkit/services/ethernet/string_utils.hpp"
#include "silkit/services/logging/ILogger.hpp"
Expand All @@ -14,7 +16,7 @@ namespace EthernetDemoCommon {
using EtherType = uint16_t;
using EthernetMac = std::array<uint8_t, 6>;

void FrameTransmitHandler(const EthernetFrameTransmitEvent& frameTransmitEvent, ILogger* logger)
inline void FrameTransmitHandler(const EthernetFrameTransmitEvent& frameTransmitEvent, ILogger* logger)
{
std::stringstream ss;
if (frameTransmitEvent.status == EthernetTransmitStatus::Transmitted)
Expand Down Expand Up @@ -45,7 +47,7 @@ void FrameTransmitHandler(const EthernetFrameTransmitEvent& frameTransmitEvent,
logger->Info(ss.str());
}

auto PrintPayload(const std::vector<uint8_t>& payload, bool printHex)
inline auto PrintPayload(const std::vector<uint8_t>& payload, bool printHex)
{
std::stringstream ss;
if (printHex)
Expand All @@ -59,7 +61,7 @@ auto PrintPayload(const std::vector<uint8_t>& payload, bool printHex)
return ss.str();
}

void FrameHandler(const EthernetFrameEvent& ethernetFrameEvent, ILogger* logger, bool printHex)
inline void FrameHandler(const EthernetFrameEvent& ethernetFrameEvent, ILogger* logger, bool printHex)
{
const size_t FrameHeaderSize = 2 * sizeof(EthernetMac) + sizeof(EtherType);
std::vector<uint8_t> payloadWithoutHeader;
Expand Down
23 changes: 16 additions & 7 deletions Demos/communication/PubSub/PubSubDemoCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: MIT

#pragma once

#include "silkit/services/pubsub/all.hpp"
#include "silkit/services/pubsub/string_utils.hpp"
#include "silkit/services/logging/ILogger.hpp"
Expand All @@ -12,9 +14,15 @@ using namespace SilKit::Services::PubSub;
// This are the common data structures used in PublisherDemo and SubscriberDemo
namespace PubSubDemoCommon {

const std::string mediaType{SilKit::Util::SerDes::MediaTypeData()};
PubSubSpec dataSpecGps{"Gps", mediaType};
PubSubSpec dataSpecTemperature{"Temperature", mediaType};
inline PubSubSpec MakeGpsSpec()
{
return {"Gps", SilKit::Util::SerDes::MediaTypeData()};
}

inline PubSubSpec MakeTemperatureSpec()
{
return {"Temperature", SilKit::Util::SerDes::MediaTypeData()};
}

// ----------------------------------------------------------------
// Data structure, serialization and deserialization for GPS Data
Expand All @@ -26,7 +34,8 @@ struct GpsData
double longitude;
std::string signalQuality;
};
std::vector<uint8_t> SerializeGPSData(const PubSubDemoCommon::GpsData& gpsData)

inline std::vector<uint8_t> SerializeGPSData(const PubSubDemoCommon::GpsData& gpsData)
{
SilKit::Util::SerDes::Serializer serializer;
serializer.BeginStruct();
Expand All @@ -38,7 +47,7 @@ std::vector<uint8_t> SerializeGPSData(const PubSubDemoCommon::GpsData& gpsData)
return serializer.ReleaseBuffer();
}

PubSubDemoCommon::GpsData DeserializeGPSData(const std::vector<uint8_t>& eventData)
inline PubSubDemoCommon::GpsData DeserializeGPSData(const std::vector<uint8_t>& eventData)
{
PubSubDemoCommon::GpsData gpsData;

Expand All @@ -56,15 +65,15 @@ PubSubDemoCommon::GpsData DeserializeGPSData(const std::vector<uint8_t>& eventDa
// Serialization and deserialization for a double (temperature)
// -----------------------------------------------------------------

std::vector<uint8_t> SerializeTemperature(double temperature)
inline std::vector<uint8_t> SerializeTemperature(double temperature)
{
SilKit::Util::SerDes::Serializer temperatureSerializer;
temperatureSerializer.Serialize(temperature);

return temperatureSerializer.ReleaseBuffer();
}

double DeserializeTemperature(const std::vector<uint8_t>& eventData)
inline double DeserializeTemperature(const std::vector<uint8_t>& eventData)
{
double temperature;

Expand Down
4 changes: 2 additions & 2 deletions Demos/communication/PubSub/PublisherDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class Publisher : public ApplicationBase

void CreateControllers() override
{
_gpsPublisher = GetParticipant()->CreateDataPublisher("GpsPublisher", PubSubDemoCommon::dataSpecGps, 0);
_gpsPublisher = GetParticipant()->CreateDataPublisher("GpsPublisher", PubSubDemoCommon::MakeGpsSpec(), 0);
_temperaturePublisher =
GetParticipant()->CreateDataPublisher("TemperaturePublisher", PubSubDemoCommon::dataSpecTemperature, 0);
GetParticipant()->CreateDataPublisher("TemperaturePublisher", PubSubDemoCommon::MakeTemperatureSpec(), 0);
}

void InitControllers() override {}
Expand Down
4 changes: 2 additions & 2 deletions Demos/communication/PubSub/SubscriberDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Subscriber : public ApplicationBase
void CreateControllers() override
{
_gpsSubscriber = GetParticipant()->CreateDataSubscriber(
"GpsSubscriber", PubSubDemoCommon::dataSpecGps,
"GpsSubscriber", PubSubDemoCommon::MakeGpsSpec(),
[this](IDataSubscriber* /*subscriber*/, const DataMessageEvent& dataMessageEvent) {
auto gpsData = PubSubDemoCommon::DeserializeGPSData(SilKit::Util::ToStdVector(dataMessageEvent.data));

Expand All @@ -33,7 +33,7 @@ class Subscriber : public ApplicationBase
});

_temperatureSubscriber = GetParticipant()->CreateDataSubscriber(
"TemperatureSubscriber", PubSubDemoCommon::dataSpecTemperature,
"TemperatureSubscriber", PubSubDemoCommon::MakeTemperatureSpec(),
[this](IDataSubscriber* /*subscriber*/, const DataMessageEvent& dataMessageEvent) {
double temperature =
PubSubDemoCommon::DeserializeTemperature(SilKit::Util::ToStdVector(dataMessageEvent.data));
Expand Down
4 changes: 2 additions & 2 deletions Demos/communication/Rpc/RpcClientDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class RpcClient : public ApplicationBase
void CreateControllers() override
{
_rpcClientSignalStrength = GetParticipant()->CreateRpcClient(
"ClientSignalStrength", RpcDemoCommon::rpcSpecSignalStrength,
"ClientSignalStrength", RpcDemoCommon::MakeSignalStrengthSpec(),
[this](IRpcClient* /*client*/, RpcCallResultEvent event) { CallReturnGetSignalStrength(event); });

_rpcClientSort = GetParticipant()->CreateRpcClient(
"ClientSort", RpcDemoCommon::rpcSpecSort,
"ClientSort", RpcDemoCommon::MakeSortSpec(),
[this](IRpcClient* /*client*/, RpcCallResultEvent event) { CallReturnSort(event); });
}

Expand Down
32 changes: 20 additions & 12 deletions Demos/communication/Rpc/RpcDemoCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
//
// SPDX-License-Identifier: MIT

#pragma once

#include "silkit/services/rpc/all.hpp"
#include "silkit/services/rpc/string_utils.hpp"
#include "silkit/services/logging/ILogger.hpp"
#include "silkit/util/serdes/Serialization.hpp"

using namespace SilKit::Services::Rpc;

static std::ostream& operator<<(std::ostream& os, const SilKit::Util::Span<const uint8_t>& v)
inline std::ostream& operator<<(std::ostream& os, const SilKit::Util::Span<const uint8_t>& v)
{
os << "[ ";
for (auto i : v)
Expand All @@ -18,17 +20,23 @@ static std::ostream& operator<<(std::ostream& os, const SilKit::Util::Span<const
return os;
}

static std::ostream& operator<<(std::ostream& os, const std::vector<uint8_t>& v)
inline std::ostream& operator<<(std::ostream& os, const std::vector<uint8_t>& v)
{
return os << SilKit::Util::ToSpan(v);
}

// This are the common data structures used in RpcServerDemo and RpcClientDemo
namespace RpcDemoCommon {

std::string mediaType{SilKit::Util::SerDes::MediaTypeRpc()};
RpcSpec rpcSpecSignalStrength{"GetSignalStrength", mediaType};
RpcSpec rpcSpecSort{"Sort", mediaType};
inline RpcSpec MakeSignalStrengthSpec()
{
return {"GetSignalStrength", SilKit::Util::SerDes::MediaTypeRpc()};
}

inline RpcSpec MakeSortSpec()
{
return {"Sort", SilKit::Util::SerDes::MediaTypeRpc()};
}

// ----------------------------------------------------------------
// Data structure, serialization and deserialization for Tuner Data
Expand All @@ -46,7 +54,7 @@ struct TunerData
TunerBand tunerBand;
};

std::vector<uint8_t> SerializeTunerData(const TunerData& tunerData)
inline std::vector<uint8_t> SerializeTunerData(const TunerData& tunerData)
{
SilKit::Util::SerDes::Serializer serializer;
serializer.BeginStruct();
Expand All @@ -57,7 +65,7 @@ std::vector<uint8_t> SerializeTunerData(const TunerData& tunerData)
return serializer.ReleaseBuffer();
}

TunerData DeserializeTunerData(const std::vector<uint8_t>& eventData)
inline TunerData DeserializeTunerData(const std::vector<uint8_t>& eventData)
{
TunerData tunerData;

Expand All @@ -74,15 +82,15 @@ TunerData DeserializeTunerData(const std::vector<uint8_t>& eventData)
// Serialization and deserialization for a double (signal strength)
// ----------------------------------------------------------------

std::vector<uint8_t> SerializeSignalStrength(double signalStrength)
inline std::vector<uint8_t> SerializeSignalStrength(double signalStrength)
{
SilKit::Util::SerDes::Serializer signalStrengthSerializer;
signalStrengthSerializer.Serialize(signalStrength);

return signalStrengthSerializer.ReleaseBuffer();
}

double DeserializeSignalStrength(const std::vector<uint8_t>& eventData)
inline double DeserializeSignalStrength(const std::vector<uint8_t>& eventData)
{
double signalStrength;

Expand All @@ -96,23 +104,23 @@ double DeserializeSignalStrength(const std::vector<uint8_t>& eventData)
// Serialization and deserialization for a std::vector<uint8_t>
// ----------------------------------------------------------------

std::vector<uint8_t> SerializeSortData(const std::vector<uint8_t>& numberList)
inline std::vector<uint8_t> SerializeSortData(const std::vector<uint8_t>& numberList)
{
SilKit::Util::SerDes::Serializer serializer;
serializer.Serialize(numberList);

return serializer.ReleaseBuffer();
}

std::vector<uint8_t> DeserializeSortData(const std::vector<uint8_t>& eventData)
inline std::vector<uint8_t> DeserializeSortData(const std::vector<uint8_t>& eventData)
{
SilKit::Util::SerDes::Deserializer deserializer(eventData);
std::vector<uint8_t> numberList = deserializer.Deserialize<std::vector<uint8_t>>();

return numberList;
}

bool EvaluateCallStatus(RpcCallResultEvent callResult, ILogger* logger)
inline bool EvaluateCallStatus(RpcCallResultEvent callResult, ILogger* logger)
{
std::stringstream ss;
bool isSuccessful = false;
Expand Down
4 changes: 2 additions & 2 deletions Demos/communication/Rpc/RpcServerDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RpcServer : public ApplicationBase
void CreateControllers() override
{
_rpcServerSignalStrength =
GetParticipant()->CreateRpcServer("ServerSignalStrength", RpcDemoCommon::rpcSpecSignalStrength,
GetParticipant()->CreateRpcServer("ServerSignalStrength", RpcDemoCommon::MakeSignalStrengthSpec(),
[this](IRpcServer* server, RpcCallEvent event) {
auto tunerData = RpcDemoCommon::DeserializeTunerData(SilKit::Util::ToStdVector(event.argumentData));

Expand Down Expand Up @@ -63,7 +63,7 @@ class RpcServer : public ApplicationBase
server->SubmitResult(event.callHandle, serializer.ReleaseBuffer());
});

_rpcServerSort = GetParticipant()->CreateRpcServer("ServerSort", RpcDemoCommon::rpcSpecSort,
_rpcServerSort = GetParticipant()->CreateRpcServer("ServerSort", RpcDemoCommon::MakeSortSpec(),
[this](IRpcServer* server, RpcCallEvent event) {
// Deserialize incoming data
auto argumentData = RpcDemoCommon::DeserializeSortData(SilKit::Util::ToStdVector(event.argumentData));
Expand Down
2 changes: 1 addition & 1 deletion Demos/communication/include/ApplicationBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct Arguments
};
std::shared_ptr<SilKit::Config::IParticipantConfiguration> _participantConfiguration{nullptr};

std::ostream& operator<<(std::ostream& out, std::chrono::nanoseconds timestamp)
inline std::ostream& operator<<(std::ostream& out, std::chrono::nanoseconds timestamp)
{
out << std::chrono::duration_cast<std::chrono::milliseconds>(timestamp).count() << "ms";
return out;
Expand Down
6 changes: 3 additions & 3 deletions Demos/communication/include/SignalHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static std::unique_ptr<SignalMonitor> gSignalMonitor;
////////////////////////////////////////////
// Inline Platform Specific Implementations
////////////////////////////////////////////
#if WIN32
#if defined(_WIN32)
#ifndef NOMINMAX
#define NOMINMAX
#endif
Expand Down Expand Up @@ -251,12 +251,12 @@ void systemHandler(const int sigNum)
//! \brief RegisterSignalHandler can be used to portably register a single signal handler.
// It only relies on async-signal-safe C functions internally, but
// it uses a dedicated thread which safely runs the user-provided handler.
void RegisterSignalHandler(SignalHandler handler)
inline void RegisterSignalHandler(SignalHandler handler)
{
gSignalMonitor.reset(new SignalMonitor(std::move(handler)));
}

void ShutdownSignalHandler()
inline void ShutdownSignalHandler()
{
gSignalMonitor.reset();
}
Loading
Loading