// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once #include #include #include #include "Channel.hpp" #include "Common.hpp" #include "Message.hpp" namespace sys { class Service; class Message; constexpr uint32_t defaultCmdTimeout = 5000; class Bus { public: // Send message directly to specified service (unicast type) static bool SendUnicast(std::shared_ptr msg, const std::string &service, Service *s); // Send message directly to specified service with timeout static SendResult SendUnicast(std::shared_ptr msg, const std::string &service, Service *s, uint32_t timeout); // Send message to specific channel static void SendMulticast(std::shared_ptr msg, BusChannels channel, Service *source); // Send message to all registered services () static void SendBroadcast(std::shared_ptr msg, Service *source); // Register new service static void Add(std::shared_ptr service); // Unregister specified service static void Remove(std::shared_ptr service); static void SendResponse(std::shared_ptr response, std::shared_ptr request, Service *sender); private: Bus(); ~Bus(); static std::map channels; static std::map> servicesRegistered; static uint64_t uniqueMsgId; static uint64_t unicastMsgId; }; } // namespace sys