annotate service/main.py @ 498:3b627382e681

core: support async methods and bridge
author Goffi <goffi@goffi.org>
date Mon, 02 Oct 2023 17:24:01 +0200
parents b3cedbee561d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
369
bbf992b0be0d android (service): set autorestart:
Goffi <goffi@goffi.org>
parents: 359
diff changeset
1 #!/usr/bin/env python3
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
2
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
3 #Libervia Desktop-Kivy
126
cd99f70ea592 global file reorganisation:
Goffi <goffi@goffi.org>
parents: 87
diff changeset
4 # Copyright (C) 2016-2018 Jérôme Poisson (goffi@goffi.org)
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
5
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
10
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
15
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
18
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
19 import sys
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
20 import os
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
21 # we want the service to access the modules from parent dir (libervia.backend, etc.)
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
22 os.chdir('..')
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
23 sys.path.insert(0, '')
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
24 from libervia.backend.core.constants import Const as C
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
25 from libervia.backend.core import log_config
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
26 # SàT log conf must be done before calling Kivy
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
27 log_config.libervia_configure(C.LOG_BACKEND_STANDARD, C)
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
28 # if this module is called, we should be on android,
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
29 # but just in case...
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from kivy import utils as kivy_utils
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
31 if kivy_utils.platform == "android":
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
32 # sys.platform is "linux" on android by default
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
33 # so we change it to allow backend to detect android
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
34 sys.platform = "android"
318
834d5c267219 core: fixed state encoding + PLUGIN_EXT on Android following Python 3 port
Goffi <goffi@goffi.org>
parents: 126
diff changeset
35 C.PLUGIN_EXT = "pyc"
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
36 from libervia.backend.core import main
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from twisted.internet import reactor
359
38d763febed6 android (service): fixed backend launch
Goffi <goffi@goffi.org>
parents: 318
diff changeset
38 from twisted.application import app, service
369
bbf992b0be0d android (service): set autorestart:
Goffi <goffi@goffi.org>
parents: 359
diff changeset
39 from jnius import autoclass
bbf992b0be0d android (service): set autorestart:
Goffi <goffi@goffi.org>
parents: 359
diff changeset
40
bbf992b0be0d android (service): set autorestart:
Goffi <goffi@goffi.org>
parents: 359
diff changeset
41
bbf992b0be0d android (service): set autorestart:
Goffi <goffi@goffi.org>
parents: 359
diff changeset
42 PythonService = autoclass('org.kivy.android.PythonService')
bbf992b0be0d android (service): set autorestart:
Goffi <goffi@goffi.org>
parents: 359
diff changeset
43 PythonService.mService.setAutoRestartService(True)
bbf992b0be0d android (service): set autorestart:
Goffi <goffi@goffi.org>
parents: 359
diff changeset
44
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
45
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
46 libervia_backend = main.LiberviaBackend()
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
47 application = service.Application("Libervia backend")
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
48 libervia_backend.setServiceParent(application)
359
38d763febed6 android (service): fixed backend launch
Goffi <goffi@goffi.org>
parents: 318
diff changeset
49 app.startApplication(application, None)
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff changeset
50 reactor.run()