refactor header file

This commit is contained in:
erylee 2013-06-28 11:01:23 +08:00
parent 860532fc68
commit 9bdbb84ed2
18 changed files with 90 additions and 94 deletions

View File

@ -24,83 +24,16 @@
-define(ERTS_MINIMUM, "5.6.3"). -define(ERTS_MINIMUM, "5.6.3").
-record(internal_user, {username, passwdhash}). %% qos levels
%name: <<"a/b/c">> -define(QOS_0, 0).
%node: node() -define(QOS_1, 1).
%words: [<<"a">>, <<"b">>, <<"c">>] -define(QOS_2, 2).
-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)).
-record(mqtt_msg, {retain,
qos,
topic,
dup,
message_id,
payload,
encoder}).

View File

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

View File

@ -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}).

View File

@ -13,5 +13,6 @@
{deps, [ {deps, [
{lager, ".*", {git, "git://github.com/basho/lager.git", {branch, "master"}}}, {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"}}} {folsom, ".*", {git, "git://github.com/boundary/folsom.git", {branch, "master"}}}
]}. ]}.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,7 +37,7 @@
%% There can be any number of root nodes; that is, there can be any number of topic trees. %% 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, -export([new/1,
type/1, type/1,

View File

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