VoIP Mailing List Archives
Mailing list archives for the VoIP community |
|
View previous topic :: View next topic |
Author |
Message |
m.sobkow at marketelsy... Guest
|
Posted: Mon Sep 14, 2009 3:00 pm Post subject: [Freeswitch-users] ERLang configuration callbacks |
|
|
I seem to be missing "something" in implementing the ERLang callbacks
for Freeswitch. Our Freeswitch server is starting and getting
registered with ERLang, we're invoking the bind for configuration, but
I'm not seeing any of my callbacks fire. What am I missing?
Sample code follows:
-module(freeswitch_bind).
-behaviour(gen_server).
-record(st, {fsnode, pbxpid}).
-export([start/3, terminate/2, code_change/3, init/1,
handle_call/3, handle_cast/2, handle_info/2]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% gen_server methods
start(Node, Section, Pid) ->
gen_server:start(?MODULE, [Node, Section, Pid], []).
init([Node, Section, Pid]) ->
io:format( "freeswitch_bind:init( [Node=~w, Section=~w, Pid=~w])~n",
[Node, Section, Pid] ),
{api, Node} ! {bind, Section},
receive
ok ->
{ok, #st{fsnode=Node, pbxpid=Pid}};
{error, Reason} ->
{stop, {error, {freeswitch_error, Reason}}}
after 5000 ->
{stop, {error, freeswitch_timeout}}
end.
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%%
%% Configuration handler replies that the requested document section,
tag, and key are not
%% found.
%%
handle_call({fetch, configuration, Tag, Key, Value, Params}, _From,
State) ->
io:format( "freeswitch_fetch:handle_call( {fetch, configuration,
Tag=~w, Key=~w, Value=~w, Params=~w}, _From, State=~w)~n",
[Tag, Key, Value, Params, State]),
Xml =
"<document type=\"freeswitch/xml\">
<section name=\"result\">
<result status=\"not found\" />
</section>
</document>",
{ reply, {ok, Xml }, State };
%%
%% Directory handler replies that the requested document section,
tag, and key are not
%% found.
%%
handle_call({fetch, directory, Tag, Key, Value, Params}, _From, State) ->
io:format( "freeswitch_fetch:handle_call( {fetch, directory, Tag=~w,
Key=~w, Value=~w, Params=~w}, _From, State=~w)~n",
[Tag, Key, Value, Params, State]),
Xml =
"<document type=\"freeswitch/xml\">
<section name=\"result\">
<result status=\"not found\" />
</section>
</document>",
{ reply, {ok, Xml }, State };
%%
%% Dialplan handler replies that the requested document section, tag,
and key are not
%% found.
%%
handle_call({fetch, dialplan, Tag, Key, Value, Params}, _From, State) ->
io:format( "freeswitch_fetch:handle_call( {fetch, dialplan, Tag=~w,
Key=~w, Value=~w, Params=~w}, _From, State=~w)~n",
[Tag, Key, Value, Params, State]),
Xml =
"<document type=\"freeswitch/xml\">
<section name=\"result\">
<result status=\"not found\" />
</section>
</document>",
{ reply, {ok, Xml }, State };
%%
%% Default handler replies that the requested document section, tag,
and key are not
%% found.
%%
handle_call({fetch, Section, Tag, Key, Value, Params}, _From, State) ->
io:format( "freeswitch_fetch:handle_call( {fetch, Section=~w,
Tag=~w, Key=~w, Value=~w, Params=~w}, _From, State=~w)~n",
[Section, Tag, Key, Value, Params, State]),
Xml =
"<document type=\"freeswitch/xml\">
<section name=\"result\">
<result status=\"not found\" />
</section>
</document>",
{ reply, {ok, Xml }, State };
%%
%% If the request isn't recognized, just log it and do nothing.
%%
handle_call(Request, _From, State) ->
io:format("freeswitch_bind:handle_call( ~w, _From, State)
unrecognized request~n",
[Request]),
{reply, {error, unrecognized_request}, State}.
handle_cast(Message, State) ->
error_logger:error_msg("~p received unrecognized cast ~p~n",
[self(), Message]),
{noreply, State}.
handle_info({fetch, Section, Tag, Key, Value, FetchID, Params},
#st{fsnode=Node, pbxpid=Pid}=State) ->
{ok, XML} = gen_server:call(Pid, {fetch, Section, Tag, Key, Value,
Params}),
{api, Node} ! {fetch_reply, FetchID, XML},
receive
ok ->
{noreply, State};
{error, Reason} ->
{stop, {error, Reason}, State}
end.
_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org |
|
Back to top |
|
|
andrew at hijacked.us Guest
|
Posted: Tue Sep 15, 2009 1:42 pm Post subject: [Freeswitch-users] ERLang configuration callbacks |
|
|
On Mon, Sep 14, 2009 at 01:54:31PM -0600, Mark Sobkow wrote:
Quote: | I seem to be missing "something" in implementing the ERLang callbacks
for Freeswitch. Our Freeswitch server is starting and getting
registered with ERLang, we're invoking the bind for configuration, but
I'm not seeing any of my callbacks fire. What am I missing?
|
The most obvious thing is that you're trying to catch info messages
using handle_call. The erlang module doesn't use the OTP protocol for
messages so handle_call/cast won't ever fire for messages sent from the
freeswitch module.
Andrew
_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org |
|
Back to top |
|
|
andrew at hijacked.us Guest
|
Posted: Tue Sep 15, 2009 1:50 pm Post subject: [Freeswitch-users] ERLang configuration callbacks |
|
|
On Tue, Sep 15, 2009 at 02:29:14PM -0400, Andrew Thompson wrote:
Quote: | On Mon, Sep 14, 2009 at 01:54:31PM -0600, Mark Sobkow wrote:
| Oh wait, I see what you're doing, you catch all the fetch requests in
the handle_info and then make a call to another process to get the XML.
My question is why are those both in the same process? The handle_info
part is fine, but then the pid you make a gen_server:call to *must* be a
different process or you'll hit a timeout and the process will exit.
However, I can't start 2 copies of that process (one to catch requests,
one to return XML) because your module always does a bind!
Regardless, I at least get fetch requests when I run your module, I
can't make it return something without refactoring it, but it does
receive the requests at least.
Andrew
_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org |
|
Back to top |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|