[thrift] preliminary Erlang support (initial import)

Summary:
 * missing {list,map,set}s, inheritance is spotty
 * loose source code, plus everything is one process (application / gen_server behavior is forthcoming)
 * codegen is a mess, need t_fp_generator

Test Plan:
 * codegen invoked without -erl generates identical code for test/
 * calculatorHandler plus 'thrift -erl -r tutorial.thrift' more or less works

Revert Plan: ok


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665146 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tutorial/erl/ErlClient.rb b/tutorial/erl/ErlClient.rb
new file mode 100644
index 0000000..bcf1300
--- /dev/null
+++ b/tutorial/erl/ErlClient.rb
@@ -0,0 +1,49 @@
+#!/usr/bin/env ruby
+
+$:.push('../gen-rb')
+
+require 'thrift/transport/tsocket'
+require 'thrift/protocol/tbinaryprotocol'
+
+require 'Calculator'
+
+begin
+  
+  transport = TBufferedTransport.new(TSocket.new('localhost', 9090))
+  protocol = TBinaryProtocol.new(transport)
+  client = Calculator::Client.new(protocol)
+  
+  transport.open()
+  
+  client.ping()
+  print "ping()\n"
+  
+  sum = client.add(1,1)
+  print "1+1=", sum, "\n"
+  
+  work = Work.new()
+  
+  begin
+    work.op = Operation::DIVIDE
+    work.num1 = 1
+    work.num2 = 0
+    quot = client.calculate(1, work)
+    puts "Whoa, we can divide by 0 now?"
+  rescue InvalidOperation => io
+    print "InvalidOperation: ", io.why, "\n"
+  end
+  
+  work.op = Operation::SUBTRACT
+  work.num1 = 15
+  work.num2 = 10
+  diff = client.calculate(1, work)
+  print "15-10=", diff, "\n"
+  
+  log = client.getStruct(1)
+  print "Log: ", log.value, "\n"
+  
+  transport.close()
+
+rescue TException => tx
+  print 'TException: ', tx.message, "\n"
+end
diff --git a/tutorial/erl/calculatorHandler.erl b/tutorial/erl/calculatorHandler.erl
new file mode 100644
index 0000000..5d42019
--- /dev/null
+++ b/tutorial/erl/calculatorHandler.erl
@@ -0,0 +1,68 @@
+-module(calculatorHandler).
+
+-include("thrift/thrift.hrl").
+-include("thrift/transport/tSocket.hrl").
+-include("thrift/protocol/tBinaryProtocol.hrl").
+-include("thrift/server/tServer.hrl").
+-include("thrift/transport/tServerSocket.hrl").
+
+-include("gen-erl/calculator.hrl").
+%-include("gen-erl/shared_types.hrl").
+
+%-include("gen-erl/tutorial_types.hrl"). % TODO(cpiro): o rly?
+
+-export([start/0, ping/0, add/2, calculate/2, getStruct/1, zip/0]).
+
+%%%   def initialize()
+%%%     @log = {}
+%%%   end
+
+% TODO: voids take only ok as return? 
+
+ping() ->
+    io:format("ping()~n",[]),
+    {ok, nil}.
+
+add(N1, N2) ->
+    io:format("add(~p,~p)~n",[N1,N2]),
+    {ok, N1+N2}.
+
+calculate(Logid, Work) ->
+    { Op, Num1, Num2 } = { Work#work.op, Work#work.num1, Work#work.num2 },
+    io:format("calculate(~p, {~p,~p,~p})~n", [Logid, Op, Num1, Num2]),
+    case Op of
+        ?ADD      -> {ok, Num1 + Num2};
+	?SUBTRACT -> {ok, Num1 - Num2};
+	?MULTIPLY -> {ok, Num1 * Num2};
+	?DIVIDE ->
+	    if 	Num2 == 0 -> {error, #invalidOperation{what=Op, why="Cannot divide by 0"}};
+		true      -> {ok, Num1 / Num2}
+	    end;
+	true ->
+	    {error, #invalidOperation{what=Op, why="Invalid operation"}}
+    end.
+
+getStruct(Key) ->
+    io:format("getStruct(~p)~n", [Key]),
+    {ok, get(Key)}.
+
+zip() ->
+    io:format("zip~n").
+
+start() ->
+    Transport = tServerSocket:new(9090),
+    Server = tServer:new(calculator, ?MODULE, Transport),
+    io:format("Starting the server...~n", []),
+    ?M0(Server, serve),
+    io:format("done.~n", []), % won't ever reach, rookie beotch
+    ok.
+
+%%% handler = CalculatorHandler.new()
+%%% processor = Calculator::Processor.new(handler)
+%%% transport = TServerSocket.new(9090)
+%%% transportFactory = TBufferedTransportFactory.new()
+%%% server = TSimpleServer.new(processor, transport, transportFactory)
+%%% 
+%%% puts "Starting the server..."
+%%% server.serve()
+%%% puts "done."