OpenCPN Partial API docs
Loading...
Searching...
No Matches
ocpn_app.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2022 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, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef _OCPN_APP_H
25#define _OCPN_APP_H
26
27#include <string>
28
29#include <wx/wxprec.h>
30
31#ifndef WX_PRECOMP
32#include <wx/app.h>
33#include <wx/cmdline.h>
34#include <wx/event.h>
35#endif // precompiled headers
36
37#include "model/comm_bridge.h"
39#include "model/local_api.h"
40#include "model/rest_server.h"
41#include "model/track.h"
43
44#include "data_monitor.h"
45#include "ocpn_plugin.h"
46
47using CallbacksByPlugin =
48 std::unordered_map<std::string, std::function<void(HostApi122::EventType)>>;
49
50class MyApp : public wxApp, public Api122Impl {
51public:
52 MyApp();
53 ~MyApp() {};
54
55 bool OnInit() override;
56 void BuildMainFrame();
57 void LoadChartDatabase();
58
59 void OnWallpaperStable();
60 int OnExit() override;
61#ifndef __ANDROID__
62 void OnInitCmdLine(wxCmdLineParser& parser) override;
63 bool OnCmdLineHelp(wxCmdLineParser& parser) override;
64 bool OnCmdLineParsed(wxCmdLineParser& parser) override;
65#endif
66 int OnRun() override;
67
68 void OnActivateApp(wxActivateEvent& event);
69 bool OpenFile(const std::string& path);
70 void OnUnhandledException() override;
71
72 void RegisterApiEventCallback(
73 const std::string& plugin_name,
74 std::function<void(HostApi122::EventType what)> callback) override;
75
76#ifdef LINUX_CRASHRPT
78 void OnFatalException();
79#endif
80
81#ifdef __WXMSW__
82 // Catch malloc/new fail exceptions
83 // All the rest will be caught be CrashRpt
84 bool OnExceptionInMainLoop();
85#endif
86
87 InstanceCheck& m_checker;
88
89 RestServer m_rest_server;
90 UsbWatchDaemon& m_usb_watcher;
91
92 DECLARE_EVENT_TABLE()
93private:
95 struct ParsedCmdline {
96 CmdlineAction action;
97 std::string arg;
98 ParsedCmdline(CmdlineAction a, const std::string& s) : action(a), arg(s) {}
99 ParsedCmdline() : ParsedCmdline(CmdlineAction::Skip, "") {}
100 ParsedCmdline(CmdlineAction a) : ParsedCmdline(a, "") {}
101 };
102
103 ParsedCmdline m_parsed_cmdline;
104 int m_exitcode;
105
106 void InitRestListeners();
107
108 void OnNewMsgTypes();
109
110 ObsListener rest_activate_listener;
111 ObsListener rest_reverse_listener;
112 ObsListener new_msg_type_listener;
113
114 CallbacksByPlugin m_api_events_callbacks;
115};
116
117wxDECLARE_APP(MyApp);
118#endif
EventType
Reported events bitmask.
Common interface for all instance checkers.
bool OnInit() override
Definition ocpn_app.cpp:731
void OnWallpaperStable()
int OnExit() override
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:257
AbstractRestServer implementation and interface to underlying IO thread.
Listen to hardware events and notifies SystemEvents when new devices are plugged in.
CommBridge class and helpers.
New NMEA Debugger successor main window.
Instance check interface.
The local API has a server side handling commands and a client part issuing commands.
PlugIn Object Definition/API.
REST API server.
Recorded track abstraction.
Generic hardware events interface.