<commit_before>%%%-------------------------------------------------------------------
%%% @author <NAME> <<EMAIL>>
%%% @copyright (C) 2014, <NAME>
%%% @doc
%%%
%%% @end
%%% Created : 20 Jan 2014 by <NAME> <<EMAIL>>
%%%-------------------------------------------------------------------
-module(marionet_sub_event_handler).

-behaviour(gen_event).

%% gen_event callbacks
-export([init/1, handle_event/2, handle_call/2, 
	 handle_info/2, terminate/2, code_change/3]).

-define(SERVER, ?MODULE).

-record(state, {subs :: list()}).

%%%===================================================================
%%% gen_event callbacks
%%%===================================================================

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Whenever a new event handler is added to an event manager,
%% this function is called to initialize the event handler.
%%
%% @spec init(Args) -> {ok, State}
%% @end
%%--------------------------------------------------------------------
init([Subscribes]) ->
    {ok, #state{subs = Subscribes}}.

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Whenever an event manager receives an event sent using
%% gen_event:notify/2 or gen_event:sync_notify/2, this function is
%% called for each installed event handler to handle the event.
%%
%% @spec handle_event(Event, State) ->
%%                          {ok, State} |
%%                          {swap_handler, Args1, State1, Mod2, Args2} |
%%                          remove_handler
%% @end
%%--------------------------------------------------------------------
handle_event({connack_accept}, State=#state{subs=Subscribes}) ->
    ok = emqttc:subscribe(emqttc, Subscribes),
    io:format("sent subscribe request: ~p~n", [Subscribes]),
    {ok, State};

handle_event({publish, <<"marionet/1/digital/0">> = Topic, Payload, 1, MsgId},
	     State) ->
    lager:info("publish: topic(id:~p):~p~n", [MsgId, Topic]),
    {ok, [16#01, _PortNo, StateList]} = marionet_data:unpack(Payload),
    lager:info("publish: state:~p~n", [StateList]),
    [_, State, _, _, _, _, _, _] = StateList,
    gpio_pin:write(25, State),
    {ok, State};

handle_event({publish, <<"marionet/2/digital/0">> = Topic, Payload, 1, MsgId},
	     State) ->
    lager:info("publish: topic(id:~p):~p~n", [MsgId, Topic]),
    {ok, [16#01, _PortNo, StateList]} = marionet_data:unpack(Payload),
    lager:info("publish: state:~p~n", [StateList]),
    [_, State, _, _, _, _, _, _] = StateList,
    gpio_pin:write(25, State),
    {ok, State};

handle_event({publish, Topic, Payload}, State) ->
    lager:info("publish: topic:~p~n", [Topic]),
    lager:info("publish: payload:~p~n", [Payload]),
    {ok, State};

handle_event({publish, Topic, Payload, 1, MsgId}, State) ->
    lager:info("publish: topic(id:~p):~p~n", [MsgId, Topic]),
    lager:info("publish: payload:~p~n", [Payload]),
    emqttc:puback(emqttc, MsgId),
    {ok, State};

handle_event(_Event, State) ->
    {ok, State}.

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Whenever an event manager receives a request sent using
%% gen_event:call/3,4, this function is called for the specified
%% event handler to handle the request.
%%
%% @spec handle_call(Request, State) ->
%%                   {ok, Reply, State} |
%%                   {swap_handler, Reply, Args1, State1, Mod2, Args2} |<commit_msg>modify for debug<commit_after>%%%-------------------------------------------------------------------
%%% @author HIRO<NAME> <<EMAIL>>
%%% @copyright (C) 2014, <NAME>
%%% @doc
%%%
%%% @end
%%% Created : 20 Jan 2014 by <NAME> <<EMAIL>>
%%%-------------------------------------------------------------------
-module(marionet_sub_event_handler).

-behaviour(gen_event).

%% gen_event callbacks
-export([init/1, handle_event/2, handle_call/2, 
	 handle_info/2, terminate/2, code_change/3]).

-define(SERVER, ?MODULE).

-record(state, {subs :: list()}).

%%%===================================================================
%%% gen_event callbacks
%%%===================================================================

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Whenever a new event handler is added to an event manager,
%% this function is called to initialize the event handler.
%%
%% @spec init(Args) -> {ok, State}
%% @end
%%--------------------------------------------------------------------
init([Subscribes]) ->
    {ok, #state{subs = Subscribes}}.

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Whenever an event manager receives an event sent using
%% gen_event:notify/2 or gen_event:sync_notify/2, this function is
%% called for each installed event handler to handle the event.
%%
%% @spec handle_event(Event, State) ->
%%                          {ok, State} |
%%                          {swap_handler, Args1, State1, Mod2, Args2} |
%%                          remove_handler
%% @end
%%--------------------------------------------------------------------
handle_event({connack_accept}, State=#state{subs=Subscribes}) ->
    ok = emqttc:subscribe(emqttc, Subscribes),
    io:format("sent subscribe request: ~p~n", [Subscribes]),
    {ok, State};

handle_event({publish, <<"marionet/1/digital/0">> = Topic, Payload, 1, MsgId},
	     State) ->
    lager:info("publish: topic(id:~p):~p~n", [MsgId, Topic]),
    {ok, [16#01, _PortNo, StateList]} = marionet_data:unpack(Payload),
    lager:info("publish: state:~p~n", [StateList]),
    [_, _, _, _, S, _, _, _] = StateList,
    gpio_pin:write(25, S),
    {ok, State};

handle_event({publish, <<"marionet/2/digital/0">> = Topic, Payload, 1, MsgId},
	     State) ->
    lager:info("publish: topic(id:~p):~p~n", [MsgId, Topic]),
    {ok, [16#01, _PortNo, StateList]} = marionet_data:unpack(Payload),
    lager:info("publish: state:~p~n", [StateList]),
    [_, _, _, _, S, _, _, _] = StateList,
    gpio_pin:write(25, S),
    {ok, State};

handle_event({publish, Topic, Payload}, State) ->
    lager:info("publish: topic:~p~n", [Topic]),
    lager:info("publish: payload:~p~n", [Payload]),
    {ok, State};

handle_event({publish, Topic, Payload, 1, MsgId}, State) ->
    lager:info("publish: topic(id:~p):~p~n", [MsgId, Topic]),
    lager:info("publish: payload:~p~n", [Payload]),
    emqttc:puback(emqttc, MsgId),
    {ok, State};

handle_event(_Event, State) ->
    {ok, State}.

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Whenever an event manager receives a request sent using
%% gen_event:call/3,4, this function is called for the specified
%% event handler to handle the request.
%%
%% @spec handle_call(Request, State) ->
%%                   {ok, Reply, State} |
%%                   {swap_handler, Reply, Args1, State1, Mod2, Args2} |
{'fraction_non_alphanumeric': 0.3351210320336281, 'fraction_numerical': 0.013625163067111175, 'mean_word_length': 2.2348804500703237, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2472546', 'n_tokens_mistral': 2159, 'n_tokens_neox': 2078, 'n_words': 474}