[thrift] Erlang Thrift changes, take 3
Summary: svn ci missed a bunch of paths ... blew away the whole thing and copied from the git repo. this is getting ridiculous.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665285 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/erl/include/thrift.hrl.orig b/lib/erl/include/thrift.hrl.orig
new file mode 100644
index 0000000..53128ce
--- /dev/null
+++ b/lib/erl/include/thrift.hrl.orig
@@ -0,0 +1,19 @@
+%%% Copyright (c) 2007- Facebook
+%%% Distributed under the Thrift Software License
+%%%
+%%% See accompanying file LICENSE or visit the Thrift site at:
+%%% http://developers.facebook.com/thrift/
+
+-define(APPLICATION, thrift).
+
+-define(CONFIG_FILE, filename:join(code:priv_dir(?APPLICATION),
+ atom_to_list(?APPLICATION) ++ ".conf")).
+
+-define(ERROR(F, D),
+ error_logger:format(F, D)).
+
+-define(INFO(Type, Report),
+ error_logger:info_report({thrift_info, Type}, Report)).
+
+-include("thrift_macros.hrl").
+-include("thrift_constants.hrl").
diff --git a/lib/erl/include/thrift_constants.hrl b/lib/erl/include/thrift_constants.hrl
new file mode 100644
index 0000000..8aad0a9
--- /dev/null
+++ b/lib/erl/include/thrift_constants.hrl
@@ -0,0 +1,25 @@
+%%% Copyright (c) 2007- Facebook
+%%% Distributed under the Thrift Software License
+%%%
+%%% See accompanying file LICENSE or visit the Thrift site at:
+%%% http://developers.facebook.com/thrift/
+
+%% TType
+-define(tType_STOP, 0).
+-define(tType_VOID, 1).
+-define(tType_BOOL, 2).
+-define(tType_BYTE, 3).
+-define(tType_DOUBLE, 4).
+-define(tType_I16, 6).
+-define(tType_I32, 8).
+-define(tType_I64, 10).
+-define(tType_STRING, 11).
+-define(tType_STRUCT, 12).
+-define(tType_MAP, 13).
+-define(tType_SET, 14).
+-define(tType_LIST, 15).
+
+% TMessageType
+-define(tMessageType_CALL, 1).
+-define(tMessageType_REPLY, 2).
+-define(tMessageType_EXCEPTION, 3).
diff --git a/lib/erl/include/thrift_macros.hrl b/lib/erl/include/thrift_macros.hrl
new file mode 100644
index 0000000..9b8a200
--- /dev/null
+++ b/lib/erl/include/thrift_macros.hrl
@@ -0,0 +1,54 @@
+%%% Copyright (c) 2007- Facebook
+%%% Distributed under the Thrift Software License
+%%%
+%%% See accompanying file LICENSE or visit the Thrift site at:
+%%% http://developers.facebook.com/thrift/
+
+%% so bad. sigh. at least we have the arity embedded in the code without having to parse it.
+%% fix me please.
+
+%% local (same process)
+-define(L0(Method), oop:call(This, Method, [])).
+-define(L1(Method, Arg1), oop:call(This, Method, [Arg1])).
+-define(L2(Method, Arg1, Arg2), oop:call(This, Method, [Arg1, Arg2])).
+-define(L3(Method, Arg1, Arg2, Arg3), oop:call(This, Method, [Arg1, Arg2, Arg3])).
+-define(L4(Method, Arg1, Arg2, Arg3, Arg4), oop:call(This, Method, [Arg1, Arg2, Arg3, Arg4])).
+-define(L5(Method, Arg1, Arg2, Arg3, Arg4, Arg5), oop:call(This, Method, [Arg1, Arg2, Arg3, Arg4, Arg5])).
+-define(L6(Method, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), oop:call(This, Method, [Arg1, Arg2, Arg3, Arg4, Arg5, Arg6])).
+
+%% local (same process), but not This (e.g. t*Factory)
+-define(F0(Obj, Method), oop:call(Obj, Method, [])).
+-define(F1(Obj, Method, Arg1), oop:call(Obj, Method, [Arg1])).
+-define(F2(Obj, Method, Arg1, Arg2), oop:call(Obj, Method, [Arg1, Arg2])).
+-define(F3(Obj, Method, Arg1, Arg2, Arg3), oop:call(Obj, Method, [Arg1, Arg2, Arg3])).
+-define(F4(Obj, Method, Arg1, Arg2, Arg3, Arg4), oop:call(Obj, Method, [Arg1, Arg2, Arg3, Arg4])).
+-define(F5(Obj, Method, Arg1, Arg2, Arg3, Arg4, Arg5), oop:call(Obj, Method, [Arg1, Arg2, Arg3, Arg4, Arg5])).
+-define(F6(Obj, Method, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), oop:call(Obj, Method, [Arg1, Arg2, Arg3, Arg4, Arg5, Arg6])).
+
+%% remote (different process)
+-define(RT0(ServerRef, Method, Timeout), gen_server:call(ServerRef, {Method, []}, Timeout)).
+-define(RT1(ServerRef, Method, Timeout, Arg1), gen_server:call(ServerRef, {Method, [Arg1]}, Timeout)).
+-define(RT2(ServerRef, Method, Timeout, Arg1, Arg2), gen_server:call(ServerRef, {Method, [Arg1, Arg2]}, Timeout)).
+-define(RT3(ServerRef, Method, Timeout, Arg1, Arg2, Arg3), gen_server:call(ServerRef, {Method, [Arg1, Arg2, Arg3]}, Timeout)).
+-define(RT4(ServerRef, Method, Timeout, Arg1, Arg2, Arg3, Arg4), gen_server:call(ServerRef, {Method, [Arg1, Arg2, Arg3, Arg4]}, Timeout)).
+-define(RT5(ServerRef, Method, Timeout, Arg1, Arg2, Arg3, Arg4, Arg5), gen_server:call(ServerRef, {Method, [Arg1, Arg2, Arg3, Arg4, Arg5]}, Timeout)).
+-define(RT6(ServerRef, Method, Timeout, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), gen_server:call(ServerRef, {Method, [Arg1, Arg2, Arg3, Arg4, Arg5, Arg6]}, Timeout)).
+
+%% remote (different process), default timeout
+-define(DEFAULT_TIMEOUT, 5000).
+-define(R0(ServerRef, Method), ?RT0(ServerRef, Method, ?DEFAULT_TIMEOUT)).
+-define(R1(ServerRef, Method, Arg1), ?RT1(ServerRef, Method, ?DEFAULT_TIMEOUT, Arg1)).
+-define(R2(ServerRef, Method, Arg1, Arg2), ?RT2(ServerRef, Method, ?DEFAULT_TIMEOUT, Arg1, Arg2)).
+-define(R3(ServerRef, Method, Arg1, Arg2, Arg3), ?RT3(ServerRef, Method, ?DEFAULT_TIMEOUT, Arg1, Arg2, Arg3)).
+-define(R4(ServerRef, Method, Arg1, Arg2, Arg3, Arg4), ?RT4(ServerRef, Method, ?DEFAULT_TIMEOUT, Arg1, Arg2, Arg3, Arg4)).
+-define(R5(ServerRef, Method, Arg1, Arg2, Arg3, Arg4, Arg5), ?RT5(ServerRef, Method, ?DEFAULT_TIMEOUT, Arg1, Arg2, Arg3, Arg4, Arg5)).
+-define(R6(ServerRef, Method, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), ?RT6(ServerRef, Method, ?DEFAULT_TIMEOUT, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)).
+
+%% remote (different process), cast
+-define(C0(ServerRef, Method), gen_server:cast(ServerRef, {Method, []})).
+-define(C1(ServerRef, Method, Arg1), gen_server:cast(ServerRef, {Method, [Arg1]})).
+-define(C2(ServerRef, Method, Arg1, Arg2), gen_server:cast(ServerRef, {Method, [Arg1, Arg2]})).
+-define(C3(ServerRef, Method, Arg1, Arg2, Arg3), gen_server:cast(ServerRef, {Method, [Arg1, Arg2, Arg3]})).
+-define(C4(ServerRef, Method, Arg1, Arg2, Arg3, Arg4), gen_server:cast(ServerRef, {Method, [Arg1, Arg2, Arg3, Arg4]})).
+-define(C5(ServerRef, Method, Arg1, Arg2, Arg3, Arg4, Arg5), gen_server:cast(ServerRef, {Method, [Arg1, Arg2, Arg3, Arg4, Arg5]})).
+-define(C6(ServerRef, Method, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), gen_server:cast(ServerRef, {Method, [Arg1, Arg2, Arg3, Arg4, Arg5, Arg6]})).
diff --git a/lib/erl/priv/thrift.conf b/lib/erl/priv/thrift.conf
new file mode 100644
index 0000000..b32d21d
--- /dev/null
+++ b/lib/erl/priv/thrift.conf
@@ -0,0 +1,7 @@
+{thrift_logger, {
+ {term_width, 110},
+ {force_one_line, true},
+ {omit, [oop_new]}, % req_processed
+ {gen_server_messages, false},
+ {lookup, true} % DNS
+ }}.
diff --git a/lib/erl/src/thrift.app.src b/lib/erl/src/thrift.app.src
old mode 100755
new mode 100644
diff --git a/lib/erl/src/thrift.appup.src b/lib/erl/src/thrift.appup.src
old mode 100755
new mode 100644
diff --git a/lib/erl/src/thrift_app.erl b/lib/erl/src/thrift_app.erl
new file mode 100644
index 0000000..dabc7ed
--- /dev/null
+++ b/lib/erl/src/thrift_app.erl
@@ -0,0 +1,25 @@
+%%% Copyright (c) 2007- Facebook
+%%% Distributed under the Thrift Software License
+%%%
+%%% See accompanying file LICENSE or visit the Thrift site at:
+%%% http://developers.facebook.com/thrift/
+
+-module(thrift_app).
+
+-export([start/2, stop/1]).
+-behaviour(application).
+
+-include("thrift.hrl").
+
+%%%
+%%% behavior definition
+%%%
+
+start(_Type, _StartArgs) ->
+ io:format("starting thrift~n"),
+ thrift_logger:install(),
+ {ok, Sup} = thrift_app_sup:start_link(),
+ {ok, Sup}.
+
+stop(_State) ->
+ ok.
diff --git a/lib/erl/src/thrift_app_sup.erl b/lib/erl/src/thrift_app_sup.erl
new file mode 100644
index 0000000..3a44c3f
--- /dev/null
+++ b/lib/erl/src/thrift_app_sup.erl
@@ -0,0 +1,19 @@
+%%% Copyright (c) 2007- Facebook
+%%% Distributed under the Thrift Software License
+%%%
+%%% See accompanying file LICENSE or visit the Thrift site at:
+%%% http://developers.facebook.com/thrift/
+
+-module(thrift_app_sup).
+
+-behaviour(supervisor).
+
+-export([start_link/0, init/1]).
+
+-define(SERVER, ?MODULE).
+
+start_link() ->
+ supervisor:start_link({local, ?SERVER}, ?MODULE, []).
+
+init(_) ->
+ {ok, {{one_for_one,10,1}, []}}.
diff --git a/lib/erl/src/thrift_logger.erl b/lib/erl/src/thrift_logger.erl
index 6deb222..13649a5 100644
--- a/lib/erl/src/thrift_logger.erl
+++ b/lib/erl/src/thrift_logger.erl
@@ -140,7 +140,7 @@
end.
%%
-handle_event1({What, _Gleader, {Pid, Format, Data}}, State) when is_list(Format) ->
+handle_event1({What, _Gleader, {Ref, Format, Data}}, State) when is_list(Format) ->
Symbol = case What of
error -> "!!";
warning_msg -> "**";
diff --git a/lib/erl/src/thrift_sup.erl b/lib/erl/src/thrift_sup.erl
new file mode 100644
index 0000000..8f6eaf7
--- /dev/null
+++ b/lib/erl/src/thrift_sup.erl
@@ -0,0 +1,40 @@
+%%% Copyright (c) 2007- Facebook
+%%% Distributed under the Thrift Software License
+%%%
+%%% See accompanying file LICENSE or visit the Thrift site at:
+%%% http://developers.facebook.com/thrift/
+
+-module(thrift_sup).
+
+-behaviour(supervisor).
+
+-include("thrift.hrl").
+
+-export([start_link/3, init/1, thrift_start_link/7]).
+
+-define(SERVER, ?MODULE).
+
+start_link(Port, Handler, Processor) ->
+ Args = [Port, Handler, Processor],
+ supervisor:start_link({local, ?SERVER}, ?MODULE, Args).
+
+init([Port, Handler, Processor]) ->
+ TF = tBufferedTransportFactory,
+ PF = tBinaryProtocolFactory,
+ ST = tErlAcceptor,
+ SF = tErlServer,
+
+ ThriftModules = [TF, PF, ST, SF],
+
+ Args = [SF, Port, Handler, Processor, ST, TF, PF],
+
+ ThriftServer = {thrift_server, {?MODULE, thrift_start_link, Args},
+ permanent, 2000, worker, ThriftModules},
+
+ {ok, {{one_for_one, 10, 1}, [ThriftServer]}}.
+
+thrift_start_link(SF = tErlServer, Port, Hnd, Pr, ST, TF, PF) ->
+ Args = [Port, Hnd, Pr, ST, TF:new(), PF:new()],
+ Pid = oop:start_new(SF, Args),
+ ?R0(Pid, effectful_serve),
+ {ok, Pid}.