From 481458d8ec8eaf9ed11f34a2d3615e0b37bb4453 Mon Sep 17 00:00:00 2001 From: turtled Date: Fri, 21 Jun 2019 14:09:41 +0800 Subject: [PATCH] Add plugin type --- include/emqx.hrl | 3 ++- src/emqx_plugins.erl | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/emqx.hrl b/include/emqx.hrl index fba079b91..e206ad51d 100644 --- a/include/emqx.hrl +++ b/include/emqx.hrl @@ -132,7 +132,8 @@ descr :: string(), vendor :: string(), active = false :: boolean(), - info :: map() + info :: map(), + type :: atom() }). %%-------------------------------------------------------------------- diff --git a/src/emqx_plugins.erl b/src/emqx_plugins.erl index b88fce472..cedb5c5b0 100644 --- a/src/emqx_plugins.erl +++ b/src/emqx_plugins.erl @@ -151,20 +151,20 @@ stop_plugins(Names) -> -spec(list() -> [emqx_types:plugin()]). list() -> 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 true -> Plugin#plugin{active = true}; false -> Plugin end end, lists:sort(ekka_boot:all_module_attributes(emqx_plugin))). -plugin(AppName) -> +plugin(AppName, Type) -> case application:get_all_key(AppName) of {ok, Attrs} -> Ver = proplists:get_value(vsn, Attrs, "0"), 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}) end. @@ -316,3 +316,10 @@ write_loaded(AppNames) -> ?LOG(error, "Open File ~p Error: ~p", [File, Error]), {error, Error} end. + +plugin_type(auth) -> auth; +plugin_type(protocol) -> protocol; +plugin_type(backend) -> backend; +plugin_type(bridge) -> bridge; +plugin_type(_) -> feature. +