OpenCPN Partial API docs
ipc_factories.cpp
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, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18  **************************************************************************/
19 
26 #include <stdlib.h>
27 
28 #include "model/ipc_api.h"
29 #include "model/wx_instance_chk.h"
30 
31 #if defined(__linux__) && !defined(__ANDROID__)
32 #include "model/dbus_client.h"
33 #include "model/dbus_server.h"
34 #endif
35 
36 static InstanceCheck& GetWxInstanceChk() {
37  static WxInstanceCheck wx_check;
38  return wx_check;
39 }
40 
41 #ifdef __ANDROID__
42 
43 std::unique_ptr<LocalClientApi> LocalClientApi::GetClient() {
44  return std::unique_ptr<LocalClientApi>(new DummyIpcClient());
45 }
46 
48  return DummyIpcServer::GetInstance();
49 }
50 
52 
54  return DummyInstanceChk::GetInstance();
55 }
56 
57 
58 #elif defined(__linux__)
59 static bool UseDbus() {
60  return getenv("FLATPAK_ID") != 0 || getenv("OCPN_FORCE_DBUS");
61 }
62 
63 std::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__
85 std::unique_ptr<LocalClientApi> LocalClientApi::GetClient() {
86  return std::unique_ptr<LocalClientApi>(new IpcClient());
87 }
88 
90  return IpcConnection::GetInstance();
91 }
92 
93 void LocalServerApi::ReleaseInstance() { IpcConnection::ReleaseInstance(); }
94 
96  return GetWxInstanceChk();
97 }
98 
99 #endif // __linux__
Implement LocalClientApi on linux using Dbus mechanisms.
Definition: dbus_client.h:33
Common interface for all instance checkers.
static InstanceCheck & GetInstance()
Started by IpcServer on filesystem fifo/socket connects.
Definition: ipc_api.h:73
Base interface for local server command handling.
Definition: local_api.h:62
static void ReleaseInstance()
Release Instance.
static LocalServerApi & GetInstance()
Thin wrapper for wxSingleInstanceChecker implementing InstanceCheck.
DBus interface header file.