This PR adds three new callback functions for use by SharedPV (p4p.server.raw) handlers. They are:
open() - called when a SharedPV is opened
post() - called each time a post operation is performed on a SharedPV
close() - called when a SharedPV is closed.
The associated changes to the p4p.server.raw.Handler class, additional new decorators, and unit tests (src/p4p/test/test_sharedpv.py) are included. The changes to src/p4p/server/raw.py are relatively minor but the examples and unit tests make this look like a much bigger PR! There was some initial discussion of the idea at #150.
Three examples that make use of the new callback functions are also included:
example/auditor.py - demonstrates using open() and close() callbacks along with the existing put() callback to record when an auditing PV that records who's made changes to other PVs is or isn't available. Probably redundant compared to the more complex example/persist.py.
example/ntscalar_control.py - implements the Control field logic for an NTScalar. This illustrates how put(), post(), and open() lead to a natural separation of concerns. Logic that does not depend on the previous state of the PV may be implemented in the handler open(), e.g. altering the value dependent on control.limitHigh and control.limitLow. Logic that depends on the current state of the PV and the proposed changes may be implemented in the post(), e.g. applying control.minStep. The put() may then be solely concerned with authorisation.
example/persist.py - demonstrates using an SQLite3 database to automatically save and restore the values of PVs. Makes use of the new handler_open_ and handler_post_ prefix arguments to make configuration convenient and to transmit information from a put() to a post() respectively. Makes full use of the new open() callback to automatically restore the value and timeStamp information of a PV and post() to automatically record this information each time it changes.
I believe the example/persist.py file probably makes the strongest case for the kind of new features that these callbacks allow or make easier.
Breaking Changes
I believe these changes may be considered largely backwards compatible. They will only cause compatibility issues:
if an existing handler implements open(), close(), or post() functions.
if a PV includes top-level fields names beginning with handler_open_ or handler_post_.
This PR adds three new callback functions for use by SharedPV (
p4p.server.raw
) handlers. They are:open()
- called when a SharedPV is openedpost()
- called each time a post operation is performed on a SharedPVclose()
- called when a SharedPV is closed.The associated changes to the
p4p.server.raw.Handler
class, additional new decorators, and unit tests (src/p4p/test/test_sharedpv.py
) are included. The changes tosrc/p4p/server/raw.py
are relatively minor but the examples and unit tests make this look like a much bigger PR! There was some initial discussion of the idea at #150.Three examples that make use of the new callback functions are also included:
example/auditor.py
- demonstrates usingopen()
andclose()
callbacks along with the existingput()
callback to record when an auditing PV that records who's made changes to other PVs is or isn't available. Probably redundant compared to the more complexexample/persist.py
.example/ntscalar_control.py
- implements the Control field logic for an NTScalar. This illustrates howput()
,post()
, andopen()
lead to a natural separation of concerns. Logic that does not depend on the previous state of the PV may be implemented in the handleropen()
, e.g. altering thevalue
dependent oncontrol.limitHigh
andcontrol.limitLow
. Logic that depends on the current state of the PV and the proposed changes may be implemented in thepost()
, e.g. applyingcontrol.minStep
. Theput()
may then be solely concerned with authorisation.example/persist.py
- demonstrates using an SQLite3 database to automatically save and restore the values of PVs. Makes use of the newhandler_open_
andhandler_post_
prefix arguments to make configuration convenient and to transmit information from aput()
to apost()
respectively. Makes full use of the newopen()
callback to automatically restore the value and timeStamp information of a PV andpost()
to automatically record this information each time it changes.I believe the
example/persist.py
file probably makes the strongest case for the kind of new features that these callbacks allow or make easier.Breaking Changes
I believe these changes may be considered largely backwards compatible. They will only cause compatibility issues:
open()
,close()
, orpost()
functions.handler_open_
orhandler_post_
.