Permalink
Browse files

WHISTLE-42: compare decoded call ids only, and allow fs longer to ret…

…urn a list of calls
  • Loading branch information...
1 parent e1487b9 commit 94c4adb1d200683d982fc6ec614e2b23c78a5185 @k-anderson k-anderson committed Feb 25, 2012
@@ -145,11 +145,11 @@ add_leg(Props) ->
%% by call_control, if so add the leg to it
CallId = props:get_value(<<"Other-Leg-Unique-ID">>, Props),
put(callid, CallId),
- case is_binary(CallId) andalso ecallmgr_call_control_sup:find_worker(CallId) of
+ case is_binary(CallId) andalso ecallmgr_call_control_sup:find_workers(CallId) of
false -> ok;
{error, _} -> ok;
- {ok, Srv} ->
- gen_server:cast(Srv, {add_leg, wh_json:from_list(Props)})
+ {ok, Srvs} ->
+ [gen_server:cast(Srv, {add_leg, wh_json:from_list(Props)}) || Srv <- Srvs]
end
end).
@@ -160,11 +160,11 @@ rm_leg(Props) ->
%% by call_control, if so remove the leg from it
CallId = props:get_value(<<"Other-Leg-Unique-ID">>, Props),
put(callid, CallId),
- case is_binary(CallId) andalso ecallmgr_call_control_sup:find_worker(CallId) of
+ case is_binary(CallId) andalso ecallmgr_call_control_sup:find_workers(CallId) of
false -> ok;
{error, _} -> ok;
- {ok, Srv} ->
- gen_server:cast(Srv, {rm_leg, wh_json:from_list(Props)})
+ {ok, Srvs} ->
+ [gen_server:cast(Srv, {rm_leg, wh_json:from_list(Props)}) || Srv <- Srvs]
end
end).
@@ -17,7 +17,7 @@
%% API
-export([start_link/0, start_proc/1]).
-export([workers/0]).
--export([find_worker/1]).
+-export([find_workers/1]).
-export([find_control_queue/1]).
-include("ecallmgr.hrl").
@@ -52,24 +52,27 @@ workers() ->
Worker =:= ecallmgr_call_control
].
--spec find_worker/1 :: (ne_binary()) -> {'error', 'not_found'} | {'ok', pid()}.
--spec do_find_worker/2 :: ([pid(),...] | [], ne_binary()) -> {'error', 'not_found'} | {'ok', pid()}.
-find_worker(CallID) ->
- do_find_worker(workers(), CallID).
+-spec find_workers/1 :: (ne_binary()) -> {'error', 'not_found'} | {'ok', [pid(),...]}.
+-spec do_find_worker/3 :: ([pid(),...] | [], [pid(),...] | [], ne_binary()) -> {'error', 'not_found'} | {'ok', pid()}.
+find_workers(CallID) ->
+ C = wh_util:to_binary(http_uri:decode(wh_util:to_list(CallID))),
+ do_find_worker(workers(), [], C).
-do_find_worker([], _CallId) ->
+do_find_worker([], [], _CallId) ->
{error, not_found};
-do_find_worker([Srv|T], CallID) ->
+do_find_worker([], Acc, _CallId) ->
+ {ok, Acc};
+do_find_worker([Srv|T], Acc, CallID) ->
case catch(ecallmgr_call_control:callid(Srv)) of
- CallID -> {ok, Srv};
- _E -> do_find_worker(T, CallID)
+ CallID -> do_find_worker(T, [Srv|Acc], CallID);
+ _E -> do_find_worker(T, Acc, CallID)
end.
-spec find_control_queue/1 :: (ne_binary()) -> {'error', 'not_found'} | {'ok', ne_binary()}.
find_control_queue(CallID) ->
- case find_worker(CallID) of
+ case find_workers(CallID) of
{error, _}=E -> E;
- {ok, Worker} ->
+ {ok, [Worker|_]} ->
{ok, ecallmgr_call_control:queue_name(Worker)}
end.
@@ -52,35 +52,35 @@ distributed_presence(Srv, Type, Event) ->
-spec show_channels/1 :: (pid()) -> [proplist(),...] | [].
show_channels(Srv) ->
- case catch(gen_server:call(Srv, show_channels, 100)) of
+ case catch(gen_server:call(Srv, show_channels, ?FS_TIMEOUT)) of
{'EXIT', _} -> [];
Else -> Else
end.
-spec hostname/1 :: (pid()) -> fs_api_ret().
hostname(Srv) ->
- case catch(gen_server:call(Srv, hostname, 100)) of
+ case catch(gen_server:call(Srv, hostname, ?FS_TIMEOUT)) of
{'EXIT', _} -> timeout;
Else -> Else
end.
-spec fs_node/1 :: (pid()) -> atom().
fs_node(Srv) ->
- case catch(gen_server:call(Srv, fs_node, 100)) of
+ case catch(gen_server:call(Srv, fs_node, ?FS_TIMEOUT)) of
{'EXIT', _} -> undefined;
Else -> Else
end.
-spec uuid_exists/2 :: (pid(), ne_binary()) -> boolean().
uuid_exists(Srv, UUID) ->
- case catch(gen_server:call(Srv, {uuid_exists, UUID}, 100)) of
+ case catch(gen_server:call(Srv, {uuid_exists, UUID}, ?FS_TIMEOUT)) of
{'EXIT', _} -> false;
Else -> Else
end.
-spec uuid_dump/2 :: (pid(), ne_binary()) -> {'ok', proplist()} | {'error', ne_binary()} | 'timeout'.
uuid_dump(Srv, UUID) ->
- case catch(gen_server:call(Srv, {uuid_dump, UUID}, 100)) of
+ case catch(gen_server:call(Srv, {uuid_dump, UUID}, ?FS_TIMEOUT)) of
{'EXIT', _} -> [];
Else -> Else
end.
@@ -449,10 +449,14 @@ process_transfer_event(<<"BLIND_TRANSFER">>, Data) ->
_ ->
props:get_value(<<"Transferee-UUID">>, Data)
end,
- case ecallmgr_call_control_sup:find_worker(TransfererCtrlUUId) of
- {ok, Pid1} ->
- ?LOG(TransfererCtrlUUId, "sending transferer notice to ecallmgr_call_control ~p", [Pid1]),
- ecallmgr_call_control:transferer(Pid1, Data);
+ case ecallmgr_call_control_sup:find_workers(TransfererCtrlUUId) of
+ {ok, Pids} ->
+ [begin
+ ecallmgr_call_control:transferer(Pid, Data),
+ ?LOG(TransfererCtrlUUId, "sending transferer notice to ecallmgr_call_control ~p", [Pid])
+ end
+ || Pid <- Pids
+ ];
{error, not_found} ->
ok
end;
@@ -463,18 +467,26 @@ process_transfer_event(_, Data) ->
_ ->
props:get_value(<<"Transferee-UUID">>, Data)
end,
- case ecallmgr_call_control_sup:find_worker(TransfererCtrlUUId) of
- {ok, Pid1} ->
- ?LOG(TransfererCtrlUUId, "sending transferer notice to ecallmgr_call_control ~p", [Pid1]),
- ecallmgr_call_control:transferer(Pid1, Data);
+ case ecallmgr_call_control_sup:find_workers(TransfererCtrlUUId) of
+ {ok, TransfererPids} ->
+ [begin
+ ecallmgr_call_control:transferer(Pid, Data),
+ ?LOG(TransfererCtrlUUId, "sending transferer notice to ecallmgr_call_control ~p", [Pid])
+ end
+ || Pid <- TransfererPids
+ ];
{error, not_found} ->
ok
end,
TransfereeCtrlUUId = props:get_value(<<"Replaces">>, Data),
case ecallmgr_call_control_sup:find_worker(TransfereeCtrlUUId) of
- {ok, Pid2} ->
- ?LOG(TransfereeCtrlUUId, "sending transferee notice to ecallmgr_call_control ~p", [Pid2]),
- ecallmgr_call_control:transferee(Pid2, Data);
+ {ok, ReplacesPids} ->
+ [begin
+ ecallmgr_call_control:transferee(Pid, Data),
+ ?LOG(TransfereeCtrlUUId, "sending transferee notice to ecallmgr_call_control ~p", [Pid])
+ end
+ || Pid <- ReplacesPids
+ ];
{error, not_found} ->
ok
end.
@@ -127,13 +127,7 @@ handle_channel_query(JObj, _Props) ->
-spec channel_query/1 :: (wh_json:json_object()) -> wh_json:json_objects().
channel_query(JObj) ->
- SearchParams = lists:foldl(fun(Field, Acc) ->
- case wh_json:get_value(Field, JObj) of
- undefined -> Acc;
- Value -> [{Field, Value} | Acc]
- end
- end, [], wapi_call:channel_query_search_fields()),
- Channels = lists:flatten([ecallmgr_fs_node:show_channels(Pid) || Pid <- ecallmgr_fs_sup:node_handlers()]),
+ Channels = lists:concat([ecallmgr_fs_node:show_channels(Pid) || Pid <- ecallmgr_fs_sup:node_handlers()]),
SearchParams = lists:foldl(fun(Field, Acc) ->
case wh_json:get_value(Field, JObj) of
undefined -> Acc;

0 comments on commit 94c4adb

Please sign in to comment.