PickBASIC / FlashBASIC
Named common in triggers
.mdTriggers can use named commons to create persistent data across the various operations.
Example(s)
To audit all accesses to a file, the application opens the audit file in the open trigger and stores the file descriptor in the common, along with the file name and an audit message number:
OpenTrigger subroutine OpenTrigger( InputFileName ) common /audit/ AuditFd, FileName, MsgNumber open “dm,Audit,” to AuditFd FileName = InputFileName MsgNumber = 1 writev “Opening “:FileName to AuditFd, FileName, MsgNumber return
The write trigger or the read trigger accesses the audit file using this file descriptor in the common:
ReadTrigger subroutine ReadTrigger( Record ) common /audit/ AuditFd, FileName, MsgNumber Msg = “Reading “:Access(10):” from “:FileName MsgNumber = MsgNumber + 1 writev Msg to AuditFd, FileName, MsgNumber return
The close trigger closes the audit file:
CloseTrigger subroutine CloseTrigger( File ) common /audit/ AuditFd, FileName, MsgNumber Msg = “Closing:FileName MsgNumber = MsgNumber + 1 writev Msg to AuditFd, FileName, MsgNumber close AuditFd return
Note:
- Triggers are attached to the file object, and while the code is shared among all users, the named commons are not. In other words, the data stored in a named common is private to the client application. Also, if a file is opened more than once (aliases), the file descriptors have different named common spaces. Make sure all accesses to the file are done using the same file descriptor.
- The named common space is destroyed when the file object is destroyed, not closed. This distinction does not affect VME applications for which closing a file implies the object destruction, but for VB and C++ applications it is possible to close the file without destroying the object.
- Commons are shared.