2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								<?xml version="1.0" encoding="UTF-8" ?> 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-14 14:18:53 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								<class  name= "JSONRPC"  inherits= "Object"  version= "4.0"  xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation= "../class.xsd" > 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									<brief_description > 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-05 14:30:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										A helper to handle dictionaries which look like JSONRPC documents.
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									</brief_description> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									<description > 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-05 14:30:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										[url=https://www.jsonrpc.org/]JSON-RPC[/url] is a standard which wraps a method call in a [JSON] object. The object has a particular structure and identifies which method is called, the parameters to that function, and carries an ID to keep track of responses. This class implements that standard on top of [Dictionary]; you will have to convert between a [Dictionary] and [JSON] with other functions.
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									</description> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									<tutorials > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									</tutorials> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									<methods > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										<method  name= "make_notification" > 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-30 15:28:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<return  type= "Dictionary"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-06 21:11:48 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<param  index= "0"  name= "method"  type= "String"  /> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											<param  index= "1"  name= "params"  type= "Variant"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											<description > 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-05 14:30:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												Returns a dictionary in the form of a JSON-RPC notification. Notifications are one-shot messages which do not expect a response.
							 
						 
					
						
							
								
									
										
										
										
											2022-08-12 09:36:48 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												- [param method]: Name of the method being called.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												- [param params]: An array or dictionary of parameters being passed to the method.
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											</description> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										</method> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										<method  name= "make_request" > 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-30 15:28:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<return  type= "Dictionary"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-06 21:11:48 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<param  index= "0"  name= "method"  type= "String"  /> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											<param  index= "1"  name= "params"  type= "Variant"  /> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											<param  index= "2"  name= "id"  type= "Variant"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											<description > 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-05 14:30:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												Returns a dictionary in the form of a JSON-RPC request. Requests are sent to a server with the expectation of a response. The ID field is used for the server to specify which exact request it is responding to.
							 
						 
					
						
							
								
									
										
										
										
											2022-08-12 09:36:48 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												- [param method]: Name of the method being called.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												- [param params]: An array or dictionary of parameters being passed to the method.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												- [param id]: Uniquely identifies this request. The server is expected to send a response with the same ID.
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											</description> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										</method> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										<method  name= "make_response" > 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-30 15:28:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<return  type= "Dictionary"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-06 21:11:48 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<param  index= "0"  name= "result"  type= "Variant"  /> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											<param  index= "1"  name= "id"  type= "Variant"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											<description > 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-05 14:30:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												When a server has received and processed a request, it is expected to send a response. If you did not want a response then you need to have sent a Notification instead.
							 
						 
					
						
							
								
									
										
										
										
											2022-08-12 09:36:48 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												- [param result]: The return value of the function which was called.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												- [param id]: The ID of the request this response is targeted to.
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											</description> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										</method> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										<method  name= "make_response_error"  qualifiers= "const" > 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-30 15:28:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<return  type= "Dictionary"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-06 21:11:48 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<param  index= "0"  name= "code"  type= "int"  /> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											<param  index= "1"  name= "message"  type= "String"  /> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											<param  index= "2"  name= "id"  type= "Variant"  default= "null"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											<description > 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-05 14:30:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												Creates a response which indicates a previous reply has failed in some way.
							 
						 
					
						
							
								
									
										
										
										
											2022-08-12 09:36:48 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												- [param code]: The error code corresponding to what kind of error this is. See the [enum ErrorCode] constants.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												- [param message]: A custom message about this error.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												- [param id]: The request this error is a response to.
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											</description> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										</method> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										<method  name= "process_action" > 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-30 15:28:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<return  type= "Variant"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-06 21:11:48 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<param  index= "0"  name= "action"  type= "Variant"  /> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											<param  index= "1"  name= "recurse"  type= "bool"  default= "false"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											<description > 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-05 14:30:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												Given a Dictionary which takes the form of a JSON-RPC request: unpack the request and run it. Methods are resolved by looking at the field called "method" and looking for an equivalently named function in the JSONRPC object. If one is found that method is called.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												To add new supported methods extend the JSONRPC class and call [method process_action] on your subclass.
							 
						 
					
						
							
								
									
										
										
										
											2022-08-12 09:36:48 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												[param action]: The action to be run, as a Dictionary in the form of a JSON-RPC request or notification.
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											</description> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										</method> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										<method  name= "process_string" > 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-30 15:28:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<return  type= "String"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-06 21:11:48 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<param  index= "0"  name= "action"  type= "String"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											<description > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											</description> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										</method> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										<method  name= "set_scope" > 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-30 15:28:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<return  type= "void"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-06 21:11:48 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											<param  index= "0"  name= "scope"  type= "String"  /> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											<param  index= "1"  name= "target"  type= "Object"  /> 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											<description > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											</description> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										</method> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									</methods> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									<constants > 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-24 11:44:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										<constant  name= "PARSE_ERROR"  value= "-32700"  enum= "ErrorCode" > 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										</constant> 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-24 11:44:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										<constant  name= "INVALID_REQUEST"  value= "-32600"  enum= "ErrorCode" > 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										</constant> 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-24 11:44:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										<constant  name= "METHOD_NOT_FOUND"  value= "-32601"  enum= "ErrorCode" > 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-05 14:30:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											A method call was requested but no function of that name existed in the JSONRPC subclass.
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										</constant> 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-24 11:44:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										<constant  name= "INVALID_PARAMS"  value= "-32602"  enum= "ErrorCode" > 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										</constant> 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-24 11:44:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										<constant  name= "INTERNAL_ERROR"  value= "-32603"  enum= "ErrorCode" > 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-29 15:33:52 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										</constant> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									</constants> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								</class>