OpenCPN Partial API docs
Loading...
Searching...
No Matches
ipc_factories.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2023 Alec Leamas *
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
27#include <stdlib.h>
28
29#include "model/ipc_api.h"
31
32#if defined(__linux__) && !defined(__ANDROID__)
33#include "model/dbus_client.h"
34#include "model/dbus_server.h"
35#endif
36
37static InstanceCheck& GetWxInstanceChk() {
38 static WxInstanceCheck wx_check;
39 return wx_check;
40}
41
42#ifdef __ANDROID__
43
44std::unique_ptr<LocalClientApi> LocalClientApi::GetClient() {
45 return std::unique_ptr<LocalClientApi>(new DummyIpcClient());
46}
47
49 return DummyIpcServer::GetInstance();
50}
51
53
55 return DummyInstanceChk::GetInstance();
56}
57
58#elif defined(__linux__)
59static bool UseDbus() {
60 return getenv("FLATPAK_ID") != 0 || getenv("OCPN_FORCE_DBUS");
61}
62
63std::unique_ptr<LocalClientApi> LocalClientApi::GetClient() {
64 if (UseDbus()) {
65 return std::unique_ptr<LocalClientApi>(new DbusLocalClient);
66 } else {
67 return std::unique_ptr<LocalClientApi>(new IpcClient);
68 }
69}
70
72 return UseDbus() ? DbusServer::GetInstance() : IpcConnection::GetInstance();
73}
74
76
78 if (UseDbus())
79 return DbusServer::GetInstance();
80 else
81 return GetWxInstanceChk();
82}
83
84#else // __linux__ nor __ANDROID__
85std::unique_ptr<LocalClientApi> LocalClientApi::GetClient() {
86 return std::unique_ptr<LocalClientApi>(new IpcClient());
87}
88
90 return IpcConnection::GetInstance();
91}
92
93void LocalServerApi::ReleaseInstance() { IpcConnection::ReleaseInstance(); }
94
95InstanceCheck& InstanceCheck::GetInstance() { return GetWxInstanceChk(); }
96
97#endif // __linux__
Implement LocalClientApi on linux using Dbus mechanisms.
Definition dbus_client.h:36
Common interface for all instance checkers.
static InstanceCheck & GetInstance()
Started by IpcServer on filesystem fifo/socket connects.
Definition ipc_api.h:67
Base interface for local server command handling.
Definition local_api.h:63
static void ReleaseInstance()
Release Instance.
static LocalServerApi & GetInstance()
Thin wrapper for wxSingleInstanceChecker implementing InstanceCheck.
Dbus local API implementation (Linux only)
DBus interface header file.
Server and client CLI api implementations.
Single instance check based on wxWidgets functions.