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"
33
34// FIXME (leamas) find new home.
35std::unique_ptr<HostApi> GetHostApi() {
36 auto impl = dynamic_cast<Api122Impl*>(wxTheApp);
37 assert(impl && "wxTheApp does not implement Api122Impl");
38 return std::make_unique<HostApi122>(HostApi122(impl));
39}
40
42 const std::string& plugin_name, std::function<void(EventType)> callback) {
43 auto impl = dynamic_cast<Api122Impl*>(wxTheApp);
44 assert(impl && "wxTheApp does not implement Api122Impl");
45 impl->RegisterApiEventCallback(plugin_name, callback);
46}
47
49 auto msg = obs::UnpackEvtPointer<SignalkMsg>(ev);
50 nlohmann::json root;
51 root["Data"] = msg->raw_message;
52 root["Context"] = msg->context;
53 root["ContextSelf"] = msg->context_self;
54 return root.dump();
55}
std::unique_ptr< HostApi > GetHostApi()
HostApi factory,.
Definition api_122.cpp:35
Unstable development API.
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:41
std::string GetSignalkPayload(ObservedEvt ev)
Get SignalK payload after receiving a message.
Definition api_122.cpp:48
EventType
Reported events bitmask.
Custom event class for OpenCPN's notification system.
Raw, undecoded messages definitions.
PlugIn Object Definition/API.