Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 1 | %%% Copyright (c) 2007- Facebook |
| 2 | %%% Distributed under the Thrift Software License |
Christopher Piro | 42fe4b9 | 2007-10-02 00:24:07 +0000 | [diff] [blame^] | 3 | %%% |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 4 | %%% See accompanying file LICENSE or visit the Thrift site at: |
| 5 | %%% http://developers.facebook.com/thrift/ |
| 6 | |
Christopher Piro | 5b3a8f7 | 2007-08-01 22:27:37 +0000 | [diff] [blame] | 7 | -define(ERROR(F, D), |
| 8 | error_logger:format(F, D)). |
| 9 | -define(INFO(Type, Report), |
| 10 | error_logger:info_report({thrift_info, Type}, Report)). |
| 11 | |
Christopher Piro | 42fe4b9 | 2007-10-02 00:24:07 +0000 | [diff] [blame^] | 12 | % local (same process) |
| 13 | -define(L0(Method), oop:call(This, Method, [])). |
| 14 | -define(L1(Method, Arg1), oop:call(This, Method, [Arg1])). |
| 15 | -define(L2(Method, Arg1, Arg2), oop:call(This, Method, [Arg1, Arg2])). |
| 16 | -define(L3(Method, Arg1, Arg2, Arg3), oop:call(This, Method, [Arg1, Arg2, Arg3])). |
| 17 | -define(L4(Method, Arg1, Arg2, Arg3, Arg4), oop:call(This, Method, [Arg1, Arg2, Arg3, Arg4])). |
| 18 | -define(L5(Method, Arg1, Arg2, Arg3, Arg4, Arg5), oop:call(This, Method, [Arg1, Arg2, Arg3, Arg4, Arg5])). |
| 19 | -define(L6(Method, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), oop:call(This, Method, [Arg1, Arg2, Arg3, Arg4, Arg5, Arg6])). |
| 20 | |
| 21 | % local (same process), but not This (e.g. t*Factory) |
| 22 | -define(F0(Obj, Method), oop:call(Obj, Method, [])). |
| 23 | -define(F1(Obj, Method, Arg1), oop:call(Obj, Method, [Arg1])). |
| 24 | -define(F2(Obj, Method, Arg1, Arg2), oop:call(Obj, Method, [Arg1, Arg2])). |
| 25 | -define(F3(Obj, Method, Arg1, Arg2, Arg3), oop:call(Obj, Method, [Arg1, Arg2, Arg3])). |
| 26 | -define(F4(Obj, Method, Arg1, Arg2, Arg3, Arg4), oop:call(Obj, Method, [Arg1, Arg2, Arg3, Arg4])). |
| 27 | -define(F5(Obj, Method, Arg1, Arg2, Arg3, Arg4, Arg5), oop:call(Obj, Method, [Arg1, Arg2, Arg3, Arg4, Arg5])). |
| 28 | -define(F6(Obj, Method, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), oop:call(Obj, Method, [Arg1, Arg2, Arg3, Arg4, Arg5, Arg6])). |
| 29 | |
| 30 | % remote (different process) |
| 31 | -define(RT0(ServerRef, Method, Timeout), gen_server:call(ServerRef, {Method, []}, Timeout)). |
| 32 | -define(RT1(ServerRef, Method, Timeout, Arg1), gen_server:call(ServerRef, {Method, [Arg1]}, Timeout)). |
| 33 | -define(RT2(ServerRef, Method, Timeout, Arg1, Arg2), gen_server:call(ServerRef, {Method, [Arg1, Arg2]}, Timeout)). |
| 34 | -define(RT3(ServerRef, Method, Timeout, Arg1, Arg2, Arg3), gen_server:call(ServerRef, {Method, [Arg1, Arg2, Arg3]}, Timeout)). |
| 35 | -define(RT4(ServerRef, Method, Timeout, Arg1, Arg2, Arg3, Arg4), gen_server:call(ServerRef, {Method, [Arg1, Arg2, Arg3, Arg4]}, Timeout)). |
| 36 | -define(RT5(ServerRef, Method, Timeout, Arg1, Arg2, Arg3, Arg4, Arg5), gen_server:call(ServerRef, {Method, [Arg1, Arg2, Arg3, Arg4, Arg5]}, Timeout)). |
| 37 | -define(RT6(ServerRef, Method, Timeout, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), gen_server:call(ServerRef, {Method, [Arg1, Arg2, Arg3, Arg4, Arg5, Arg6]}, Timeout)). |
| 38 | |
| 39 | % remote (different process), default timeout |
| 40 | -define(DEFAULT_TIMEOUT, 5000). |
| 41 | -define(R0(ServerRef, Method), ?RT0(ServerRef, Method, ?DEFAULT_TIMEOUT)). |
| 42 | -define(R1(ServerRef, Method, Arg1), ?RT1(ServerRef, Method, ?DEFAULT_TIMEOUT, Arg1)). |
| 43 | -define(R2(ServerRef, Method, Arg1, Arg2), ?RT2(ServerRef, Method, ?DEFAULT_TIMEOUT, Arg1, Arg2)). |
| 44 | -define(R3(ServerRef, Method, Arg1, Arg2, Arg3), ?RT3(ServerRef, Method, ?DEFAULT_TIMEOUT, Arg1, Arg2, Arg3)). |
| 45 | -define(R4(ServerRef, Method, Arg1, Arg2, Arg3, Arg4), ?RT4(ServerRef, Method, ?DEFAULT_TIMEOUT, Arg1, Arg2, Arg3, Arg4)). |
| 46 | -define(R5(ServerRef, Method, Arg1, Arg2, Arg3, Arg4, Arg5), ?RT5(ServerRef, Method, ?DEFAULT_TIMEOUT, Arg1, Arg2, Arg3, Arg4, Arg5)). |
| 47 | -define(R6(ServerRef, Method, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), ?RT6(ServerRef, Method, ?DEFAULT_TIMEOUT, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)). |
| 48 | |
| 49 | % remote (different process), cast |
| 50 | -define(C0(ServerRef, Method), gen_server:cast(ServerRef, {Method, []})). |
| 51 | -define(C1(ServerRef, Method, Arg1), gen_server:cast(ServerRef, {Method, [Arg1]})). |
| 52 | -define(C2(ServerRef, Method, Arg1, Arg2), gen_server:cast(ServerRef, {Method, [Arg1, Arg2]})). |
| 53 | -define(C3(ServerRef, Method, Arg1, Arg2, Arg3), gen_server:cast(ServerRef, {Method, [Arg1, Arg2, Arg3]})). |
| 54 | -define(C4(ServerRef, Method, Arg1, Arg2, Arg3, Arg4), gen_server:cast(ServerRef, {Method, [Arg1, Arg2, Arg3, Arg4]})). |
| 55 | -define(C5(ServerRef, Method, Arg1, Arg2, Arg3, Arg4, Arg5), gen_server:cast(ServerRef, {Method, [Arg1, Arg2, Arg3, Arg4, Arg5]})). |
| 56 | -define(C6(ServerRef, Method, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), gen_server:cast(ServerRef, {Method, [Arg1, Arg2, Arg3, Arg4, Arg5, Arg6]})). |
| 57 | |
| 58 | % spawn new server |
| 59 | %% -define(NEW(Class, Args), %% |
| 60 | %% gen_server:start_link(thrift_oop_server, {Class, Args}, [])). %% |
| 61 | %% moved to oop:start_new/2 |
| 62 | |
| 63 | % old |
| 64 | %% -define(M0(Obj, Method), oop:call(Obj, Method, [])). %% |
| 65 | %% -define(M1(Obj, Method, Arg1), oop:call(Obj, Method, [Arg1])). %% |
| 66 | %% -define(M2(Obj, Method, Arg1, Arg2), oop:call(Obj, Method, [Arg1, Arg2])). %% |
| 67 | %% -define(M3(Obj, Method, Arg1, Arg2, Arg3), oop:call(Obj, Method, [Arg1, Arg2, Arg3])). %% |
| 68 | %% -define(M4(Obj, Method, Arg1, Arg2, Arg3, Arg4), oop:call(Obj, Method, [Arg1, Arg2, Arg3, Arg4])). %% |
| 69 | %% -define(M5(Obj, Method, Arg1, Arg2, Arg3, Arg4, Arg5), oop:call(Obj, Method, [Arg1, Arg2, Arg3, Arg4, Arg5])). %% |
| 70 | %% -define(M6(Obj, Method, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), oop:call(Obj, Method, [Arg1, Arg2, Arg3, Arg4, Arg5, Arg6])). %% |
| 71 | |
| 72 | %%% implicit call: old |
| 73 | |
| 74 | %% -define(M0(Obj, Method), ((?CLASS(Obj)):Method(Obj))). %% |
| 75 | %% -define(M1(Obj, Method, Arg1), ((?CLASS(Obj)):Method(Obj, Arg1))). %% |
| 76 | %% -define(M2(Obj, Method, Arg1, Arg2), ((?CLASS(Obj)):Method(Obj, Arg1, Arg2))). %% |
| 77 | %% -define(M3(Obj, Method, Arg1, Arg2, Arg3), ((?CLASS(Obj)):Method(Obj, Arg1, Arg2, Arg3))). %% |
| 78 | %% -define(M4(Obj, Method, Arg1, Arg2, Arg3, Arg4), ((?CLASS(Obj)):Method(Obj, Arg1, Arg2, Arg3, Arg4))). %% |
| 79 | %% -define(M5(Obj, Method, Arg1, Arg2, Arg3, Arg4, Arg5), ((?CLASS(Obj)):Method(Obj, Arg1, Arg2, Arg3, Arg4, Arg5))). %% |
| 80 | %% -define(M6(Obj, Method, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6), ((?CLASS(Obj)):Method(Obj, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6))). %% |
| 81 | |
| 82 | %% TType |
| 83 | -define(tType_STOP, 0). |
| 84 | -define(tType_VOID, 1). |
| 85 | -define(tType_BOOL, 2). |
| 86 | -define(tType_BYTE, 3). |
| 87 | -define(tType_DOUBLE, 4). |
| 88 | -define(tType_I16, 6). |
| 89 | -define(tType_I32, 8). |
| 90 | -define(tType_I64, 10). |
| 91 | -define(tType_STRING, 11). |
| 92 | -define(tType_STRUCT, 12). |
| 93 | -define(tType_MAP, 13). |
| 94 | -define(tType_SET, 14). |
| 95 | -define(tType_LIST, 15). |
| 96 | |
| 97 | % tmessagetype |
| 98 | -define(tMessageType_CALL, 1). |
| 99 | -define(tMessageType_REPLY, 2). |
| 100 | -define(tMessageType_EXCEPTION, 3). |
| 101 | |
| 102 | % TProcessor |
| 103 | % ? |
| 104 | |
| 105 | % -include("tApplicationException.hrl"). |