cut 3.3.0
Loading...
Searching...
No Matches
comms.multimaladapter.MultiMalAdapter Class Reference

Qt-based asynchronous MAL Request-Reply wrapper class. More...

Public Member Functions

 __init__ (self, str uri, bool autoconnect=False, bool async_if=False)
 Initializator for the MultiMalAdapter.
 
 set_timeout_connection (self, int timeout)
 Changes the default value for connection timeout.
 
 set_timeout_reply (self, int timeout)
 Changes the default value for reply timeout.
 
 get_interface (self)
 Returns the MAL RR client.
 
 get_mal (self)
 Returns the MAL implementation.
 
 get_factory (self)
 Returns the MAL factory.
 
bool is_autoconnection (self)
 Returns value autoconnection flag.
 
 set_autoconnection (self, bool new_value)
 Sets autoconnection flag.
 
bool is_connected (self)
 Indicates if the MalAdapter is currently connected or not.
 
 set_connection (self, bool new_value, int connection_timeout=DEFAULT_CONNECTION_TIMEOUT, int reply_timeout=DEFAULT_REPLY_TIMEOUT, bool force_connection=False)
 Main interaction point of the class.
 
 on_connection_changed (self, bool new_value)
 Handles reconnection if needed, this is the callback for autoconnection.
 
list[str] query_commands (self)
 Prepares a list of method names that this server offers through its services.
 
str get_method_arg_type (self, str method_query)
 Returns the datatype (MAL ICD string that defines the datatype) or the first argument of the method.
 
 get_timeout_millis (self)
 Returns the current timeout value for commands.
 
 set_timeout_millis (self, int timeout)
 Sets the timeout value for execution of commands.
 
 __getattr__ (self, name)
 Overrides.
 
Any command_inout (self, str cmd, list|None params=None)
 Executes a command in the MAL RR Server.
 
Task command_in_task (self, str cmd, list|None params=None, started_slot=None, cancelled_slot=None, progress_slot=None, result_slot=None, error_slot=None, finished_slot=None, no_start=False)
 Executes a command asynchronously via Task.
 

Static Public Attributes

 connection_changed = Signal(bool)
 Emitted when the connection state changes.
 
 connected
 Qt Property that indicates if the MalAdapter is "connected" or not.
 

Protected Member Functions

 _set_connected (self, bool state)
 Sets the property "connected" to true, and emits the connectionChanged signal.
 
 _connection_listener (self, bool status)
 Callback method for the MAL RR register listener.
 
 _connect (self, int connection_timeout=DEFAULT_CONNECTION_TIMEOUT, int reply_timeout=DEFAULT_REPLY_TIMEOUT)
 Implements the actual connection to the MAL Request Reply interface.
 
MalRRService _connect_to_service (self, str path, str if_xml, int connection_timeout=3000, int reply_timeout=3000)
 Implements the actual connection to the MAL Request Reply interface.
 
Type|None _replace_sync_for_async (self, Type interface_class)
 Returns the Async version of the MAL interface, given the Sync one.
 

Detailed Description

Qt-based asynchronous MAL Request-Reply wrapper class.

Handles Requests and connection.

The MultiMalAdapter provides a complete solution to access a MAL RR server and its services. It is intended to be used in the MAL RR Plugin, but a developer may access still MAL and MAL Factory objects and directly invoke the services methods.

MultiMalAdapter also provides the connected Property, with the connection_changed(bool) Signal. Please use this Signal to program event based changes for your applications.

See also
Logger
QObject

Constructor & Destructor Documentation

◆ __init__()

comms.multimaladapter.MultiMalAdapter.__init__ ( self,
str uri,
bool autoconnect = False,
bool async_if = False )

Initializator for the MultiMalAdapter.

The MultiMalAdapter provides a complete solution to access a MAL RR server and its services. It is intended to be used in the MAL RR Plugin, but a developer may access still MAL and MAL Factory objects and directly invoke the services methods.

It requires a URI and allows so determine if the class instance will automatically connect to the server.

Parameters
uriURI of the MAL Reply Request Endpoint
autoconnectBoolean that indicates if the object will start and retry automatically its connection.
async_ifBoolean, if True the MultiMalAdapter class will use the Async interface

Member Function Documentation

◆ __getattr__()

comms.multimaladapter.MultiMalAdapter.__getattr__ ( self,
name )

Overrides.

Note
This is necessary due to the TaurusCommandButton requiring both certain command be available at the modelObj level.

◆ _connect()

comms.multimaladapter.MultiMalAdapter._connect ( self,
int connection_timeout = DEFAULT_CONNECTION_TIMEOUT,
int reply_timeout = DEFAULT_REPLY_TIMEOUT )
protected

Implements the actual connection to the MAL Request Reply interface.

This method is started in another thread, so certain member need to be protected by using threading.RLock.

It will try to connect to the Introspection interface to execute GetInterfaces(). From its results, it will then connect to the offered services.

◆ _connect_to_service()

MalRRService comms.multimaladapter.MultiMalAdapter._connect_to_service ( self,
str path,
str if_xml,
int connection_timeout = 3000,
int reply_timeout = 3000 )
protected

Implements the actual connection to the MAL Request Reply interface.

This method is started in another thread, so certain member need to be protected by using threading.RLock.

◆ _connection_listener()

comms.multimaladapter.MultiMalAdapter._connection_listener ( self,
bool status )
protected

Callback method for the MAL RR register listener.

Parameters
[in]statusbool with the new status of connection

◆ _replace_sync_for_async()

Type|None comms.multimaladapter.MultiMalAdapter._replace_sync_for_async ( self,
Type interface_class )
protected

Returns the Async version of the MAL interface, given the Sync one.

Parameters
[in]interface_classClass Type of the Sync MAL interface
Returns
Class Type of the Async MAL interface

◆ command_in_task()

Task comms.multimaladapter.MultiMalAdapter.command_in_task ( self,
str cmd,
list | None params = None,
started_slot = None,
cancelled_slot = None,
progress_slot = None,
result_slot = None,
error_slot = None,
finished_slot = None,
no_start = False )

Executes a command asynchronously via Task.

Future results, result/error is handled through signals.

Parameters
[in]cmdCommand name
[in]paramsParameters list for the command to be executed.
[in]started_slotOptional slot called when the Task starts.
[in]cancelled_slotOptional slot called when the Task is cancelled.
[in]progress_slotOptional slot called with AMI (multiple replies) values.
[in]result_slotOptional slot called with the resolved result.
[in]error_slotOptional slot called on error.
[in]finished_slotOptional slot called when the task finishes.
[in]no_startReturns an unstarted Task. Useful for further configuration or testing.
Returns
Task The Task instance executing the command.

◆ command_inout()

Any comms.multimaladapter.MultiMalAdapter.command_inout ( self,
str cmd,
list | None params = None )

Executes a command in the MAL RR Server.

The command in question is identified by #cmd and uses #params as the parameters for the command execution.

Parameters
[in]cmdCommand name
[in]paramsParameters list for the command to be executed.
Returns
Any object. It depends on the underlying command.

◆ get_factory()

comms.multimaladapter.MultiMalAdapter.get_factory ( self)

Returns the MAL factory.

Use it to create structures.

◆ get_method_arg_type()

str comms.multimaladapter.MultiMalAdapter.get_method_arg_type ( self,
str method_query )

Returns the datatype (MAL ICD string that defines the datatype) or the first argument of the method.

Parameters
[in]method_queryMethod name as a string
Returns
string name of the parameter, one of 'string' 'boolean' 'double' 'uint8_t', etc

◆ on_connection_changed()

comms.multimaladapter.MultiMalAdapter.on_connection_changed ( self,
bool new_value )

Handles reconnection if needed, this is the callback for autoconnection.

Parameters
[in]new_valueBoolean, new connection state

◆ set_connection()

comms.multimaladapter.MultiMalAdapter.set_connection ( self,
bool new_value,
int connection_timeout = DEFAULT_CONNECTION_TIMEOUT,
int reply_timeout = DEFAULT_REPLY_TIMEOUT,
bool force_connection = False )

Main interaction point of the class.

Developers should invoke this to start a connection attempt, or request disconnection.

It does decision logic based on the state of connection.

If connection is requested, and is already connected, it will do nothing. If disconnection is requested, and is already disconnected, it will do nothing.

Parameters
[in]new_valueBoolean. True to connect, False to disconnect
[in]connection_timeoutint. Timeout for connection attemp in milliseconds
[in]reply_timeoutint. Timeout for replies in milliseconds
[in]force_connectionbool. Set to True to ignore an ongoing connection request and try anyways.

◆ set_timeout_millis()

comms.multimaladapter.MultiMalAdapter.set_timeout_millis ( self,
int timeout )

Sets the timeout value for execution of commands.

Todo
: This is an incomplete workwaround. In the case of MalAdapter works, but for MultiMalAdapter, it needs to be applied to all services.

Member Data Documentation

◆ connected

comms.multimaladapter.MultiMalAdapter.connected
static
Initial value:
= Property(
bool, fget=is_connected, fset=_set_connected, notify=connection_changed
)

Qt Property that indicates if the MalAdapter is "connected" or not.

A bool that is true if connected, false when not. The MAL RR Client provides a connectionListener callback that informs of status changes. When status changes the connectionChanged signal is fired. It carries as argument the new status.

◆ connection_changed

comms.multimaladapter.MultiMalAdapter.connection_changed = Signal(bool)
static

Emitted when the connection state changes.

Provides two states: Connected (True) or Disconnected (False).

Parameters
boolNew state of connection: True = connected; False = disconnected

The documentation for this class was generated from the following file: