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#include "welcome.h"
47
48using CallbacksByPlugin =
49 std::unordered_map<std::string, std::function<void(HostApi122::EventType)>>;
50
51class MyApp : public wxApp, public Api122Impl {
52public:
53 MyApp();
54 ~MyApp() {};
55
56 bool OnInit() override;
57 void BuildMainFrame();
58 void LoadChartDatabase();
59
60 void OnWallpaperStable();
61 int OnExit() override;
62#ifndef __ANDROID__
63 void OnInitCmdLine(wxCmdLineParser& parser) override;
64 bool OnCmdLineHelp(wxCmdLineParser& parser) override;
65 bool OnCmdLineParsed(wxCmdLineParser& parser) override;
66#endif
67 int OnRun() override;
68
69 void OnActivateApp(wxActivateEvent& event);
70 bool OpenFile(const std::string& path);
71 void OnUnhandledException() override;
72
73 void RegisterApiEventCallback(
74 const std::string& plugin_name,
75 std::function<void(HostApi122::EventType what)> callback) override;
76
77#ifdef LINUX_CRASHRPT
79 void OnFatalException();
80#endif
81
82#ifdef __WXMSW__
83 // Catch malloc/new fail exceptions
84 // All the rest will be caught be CrashRpt
85 bool OnExceptionInMainLoop();
86#endif
87
88 InstanceCheck& m_checker;
89
90 RestServer m_rest_server;
91 UsbWatchDaemon& m_usb_watcher;
92
93 DECLARE_EVENT_TABLE()
94private:
96 struct ParsedCmdline {
97 CmdlineAction action;
98 std::string arg;
99 ParsedCmdline(CmdlineAction a, const std::string& s) : action(a), arg(s) {}
100 ParsedCmdline() : ParsedCmdline(CmdlineAction::Skip, "") {}
101 ParsedCmdline(CmdlineAction a) : ParsedCmdline(a, "") {}
102 };
103
104 ParsedCmdline m_parsed_cmdline;
105 int m_exitcode;
106
107 void InitRestListeners();
108
109 void OnNewMsgTypes();
110
111 obs::Listener rest_activate_listener;
112 obs::Listener rest_reverse_listener;
113 obs::Listener new_msg_type_listener;
114
115 CallbacksByPlugin m_api_events_callbacks;
116};
117
118wxDECLARE_APP(MyApp);
119#endif
EventType
Reported events bitmask.
Common interface for all instance checkers.
bool OnInit() override
Definition ocpn_app.cpp:736
void OnWallpaperStable()
int OnExit() override
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.
Welcome to OpenCPN stuff.