OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_navmsg_bus.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2022 by David Register *
3 * Copyright (C) 2022 Alec Leamas *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
27#ifndef NAVMSG_BUS_H_
28#define NAVMSG_BUS_H_
29
30#include <memory>
31#include <mutex>
32#include <set>
33#include <string>
34
35#include "model/comm_driver.h"
36#include "observable_evtvar.h"
37
39class NavMsgBus : public DriverListener {
40public:
41 /* Singleton implementation. */
42 static NavMsgBus& GetInstance();
43
44 NavMsgBus& operator=(NavMsgBus&) = delete;
45 NavMsgBus(const NavMsgBus&) = delete;
46
48 void SendMessage(std::shared_ptr<const NavMsg> message,
49 std::shared_ptr<const NavAddr> address);
50
52 void RegisterKey(const std::string& key);
53
55 void Notify(std::shared_ptr<const NavMsg> message);
56
57 /* DriverListener implementation: */
58 void Notify(const AbstractCommDriver& driver);
59
61 const std::set<std::string>& GetActiveMessages() { return m_active_messages; }
62
65
66private:
67 std::mutex m_mutex;
68 NavMsgBus() = default;
69
70 std::set<std::string> m_active_messages;
71};
72
73#endif // NAVMSG_BUS_H_
Common interface for all drivers.
Definition comm_driver.h:65
Interface for handling incoming messages.
Definition comm_driver.h:50
Generic event handling between MVC Model and Controller based on a shared EventVar variable.
The raw message layer, a singleton.
void SendMessage(std::shared_ptr< const NavMsg > message, std::shared_ptr< const NavAddr > address)
Send a message to given destination using suitable driver.
const std::set< std::string > & GetActiveMessages()
Return list of message types sent or received.
void RegisterKey(const std::string &key)
Register a message type in list the GetActiveMessages() list.
void Notify(std::shared_ptr< const NavMsg > message)
Accept message received by driver, make it available for upper layers.
EventVar new_msg_event
Notified without data when new message type(s) are detected.
Communication driver layer.
A common variable shared between producer and consumer which supports Listen() and Notify().