فهرست منبع

Add plugin type

turtled 6 سال پیش
والد
کامیت
481458d8ec
2فایلهای تغییر یافته به همراه13 افزوده شده و 5 حذف شده
  1. 2 1
      include/emqx.hrl
  2. 11 4
      src/emqx_plugins.erl

+ 2 - 1
include/emqx.hrl

@@ -132,7 +132,8 @@
           descr          :: string(),
           descr          :: string(),
           vendor         :: string(),
           vendor         :: string(),
           active = false :: boolean(),
           active = false :: boolean(),
-          info           :: map()
+          info           :: map(),
+          type           :: atom()
         }).
         }).
 
 
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------

+ 11 - 4
src/emqx_plugins.erl

@@ -151,20 +151,20 @@ stop_plugins(Names) ->
 -spec(list() -> [emqx_types:plugin()]).
 -spec(list() -> [emqx_types:plugin()]).
 list() ->
 list() ->
     StartedApps = names(started_app),
     StartedApps = names(started_app),
-    lists:map(fun({Name, _, _}) ->
-        Plugin = plugin(Name),
+    lists:map(fun({Name, _, [Type| _]}) ->
+        Plugin = plugin(Name, Type),
         case lists:member(Name, StartedApps) of
         case lists:member(Name, StartedApps) of
             true  -> Plugin#plugin{active = true};
             true  -> Plugin#plugin{active = true};
             false -> Plugin
             false -> Plugin
         end
         end
     end, lists:sort(ekka_boot:all_module_attributes(emqx_plugin))).
     end, lists:sort(ekka_boot:all_module_attributes(emqx_plugin))).
 
 
-plugin(AppName) ->
+plugin(AppName, Type) ->
     case application:get_all_key(AppName) of
     case application:get_all_key(AppName) of
         {ok, Attrs} ->
         {ok, Attrs} ->
             Ver = proplists:get_value(vsn, Attrs, "0"),
             Ver = proplists:get_value(vsn, Attrs, "0"),
             Descr = proplists:get_value(description, Attrs, ""),
             Descr = proplists:get_value(description, Attrs, ""),
-            #plugin{name = AppName, version = Ver, descr = Descr};
+            #plugin{name = AppName, version = Ver, descr = Descr, type = plugin_type(Type)};
         undefined -> error({plugin_not_found, AppName})
         undefined -> error({plugin_not_found, AppName})
     end.
     end.
 
 
@@ -316,3 +316,10 @@ write_loaded(AppNames) ->
             ?LOG(error, "Open File ~p Error: ~p", [File, Error]),
             ?LOG(error, "Open File ~p Error: ~p", [File, Error]),
             {error, Error}
             {error, Error}
     end.
     end.
+
+plugin_type(auth) -> auth;
+plugin_type(protocol) -> protocol;
+plugin_type(backend) -> backend;
+plugin_type(bridge) -> bridge;
+plugin_type(_) -> feature.
+