PageRenderTime 17ms CodeModel.GetById 8ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/ucengine/src/controllers/async/uce_async.erl

http://github.com/AF83/ucengine
Erlang | 45 lines | 23 code | 5 blank | 17 comment | 0 complexity | e3581fa55a0eca30f65be910d5c239bb MD5 | raw file
 1%%
 2%%  U.C.Engine - Unified Collaboration Engine
 3%%  Copyright (C) 2011 af83
 4%%
 5%%  This program is free software: you can redistribute it and/or modify
 6%%  it under the terms of the GNU Affero General Public License as published by
 7%%  the Free Software Foundation, either version 3 of the License, or
 8%%  (at your option) any later version.
 9%%
10%%  This program is distributed in the hope that it will be useful,
11%%  but WITHOUT ANY WARRANTY; without even the implied warranty of
12%%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13%%  GNU Affero General Public License for more details.
14%%
15%%  You should have received a copy of the GNU Affero General Public License
16%%  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17%%
18-module(uce_async).
19
20-export([listen/7, filter/2]).
21
22-include("uce.hrl").
23
24listen(Domain, Location, Search, From, Types, Parent, Timeout) ->
25    receive
26        {event, Event} ->
27            case filter(Search, Event) of
28                false ->
29                    listen(Domain, Location, Search, From, Types, Parent, Timeout);
30                true ->
31                    {ok, Event}
32            end;
33        Other ->
34            ?WARNING_MSG("unattended message ~p", [Other]),
35            {ok, []}
36    after
37        Timeout ->
38            {ok, []}
39    end.
40
41
42filter("", _Event) ->
43    true;
44filter(Search, #uce_event{metadata=Metadata}) ->
45    uce_event_erlang_search:search_metadata(Metadata, Search).