-
Notifications
You must be signed in to change notification settings - Fork 27
/
service_factory_bundle.py
68 lines (54 loc) · 1.24 KB
/
service_factory_bundle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -- Content-Encoding: UTF-8 --
"""
Simple bundle registering a service
:author: Thomas Calmant
"""
__version__ = (1, 0, 0)
SVC = "greetings"
from pelix.constants import BundleActivator
class Service:
"""
Service per bundle
"""
def __init__(self, bundle_id):
self.__id = bundle_id
def show(self):
return self.__id
class ServiceFactoryTest:
"""
Simple test service
"""
def get_service(self, bundle, registration):
"""
Provide a new service
"""
return Service(bundle.get_bundle_id())
@BundleActivator
class ActivatorService:
"""
Test activator
"""
def __init__(self):
"""
Constructor
"""
self.context = None
self.factory = None
self.reg = None
def start(self, context):
"""
Bundle started
"""
self.context = context
# Register the service
self.factory = ServiceFactoryTest()
self.reg = context.register_service(
SVC, self.factory, {"test": True, "answer": 0},
factory=True)
def stop(self, context):
"""
Bundle stopped
"""
self.reg.unregister()
self.reg = None