|
1 | 1 | """ |
2 | | -ISISServer is used to create PVs and manage their lifetimes |
| 2 | +SimpleServer is used to create PVs and manage their lifetimes |
3 | 3 | """ |
4 | 4 |
|
5 | 5 | from __future__ import annotations |
6 | 6 |
|
7 | 7 | import logging |
8 | 8 |
|
9 | | -from p4p import Value |
10 | 9 | from p4p.client.thread import Context |
11 | 10 | from p4p.server import Server, StaticProvider |
12 | 11 | from p4p.server.thread import SharedPV |
13 | 12 |
|
14 | 13 | from p4p_ext.pvrecipe import BasePVRecipe |
| 14 | +from p4p_ext.server import BaseSimpleServer |
15 | 15 |
|
16 | 16 | logger = logging.getLogger(__name__) |
17 | 17 |
|
18 | 18 |
|
19 | | -class SimpleServer: |
| 19 | +class SimpleServer(BaseSimpleServer): |
20 | 20 | """ |
21 | 21 | Creates PVs and manages their lifetimes |
22 | | -
|
23 | | -
|
24 | 22 | """ |
25 | 23 |
|
26 | | - def __init__(self, ioc_name: str, section: str, description: str, prefix="") -> None: |
| 24 | + def __init__(self, prefix: str = "") -> None: |
27 | 25 | """ |
28 | 26 | Initialize the ISIS Server instance. |
29 | 27 |
|
30 | | - :param ioc_name: A PV naming convention compatible name for the IOC (Input/Output Controller). |
31 | | - :param section: The section or group responsible for the server e.g. Controls Software Applications, Diagnostics etc. |
32 | | - :param description: A detailed description of the server and what it does. |
33 | 28 | :param prefix: The prefix to be added to the PVs (Process Variables) of the server e.g. DEV: Defaults to "". |
34 | 29 | """ |
35 | | - # provide information for IOC stats PVs |
36 | | - self.ioc_name: str = ioc_name #: The name of the IOC (Input/Output Controller). |
37 | | - self.section: str = section #: The section or group responsible for this server, e.g. Synch RF |
38 | | - self.description: str = description #: A description of the purpose of this server. |
39 | | - # the prefix determines the prefix of the PVs to be added to the server e.g. DEV: |
40 | | - self.prefix: str = prefix #: The prefix to be prepended to the PVs generated by this server. |
| 30 | + super().__init__(prefix) |
41 | 31 |
|
42 | 32 | self._provider = StaticProvider() |
43 | 33 | self._server: Server | None = None |
44 | | - self._pvs: dict[str, SharedPV] = {} |
45 | 34 |
|
46 | 35 | self._running = False |
47 | 36 |
|
@@ -122,35 +111,3 @@ def remove_pv(self, pv_name: str) -> None: |
122 | 111 | # from the live system |
123 | 112 | self._provider.remove(pv_name) |
124 | 113 | logger.debug("Removed %s from server", pv_name) |
125 | | - |
126 | | - @property |
127 | | - def pvlist(self) -> list[str]: |
128 | | - """The PVs managed by the server""" |
129 | | - return list(self._pvs.keys()) |
130 | | - |
131 | | - def __getitem__(self, pv_name: str) -> SharedPV | None: |
132 | | - """Return one of the PVs managed by the server given its name""" |
133 | | - if not pv_name.startswith(self.prefix): |
134 | | - pv_name = self.prefix + pv_name |
135 | | - return self._pvs.get(pv_name) |
136 | | - |
137 | | - def get_pv_value(self, pv_name: str) -> Value: |
138 | | - """ |
139 | | - Get the value of a PV using SharedPV.current() if the PV is on this server |
140 | | - or Context.get() if it is not. |
141 | | - """ |
142 | | - if pv_name in self.pvlist: |
143 | | - logger.debug("Getting value using SharedPV for pv %s", pv_name) |
144 | | - shared_pv = self._pvs.get(pv_name, None) |
145 | | - if shared_pv: |
146 | | - return shared_pv.current() |
147 | | - |
148 | | - logger.debug("Doing Context.get() for pv %s", pv_name) |
149 | | - return self._ctxt.get(pv_name) # type: ignore |
150 | | - |
151 | | - def put_pv_value(self, pv_name: str, value: Value): |
152 | | - """ |
153 | | - Put the value to a PV using the server Context member self._ctxt |
154 | | - """ |
155 | | - logger.debug("Trying putting value %r to pv %s", value, pv_name) |
156 | | - self._ctxt.put(pv_name, value) |
0 commit comments