Skip to content

sdl2: add support to start multiple services#608

Merged
kived merged 3 commits into
masterfrom
feature-multiple-services
Jan 25, 2016
Merged

sdl2: add support to start multiple services#608
kived merged 3 commits into
masterfrom
feature-multiple-services

Conversation

@tito

@tito tito commented Jan 22, 2016

Copy link
Copy Markdown
Member

The current service approach is automatic, and supports only one service if there is a service/main.py file in the application.

This approach is complementary, and allow the user to declare multiple others services from name + entrypoint:

  1. build.py have a new --service name:entrypoint.py option that can be used multiple time
    1.1 it will generate appropriate service file out of the Service.tmpl.java into your.package.ServiceNAME
    1.2 it will declare the service in the AndroidManifest.xml
  2. PythonActivity.start_service and PythonActivtiy changed to pass the default entrypoint (either main.pyo or service/main.pyo).
  3. start.c is changed to use the entrypoint that we passed along. It as mangling to either use pyo in priority, or fallback to py if pyo is not found.

Note that if you declare a name "S1", the java service will be named "ServiceS1", and your name will be capitalized (to have a correct java classname)

They are declared to run as separated process from the application. So it's up to you to came with a communication layer between your application and services. The stop method kill the process, without any warning. Use your own communication layer first to soft kill before doing stop.
Any call to start without stop will have no effect.

Usage example:

Building:

p4a apk ... --package org.domain --name testservices --service S1:service_s1.py --service S2:service_s2.py`

Pure python usage:

from jnius import autoclass
context = autoclass("org.kivy.android.PythonActivity").mActivity
ServiceS1 = autoclass("org.domain.testservices.ServiceS1")
ServiceS2 = autoclass("org.domain.testservices.ServiceS2")

ServiceS1.start(context, "")
ServiceS2.start(context, "")
ServiceS2.stop(context)
ServiceS1.stop(context)

@kived

kived commented Jan 22, 2016

Copy link
Copy Markdown
Contributor

Looks mostly good so far, but I'm having an issue with one of my services not being able to import some modules (not sure why, as the main app imports the modules fine, as do the other services).

I did add some changes to use different log tags for the services.

@tito

tito commented Jan 23, 2016

Copy link
Copy Markdown
Member Author

Looking good for the logtag!

On my side, i did make a library more "official" and clean to use them:
https://github.com/tito/servicelib

Maybe that would be good to put it under kivy umbrella?

@kived

kived commented Jan 25, 2016

Copy link
Copy Markdown
Contributor

I think that servicelib could be a good addition. It won't handle all cases, but it will work great when you just need a cross-platform multiprocessing type solution.

kived added a commit that referenced this pull request Jan 25, 2016
sdl2: add support to start multiple services
@kived kived merged commit 1d030d4 into master Jan 25, 2016
@kived

kived commented Jan 25, 2016

Copy link
Copy Markdown
Contributor

👍

@akshayaurora akshayaurora deleted the feature-multiple-services branch May 3, 2016 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants