pass test cases first
This commit is contained in:
parent
dd9217bf73
commit
6e64686f77
|
@ -217,41 +217,45 @@ topics(_) ->
|
||||||
{"topics show <Topic>", "Show a topic"}]).
|
{"topics show <Topic>", "Show a topic"}]).
|
||||||
|
|
||||||
subscriptions(["list"]) ->
|
subscriptions(["list"]) ->
|
||||||
lists:foreach(fun({Sub, Topic, Opts}) when is_pid(Sub) ->
|
lists:foreach(fun(Subscription) ->
|
||||||
?PRINT("~p -> ~s: ~p~n", [Sub, Topic, Opts]);
|
print(subscription, Subscription)
|
||||||
({Sub, Topic, Opts}) ->
|
end, []); %%emqttd:subscriptions());
|
||||||
?PRINT("~s -> ~s: ~p~n", [Sub, Topic, Opts])
|
|
||||||
end, emqttd:subscriptions());
|
|
||||||
|
|
||||||
subscriptions(["show", ClientId]) ->
|
subscriptions(["show", ClientId]) ->
|
||||||
case mnesia:dirty_read(mqtt_subscription, bin(ClientId)) of
|
case ets:lookup(mqtt_subscription, bin(ClientId)) of
|
||||||
[] -> ?PRINT_MSG("Not Found.~n");
|
[] -> ?PRINT_MSG("Not Found.~n");
|
||||||
Records -> print(Records)
|
Records -> [print(subscription, Subscription) || Subscription <- Records]
|
||||||
end;
|
end;
|
||||||
|
|
||||||
subscriptions(["add", ClientId, Topic, QoS]) ->
|
%%
|
||||||
Add = fun(IntQos) ->
|
%% subscriptions(["add", ClientId, Topic, QoS]) ->
|
||||||
Subscription = #mqtt_subscription{subid = bin(ClientId),
|
%% Add = fun(IntQos) ->
|
||||||
topic = bin(Topic),
|
%% Subscription = #mqtt_subscription{subid = bin(ClientId),
|
||||||
qos = IntQos},
|
%% topic = bin(Topic),
|
||||||
case emqttd_backend:add_subscription(Subscription) of
|
%% qos = IntQos},
|
||||||
ok ->
|
%% case emqttd_backend:add_subscription(Subscription) of
|
||||||
?PRINT_MSG("ok~n");
|
%% ok ->
|
||||||
{error, already_existed} ->
|
%% ?PRINT_MSG("ok~n");
|
||||||
?PRINT_MSG("Error: already existed~n");
|
%% {error, already_existed} ->
|
||||||
{error, Reason} ->
|
%% ?PRINT_MSG("Error: already existed~n");
|
||||||
?PRINT("Error: ~p~n", [Reason])
|
%% {error, Reason} ->
|
||||||
end
|
%% ?PRINT("Error: ~p~n", [Reason])
|
||||||
end,
|
%% end
|
||||||
if_valid_qos(QoS, Add);
|
%% end,
|
||||||
|
%% if_valid_qos(QoS, Add);
|
||||||
|
%%
|
||||||
|
|
||||||
subscriptions(["del", ClientId]) ->
|
%%
|
||||||
Ok = emqttd_backend:del_subscriptions(bin(ClientId)),
|
%% subscriptions(["del", ClientId]) ->
|
||||||
?PRINT("~p~n", [Ok]);
|
%% Ok = emqttd_backend:del_subscriptions(bin(ClientId)),
|
||||||
|
%% ?PRINT("~p~n", [Ok]);
|
||||||
|
%%
|
||||||
|
|
||||||
subscriptions(["del", ClientId, Topic]) ->
|
%%
|
||||||
Ok = emqttd_backend:del_subscription(bin(ClientId), bin(Topic)),
|
%% subscriptions(["del", ClientId, Topic]) ->
|
||||||
?PRINT("~p~n", [Ok]);
|
%% Ok = emqttd_backend:del_subscription(bin(ClientId), bin(Topic)),
|
||||||
|
%% ?PRINT("~p~n", [Ok]);
|
||||||
|
%%
|
||||||
|
|
||||||
subscriptions(_) ->
|
subscriptions(_) ->
|
||||||
?USAGE([{"subscriptions list", "List all subscriptions"},
|
?USAGE([{"subscriptions list", "List all subscriptions"},
|
||||||
|
@ -526,6 +530,11 @@ print({ClientId, _ClientPid, CleanSess, SessInfo}) ->
|
||||||
"created_at=~w)~n",
|
"created_at=~w)~n",
|
||||||
[ClientId, CleanSess | [format(Key, get_value(Key, SessInfo)) || Key <- InfoKeys]]).
|
[ClientId, CleanSess | [format(Key, get_value(Key, SessInfo)) || Key <- InfoKeys]]).
|
||||||
|
|
||||||
|
print(subscription, {Sub, Topic, Opts}) when is_pid(Sub) ->
|
||||||
|
?PRINT("~p -> ~s: ~p~n", [Sub, Topic, Opts]);
|
||||||
|
print(subscription, {Sub, Topic, Opts}) ->
|
||||||
|
?PRINT("~s -> ~s: ~p~n", [Sub, Topic, Opts]).
|
||||||
|
|
||||||
format(created_at, Val) ->
|
format(created_at, Val) ->
|
||||||
emqttd_time:now_to_secs(Val);
|
emqttd_time:now_to_secs(Val);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue