websocket_bridge

Contents

websocket_bridge#

namespace heph
namespace ws#

Functions

bool saveSchemaToDatabase(const foxglove::Channel &channel_definition, ProtobufSchemaDatabase &schema_db)#
bool saveSchemaToDatabase(const foxglove::Service &service_definition, ProtobufSchemaDatabase &schema_db)#
bool saveSchemaToDatabase(const foxglove::ServiceResponseDefinition &service_request_definition, ProtobufSchemaDatabase &schema_db)#
std::unique_ptr<google::protobuf::Message> retrieveRequestMessageFromDatabase(foxglove::ServiceId service_id, const ProtobufSchemaDatabase &schema_db)#
std::unique_ptr<google::protobuf::Message> retrieveResponseMessageFromDatabase(foxglove::ServiceId service_id, const ProtobufSchemaDatabase &schema_db)#
std::unique_ptr<google::protobuf::Message> retrieveMessageFromDatabase(const std::string &schema_name, const ProtobufSchemaDatabase &schema_db)#
std::pair<std::string, std::string> retrieveSchemaNamesFromServiceId(foxglove::ServiceId service_id, const ProtobufSchemaDatabase &schema_db)#
std::string retrieveSchemaNameFromChannelId(foxglove::ChannelId channel_id, const ProtobufSchemaDatabase &schema_db)#
template<typename T>
void setRandomValue(google::protobuf::Message *message, const google::protobuf::FieldDescriptor *field, RandomGenerators &generators)#
void fillRepeatedField(google::protobuf::Message *message, const google::protobuf::FieldDescriptor *field, RandomGenerators &generators, int depth)#
void fillMessageWithRandomValues(google::protobuf::Message *message, RandomGenerators &generators, int depth = 0)#
std::unique_ptr<google::protobuf::Message> generateRandomMessageFromSchemaName(const std::string &schema_name, ProtobufSchemaDatabase &schema_db)#
std::string convertProtoBytesToFoxgloveBase64String(const std::vector<std::byte> &data)#
std::string convertSerializationTypeToString(const serdes::TypeInfo::Serialization &serialization)#
void debugPrintSchema(const std::vector<std::byte> &schema)#
void debugPrintMessage(const google::protobuf::Message &message)#
void printBinary(const uint8_t *data, size_t length)#
std::string getTimestampString()#
foxglove::ChannelWithoutId convertIpcTypeInfoToWsChannelInfo(const std::string &topic, const serdes::TypeInfo &type_info)#
std::optional<serdes::TypeInfo> convertWsChannelInfoToIpcTypeInfo(const foxglove::ClientAdvertisement &channel_info)#
struct ProtobufSchemaDatabase#

Public Members

std::unordered_map<foxglove::ServiceId, std::pair<std::string, std::string>> service_id_to_schema_names#
std::unordered_map<foxglove::ChannelId, std::string> channel_id_to_schema_name#
std::unique_ptr<google::protobuf::SimpleDescriptorDatabase> proto_db#
std::unique_ptr<google::protobuf::DescriptorPool> proto_pool#
std::unique_ptr<google::protobuf::DynamicMessageFactory> proto_factory#

Public Functions

ProtobufSchemaDatabase()#
~ProtobufSchemaDatabase() = default#
struct RandomGenerators#

Public Members

std::mt19937 gen#
std::uniform_int_distribution<int32_t> int32_dist#
std::uniform_int_distribution<int64_t> int64_dist#
std::uniform_int_distribution<uint32_t> uint32_dist#
std::uniform_int_distribution<uint64_t> uint64_dist#
std::uniform_real_distribution<float> float_dist#
std::uniform_real_distribution<double> double_dist#

Public Functions

RandomGenerators(int min, int max)#
namespace heph
namespace ws

Functions

std::optional<std::unique_ptr<google::protobuf::Message>> receiveResponse(const WsServiceResponse &service_response, WsAdvertisements &ws_server_ads, ServiceCallState &state)#
void receiveFailureResponse(const std::string &error_msg, ServiceCallState &state)#
bool allServiceCallsFinished(const ServiceCallStateMap &state)#
std::string horizontalLine(uint32_t cell_content_width, uint32_t columns)#
void printServiceCallStateMap(ServiceCallStateMap &state)#
void printAdvertisedServices(const WsAdvertisements &ws_server_ads)#
void printAdvertisedTopics(const WsAdvertisements &ws_server_ads)#
void printClientChannelAds(const std::vector<WsClientChannelAd> &client_ads)#
struct ServiceCallState#

Public Types

enum class Status : std::uint8_t#

Values:

enumerator SUCCESS#
enumerator DISPATCHED#
enumerator FAILED#

Public Members

uint32_t call_id#
Status status#
std::chrono::steady_clock::time_point dispatch_time#
std::chrono::steady_clock::time_point response_time#
std::optional<WsServiceResponse> response#
std::string error_message#

Public Functions

explicit ServiceCallState(uint32_t id)#
bool hasResponse() const#
bool wasSuccessful() const#
bool hasFailed() const#
std::optional<std::chrono::milliseconds> getDurationMs() const#

Typedefs

using WsClientNoTls = foxglove::Client<foxglove::WebSocketNoTls>#
using ServiceCallStateMap = std::map<uint32_t, ServiceCallState>#
namespace heph
namespace ws
class WebsocketBridge#

Public Functions

WebsocketBridge(const std::shared_ptr<ipc::zenoh::Session> &session, const WebsocketBridgeConfig &config)#
~WebsocketBridge() = default#
void start()#
void stop()#
namespace heph
namespace ws

Functions

bool convertIpcRawServiceResponseToWsServiceResponse(WsServiceId service_id, WsServiceCallId call_id, const ipc::zenoh::ServiceResponse<std::vector<std::byte>> &raw_response, WsServiceResponse &ws_response)#
std::optional<WsChannelAd> convertWsJsonMsgToChannel(const nlohmann::json &channel_json)#
std::optional<WsInfo> convertWsJsonMsgtoServerOptions(const nlohmann::json &server_options_json)#
std::optional<WsServiceAd> convertWsJsonMsgToService(const nlohmann::json &service_json)#
bool parseWsAdvertisements(const nlohmann::json &server_txt_msg, WsAdvertisements &ws_server_ads)#
bool parseWsServiceFailure(const nlohmann::json &server_txt_msg, WsServiceFailure &service_failure)#
struct WsAdvertisements#

Public Members

WsInfo info#
std::unordered_map<WsChannelId, WsChannelAd> channels#
std::unordered_map<WsServiceId, WsServiceAd> services#
ProtobufSchemaDatabase schema_db#
struct WsClientComparator#

Public Functions

inline bool operator()(const ClientHandleWithName &lhs, const ClientHandleWithName &rhs) const#
struct WsServiceFailure#

Public Members

WsServiceCallId call_id#
std::string error_message#

Typedefs

using WsClientHandle = foxglove::ConnHandle#
using WsInterface = foxglove::ServerInterface<WsClientHandle>#
using WsInterfacePtr = std::unique_ptr<WsInterface>#
using WsHandlers = foxglove::ServerHandlers<WsClientHandle>#
using WsFactory = foxglove::ServerFactory#
using WsInfo = foxglove::ServerOptions#
using WsLogLevel = foxglove::WebSocketLogLevel#
using WsChannelId = foxglove::ChannelId#
using WsChannelInfo = foxglove::ChannelWithoutId#
using WsChannelAd = foxglove::Channel#
using WsClientChannelId = foxglove::ClientChannelId#
using WsClientChannelIdSet = std::unordered_set<WsClientChannelId>#
using WsClientChannelAd = foxglove::ClientAdvertisement#
using WsSubscriptionId = foxglove::SubscriptionId#
using WsClientMessage = foxglove::ClientMessage#
using WsServiceId = foxglove::ServiceId#
using WsServiceCallId = uint32_t#
using WsServiceInfo = foxglove::ServiceWithoutId#
using WsServiceAd = foxglove::Service#
using WsServiceRequestDefinition = foxglove::ServiceRequestDefinition#
using WsServiceResponseDefinition = foxglove::ServiceResponseDefinition#
using WsServiceRequest = foxglove::ServiceRequest#
using WsServiceResponse = foxglove::ServiceResponse#
using WsBinaryOpCode = foxglove::BinaryOpcode#
using WsClientBinaryOpCode = foxglove::ClientBinaryOpcode#
using ClientHandleWithName = std::pair<WsClientHandle, std::string>#
using WsClientHandleSet = std::set<ClientHandleWithName, WsClientComparator>#
namespace heph
namespace ws

Functions

std::vector<std::regex> parseRegexStrings(const std::vector<std::string> &regex_string_vector)#
bool shouldBridgeIpcTopic(const std::string &topic, const WebsocketBridgeConfig &config)#
bool shouldBridgeIpcService(const std::string &service, const WebsocketBridgeConfig &config)#
bool shouldBridgeWsTopic(const std::string &topic, const WebsocketBridgeConfig &config)#
bool isMatch(const std::string &topic, const std::vector<std::regex> &regex_list)#
bool isMatch(const std::string &topic, const std::vector<std::string> &regex_string_list)#
WebsocketBridgeConfig loadBridgeConfigFromYaml(const std::string &yaml_file_path)#
void saveBridgeConfigToYaml(const WebsocketBridgeConfig &config, const std::string &path)#
std::string convertBridgeConfigToString(const WebsocketBridgeConfig &config)#
struct WebsocketBridgeConfig#

Public Members

WsInfo ws_server_config  = {.capabilities = {foxglove::CAPABILITY_CLIENT_PUBLISH,foxglove::CAPABILITY_SERVICES,foxglove::CAPABILITY_CONNECTION_GRAPH,},.supportedEncodings = {},.metadata = {},.sendBufferLimitBytes = foxglove::DEFAULT_SEND_BUFFER_LIMIT_BYTES,.useTls = false,.certfile = "",.keyfile = "",.sessionId ="session_" +std::to_string(std::chrono::system_clock::now().time_since_epoch().count()),.numWorkerThreads = 1,.useCompression = true,.clientTopicWhitelistPatterns = parseRegexStrings({ ".*" }),}
uint16_t ws_server_port = DEFAULT_WS_SERVER_PORT#
std::string ws_server_address = "0.0.0.0"#
bool ws_server_verbose_bridge_state = false#
bool ws_server_verbose_ipc_graph_state = false#
heph::ipc::zenoh::Config zenoh_config#
int ipc_service_call_timeout_ms = DEFAULT_IPC_SERVICE_CALL_TIMEOUT_MS#
bool ipc_service_service_request_async = true#
bool ipc_advertise_topics_based_on_subscribers = true#
std::vector<std::string> ipc_topic_whitelist = {".*"}#
std::vector<std::string> ipc_topic_blacklist#
std::vector<std::string> ipc_service_whitelist = {".*"}#
std::vector<std::string> ipc_service_blacklist#

Public Static Attributes

static uint16_t DEFAULT_WS_SERVER_PORT = 8765#
static int DEFAULT_IPC_SERVICE_CALL_TIMEOUT_MS = 5000#
namespace heph
namespace ws
class IpcEntityManager#

Public Functions

IpcEntityManager(std::shared_ptr<ipc::zenoh::Session> session, ipc::zenoh::Config config)#
~IpcEntityManager()#
void start()#
void stop()#
bool hasSubscriber(const std::string &topic) const#
void addSubscriber(const std::string &topic, const serdes::TypeInfo &topic_type_info, const TopicSubscriberWithTypeCallback &subscriber_cb)#
void removeSubscriber(const std::string &topic)#
bool hasPublisher(const std::string &topic) const#
void addPublisher(const std::string &topic, const serdes::TypeInfo &topic_type_info)#
void removePublisher(const std::string &topic)#
bool publishMessage(const std::string &topic, std::span<const std::byte> data)#
RawServiceResponses callService(uint32_t call_id, const ipc::TopicConfig &topic_config, std::span<const std::byte> buffer, std::chrono::milliseconds timeout)#
std::future<void> callServiceAsync(uint32_t call_id, const ipc::TopicConfig &topic_config, std::span<const std::byte> buffer, std::chrono::milliseconds timeout, AsyncServiceResponseCallback callback)#

Typedefs

using TopicSubscriberWithTypeCallback = std::function<void(const ipc::zenoh::MessageMetadata&, std::span<const std::byte>, const serdes::TypeInfo&)>#
using RawServiceResponses = std::vector<ipc::zenoh::ServiceResponse<std::vector<std::byte>>>#
using AsyncServiceResponseCallback = std::function<void(const RawServiceResponses&)>#
namespace heph
namespace ws
class WebsocketBridgeState#

Public Functions

WebsocketBridgeState() = default#
std::string toString() const#
void printBridgeState() const#
bool checkConsistency() const#
std::string getIpcTopicForWsChannel(const WsChannelId &channel_id) const#
WsChannelId getWsChannelForIpcTopic(const std::string &topic) const#
void addWsChannelToIpcTopicMapping(const WsChannelId &channel_id, const std::string &topic)#
void removeWsChannelToIpcTopicMapping(const WsChannelId &channel_id, const std::string &topic)#
bool hasWsChannelMapping(const WsChannelId &channel_id) const#
bool hasIpcTopicMapping(const std::string &topic) const#
std::string topicChannelMappingToString() const#
bool hasWsChannelWithClients(const WsChannelId &channel_id) const#
void addWsChannelToClientMapping(const WsChannelId &channel_id, const WsClientHandle &client_handle, const std::string &client_name)#
void removeWsChannelToClientMapping(const WsChannelId &channel_id)#
void removeWsChannelToClientMapping(const WsChannelId &channel_id, const WsClientHandle &client_handle)#
std::optional<WsClientHandleSet> getClientsForWsChannel(const WsChannelId &channel_id) const#
std::string getIpcServiceForWsService(const WsServiceId &service_id) const#
WsChannelId getWsServiceForIpcService(const std::string &service_name) const#
void addWsServiceToIpcServiceMapping(const WsServiceId &service_id, const std::string &service_name)#
void removeWsServiceToIpcServiceMapping(const WsServiceId &service_id, const std::string &service_name)#
bool hasWsServiceMapping(const WsChannelId &service_id) const#
bool hasIpcServiceMapping(const std::string &service_name) const#
std::string servicMappingToString() const#
bool hasCallIdToClientMapping(uint32_t call_id) const#
void addCallIdToClientMapping(uint32_t call_id, const WsClientHandle &client_handle, const std::string &client_name)#
void removeCallIdToClientMapping(uint32_t call_id)#
std::optional<ClientHandleWithName> getClientForCallId(uint32_t call_id) const#
std::string callIdToClientMappingToString() const#
bool hasClientChannelsForTopic(const std::string &topic) const#
std::string getTopicForClientChannel(const WsClientChannelId &client_channel_id) const#
WsClientChannelIdSet getClientChannelsForTopic(const std::string &topic) const#
void addClientChannelToTopicMapping(const WsClientChannelId &client_channel_id, const std::string &topic)#
void removeClientChannelToTopicMapping(const WsClientChannelId &client_channel_id)#
bool hasClientChannelMapping(const WsClientChannelId &client_channel_id) const#
bool hasTopicToClientChannelMapping(const std::string &topic) const#
std::string clientChannelMappingToString() const#
bool hasClientForClientChannel(const WsClientChannelId &client_channel_id) const#
void addClientChannelToClientMapping(const WsClientChannelId &client_channel_id, const WsClientHandle &client_handle, const std::string &client_name)#
void removeClientChannelToClientMapping(const WsClientChannelId &client_channel_id)#
std::optional<ClientHandleWithName> getClientForClientChannel(const WsClientChannelId &client_channel_id) const#