RPC Message

Message exchanged in SHV is IMap with meta-data attached from RPC Value point of view.

There are three kinds of RPC messages defined:

RPC message can have meta-data attribute defined.

Attribute numberAttribute nameTypeDescription
1MetaTypeIdIntAlways equal to 1 in case of RPC message
2MetaTypeNameSpaceIdIntAlways equal to 0 in case of RPC message, may be omitted.
8RequestIdIntEvery RPC request must have unique number per client. Matching RPC response will have the same number.
9ShvPathStringPath on which method will be called.
10Method/SignalStringName of called RPC method or raised signal.
11CallerIdsList of IntInternal attribute filled by broker in request message to distinguish requests with the same request ID, but issued by different clients.
13RevCallerIdsList of IntReserved for SHV v2 broker compatibility
14AccessStringAccess granted by broker for called shvPath and method to current user. This should be used only for extra access info and for backward compatibility while AccessLevel is prefered instead.
16UserIdStringID of user calling RPC method.
17AccessLevelIntAccess level user has assigned for request or minimal access level needed to allow signal to be received.
18SeqNoIntReserved, it will be used in next API version for multi-part messages https://github.com/silicon-heaven/libshv/wiki/multipart-messages
19SourceStringUsed for signals to store method name this signal is associated with.
20RepeatBoolUsed for signals to informat that signal was emited as a repeat of some older ones (that might not might not have been sent).

Second part of RPC message is IMap with following possible keys.

KeyKey nameDescription
1ParamsOptional method parameters, any RPC Value is allowed.
2ResultSuccessful method call result, any RPC Value is allowed.
3ErrorMethod call exception, see RPC error for more details
4DelayMethod call result delay, Double is allowed.
5AbortMethod call abort (true) or state query (false), Bool is allowed.

RequestId can be any unique number assigned by side that sends request initially. It is used to pair up requests with their responses. The common approach is to just use request message counter as request ID.

CallerIds are related to the broker and unless you are implementing a broker you need to know only that they are additional identifiers for the message alongside the RequestId to pair requests with their responses and thus should be always included in the response message if they were present in the request.

The ShvPath is used to select exact node of method in the SHV tree.

AccessLevel is the way to specify access level. It is numerical with predefined range (0-63) and brokers on the way can lower this number to even further limit access. Broker are prohibited to increase this number. Access should be used to get level if this field is not present. Admin access level should be considered as the base limit if neither AccessLevel nor Access field is present.

userId is string containing information about the login names and the broker names along the RPC message path through the brokers hierarchy. The format isuser-name1:broker-name1;user-name2:broker-name2;..., for example: john@foo.bar:broker1;broker1-login:broker2. User name and broker name is delimited by :, user:broker pairs are delimited by ';'.

Access is older approach for the access control. It is assigned to request by broker according to user rights. Multiple grants can be specified and separated by comma. This is no longer the primary way and is used only for pre-SHV 3.0 peers or if additional access fields are specified.

The following are all defined AccessLevels and their Access representations:

NameNumerical representationAccess representation
Browse1bws
Read8rd
Write16wr
Command24cmd
Config32cfg
Service40srv
Super-service48ssrv
Development56dev
Admin63su

Request

Message used to invoke remote method.

Methods invoked using this request needs to be idempotent, because RPC transport layers do not ensure deliverability. You might also want to try to send request again when you receive no response because of this.

Attributes:

AttributeRequiredBroker propagationNote
MetaTypeIdyescopied
RequestIdyescopied
ShvPathyesmatched prefix removed
Methodyescopied
CallerIdsnobroker's path identifier can be added to the listAdded and modified by brokers
RevCallerIdsnobroker's reverse path identifier can be removed from the listIf tunneling or multi-part message is needed
Accessnoset and modifiedMust be kept in sync with AccessLevel or not specified at all
AccessLevelnoset and modifiedBroker always only reduces the already present value
UserIdnoappended if presentAppend to non-zero string with comma

Keys (only one can be used in the single message):

Key nameRequiredNote
ParamsnoAny valid RPC Value
AbortyesBool where true forces abort and false only immediate Reponse (thus it can be Delay).

Examples

RPC call invocation, method switchLeft on path test/pme/849V with request ID 56 and parameter true.

<1:1,8:56,9:"test/pme/849V",10:"switchLeft">i{1:true}

Response

Response to Request. The response should be generated as soon as possible. If some work has to be performed before full response can be generated then Response Delay can be sent in reasonable intervals, until Result or Error is prepared.

Attributes:

AttributeRequiredBroker propagationNote
MetaTypeIdyescopied
RequestIdyescopied
CallerIdsnobroker's path identifier must be removed from the listSender must copy original value form Request if present.
RevCallerIdsnobroker's reverse path identifier can be removed added to the listSender must copy original value form Request if present.

Keys (only one can be used in the single message):

Key nameRequiredNote
ResultUsed in case of successful method call result, any RPC Value is allowed. Result is considered to be Null if Result key is missing.
ErroryesRequired in case of method call exception, see RPC error for more details.
DelayyesRequired in case nor Result or Error can't be generated immediately. The value is Double from 0 to 1.

RpcResponse is invalid when both keys (Result and Error) are present.

RPC Error

RPC Error is IMap with following keys defined

KeyKey nameRequiredDescription
1CodeyesError code
2MessagenoError message string
3DatanoArbitrary payload, can be used for example for exception localization additional info.

Error codes:

ValueNameDescription
1Reserved for backward compatibility
2MethodNotFoundThe method does not exist or is not available or not accessible with given access level.
3InvalidParamsInvalid method parameter.
4Reserved for backward compatibility
5Reserved for backward compatibility
6ImplementationReserved1Won't ever be used in the communication and is reserved for implementations usage (such as signaling method timeout)
7ImplementationReserved2Same as ImplementationReserved1
8MethodCallExceptionGeneric execution exception of the method.
9ImplementationReserved3Same as ImplementationReserved1
10LoginRequiredMethod call without previous successful login.
11UserIDRequiredMethod call requires UserID to be present in the request message. Send it again with UserID.
12NotImplementedCan be used if method is valid but not implemented for what ever reason.
13TryAgainLaterUsed in cases when request can't be handled now but might be in the future.
14RequestInvalidUsed exclusively for Abort request. It doesn't specify if invalidation is caused by Abort just that there is no such request
32+MethodCallExceptionSpecificApplication specific MethodCallException

Examples

Successful response to method call from example above

<1:1,8:56>i{2:true}

Exception when unknown method is called

<1:1,8:11>i{3:i{1:8,2:"method: foo path: what: Method: 'foo' on path 'shv/cze' doesn't exist"}}

Signal

Spontaneous message sent without prior request and thus without RequestId. It is used mainly notify clients that some technological value had changed without need to poll.

Attributes:

AttributeRequiredBroker propagationNote
MetaTypeIdyescopied
ShvPathyesmouint point of the source is prefixed
SignalnocopiedIf not specified "chng" is assumed
SourcenocopiedIf not specified "get" is assumed)
AccessLevelnocopiedUsed to decide signal propagation on brokers, if not specified Read is assumed
UserIdnocopied
RepeatnocopiedIf not specified false is assumed

Keys:

KeyRequiredNote
ParamsnoAny valid RPC Value

Warning: all signal names ending with chng (that includes chng and others such as fchng) are considered as property changes of the method they are associated with, and thus cache can use to update its state them instead of method call. If your method emits signals with different parameter than response's result then do not use signal names ending with chng.

Examples

Spontaneous notification about change of status/motorMoving property to true.

<1:1,9:"shv/test/pme/849V/status/motorMoving",10:"chng",11:"get">i{1:true}