WIP: Need to switch to wxAcceleratorTable
This commit is contained in:
+11
-11
@@ -55,7 +55,7 @@
|
|||||||
-type state() :: #s{}.
|
-type state() :: #s{}.
|
||||||
-type ui_name() :: gd_v_netman
|
-type ui_name() :: gd_v_netman
|
||||||
| gd_v_wallman
|
| gd_v_wallman
|
||||||
| gd_v_doomweaver
|
| gd_v_fateweaver
|
||||||
| gd_v_express.
|
| gd_v_express.
|
||||||
|
|
||||||
|
|
||||||
@@ -248,8 +248,8 @@ open_contract(ConID) ->
|
|||||||
when ConID :: string(),
|
when ConID :: string(),
|
||||||
DevmanToFront :: boolean().
|
DevmanToFront :: boolean().
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Ask the controller to tell the doomweaver interface to open a deployed contract.
|
%% Ask the controller to tell the fateweaver interface to open a deployed contract.
|
||||||
%% The controller will start the doomweaver if it isn't already on.
|
%% The controller will start the fateweaver if it isn't already on.
|
||||||
|
|
||||||
open_contract(ConID, DevmanToFront) when is_binary(ConID) ->
|
open_contract(ConID, DevmanToFront) when is_binary(ConID) ->
|
||||||
gd_server:cast(?MODULE, {open_contract, ConID, DevmanToFront});
|
gd_server:cast(?MODULE, {open_contract, ConID, DevmanToFront});
|
||||||
@@ -272,9 +272,9 @@ show_call(ConID, Info) ->
|
|||||||
Info :: map(),
|
Info :: map(),
|
||||||
DevmanToFront :: boolean().
|
DevmanToFront :: boolean().
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Ask the controller to tell the doomweaver interface to dislpay the result of a call
|
%% Ask the controller to tell the fateweaver interface to dislpay the result of a call
|
||||||
%% to the indicated contract. Opens the contract in question if it isn't alread open.
|
%% to the indicated contract. Opens the contract in question if it isn't alread open.
|
||||||
%% Starts the doomweaver if it isn't already running.
|
%% Starts the fateweaver if it isn't already running.
|
||||||
|
|
||||||
show_call(ConID, Info, DevmanToFront) when is_binary(ConID) ->
|
show_call(ConID, Info, DevmanToFront) when is_binary(ConID) ->
|
||||||
gd_server:cast(?MODULE, {show_call, ConID, Info, DevmanToFront});
|
gd_server:cast(?MODULE, {show_call, ConID, Info, DevmanToFront});
|
||||||
@@ -661,7 +661,7 @@ task_data(gd_v_netman, #s{wallet = none}) ->
|
|||||||
[];
|
[];
|
||||||
task_data(gd_v_wallman, #s{wallets = Wallets}) ->
|
task_data(gd_v_wallman, #s{wallets = Wallets}) ->
|
||||||
Wallets;
|
Wallets;
|
||||||
task_data(gd_v_doomweaver, #s{}) ->
|
task_data(gd_v_fateweaver, #s{}) ->
|
||||||
[];
|
[];
|
||||||
task_data(gd_v_express, State) ->
|
task_data(gd_v_express, State) ->
|
||||||
{ok, Selected, Keys} = do_list_keys(State),
|
{ok, Selected, Keys} = do_list_keys(State),
|
||||||
@@ -1075,15 +1075,15 @@ do_drop_key(ID, State = #s{wallet = W, wallets = Wallets, pass = Pass}) ->
|
|||||||
|
|
||||||
|
|
||||||
do_open_contract(ConID, ToFront, State) ->
|
do_open_contract(ConID, ToFront, State) ->
|
||||||
NewState = do_show_ui(gd_v_doomweaver, ToFront, State),
|
NewState = do_show_ui(gd_v_fateweaver, ToFront, State),
|
||||||
ok = gd_v_doomweaver:open_contract(ConID),
|
ok = gd_v_fateweaver:open_contract(ConID),
|
||||||
NewState.
|
NewState.
|
||||||
|
|
||||||
|
|
||||||
do_show_call(ConID, Info, ToFront, State) ->
|
do_show_call(ConID, Info, ToFront, State) ->
|
||||||
NewState = do_show_ui(gd_v_doomweaver, ToFront, State),
|
NewState = do_show_ui(gd_v_fateweaver, ToFront, State),
|
||||||
ok = gd_v_doomweaver:open_contract(ConID),
|
ok = gd_v_fateweaver:open_contract(ConID),
|
||||||
ok = gd_v_doomweaver:call_result(ConID, Info),
|
ok = gd_v_fateweaver:call_result(ConID, Info),
|
||||||
NewState.
|
NewState.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+32
-12
@@ -291,7 +291,7 @@ handle_event(#wx{event = #wxCommand{type = command_button_clicked},
|
|||||||
case lists:keyfind(ID, #w.id, Buttons) of
|
case lists:keyfind(ID, #w.id, Buttons) of
|
||||||
#w{name = wallet} -> wallman(State);
|
#w{name = wallet} -> wallman(State);
|
||||||
#w{name = chain} -> netman(State);
|
#w{name = chain} -> netman(State);
|
||||||
#w{name = dev} -> doomweaver(State);
|
#w{name = dev} -> fateweaver(State);
|
||||||
#w{name = node} -> set_node(State);
|
#w{name = node} -> set_node(State);
|
||||||
#w{name = make_key} -> make_key(State);
|
#w{name = make_key} -> make_key(State);
|
||||||
#w{name = recover} -> recover_key(State);
|
#w{name = recover} -> recover_key(State);
|
||||||
@@ -312,13 +312,15 @@ handle_event(#wx{event = #wxCommand{type = command_listbox_selected,
|
|||||||
State) ->
|
State) ->
|
||||||
NewState = do_selection(Selected, State),
|
NewState = do_selection(Selected, State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
handle_event(#wx{event = #wxKey{keyCode = Code}}, State) ->
|
handle_event(#wx{event = Event = #wxKey{keyCode = Code}}, State = #s{frame = Frame}) ->
|
||||||
NewState =
|
NewState =
|
||||||
case Code of
|
case Code of
|
||||||
69 -> express(State);
|
69 -> express(State); % 'E'
|
||||||
70 -> doomweaver(State);
|
70 -> fateweaver(State); % 'F'
|
||||||
_ ->
|
_ ->
|
||||||
ok = io:format("Code: ~p~n", [Code]),
|
ok = tell(info, "Code: ~p", [Code]),
|
||||||
|
ok = tell(info, "Frame ID: ~p", [wxFrame:getId(Frame)]),
|
||||||
|
ok = tell(info, "Event: ~p", [Event]),
|
||||||
State
|
State
|
||||||
end,
|
end,
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
@@ -377,10 +379,10 @@ netman(State) ->
|
|||||||
State.
|
State.
|
||||||
|
|
||||||
|
|
||||||
doomweaver(State = #s{accounts = []}) ->
|
fateweaver(State = #s{accounts = []}) ->
|
||||||
State;
|
State;
|
||||||
doomweaver(State) ->
|
fateweaver(State) ->
|
||||||
ok = gd_con:show_ui(gd_v_doomweaver),
|
ok = gd_con:show_ui(gd_v_fateweaver),
|
||||||
State.
|
State.
|
||||||
|
|
||||||
|
|
||||||
@@ -392,6 +394,7 @@ express(State) ->
|
|||||||
|
|
||||||
|
|
||||||
set_node(State = #s{frame = Frame, j = J}) ->
|
set_node(State = #s{frame = Frame, j = J}) ->
|
||||||
|
true = wxFrame:disconnect(Frame, char_hook),
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Set Node")),
|
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Set Node")),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
|
||||||
@@ -443,6 +446,7 @@ set_node(State = #s{frame = Frame, j = J}) ->
|
|||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
|
ok = wxFrame:connect(Frame, char_hook),
|
||||||
State.
|
State.
|
||||||
|
|
||||||
add_node2(Address, PortCtrls) ->
|
add_node2(Address, PortCtrls) ->
|
||||||
@@ -475,6 +479,7 @@ s_to_i(S) ->
|
|||||||
|
|
||||||
|
|
||||||
make_key(State = #s{frame = Frame, j = J}) ->
|
make_key(State = #s{frame = Frame, j = J}) ->
|
||||||
|
true = wxFrame:disconnect(Frame, char_hook),
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("New Key")),
|
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("New Key")),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
|
||||||
@@ -544,10 +549,12 @@ make_key(State = #s{frame = Frame, j = J}) ->
|
|||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
|
ok = wxFrame:connect(Frame, char_hook),
|
||||||
State.
|
State.
|
||||||
|
|
||||||
|
|
||||||
recover_key(State = #s{frame = Frame, j = J}) ->
|
recover_key(State = #s{frame = Frame, j = J}) ->
|
||||||
|
true = wxFrame:disconnect(Frame, char_hook),
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Mnemonic")),
|
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Mnemonic")),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
||||||
MnemSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Recovery Phrase")}]),
|
MnemSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Recovery Phrase")}]),
|
||||||
@@ -573,6 +580,7 @@ recover_key(State = #s{frame = Frame, j = J}) ->
|
|||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
|
ok = wxFrame:connect(Frame, char_hook),
|
||||||
State.
|
State.
|
||||||
|
|
||||||
|
|
||||||
@@ -585,6 +593,7 @@ show_mnemonic(State = #s{picker = Picker}) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
show_mnemonic(Selected, State = #s{frame = Frame, j = J, accounts = Accounts}) ->
|
show_mnemonic(Selected, State = #s{frame = Frame, j = J, accounts = Accounts}) ->
|
||||||
|
true = wxFrame:disconnect(Frame, char_hook),
|
||||||
#poa{id = ID} = lists:nth(Selected, Accounts),
|
#poa{id = ID} = lists:nth(Selected, Accounts),
|
||||||
{ok, Mnemonic} = gd_con:mnemonic(ID),
|
{ok, Mnemonic} = gd_con:mnemonic(ID),
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Mnemonic")),
|
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Mnemonic")),
|
||||||
@@ -610,6 +619,7 @@ show_mnemonic(Selected, State = #s{frame = Frame, j = J, accounts = Accounts}) -
|
|||||||
?wxID_OK -> gd_lib:copy_to_clipboard(Mnemonic)
|
?wxID_OK -> gd_lib:copy_to_clipboard(Mnemonic)
|
||||||
end,
|
end,
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
|
ok = wxFrame:connect(Frame, char_hook),
|
||||||
State.
|
State.
|
||||||
|
|
||||||
|
|
||||||
@@ -644,6 +654,7 @@ drop_key(State = #s{picker = Picker}) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
drop_key(Selected, State = #s{frame = Frame, j = J, accounts = Accounts, prefs = Prefs}) ->
|
drop_key(Selected, State = #s{frame = Frame, j = J, accounts = Accounts, prefs = Prefs}) ->
|
||||||
|
true = wxFrame:disconnect(Frame, char_hook),
|
||||||
#poa{id = ID, name = Name} = lists:nth(Selected, Accounts),
|
#poa{id = ID, name = Name} = lists:nth(Selected, Accounts),
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("New Key"), [{size, {500, 150}}]),
|
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("New Key"), [{size, {500, 150}}]),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
||||||
@@ -672,6 +683,7 @@ drop_key(Selected, State = #s{frame = Frame, j = J, accounts = Accounts, prefs =
|
|||||||
Prefs
|
Prefs
|
||||||
end,
|
end,
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
|
ok = wxFrame:connect(Frame, char_hook),
|
||||||
State#s{prefs = NewPrefs}.
|
State#s{prefs = NewPrefs}.
|
||||||
|
|
||||||
|
|
||||||
@@ -841,6 +853,7 @@ do_chain(ChainID, #node{ip = IP}, #s{buttons = Buttons}) ->
|
|||||||
|
|
||||||
|
|
||||||
do_ask_password(#s{frame = Frame, prefs = Prefs, j = J}) ->
|
do_ask_password(#s{frame = Frame, prefs = Prefs, j = J}) ->
|
||||||
|
true = wxFrame:disconnect(Frame, char_hook),
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Password")),
|
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Password")),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
||||||
Label = J("Password (leave blank for no password)"),
|
Label = J("Password (leave blank for no password)"),
|
||||||
@@ -872,7 +885,8 @@ do_ask_password(#s{frame = Frame, prefs = Prefs, j = J}) ->
|
|||||||
?wxID_CANCEL ->
|
?wxID_CANCEL ->
|
||||||
gd_con:open_wallet(Path, none)
|
gd_con:open_wallet(Path, none)
|
||||||
end,
|
end,
|
||||||
wxDialog:destroy(Dialog).
|
ok = wxDialog:destroy(Dialog),
|
||||||
|
wxFrame:connect(Frame, char_hook).
|
||||||
|
|
||||||
do_grids_mess_sig(_, #s{accounts = []}) ->
|
do_grids_mess_sig(_, #s{accounts = []}) ->
|
||||||
ok;
|
ok;
|
||||||
@@ -901,6 +915,7 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
|
|||||||
"public_id" := ID,
|
"public_id" := ID,
|
||||||
"payload" := Message},
|
"payload" := Message},
|
||||||
#s{frame = Frame, j = J}) ->
|
#s{frame = Frame, j = J}) ->
|
||||||
|
true = wxFrame:disconnect(Frame, char_hook),
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Message Signature Request")),
|
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Message Signature Request")),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
||||||
Instruction =
|
Instruction =
|
||||||
@@ -936,13 +951,15 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
|
|||||||
?wxID_OK -> gd_con:sign_mess(Request);
|
?wxID_OK -> gd_con:sign_mess(Request);
|
||||||
?wxID_CANCEL -> ok
|
?wxID_CANCEL -> ok
|
||||||
end,
|
end,
|
||||||
wxDialog:destroy(Dialog);
|
ok = wxDialog:destroy(Dialog),
|
||||||
|
wxFrame:connect(Frame, char_hook);
|
||||||
do_grids_mess_sig2(Request = #{"grids" := 1,
|
do_grids_mess_sig2(Request = #{"grids" := 1,
|
||||||
"type" := "binary",
|
"type" := "binary",
|
||||||
"url" := URL,
|
"url" := URL,
|
||||||
"public_id" := ID,
|
"public_id" := ID,
|
||||||
"payload" := Base64},
|
"payload" := Base64},
|
||||||
#s{frame = Frame, j = J}) ->
|
#s{frame = Frame, j = J}) ->
|
||||||
|
true = wxFrame:disconnect(Frame, char_hook),
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Binary Data Signature Request")),
|
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Binary Data Signature Request")),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
||||||
Instruction =
|
Instruction =
|
||||||
@@ -978,7 +995,8 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
|
|||||||
?wxID_OK -> gd_con:sign_binary(Request);
|
?wxID_OK -> gd_con:sign_binary(Request);
|
||||||
?wxID_CANCEL -> ok
|
?wxID_CANCEL -> ok
|
||||||
end,
|
end,
|
||||||
wxDialog:destroy(Dialog);
|
ok = wxDialog:destroy(Dialog),
|
||||||
|
wxFrame:connect(Frame, char_hook);
|
||||||
do_grids_mess_sig2(Request = #{"grids" := 1,
|
do_grids_mess_sig2(Request = #{"grids" := 1,
|
||||||
"type" := "tx",
|
"type" := "tx",
|
||||||
"url" := URL,
|
"url" := URL,
|
||||||
@@ -987,6 +1005,7 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
|
|||||||
"public_id" := ID,
|
"public_id" := ID,
|
||||||
"payload" := CallData},
|
"payload" := CallData},
|
||||||
#s{frame = Frame, j = J}) ->
|
#s{frame = Frame, j = J}) ->
|
||||||
|
true = wxFrame:disconnect(Frame, char_hook),
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Message Signature Request")),
|
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Message Signature Request")),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
|
||||||
@@ -1034,6 +1053,7 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
|
|||||||
?wxID_OK -> gd_con:sign_tx(Request);
|
?wxID_OK -> gd_con:sign_tx(Request);
|
||||||
?wxID_CANCEL -> ok
|
?wxID_CANCEL -> ok
|
||||||
end,
|
end,
|
||||||
wxDialog:destroy(Dialog);
|
ok = wxDialog:destroy(Dialog),
|
||||||
|
wxFrame:connect(Frame, char_hook);
|
||||||
do_grids_mess_sig2(BadRequest, _) ->
|
do_grids_mess_sig2(BadRequest, _) ->
|
||||||
tell("Bad request: ~tp", [BadRequest]).
|
tell("Bad request: ~tp", [BadRequest]).
|
||||||
|
|||||||
+12
-4
@@ -37,11 +37,13 @@ fetch(Rider, Parcel) ->
|
|||||||
init(ID, Host = {Addr, Port}) ->
|
init(ID, Host = {Addr, Port}) ->
|
||||||
ok = tell(info, "Addr: ~p, Port: ~p", [Addr, Port]),
|
ok = tell(info, "Addr: ~p, Port: ~p", [Addr, Port]),
|
||||||
Options = [{mode, binary}, {active, once}, {packet, 4}, {keepalive, true}],
|
Options = [{mode, binary}, {active, once}, {packet, 4}, {keepalive, true}],
|
||||||
|
State = #s{id = ID, host = Host},
|
||||||
case gen_tcp:connect(Addr, Port, Options, 5000) of
|
case gen_tcp:connect(Addr, Port, Options, 5000) of
|
||||||
{ok, Socket} ->
|
{ok, Socket} ->
|
||||||
ok = tell(info, "Socket: ~p", [Socket]),
|
ok = tell(info, "Socket: ~p", [Socket]),
|
||||||
|
NextState = State#s{socket = Socket},
|
||||||
ok = gen_tcp:send(Socket, <<"GajuExpress 1 RECVR">>),
|
ok = gen_tcp:send(Socket, <<"GajuExpress 1 RECVR">>),
|
||||||
authenticate(#s{host = Host, socket = Socket});
|
authenticate(NextState);
|
||||||
Error ->
|
Error ->
|
||||||
ok = tell(warning, "Failed to connect to ~p with ~p", [Host, Error]),
|
ok = tell(warning, "Failed to connect to ~p with ~p", [Host, Error]),
|
||||||
retire(State, normal)
|
retire(State, normal)
|
||||||
@@ -92,13 +94,13 @@ get_list(State = #s{socket = Socket}) ->
|
|||||||
ok = inet:setopts(Socket, [{active, once}]),
|
ok = inet:setopts(Socket, [{active, once}]),
|
||||||
receive
|
receive
|
||||||
{tcp, Socket, Binary} ->
|
{tcp, Socket, Binary} ->
|
||||||
read_manifest(State, Binary);
|
read_manifest(State, Binary)
|
||||||
after 5000 ->
|
after 5000 ->
|
||||||
ok = tell(info, "Timed out on get_list/1"),
|
ok = tell(info, "Timed out on get_list/1"),
|
||||||
retire(State, normal)
|
retire(State, normal)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
read_manifest(State = #s{id = ID}, Binary) ->
|
read_manifest(State, Binary) ->
|
||||||
case zx_lib:b_to_ts(Binary) of
|
case zx_lib:b_to_ts(Binary) of
|
||||||
{ok, {pending, Manifest}} ->
|
{ok, {pending, Manifest}} ->
|
||||||
ok = gd_v_express:pending(Manifest),
|
ok = gd_v_express:pending(Manifest),
|
||||||
@@ -119,6 +121,7 @@ loop(State = #s{socket = Socket}) ->
|
|||||||
ok = tell(info, "Got: ~tp", [Message]),
|
ok = tell(info, "Got: ~tp", [Message]),
|
||||||
loop(State);
|
loop(State);
|
||||||
{fetch, ParcelID} ->
|
{fetch, ParcelID} ->
|
||||||
|
ok = do_fetch(State, ParcelID),
|
||||||
loop(State);
|
loop(State);
|
||||||
{tcp_closed, Socket} ->
|
{tcp_closed, Socket} ->
|
||||||
retire(State, normal);
|
retire(State, normal);
|
||||||
@@ -128,10 +131,15 @@ loop(State = #s{socket = Socket}) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
do_fetch(State, ParcelID) ->
|
||||||
|
tell(info, "Wood B Fetching! State: ~p ParcelID: ~p", [State, ParcelID]),
|
||||||
|
ok.
|
||||||
|
|
||||||
|
|
||||||
retire(#s{socket = none}, Reason) ->
|
retire(#s{socket = none}, Reason) ->
|
||||||
gd_v_express ! {retiring, self(), Reason},
|
gd_v_express ! {retiring, self(), Reason},
|
||||||
exit(Reason);
|
exit(Reason);
|
||||||
retire(#s{socket = Socket} Reason) ->
|
retire(#s{socket = Socket}, Reason) ->
|
||||||
ok = zx_net:disconnect(Socket),
|
ok = zx_net:disconnect(Socket),
|
||||||
gd_v_express ! {retiring, self(), Reason},
|
gd_v_express ! {retiring, self(), Reason},
|
||||||
exit(Reason).
|
exit(Reason).
|
||||||
|
|||||||
+72
-17
@@ -16,7 +16,7 @@
|
|||||||
-copyright("QPQ AG <info@qpq.swiss>").
|
-copyright("QPQ AG <info@qpq.swiss>").
|
||||||
-license("GPL-3.0-or-later").
|
-license("GPL-3.0-or-later").
|
||||||
|
|
||||||
-export([stuff/1, check/2]).
|
-export([quote/2, tx/2]).
|
||||||
-export([init/1, stop/1]).
|
-export([init/1, stop/1]).
|
||||||
-include("$zx_include/zx_logger.hrl").
|
-include("$zx_include/zx_logger.hrl").
|
||||||
|
|
||||||
@@ -25,14 +25,19 @@
|
|||||||
socket = none :: none | gen_tcp:socket()}).
|
socket = none :: none | gen_tcp:socket()}).
|
||||||
|
|
||||||
|
|
||||||
stuff(Rider) ->
|
quote(Rider, MochilaSize) ->
|
||||||
Rider ! {self(), host},
|
Ref = make_ref(),
|
||||||
receive {host, Stuff} -> Stuff end.
|
Rider ! {Ref, quote, MochilaSize},
|
||||||
|
receive
|
||||||
|
{Ref, Response} -> Response
|
||||||
|
after 6000 -> {error, timeout}
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
check(Rider, ID) ->
|
tx(Rider, MochilaPath) ->
|
||||||
Rider ! {check, ID},
|
Ref = make_ref(),
|
||||||
ok.
|
Rider ! {Ref, tx, MochilaPath},
|
||||||
|
receive {Ref, Response} -> Response end.
|
||||||
|
|
||||||
|
|
||||||
stop(Rider) ->
|
stop(Rider) ->
|
||||||
@@ -43,31 +48,81 @@ stop(Rider) ->
|
|||||||
init(Host = {Addr, Port}) ->
|
init(Host = {Addr, Port}) ->
|
||||||
ok = tell(info, "Addr: ~p, Port: ~p", [Addr, Port]),
|
ok = tell(info, "Addr: ~p, Port: ~p", [Addr, Port]),
|
||||||
Options = [{mode, binary}, {active, once}, {packet, 4}, {keepalive, true}],
|
Options = [{mode, binary}, {active, once}, {packet, 4}, {keepalive, true}],
|
||||||
|
State = #s{host = Host},
|
||||||
case gen_tcp:connect(Addr, Port, Options, 5000) of
|
case gen_tcp:connect(Addr, Port, Options, 5000) of
|
||||||
{ok, Socket} ->
|
{ok, Socket} ->
|
||||||
ok = tell(info, "Socket: ~p", [Socket]),
|
NextState = State#s{socket = Socket},
|
||||||
loop(#s{host = Host, socket = Socket});
|
ok = send(NextState, <<"GajuExpress 1 RIDER">>),
|
||||||
|
loop(NextState);
|
||||||
Error ->
|
Error ->
|
||||||
ok = tell(warning, "Failed to connect to ~p with ~p", [Host, Error]),
|
ok = tell(warning, "Failed to connect to ~p with ~p", [Host, Error]),
|
||||||
retire(normal)
|
retire(State, normal)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
loop(State = #s{socket = Socket}) ->
|
loop(State = #s{socket = Socket}) ->
|
||||||
ok = inet:setopts(Socket, [{active, once}]),
|
ok = inet:setopts(Socket, [{active, once}]),
|
||||||
receive
|
receive
|
||||||
{tcp, Socket, Message} ->
|
{tcp, Socket, Binary} ->
|
||||||
ok = tell(info, "Got: ~tp", [Message]),
|
ok = handle(State, Binary),
|
||||||
loop(State);
|
loop(State);
|
||||||
{check, ID} ->
|
{tcp_closed, Socket} ->
|
||||||
ok = gen_tcp:send(Socket, <<"GajuExpress 1 RECVR">>),
|
retire(State, normal);
|
||||||
|
{Ref, quote, Mochila} ->
|
||||||
|
Response = do_quote(State, Mochila),
|
||||||
|
gd_v_express ! {Ref, Response},
|
||||||
loop(State);
|
loop(State);
|
||||||
retire ->
|
retire ->
|
||||||
ok = gen_tcp:send(<<"bye">>),
|
retire(State, normal)
|
||||||
retire(normal)
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
retire(Reason) ->
|
handle(State = #s{socket = Socket}, Binary) ->
|
||||||
|
case zx_lib:b_to_ts(Binary) of
|
||||||
|
{ok, ping} ->
|
||||||
|
Pong = term_to_binary(pong),
|
||||||
|
send(Socket, Pong);
|
||||||
|
Error ->
|
||||||
|
ok = tell(info, "Received weird message: ~p", [Error]),
|
||||||
|
retire(State, normal)
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
send(State = #s{socket = Socket}, Binary) ->
|
||||||
|
case gen_tcp:send(Socket, Binary) of
|
||||||
|
ok ->
|
||||||
|
ok;
|
||||||
|
Error ->
|
||||||
|
ok = tell(info, "Send to GajuExpress failed with ~p", [Error]),
|
||||||
|
retire(State, normal)
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
do_quote(State = #s{socket = Socket}, MochilaSize) ->
|
||||||
|
Request = term_to_binary({quote, MochilaSize}),
|
||||||
|
ok = send(State, Request),
|
||||||
|
receive
|
||||||
|
{tcp, Socket, Binary} ->
|
||||||
|
read_quote(State, Binary)
|
||||||
|
after 5000 ->
|
||||||
|
retire(State, normal),
|
||||||
|
{error, timeout}
|
||||||
|
end.
|
||||||
|
|
||||||
|
read_quote(State, Binary) ->
|
||||||
|
case zx_lib:b_to_ts(Binary) of
|
||||||
|
{ok, {quote, Pucks}} ->
|
||||||
|
{ok, Pucks};
|
||||||
|
Error ->
|
||||||
|
ok = tell(info, "GajuExpress responded with trash: ~p", [Error]),
|
||||||
|
retire(State, normal)
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
retire(#s{socket = none}, Reason) ->
|
||||||
|
gd_v_express ! {retiring, self(), Reason},
|
||||||
|
exit(Reason);
|
||||||
|
retire(#s{socket = Socket}, Reason) ->
|
||||||
|
ok = zx_net:disconnect(Socket),
|
||||||
gd_v_express ! {retiring, self(), Reason},
|
gd_v_express ! {retiring, self(), Reason},
|
||||||
exit(Reason).
|
exit(Reason).
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
-module(gd_v_doomweaver).
|
-module(gd_v_fateweaver).
|
||||||
-vsn("0.10.0").
|
-vsn("0.10.0").
|
||||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||||
-copyright("QPQ AG <info@qpq.swiss>").
|
-copyright("QPQ AG <info@qpq.swiss>").
|
||||||
Reference in New Issue
Block a user