Mark,<br><br>You might want to send this question to <a href="mailto:freeswitch-dev@lists.freeswitch.org">freeswitch-dev@lists.freeswitch.org</a> as it's a bit intense for the users list. :)<br>-MC<br><br><div class="gmail_quote">
On Tue, Sep 15, 2009 at 7:38 AM, Mark Sobkow <span dir="ltr"><<a href="mailto:m.sobkow@marketelsystems.com">m.sobkow@marketelsystems.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I still need to stuff the Freeswitch PID into global storage somewhere so the process that's handling the configuration requests can send the reply without crashing (it's just getting a node id, not a Pid), but I seem to be on my way to configuring Freeswitch via ERLang.<br>
<br>
freeswitch_bind.erl has the calls added to register the ERLang callbacks. The callback function itself is in the aptly named freeswitch_callback.erl.<br>
<br>-module(freeswitch_bind).<br>
<br>
-behaviour(gen_server).<br>
<br>
-record(st, {fsnode, pbxpid, configpid, dirpid, dialpid}).<br>
<br>
-export([start/3, terminate/2, code_change/3, init/1,<br>
handle_call/3, handle_cast/2, handle_info/2]).<br>
<br>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<br>
%% gen_server methods<br>
start(Node, Section, Pid) -><br>
gen_server:start(?MODULE, [Node, Section, Pid], []).<br>
<br>
init([Node, Section, Pid]) -><br>
io:format( "freeswitch_bind:init( [Node=~w, Section=~w, Pid=~w])~n", [Node, Section, Pid] ),<br>
{api, Node} ! {bind, Section},<br>
receive<br>
ok -><br>
{ok, ConfigurationPid } = freeswitch:start_fetch_handler( Node, configuration, freeswitch_callback, fetch_handler ),<br>
{ok, DirectoryPid } = freeswitch:start_fetch_handler( Node, directory, freeswitch_callback, fetch_handler ),<br>
{ok, DialplanPid } = freeswitch:start_fetch_handler( Node, dialplan, freeswitch_callback, fetch_handler ),<br>
{ok, #st{fsnode=Node, pbxpid=Pid, configpid=ConfigurationPid, dirpid=DirectoryPid, dialpid=DialplanPid}};<br>
{error, Reason} -><br>
{stop, {error, {freeswitch_error, Reason}}}<br>
after 5000 -><br>
{stop, {error, freeswitch_timeout}}<br>
end.<br>
<br>
terminate(_Reason, _State) -><br>
ok.<br>
<br>
code_change(_OldVsn, State, _Extra) -><br>
{ok, State}.<br>
<br>
%%<br>
%% If the request isn't recognized, just log it and do nothing.<br>
%%<br>
handle_call(Request, _From, State) -><br>
io:format("freeswitch_bind:handle_call( ~w, _From, State) unrecognized request~n",<br>
[Request]),<br>
{reply, {error, unrecognized_request}, State}.<br>
<br>
handle_cast(Message, State) -><br>
error_logger:error_msg("~p received unrecognized cast ~p~n",<br>
[self(), Message]),<br>
{noreply, State}.<br>
<br>
handle_info({fetch, Section, Tag, Key, Value, FetchID, Params}, #st{fsnode=Node, pbxpid=Pid}=State) -><br>
{ok, XML} = gen_server:call(Pid, {fetch, Section, Tag, Key, Value, Params}),<br>
{api, Node} ! {fetch_reply, FetchID, XML},<br>
receive<br>
ok -><br>
{noreply, State};<br>
{error, Reason} -><br>
{stop, {error, Reason}, State}<br>
end.<br>
<br>%% Author: mark<br>
%% Created: Sep 15, 2009<br>
%% Description: TODO: Add description to freeswitch_callback<br>
-module(freeswitch_callback).<br>
<br>
-behaviour(gen_server).<br>
<br>
-record(st, {fsnode, pbxpid}).<br>
<br>
-export([start/3, terminate/2, code_change/3, init/1,<br>
handle_call/3, handle_cast/2, handle_info/2, fetch_handler/1]).<br>
<br>
start(Node, Section, Pid) -><br>
gen_server:start(?MODULE, [Node, Section, Pid], []).<br>
<br>
init([Node, Section, Pid]) -><br>
io:format( "freeswitch_callback:init( [Node=~w, Section=~w, Pid=~w])~n", [Node, Section, Pid] ),<br>
{ok, #st{fsnode=Node, pbxpid=Pid}}.<br>
<br>
terminate(_Reason, _State) -><br>
ok.<br>
<br>
code_change(_OldVsn, State, _Extra) -><br>
{ok, State}.<br>
<br>
%%<br>
%% Callback for freeswitch:start_fetch_handler() called in freeswitch_bind:init()<br>
%%<br>
fetch_handler( FreeswitchNode ) -><br>
receive<br>
{ nodedown, Node } -><br>
io:format( "freeswitch_callback:fetch_handler() Node ~w is down~n", [Node] ),<br>
ok;<br>
{ fetch, Section, Tag, Key, Value, FetchId, Params } -><br>
io:format( "freeswitch_callback:fetch_handler() Invoking xml_fetch()~n" ),<br>
{ok, Xml} = xml_fetch( {fetch, Section, Tag, Key, Value, Params} ),<br>
io:format( "freeswitch_callback:fetch_handler() Sending reply to FreeswitchNode ~w: ~s~n", [FreeswitchNode, Xml] ),<br>
FreeswitchNode ! { fetch_reply, FetchId, Xml },<br>
io:format( "freeswitch_callback:fetch_handler() Reply sent~n" ),<br>
ok<br>
end,<br>
{ ok } = fetch_handler( FreeswitchNode ),<br>
{ ok }.<br>
<br>
%%<br>
%% Configuration handler replies that the requested document section, tag, and key are not<br>
%% found.<br>
%%<br>
xml_fetch({fetch, configuration, Tag, Key, Value, Params}) -><br>
io:format( "freeswitch_callback:handle_call( {fetch, configuration, Tag=~s, Key=~s, Value=~s, Params=~w} )~n",<br>
[Tag, Key, Value, Params]),<br>
Xml =<br>
"<document type=\"freeswitch/xml\"><br>
<section name=\"result\"><br>
<result status=\"not found\" /><br>
</section><br>
</document>",<br>
{ok, Xml };<br>
<br>
%%<br>
%% Directory handler replies that the requested document section, tag, and key are not<br>
%% found.<br>
%%<br>
xml_fetch({fetch, directory, Tag, Key, Value, Params}) -><br>
io:format( "freeswitch_callback:xml_fetch( {fetch, directory, Tag=~s, Key=~s, Value=~s, Params=~w} )~n",<br>
[Tag, Key, Value, Params]),<br>
Xml =<br>
"<document type=\"freeswitch/xml\"><br>
<section name=\"result\"><br>
<result status=\"not found\" /><br>
</section><br>
</document>",<br>
{ok, Xml };<br>
<br>
%%<br>
%% Dialplan handler replies that the requested document section, tag, and key are not<br>
%% found.<br>
%%<br>
xml_fetch({fetch, dialplan, Tag, Key, Value, Params}) -><br>
io:format( "freeswitch_callback:xml_fetch( {fetch, dialplan, Tag=~s, Key=~s, Value=~s, Params=~w} )~n",<br>
[Tag, Key, Value, Params]),<br>
Xml =<br>
"<document type=\"freeswitch/xml\"><br>
<section name=\"result\"><br>
<result status=\"not found\" /><br>
</section><br>
</document>",<br>
{ok, Xml };<br>
<br>
%%<br>
%% Default handler replies that the requested document section, tag, and key are not<br>
%% found.<br>
%%<br>
xml_fetch({fetch, Section, Tag, Key, Value, Params}) -><br>
io:format( "freeswitch_callback:xml_fetch( {fetch, Section=~w, Tag=~s, Key=~s, Value=~s, Params=~w} )~n",<br>
[Section, Tag, Key, Value, Params]),<br>
Xml =<br>
"<document type=\"freeswitch/xml\"><br>
<section name=\"result\"><br>
<result status=\"not found\" /><br>
</section><br>
</document>",<br>
{ok, Xml };<br>
<br>
%%<br>
%% If the request isn't recognized, just log it.<br>
%%<br>
xml_fetch( Request ) -><br>
io:format( "freeswitch_callback:xml_fetch( Request=~w ) not recognized~n",<br>
[Request]),<br>
Xml =<br>
"<document type=\"freeswitch/xml\"><br>
<section name=\"result\"><br>
<result status=\"not found\" /><br>
</section><br>
</document>",<br>
{ok, Xml }.<br>
<br>
<br>
%%<br>
%% If the request isn't recognized, just log it and do nothing.<br>
%%<br>
handle_call(Request, _From, State) -><br>
io:format("freeswitch_callback:handle_call( ~w, _From, State) unrecognized request~n",<br>
[Request]),<br>
{reply, {error, unrecognized_request}, State}.<br>
<br>
handle_cast(Message, State) -><br>
error_logger:error_msg("~p received unrecognized cast ~p~n",<br>
[self(), Message]),<br>
{noreply, State}.<br>
<br>
handle_info({fetch, Section, Tag, Key, Value, FetchID, Params}, #st{fsnode=Node, pbxpid=Pid}=State) -><br>
{ok, XML} = gen_server:call(Pid, {fetch, Section, Tag, Key, Value, Params}),<br>
{api, Node} ! {fetch_reply, FetchID, XML},<br>
receive<br>
ok -><br>
{noreply, State};<br>
{error, Reason} -><br>
{stop, {error, Reason}, State}<br>
end.<br>
<br>_______________________________________________<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br>