<commit_before>-module(chat_srv).
-include_lib("amqp_client.hrl").

-export([start_link/0]).
-export([terminate/2]).
-export([init/1, handle_call/3]).
-export([start_loop/3]).

-export([start_service/3]).
-export([stop_service/3]).

start_link() ->
	gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

init(_Args) ->
	{ok, dict:new()}.

%%
%% APIs
%%
start_service(ServerIp, ToClientEx, FromClientEx)
	when is_binary(ToClientEx), is_binary(FromClientEx) ->
	Reply = gen_server:call(?MODULE, {start_service, ServerIp, ToClientEx, FromClientEx}).

stop_service(ServerIp, ToClientEx, FromClientEx) ->
	Reply = gen_server:call(?MODULE, {stop_service, ServerIp, ToClientEx, FromClientEx}).
%%
%% Internal use.
%%

start_loop(ServerIp, ToClientEx, FromClientEx) ->
    InboundExchange = FromClientEx,
    OutboundExchange = ToClientEx, 

    
    % コネクション開く
    {ok, Connection} =
        amqp_connection:start(#amqp_params_network{host = "localhost"}),

    %% 送信用
    % OUTチャネル開く
    {ok, ChOut} = amqp_connection:open_channel(Connection),
    % エクスチェンジを宣言
    amqp_channel:call(ChOut, #'exchange.declare'{exchange = OutboundExchange, type = <<"fanout">>}),

    %% 受信用
    % Inチャネルを開く
    {ok, ChIn} = amqp_connection:open_channel(Connection),
    % エクスチェンジを宣言
    amqp_channel:call(ChIn, #'exchange.declare'{exchange = InboundExchange, type = <<"fanout">>}),
    % Inキューを宣言する。
    #'queue.declare_ok'{queue = Queue} = amqp_channel:call(ChIn, #'queue.declare'{exclusive = true}),
    % 指定のOUTエクスチェンジに受信キューをバインドする。
    amqp_channel:call(ChIn, #'queue.bind'{exchange = InboundExchange, queue = Queue}),
    % 指定のキューの購読開始。
    amqp_channel:subscribe(ChIn, #'basic.consume'{queue = Queue, no_ack = true}, self()),

    % ok待ち
    io:format(" [*] Waiting for logs. To exit press CTRL+C~n"),
    receive<commit_msg>fixed: not applied ServerIp parameter in start_service/3<commit_after>-module(chat_srv).
-include_lib("amqp_client.hrl").

-export([start_link/0]).
-export([terminate/2]).
-export([init/1, handle_call/3]).
-export([start_loop/3]).

-export([start_service/3]).
-export([stop_service/3]).

start_link() ->
	gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

init(_Args) ->
	{ok, dict:new()}.

%%
%% APIs
%%
start_service(ServerIp, ToClientEx, FromClientEx)
	when is_binary(ToClientEx), is_binary(FromClientEx) ->
	Reply = gen_server:call(?MODULE, {start_service, ServerIp, ToClientEx, FromClientEx}).

stop_service(ServerIp, ToClientEx, FromClientEx) ->
	Reply = gen_server:call(?MODULE, {stop_service, ServerIp, ToClientEx, FromClientEx}).
%%
%% Internal use.
%%

start_loop(ServerIp, ToClientEx, FromClientEx) ->
    InboundExchange = FromClientEx,
    OutboundExchange = ToClientEx, 

    
    % コネクション開く
    {ok, Connection} =
        amqp_connection:start(#amqp_params_network{host = ServerIp}),

    %% 送信用
    % OUTチャネル開く
    {ok, ChOut} = amqp_connection:open_channel(Connection),
    % エクスチェンジを宣言
    amqp_channel:call(ChOut, #'exchange.declare'{exchange = OutboundExchange, type = <<"fanout">>}),

    %% 受信用
    % Inチャネルを開く
    {ok, ChIn} = amqp_connection:open_channel(Connection),
    % エクスチェンジを宣言
    amqp_channel:call(ChIn, #'exchange.declare'{exchange = InboundExchange, type = <<"fanout">>}),
    % Inキューを宣言する。
    #'queue.declare_ok'{queue = Queue} = amqp_channel:call(ChIn, #'queue.declare'{exclusive = true}),
    % 指定のOUTエクスチェンジに受信キューをバインドする。
    amqp_channel:call(ChIn, #'queue.bind'{exchange = InboundExchange, queue = Queue}),
    % 指定のキューの購読開始。
    amqp_channel:subscribe(ChIn, #'basic.consume'{queue = Queue, no_ack = true}, self()),

    % ok待ち
    io:format(" [*] Waiting for logs. To exit press CTRL+C~n"),
    receive
{'fraction_non_alphanumeric': 0.16475722858701583, 'fraction_numerical': 0.004091653027823241, 'mean_word_length': 4.857827476038339, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '301141', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1446, 'n_words': 211}