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&#39;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">&lt;<a href="mailto:m.sobkow@marketelsystems.com">m.sobkow@marketelsystems.com</a>&gt;</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&#39;s handling the configuration requests can send the reply without crashing (it&#39;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) -&gt;<br>
    gen_server:start(?MODULE, [Node, Section, Pid], []).<br>
<br>
init([Node, Section, Pid]) -&gt;<br>
        io:format( &quot;freeswitch_bind:init( [Node=~w, Section=~w, Pid=~w])~n&quot;, [Node, Section, Pid] ),<br>
    {api, Node} ! {bind, Section},<br>
    receive<br>
        ok -&gt;<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} -&gt;<br>
            {stop, {error, {freeswitch_error, Reason}}}<br>
    after 5000 -&gt;<br>
            {stop, {error, freeswitch_timeout}}<br>
    end.<br>
<br>
terminate(_Reason, _State) -&gt;<br>
    ok.<br>
<br>
code_change(_OldVsn, State, _Extra) -&gt;<br>
    {ok, State}.<br>
<br>
%%<br>
%%      If the request isn&#39;t recognized, just log it and do nothing.<br>
%%<br>
handle_call(Request, _From, State) -&gt;<br>
    io:format(&quot;freeswitch_bind:handle_call( ~w, _From, State) unrecognized request~n&quot;,<br>
                [Request]),<br>
    {reply, {error, unrecognized_request}, State}.<br>
<br>
handle_cast(Message, State) -&gt;<br>
    error_logger:error_msg(&quot;~p received unrecognized cast ~p~n&quot;,<br>
                           [self(), Message]),<br>
    {noreply, State}.<br>
<br>
handle_info({fetch, Section, Tag, Key, Value, FetchID, Params}, #st{fsnode=Node, pbxpid=Pid}=State) -&gt;<br>
    {ok, XML} = gen_server:call(Pid, {fetch, Section, Tag, Key, Value, Params}),<br>
    {api, Node} ! {fetch_reply, FetchID, XML},<br>
    receive<br>
        ok -&gt;<br>
            {noreply, State};<br>
        {error, Reason} -&gt;<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) -&gt;<br>
    gen_server:start(?MODULE, [Node, Section, Pid], []).<br>
<br>
init([Node, Section, Pid]) -&gt;<br>
        io:format( &quot;freeswitch_callback:init( [Node=~w, Section=~w, Pid=~w])~n&quot;, [Node, Section, Pid] ),<br>
    {ok, #st{fsnode=Node, pbxpid=Pid}}.<br>
<br>
terminate(_Reason, _State) -&gt;<br>
    ok.<br>
<br>
code_change(_OldVsn, State, _Extra) -&gt;<br>
    {ok, State}.<br>
<br>
%%<br>
%% Callback for freeswitch:start_fetch_handler() called in freeswitch_bind:init()<br>
%%<br>
fetch_handler( FreeswitchNode ) -&gt;<br>
        receive<br>
                { nodedown, Node } -&gt;<br>
                        io:format( &quot;freeswitch_callback:fetch_handler() Node ~w is down~n&quot;, [Node] ),<br>
                        ok;<br>
                { fetch, Section, Tag, Key, Value, FetchId, Params } -&gt;<br>
                        io:format( &quot;freeswitch_callback:fetch_handler() Invoking xml_fetch()~n&quot; ),<br>
                    {ok, Xml} = xml_fetch( {fetch, Section, Tag, Key, Value, Params} ),<br>
                        io:format( &quot;freeswitch_callback:fetch_handler() Sending reply to FreeswitchNode ~w: ~s~n&quot;, [FreeswitchNode, Xml] ),<br>
                        FreeswitchNode ! { fetch_reply, FetchId, Xml },<br>
                        io:format( &quot;freeswitch_callback:fetch_handler() Reply sent~n&quot; ),<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}) -&gt;<br>
        io:format( &quot;freeswitch_callback:handle_call( {fetch, configuration, Tag=~s, Key=~s, Value=~s, Params=~w} )~n&quot;,<br>
                [Tag, Key, Value, Params]),<br>
        Xml =<br>
&quot;&lt;document type=\&quot;freeswitch/xml\&quot;&gt;<br>
        &lt;section name=\&quot;result\&quot;&gt;<br>
                &lt;result status=\&quot;not found\&quot; /&gt;<br>
        &lt;/section&gt;<br>
&lt;/document&gt;&quot;,<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}) -&gt;<br>
        io:format( &quot;freeswitch_callback:xml_fetch( {fetch, directory, Tag=~s, Key=~s, Value=~s, Params=~w} )~n&quot;,<br>
                [Tag, Key, Value, Params]),<br>
        Xml =<br>
&quot;&lt;document type=\&quot;freeswitch/xml\&quot;&gt;<br>
        &lt;section name=\&quot;result\&quot;&gt;<br>
                &lt;result status=\&quot;not found\&quot; /&gt;<br>
        &lt;/section&gt;<br>
&lt;/document&gt;&quot;,<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}) -&gt;<br>
        io:format( &quot;freeswitch_callback:xml_fetch( {fetch, dialplan, Tag=~s, Key=~s, Value=~s, Params=~w} )~n&quot;,<br>
                [Tag, Key, Value, Params]),<br>
        Xml =<br>
&quot;&lt;document type=\&quot;freeswitch/xml\&quot;&gt;<br>
        &lt;section name=\&quot;result\&quot;&gt;<br>
                &lt;result status=\&quot;not found\&quot; /&gt;<br>
        &lt;/section&gt;<br>
&lt;/document&gt;&quot;,<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}) -&gt;<br>
        io:format( &quot;freeswitch_callback:xml_fetch( {fetch, Section=~w, Tag=~s, Key=~s, Value=~s, Params=~w} )~n&quot;,<br>
                [Section, Tag, Key, Value, Params]),<br>
        Xml =<br>
&quot;&lt;document type=\&quot;freeswitch/xml\&quot;&gt;<br>
        &lt;section name=\&quot;result\&quot;&gt;<br>
                &lt;result status=\&quot;not found\&quot; /&gt;<br>
        &lt;/section&gt;<br>
&lt;/document&gt;&quot;,<br>
        {ok, Xml };<br>
<br>
%%<br>
%%      If the request isn&#39;t recognized, just log it.<br>
%%<br>
xml_fetch( Request ) -&gt;<br>
        io:format( &quot;freeswitch_callback:xml_fetch( Request=~w ) not recognized~n&quot;,<br>
                [Request]),<br>
        Xml =<br>
&quot;&lt;document type=\&quot;freeswitch/xml\&quot;&gt;<br>
        &lt;section name=\&quot;result\&quot;&gt;<br>
                &lt;result status=\&quot;not found\&quot; /&gt;<br>
        &lt;/section&gt;<br>
&lt;/document&gt;&quot;,<br>
        {ok, Xml }.<br>
<br>
<br>
%%<br>
%%      If the request isn&#39;t recognized, just log it and do nothing.<br>
%%<br>
handle_call(Request, _From, State) -&gt;<br>
    io:format(&quot;freeswitch_callback:handle_call( ~w, _From, State) unrecognized request~n&quot;,<br>
                [Request]),<br>
    {reply, {error, unrecognized_request}, State}.<br>
<br>
handle_cast(Message, State) -&gt;<br>
    error_logger:error_msg(&quot;~p received unrecognized cast ~p~n&quot;,<br>
                           [self(), Message]),<br>
    {noreply, State}.<br>
<br>
handle_info({fetch, Section, Tag, Key, Value, FetchID, Params}, #st{fsnode=Node, pbxpid=Pid}=State) -&gt;<br>
    {ok, XML} = gen_server:call(Pid, {fetch, Section, Tag, Key, Value, Params}),<br>
    {api, Node} ! {fetch_reply, FetchID, XML},<br>
    receive<br>
        ok -&gt;<br>
            {noreply, State};<br>
        {error, Reason} -&gt;<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>