OpenCPN Partial API docs
Loading...
Searching...
No Matches
api_122.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2024 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25#include <wx/app.h>
26
27#include "ocpn_plugin.h"
28
29#include "ocpn-nlohmann/json.hpp"
30#include "observable/observable.h"
31
32#include "model/comm_navmsg.h"
34
35// FIXME (leamas) find new home.
36std::unique_ptr<HostApi> GetHostApi() {
37 auto impl = dynamic_cast<Api122Impl*>(wxTheApp);
38 assert(impl && "wxTheApp does not implement Api122Impl");
39 return std::make_unique<HostApi123>(HostApi123(impl));
40}
41
43 const std::string& plugin_name, std::function<void(EventType)> callback) {
44 auto impl = dynamic_cast<Api122Impl*>(wxTheApp);
45 assert(impl && "wxTheApp does not implement Api122Impl");
46 impl->RegisterApiEventCallback(plugin_name, callback);
47}
48
50 auto msg = obs::UnpackEvtPointer<SignalkMsg>(ev);
51 nlohmann::json root;
52 root["Data"] = msg->raw_message;
53 root["Context"] = msg->context;
54 root["ContextSelf"] = msg->context_self;
55 return root.dump();
56}
57
58const std::set<std::string>& HostApi122::GetActiveMessages() {
59 return NavMsgBus::GetInstance().GetActiveMessages();
60}
std::unique_ptr< HostApi > GetHostApi()
HostApi factory,.
Definition api_122.cpp:36
virtual const std::set< std::string > & GetActiveMessages()
Return currently known messages types flowing through system.
Definition api_122.cpp:58
virtual void RegisterApiEventCallback(const std::string &plugin_name, std::function< void(EventType what)> callback)
Register a new callback invoked when an EventType event occurs.
Definition api_122.cpp:42
virtual std::string GetSignalkPayload(ObservedEvt ev)
Get SignalK payload after receiving a message.
Definition api_122.cpp:49
EventType
Reported events bitmask.
Unstable development API.
const std::set< std::string > & GetActiveMessages()
Return list of message types sent or received.
Custom event class for OpenCPN's notification system.
Raw, undecoded messages definitions.
Raw messages layer, supports sending and recieving navmsg messages.
PlugIn Object Definition/API.