C0 code coverage information

Generated on 2009-08-09 21:22:57 with etap 0.3.4.

Name Total lines Lines of code Total coverage Code coverage
couch_db_update_notifier ?? ?? ??
40% 
....1 % Licensed under the Apache License, Version 2.0 (the "License"); you may not
....2 % use this file except in compliance with the License. You may obtain a copy of
....3 % the License at
....4 %
....5 %   http://www.apache.org/licenses/LICENSE-2.0
....6 %
....7 % Unless required by applicable law or agreed to in writing, software
....8 % distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
....9 % WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
...10 % License for the specific language governing permissions and limitations under
...11 % the License.
...12 
...13 %
...14 % This causes an OS process to spawned and it is notified every time a database
...15 % is updated.
...16 %
...17 % The notifications are in the form of a the database name sent as a line of
...18 % text to the OS processes stdout.
...19 %
...20 
...21 -module(couch_db_update_notifier).
...22 
...23 -behaviour(gen_event).
...24 
...25 -export([start_link/1, notify/1]).
...26 -export([init/1, terminate/2, handle_event/2, handle_call/2, handle_info/2, code_change/3,stop/1]).
...27 
...28 -include("couch_db.hrl").
...29 
...30 start_link(Exec) ->
...31     couch_event_sup:start_link(couch_db_update, {couch_db_update_notifier, make_ref()}, Exec).
...32 
...33 notify(Event) ->
...34     gen_event:notify(couch_db_update, Event).
...35 
...36 stop(Pid) ->
...37     couch_event_sup:stop(Pid).
...38 
...39 init(Exec) when is_list(Exec) -> % an exe
...40     couch_os_process:start_link(Exec, []);
...41 init(Else) ->
...42     {ok, Else}.
...43 
...44 terminate(_Reason, Pid) when is_pid(Pid) ->
...45     couch_os_process:stop(Pid),
...46     ok;
...47 terminate(_Reason, _State) ->
...48     ok.
...49 
...50 handle_event(Event, Fun) when is_function(Fun, 1) ->
...51     Fun(Event),
...52     {ok, Fun};
...53 handle_event(Event, {Fun, FunAcc}) ->
...54     FunAcc2 = Fun(Event, FunAcc),
...55     {ok, {Fun, FunAcc2}};
...56 handle_event({EventAtom, DbName}, Pid) ->
...57     Obj = {[{type, list_to_binary(atom_to_list(EventAtom))}, {db, DbName}]},
...58     ok = couch_os_process:send(Pid, Obj),
...59     {ok, Pid}.
...60 
...61 handle_call(_Request, State) ->
...62     {reply, ok, State}.
...63 
...64 handle_info({'EXIT', Pid, Reason}, Pid) ->
...65     ?LOG_ERROR("Update notification process ~p died: ~p", [Pid, Reason]),
...66     remove_handler;
...67 handle_info({'EXIT', _, _}, Pid) ->
...68     %% the db_update event manager traps exits and forwards this message to all
...69     %% its handlers. Just ignore as it wasn't our os_process that exited.
...70     {ok, Pid}.
...71 
...72 code_change(_OldVsn, State, _Extra) ->
...73     {ok, State}.

Generated using etap 0.3.4.