This module defines the callback behaviour of Megaco users. A megaco_user compliant callback module must export the following functions:
The semantics of them and their exact signatures are explained below.
The
but if the
Must of the functions below has an optional
The record initially returned by
Is the actual protocol version. In most cases the protocol version is retrieved from the processed message, but there are exceptions:
When
In these cases, the ProtocolVersion default version is obtained from the static connection configuration:
Invoked when a new connection is established
Connections may either be established by an explicit call to megaco:connect/4 or implicitly at the first invocation of megaco:receive_message/3.
Normally a Media Gateway (MG) connects explicitly while a Media Gateway Controller (MGC) connects implicitly.
At the Media Gateway Controller (MGC) side it is possible to reject
a connection request (and send a message error reply to the gateway)
by returning
See
Invoked when a connection is teared down
The disconnect may either be made explicitly by a call to megaco:disconnect/2 or implicitly when the control process of the connection dies.
Invoked when a received message had syntax errors
Incoming messages is delivered by megaco:receive_message/4 and normally decoded successfully. But if the decoding failed this function is called in order to decide if the originator should get a reply message (reply) or if the reply silently should be discarded (no_reply).
Syntax errors are detected locally on this side of the protocol and may have many causes, e.g. a malfunctioning transport layer, wrong encoder/decoder selected, bad configuration of the selected encoder/decoder etc.
The error descriptor defaults to
Any other return values (including exit signals or throw) and the
See
Invoked when a received message just contains an error instead of a list of transactions.
Incoming messages is delivered by megaco:receive_message/4 and successfully decoded. Normally a message contains a list of transactions, but it may instead contain an ErrorDescriptor on top level of the message.
Message errors are detected remotely on the other side of the protocol. And you probably don't want to reply to it, but it may indicate that you have outstanding transactions that not will get any response (request -> reply; reply -> ack).
See
Invoked for each transaction request
Incoming messages is delivered by megaco:receive_message/4 and successfully decoded. Normally a message contains a list of transactions and this function is invoked for each TransactionRequest in the message.
This function takes a list of 'ActionRequest' records and has three main options:
Decide that these action requests shall be ignored completely.
Decide that the processing of these action requests will take a long time and that the originator should get an immediate 'TransactionPending' reply as interim response. The actual processing of these action requests instead should be delegated to the the handle_trans_long_request/3 callback function with the req_data() as one of its arguments.
Process the action requests and either return an error_descr() indicating some fatal error or a list of action replies (wildcarded or not).
If for some reason megaco is unable to deliver the reply,
the reason for this will be passed to the user via a call
to the callback function
The ack_action() is either:
Meaning that you don't care if the reply is acknowledged or not.
Meaning that you want an immediate acknowledgement when the other part receives this transaction reply. When the acknowledgement eventually is received, the handle_trans_ack/4 callback function will be invoked with the ack_data() as one of its arguments. ack_data() may be any Erlang term.
This has the same effect as the above, if and only if megaco has sent at least one pending message for this request (during the processing of the request). If no pending message has been sent, then immediate acknowledgement will not be requested.
Note that this only works as specified if the
Meaning that you want an acknowledgement sometime. When the acknowledgement eventually is received, the handle_trans_ack/4 callback function will be invoked with the ack_data() as one of its arguments. ack_data() may be any Erlang term.
Any other return values (including exit signals or throw) will result in an error descriptor with code 500 (internal gateway error) and the module name (of the callback module) as reason.
See
Optionally invoked for a time consuming transaction request
If this function gets invoked or not is controlled by the reply from the preceding call to handle_trans_request/3. The handle_trans_request/3 function may decide to process the action requests itself or to delegate the processing to this function.
The req_data() argument to this function is the Erlang term returned by handle_trans_request/3.
Any other return values (including exit signals or throw) will result in an error descriptor with code 500 (internal gateway error) and the module name (of the callback module) as reason.
See
Optionally invoked for a transaction reply
The sender of a transaction request has the option of
deciding, whether the originating Erlang process should
synchronously wait (
Note that if the reply is segmented (split into several smaller
messages; segments), then some extra info, segment number and
an indication if all segments of a reply has been received or
not, is also included in the
The
At
A list of 'ActionReply' records possibly containing error indications.
A tuple of size three containing:
the segment number,
the
A
A
A
A
An
See
Optionally invoked for a transaction acknowledgement
If this function gets invoked or not, is controlled by the reply from the preceding call to handle_trans_request/3. The handle_trans_request/3 function may decide to return {handle_ack, ack_data()} or {handle_sloppy_ack, ack_data()} meaning that you need an immediate acknowledgement of the reply and that this function should be invoked to handle the acknowledgement.
The ack_data() argument to this function is the Erlang term returned by handle_trans_request/3.
If the AckStatus is ok, it is indicating that this is a true acknowledgement of the transaction reply.
If the AckStatus is {error, Reason}, it is an indication that the acknowledgement or even the reply (for which this is an acknowledgement) was not delivered, but there is no point in waiting any longer for it to arrive. This happens when:
The
When megaco fails to send the reply (see
The user has explicitly cancelled the wait (megaco:cancel/2).
See
Invoked when a unexpected message is received
If a reply to a request is not received in time, the megaco stack removes all info about the request from its tables. If a reply should arrive after this has been done the app has no way of knowing where to send this message. The message is delivered to the "user" by calling this function on the local node (the node which has the link).
See
Invoked when a transaction request has been aborted
This function is invoked if the originating pending limit has been exceeded. This usually means that a request has taken abnormally long time to complete.
See
This function is called when a segment reply has been received
if the
This is in effect a progress report.
See