fix service
This commit is contained in:
parent
6c96c18332
commit
d15efa1a96
@ -4,6 +4,7 @@
|
|||||||
%%% @doc
|
%%% @doc
|
||||||
%%% 1. 需要管理服务的整个生命周期,包括: 启动,停止
|
%%% 1. 需要管理服务的整个生命周期,包括: 启动,停止
|
||||||
%%% 2. 需要监控服务的状态,通过port的方式
|
%%% 2. 需要监控服务的状态,通过port的方式
|
||||||
|
%%% 3. 服务的启动和关闭,需要在更高的层级控制
|
||||||
%%% @end
|
%%% @end
|
||||||
%%% Created : 18. 4月 2025 16:50
|
%%% Created : 18. 4月 2025 16:50
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
@ -15,7 +16,7 @@
|
|||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/2]).
|
-export([start_link/2]).
|
||||||
-export([get_name/1, get_pid/1, start_service/1, stop_service/1, attach_channel/2]).
|
-export([get_name/1, get_pid/1, attach_channel/2]).
|
||||||
-export([push_config/3, request_config/1, invoke/3]).
|
-export([push_config/3, request_config/1, invoke/3]).
|
||||||
-export([metric_data/3, send_event/3]).
|
-export([metric_data/3, send_event/3]).
|
||||||
|
|
||||||
@ -47,18 +48,23 @@ get_name(ServiceId) when is_binary(ServiceId) ->
|
|||||||
get_pid(ServiceId) when is_binary(ServiceId) ->
|
get_pid(ServiceId) when is_binary(ServiceId) ->
|
||||||
whereis(get_name(ServiceId)).
|
whereis(get_name(ServiceId)).
|
||||||
|
|
||||||
|
-spec push_config(Pid :: pid(), Ref :: reference(), ConfigJson :: binary()) -> no_return().
|
||||||
push_config(Pid, Ref, ConfigJson) when is_pid(Pid), is_binary(ConfigJson) ->
|
push_config(Pid, Ref, ConfigJson) when is_pid(Pid), is_binary(ConfigJson) ->
|
||||||
gen_server:cast(Pid, {push_config, Ref, self(), ConfigJson}).
|
gen_server:cast(Pid, {push_config, Ref, self(), ConfigJson}).
|
||||||
|
|
||||||
|
-spec push_config(Pid :: pid(), Ref :: reference(), Payload :: binary()) -> no_return().
|
||||||
invoke(Pid, Ref, Payload) when is_pid(Pid), is_reference(Ref), is_binary(Payload) ->
|
invoke(Pid, Ref, Payload) when is_pid(Pid), is_reference(Ref), is_binary(Payload) ->
|
||||||
gen_server:cast(Pid, {invoke, Ref, self(), Payload}).
|
gen_server:cast(Pid, {invoke, Ref, self(), Payload}).
|
||||||
|
|
||||||
|
-spec request_config(Pid :: pid()) -> {ok, Config :: binary()}.
|
||||||
request_config(Pid) when is_pid(Pid) ->
|
request_config(Pid) when is_pid(Pid) ->
|
||||||
gen_server:call(Pid, request_config).
|
gen_server:call(Pid, request_config).
|
||||||
|
|
||||||
|
-spec metric_data(Pid :: pid(), DeviceUUID :: binary(), Data :: binary()) -> no_return().
|
||||||
metric_data(Pid, DeviceUUID, Data) when is_pid(Pid), is_binary(DeviceUUID), is_binary(Data) ->
|
metric_data(Pid, DeviceUUID, Data) when is_pid(Pid), is_binary(DeviceUUID), is_binary(Data) ->
|
||||||
gen_server:cast(Pid, {metric_data, DeviceUUID, Data}).
|
gen_server:cast(Pid, {metric_data, DeviceUUID, Data}).
|
||||||
|
|
||||||
|
-spec send_event(Pid :: pid(), EventType :: integer(), Params :: binary()) -> no_return().
|
||||||
send_event(Pid, EventType, Params) when is_pid(Pid), is_integer(EventType), is_binary(Params) ->
|
send_event(Pid, EventType, Params) when is_pid(Pid), is_integer(EventType), is_binary(Params) ->
|
||||||
gen_server:cast(Pid, {send_event, EventType, Params}).
|
gen_server:cast(Pid, {send_event, EventType, Params}).
|
||||||
|
|
||||||
@ -66,14 +72,6 @@ send_event(Pid, EventType, Params) when is_pid(Pid), is_integer(EventType), is_b
|
|||||||
attach_channel(Pid, ChannelPid) when is_pid(Pid), is_pid(ChannelPid) ->
|
attach_channel(Pid, ChannelPid) when is_pid(Pid), is_pid(ChannelPid) ->
|
||||||
gen_server:call(Pid, {attach_channel, ChannelPid}).
|
gen_server:call(Pid, {attach_channel, ChannelPid}).
|
||||||
|
|
||||||
-spec start_service(Pid :: pid()) -> ok | {error, Reason :: binary()}.
|
|
||||||
start_service(Pid) when is_pid(Pid) ->
|
|
||||||
gen_server:call(Pid, start_service).
|
|
||||||
|
|
||||||
-spec stop_service(Pid :: pid()) -> ok | {error, Reason :: binary()}.
|
|
||||||
stop_service(Pid) when is_pid(Pid) ->
|
|
||||||
gen_server:call(Pid, stop_service).
|
|
||||||
|
|
||||||
%% @doc Spawns the server and registers the local name (unique)
|
%% @doc Spawns the server and registers the local name (unique)
|
||||||
-spec(start_link(Name :: atom(), Service :: binary()) ->
|
-spec(start_link(Name :: atom(), Service :: binary()) ->
|
||||||
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
|
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user