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, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 **************************************************************************/
20
28#ifndef _NAVMSG_BUS_H__
29#define _NAVMSG_BUS_H__
30
31#include <memory>
32#include <mutex>
33#include <set>
34#include <string>
35
36#include "model/comm_driver.h"
37#include "observable_evtvar.h"
38
40class NavMsgBus : public DriverListener {
41public:
42 /* Singleton implementation. */
43 static NavMsgBus& GetInstance();
44
45 NavMsgBus& operator=(NavMsgBus&) = delete;
46 NavMsgBus(const NavMsgBus&) = delete;
47
49 void SendMessage(std::shared_ptr<const NavMsg> message,
50 std::shared_ptr<const NavAddr> address);
51
53 void Notify(std::shared_ptr<const NavMsg> message);
54
55 /* DriverListener implementation: */
56 void Notify(const AbstractCommDriver& driver);
57
59 const std::set<std::string>& GetActiveMessages() { return m_active_messages; }
60
63
64private:
65 std::mutex m_mutex;
66 NavMsgBus() = default;
67
68 std::set<std::string> m_active_messages;
69};
70
71#endif // NAVMSG_BUS_H
Common interface for all drivers.
Definition comm_driver.h:58
Interface implemented by transport layer and possible other parties like test code which should handl...
Definition comm_driver.h:48
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 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.