Module use_case_bridge_server

Use-Case-Bridge-Server is an example of a application which employs Idefisk as a interface to the Asterisk PBX.

Copyright © 2005-2006 Ericsson

Version: 1.0

Behaviour: gen_server.

Authors: Freek Sanders (freekisanders@gmail.com) [web site: http://www.freeksanders.tk].

Description

Use-Case-Bridge-Server is an example of a application which employs Idefisk as a interface to the Asterisk PBX. Use-Case-Bridge-Server is started by the Idefisk-Supervisor (see idefisk_supervisor) and communicates with a given Ext-Ast-Interface instance through its process id. Use-Case-Bridge-Server uses Use-Case-Call (see use_case_call) to keep an intern record of created calls, legs and resources, as well as to receive messages.

Use Case Actions

When Use-Case-Bridge-Server receives a incoming message from Idefisk, it starts a new SingleBridge (see use_case_single_bridge). This SingleBridge communicates with ExtENS, resulting in the creation of another SingleBridge. This new SingleBridge registers with Use-Case-Bridge-Server (see use_case_bridge_server:register_bridge/3. The server then creates a new leg, of which the id is send to the new SingleBridge. Then the new leg is routed. When a 'answer' is received from Asterisk, the SingleBridge is alerted. The SingleBridge then contacts ExtENS to pass the 'answer' message. Meanwhile, the new leg is attached. ExtENS passes the 'answer' message to the original SingleBridge, which passes it to the Use-Case-Bridge-Server. The server then attaches the original leg, after which conversation can start.

When one party (i.e. leg) hangs up, the SingleBridge is alerted, and passes the message to ExtENS. ExtENS then alerts the other SingleBridge, which in turn passes the message to Use-Case-Bridge-Server. At receiving the message, Use-Case-Bridge-Server hangs up the remaining leg.


idefisk.conf Configuration

Set asterisk_ext_module to 'use_case_bridge_server' : {asterisk_ext_module, use_case_bridge_server}
Set asterisk_ext_module_start to 'true' : {asterisk_ext_module_start, true}
Set asterisk_ext_module_args to the BridgeServer : {asterisk_ext_module_args, [BridgeServerArgs::bridge_server_args()]}


(see the type definitions below)
More info about the format:
MORE INFO, I.E.:

StartId is where the id of the place where the Bridge-Server begins.
This can be a integer, atom or string.


Final Note

Use-Case-Bridge-Server has been implemented using the gen-server behaviour. This means that all function calls returning 'ok' (see below) are gen_server casts, which carry out their function asynchronously. An 'ok' does not mean success. If a function has success or not can only be derived from side-effects and messages printed to the command line.

For more information about the flow of events and an explanation of terms see ext_ast_interface.

Function Index

attach_leg/2Attaches a leg.
call_created_for_all_with_global_call_id/3*
call_leg_bridge_search/3*
call_msg/3A incoming call message.
create_dtmf_collector/3Creates a dtmf collector.
create_global_call_id/0*
create_leg/3Creates a new leg.
create_sound_player/3Creates a sound player.
die/0Destroys the use case.
divide_text/2*
divide_text/3*
get_all_rsrc_with_call_id/2*
get_all_rsrc_with_call_id_and_type/3*
get_all_rsrc_with_global_call_id_and_type/3*
get_all_rsrc_with_leg_id/2*
get_config_values/0*
get_item/3*
incoming_call/3A new caller has been detected by Asterisk.
keypop/3*
leg_msg/5A incoming leg message.
play_file/3Plays the indicated soundfile.
register_bridge/3A new SingleBridge has been created which has also received a IAM (Initial Address Message).
release_leg/4Releases a leg.
resource_msg/5A incoming resource message.
route_leg/4Routes a given leg.
start_phone/2*
stop_dtmf/2Stops the dtmf receiver.
stop_file/2Stops the sound player.
text_received/3Pronounce the given text.

Function Details

attach_leg/2

attach_leg(CallId::integer(), LegId::integer()) -> ok

Attaches a leg. Action: attach the specified leg of the given call.

Introduced in: 1.0

call_created_for_all_with_global_call_id/3 *

call_created_for_all_with_global_call_id(GlobalCallId, CallId, Bridges) -> term()

call_leg_bridge_search/3 *

call_leg_bridge_search(CallId, LegId, Bridges) -> term()

call_msg/3

call_msg(CallId::integer(), CallPid::pid(), Msg::string()) -> ok

A incoming call message.

Introduced in: 1.0

create_dtmf_collector/3

create_dtmf_collector(GlobalCallId::atom(), LegId::integer(), F::fun()) -> ok

Creates a dtmf collector. ExtENS instructs the BridgeServer to create a dtmf collector. Action: remember the GlobalCallId, LegId and Function for later use. Reserve a 'DTMF RECEIVER' resource.
When the resource is reserved, save its id, attach it, and send a message back to ExtENS using the F function.
When dtmf events are received, send the received digits to ExtENS using the F function.

Introduced in: 1.0

create_global_call_id/0 *

create_global_call_id() -> term()

create_leg/3

create_leg(CallId::integer(), OrigAddr::string(), DestAddr::string()) -> ok

Creates a new leg. Action: create a new leg, and eventually send back the leg id.

Introduced in: 1.0

create_sound_player/3

create_sound_player(GlobalCallId::atom(), LegId::integer(), F::fun()) -> ok

Creates a sound player. ExtENS instructs the BridgeServer to create a sound player. Action: remember the GlobalCallId, LegId and Function for later use. Reserve a 'SOUND PLAYER' resource.
When the resource is reserved, save its id, attach it, and send a message back to ExtENS using the F function.

Introduced in: 1.0

die/0

die() -> ok

Destroys the use case.

Introduced in: 1.0

divide_text/2 *

divide_text(Splitter, Text) -> term()

divide_text/3 *

divide_text(Splitter, T, Acc) -> term()

get_all_rsrc_with_call_id/2 *

get_all_rsrc_with_call_id(CallId, Rsrcs) -> term()

get_all_rsrc_with_call_id_and_type/3 *

get_all_rsrc_with_call_id_and_type(CallId, Type, Rsrcs) -> term()

get_all_rsrc_with_global_call_id_and_type/3 *

get_all_rsrc_with_global_call_id_and_type(GlobalCallId, Type, Rsrcs) -> term()

get_all_rsrc_with_leg_id/2 *

get_all_rsrc_with_leg_id(LegId, Rsrcs) -> term()

get_config_values/0 *

get_config_values() -> term()

get_item/3 *

get_item(Nr, Default, T) -> term()

incoming_call/3

incoming_call(CallId::integer(), OrigAddr::string(), DestAddr::string()) -> F::function()

A new caller has been detected by Asterisk. Ext-Ast-Interface alerts the use case to a incoming call. A incoming call means that both a call with id CallId and a leg with id 1 have been created.

Introduced in: 1.0

keypop/3 *

keypop(Key, N, TupleList1) -> term()

leg_msg/5

leg_msg(CallId::integer(), CallPid::pid(), LegId::integer(), LegPid::pid(), Msg::string()) -> ok

A incoming leg message.

Introduced in: 1.0

play_file/3

play_file(GlobalCallId::atom(), LegId::integer(), File::string()) -> ok

Plays the indicated soundfile. Action: start playing the indicated file.
Find the call id of the resource based on the GlobalCallId saved after the create_sound_player instruction.
The resource id is taken from the list of resource ids containing all resources, based on the 'SOUND PLAYER' type, CallId and LegId.

Introduced in: 1.0

register_bridge/3

register_bridge(BridgePid::pid(), CallId::integer(), GlobalCallId::string()) -> ok

A new SingleBridge has been created which has also received a IAM (Initial Address Message). Action: create a new leg, and eventually send back the leg id. Also create and attach a 'TEXT PRONOUNCER' resource for pronouncing text.

Introduced in: 1.0

release_leg/4

release_leg(SinglePid::pid(), CallId::integer(), LegId::integer(), Cause::string()) -> ok

Releases a leg. A SingleBridge (its pid being SinglePid) instructs the BridgeServer to release a leg. Action: release the specified leg of the given call, with the reason being indicated by the 'Cause' string.

Introduced in: 1.0

resource_msg/5

resource_msg(CallId::integer(), CallPid::pid(), RsrcId::integer(), RsrcPid::pid(), Msg::string()) -> ok

A incoming resource message.

Introduced in: 1.0

route_leg/4

route_leg(CallId::integer(), LegId::integer(), OrigAddr::string(), DestAddr::string()) -> ok

Routes a given leg. Action: route the specified leg of the given call to the indicated DestAddr with the originating address OrigAddr.

Introduced in: 1.0

start_phone/2 *

start_phone(OrigNumber, MSC) -> term()

stop_dtmf/2

stop_dtmf(GlobalCallId::atom(), LegId::integer()) -> ok

Stops the dtmf receiver. Action: stop receiving dtmf.
Find the call id of the resource based on the GlobalCallId saved after the create_sound_player instruction.
The resource id is taken from the list of resource ids containing all resources, based on the 'DTMF RECEIVER' type, CallId and LegId.

Introduced in: 1.0

stop_file/2

stop_file(GlobalCallId::atom(), LegId::integer()) -> ok

Stops the sound player. Action: stop playing the sound.
Find the call id of the resource based on the GlobalCallId saved after the create_sound_player instruction.
The resource id is taken from the list of resource ids containing all resources, based on the 'SOUND PLAYER' type, CallId and LegId.

Introduced in: 1.0

text_received/3

text_received(SinglePid::atom(), CallId::integer(), Text::string()) -> ok

Pronounce the given text. Action: add the given text to the current text.
If it contains a '.', command the Ext-Ast-Interface to pronounce everything before the point, and remove that from the current text.

Introduced in: 1.0