Bläddra i källkod

fix subscriptions cli

Feng 10 år sedan
förälder
incheckning
e37b00a9e4
1 ändrade filer med 12 tillägg och 4 borttagningar
  1. 12 4
      src/emqttd_cli.erl

+ 12 - 4
src/emqttd_cli.erl

@@ -241,19 +241,26 @@ subscriptions(["list"]) ->
 
 
 subscriptions(["show", ClientId]) ->
 subscriptions(["show", ClientId]) ->
     if_subscription(fun() ->
     if_subscription(fun() ->
-            case emqttd_pubsub:lookup(subscription, ClientId) of
+            case emqttd_pubsub:lookup(subscription, bin(ClientId)) of
                 []      -> ?PRINT_MSG("Not Found.~n");
                 []      -> ?PRINT_MSG("Not Found.~n");
                 Records -> print(subscription, ClientId, Records)
                 Records -> print(subscription, ClientId, Records)
             end
             end
         end);
         end);
 
 
 subscriptions(["add", ClientId, Topic, QoS]) ->
 subscriptions(["add", ClientId, Topic, QoS]) ->
-    Create = fun(IntQos) -> emqttd_pubsub:create(subscription, {ClientId, Topic, IntQos}) end,
+    Create = fun(IntQos) ->
+                Subscription = {bin(ClientId), bin(Topic), IntQos},
+                case emqttd_pubsub:create(subscription, Subscription) of
+                    ok             -> ?PRINT_MSG("ok~n");
+                    {error, Error} -> ?PRINT("Error: ~p~n", [Error])
+                end
+             end,
     if_subscription(fun() -> if_valid_qos(QoS, Create) end);
     if_subscription(fun() -> if_valid_qos(QoS, Create) end);
 
 
 subscriptions(["del", ClientId, Topic]) ->
 subscriptions(["del", ClientId, Topic]) ->
     if_subscription(fun() ->
     if_subscription(fun() ->
-            emqttd_pubsub:delete(subscription, {ClientId, Topic})
+            Ok = emqttd_pubsub:delete(subscription, {bin(ClientId), bin(Topic)}),
+            ?PRINT("~p~n", [Ok])
         end);
         end);
 
 
 subscriptions(_) ->
 subscriptions(_) ->
@@ -279,7 +286,8 @@ if_could_print(Tab, Fun) ->
 
 
 if_valid_qos(QoS, Fun) ->
 if_valid_qos(QoS, Fun) ->
     try list_to_integer(QoS) of
     try list_to_integer(QoS) of
-        Int when ?IS_QOS(Int) -> Fun(Int)
+        Int when ?IS_QOS(Int) -> Fun(Int);
+        _ -> ?PRINT_MSG("QoS should be 0, 1, 2~n")
     catch _:_ ->
     catch _:_ ->
         ?PRINT_MSG("QoS should be 0, 1, 2~n")
         ?PRINT_MSG("QoS should be 0, 1, 2~n")
     end.
     end.