OpenCPN Partial API docs
ocpn_app.h
1 /***************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose: OpenCPN Main wxWidgets Program
5  * Author: David Register
6  *
7  ***************************************************************************
8  * Copyright (C) 2022 by David S. Register *
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  * This program is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18  * GNU General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU General Public License *
21  * along with this program; if not, write to the *
22  * Free Software Foundation, Inc., *
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24  **************************************************************************/
25 
26 #ifndef _OCPN_APP_H
27 #define _OCPN_APP_H
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/instance_check.h"
38 
39 #include "model/comm_bridge.h"
40 #include "model/local_api.h"
41 #include "model/rest_server.h"
42 #include "model/usb_watch_daemon.h"
43 class Track;
44 
45 class MyApp : public wxApp {
46 public:
47  MyApp();
48  ~MyApp(){};
49 
50  bool OnInit() override;
51  int OnExit() override;
52 #ifndef __ANDROID__
53  void OnInitCmdLine(wxCmdLineParser& parser) override;
54  bool OnCmdLineHelp(wxCmdLineParser& parser) override;
55  bool OnCmdLineParsed(wxCmdLineParser& parser) override;
56 #endif
57  int OnRun() override;
58 
59  void OnActivateApp(wxActivateEvent& event);
60  bool OpenFile(const std::string& path);
61 
62 #ifdef LINUX_CRASHRPT
64  void OnFatalException();
65 #endif
66 
67 #ifdef __WXMSW__
68  // Catch malloc/new fail exceptions
69  // All the rest will be caught be CrashRpt
70  bool OnExceptionInMainLoop();
71 #endif
72 
73  InstanceCheck& m_checker;
74  CommBridge m_comm_bridge;
75 
76  RestServer m_rest_server;
77  UsbWatchDaemon& m_usb_watcher;
78 
79  DECLARE_EVENT_TABLE()
80 private:
81 
83  struct ParsedCmdline {
84  CmdlineAction action;
85  std::string arg;
86  ParsedCmdline(CmdlineAction a, const std::string& s) : action(a), arg(s) {}
87  ParsedCmdline() : ParsedCmdline(CmdlineAction::Skip, "") {}
88  ParsedCmdline(CmdlineAction a) : ParsedCmdline(a, "") {}
89  };
90 
91  ParsedCmdline m_parsed_cmdline;
92  int m_exitcode;
93 
94  void InitRestListeners();
95  ObsListener rest_activate_listener;
96  ObsListener rest_reverse_listener;
97 
98 };
99 
100 wxDECLARE_APP(MyApp);
101 #endif
Common interface for all instance checkers.
Definition: ocpn_app.h:45
Define an action to be performed when a KeyProvider is notified.
Definition: observable.h:210
AbstractRestServer implementation and interface to underlying IO thread.
Definition: rest_server.h:241
Definition: track.h:78
Listen to hardware events and notifies SystemEvents when new devices are plugged in.
The local API has a server side handling commands and a client part issuing commands.
Generic hardware events interface.