/
sync.erl
118 lines (89 loc) · 2.53 KB
/
sync.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
%% vim: ts=4 sw=4 et
%% Copyright (c) 2011 Rusty Klophaus
%% Released under the MIT License.
-module (sync).
-behaviour(application).
-behaviour(supervisor).
%% API.
-export ([
start/0,
patch/0,
go/0,
pause/0,
info/0,
stop/0,
growl/1,growl/0,
log/1,log/0,
onsync/1,onsync/0,
enable_autotest/0,
disable_autotest/0
]).
%% Application Callbacks.
-export([start/2, stop/1]).
%% Supervisor Callbacks.
-export([init/1]).
-include_lib("kernel/include/file.hrl").
-define(SERVER, ?MODULE).
-define(PRINT(Var), io:format("DEBUG: ~p:~p - ~p~n~n ~p~n~n", [?MODULE, ?LINE, ??Var, Var])).
-define(CHILD(I,Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
-define(VALID_GROWL_OR_LOG(X), is_boolean(X); is_list(X); X==all; X==none; X==skip_success).
%% ----------------------------------------------------------------------
%% API
%% ----------------------------------------------------------------------
start() ->
application:start(compiler),
application:start(syntax_tools),
application:start(sync).
go() ->
case start() of
ok ->
ok;
{error, {already_started, sync}} ->
sync_scanner:unpause(),
sync_scanner:rescan()
end.
patch() ->
go(),
sync_scanner:enable_patching(),
ok.
pause() ->
sync_scanner:pause().
info() ->
sync_scanner:info().
stop() ->
application:stop(sync).
growl(Val) when ?VALID_GROWL_OR_LOG(Val) ->
sync_scanner:set_growl(Val).
growl() ->
sync_scanner:get_growl().
log(Val) when ?VALID_GROWL_OR_LOG(Val) ->
sync_scanner:set_log(Val).
log() ->
sync_scanner:get_log().
onsync(Fun) ->
sync_options:set_onsync(Fun).
onsync() ->
sync_options:get_onsync().
clear_onsync() ->
sync_options:clear_onsync().
enable_autotest() ->
sync_options:enable_autotest().
disable_autotest() ->
clear_onsync().
%% ----------------------------------------------------------------------
%% Application Callbacks
%% ----------------------------------------------------------------------
start(_StartType, _StartArgs) ->
io:format("Starting Sync (Automatic Code Compiler / Reloader)~n"),
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
stop(_State) ->
ok.
%% ----------------------------------------------------------------------
%% Supervisor Callbacks
%% ----------------------------------------------------------------------
init([]) ->
%% Return.
{ok, { {rest_for_one, 5, 10}, [
?CHILD(sync_options, worker),
?CHILD(sync_scanner, worker)
]} }.