erylee 13 лет назад
Родитель
Сommit
6d795c7273

+ 1 - 0
src/emqtt.app.src

@@ -12,6 +12,7 @@
 	emqtt_client_sup,
 	emqtt_client_monitor,
 	emqtt_ctl,
+	emqtt_db,
 	emqtt_frame,
 	emqtt_lib,
 	emqtt_listener,

+ 22 - 2
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 <ery.lee at gmail dot com>
+%% 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).
+
 

+ 28 - 2
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 <ery.lee at gmail dot com>
+%% 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.
 

+ 17 - 0
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 <ery.lee at gmail dot com>
+%% Copyright (C) 2012 Ery Lee All Rights Reserved.
+
 -module(emqtt_auth).
 
+-author('ery.lee@gmail.com').
+
 -include("emqtt.hrl").
 
 -export([start_link/0,

+ 17 - 0
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 <ery.lee at gmail dot com>
+%% Copyright (C) 2012 Ery Lee All Rights Reserved.
+
 -module(emqtt_auth_anonymous).
 
+-author('ery.lee@gmail.com').
+
 -export([init/1,
 		add/2,
 		check/2,

+ 15 - 0
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 <ery.lee at gmail dot com>
+%% Copyright (C) 2012 Ery Lee All Rights Reserved.
+
 -module(emqtt_auth_internal).
 
 -include("emqtt.hrl").

+ 15 - 0
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 <ery.lee at gmail dot com>
+%% Copyright (C) 2012 Ery Lee All Rights Reserved.
+
 -module(emqtt_client).
 
 -behaviour(gen_server2).

+ 15 - 0
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 <ery.lee at gmail dot com>
+%% Copyright (C) 2012 Ery Lee All Rights Reserved.
+
 -module(emqtt_client_monitor).
 
 -include("emqtt.hrl").

+ 15 - 0
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 <ery.lee at gmail dot com>
+%% Copyright (C) 2012 Ery Lee All Rights Reserved.
+
 -module(emqtt_client_sup).
 
 -export([start_link/0, start_client/1]).

+ 15 - 0
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 <ery.lee at gmail dot com>
+%% Copyright (C) 2012 Ery Lee All Rights Reserved.
+
 -module(emqtt_ctl).
 
 -include("emqtt.hrl").

+ 31 - 0
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 <ery.lee at gmail dot com>
+%% 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().
+
+

+ 14 - 0
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 <ery.lee@gmail.com>
+%% Copyright (c) 2012 Ery Lee.  All rights reserved.
+%%
 -module(emqtt_lib).
 

+ 14 - 0
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 <ery.lee@gmail.com>
+%% Copyright (c) 2012 Ery Lee.  All rights reserved.
+%%
+
 -module(emqtt_listener).
 
 -include("emqtt.hrl").

+ 15 - 0
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 <ery.lee at gmail dot com>
+%% Copyright (C) 2012 Ery Lee All Rights Reserved.
+
 -module(emqtt_net).
 
 -export([tcp_name/3, tcp_host/1, getaddr/2, port_to_listeners/1]).

+ 15 - 0
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 <ery.lee at gmail dot com>
+%% Copyright (C) 2012 Ery Lee All Rights Reserved.
+
 -module(emqtt_registry).
 
 -include("emqtt.hrl").

+ 14 - 0
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 <ery.lee@gmail.com>
+%% Copyright (c) 2012 Ery Lee.  All rights reserved.
+%%
+
 -module(emqtt_router).
 
 -include("emqtt.hrl").

+ 29 - 2
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 <ery.lee at gmail dot com>
+%% 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
 %% ===================================================================