Add options to connect methods
Communication protocols might need options, that need to be set but cannot be encoded in the URI, e.g., credentials. One such option is already present for send ports: The decision, whether to send the current value.
It would be nice to have a dedicated object to set protocol-specific options. For this, newly generated nonterminals could be used. A grammar could look like:
ConnectionOption ;
MqttConnectionOption : ConnectionOption ::= <UserName> <Password> <QoS> ;
RestClientConnectionOption : ConnectionOption ::= <CacheDuration:int> ;
Ideally, one separates options only valid for receiving, and others only valid for sending. However, this creates another inheritance hierarchy (one for protocol, and one for receiving/sending). Since this grammar is generated, duplication is handled by RagConnect. A generated grammar could then look like:
ReceiveConnectionOption ;
SendConnectionOption ::= <SendCurrentValue:boolean> ;
ReceiveMqttConnectionOption : ReceiveConnectionOption ::= <UserName> <Password> ;
SendMqttConnectionOption : SendConnectionOption ::= <UserName> <Password> <QoS> ;
ReceiveRestClientConnectionOption : ReceiveConnectionOption ::= <CacheDuration:int> ;
SendRestClientConnectionOption : SendConnectionOption ::= ;
The API would change to something like:
// for receiving:
boolean A.connectId(String uri, ReceiveConnectionOption option);
// for sending:
boolean A.connectId(String uri, SendConnectionOption option);
// probably add the following backwards compatible methods
boolean A.connectId(String uri) {
return connectId(uri, createReceiveOptionFor(uri));
}
boolean A.connectId(String uri, boolean sendCurrentValue) {
return connectId(uri, createSendOptionFor(uri).setSendCurrentValue(sendCurrentValue));
}
If only one protocol is selected, the option class in the method signature could also be directly that of the selected protocol.
An open question is how to specify the options conveniently for protocol maintainers.