-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Channel interface in SPARK #807
Comments
This probably solves #766. Having a |
I updated the description. |
This comment has been minimized.
This comment has been minimized.
I have changed the title and the description of the issue and also added the new design options (as O2, O3 and O3a) to keep a better overview of all considered designs. For the new design options, the session model would probably have to be changed. To enable stopping the state machine before reading or writing to a channel, the read or write action must be performed in a separate state. |
I have created a prototypical implementation of O3 based on a simple example session with multiple channels. The code is executable and is completely verified. O3 seems to fulfill our requirements, so that we could start adapting the code generator. |
Context and Problem Statement
The current session interface requires channels to provide subprograms as generic parameters to the session. The arguments of these subprograms currently only include the buffer, its size and it data is available. However they do not include any state about the interface being used. This restriction requires the package that provides the implementations to hold package state which is particularly inconvenient if there are multiple connections should be handled.
Requirements
Considered Options
O1
To solve this problem a context argument should be added to the session interface that allows the user of the session to pass external state through the sessions state machine.
The new session interface could look as follows:
The user of this package would then have to implement these properties accordingly:
It may not be required to have separate post and preconditions for the context.
O2
After some discussion the API design has been significantly changed. A channel is treated as a variable and the
Run
procedure will stop if data is needed or available.Both interfaces with one and two pointers are needed. If only a single transport buffer is available the in out variant has to be used. On the other hand a readable buffer might not be writable so a separate read and write pointer are required.
Furthermore the channel is intended to handle as a variable in the session. In the case of a single pointer it's clear that this memory can be used. If two pointers are provided the writable memory needs to be used for that purpose.
To prevent implementing both variants separately the
Run
with two pointers can implemented as follows (at the expense of at least one copy):This interface can be used in different settings. Either in a asynchronous interrupt driven environment:
After some discussion this option has been discarded. The reason is that the session internally assumes that the memory of the pointer doesn't change. This cannot be ensured.
A further problem is that there is no signalling to the session if a pointer has been initialized and is ready to use.
O3
Another option are simple read and write procedures:
This interface allows a synchronous use:
Asynchronous interfaces are also supported:
This interface also allows partial reading and writing:
A C API would be analogous:
Semantics
X'Read (Y)
andX'Write (Y)
with sameX
)X'Read (Y)
orX'Write (Y)
with sameY
)X'Has_Data
)Run
continues based on given state transitionsO3A
One of the problems with O3 is that a separate buffer is required if the IO code needs a buffer. To prevent a copy the session can make the internal buffer accessible via a generic callback. The implementation is analogous to the non-callback variant:
This simplifies the usage with other read/write procedures:
Since C uses pointers in its API a copy can be done directly with
memcpy
and the interface conversion done here is not necessary.Decision Outcome
O3
The text was updated successfully, but these errors were encountered: