소스 검색

refactor header file

erylee 12 년 전
부모
커밋
9bdbb84ed2

+ 13 - 80
include/emqtt.hrl

@@ -24,83 +24,16 @@
 
 -define(ERTS_MINIMUM, "5.6.3").                  
 
--record(internal_user, {username, passwdhash}).
-
-%name: <<"a/b/c">>
-%node: node()
-%words: [<<"a">>, <<"b">>, <<"c">>]
--record(topic, {name, node}).
-
--record(trie, {edge, node_id}).
-
--record(trie_node, {node_id, edge_count=0, topic}).
-
--record(trie_edge, {node_id, word}).
-
-%topic: topic name
-
--record(subscriber, {topic, qos, client}).
-
-%% ---------------------------------
-%% Logging mechanism
-
--define(PRINT(Format, Args),
-    io:format(Format, Args)).
-
--define(PRINT_MSG(Msg),
-    io:format(Msg)).
-
--define(DEBUG(Format, Args),
-    lager:debug(Format, Args)).
-
--define(DEBUG_TRACE(Dest, Format, Args),
-    lager:debug(Dest, Format, Args)).
-
--define(DEBUG_MSG(Msg),
-    lager:debug(Msg)).
-
--define(INFO(Format, Args),
-    lager:info(Format, Args)).
-
--define(INFO_TRACE(Dest, Format, Args),
-    lager:info(Dest, Format, Args)).
-
--define(INFO_MSG(Msg),
-    lager:info(Msg)).
-
--define(WARN(Format, Args),
-    lager:warning(Format, Args)).
-
--define(WARN_TRACE(Dest, Format, Args),
-    lager:warning(Dest, Format, Args)).
-
--define(WARN_MSG(Msg),
-    lager:warning(Msg)).
-			      
--define(WARNING(Format, Args),
-    lager:warning(Format, Args)).
-
--define(WARNING_TRACE(Dest, Format, Args),
-    lager:warning(Dest, Format, Args)).
-
--define(WARNING_MSG(Msg),
-    lager:warning(Msg)).
-
--define(ERROR(Format, Args),
-    lager:error(Format, Args)).
-
--define(ERROR_TRACE(Dest, Format, Args),
-    lager:error(Dest, Format, Args)).
-
--define(ERROR_MSG(Msg),
-    lager:error(Msg)).
-
--define(CRITICAL(Format, Args),
-    lager:critical(Format, Args)).
-
--define(CRITICAL_TRACE(Dest, Format, Args),
-    lager:critical(Dest, Format, Args)).
-
--define(CRITICAL_MSG(Msg),
-    lager:critical(Msg)).
-
+%% qos levels
+
+-define(QOS_0, 0).
+-define(QOS_1, 1).
+-define(QOS_2, 2).
+
+-record(mqtt_msg,            {retain,
+                              qos,
+                              topic,
+                              dup,
+                              message_id,
+                              payload,
+							  encoder}).

+ 0 - 12
include/emqtt_frame.hrl

@@ -48,11 +48,6 @@
 -define(CONNACK_CREDENTIALS, 4). %% bad user name or password
 -define(CONNACK_AUTH,        5). %% not authorized
 
-%% qos levels
-
--define(QOS_0, 0).
--define(QOS_1, 1).
--define(QOS_2, 2).
 
 -record(mqtt_frame, {fixed,
                      variable,
@@ -91,11 +86,4 @@
 
 -record(mqtt_frame_other,    {other}).
 
--record(mqtt_msg,            {retain,
-                              qos,
-                              topic,
-                              dup,
-                              message_id,
-                              payload}).
-
 

+ 36 - 0
include/emqtt_internal.hrl

@@ -0,0 +1,36 @@
+%% 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 Initial Developer of the Original Code is ery.lee@gmail.com
+%% Copyright (c) 2012 Ery Lee.  All rights reserved.
+%%
+
+%% -------------------------------------------
+%% banner
+%% -------------------------------------------
+
+-record(internal_user, {username, passwdhash}).
+
+%name: <<"a/b/c">>
+%node: node()
+%words: [<<"a">>, <<"b">>, <<"c">>]
+-record(topic, {name, node}).
+
+-record(trie, {edge, node_id}).
+
+-record(trie_node, {node_id, edge_count=0, topic}).
+
+-record(trie_edge, {node_id, word}).
+
+%topic: topic name
+
+-record(subscriber, {topic, qos, client}).
+

+ 1 - 0
rebar.config

@@ -13,5 +13,6 @@
 
 {deps, [
 	{lager, ".*", {git, "git://github.com/basho/lager.git", {branch, "master"}}},
+	{elog, ".*", {git, "git://github.com/erylee/elog.git", {branch, "master"}}},
 	{folsom, ".*", {git, "git://github.com/boundary/folsom.git", {branch, "master"}}}
 ]}.

+ 2 - 0
rel/reltool.config

@@ -9,6 +9,7 @@
          sasl,
          mnesia,
 		 lager,
+		 elog,
 		 compiler,
 		 {folsom, load},
          emqtt
@@ -32,6 +33,7 @@
        {app, mnesia, [{incl_cond, include}]},
        {app, compiler, [{incl_cond, include}]},
        {app, lager, [{incl_cond, include}]},
+       {app, elog, [{incl_cond, include}]},
        {app, folsom, [{incl_cond, include}]},
        {app, emqtt, [{mod_cond, app}, {incl_cond, include}]}
       ]}.

+ 2 - 0
src/emqtt_app.erl

@@ -19,6 +19,8 @@
 
 -include("emqtt.hrl").
 
+-include_lib("elog/include/elog.hrl").
+
 -behaviour(application).
 
 %% Application callbacks

+ 2 - 0
src/emqtt_auth.erl

@@ -19,6 +19,8 @@
 
 -include("emqtt.hrl").
 
+-include_lib("elog/include/elog.hrl").
+
 -export([start_link/0,
 		add/2,
 		check/2,

+ 1 - 1
src/emqtt_auth_internal.erl

@@ -15,7 +15,7 @@
 
 -module(emqtt_auth_internal).
 
--include("emqtt.hrl").
+-include("emqtt_internal.hrl").
 
 -export([init/1,
 		add/2,

+ 14 - 2
src/emqtt_client.erl

@@ -27,8 +27,13 @@
 		terminate/2]).
 
 -include("emqtt.hrl").
+
 -include("emqtt_frame.hrl").
 
+-include("emqtt_internal.hrl").
+
+-include_lib("elog/include/elog.hrl").
+
 -define(CLIENT_ID_MAXLEN, 23).
 
 -record(state, {socket,
@@ -99,7 +104,14 @@ handle_info({route, Msg}, #state{socket = Sock, message_id=MsgId} = State) ->
 			  qos        = Qos,
 			  topic      = Topic,
 			  dup        = Dup,
-			  payload    = Payload} = Msg,
+			  payload    = Payload,
+			  encoder 	 = Encoder} = Msg,
+	
+	Payload1 = 
+	if
+	Encoder == undefined -> Payload;
+	true -> Encoder(Payload)
+	end,
 
 	Frame = #mqtt_frame{
 		fixed = #mqtt_frame_fixed{type 	 = ?PUBLISH,
@@ -111,7 +123,7 @@ handle_info({route, Msg}, #state{socket = Sock, message_id=MsgId} = State) ->
 													Qos == ?QOS_0 -> undefined;
 													true -> MsgId
 													end},
-		payload = Payload},
+		payload = Payload1},
 
 	send_frame(Sock, Frame),
 

+ 4 - 0
src/emqtt_client_monitor.erl

@@ -17,6 +17,10 @@
 
 -include("emqtt.hrl").
 
+-include("emqtt_internal.hrl").
+
+-include_lib("elog/include/elog.hrl").
+
 -export([start_link/0, mon/1]).
 
 -behaviour(gen_server).

+ 2 - 0
src/emqtt_ctl.erl

@@ -17,6 +17,8 @@
 
 -include("emqtt.hrl").
 
+-include_lib("elog/include/elog.hrl").
+
 -export([status/1,
 		cluster_info/1,
 		cluster/1,

+ 2 - 0
src/emqtt_frame.erl

@@ -19,6 +19,8 @@
 
 -include("emqtt_frame.hrl").
 
+-include("emqtt_internal.hrl").
+
 -export([parse/2, initial_state/0]).
 -export([serialise/1]).
 

+ 2 - 0
src/emqtt_listener.erl

@@ -16,6 +16,8 @@
 
 -include("emqtt.hrl").
 
+-include_lib("elog/include/elog.hrl").
+
 -export([spec/2, listener_started/3, listener_stopped/3]).
 
 spec({Listener, SockOpts}, Callback) ->

+ 2 - 0
src/emqtt_registry.erl

@@ -17,6 +17,8 @@
 
 -include("emqtt.hrl").
 
+-include_lib("elog/include/elog.hrl").
+
 -export([start_link/0, 
 		size/0,
 		register/2,

+ 2 - 0
src/emqtt_retained.erl

@@ -34,6 +34,8 @@
 
 -include("emqtt.hrl").
 
+-include_lib("elog/include/elog.hrl").
+
 -export([start_link/0,
 		lookup/1,
 		insert/2,

+ 4 - 0
src/emqtt_router.erl

@@ -17,8 +17,12 @@
 
 -include("emqtt_frame.hrl").
 
+-include("emqtt_internal.hrl").
+
 -include_lib("stdlib/include/qlc.hrl").
 
+-include_lib("elog/include/elog.hrl").
+
 -export([start_link/0]).
 
 -export([topics/0,

+ 1 - 1
src/emqtt_topic.erl

@@ -37,7 +37,7 @@
 %% There can be any number of root nodes; that is, there can be any number of topic trees.
 %% ------------------------------------------------------------------------
 
--include("emqtt.hrl").
+-include("emqtt_internal.hrl").
  
 -export([new/1,
 		 type/1,

+ 2 - 0
src/tcp_listener.erl

@@ -18,6 +18,8 @@
 
 -include("emqtt.hrl").
 
+-include_lib("elog/include/elog.hrl").
+
 -behaviour(gen_server).
 
 -export([start_link/8]).