'Adds a message listener function that will be called every time the specified message is received.
.. tip::
We recommend you use :py:func:`on_message` instead of this method as it has a more elegant syntax.
This method is only preferred if you need to be able to
:py:func:`remove the listener <remove_message_listener>`.
The callback function must have three arguments:
* ``self`` - the current vehicle.
* ``name`` - the name of the message that was intercepted.
* ``message`` - the actual message (a `pymavlink <http://www.qgroundcontrol.org/mavlink/pymavlink>`_
`class <https://www.samba.org/tridge/UAV/pymavlink/apidocs/classIndex.html>`_).
For example, in the fragment below ``my_method`` will be called for every heartbeat message:
.. code:: python
#Callback method for new messages
def my_method(self, name, msg):
pass
vehicle.add_message_listener(\'HEARTBEAT\',my_method)
See :ref:`mavlink_messages` for more information.
:param String name: The name of the message to be intercepted by the listener function (or \'*\' to get all messages).
:param fn: The listener function that will be called if a message is received.'

def add_message_listener(self, name, fn):

    name = str(name)
    if (name not in self._message_listeners):
        self._message_listeners[name] = []
    if (fn not in self._message_listeners[name]):
        self._message_listeners[name].append(fn)
