From 6d795c7273c4ad353e23fa183dc9253cf22b8e9a Mon Sep 17 00:00:00 2001 From: erylee Date: Thu, 27 Dec 2012 21:55:41 +0800 Subject: [PATCH] add license --- src/emqtt.app.src | 1 + src/emqtt.erl | 24 ++++++++++++++++++++++-- src/emqtt_app.erl | 28 +++++++++++++++++++++++++++- src/emqtt_auth.erl | 17 +++++++++++++++++ src/emqtt_auth_anonymous.erl | 17 +++++++++++++++++ src/emqtt_auth_internal.erl | 15 +++++++++++++++ src/emqtt_client.erl | 15 +++++++++++++++ src/emqtt_client_monitor.erl | 15 +++++++++++++++ src/emqtt_client_sup.erl | 15 +++++++++++++++ src/emqtt_ctl.erl | 15 +++++++++++++++ src/emqtt_db.erl | 31 +++++++++++++++++++++++++++++++ src/emqtt_lib.erl | 14 ++++++++++++++ src/emqtt_listener.erl | 14 ++++++++++++++ src/emqtt_net.erl | 15 +++++++++++++++ src/emqtt_registry.erl | 15 +++++++++++++++ src/emqtt_router.erl | 14 ++++++++++++++ src/emqtt_sup.erl | 31 +++++++++++++++++++++++++++++-- 17 files changed, 291 insertions(+), 5 deletions(-) create mode 100644 src/emqtt_db.erl diff --git a/src/emqtt.app.src b/src/emqtt.app.src index 98cf47037..cf2b7543c 100644 --- a/src/emqtt.app.src +++ b/src/emqtt.app.src @@ -12,6 +12,7 @@ emqtt_client_sup, emqtt_client_monitor, emqtt_ctl, + emqtt_db, emqtt_frame, emqtt_lib, emqtt_listener, diff --git a/src/emqtt.erl b/src/emqtt.erl index 3ae6127ad..e11a1ef96 100644 --- a/src/emqtt.erl +++ b/src/emqtt.erl @@ -1,11 +1,31 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. + -module(emqtt). -export([start/0]). + +%% +%% @spec start() -> 'ok' +%% start() -> - ok = application:start(sasl), + application:start(sasl), mnesia:create_schema([node()]), mnesia:start(), lager:start(), - ok = application:start(emqtt). + application:start(emqtt). + diff --git a/src/emqtt_app.erl b/src/emqtt_app.erl index 8ff827ea3..516657dbd 100644 --- a/src/emqtt_app.erl +++ b/src/emqtt_app.erl @@ -1,6 +1,22 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. -module(emqtt_app). +-author('ery.lee@gmail.com'). + -include("emqtt.hrl"). -behaviour(application). @@ -12,10 +28,20 @@ %% Application callbacks %% =================================================================== +%% +%% @spec start(atom(), list()) -> {ok, pid()} +%% start(_StartType, _StartArgs) -> + ?INFO("starting emqtt on node '~s'", [node()]), {ok, Listeners} = application:get_env(listeners), - emqtt_sup:start_link(Listeners). + {ok, SupPid} = emqtt_sup:start_link(Listeners), + register(emqtt, self()), + ?INFO_MSG("emqtt broker is running now."), + {ok, SupPid}. +%% +%% @spec stop(atom) -> 'ok' +%% stop(_State) -> ok. diff --git a/src/emqtt_auth.erl b/src/emqtt_auth.erl index 88a11b8bf..3b9b0fcbf 100644 --- a/src/emqtt_auth.erl +++ b/src/emqtt_auth.erl @@ -1,5 +1,22 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. + -module(emqtt_auth). +-author('ery.lee@gmail.com'). + -include("emqtt.hrl"). -export([start_link/0, diff --git a/src/emqtt_auth_anonymous.erl b/src/emqtt_auth_anonymous.erl index ca41f19b0..d28e3f5b6 100644 --- a/src/emqtt_auth_anonymous.erl +++ b/src/emqtt_auth_anonymous.erl @@ -1,5 +1,22 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. + -module(emqtt_auth_anonymous). +-author('ery.lee@gmail.com'). + -export([init/1, add/2, check/2, diff --git a/src/emqtt_auth_internal.erl b/src/emqtt_auth_internal.erl index fa1c63789..2cf9ec010 100644 --- a/src/emqtt_auth_internal.erl +++ b/src/emqtt_auth_internal.erl @@ -1,3 +1,18 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. + -module(emqtt_auth_internal). -include("emqtt.hrl"). diff --git a/src/emqtt_client.erl b/src/emqtt_client.erl index 4c8784341..4a6270702 100644 --- a/src/emqtt_client.erl +++ b/src/emqtt_client.erl @@ -1,3 +1,18 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. + -module(emqtt_client). -behaviour(gen_server2). diff --git a/src/emqtt_client_monitor.erl b/src/emqtt_client_monitor.erl index cdc2c6597..6d0c7c3f5 100644 --- a/src/emqtt_client_monitor.erl +++ b/src/emqtt_client_monitor.erl @@ -1,3 +1,18 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. + -module(emqtt_client_monitor). -include("emqtt.hrl"). diff --git a/src/emqtt_client_sup.erl b/src/emqtt_client_sup.erl index df33865d0..b336badcb 100644 --- a/src/emqtt_client_sup.erl +++ b/src/emqtt_client_sup.erl @@ -1,3 +1,18 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. + -module(emqtt_client_sup). -export([start_link/0, start_client/1]). diff --git a/src/emqtt_ctl.erl b/src/emqtt_ctl.erl index fc8f5d002..a56b5e4b3 100644 --- a/src/emqtt_ctl.erl +++ b/src/emqtt_ctl.erl @@ -1,3 +1,18 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. + -module(emqtt_ctl). -include("emqtt.hrl"). diff --git a/src/emqtt_db.erl b/src/emqtt_db.erl new file mode 100644 index 000000000..b521bf260 --- /dev/null +++ b/src/emqtt_db.erl @@ -0,0 +1,31 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. + +-module(emqtt_db). + +-export([init/0, stop/0]). + +init() -> + case mnesia:system_info(extra_db_nodes) of + [] -> mnesia:create_schema([node()]); + _ -> ok + end, + ok = mnesia:start(), + mnesia:wait_for_tables(mnesia:system_info(local_tables), infinity). + +stop() -> + mnesia:stop(). + + diff --git a/src/emqtt_lib.erl b/src/emqtt_lib.erl index 44d8566ae..93925c66d 100644 --- a/src/emqtt_lib.erl +++ b/src/emqtt_lib.erl @@ -1,2 +1,16 @@ + +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% Developer of the eMQTT Code is +%% Copyright (c) 2012 Ery Lee. All rights reserved. +%% -module(emqtt_lib). diff --git a/src/emqtt_listener.erl b/src/emqtt_listener.erl index c6c558182..58b17078b 100644 --- a/src/emqtt_listener.erl +++ b/src/emqtt_listener.erl @@ -1,3 +1,17 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% Developer of the eMQTT Code is +%% Copyright (c) 2012 Ery Lee. All rights reserved. +%% + -module(emqtt_listener). -include("emqtt.hrl"). diff --git a/src/emqtt_net.erl b/src/emqtt_net.erl index 03146c4d2..ed1299ba5 100644 --- a/src/emqtt_net.erl +++ b/src/emqtt_net.erl @@ -1,3 +1,18 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. + -module(emqtt_net). -export([tcp_name/3, tcp_host/1, getaddr/2, port_to_listeners/1]). diff --git a/src/emqtt_registry.erl b/src/emqtt_registry.erl index 7f437234f..b8afab57d 100644 --- a/src/emqtt_registry.erl +++ b/src/emqtt_registry.erl @@ -1,3 +1,18 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. + -module(emqtt_registry). -include("emqtt.hrl"). diff --git a/src/emqtt_router.erl b/src/emqtt_router.erl index 78f397504..288cd9ece 100644 --- a/src/emqtt_router.erl +++ b/src/emqtt_router.erl @@ -1,3 +1,17 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% Developer of the eMQTT Code is +%% Copyright (c) 2012 Ery Lee. All rights reserved. +%% + -module(emqtt_router). -include("emqtt.hrl"). diff --git a/src/emqtt_sup.erl b/src/emqtt_sup.erl index b257bf1aa..38d324039 100644 --- a/src/emqtt_sup.erl +++ b/src/emqtt_sup.erl @@ -1,3 +1,18 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is eMQTT +%% +%% The Initial Developer of the Original Code is +%% Copyright (C) 2012 Ery Lee All Rights Reserved. + -module(emqtt_sup). -include("emqtt.hrl"). @@ -5,7 +20,9 @@ -behaviour(supervisor). %% API --export([start_link/1]). +-export([start_link/1, + start_child/1, + start_child/2]). %% Supervisor callbacks -export([init/1]). @@ -16,10 +33,20 @@ %% =================================================================== %% API functions %% =================================================================== - start_link(Listeners) -> supervisor:start_link({local, ?MODULE}, ?MODULE, [Listeners]). + +start_child(ChildSpec) when is_tuple(ChildSpec) -> + supervisor:start_child(?MODULE, ChildSpec). + +%% +%% start_child(Mod::atom(), Type::type()) -> {ok, pid()} +%% @type type() = worker | supervisor +%% +start_child(Mod, Type) when is_atom(Mod) and is_atom(Type) -> + supervisor:start_child(?MODULE, ?CHILD(Mod, Type)). + %% =================================================================== %% Supervisor callbacks %% ===================================================================