Debian Codegraph @

envisage/i_service_registry.py

raw
1 # (C) Copyright 2007-2025 Enthought, Inc., Austin, TX
2 # All rights reserved.
3 #
4 # This software is provided without warranty under the terms of the BSD
5 # license included in LICENSE.txt and may be redistributed only under
6 # the conditions described in the aforementioned license. The license
7 # is also available online at http://www.enthought.com/licenses/BSD.txt
8 #
9 # Thanks for using Enthought open source!
10 """ The service registry interface. """
11
12
13 # Enthought library imports.
14 from traits.api import Event, Interface
15
16
17 class IServiceRegistry(Interface):
18 """The service registry interface.
19
20 The service registry provides a 'Yellow Pages' style mechanism, in that
21 services are published and looked up by protocol (meaning, *interface*,
22 *type*, or *class* (for old-style classes!). It is called a 'Yellow Pages'
23 mechanism because it is just like looking up a telephone number in the
24 'Yellow Pages' phone book. You use the 'Yellow Pages' instead of the
25 'White Pages' when you don't know the *name* of the person you want to
26 call but you do know what *kind* of service you require. For example, if
27 you have a leaking pipe, you know you need a plumber, so you pick up your
28 'Yellow Pages', go to the 'Plumbers' section and choose one that seems to
29 fit the bill based on price, location, certification, etc. The service
30 registry does exactly the same thing as the 'Yellow Pages', only with
31 objects, and it even allows you to publish your own entries for free
32 (unlike the *real* one)!
33
34 """
35
36 # An event that is fired when a service is registered.
37 registered = Event
38
39 # An event that is fired when a service is unregistered.
40 unregistered = Event
41
42 def get_service(self, protocol, query="", minimize="", maximize=""):
43 """Return at most one service that matches the specified query.
44
45 The protocol can be an actual class or interface, or the *name* of a
46 class or interface in the form '<module_name>.<class_name>'.
47
48 Return None if no such service is found.
49
50 If no query is specified then a service that provides the specified
51 protocol is returned (if one exists).
52
53 NOTE: If more than one service exists that match the criteria then
54 Don't try to guess *which* one it will return - it is random!
55
56 """
57
58 def get_service_from_id(self, service_id):
59 """Return the service with the specified id.
60
61 If no such service exists a 'ValueError' exception is raised.
62
63 """
64
65 def get_services(self, protocol, query="", minimize="", maximize=""):
66 """Return all services that match the specified query.
67
68 The protocol can be an actual class or interface, or the *name* of a
69 class or interface in the form '<module_name>.<class_name>'.
70
71 If no services match the query, then an empty list is returned.
72
73 If no query is specified then all services that provide the specified
74 protocol are returned (if any exist).
75
76 """
77
78 def get_service_properties(self, service_id):
79 """Return the dictionary of properties associated with a service.
80
81 If no such service exists a 'ValueError' exception is raised.
82
83 The properties returned are 'live' i.e. changing them immediately
84 changes the service registration.
85
86 """
87
88 def register_service(self, protocol, obj, properties=None):
89 """Register a service.
90
91 The protocol can be an actual class or interface, or the *name* of a
92 class or interface in the form::
93
94 'foo.bar.baz'
95
96 Which is turned into the equivalent of an import statement that
97 looks like::
98
99 from foo.bar import baz
100
101 Return a service Id that can be used to unregister the service and to
102 get/set any service properties.
103
104 If 'obj' does not implement the specified protocol then it is treated
105 as a 'service factory' that will be called the first time a service of
106 the appropriate type is requested. A 'service factory' is simply a
107 callable that takes the properties specified here as keyword arguments
108 and returns an object. For *really* lazy loading, the factory can also
109 be specified as a string which is used to import the callable.
110
111 """
112
113 def set_service_properties(self, service_id, properties):
114 """Set the dictionary of properties associated with a service.
115
116 If no such service exists a 'ValueError' exception is raised.
117
118 """
119
120 def unregister_service(self, service_id):
121 """Unregister a service.
122
123 If no such service exists a 'ValueError' exception is raised.
124
125 """