mqtt_topic
This commit is contained in:
parent
0816ec9966
commit
a1ed02499c
|
@ -36,16 +36,6 @@
|
||||||
|
|
||||||
-define(SHARE, <<"$share/">>). %% Shared Topic
|
-define(SHARE, <<"$share/">>). %% Shared Topic
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% MQTT Topic
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
-record(mqtt_topic, {
|
|
||||||
topic :: binary(),
|
|
||||||
flags :: [retained | static]
|
|
||||||
}).
|
|
||||||
|
|
||||||
-type mqtt_topic() :: #mqtt_topic{}.
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% PubSub
|
%% PubSub
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -54,6 +44,17 @@
|
||||||
|
|
||||||
-define(PUBSUB(PS), (PS =:= publish orelse PS =:= subscribe)).
|
-define(PUBSUB(PS), (PS =:= publish orelse PS =:= subscribe)).
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% MQTT Topic
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
|
-record(mqtt_topic, {
|
||||||
|
topic :: binary(),
|
||||||
|
flags = [] :: [retained | static]
|
||||||
|
}).
|
||||||
|
|
||||||
|
-type(mqtt_topic() :: #mqtt_topic{}).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% MQTT Client
|
%% MQTT Client
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -53,20 +53,19 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
mnesia(boot) ->
|
mnesia(boot) ->
|
||||||
|
ok = emqttd_mnesia:create_table(mqtt_topic, [
|
||||||
|
{ram_copies, [node()]},
|
||||||
|
{record_name, mqtt_topic},
|
||||||
|
{attributes, record_info(fields, mqtt_topic)}]),
|
||||||
ok = emqttd_mnesia:create_table(mqtt_route, [
|
ok = emqttd_mnesia:create_table(mqtt_route, [
|
||||||
{type, bag},
|
{type, bag},
|
||||||
{ram_copies, [node()]},
|
{ram_copies, [node()]},
|
||||||
{record_name, mqtt_route},
|
{record_name, mqtt_route},
|
||||||
{attributes, record_info(fields, mqtt_route)}]),
|
{attributes, record_info(fields, mqtt_route)}]);
|
||||||
|
|
||||||
ok = emqttd_mnesia:create_table(topic, [
|
|
||||||
{ram_copies, [node()]},
|
|
||||||
{record_name, mqtt_topic},
|
|
||||||
{attributes, record_info(fields, mqtt_topic)}]);
|
|
||||||
|
|
||||||
mnesia(copy) ->
|
mnesia(copy) ->
|
||||||
ok = emqttd_mnesia:copy_table(mqtt_route, ram_copies),
|
ok = emqttd_mnesia:copy_table(topic),
|
||||||
ok = emqttd_mnesia:copy_table(topic).
|
ok = emqttd_mnesia:copy_table(mqtt_route, ram_copies).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Start the Router
|
%% Start the Router
|
||||||
|
@ -126,7 +125,8 @@ add_route_(Route = #mqtt_route{topic = Topic}) ->
|
||||||
true -> emqttd_trie:insert(Topic);
|
true -> emqttd_trie:insert(Topic);
|
||||||
false -> ok
|
false -> ok
|
||||||
end,
|
end,
|
||||||
mnesia:write(Route);
|
mnesia:write(Route),
|
||||||
|
mnesia:write(#mqtt_topic{topic = Topic});
|
||||||
Records ->
|
Records ->
|
||||||
case lists:member(Route, Records) of
|
case lists:member(Route, Records) of
|
||||||
true -> ok;
|
true -> ok;
|
||||||
|
@ -164,7 +164,8 @@ del_route_(Route = #mqtt_route{topic = Topic}) ->
|
||||||
case emqttd_topic:wildcard(Topic) of
|
case emqttd_topic:wildcard(Topic) of
|
||||||
true -> emqttd_trie:delete(Topic);
|
true -> emqttd_trie:delete(Topic);
|
||||||
false -> ok
|
false -> ok
|
||||||
end;
|
end,
|
||||||
|
mnesia:delete({mqtt_topic, Topic});
|
||||||
_More ->
|
_More ->
|
||||||
%% Remove route only
|
%% Remove route only
|
||||||
mnesia:delete_object(Route)
|
mnesia:delete_object(Route)
|
||||||
|
|
Loading…
Reference in New Issue