From f2e66c1cb79ec0c1e2a515668f15410a60140011 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Wed, 11 Jun 2008 01:14:38 +0000 Subject: [PATCH] Remove all of the old Erlang stuff in preparation for renaming alterl. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@666480 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/Makefile.am | 2 - compiler/cpp/src/generate/t_erl_generator.cc | 1583 ----------------- compiler/cpp/src/generate/t_erl_generator.h | 196 -- compiler/cpp/src/main.cc | 14 +- lib/Makefile.am | 3 +- lib/erl/COPYING | 24 - lib/erl/LICENSE | 24 - lib/erl/Makefile | 15 - lib/erl/README | 82 - lib/erl/TODO | 35 - lib/erl/build/beamver | 59 - lib/erl/build/buildtargets.mk | 15 - lib/erl/build/colors.mk | 24 - lib/erl/build/docs.mk | 12 - lib/erl/build/mime.types | 98 - lib/erl/build/otp.mk | 146 -- lib/erl/build/otp_subdir.mk | 85 - lib/erl/build/raw_test.mk | 29 - lib/erl/include/oop.hrl | 25 - lib/erl/include/protocol/tBinaryProtocol.hrl | 10 - .../protocol/tBinaryProtocolFactory.hrl | 7 - lib/erl/include/protocol/tProtocol.hrl | 7 - .../include/protocol/tProtocolException.hrl | 15 - lib/erl/include/protocol/tProtocolFactory.hrl | 7 - lib/erl/include/server/tErlServer.hrl | 7 - lib/erl/include/server/tServer.hrl | 7 - lib/erl/include/server/tSimpleServer.hrl | 7 - lib/erl/include/tApplicationException.hrl | 16 - lib/erl/include/tErlProcessor.hrl | 7 - lib/erl/include/tException.hrl | 7 - lib/erl/include/tProcessor.hrl | 8 - lib/erl/include/thrift.hrl | 14 - lib/erl/include/thrift_constants.hrl | 25 - lib/erl/include/thrift_macros.hrl | 54 - .../include/transport/tBufferedTransport.hrl | 7 - .../transport/tBufferedTransportFactory.hrl | 7 - lib/erl/include/transport/tErlAcceptor.hrl | 7 - lib/erl/include/transport/tServerSocket.hrl | 7 - .../include/transport/tServerTransport.hrl | 7 - lib/erl/include/transport/tSocket.hrl | 7 - lib/erl/include/transport/tTransport.hrl | 7 - .../include/transport/tTransportException.hrl | 13 - .../include/transport/tTransportFactory.hrl | 7 - lib/erl/src/Makefile | 117 -- lib/erl/src/oop.erl | 261 --- lib/erl/src/protocol/tBinaryProtocol.erl | 218 --- .../src/protocol/tBinaryProtocolFactory.erl | 57 - lib/erl/src/protocol/tProtocol.erl | 175 -- lib/erl/src/protocol/tProtocolException.erl | 57 - lib/erl/src/protocol/tProtocolFactory.erl | 54 - lib/erl/src/server/tErlServer.erl | 102 -- lib/erl/src/server/tServer.erl | 81 - lib/erl/src/server/tSimpleServer.erl | 111 -- lib/erl/src/tApplicationException.erl | 114 -- lib/erl/src/tErlProcessor.erl | 63 - lib/erl/src/tException.erl | 93 - lib/erl/src/tProcessor.erl | 50 - lib/erl/src/thrift.app.src | 46 - lib/erl/src/thrift.appup.src | 1 - lib/erl/src/thrift.erl | 65 - lib/erl/src/thrift_app.erl | 25 - lib/erl/src/thrift_app_sup.erl | 19 - lib/erl/src/thrift_logger.erl | 249 --- lib/erl/src/thrift_oop_server.erl | 152 -- lib/erl/src/thrift_sup.erl | 45 - lib/erl/src/thrift_utils.erl | 51 - lib/erl/src/transport/tBufferedTransport.erl | 86 - .../transport/tBufferedTransportFactory.erl | 54 - lib/erl/src/transport/tErlAcceptor.erl | 157 -- lib/erl/src/transport/tServerSocket.erl | 96 - lib/erl/src/transport/tServerTransport.erl | 52 - lib/erl/src/transport/tSocket.erl | 134 -- lib/erl/src/transport/tTransport.erl | 99 -- lib/erl/src/transport/tTransportException.erl | 57 - lib/erl/src/transport/tTransportFactory.erl | 52 - lib/erl/vsn.mk | 1 - tutorial/erl/client.erl | 73 - tutorial/erl/client.sh | 1 - tutorial/erl/server.config | 28 - tutorial/erl/server.erl | 76 - tutorial/erl/server.sh | 18 - 81 files changed, 2 insertions(+), 5926 deletions(-) delete mode 100644 compiler/cpp/src/generate/t_erl_generator.cc delete mode 100644 compiler/cpp/src/generate/t_erl_generator.h delete mode 100644 lib/erl/COPYING delete mode 100644 lib/erl/LICENSE delete mode 100644 lib/erl/Makefile delete mode 100644 lib/erl/README delete mode 100644 lib/erl/TODO delete mode 100644 lib/erl/build/beamver delete mode 100644 lib/erl/build/buildtargets.mk delete mode 100644 lib/erl/build/colors.mk delete mode 100644 lib/erl/build/docs.mk delete mode 100644 lib/erl/build/mime.types delete mode 100644 lib/erl/build/otp.mk delete mode 100644 lib/erl/build/otp_subdir.mk delete mode 100644 lib/erl/build/raw_test.mk delete mode 100644 lib/erl/include/oop.hrl delete mode 100644 lib/erl/include/protocol/tBinaryProtocol.hrl delete mode 100644 lib/erl/include/protocol/tBinaryProtocolFactory.hrl delete mode 100644 lib/erl/include/protocol/tProtocol.hrl delete mode 100644 lib/erl/include/protocol/tProtocolException.hrl delete mode 100644 lib/erl/include/protocol/tProtocolFactory.hrl delete mode 100644 lib/erl/include/server/tErlServer.hrl delete mode 100644 lib/erl/include/server/tServer.hrl delete mode 100644 lib/erl/include/server/tSimpleServer.hrl delete mode 100644 lib/erl/include/tApplicationException.hrl delete mode 100644 lib/erl/include/tErlProcessor.hrl delete mode 100644 lib/erl/include/tException.hrl delete mode 100644 lib/erl/include/tProcessor.hrl delete mode 100644 lib/erl/include/thrift.hrl delete mode 100644 lib/erl/include/thrift_constants.hrl delete mode 100644 lib/erl/include/thrift_macros.hrl delete mode 100644 lib/erl/include/transport/tBufferedTransport.hrl delete mode 100644 lib/erl/include/transport/tBufferedTransportFactory.hrl delete mode 100644 lib/erl/include/transport/tErlAcceptor.hrl delete mode 100644 lib/erl/include/transport/tServerSocket.hrl delete mode 100644 lib/erl/include/transport/tServerTransport.hrl delete mode 100644 lib/erl/include/transport/tSocket.hrl delete mode 100644 lib/erl/include/transport/tTransport.hrl delete mode 100644 lib/erl/include/transport/tTransportException.hrl delete mode 100644 lib/erl/include/transport/tTransportFactory.hrl delete mode 100644 lib/erl/src/Makefile delete mode 100644 lib/erl/src/oop.erl delete mode 100644 lib/erl/src/protocol/tBinaryProtocol.erl delete mode 100644 lib/erl/src/protocol/tBinaryProtocolFactory.erl delete mode 100644 lib/erl/src/protocol/tProtocol.erl delete mode 100644 lib/erl/src/protocol/tProtocolException.erl delete mode 100644 lib/erl/src/protocol/tProtocolFactory.erl delete mode 100644 lib/erl/src/server/tErlServer.erl delete mode 100644 lib/erl/src/server/tServer.erl delete mode 100644 lib/erl/src/server/tSimpleServer.erl delete mode 100644 lib/erl/src/tApplicationException.erl delete mode 100644 lib/erl/src/tErlProcessor.erl delete mode 100644 lib/erl/src/tException.erl delete mode 100644 lib/erl/src/tProcessor.erl delete mode 100644 lib/erl/src/thrift.app.src delete mode 100644 lib/erl/src/thrift.appup.src delete mode 100644 lib/erl/src/thrift.erl delete mode 100644 lib/erl/src/thrift_app.erl delete mode 100644 lib/erl/src/thrift_app_sup.erl delete mode 100644 lib/erl/src/thrift_logger.erl delete mode 100644 lib/erl/src/thrift_oop_server.erl delete mode 100644 lib/erl/src/thrift_sup.erl delete mode 100644 lib/erl/src/thrift_utils.erl delete mode 100644 lib/erl/src/transport/tBufferedTransport.erl delete mode 100644 lib/erl/src/transport/tBufferedTransportFactory.erl delete mode 100644 lib/erl/src/transport/tErlAcceptor.erl delete mode 100644 lib/erl/src/transport/tServerSocket.erl delete mode 100644 lib/erl/src/transport/tServerTransport.erl delete mode 100644 lib/erl/src/transport/tSocket.erl delete mode 100644 lib/erl/src/transport/tTransport.erl delete mode 100644 lib/erl/src/transport/tTransportException.erl delete mode 100644 lib/erl/src/transport/tTransportFactory.erl delete mode 100644 lib/erl/vsn.mk delete mode 100644 tutorial/erl/client.erl delete mode 120000 tutorial/erl/client.sh delete mode 100644 tutorial/erl/server.config delete mode 100644 tutorial/erl/server.erl delete mode 100755 tutorial/erl/server.sh diff --git a/compiler/cpp/Makefile.am b/compiler/cpp/Makefile.am index 33d61a73..81aebd43 100644 --- a/compiler/cpp/Makefile.am +++ b/compiler/cpp/Makefile.am @@ -11,7 +11,6 @@ thrift_SOURCES = src/thrifty.yy \ src/generate/t_generator.cc \ src/generate/t_php_generator.cc \ src/generate/t_xsd_generator.cc \ - src/generate/t_erl_generator.cc \ src/generate/t_alterl_generator.cc \ src/globals.h \ src/main.h \ @@ -39,7 +38,6 @@ thrift_SOURCES = src/thrifty.yy \ src/generate/t_oop_generator.h \ src/generate/t_php_generator.h \ src/generate/t_xsd_generator.h \ - src/generate/t_erl_generator.h \ src/generate/t_alterl_generator.h if THRIFT_GEN_cpp diff --git a/compiler/cpp/src/generate/t_erl_generator.cc b/compiler/cpp/src/generate/t_erl_generator.cc deleted file mode 100644 index 069d4b49..00000000 --- a/compiler/cpp/src/generate/t_erl_generator.cc +++ /dev/null @@ -1,1583 +0,0 @@ -// Copyright (c) 2006- Facebook -// Distributed under the Thrift Software License -// -// See accompanying file LICENSE or visit the Thrift site at: -// http://developers.facebook.com/thrift/ - -#include -#include -#include -#include -#include "t_erl_generator.h" -#include "platform.h" - -using namespace std; - -/** - * UI for file generation by opening up the necessary file output - * streams. - * - * @param tprogram The program to generate - */ -void t_erl_generator::init_generator() { - // Make output directory - MKDIR(get_out_dir().c_str()); - - // setup export lines - export_lines_first_ = true; - export_types_lines_first_ = true; - - // types files - string f_types_name = get_out_dir()+program_name_+"_types.erl"; - string f_types_hrl_name = get_out_dir()+program_name_+"_types.hrl"; - - f_types_file_.open(f_types_name.c_str()); - f_types_hrl_file_.open(f_types_hrl_name.c_str()); - - hrl_header(f_types_hrl_file_, program_name_ + "_types"); - - f_types_file_ << - erl_autogen_comment() << endl << - "-module(" << program_name_ << "_types)." << endl << - erl_imports() << endl; - - f_types_file_ << - "-include(\"" << program_name_ << "_types.hrl\")." << endl << - endl; - - f_types_hrl_file_ << render_includes() << endl; - - // consts file - string f_consts_name = get_out_dir()+program_name_+"_constants.hrl"; - f_consts_.open(f_consts_name.c_str()); - - f_consts_ << - erl_autogen_comment() << endl << - erl_imports() << endl << - "-include(\"" << program_name_ << "_types.hrl\")." << endl << - endl; -} - -/** - * Boilerplate at beginning and end of header files - */ -void t_erl_generator::hrl_header(ostream& out, string name) { - out << "-ifndef(_" << name << "_included)." << endl << - "-define(_" << name << "_included, yeah)." << endl; -} - -void t_erl_generator::hrl_footer(ostream& out, string name) { - out << "-endif." << endl; -} - -/** - * Renders all the imports necessary for including another Thrift program - */ -string t_erl_generator::render_includes() { - const vector& includes = program_->get_includes(); - string result = ""; - for (size_t i = 0; i < includes.size(); ++i) { - result += "-include(\"" + includes[i]->get_name() + "_types.hrl\").\n"; - } - if (includes.size() > 0) { - result += "\n"; - } - return result; -} - -/** - * Autogen'd comment - */ -string t_erl_generator::erl_autogen_comment() { - return - std::string("%%\n") + - "%% Autogenerated by Thrift\n" + - "%%\n" + - "%% DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n" + - "%%\n"; -} - -/** - * Prints standard thrift imports - */ -string t_erl_generator::erl_imports() { - return - string("-include(\"thrift.hrl\").\n") + - "-include(\"tApplicationException.hrl\").\n" + - "-include(\"protocol/tProtocol.hrl\").\n"; -} - -/** - * Closes the type files - */ -void t_erl_generator::close_generator() { - // Close types file - f_types_file_ << "-export([" << export_types_lines_.str() << "])." << endl; - f_types_file_ << f_types_.str(); - - hrl_footer(f_types_hrl_file_, string("BOGUS")); - - f_types_file_.close(); - f_types_hrl_file_.close(); - f_consts_.close(); -} - -/** - * Generates a typedef. no op - * - * @param ttypedef The type definition - */ -void t_erl_generator::generate_typedef(t_typedef* ttypedef) { -} - -/** - * Generates code for an enumerated type. Done using a class to scope - * the values. - * - * @param tenum The enumeration - */ -void t_erl_generator::generate_enum(t_enum* tenum) { - vector constants = tenum->get_constants(); - vector::iterator c_iter; - - int value = -1; - - for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) { - if ((*c_iter)->has_value()) { - value = (*c_iter)->get_value(); - } else { - ++value; - } - - string name = capitalize((*c_iter)->get_name()); - - f_types_hrl_file_ << - indent() << "-define(" << program_name_ << "_" << name << ", " << value << ")."<< endl; - } - - f_types_hrl_file_ << endl; -} - -/** - * Generate a constant value - */ -void t_erl_generator::generate_const(t_const* tconst) { - t_type* type = tconst->get_type(); - string name = capitalize(tconst->get_name()); - t_const_value* value = tconst->get_value(); - - f_consts_ << "-define(" << program_name_ << "_" << name << ", " << render_const_value(type, value) << ")." << endl << endl; -} - -/** - * Prints the value of a constant with the given type. Note that type checking - * is NOT performed in this function as it is always run beforehand using the - * validate_types method in main.cc - */ -string t_erl_generator::render_const_value(t_type* type, t_const_value* value) { - type = get_true_type(type); - std::ostringstream out; - - if (type->is_base_type()) { - t_base_type::t_base tbase = ((t_base_type*)type)->get_base(); - switch (tbase) { - case t_base_type::TYPE_STRING: - out << "\"" << value->get_string() << "\""; - break; - case t_base_type::TYPE_BOOL: - out << (value->get_integer() > 0 ? "true" : "false"); - break; - case t_base_type::TYPE_BYTE: - case t_base_type::TYPE_I16: - case t_base_type::TYPE_I32: - case t_base_type::TYPE_I64: - out << value->get_integer(); - break; - case t_base_type::TYPE_DOUBLE: - if (value->get_type() == t_const_value::CV_INTEGER) { - out << value->get_integer(); - } else { - out << value->get_double(); - } - break; - default: - throw "compiler error: no const of base type " + t_base_type::t_base_name(tbase); - } - } else if (type->is_enum()) { - indent(out) << value->get_integer(); - - } else if (type->is_struct() || type->is_xception()) { - out << "#" << type->get_name() << "{"; - const vector& fields = ((t_struct*)type)->get_members(); - vector::const_iterator f_iter; - const map& val = value->get_map(); - map::const_iterator v_iter; - - bool first = true; - for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) { - t_type* field_type = NULL; - for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) { - if ((*f_iter)->get_name() == v_iter->first->get_string()) { - field_type = (*f_iter)->get_type(); - } - } - if (field_type == NULL) { - throw "type error: " + type->get_name() + " has no field " + v_iter->first->get_string(); - } - - if (first) { - first = false; - } else { - out << ","; - } - out << v_iter->first->get_string(); - out << " = "; - out << render_const_value(field_type, v_iter->second); - } - indent_down(); - indent(out) << "}"; - - } else if (type->is_map()) { - t_type* ktype = ((t_map*)type)->get_key_type(); - t_type* vtype = ((t_map*)type)->get_val_type(); - const map& val = value->get_map(); - map::const_iterator v_iter; - - bool first = true; - out << "dict:from_list(["; - for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) { - if (first) { - first=false; - } else { - out << ","; - } - out << "(" - << render_const_value(ktype, v_iter->first) << "," - << render_const_value(vtype, v_iter->second) << ")"; - } - out << "])"; - - } else if (type->is_set()) { - t_type* etype; - etype = ((t_set*)type)->get_elem_type(); - - bool first = true; - const vector& val = value->get_list(); - vector::const_iterator v_iter; - out << "sets:from_list(["; - for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) { - if (first) { - first=false; - } else { - out << ","; - } - out << "(" << render_const_value(etype, *v_iter) << ",true)"; - } - out << "])"; - - } else if (type->is_list()) { - t_type* etype; - etype = ((t_list*)type)->get_elem_type(); - out << "["; - - bool first = true; - const vector& val = value->get_list(); - vector::const_iterator v_iter; - for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) { - if (first) { - first=false; - } else { - out << ","; - } - out << render_const_value(etype, *v_iter); - } - out << "]"; - } else { - throw "CANNOT GENERATE CONSTANT FOR TYPE: " + type->get_name(); - } - return out.str(); -} - -/** - * Generates a struct - */ -void t_erl_generator::generate_struct(t_struct* tstruct) { - generate_erl_struct(tstruct, false); -} - -/** - * Generates a struct definition for a thrift exception. Basically the same - * as a struct but extends the Exception class. - * - * @param txception The struct definition - */ -void t_erl_generator::generate_xception(t_struct* txception) { - generate_erl_struct(txception, true); -} - -/** - * Generates a struct - */ -void t_erl_generator::generate_erl_struct(t_struct* tstruct, - bool is_exception) { - generate_erl_struct_definition(f_types_, f_types_hrl_file_, tstruct, is_exception); -} - -/** - * Generates a struct definition for a thrift data type. - * - * @param tstruct The struct definition - */ -void t_erl_generator::generate_erl_struct_definition(ostream& out, - ostream& hrl_out, - t_struct* tstruct, - bool is_exception, - bool is_result) -{ - const vector& members = tstruct->get_members(); - vector::const_iterator m_iter; - - indent(out) << "%% struct " << type_name(tstruct) << endl; - - if (is_exception) { - } - - out << endl; - - if (members.size() > 0) { - indent(out) << "% -record(" << type_name(tstruct) << ", {"; - indent(hrl_out) << "-record(" << type_name(tstruct) << ", {"; - - bool first = true; - for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) { - if (first) { - first = false; - } else { - out << ", "; - hrl_out << ", "; - } - out << (*m_iter)->get_name(); - hrl_out << (*m_iter)->get_name(); - } - out << "})." << endl; - hrl_out << "})." << endl; - } else { // no members; explicit comment - indent(out) << "% -record(" << type_name(tstruct) << ", {})." << endl; - indent(hrl_out) << "-record(" << type_name(tstruct) << ", {})." << endl; - } - - out << endl; - hrl_out << endl; - - generate_erl_struct_reader(out, tstruct); - generate_erl_struct_writer(out, tstruct); -} - -/** - * Generates the read method for a struct - */ -void t_erl_generator::generate_erl_struct_reader(ostream& out, - t_struct* tstruct) { - const vector& fields = tstruct->get_members(); - vector::const_iterator f_iter; - - string name = type_name(tstruct) + "_read"; - - if (out == f_types_) { // OH HAI MR. HORRIBLE - export_types_string(name, 1); - } else { - export_string(name, 1); - } - - indent(out) << name << "(Iprot) ->" << endl; - indent_up(); - - out << - indent() << "?R0(Iprot, readStructBegin)," << endl << - indent() << "Str = " << type_name(tstruct) << "_read_loop(Iprot, "; - - // empty struct - out << "#" << type_name(tstruct) << "{}"; - out << ")," << endl << - indent() << "?R0(Iprot, readStructEnd)," << endl << - indent() << "Str." << endl; - - indent_down(); - - indent(out) << - "" << type_name(tstruct) << "_read_loop(Iprot, Str) ->" << endl; - indent_up(); - - // Read beginning field marker - out << - indent() << "{ _Fname, Ftype, Fid } = ?R0(Iprot, readFieldBegin)," << endl << - indent() << "Fid, % suppress unused warnings" << endl; - - // Check for field STOP marker and break - indent(out) << "if" << endl; - indent_up(); - indent(out) << "Ftype == ?tType_STOP ->" << endl << - indent() << " Str;" << endl; - - // Generate deserialization code for known cases - for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) { - out << indent() << "(Fid == " << (*f_iter)->get_key() << "), (Ftype == " - << type_to_enum((*f_iter)->get_type()) << ") ->" << endl; - - indent_up(); - generate_deserialize_field(out, *f_iter, "Val"); - - out << indent() << "?R0(Iprot, readFieldEnd)," << endl - << indent() << type_name(tstruct) << "_read_loop(Iprot, " - << "Str#" << type_name(tstruct) - << "{" << (*f_iter)->get_name() - << "=Val});" << endl; - indent_down(); - } - - // In the default case we skip the field - out << - indent() << "true ->" << endl << - indent() << " ?R1(Iprot, skip, Ftype)," << endl << - indent() << " ?R0(Iprot, readFieldEnd)," << endl << - indent() << " " << type_name(tstruct) << "_read_loop(Iprot, Str)" << endl; - indent_down(); - - indent(out) << "end." << endl; - - indent_down(); - out << endl; -} - -void t_erl_generator::generate_erl_struct_writer(ostream& out, - t_struct* tstruct) { - string name = tstruct->get_name(); - const vector& fields = tstruct->get_members(); - vector::const_iterator f_iter; - - string fname = type_name(tstruct) + "_write"; - - if (out == f_types_) { // OH HAI MR. HORRIBLE - export_types_string(fname, 2); - } else { - export_string(fname, 2); - } - - indent(out) << fname << "(Str, Oprot) ->" << endl; - indent_up(); - - out << - indent() << "Str, % suppress unused warnings" << endl << - indent() << "?R1(Oprot, writeStructBegin, \"" << name << "\")," << endl; - - string prefix = string("Str#") + type_name(tstruct) + "."; - for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) { - // Write field header - indent(out) << - "if " << prefix << (*f_iter)->get_name() << " /= undefined ->" << endl; - indent_up(); - indent(out) << - "?R3(Oprot, writeFieldBegin, " << - "\"" << (*f_iter)->get_name() << "\", " << - type_to_enum((*f_iter)->get_type()) << ", " << - (*f_iter)->get_key() << ")," << endl; - - // Write field contents - generate_serialize_field(out, *f_iter, prefix); - - // Write field closer - indent(out) << - "?R0(Oprot, writeFieldEnd);" << endl << - indent() << "true -> ok" << endl; - - indent_down(); - out << " end," << endl; - } - - // Write the struct map - out << - indent() << "?R0(Oprot, writeFieldStop)," << endl << - indent() << "?R0(Oprot, writeStructEnd)," << endl << - indent() << "ok." << endl; - - indent_down(); - - out << endl; -} - -/** - * Generates a thrift service. - * - * @param tservice The service definition - */ -void t_erl_generator::generate_service(t_service* tservice) { - // somehow this point is reached before the constructor and it's not downcased yet - // ...awesome - service_name_[0] = tolower(service_name_[0]); - - string f_service_hrl_name = get_out_dir()+service_name_+"_thrift.hrl"; - string f_service_name = get_out_dir()+service_name_+"_thrift.erl"; - f_service_file_.open(f_service_name.c_str()); - f_service_hrl_.open(f_service_hrl_name.c_str()); - - hrl_header(f_service_hrl_, service_name_); - - if (tservice->get_extends() != NULL) { - f_service_hrl_ << "-include(\"" << - uncapitalize(tservice->get_extends()->get_name()) << "_thrift.hrl\"). % inherit " << endl; - } - - f_service_hrl_ << - "-include(\"" << program_name_ << "_types.hrl\")." << endl << - endl; - - // Generate the three main parts of the service (well, two for now in PHP) - generate_service_helpers(tservice); // cpiro: New Erlang Order - - generate_service_interface(tservice); - generate_service_client(tservice); - generate_service_server(tservice); - - // indent_down(); - - f_service_file_ << - erl_autogen_comment() << endl << - "-module(" << service_name_ << "_thrift)." << endl << endl << - erl_imports() << endl; - - f_service_file_ << "-include(\"" << uncapitalize(tservice->get_name()) << "_thrift.hrl\")." << endl << endl; - - f_service_file_ << "-export([" << export_lines_.str() << "])." << endl << endl; - - f_service_file_ << f_service_.str(); - - hrl_footer(f_service_hrl_, f_service_name); - - // Close service file - f_service_file_.close(); - f_service_hrl_.close(); -} - -/** - * Generates helper functions for a service. - * - * @param tservice The service to generate a header definition for - */ -void t_erl_generator::generate_service_helpers(t_service* tservice) { - vector functions = tservice->get_functions(); - vector::iterator f_iter; - - // indent(f_service_) << - // "% HELPER FUNCTIONS AND STRUCTURES" << endl << endl; - - for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) { - t_struct* ts = (*f_iter)->get_arglist(); - - generate_erl_struct_definition(f_service_, f_service_hrl_, ts, false); - generate_erl_function_helpers(*f_iter); - } -} - -/** - * Generates a struct and helpers for a function. - * - * @param tfunction The function - */ -void t_erl_generator::generate_erl_function_helpers(t_function* tfunction) { - t_struct result(program_, tfunction->get_name() + "_result"); - t_field success(tfunction->get_returntype(), "success", 0); - if (!tfunction->get_returntype()->is_void()) { - result.append(&success); - } - t_struct* xs = tfunction->get_xceptions(); - const vector& fields = xs->get_members(); - vector::const_iterator f_iter; - for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) { - result.append(*f_iter); - } - generate_erl_struct_definition(f_service_, f_service_hrl_, &result, false, true); -} - -/** - * Generates a service interface definition. - * - * @param tservice The service to generate a header definition for - */ -void t_erl_generator::generate_service_interface(t_service* tservice) { - // f_service_ << - // indent() << "module Iface" << endl; - // indent_up(); - - // if (tservice->get_extends() != NULL) { - // string extends = type_name(tservice->get_extends()); - // indent(f_service_) << "include " << extends << "::Iface" << endl; - // } - - vector functions = tservice->get_functions(); - vector::iterator f_iter; - f_service_ << "%%% interface" << endl; - for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) { - f_service_ << - indent() << "% " << function_signature(*f_iter) << endl; - } - // indent_down(); - indent(f_service_) << endl; -} - -/** - * Generates a service client definition. - * - * @param tservice The service to generate a server for. - */ -void t_erl_generator::generate_service_client(t_service* tservice) { - string extends = ""; - string extends_client = ""; - // if (tservice->get_extends() != NULL) { - // extends = type_name(tservice->get_extends()); - // extends_client = " < " + extends + "::Client "; - // } - - // indent(f_service_) << - // "class Client" << extends_client << endl; - // indent_up(); - - // indent(f_service_) << - // "include Iface" << endl << endl; - - // Constructor function - export_string("new", 2); - export_string("new", 1); - - f_service_ << - indent() << "new(Iprot, Oprot) ->" << endl << - indent() << " #"<" << endl << - indent() << " #"< functions = tservice->get_functions(); - vector::const_iterator f_iter; - for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) { - t_struct* arg_struct = (*f_iter)->get_arglist(); - const vector& fields = arg_struct->get_members(); - vector::const_iterator fld_iter; - string funname = (*f_iter)->get_name(); - - export_function(*f_iter); - - // Open function - indent(f_service_) << - function_signature(*f_iter) << " ->" << endl; - - indent_up(); - - indent(f_service_) << - "send_" << funname << "(This"; - - //bool first = true; - for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) { - // if (first) { - // first = false; - // } else { - f_service_ << ", "; - // } - f_service_ << capitalize((*fld_iter)->get_name()); - } - f_service_ << ")," << endl; - - if ((*f_iter)->is_async()) { - f_service_ << indent() << "ok." << endl; - } else { - f_service_ << indent() << "recv_" << funname << "(This)." << endl; - } - - indent_down(); - f_service_ << endl; - - export_function(*f_iter, "send_"); - - indent(f_service_) << - function_signature(*f_iter, "send_") << " ->" << endl; - indent_up(); - - std::string argsname = capitalize((*f_iter)->get_name() + "_args"); - - // Serialize the request header - f_service_ << - indent() << "Oprot = This#" << service_name_ << ".oprot," << endl << - indent() << "Seqid = This#" << service_name_ << ".seqid," << endl << - indent() << "?R3(Oprot, writeMessageBegin, \"" << (*f_iter)->get_name() << "\", ?tMessageType_CALL, Seqid)," << endl << - indent() << "Args = #" << uncapitalize(funname) << "_args{"; - - bool first = true; - for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) { - f_service_ << (first ? first = false, "" : ", ") - << (*fld_iter)->get_name() - << "=" << capitalize((*fld_iter)->get_name()); - } - f_service_ << "}," << endl; - indent(f_service_) << uncapitalize(funname) << "_args_write(Args, Oprot)," << endl; - - // Write to the stream - f_service_ << - indent() << "?R0(Oprot, writeMessageEnd)," << endl << - indent() << "Trans = ?R1(Oprot, get, trans)," << endl << - indent() << "?R0(Trans, effectful_flush)," << endl << - indent() << "ok." << endl; - - indent_down(); - - if (!(*f_iter)->is_async()) { - std::string resultname = uncapitalize((*f_iter)->get_name() + "_result"); - t_struct noargs(program_); - - t_function recv_function((*f_iter)->get_returntype(), - string("recv_") + (*f_iter)->get_name(), - &noargs); - - export_function(&recv_function, ""); - - // Open function - f_service_ << - endl << - indent() << function_signature(&recv_function) << " ->" << endl; - indent_up(); - - // TODO(mcslee): Validate message reply here, seq ids etc. - - f_service_ << - indent() << "Iprot = This#" << service_name_ << ".iprot," << endl << - indent() << "{ _Fname, Mtype, _Rseqid } = ?R0(Iprot, readMessageBegin)," << endl << - indent() << "if" << endl << - indent() << " Mtype == ?tMessageType_EXCEPTION ->" << endl << - indent() << " X = tApplicationException:new()," << endl << - indent() << " tApplicationException:read(X, Iprot)," << endl << - indent() << " ?R0(Iprot, readMessageEnd)," << endl << - indent() << " throw(X);" << endl << - indent() << " true ->" << endl << - indent() << " Result = " << resultname << "_read(Iprot)," << endl << - indent() << " Result, % suppress unused warnings" << endl << - indent() << " ?R0(Iprot, readMessageEnd)," << endl << - indent() << " if % time to figure out retval" << endl; - - // WATCH cpiro - // Careful, only return _result if not a void function - - // TODO(cpiro): exit or {ok, _} and {error, _} ?? - - std::string result = "Result#"+resultname+"."; - if (!(*f_iter)->get_returntype()->is_void()) { - f_service_ << - indent() << " " << result << "success /= nil ->" << endl << - indent() << " " << result << "success;" << endl; - } - - t_struct* xs = (*f_iter)->get_xceptions(); // TODO(cpiro) - const std::vector& xceptions = xs->get_members(); - vector::const_iterator x_iter; - for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) { - f_service_ << - indent() << " " << result << (*x_iter)->get_name() << " /= nil -> " << endl << - indent() << " throw(" << result << (*x_iter)->get_name() << ");" << endl; - } - - // Careful, only return _result if not a void function - if ((*f_iter)->get_returntype()->is_void()) { - f_service_ << - indent() << " true -> nil" << endl << - indent() << " end" << endl; - } else { - f_service_ << - indent() << " true ->" << endl << - indent() << " throw(tApplicationException:new(?tApplicationException_MISSING_RESULT, \"" << (*f_iter)->get_name() << " failed: unknown result\"))" << endl << - indent() << " end" << endl; - } - - // Close function - indent(f_service_) << "end." << endl << endl; - indent_down(); - } - } - - indent_down(); - indent(f_service_) << endl; -} - -/** - * Generates a service server definition. - * - * @param tservice The service to generate a server for. - */ -void t_erl_generator::generate_service_server(t_service* tservice) { - // Generate the dispatch methods - vector functions = tservice->get_functions(); - vector::iterator f_iter; - - string extends = ""; - string extends_processor = ""; - if (tservice->get_extends() != NULL) { - extends = type_name(tservice->get_extends()); - extends_processor = " INHERIT(" + extends + "::Processor) % TODO"; - } - - // Generate the header portion - indent(f_service_) << - "%% processor" << extends_processor << endl; - - indent_up(); - - // TODO: inheritance runtime code (prolly) goes here: - - // f_service_ << - // indent() << "include Iface" << endl << - // indent() << "include TProcessor" << endl << - // endl; - - /* - indent(f_service_) << - "def initialize(handler)" << endl; - indent_up(); - if (extends.empty()) { - f_service_ << - indent() << "@handler = handler" << endl << - indent() << "@processMap = {}" << endl; - } else { - f_service_ << - indent() << "super(handler)" << endl; - } - for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) { - f_service_ << - indent() << "@processMap['" << (*f_iter)->get_name() << "'] = method(:process_" << (*f_iter)->get_name() << ")" << endl; - } - indent_down(); - indent(f_service_) << "end" << endl << endl; - */ - - export_string("process", 3); - export_string("proc", 6); - - // Generate the server implementation - indent(f_service_) << - "process(HandlerModule, Iprot, Oprot) ->" << endl; - indent_up(); - - f_service_ << - indent() << "{ Name, _Type, Seqid } = ?R0(Iprot, readMessageBegin)," << endl << - indent() << "proc(Name, _Type, Seqid, HandlerModule, Iprot, Oprot)." << endl; - - indent_down(); - indent(f_service_) << - "proc(Name, _Type, Seqid, HandlerModule, Iprot, Oprot) ->" << endl; - indent_up(); - - // TODO(mcslee): validate message - - // HOT: dictionary function lookup - f_service_ << - // try to dispatch to one of our process_* - indent() << "case Name of" << endl; - - for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) { - f_service_ << - indent() << " \"" << (*f_iter)->get_name() << "\" -> process_" << (*f_iter)->get_name() << "(HandlerModule, Seqid, Iprot, Oprot);" << endl; - } - - indent(f_service_) << " _ -> % unknown function" << endl; - if (tservice->get_extends() != NULL) { - indent(f_service_) << " " << extends << "_thrift:proc(Name,_Type,Seqid,HandlerModule, Iprot, Oprot)" << endl; - } else { - f_service_ << - indent() << " ?R1(Iprot, skip, ?tType_STRUCT)," << endl << - indent() << " ?R0(Iprot, readMessageEnd)," << endl << - indent() << " X = tApplicationException:new(?tApplicationException_UNKNOWN_METHOD, \"Unknown function \" ++ Name)," << endl << - indent() << " ?R3(Oprot, writeMessageBegin, Name, ?tMessageType_EXCEPTION, Seqid)," << endl << - indent() << " tApplicationException:write(X, Oprot)," << endl << - indent() << " ?R0(Oprot, writeMessageEnd)," << endl << - indent() << " Trans = ?R1(Oprot, get, trans)," << endl << - indent() << " ?R0(Trans, effectful_flush)," << endl << - indent() << " {error, X} % what's the retval in this case?" << endl; - } - f_service_ << indent() << "end." << endl; - - indent_down(); - - // Generate the process subfunctions - for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) { - generate_process_function(tservice, *f_iter); - } - - indent_down(); - indent(f_service_) << endl << endl; -} - -/** - * Generates a process function definition. - * - * @param tfunction The function to write a dispatcher for - */ -void t_erl_generator::generate_process_function(t_service* tservice, - t_function* tfunction) { - - string name = "process_" + tfunction->get_name(); - - export_string(name, 4); - - // Open function - indent(f_service_) << - name << - "(HandlerModule, Seqid, Iprot, Oprot) ->" << endl; - indent_up(); - - f_service_ << - indent() << "Seqid, Oprot, % suppress unused warnings" << endl; - - string ucfunname = uncapitalize(tfunction->get_name()); - string argsname = ucfunname + "_args"; - string resultname = ucfunname + "_result"; - - f_service_ << - indent() << "_Args = " << argsname << "_read(Iprot)," << endl << - // indent() << "Args, Seqid, Oprot, % suppress unused warnings" << endl << - // indent() << "Args % suppress unused warnings" << endl << - indent() << "?R0(Iprot, readMessageEnd)," << endl; - - t_struct* xs = tfunction->get_xceptions(); - const std::vector& xceptions = xs->get_members(); - vector::const_iterator x_iter; - - // Declare result for non async function - if (!tfunction->is_async()) { - } - - // Generate the function call - t_struct* arg_struct = tfunction->get_arglist(); - const std::vector& fields = arg_struct->get_members(); - vector::const_iterator f_iter; - - indent(f_service_) << "try" << endl; - indent_up(); - - indent(f_service_) << "Result = "; - if (xceptions.size() > 0) { - f_service_ << "try" << endl; - } else { - f_service_ << "begin" << endl; - } - indent_up(); - - f_service_ << indent(); - if (!tfunction->is_async() && !tfunction->get_returntype()->is_void()) { - f_service_<< "Res = "; - } - f_service_ << "HandlerModule:" << atomize(tfunction->get_name()) << "("; - - bool first = true; - for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) { - if (first) { - first = false; - } else { - f_service_ << ", "; - } - f_service_ << "_Args#" << argsname << "." << (*f_iter)->get_name(); - } - f_service_ << ")," << endl; - if (!tfunction->is_async() && !tfunction->get_returntype()->is_void()) { - indent(f_service_) << "#" << resultname << "{success=Res}" << endl; - } else{ - indent(f_service_) << "#" << resultname << "{}" << endl; - } - indent_down(); - if (!tfunction->is_async() && xceptions.size() > 0) { - indent(f_service_) << "catch" << endl; - indent_up(); - for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) { - indent(f_service_) << "E when is_record(E," << uncapitalize((*x_iter)->get_type()->get_name()) << ") ->" << endl; - indent_up(); - indent(f_service_) << "#" << resultname << "{" << (*x_iter)->get_name() << " = E};" << endl; - indent_down(); - } - indent(f_service_) << "dummy -> dummy % TODO: only for the semicolon's sake" << endl; - indent_down(); - } - indent(f_service_) << "end," << endl; - - if (!tfunction->is_async()) { - f_service_ << - indent() << "?R3(Oprot, writeMessageBegin, \"" << tfunction->get_name() << "\", ?tMessageType_REPLY, Seqid)," << endl << - indent() << ucfunname << "_result_write(Result, Oprot)," << endl; - } - indent(f_service_) << "Result" << endl; - indent_down(); - - // catch errors in the handler - indent(f_service_) << "catch" << endl << - indent() << " _:Kind when Kind == undef; Kind == function_clause ->" << endl << - indent() << " X = tApplicationException:new(?tApplicationException_HANDLER_ERROR, \"Handler doesn't implement " - << tfunction->get_name() <<"\")," << endl << - - indent() << " ?R3(Oprot, writeMessageBegin, \"" << tfunction->get_name() << "\", ?tMessageType_EXCEPTION, Seqid)," << endl << - indent() << " tApplicationException:write(X, Oprot)," << endl << - indent() << " {error, X};" << endl << - indent() << " _:_Kind ->" << endl << - indent() << " X = tApplicationException:new(?tApplicationException_HANDLER_ERROR, \"Unknown handler error in " - << tfunction->get_name() << "\")," << endl << - - indent() << " ?R3(Oprot, writeMessageBegin, \"" << tfunction->get_name() << "\", ?tMessageType_EXCEPTION, Seqid)," << endl << - indent() << " tApplicationException:write(X, Oprot)," << endl << - indent() << " {error, X}" << endl; - - // 'after' block if we're expecting a result written - if (!tfunction->is_async()) { - f_service_ << - indent() << "after" << endl; - - indent_up(); - - indent(f_service_) << "?R0(Oprot, writeMessageEnd)," << endl << - indent() << "Trans = ?R1(Oprot, get, trans)," << endl << - indent() << "?R0(Trans, effectful_flush)" << endl; - - indent_down(); - } - - indent(f_service_) << "end." << endl; - - indent_down(); -} - -/** - * Deserializes a field of any type. - */ -void t_erl_generator::generate_deserialize_field(ostream &out, - t_field* tfield, - string prefix, - bool inclass) { - t_type* type = get_true_type(tfield->get_type()); - - if (type->is_void()) { - throw "CANNOT GENERATE DESERIALIZE CODE FOR void TYPE: " + - prefix + tfield->get_name(); - } - - string name = prefix; //+ tfield->get_name(); - - if (type->is_struct() || type->is_xception()) { - generate_deserialize_struct(out, - (t_struct*)type, - name); - } else if (type->is_container()) { - generate_deserialize_container(out, type, name); - } else if (type->is_base_type() || type->is_enum()) { - indent(out) << - name << " = ?R0(Iprot, "; - - if (type->is_base_type()) { - t_base_type::t_base tbase = ((t_base_type*)type)->get_base(); - switch (tbase) { - case t_base_type::TYPE_VOID: - throw "compiler error: cannot serialize void field in a struct: " + - name; - break; - case t_base_type::TYPE_STRING: - out << "readString"; - break; - case t_base_type::TYPE_BOOL: - out << "readBool"; - break; - case t_base_type::TYPE_BYTE: - out << "readByte"; - break; - case t_base_type::TYPE_I16: - out << "readI16"; - break; - case t_base_type::TYPE_I32: - out << "readI32"; - break; - case t_base_type::TYPE_I64: - out << "readI64"; - break; - case t_base_type::TYPE_DOUBLE: - out << "readDouble"; - break; - default: - throw "compiler error: no PHP name for base type " + t_base_type::t_base_name(tbase); - } - } else if (type->is_enum()) { - out << "readI32"; - } - out << ")," << endl; - - } else { - printf("DO NOT KNOW HOW TO DESERIALIZE FIELD '%s' TYPE '%s'\n", - tfield->get_name().c_str(), type->get_name().c_str()); - } -} - -/** - * Generates an unserializer for a struct, calling read() - */ -void t_erl_generator::generate_deserialize_struct(ostream &out, - t_struct* tstruct, - string prefix) { - out << - indent() << prefix << " = " << (tstruct->get_program())->get_name() << "_types:" << type_name(tstruct) << "_read(Iprot)," << endl; -} - -/** - * Serialize a container by writing out the header followed by - * data and then a footer. - */ -void t_erl_generator::generate_deserialize_container(ostream &out, - t_type* ttype, - string prefix) { - string size = tmp("_size"); - string ktype = tmp("_ktype"); - string vtype = tmp("_vtype"); - string etype = tmp("_etype"); - - t_field fsize(g_type_i32, size); - t_field fktype(g_type_byte, ktype); - t_field fvtype(g_type_byte, vtype); - t_field fetype(g_type_byte, etype); - - // Declare variables, read header - if (ttype->is_map()) { - t_map* tmap = (t_map*)ttype; - string key = tmp("_key"); - string val = tmp("_val"); - t_field fkey(tmap->get_key_type(), key); - t_field fval(tmap->get_val_type(), val); - - out << - indent() << "{" << ktype << ", " << vtype << ", " << size << " } = ?R0(Iprot,readMapBegin)," << endl; - out << - indent() << prefix << " = dict:from_list(thrift_utils:tabulate(" << size << "," << endl; - indent_up(); - out << indent() << "fun (_) ->" << endl; - indent_up(); - generate_deserialize_field(out, &fkey,key); - generate_deserialize_field(out, &fval,val); - out << indent() << "{" << key << "," << val << "}" << endl; - indent_down(); - out << indent() << "end))," << endl; - indent_down(); - out << indent() << "?R0(Iprot,readMapEnd)," << endl; - - } else if (ttype->is_set()) { - t_set* tset = (t_set*)ttype; - string elem = tmp("_elem"); - t_field felem(tset->get_elem_type(), elem); - out << - indent() << "{" << etype << ", " << size << "} = ?R0(Iprot,readSetBegin)," << endl; - out << - indent() << prefix << " = sets:from_list(thrift_utils:tabulate(" << size << "," << endl; - indent_up(); - out << indent() << "fun (_) ->" << endl; - indent_up(); - generate_deserialize_field(out,&felem,elem); - out << indent() << elem << endl; - indent_down(); - out << indent() << "end)),"; - indent_down(); - out << indent() << "?R0(Iprot,readSetEnd)," << endl; - - } else if (ttype->is_list()) { - t_list* tlist = (t_list*)ttype; - string elem = tmp("_elem"); - t_field felem(tlist->get_elem_type(), elem); - out << indent() << "{" << etype << ", " << size << "} = ?R0(Iprot,readListBegin)," << endl; - out << indent() << prefix << " = thrift_utils:tabulate(" << size << "," << endl; - indent_up(); - out << indent() << "fun (_) ->" << endl; - indent_up(); - generate_deserialize_field(out,&felem,elem); - out << indent() << elem << endl; - indent_down(); - out << indent() << "end)," << endl; - indent_down(); - out << indent() << "?R0(Iprot,readListEnd)," << endl; - } -} - - -/** - * Generates code to deserialize a map UNUSED - */ -void t_erl_generator::generate_deserialize_map_element(ostream &out, // TODO - t_map* tmap, - string prefix) { - string key = tmp("_key"); - string val = tmp("_val"); - t_field fkey(tmap->get_key_type(), key); - t_field fval(tmap->get_val_type(), val); - - generate_deserialize_field(out, &fkey); - generate_deserialize_field(out, &fval); - - indent(out) << - prefix << "[" << key << "] = " << val << endl; -} - -/** - * Read a set element UNUSED - */ -void t_erl_generator::generate_deserialize_set_element(ostream &out, // TODO - t_set* tset, - string prefix) { - string elem = tmp("_elem"); - t_field felem(tset->get_elem_type(), elem); - - generate_deserialize_field(out, &felem); - - indent(out) << - prefix << "[" << elem << "] = true" << endl; -} - -/** - * Read a list element UNUSED - */ -void t_erl_generator::generate_deserialize_list_element(ostream &out, // TODO - t_list* tlist, - string prefix) { - string elem = tmp("_elem"); - t_field felem(tlist->get_elem_type(), elem); - - generate_deserialize_field(out, &felem); - - indent(out) << - prefix << ".push(" << elem << ")" << endl; -} - - -/** - * Serializes a field of any type. - * - * @param tfield The field to serialize - * @param prefix Name to prepend to field name - */ -void t_erl_generator::generate_serialize_field(ostream &out, - t_field* tfield, - string prefix) { - t_type* type = get_true_type(tfield->get_type()); - - // Do nothing for void types - if (type->is_void()) { - throw "CANNOT GENERATE SERIALIZE CODE FOR void TYPE: " + - prefix + tfield->get_name(); - } - - if (type->is_struct() || type->is_xception()) { - generate_serialize_struct(out, - (t_struct*)type, - prefix + tfield->get_name()); - } else if (type->is_container()) { - generate_serialize_container(out, - type, - prefix + tfield->get_name()); - } else if (type->is_base_type() || type->is_enum()) { - - string name = prefix + tfield->get_name(); - - indent(out) << - "?R1(Oprot, "; - - if (type->is_base_type()) { - t_base_type::t_base tbase = ((t_base_type*)type)->get_base(); - switch (tbase) { - case t_base_type::TYPE_VOID: - throw - "compiler error: cannot serialize void field in a struct: " + name; - break; - case t_base_type::TYPE_STRING: - out << "writeString, " << name << "),"; - break; - case t_base_type::TYPE_BOOL: - out << "writeBool, " << name << "),"; - break; - case t_base_type::TYPE_BYTE: - out << "writeByte, " << name << "),"; - break; - case t_base_type::TYPE_I16: - out << "writeI16, " << name << "),"; - break; - case t_base_type::TYPE_I32: - out << "writeI32, " << name << "),"; - break; - case t_base_type::TYPE_I64: - out << "writeI64, " << name << "),"; - break; - case t_base_type::TYPE_DOUBLE: - out << "writeDouble, " << name << "),"; - break; - default: - throw "compiler error: no PHP name for base type " + t_base_type::t_base_name(tbase); - } - } else if (type->is_enum()) { - out << "writeI32, " << name << "),"; - } - out << "" << endl; - } else { - printf("DO NOT KNOW HOW TO SERIALIZE FIELD '%s%s' TYPE '%s'\n", - prefix.c_str(), - tfield->get_name().c_str(), - type->get_name().c_str()); - } -} - -/** - * Serializes all the members of a struct. - * - * @param tstruct The struct to serialize - * @param prefix String prefix to attach to all fields - */ -void t_erl_generator::generate_serialize_struct(ostream &out, - t_struct* tstruct, - string prefix) { - indent(out) << tstruct->get_program()->get_name() << "_types:" << uncapitalize(tstruct->get_name()) << "_write(" << prefix << ", Oprot)," << endl; -} - -void t_erl_generator::generate_serialize_container(ostream &out, // TODO - t_type* ttype, - string prefix) { - if (ttype->is_map()) { - indent(out) << - "?R3(Oprot, writeMapBegin, " << - type_to_enum(((t_map*)ttype)->get_key_type()) << ", " << - type_to_enum(((t_map*)ttype)->get_val_type()) << ", thrift_utils:dict_size(" << - prefix << "))," << endl; - } else if (ttype->is_set()) { - indent(out) << - "?R2(Oprot, writeSetBegin, " << - type_to_enum(((t_set*)ttype)->get_elem_type()) << ", sets:size(" << - prefix << "))," << endl; - } else if (ttype->is_list()) { - indent(out) << - "?R2(Oprot, writeListBegin, " << - type_to_enum(((t_list*)ttype)->get_elem_type()) << ", length(" << - prefix << "))," << endl; - } - - if (ttype->is_map()) { - string kiter = tmp("_kiter"); - string viter = tmp("_viter"); - indent(out) << - "dict:fold(fun ("<< kiter << ", " << viter << ",_)->" << endl; - indent_up(); - generate_serialize_map_element(out, (t_map*)ttype, kiter, viter); - indent(out) << "nil" << endl; - indent_down(); - indent(out) << "end, nil," << prefix << ")," << endl; - } else if (ttype->is_set()) { - string iter = tmp("_iter"); - indent(out) << - "sets:fold(fun ("<< iter << ",_)->" << endl; - indent_up(); - generate_serialize_set_element(out, (t_set*)ttype, iter); - indent(out) << "nil" << endl; - indent_down(); - indent(out) << "end, nil," << prefix << ")," << endl; - } else if (ttype->is_list()) { - string iter = tmp("_iter"); - indent(out) << - "lists:foldl(fun (" << iter << ",_)->" << endl; - indent_up(); - generate_serialize_list_element(out, (t_list*)ttype, iter); - indent(out) << "nil" << endl; - indent_down(); - indent(out) << "end,nil," << prefix << ")," << endl; - } - - if (ttype->is_map()) { - indent(out) << - "?R0(Oprot, writeMapEnd)," << endl; - } else if (ttype->is_set()) { - indent(out) << - "?R0(Oprot, writeSetEnd)," << endl; - } else if (ttype->is_list()) { - indent(out) << - "?R0(Oprot, writeListEnd)," << endl; - } -} - -/** - * Serializes the members of a map. - * - */ -void t_erl_generator::generate_serialize_map_element(ostream &out, - t_map* tmap, - string kiter, - string viter) { - t_field kfield(tmap->get_key_type(), kiter); - generate_serialize_field(out, &kfield, ""); - - t_field vfield(tmap->get_val_type(), viter); - generate_serialize_field(out, &vfield, ""); -} - -/** - * Serializes the members of a set. - */ -void t_erl_generator::generate_serialize_set_element(ostream &out, - t_set* tset, - string iter) { - t_field efield(tset->get_elem_type(), iter); - generate_serialize_field(out, &efield, ""); -} - -/** - * Serializes the members of a list. - */ -void t_erl_generator::generate_serialize_list_element(ostream &out, - t_list* tlist, - string iter) { - t_field efield(tlist->get_elem_type(), iter); - generate_serialize_field(out, &efield, ""); -} - -/** - * Declares a field, which may include initialization as necessary. - * - * @param ttype The type - */ -string t_erl_generator::declare_field(t_field* tfield) { // TODO - string result = "@" + tfield->get_name(); - t_type* type = get_true_type(tfield->get_type()); - if (tfield->get_value() != NULL) { - result += " = " + render_const_value(type, tfield->get_value()); - } else { - result += " = nil"; - } - return result; -} - -/** - * Renders a function signature of the form 'type name(args)' - * - * @param tfunction Function definition - * @return String of rendered function definition - */ -string t_erl_generator::function_signature(t_function* tfunction, - string prefix) { - return - atomize(prefix + tfunction->get_name()) + - "(This" + capitalize(argument_list(tfunction->get_arglist())) + ")"; -} - -/** - * Add a function to the exports list - */ -void t_erl_generator::export_string(string name, int num) { - if (export_lines_first_) { - export_lines_first_ = false; - } else { - export_lines_ << ", "; - } - - export_lines_ << atomize(name) << "/" << num; -} - -void t_erl_generator::export_types_function(t_function* tfunction, - string prefix) { - - export_types_string(prefix + tfunction->get_name(), - 1 // This - + ((tfunction->get_arglist())->get_members()).size() - ); -} - -void t_erl_generator::export_types_string(string name, int num) { - if (export_types_lines_first_) { - export_types_lines_first_ = false; - } else { - export_types_lines_ << ", "; - } - export_types_lines_ << name << "/" << num; -} - -void t_erl_generator::export_function(t_function* tfunction, - string prefix) { - - export_string(prefix + tfunction->get_name(), - 1 // This - + ((tfunction->get_arglist())->get_members()).size() - ); -} - - -/** - * Renders a field list - */ -string t_erl_generator::argument_list(t_struct* tstruct) { - string result = ""; - - const vector& fields = tstruct->get_members(); - vector::const_iterator f_iter; - bool first = true; - for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) { - if (first) { - first = false; - result += ", "; // initial comma to compensate for initial This - } else { - result += ", "; - } - result += capitalize((*f_iter)->get_name()); - } - return result; -} - -string t_erl_generator::type_name(t_type* ttype) { - string prefix = ""; - string name = ttype->get_name(); - - if (ttype->is_struct() || ttype->is_xception() || ttype->is_service()) { - name = uncapitalize(ttype->get_name()); - } - - return prefix + name; -} - -/** - * Converts the parse type to a Erlang "type" (macro for int constants) - */ -string t_erl_generator::type_to_enum(t_type* type) { - type = get_true_type(type); - - if (type->is_base_type()) { - t_base_type::t_base tbase = ((t_base_type*)type)->get_base(); - switch (tbase) { - case t_base_type::TYPE_VOID: - throw "NO T_VOID CONSTRUCT"; - case t_base_type::TYPE_STRING: - return "?tType_STRING"; - case t_base_type::TYPE_BOOL: - return "?tType_BOOL"; - case t_base_type::TYPE_BYTE: - return "?tType_BYTE"; - case t_base_type::TYPE_I16: - return "?tType_I16"; - case t_base_type::TYPE_I32: - return "?tType_I32"; - case t_base_type::TYPE_I64: - return "?tType_I64"; - case t_base_type::TYPE_DOUBLE: - return "?tType_DOUBLE"; - } - } else if (type->is_enum()) { - return "?tType_I32"; - } else if (type->is_struct() || type->is_xception()) { - return "?tType_STRUCT"; - } else if (type->is_map()) { - return "?tType_MAP"; - } else if (type->is_set()) { - return "?tType_SET"; - } else if (type->is_list()) { - return "?tType_LIST"; - } - - throw "INVALID TYPE IN type_to_enum: " + type->get_name(); -} diff --git a/compiler/cpp/src/generate/t_erl_generator.h b/compiler/cpp/src/generate/t_erl_generator.h deleted file mode 100644 index a556e9ab..00000000 --- a/compiler/cpp/src/generate/t_erl_generator.h +++ /dev/null @@ -1,196 +0,0 @@ -#ifndef T_ERL_GENERATOR_H -#define T_ERL_GENERATOR_H - -#include -#include -#include -#include - -#include "t_oop_generator.h" - -/** - * Erlang code generator. - * - * @author - */ -class t_erl_generator : public t_oop_generator { - public: - t_erl_generator(t_program* program) : - t_oop_generator(program) - { - program_name_[0] = tolower(program_name_[0]); - service_name_[0] = tolower(service_name_[0]); - out_dir_base_ = "gen-erl"; - } - - /** - * Init and close methods - */ - - void init_generator(); - void close_generator(); - - /** - * Program-level generation functions - */ - - void generate_typedef (t_typedef* ttypedef); - void generate_enum (t_enum* tenum); - void generate_const (t_const* tconst); - void generate_struct (t_struct* tstruct); - void generate_xception (t_struct* txception); - void generate_service (t_service* tservice); - - std::string render_const_value(t_type* type, t_const_value* value); - - /** - * Struct generation code - */ - - void generate_erl_struct(t_struct* tstruct, bool is_exception); - void generate_erl_struct_definition(std::ostream& out, std::ostream& hrl_out, t_struct* tstruct, bool is_xception=false, bool is_result=false); - void generate_erl_struct_reader(std::ostream& out, t_struct* tstruct); - void generate_erl_struct_writer(std::ostream& out, t_struct* tstruct); - void generate_erl_function_helpers(t_function* tfunction); - - /** - * Service-level generation functions - */ - - void generate_service_helpers (t_service* tservice); - void generate_service_interface (t_service* tservice); - void generate_service_client (t_service* tservice); - void generate_service_server (t_service* tservice); - void generate_process_function (t_service* tservice, t_function* tfunction); - - /** - * Serialization constructs - */ - - void generate_deserialize_field (std::ostream &out, - t_field* tfield, - std::string prefix="", - bool inclass=false); - - void generate_deserialize_struct (std::ostream &out, - t_struct* tstruct, - std::string prefix=""); - - void generate_deserialize_container (std::ostream &out, - t_type* ttype, - std::string prefix=""); - - void generate_deserialize_set_element (std::ostream &out, - t_set* tset, - std::string prefix=""); - - void generate_deserialize_map_element (std::ostream &out, - t_map* tmap, - std::string prefix=""); - - void generate_deserialize_list_element (std::ostream &out, - t_list* tlist, - std::string prefix=""); - - void generate_serialize_field (std::ostream &out, - t_field* tfield, - std::string prefix=""); - - void generate_serialize_struct (std::ostream &out, - t_struct* tstruct, - std::string prefix=""); - - void generate_serialize_container (std::ostream &out, - t_type* ttype, - std::string prefix=""); - - void generate_serialize_map_element (std::ostream &out, - t_map* tmap, - std::string kiter, - std::string viter); - - void generate_serialize_set_element (std::ostream &out, - t_set* tmap, - std::string iter); - - void generate_serialize_list_element (std::ostream &out, - t_list* tlist, - std::string iter); - - /** - * Helper rendering functions - */ - - std::string erl_autogen_comment(); - std::string erl_imports(); - std::string render_includes(); - std::string declare_field(t_field* tfield); - std::string type_name(t_type* ttype); - std::string function_signature(t_function* tfunction, std::string prefix=""); - - std::string argument_list(t_struct* tstruct); - std::string type_to_enum(t_type* ttype); - - std::string capitalize(std::string in) { - in[0] = toupper(in[0]); - return in; - } - - std::string uncapitalize(std::string in) { - in[0] = tolower(in[0]); - return in; - } - - std::string atomize(std::string in) { - if (isupper(in[0])) { - return "'" + in + "'"; - } else { - return in; - } - } - - private: - - /** - * add function to export list - */ - - void export_function(t_function* tfunction, std::string prefix=""); - void export_string(std::string name, int num); - - void export_types_function(t_function* tfunction, std::string prefix=""); - void export_types_string(std::string name, int num); - - /** - * write out headers and footers for hrl files - */ - - void hrl_header(std::ostream& out, std::string name); - void hrl_footer(std::ostream& out, std::string name); - - /** - * stuff to spit out at the top of generated files - */ - - bool export_lines_first_; - std::ostringstream export_lines_; - - bool export_types_lines_first_; - std::ostringstream export_types_lines_; - - /** - * File streams - */ - - std::ostringstream f_types_; - std::ofstream f_types_file_; - std::ofstream f_types_hrl_file_; - - std::ofstream f_consts_; - std::ostringstream f_service_; - std::ofstream f_service_file_; - std::ofstream f_service_hrl_; - -}; - -#endif diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc index 80d39606..7fcab639 100644 --- a/compiler/cpp/src/main.cc +++ b/compiler/cpp/src/main.cc @@ -38,7 +38,6 @@ #include "parse/t_scope.h" #include "generate/t_php_generator.h" #include "generate/t_xsd_generator.h" -#include "generate/t_erl_generator.h" #include "generate/t_alterl_generator.h" using namespace std; @@ -152,7 +151,6 @@ bool gen_phpa = false; bool gen_phpo = false; bool gen_rest = false; bool gen_perl = false; -bool gen_erl = false; bool gen_alterl = false; bool gen_ocaml = false; bool gen_hs = false; @@ -603,7 +601,6 @@ void usage() { fprintf(stderr, " -phpa Generate PHP with autoload (with -php)\n"); fprintf(stderr, " -phpo Generate PHP with object oriented subclasses (with -php)\n"); fprintf(stderr, " -xsd Generate XSD output files\n"); - fprintf(stderr, " -erl Generate Erlang output files\n"); fprintf(stderr, " -alterl Generate Alternative Erlang output files\n"); fprintf(stderr, " -o dir Set the output directory for gen-* packages\n"); fprintf(stderr, " (default: current directory)\n"); @@ -874,13 +871,6 @@ void generate(t_program* program, const vector& generator_strings) { delete xsd; } - if (gen_erl) { - pverbose("Generating Erlang\n"); - t_erl_generator* erl = new t_erl_generator(program); - erl->generate_program(); - delete erl; - } - if (gen_alterl) { pverbose("Generating Alternative Erlang\n"); t_alterl_generator* alterl = new t_alterl_generator(program); @@ -1002,8 +992,6 @@ int main(int argc, char** argv) { gen_xsd = true; } else if (strcmp(arg, "-perl") == 0) { gen_perl = true; - } else if (strcmp(arg, "-erl") == 0) { - gen_erl = true; } else if (strcmp(arg, "-alterl") == 0) { gen_alterl = true; } else if (strcmp(arg, "-ocaml") == 0) { @@ -1117,7 +1105,7 @@ int main(int argc, char** argv) { } // You gotta generate something! - if (!gen_php && !gen_phpi && !gen_xsd && !gen_erl && !gen_alterl && generator_strings.empty()) { + if (!gen_php && !gen_phpi && !gen_xsd && !gen_alterl && generator_strings.empty()) { fprintf(stderr, "!!! No output language(s) specified\n\n"); usage(); } diff --git a/lib/Makefile.am b/lib/Makefile.am index 5d2e1fa0..8cbb80f2 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -11,12 +11,11 @@ SUBDIRS += java endif if ENABLE_ERLANG -SUBDIRS += erl +SUBDIRS += alterl endif EXTRA_DIST = \ cocoa \ - erl \ hs \ ocaml \ perl \ diff --git a/lib/erl/COPYING b/lib/erl/COPYING deleted file mode 100644 index 0101a7dc..00000000 --- a/lib/erl/COPYING +++ /dev/null @@ -1,24 +0,0 @@ -Thrift Software License -Copyright (c) 2006- Facebook, Inc. - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/lib/erl/LICENSE b/lib/erl/LICENSE deleted file mode 100644 index 0101a7dc..00000000 --- a/lib/erl/LICENSE +++ /dev/null @@ -1,24 +0,0 @@ -Thrift Software License -Copyright (c) 2006- Facebook, Inc. - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/lib/erl/Makefile b/lib/erl/Makefile deleted file mode 100644 index 09b1d1fd..00000000 --- a/lib/erl/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -MODULES = \ - src - -all clean docs: - for dir in $(MODULES); do \ - (cd $$dir; ${MAKE} $@); \ - done - -check: all - -distclean: clean - -# Hack to make "make dist" work. -# This should not work, but it appears to. -distdir: diff --git a/lib/erl/README b/lib/erl/README deleted file mode 100644 index caea0670..00000000 --- a/lib/erl/README +++ /dev/null @@ -1,82 +0,0 @@ -Thrift Erlang Library - -README Author: Chris Piro (cpiro@facebook.com) -Last Modified: 2007-Sep-17 - -Thrift is distributed under the Thrift open source software license. -Please see the included LICENSE file. - -Using Thrift with Erlang -======================== - -The Thrift Erlang binding is built using GNU make. Run `make' in -lib/erl to generate the necessary .beam object files in lib/erl/ebin/. -Although the directories are laid out much like an OTP application, -these bindings (as you will soon discover) are not an OTP application -proper. When starting the Erlang emulator (interpreter) you must use -`-pa /path/to/thrift/lib/erl/ebin' to load the bindings. - -Running the Tutorial -==================== - -It is recommended to pattern your own servers after the tutorial -included in tutorial/. Generate the gen-erl/ directory by running -tutorial.thrift, then cd to tutorial/erl/ and run server.sh. This -script includes the commmands necessary to compile the generated -Erlang source, compile the tutorial server itself, and open the Erlang -emulator. At the emulator prompt, type `server:start()' to begin -listening for connections. - -Note that there is no tutorial client; you may use a supplied client -in another language. - -Implementation Notes -==================== - -tExecptions and t*Factorys are straight "new" -- e.g. TF = -tTransportFactory:new() everything else is start_new -(i.e. gen_server:start_link) -- this spawns a process and returns a -pid - -tErlProcessor is a shim around the generated code (which is not -actually a gen_server). Of course tErlProcessor isn't a gen_server -either ... thrift_oop_server is a shim to make our "Thrift objects" -gen_servers. Maybe we should remove some layers? - -get/set never means process dictionary - -Use tErlServer and tErlAcceptor. tSimpleServer and tServerSocket as -are present in the other bindings are incompatible by design ... the -call trace is spastic across the process tree. tErlServer and -tErlAcceptor follow the same model as iserve: - - * the top level code spawns a tErlServer, which listens on a socket - * a tErlAcceptor is spawned and calls accept() on the listening -socket - * when accept() finishes, the tErlAcceptor - * tells the tErlServer to spawn a new acceptor - * handles the requests by spawning a processor, a transport, and a -protocol - * (the tricky part) when the socket closes, the protocol exits, so: - * the transport exits because it's the one caller of the protocol - * likewise, the processor exits because it's the caller of the -transport - * the tErlAcceptor traps the protocol's exit and exits with an -acceptor_done - * the tErlServer sees that the acceptor exited and does nothing -since there is already another acceptor accept()ing on the listen -socket - -For info about iserve: http://www.trapexit.org/A_fast_web_server_demonstrating_some_undocumented_Erlang_features - -Final Thoughts -============== - -This binding is a work in progress. It's certainly less thoroughly -tested than the other, older bindings. Despite using parts from -otp_base it is not packaged well, nor is it an OTP application (not to -mention its many smaller transgressions). This implementation -intentionally patterns after the other bindings (which is why there's -oop.erl and thrift_oop_server), but regretfully it departs from -idiomatic Erlang. Please see the included TODO and contribute your -improvements back to the project. diff --git a/lib/erl/TODO b/lib/erl/TODO deleted file mode 100644 index 03384fb1..00000000 --- a/lib/erl/TODO +++ /dev/null @@ -1,35 +0,0 @@ -make thrift a proper OTP application - * app-wide configuration (do DNS lookups?) - * default protocols / transports (forget this factory business) - * factor for elegance - -tutorial client - -make all methods effectful, remove the special casing (optionally, implement monads for Erlang) - -change objects from {record_tag, ...} to {oop_object, {record_tag, ...}, other_useful_stuff} -so 1) we know exactly what's an object (can write is_object/1) e.g. - is the tuple {tTransportException, ...} an object or a tuple that happens to start with that atom? - we can't check this using is_record/2 without include every header file - also, this makes it easy to pick objects out of deep tuples - 2) we can build more functionality into oop later if need be - carry around the class/superclasses so is_a(Object, ClassOrSuperclass) is easy - 3) maybe hack up io:format and friends to run objects through oop:inspect automatically - -Currently we can't distingish a method exiting in the middle with an undef or function_clause from a method not being defined in a module. Big example: if the generated code can't be called at tErlProcessor.erl:63, it will exit with a missing_method not because tErlProcessor:process/3 is undefined, but because GP:process/3 is undefined, but the error makes it seem like the former happened. The oop code needs to be smarter -- I think it's possible to either a) hook into Erlang's missing function handler or b) do some introspection to determine directly whether a function is defined, rather than trying to infer from the exit. - -test suites - -move as much (program logic) as possible out of thrift_logger - -make thrift_logger 100% robust - -thrift_logger detects term width? - -undisgustify codegen - -move away from thrift_oop_server shim to straight-up gen_servers - -move away from Factories - -move away from ?L0, ?M0, and friends ... make calls in oop or individual modules (like gen_servers should be) diff --git a/lib/erl/build/beamver b/lib/erl/build/beamver deleted file mode 100644 index 2b5f77b3..00000000 --- a/lib/erl/build/beamver +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/sh - -# erlwareSys: otp/build/beamver,v 1.1 2002/02/14 11:45:20 hal Exp $ - -# usage: beamver -# -# if there's a usable -vsn() attribute, print it and exit with status 0 -# otherwise, print nothing and exit with status 1 - -# From the Erlang shell: -# -# 5> code:which(acca_inets). -# "/home/martin/work/otp/releases//../../acca/ebin/.beam" -# -# 8> beam_lib:version(code:which()). -# {ok,{,['$Id: beamver,v 1.1.1.1 2003/06/13 21:43:21 mlogan Exp $ ']}} - -# TMPFILE looks like this: -# -# io:format("hello ~p~n", -# beam_lib:version("/home/hal/work/otp/acca/ebin/acca_inets.beam")]). - -TMPFILE=/tmp/beamver.$$ - -# exit with failure if we can't read the file -test -f "$1" || exit 1 -BEAMFILE=\"$1\" - -cat > $TMPFILE <<_EOF -io:format("~p~n", - [beam_lib:version($BEAMFILE)]). -_EOF - -# beam_result is {ok,{Module_name, Beam_version} or {error,beam_lib,{Reason}} -beam_result=`erl -noshell \ - -s file eval $TMPFILE \ - -s erlang halt` - -rm -f $TMPFILE - -# sed regexes: -# remove brackets and anything outside them -# remove quotes and anything outside them -# remove apostrophes and anything outside them -# remove leading and trailing spaces - -case $beam_result in -\{ok*) - echo $beam_result | sed -e 's/.*\[\(.*\)].*/\1/' \ - -e 's/.*\"\(.*\)\".*/\1/' \ - -e "s/.*\'\(.*\)\'.*/\1/" \ - -e 's/ *$//' -e 's/^ *//' - exit 0 - ;; -*) - exit 1 - ;; -esac - diff --git a/lib/erl/build/buildtargets.mk b/lib/erl/build/buildtargets.mk deleted file mode 100644 index db52b785..00000000 --- a/lib/erl/build/buildtargets.mk +++ /dev/null @@ -1,15 +0,0 @@ -EBIN ?= ../ebin -ESRC ?= . -EMULATOR = beam - -ERLC_WFLAGS = -W -ERLC = erlc $(ERLC_WFLAGS) $(ERLC_FLAGS) -ERL = erl -boot start_clean - -$(EBIN)/%.beam: $(ESRC)/%.erl - @echo " ERLC $<" - @$(ERLC) $(ERL_FLAGS) $(ERL_COMPILE_FLAGS) -o$(EBIN) $< - -.erl.beam: - $(ERLC) $(ERL_FLAGS) $(ERL_COMPILE_FLAGS) -o$(dir $@) $< - diff --git a/lib/erl/build/colors.mk b/lib/erl/build/colors.mk deleted file mode 100644 index 4d69c41d..00000000 --- a/lib/erl/build/colors.mk +++ /dev/null @@ -1,24 +0,0 @@ -# Colors to assist visual inspection of make output. - -# Colors -LGRAY=$$'\e[0;37m' -DGRAY=$$'\e[1;30m' -LGREEN=$$'\e[1;32m' -LBLUE=$$'\e[1;34m' -LCYAN=$$'\e[1;36m' -LPURPLE=$$'\e[1;35m' -LRED=$$'\e[1;31m' -NO_COLOR=$$'\e[0m' -DEFAULT=$$'\e[0m' -BLACK=$$'\e[0;30m' -BLUE=$$'\e[0;34m' -GREEN=$$'\e[0;32m' -CYAN=$$'\e[0;36m' -RED=$$'\e[0;31m' -PURPLE=$$'\e[0;35m' -BROWN=$$'\e[0;33m' -YELLOW=$$'\e[1;33m' -WHITE=$$'\e[1;37m' - -BOLD=$$'\e[1;37m' -OFF=$$'\e[0m' diff --git a/lib/erl/build/docs.mk b/lib/erl/build/docs.mk deleted file mode 100644 index b0b7377f..00000000 --- a/lib/erl/build/docs.mk +++ /dev/null @@ -1,12 +0,0 @@ -EDOC_PATH=../../../tools/utilities - -#single place to include docs from. -docs: - @mkdir -p ../doc - @echo -n $${MY_BLUE:-$(BLUE)}; \ - $(EDOC_PATH)/edoc $(APP_NAME); \ - if [ $$? -eq 0 ]; then \ - echo $${MY_LRED:-$(LRED)}"$$d Doc Failed"; \ - fi; \ - echo -n $(OFF)$(NO_COLOR) - diff --git a/lib/erl/build/mime.types b/lib/erl/build/mime.types deleted file mode 100644 index d6e3c0d0..00000000 --- a/lib/erl/build/mime.types +++ /dev/null @@ -1,98 +0,0 @@ - -application/activemessage -application/andrew-inset -application/applefile -application/atomicmail -application/dca-rft -application/dec-dx -application/mac-binhex40 hqx -application/mac-compactpro cpt -application/macwriteii -application/msword doc -application/news-message-id -application/news-transmission -application/octet-stream bin dms lha lzh exe class -application/oda oda -application/pdf pdf -application/postscript ai eps ps -application/powerpoint ppt -application/remote-printing -application/rtf rtf -application/slate -application/wita -application/wordperfect5.1 -application/x-bcpio bcpio -application/x-cdlink vcd -application/x-compress Z -application/x-cpio cpio -application/x-csh csh -application/x-director dcr dir dxr -application/x-dvi dvi -application/x-gtar gtar -application/x-gzip gz -application/x-hdf hdf -application/x-httpd-cgi cgi -application/x-koan skp skd skt skm -application/x-latex latex -application/x-mif mif -application/x-netcdf nc cdf -application/x-sh sh -application/x-shar shar -application/x-stuffit sit -application/x-sv4cpio sv4cpio -application/x-sv4crc sv4crc -application/x-tar tar -application/x-tcl tcl -application/x-tex tex -application/x-texinfo texinfo texi -application/x-troff t tr roff -application/x-troff-man man -application/x-troff-me me -application/x-troff-ms ms -application/x-ustar ustar -application/x-wais-source src -application/zip zip -audio/basic au snd -audio/mpeg mpga mp2 -audio/x-aiff aif aiff aifc -audio/x-pn-realaudio ram -audio/x-pn-realaudio-plugin rpm -audio/x-realaudio ra -audio/x-wav wav -chemical/x-pdb pdb xyz -image/gif gif -image/ief ief -image/jpeg jpeg jpg jpe -image/png png -image/tiff tiff tif -image/x-cmu-raster ras -image/x-portable-anymap pnm -image/x-portable-bitmap pbm -image/x-portable-graymap pgm -image/x-portable-pixmap ppm -image/x-rgb rgb -image/x-xbitmap xbm -image/x-xpixmap xpm -image/x-xwindowdump xwd -message/external-body -message/news -message/partial -message/rfc822 -multipart/alternative -multipart/appledouble -multipart/digest -multipart/mixed -multipart/parallel -text/html html htm -text/x-server-parsed-html shtml -text/plain txt -text/richtext rtx -text/tab-separated-values tsv -text/x-setext etx -text/x-sgml sgml sgm -video/mpeg mpeg mpg mpe -video/quicktime qt mov -video/x-msvideo avi -video/x-sgi-movie movie -x-conference/x-cooltalk ice -x-world/x-vrml wrl vrml diff --git a/lib/erl/build/otp.mk b/lib/erl/build/otp.mk deleted file mode 100644 index 1d16e2c8..00000000 --- a/lib/erl/build/otp.mk +++ /dev/null @@ -1,146 +0,0 @@ -# +----------------------------------------------------------------------+ -# $Id: otp.mk,v 1.4 2004/07/01 14:57:10 tfee Exp $ -# +----------------------------------------------------------------------+ - -# otp.mk -# - to be included in all OTP Makefiles -# installed to /usr/local/include/erlang/otp.mk - -# gmake looks in /usr/local/include - that's hard-coded -# users of this file will use -# include erlang/top.mk - -# most interface files will be installed to $ERL_RUN_TOP/app-vsn/include/*.hrl - -# group owner for library/include directories -ERLANGDEV_GROUP=erlangdev - -# ERL_TOP is root of Erlang source tree -# ERL_RUN_TOP is root of Erlang target tree (some Ericsson Makefiles use $ROOT) -# ERLANG_OTP is target root for Erlang code -# - see sasl/systools reference manual page; grep "TEST" - -# OS_TYPE is FreeBSD, NetBSD, OpenBSD, Linux, SCO_SV, SunOS. -OS_TYPE=${shell uname} - -# MHOST is the host where this Makefile runs. -MHOST=${shell hostname -s} -ERL_COMPILE_FLAGS+=-W0 - -# The location of the erlang runtime system. -ifndef ERL_RUN_TOP -ERL_RUN_TOP=/usr/local/lib/erlang -endif - - -# Edit to reflect local environment. -# ifeq (${OS_TYPE},Linux) -# ERL_RUN_TOP=/usr/local/lib/erlang -# Note* ERL_RUN_TOP can be determined by starting an -# erlang shell and typing code:root_dir(). -# ERL_TOP=a symbolic link to the actual source top, which changes from version to version -# Note* ERL_TOP is the directory where the erlang -# source files reside. Make sure to run ./configure there. -# TARGET=i686-pc-linux-gnu -# Note* Target can be found in $ERL_TOP/erts -# endif - -# See above for directions. -ifeq (${OS_TYPE},Linux) -ERL_TOP=/opt/OTP_SRC -TARGET=i686-pc-linux-gnu -endif - -ERLANG_OTP=/usr/local/erlang/otp -VAR_OTP=/var/otp - - -# Aliases for common binaries -# Note - CFLAGS is modified in erlang.conf - - -################################ -# SunOS -################################ -ifeq (${OS_TYPE},SunOS) - - CC=gcc - CXX=g++ - AR=/usr/ccs/bin/ar - ARFLAGS=-rv - CXXFLAGS+=${CFLAGS} -I/usr/include/g++ - LD=/usr/ccs/bin/ld - RANLIB=/usr/ccs/bin/ranlib - -CFLAGS+=-Wall -pedantic -ansi -O -CORE=*.core -endif - - -################################ -# FreeBSD -################################ -ifeq (${OS_TYPE},FreeBSD) - - ifdef LINUXBIN - COMPAT_LINUX=/compat/linux - CC=${COMPAT_LINUX}/usr/bin/gcc - CXX=${COMPAT_LINUX}/usr/bin/g++ - AR=${COMPAT_LINUX}/usr/bin/ar - ARFLAGS=-rv - CXXFLAGS+=-fhandle-exceptions ${CFLAGS} -I${COMPAT_LINUX}/usr/include/g++ - LD=${COMPAT_LINUX}/usr/bin/ld - RANLIB=${COMPAT_LINUX}/usr/bin/ranlib - BRANDELF=brandelf -t Linux - else - CC=gcc - CXX=g++ - AR=/usr/bin/ar - ARFLAGS=-rv - CXXFLAGS+=-fhandle-exceptions ${CFLAGS} -I/usr/include/g++ - LD=/usr/bin/ld - RANLIB=/usr/bin/ranlib - BRANDELF=@true - - ifdef USES_PTHREADS - CFLAGS+=-D_THREAD_SAFE - LDFLAGS+=-lc_r - - # -pthread flag for 3.0+ - ifneq (${shell uname -r | cut -d. -f1},2) - CFLAGS+=-pthread - endif - endif - endif - -CFLAGS+=-Wall -pedantic -ansi -O -DFREEBSD -CORE=*.core -endif - -################################ -# OpenBSD -################################ -ifeq (${OS_TYPE},OpenBSD) - - CC=gcc - CXX=g++ - AR=/usr/bin/ar - ARFLAGS=-rv - CXXFLAGS+=${CFLAGS} -I/usr/include/g++ - LD=/usr/bin/ld - RANLIB=/usr/bin/ranlib - - ifdef USES_PTHREADS - CFLAGS+=-D_THREAD_SAFE - LDFLAGS+=-lc_r - - # -pthread flag for 3.0+ - ifneq (${shell uname -r | cut -d. -f1},2) - CFLAGS+=-pthread - endif - endif - -CFLAGS+=-Wall -pedantic -ansi -O -DOPENBSD -CORE=*.core -endif - diff --git a/lib/erl/build/otp_subdir.mk b/lib/erl/build/otp_subdir.mk deleted file mode 100644 index 2a36c658..00000000 --- a/lib/erl/build/otp_subdir.mk +++ /dev/null @@ -1,85 +0,0 @@ -# Comment by tfee 2004-07-01 -# ========================== -# This file is a mod of the stock OTP one. -# The change allows make to stop when a compile error occurs. -# This file needs to go into two places: -# /usr/local/include/erlang -# /opt/OTP_SRC/make -# -# where OTP_SRC is a symbolic link to a peer directory containing -# the otp source, e.g. otp_src_R9C-2. -# -# After installing OTP, running sudo make install in otp/build -# will push this file out to the two places listed above. -# -# The mod involves setting the shell variable $short_circuit, which we -# introduce - ie it is not in the stock file. This variable is tested -# to affect execution flow and is also returned to affect the flow in -# the calling script (this one). The latter step is necessary because -# of the recursion involved. -# ===================================================================== - - -# ``The contents of this file are subject to the Erlang Public License, -# Version 1.1, (the "License"); you may not use this file except in -# compliance with the License. You should have received a copy of the -# Erlang Public License along with this software. If not, it can be -# retrieved via the world wide web at http://www.erlang.org/. -# -# Software distributed under the License is distributed on an "AS IS" -# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -# the License for the specific language governing rights and limitations -# under the License. -# -# The Initial Developer of the Original Code is Ericsson Utvecklings AB. -# Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings -# AB. All Rights Reserved.'' -# -# $Id: otp_subdir.mk,v 1.5 2004/07/12 15:12:23 jeinhorn Exp $ -# -# -# Make include file for otp - -.PHONY: debug opt release docs release_docs tests release_tests \ - clean depend - -# -# Targets that don't affect documentation directories -# -debug opt release docs release_docs tests release_tests clean depend: prepare - @set -e ; \ - app_pwd=`pwd` ; \ - if test -f vsn.mk; then \ - echo "=== Entering application" `basename $$app_pwd` ; \ - fi ; \ - case "$(MAKE)" in *clearmake*) tflag="-T";; *) tflag="";; esac; \ - short_circuit=0 ; \ - for d in $(SUB_DIRECTORIES); do \ - if [[ $$short_circuit = 0 ]]; then \ - if test -f $$d/SKIP ; then \ - echo "=== Skipping subdir $$d, reason:" ; \ - cat $$d/SKIP ; \ - echo "===" ; \ - else \ - if test ! -d $$d ; then \ - echo "=== Skipping subdir $$d, it is missing" ; \ - else \ - xflag="" ; \ - if test -f $$d/ignore_config_record.inf; then \ - xflag=$$tflag ; \ - fi ; \ - (cd $$d && $(MAKE) $$xflag $@) ; \ - if [[ $$? != 0 ]]; then \ - short_circuit=1 ; \ - fi ; \ - fi ; \ - fi ; \ - fi ; \ - done ; \ - if test -f vsn.mk; then \ - echo "=== Leaving application" `basename $$app_pwd` ; \ - fi ; \ - exit $$short_circuit - -prepare: - echo diff --git a/lib/erl/build/raw_test.mk b/lib/erl/build/raw_test.mk deleted file mode 100644 index bf8535d1..00000000 --- a/lib/erl/build/raw_test.mk +++ /dev/null @@ -1,29 +0,0 @@ -# for testing erlang files directly. The set up for a -# this type of test would be -# files to test reside in lib//src and the test files which are -# just plain erlang code reside in lib//test -# -# This color codes emitted while the tests run assume that you are using -# a white-on-black display schema. If not, e.g. if you use a white -# background, you will not be able to read the "WHITE" text. -# You can override this by supplying your own "white" color, -# which may in fact be black! You do this by defining an environment -# variable named "MY_WHITE" and setting it to $'\e[0;30m' (which is -# simply bash's way of specifying "Escape [ 0 ; 3 0 m"). -# Similarly, you can set your versions of the standard colors -# found in colors.mk. - -test: - @TEST_MODULES=`ls *_test.erl`; \ - trap "echo $(OFF)$(NO_COLOR); exit 1;" 1 2 3 6; \ - for d in $$TEST_MODULES; do \ - echo $${MY_GREEN:-$(GREEN)}"Testing File $$d" $${MY_WHITE:-$(WHITE)}; \ - echo -n $${MY_BLUE:-$(BLUE)}; \ - erl -name $(APP_NAME) $(TEST_LIBS) \ - -s `basename $$d .erl` all -s init stop -noshell; \ - if [ $$? -ne 0 ]; then \ - echo $${MY_LRED:-$(LRED)}"$$d Test Failed"; \ - fi; \ - echo -n $(OFF)$(NO_COLOR); \ - done - diff --git a/lib/erl/include/oop.hrl b/lib/erl/include/oop.hrl deleted file mode 100644 index 66d1a0c8..00000000 --- a/lib/erl/include/oop.hrl +++ /dev/null @@ -1,25 +0,0 @@ -%%% 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(CLASS(Obj), element(1, Obj)). - --define(DEFINE_ATTR(Attr), attr(This, get, Attr, _Value) -> This#?MODULE.Attr; - attr(This, set, Attr, Value) -> This#?MODULE{Attr=Value} -). - -%%% static: use only if you're sure This is class ?MODULE and not a super/subclass --define(ATTR(Attr), This#?MODULE.Attr). - -%%% convenience for implementing inspect/1 -%%% e.g. -> "foo=5" --define(FORMAT_ATTR(Attr), - io_lib:write_atom(Attr) ++ "=" ++ io_lib:print(?ATTR(Attr)) -). - --define(ATTR_DUMMY, - attr(dummy, dummy, dummy, dummy) -> - exit(dummy_attr_used) -). diff --git a/lib/erl/include/protocol/tBinaryProtocol.hrl b/lib/erl/include/protocol/tBinaryProtocol.hrl deleted file mode 100644 index dea2e29c..00000000 --- a/lib/erl/include/protocol/tBinaryProtocol.hrl +++ /dev/null @@ -1,10 +0,0 @@ -%%% 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(VERSION_MASK, 16#FFFF0000). --define(VERSION_1, 16#80010000). - --record(tBinaryProtocol, {super}). diff --git a/lib/erl/include/protocol/tBinaryProtocolFactory.hrl b/lib/erl/include/protocol/tBinaryProtocolFactory.hrl deleted file mode 100644 index cf8c92b0..00000000 --- a/lib/erl/include/protocol/tBinaryProtocolFactory.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tBinaryProtocolFactory, {super}). diff --git a/lib/erl/include/protocol/tProtocol.hrl b/lib/erl/include/protocol/tProtocol.hrl deleted file mode 100644 index d393f352..00000000 --- a/lib/erl/include/protocol/tProtocol.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tProtocol, {trans}). diff --git a/lib/erl/include/protocol/tProtocolException.hrl b/lib/erl/include/protocol/tProtocolException.hrl deleted file mode 100644 index 9d2f31af..00000000 --- a/lib/erl/include/protocol/tProtocolException.hrl +++ /dev/null @@ -1,15 +0,0 @@ -%%% 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(tProtocolException_UNKNOWN, 0). --define(tProtocolException_INVALID_DATA, 1). --define(tProtocolException_NEGATIVE_SIZE, 2). --define(tProtocolException_SIZE_LIMIT, 3). --define(tProtocolException_BAD_VERSION, 4). - --record(tProtocolException, {super}). - - diff --git a/lib/erl/include/protocol/tProtocolFactory.hrl b/lib/erl/include/protocol/tProtocolFactory.hrl deleted file mode 100644 index 6335dd96..00000000 --- a/lib/erl/include/protocol/tProtocolFactory.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tProtocolFactory, {}). diff --git a/lib/erl/include/server/tErlServer.hrl b/lib/erl/include/server/tErlServer.hrl deleted file mode 100644 index b60df710..00000000 --- a/lib/erl/include/server/tErlServer.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tErlServer, {super, acceptor, listenSocket, port}). diff --git a/lib/erl/include/server/tServer.hrl b/lib/erl/include/server/tServer.hrl deleted file mode 100644 index 9488438a..00000000 --- a/lib/erl/include/server/tServer.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tServer, {handler, processor, serverTransport, transportFactory, protocolFactory}). diff --git a/lib/erl/include/server/tSimpleServer.hrl b/lib/erl/include/server/tSimpleServer.hrl deleted file mode 100644 index e6d257d3..00000000 --- a/lib/erl/include/server/tSimpleServer.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tSimpleServer, {super}). diff --git a/lib/erl/include/tApplicationException.hrl b/lib/erl/include/tApplicationException.hrl deleted file mode 100644 index 5e2b515c..00000000 --- a/lib/erl/include/tApplicationException.hrl +++ /dev/null @@ -1,16 +0,0 @@ -%%% 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/ - -% TApplicationException --define(tApplicationException_UNKNOWN, 0). --define(tApplicationException_UNKNOWN_METHOD, 1). --define(tApplicationException_INVALID_MESSAGE_TYPE, 2). --define(tApplicationException_WRONG_METHOD_NAME, 3). --define(tApplicationException_BAD_SEQUENCE_ID, 4). --define(tApplicationException_MISSING_RESULT, 5). --define(tApplicationException_HANDLER_ERROR, 6). - --record(tApplicationException, {super}). diff --git a/lib/erl/include/tErlProcessor.hrl b/lib/erl/include/tErlProcessor.hrl deleted file mode 100644 index 65e5cd07..00000000 --- a/lib/erl/include/tErlProcessor.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tErlProcessor, {super, generatedProcessor, handler}). diff --git a/lib/erl/include/tException.hrl b/lib/erl/include/tException.hrl deleted file mode 100644 index 896e8cb3..00000000 --- a/lib/erl/include/tException.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tException, {message, type, backtrace}). diff --git a/lib/erl/include/tProcessor.hrl b/lib/erl/include/tProcessor.hrl deleted file mode 100644 index 18833975..00000000 --- a/lib/erl/include/tProcessor.hrl +++ /dev/null @@ -1,8 +0,0 @@ -%%% 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/ - --record(tProcessor, {}). - diff --git a/lib/erl/include/thrift.hrl b/lib/erl/include/thrift.hrl deleted file mode 100644 index 4bc994ed..00000000 --- a/lib/erl/include/thrift.hrl +++ /dev/null @@ -1,14 +0,0 @@ -%%% 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(ERROR(F, D), - error_logger:format(F, D)). - --define(INFO(F, D), - error_logger:info_msg(F, D)). - --include("thrift_macros.hrl"). --include("thrift_constants.hrl"). diff --git a/lib/erl/include/thrift_constants.hrl b/lib/erl/include/thrift_constants.hrl deleted file mode 100644 index 19480610..00000000 --- a/lib/erl/include/thrift_constants.hrl +++ /dev/null @@ -1,25 +0,0 @@ -%%% 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 deleted file mode 100644 index a1a6bad0..00000000 --- a/lib/erl/include/thrift_macros.hrl +++ /dev/null @@ -1,54 +0,0 @@ -%%% 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/include/transport/tBufferedTransport.hrl b/lib/erl/include/transport/tBufferedTransport.hrl deleted file mode 100644 index 0aa1a914..00000000 --- a/lib/erl/include/transport/tBufferedTransport.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tBufferedTransport, {super, transport, wbuf}). diff --git a/lib/erl/include/transport/tBufferedTransportFactory.hrl b/lib/erl/include/transport/tBufferedTransportFactory.hrl deleted file mode 100644 index 69081b4f..00000000 --- a/lib/erl/include/transport/tBufferedTransportFactory.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tBufferedTransportFactory, {super}). diff --git a/lib/erl/include/transport/tErlAcceptor.hrl b/lib/erl/include/transport/tErlAcceptor.hrl deleted file mode 100644 index 43babb53..00000000 --- a/lib/erl/include/transport/tErlAcceptor.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tErlAcceptor, {super, serverPid, transportFactory, protocolFactory}). diff --git a/lib/erl/include/transport/tServerSocket.hrl b/lib/erl/include/transport/tServerSocket.hrl deleted file mode 100644 index 2f85b8ac..00000000 --- a/lib/erl/include/transport/tServerSocket.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tServerSocket, {super, port, handle}). diff --git a/lib/erl/include/transport/tServerTransport.hrl b/lib/erl/include/transport/tServerTransport.hrl deleted file mode 100644 index ccb75e49..00000000 --- a/lib/erl/include/transport/tServerTransport.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tServerTransport, {}). diff --git a/lib/erl/include/transport/tSocket.hrl b/lib/erl/include/transport/tSocket.hrl deleted file mode 100644 index 95d8d875..00000000 --- a/lib/erl/include/transport/tSocket.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tSocket, {super, host, port, handle}). diff --git a/lib/erl/include/transport/tTransport.hrl b/lib/erl/include/transport/tTransport.hrl deleted file mode 100644 index 8d742898..00000000 --- a/lib/erl/include/transport/tTransport.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tTransport, {}). diff --git a/lib/erl/include/transport/tTransportException.hrl b/lib/erl/include/transport/tTransportException.hrl deleted file mode 100644 index 0fcc99fc..00000000 --- a/lib/erl/include/transport/tTransportException.hrl +++ /dev/null @@ -1,13 +0,0 @@ -%%% 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(tTransportException_UNKNOWN, 0). --define(tTransportException_NOT_OPEN, 1). --define(tTransportException_ALREADY_OPEN, 2). --define(tTransportException_TIMED_OUT, 3). --define(tTransportException_END_OF_FILE, 4). - --record(tTransportException, {super}). diff --git a/lib/erl/include/transport/tTransportFactory.hrl b/lib/erl/include/transport/tTransportFactory.hrl deleted file mode 100644 index 05aa8203..00000000 --- a/lib/erl/include/transport/tTransportFactory.hrl +++ /dev/null @@ -1,7 +0,0 @@ -%%% 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/ - --record(tTransportFactory, {}). diff --git a/lib/erl/src/Makefile b/lib/erl/src/Makefile deleted file mode 100644 index 32db9c40..00000000 --- a/lib/erl/src/Makefile +++ /dev/null @@ -1,117 +0,0 @@ -# $Id: Makefile,v 1.3 2004/08/13 16:35:59 mlogan Exp $ -# -include ../build/otp.mk -include ../build/colors.mk -include ../build/buildtargets.mk - -# ---------------------------------------------------- -# Application version -# ---------------------------------------------------- - -include ../vsn.mk -APP_NAME=thrift -PFX=thrift -VSN=$(THRIFT_VSN) - -# ---------------------------------------------------- -# Install directory specification -# WARNING: INSTALL_DIR the command to install a directory. -# INSTALL_DST is the target directory -# ---------------------------------------------------- -INSTALL_DST = $(ERLANG_OTP)/lib/$(APP_NAME)-$(VSN) - -# ---------------------------------------------------- -# Target Specs -# ---------------------------------------------------- - - -MODULES = $(shell find . -name \*.erl | sed s:^\\./:: | sed s/\\.erl//) -MODULES_STRING_LIST = $(shell find . -name \*.erl | sed s:^\\./:\": | sed s/\\.erl/\",/) - -HRL_FILES= -INTERNAL_HRL_FILES= $(APP_NAME).hrl -ERL_FILES= $(MODULES:%=%.erl) -DOC_FILES=$(ERL_FILES) - -APP_FILE= $(APP_NAME).app -APPUP_FILE= $(APP_NAME).appup - -APP_SRC= $(APP_FILE).src -APPUP_SRC= $(APPUP_FILE).src - -APP_TARGET= $(EBIN)/$(APP_FILE) -APPUP_TARGET= $(EBIN)/$(APPUP_FILE) - -BEAMS= $(MODULES:%=$(EBIN)/%.$(EMULATOR)) -TARGET_FILES= $(BEAMS) $(APP_TARGET) $(APPUP_TARGET) - -WEB_TARGET=/var/yaws/www/$(APP_NAME) - -# ---------------------------------------------------- -# FLAGS -# ---------------------------------------------------- - -ERL_FLAGS += -ERL_INCLUDE = -I../include -I../../fslib/include -I../../system_status/include -ERL_COMPILE_FLAGS += $(ERL_INCLUDE) - -# ---------------------------------------------------- -# Targets -# ---------------------------------------------------- - -all debug opt: $(EBIN) $(TARGET_FILES) - -#$(EBIN)/rm_logger.beam: $(APP_NAME).hrl -include ../build/docs.mk - -# Note: In the open-source build clean must not destroy the preloaded -# beam files. -clean: - rm -f $(TARGET_FILES) - rm -f *~ - rm -f core - rm -rf $(EBIN) - rm -rf *html - -$(EBIN): - mkdir $(EBIN) - -dialyzer: $(TARGET_FILES) - dialyzer --src -r . $(ERL_INCLUDE) - -# ---------------------------------------------------- -# Special Build Targets -# ---------------------------------------------------- - -$(APP_TARGET): $(APP_SRC) ../vsn.mk $(BEAMS) - sed -e 's;%VSN%;$(VSN);' \ - -e 's;%PFX%;$(PFX);' \ - -e 's;%APP_NAME%;$(APP_NAME);' \ - -e 's;%MODULES%;%MODULES%$(MODULES_STRING_LIST);' \ - $< > $<".tmp" - sed -e 's/%MODULES%\(.*\),/\1/' \ - $<".tmp" > $@ - rm $<".tmp" - - -$(APPUP_TARGET): $(APPUP_SRC) ../vsn.mk - sed -e 's;%VSN%;$(VSN);' $< > $@ - -$(WEB_TARGET): ../markup/* - rm -rf $(WEB_TARGET) - mkdir $(WEB_TARGET) - cp -r ../markup/ $(WEB_TARGET) - cp -r ../skins/ $(WEB_TARGET) - -# ---------------------------------------------------- -# Install Target -# ---------------------------------------------------- - -install: all $(WEB_TARGET) -# $(INSTALL_DIR) $(INSTALL_DST)/src -# $(INSTALL_DATA) $(ERL_FILES) $(INSTALL_DST)/src -# $(INSTALL_DATA) $(INTERNAL_HRL_FILES) $(INSTALL_DST)/src -# $(INSTALL_DIR) $(INSTALL_DST)/include -# $(INSTALL_DATA) $(HRL_FILES) $(INSTALL_DST)/include -# $(INSTALL_DIR) $(INSTALL_DST)/ebin -# $(INSTALL_DATA) $(TARGET_FILES) $(INSTALL_DST)/ebin diff --git a/lib/erl/src/oop.erl b/lib/erl/src/oop.erl deleted file mode 100644 index 418f0f28..00000000 --- a/lib/erl/src/oop.erl +++ /dev/null @@ -1,261 +0,0 @@ -%%% 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/ - -%%% -%%% dox: -%%% -%%% C++ <-> Erlang -%%% classes modules -%%% class b : public a a:super() -> b. -%%% - --module(oop). - --export([start_new/2, get/2, set/3, call/2, call/3, inspect/1, class/1, is_object/1, is_a/2]). --export([call1/3]). %% only for thrift_oop_server ... don't use it --export([behaviour_info/1]). - --include("thrift.hrl"). --include("oop.hrl"). - -%% state for the call loop --record(cstate, { - obj, %% the current object (on which we want to invoke MFA) - module, %% the current module we're considering - func, %% the method name (i.e. the function we're trying to invoke in Module) - args, %% the arguments, the first of which is Obj - tried, %% a (backwards) list of modules we've tried - first_obj %% the original object - }). - -%%% -%%% behavior definition -%%% - -behaviour_info(callbacks) -> - [ {attr, 4}, - {super, 0} - ]; -behaviour_info(_) -> - undefined. - -%%% -%%% public interface -%%% - -%% TODO: voids take only ok as return? -start_new(none=Resv, _) -> - ?ERROR("can't instantiate ~p: class name is a reserved word", [Resv]), - error; -start_new(Class, Args) -> - {ok, Pid} = gen_server:start_link(thrift_oop_server, {Class, Args}, []), - Pid. - -%% get(Obj, Field) -> term() -%% looks up Field in Obj or its ancestor objects -get(Obj, Field) -> - call(Obj, attr, [get, Field, get]). - -set(Obj, Field, Value) -> %% TODO: could be tail-recursive - Module = ?CLASS(Obj), - case apply_if_defined(Module, attr, [Obj, set, Field, Value]) of - {ok, V} -> V; - undef -> - case get_superobject(Obj) of - {ok, Superobj} -> - Superobj1 = set(Superobj, Field, Value), - Module:attr(Obj, set, super, Superobj1); - undef -> - error(missing_attr_set, Field, Obj) - end - end. - -%% -%% ** dynamic method dispatch ** -%% -%% calls Module:Func(*Args) if it exists -%% if not, Module <- Module:super() and try again recursively -%% -%% Module:attr(*Args) is handled specially: -%% Obj needs to be replaced with Obj's "superobject" -%% -call(Obj, Func) -> - call(Obj, Func, []). - -call(Obj, Func, ArgsProper) -> - %% this is WAY too expensive - %% ?INFO("oop:call called: Obj=~p Func=~p ArgsProper=~p", [inspect(Obj), Func, ArgsProper]), - case call1(Obj, Func, ArgsProper) of - {ok, Value} -> Value; - {error, Kind, S1} -> error(Kind, S1) - end. - -call1(Obj, Func, ArgsProper) -> - S = #cstate{ - obj = Obj, - module = ?CLASS(Obj), - func = Func, - args = [Obj|ArgsProper], %% prepend This to args - tried = [], - first_obj = Obj - }, - call1(S). - -call1(S = #cstate{obj=Obj, module=Module, func=Func, args=Args}) -> - %% ?INFO("call1~n obj=~p~n MFA=~p, ~p, ~p", [inspect(Obj), Module, Func, Args]), - %% io:format("call ~p~n", [Module]), - case apply_if_defined(Module, Func, Args) of - {ok, Value} -> {ok, Value}; - undef -> call1_try_super(S) - end. - -call1_try_super(S = #cstate{func=attr, module=Module, tried=Tried}) -> - case Module:super() of - none -> {error, missing_attr, S}; - Superclass -> call1_try_super_attr(Superclass, S) - end; -call1_try_super(S = #cstate{func=Func, module=Module, tried=Tried}) -> - case Module:super() of - none -> {error, missing_method, S}; - Superclass -> - S1 = S#cstate{ - module = Superclass, - tried = [Module|Tried] - }, - call1(S1) - end. - -call1_try_super_attr(Superclass, S = #cstate{obj=Obj, module=Module, args=Args, tried=Tried}) -> - %% look for attrs in the "super object" - case get_superobject(Obj) of - undef -> {error, missing_superobj, S}; - {ok, Superobj} when Module == ?CLASS(Obj) -> - %% replace This with Superobj - S1 = S#cstate{ - obj = Superobj, - args = [Superobj|tl(Args)], - module = Superclass, - tried = [Module|Tried] - }, - call1(S1) - end. - -%% careful: not robust against records beginning with a class name -%% (note: we can't just guard with is_record(?CLASS(Obj), Obj) since we -%% can't/really really shouldn't require all record definitions in this file -inspect(Obj) -> - try - case is_object(Obj) of - true -> - DeepList = inspect1(Obj, "#<"), - lists:flatten(DeepList); - false -> - thrift_utils:sformat("~p", [Obj]) - end - catch - _:E -> - thrift_utils:sformat("INSPECT_ERROR(~p) ~p", [E, Obj]) - - %% TODO(cpiro): bring this back once we're done testing: - %% _:E -> thrift_utils:sformat("~p", [Obj]) - end. - -inspect1(Obj, Str) -> - Class = ?CLASS(Obj), - Inspect = Class:inspect(Obj), - Current = atom_to_list(Class) ++ ": " ++ Inspect, - - case get_superobject(Obj) of - {ok, Superobj} -> - inspect1(Superobj, Str ++ Current ++ " | "); - undef -> - Str ++ Current ++ ">" - end. - -%% class(Obj) -> atom() = Class -%% | none -class(Obj) when is_tuple(Obj) -> - %% if it's an object its first element will be a class name, and it'll have super/0 - case apply_if_defined(?CLASS(Obj), super, []) of - {ok, _} -> ?CLASS(Obj); - undef -> none - end; -class(_) -> none. - -%% is_a relationship -is_a(Obj, Class) -> - %% ?INFO("is_a ~p ~p", [Obj, Class]), - case is_object(Obj) of - true -> - is_a1(Obj, Class); - false -> - false - end. -is_a1(Obj, Class) when Class == ?CLASS(Obj) -> - true; -is_a1(Obj, Class) -> - case get_superobject(Obj) of - undef -> - false; - {ok, SuperObj} -> - is_a1(SuperObj, Class) - end. - -%% is the tuple/record an object? -%% is_object(Obj) = bool() -is_object(Obj) when is_tuple(Obj) -> - case class(Obj) of - none -> false; - _ -> true - end; -is_object(_) -> false. - -%%% -%%% private helpers -%%% - -%% apply_if_defined(MFA) -> {ok, apply(MFA)} -%% | undef -%% this could be worth some money -apply_if_defined(M, F, A) -> - apply_if_defined({M,F,A}). - -apply_if_defined({M,F,A} = MFA) -> - try - %% io:format("apply ~p ~p ~p~n", [M,F,A]), - {ok, apply(M, F, A)} - catch - _:Kind when Kind == undef; Kind == function_clause -> - case erlang:get_stacktrace() of - %% the first stack call should match MFA when `apply' fails because the function is undefined - %% they won't match if the function is currently running and an error happens in the middle - [MFA|_] -> undef; % trapped successfully - ST -> - io:format("DONIT THE EXIT THING ~p~n", [Kind]), - exit({Kind, ST}) % some unrelated error, re-exit - end - end. - -get_superobject(Obj) -> - apply_if_defined(?CLASS(Obj), attr, [Obj, get, super, get]). - -%%% -%%% errors -%%% - -tried(S = #cstate{module=Module, tried=Tried}) -> - lists:reverse([Module|Tried]). - -error(missing_superobj, S = #cstate{obj=Obj}) -> - exit({missing_superobj, {inspect(Obj), tried(S)}}); -error(missing_method, S = #cstate{obj=Obj, func=Func, args=Args}) -> - exit({missing_method, {Func, inspect(Obj), tl(Args), tried(S)}}); -error(missing_attr, S = #cstate{args=Args, first_obj=FirstObj}) -> - exit({missing_attr, {hd(tl(Args)), inspect(FirstObj), tried(S)}}). - -error(missing_attr_set, Field, Obj) -> - BT = "..", %% TODO: give a backtrace - exit({missing_attr, {Field, inspect(Obj), BT}}). diff --git a/lib/erl/src/protocol/tBinaryProtocol.erl b/lib/erl/src/protocol/tBinaryProtocol.erl deleted file mode 100644 index 2155be65..00000000 --- a/lib/erl/src/protocol/tBinaryProtocol.erl +++ /dev/null @@ -1,218 +0,0 @@ -%%% 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(tBinaryProtocol). - --include("oop.hrl"). - --include("thrift.hrl"). --include("protocol/tProtocolException.hrl"). --include("protocol/tBinaryProtocol.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([ - new/1, - - writeMessageBegin/4, - writeFieldBegin/4, writeFieldStop/1, - writeMapBegin/4, - writeListBegin/3, - writeSetBegin/3, - - writeBool/2, writeByte/2, writeI16/2, writeI32/2, - writeI64/2, writeDouble/2, writeString/2, - - readMessageBegin/1, - readFieldBegin/1, - readMapBegin/1, - readListBegin/1, - readSetBegin/1, - - readBool/1, readByte/1, readI16/1, readI32/1, - readI64/1, readDouble/1, readString/1 -]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(super). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tProtocol. - -%%% inspect(This) -> string() - -inspect(_This) -> - "". - -%%% -%%% class methods -%%% - -new(Trans) -> - Super = (super()):new(Trans), - #?MODULE{super=Super}. - -%%% -%%% instance methods -%%% - -writeMessageBegin(This, Name, Type, Seqid) -> - ?L1(writeI32, ?VERSION_1 bor Type), - ?L1(writeString, Name), - ?L1(writeI32, Seqid), - ok. - -writeFieldBegin(This, _Name, Type, Id) -> - ?L1(writeByte, Type), - ?L1(writeI16, Id), - ok. - -writeFieldStop(This) -> - ?L1(writeByte, ?tType_STOP), - ok. - -writeMapBegin(This, Ktype, Vtype, Size) -> - ?L1(writeByte, Ktype), - ?L1(writeByte, Vtype), - ?L1(writeI32, Size), - ok. - -writeListBegin(This, Etype, Size) -> - ?L1(writeByte, Etype), - ?L1(writeI32, Size), - ok. - -writeSetBegin(This, Etype, Size) -> - ?L1(writeByte, Etype), - ?L1(writeI32, Size), - ok. - -% - -writeBool(This, true) -> - ?L1(writeByte, 1); -writeBool(This, false) -> - ?L1(writeByte, 0). - -writeByte(This, Byte) when is_integer(Byte) -> - Trans = oop:get(This, trans), - ?R1(Trans, effectful_write, <>). - -writeI16(This, I16) when is_integer(I16) -> - Trans = oop:get(This, trans), - ?R1(Trans, effectful_write, <>). - -writeI32(This, I32) when is_integer(I32) -> - Trans = oop:get(This, trans), - ?R1(Trans, effectful_write, <>). - -writeI64(This, I64) when is_integer(I64) -> - Trans = oop:get(This, trans), - ?R1(Trans, effectful_write, <>). - -writeDouble(This, Double) when is_float(Double) -> - Trans = oop:get(This, trans), - ?R1(Trans, effectful_write, <>). - -writeString(This, Str) when is_list(Str) -> % [char()] or iolist() - Trans = oop:get(This, trans), - Data = list_to_binary(Str), - ?L1(writeI32, size(Data)), - ?R1(Trans, effectful_write, Data); - -writeString(This, Binary) when is_binary(Binary) -> - Trans = oop:get(This, trans), - ?L1(writeI32, size(Binary)), - ?R1(Trans, effectful_write, Binary). - -%% - -readMessageBegin(This) -> - Version = ?L0(readI32), - if - (Version band ?VERSION_MASK) /= ?VERSION_1 -> - tException:throw(tProtocolException, [?tProtocolException_BAD_VERSION, "Missing version identifier"]); - true -> ok - end, - Type = Version band 16#000000ff, - Name = ?L0(readString), - Seqid = ?L0(readI32), - { Name, Type, Seqid }. - -readFieldBegin(This) -> - Type = ?L0(readByte), - case Type of - ?tType_STOP -> - { nil, Type, 0 }; % WATCH - _ -> - Id = ?L0(readI16), - { nil, Type, Id } - end. - -readMapBegin(This) -> - Ktype = ?L0(readByte), - Vtype = ?L0(readByte), - Size = ?L0(readI32), - { Ktype, Vtype, Size }. - -readListBegin(This) -> - Etype = ?L0(readByte), - Size = ?L0(readI32), - { Etype, Size }. - -readSetBegin(This) -> - Etype = ?L0(readByte), - Size = ?L0(readI32), - { Etype, Size }. - -%% - -readBool(This) -> - Byte = ?L0(readByte), - (Byte /= 0). - -readByte(This) -> - Trans = oop:get(This, trans), - <> = ?R1(Trans, readAll, 1), - Val. - -readI16(This) -> - Trans = oop:get(This, trans), - <> = ?R1(Trans, readAll, 2), - Val. - -readI32(This) -> - Trans = oop:get(This, trans), - <> = ?R1(Trans, readAll, 4), - Val. - -readI64(This) -> - Trans = oop:get(This, trans), - <> = ?R1(Trans, readAll, 8), - Val. - -readDouble(This) -> - Trans = oop:get(This, trans), - <> = ?R1(Trans, readAll, 8), - Val. - -readString(This) -> - Trans = oop:get(This, trans), - Sz = ?L0(readI32), - binary_to_list(?R1(Trans, readAll, Sz)). diff --git a/lib/erl/src/protocol/tBinaryProtocolFactory.erl b/lib/erl/src/protocol/tBinaryProtocolFactory.erl deleted file mode 100644 index c525cdb0..00000000 --- a/lib/erl/src/protocol/tBinaryProtocolFactory.erl +++ /dev/null @@ -1,57 +0,0 @@ -%%% 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(tBinaryProtocolFactory). - --include("oop.hrl"). - --include("thrift.hrl"). --include("protocol/tBinaryProtocol.hrl"). --include("protocol/tBinaryProtocolFactory.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/0, getProtocol/2]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(super). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tProtocolFactory. - -%%% inspect(This) -> string() - -inspect(_This) -> - "". - -%%% -%%% class methods -%%% - -new() -> - Super = (super()):new(), - #?MODULE{super=Super}. - -%%% -%%% instance methods -%%% - -getProtocol(_This, Trans) -> - oop:start_new(tBinaryProtocol, [Trans]). - diff --git a/lib/erl/src/protocol/tProtocol.erl b/lib/erl/src/protocol/tProtocol.erl deleted file mode 100644 index 4ef67b80..00000000 --- a/lib/erl/src/protocol/tProtocol.erl +++ /dev/null @@ -1,175 +0,0 @@ -%%% 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(tProtocol). - --include("oop.hrl"). - --include("thrift.hrl"). --include("protocol/tProtocol.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([ - new/1, - skip/2, - - writeMessageBegin/4, writeMessageEnd/1, - writeStructBegin/2, writeStructEnd/1, - writeFieldBegin/4, writeFieldEnd/1, writeFieldStop/1, - writeMapBegin/4, writeMapEnd/1, - writeListBegin/3, writeListEnd/1, - writeSetBegin/3, writeSetEnd/1, - - writeBool/2, writeByte/2, writeI16/2, writeI32/2, - writeI64/2, writeDouble/2, writeString/2, - - readMessageBegin/1, readMessageEnd/1, - readStructBegin/1, readStructEnd/1, - readFieldBegin/1, readFieldEnd/1, - readMapBegin/1, readMapEnd/1, - readListBegin/1, readListEnd/1, - readSetBegin/1, readSetEnd/1, - - readBool/1, readByte/1, readI16/1, readI32/1, - readI64/1, readDouble/1, readString/1 - ]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(trans). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - none. - -%%% inspect(This) -> string() - -inspect(This) -> - ?FORMAT_ATTR(trans). - -%%% -%%% class methods -%%% - -new(Trans) -> - #?MODULE{trans=Trans}. - -%%% -%%% instance methods -%%% - -writeMessageBegin(_This, _Name, _Type, _Seqid) -> ok. -writeMessageEnd(_This) -> ok. -writeStructBegin(_This, _Name) -> ok. -writeStructEnd(_This) -> ok. -writeFieldBegin(_This, _Name, _Type, _Id) -> ok. -writeFieldEnd(_This) -> ok. -writeFieldStop(_This) -> ok. -writeMapBegin(_This, _Ktype, _Vtype, _Size) -> ok. -writeMapEnd(_This) -> ok. -writeListBegin(_This, _Etype, _Size) -> ok. -writeListEnd(_This) -> ok. -writeSetBegin(_This, _Etype, _Size) -> ok. -writeSetEnd(_This) -> ok. - -writeBool(_This, _Value) -> ok. -writeByte(_This, _Value) -> ok. -writeI16(_This, _Value) -> ok. -writeI32(_This, _Value) -> ok. -writeI64(_This, _Value) -> ok. -writeDouble(_This, _Value) -> ok. -writeString(_This, _Value) -> ok. - -readMessageBegin(_This) -> ok. -readMessageEnd(_This) -> ok. -readStructBegin(_This) -> ok. -readStructEnd(_This) -> ok. -readFieldBegin(_This) -> ok. -readFieldEnd(_This) -> ok. -readMapBegin(_This) -> ok. -readMapEnd(_This) -> ok. -readListBegin(_This) -> ok. -readListEnd(_This) -> ok. -readSetBegin(_This) -> ok. -readSetEnd(_This) -> ok. - -readBool(_This) -> ok. -readByte(_This) -> ok. -readI16(_This) -> ok. -readI32(_This) -> ok. -readI64(_This) -> ok. -readDouble(_This) -> ok. -readString(_This) -> ok. - -skip(This, Type) -> - case Type of - ?tType_STOP -> nil; % WATCH - ?tType_BOOL -> ?L0(readBool); - ?tType_BYTE -> ?L0(readByte); - ?tType_I16 -> ?L0(readI16); - ?tType_I32 -> ?L0(readI32); - ?tType_I64 -> ?L0(readI64); - ?tType_DOUBLE -> ?L0(readDouble); - ?tType_STRING -> ?L0(readString); - - ?tType_STRUCT -> - ?L0(readStructBegin), - skip_struct_loop(This), - - %% cpiro: this isn't here in the original tprotocol.rb, but i think it's a bug - ?L0(readStructEnd); - - ?tType_MAP -> - {Ktype, Vtype, Size} = ?L0(readMapBegin), - skip_map_repeat(This, Ktype, Vtype, Size), - ?L0(readMapEnd); - - ?tType_SET -> - {Etype, Size} = ?L0(readSetBegin), - skip_set_repeat(This, Etype, Size), - ?L0(readSetEnd); - - ?tType_LIST -> - {Etype, Size} = ?L0(readListBegin), - skip_set_repeat(This, Etype, Size), % [sic] skipping same as for SET - ?L0(readListEnd) - end. - -skip_struct_loop(This) -> - { _Name, Type, _Id } = ?L0(readFieldBegin), - if - Type == ?tType_STOP -> - ok; - - true -> - ?L1(skip, Type), - ?L0(readFieldEnd), - - %% cpiro: this is here in original tprotocol.rb, but i think it's a bug - %% ?L0(readStructEnd), - skip_struct_loop(This) - end. - -skip_map_repeat(This, Ktype, Vtype, Times) -> - ?L1(skip, Ktype), - ?L1(skip, Vtype), - skip_map_repeat(This, Ktype, Vtype, Times-1). - -skip_set_repeat(This, Etype, Times) -> - ?L1(skip, Etype), - skip_set_repeat(This, Etype, Times-1). diff --git a/lib/erl/src/protocol/tProtocolException.erl b/lib/erl/src/protocol/tProtocolException.erl deleted file mode 100644 index 84833a82..00000000 --- a/lib/erl/src/protocol/tProtocolException.erl +++ /dev/null @@ -1,57 +0,0 @@ -%%% 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(tProtocolException). - --include("oop.hrl"). - --include("thrift.hrl"). --include("protocol/tProtocolException.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/0, new/1, new/2]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(super). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tException. - -%%% inspect(This) -> string() - -inspect(This) -> - "". - -%%% -%%% class methods -%%% - -new(Type, Message) -> - Super = (super()):new(Type, Message), - #?MODULE{super=Super}. - -new() -> - new(?tProtocolException_UNKNOWN, undefined). -new(Type) -> - new(Type, undefined). - -%%% -%%% instance methods -%%% diff --git a/lib/erl/src/protocol/tProtocolFactory.erl b/lib/erl/src/protocol/tProtocolFactory.erl deleted file mode 100644 index f756a293..00000000 --- a/lib/erl/src/protocol/tProtocolFactory.erl +++ /dev/null @@ -1,54 +0,0 @@ -%%% 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(tProtocolFactory). - --include("oop.hrl"). - --include("thrift.hrl"). --include("protocol/tProtocolFactory.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/0, getProtocol/2]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?ATTR_DUMMY. - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - none. - -%%% inspect(This) -> string() - -inspect(_This) -> - "". - -%%% -%%% class methods -%%% - -new() -> - #?MODULE{}. - -%%% -%%% instance methods -%%% - -getProtocol(This, Trans) -> - nil. diff --git a/lib/erl/src/server/tErlServer.erl b/lib/erl/src/server/tErlServer.erl deleted file mode 100644 index 10ac2b25..00000000 --- a/lib/erl/src/server/tErlServer.erl +++ /dev/null @@ -1,102 +0,0 @@ -%%% 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(tErlServer). - --include("oop.hrl"). - --include("thrift.hrl"). --include("transport/tTransportException.hrl"). --include("server/tErlServer.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/6, new/5, new/4, effectful_serve/1, effectful_new_acceptor/1]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(super); -?DEFINE_ATTR(acceptor); -?DEFINE_ATTR(listenSocket); -?DEFINE_ATTR(port). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tServer. - -%%% inspect(This) -> string() - -inspect(This) -> - ?FORMAT_ATTR(acceptor) ++ ", " ++ - ?FORMAT_ATTR(listenSocket) ++ ", " ++ - ?FORMAT_ATTR(port). - -%%% -%%% class methods -%%% - -new(Port, Handler, Processor, ServerTransport, TransportFactory, ProtocolFactory) -> - Super = (super()):new(Handler, Processor, ServerTransport, TransportFactory, ProtocolFactory), - #?MODULE{super=Super, port=Port, listenSocket=nil, acceptor=nil}. - -new(Port, Handler, Processor, ServerTransport) -> - new(Port, Handler, Processor, ServerTransport, nil, nil). - -new(Port, Handler, Processor, ServerTransport, TransportFactory) -> - new(Port, Handler, Processor, ServerTransport, TransportFactory, nil). - -% listenSocket, acceptor, port - -effectful_serve(This) -> - Port = oop:get(This, port), - - Options = [binary, {packet, 0}, {active, false}], - - %% listen - case gen_tcp:listen(Port, Options) of - {ok, ListenSocket} -> - ?INFO("thrift server listening on port ~p", [Port]), - - This1 = oop:set(This, listenSocket, ListenSocket), - - %% spawn acceptor - {_Acceptor, This2} = effectful_new_acceptor(This1), - - {ok, This2}; - - {error, eaddrinuse} -> - ?ERROR("thrift couldn't bind port ~p, address in use", [Port]), - {{error, eaddrinuse}, This} %% state before the accept - end. - -effectful_new_acceptor(This) -> - ListenSocket = oop:get(This, listenSocket), - Processor = oop:get(This, processor), %% cpiro: generated processor, not the "actual" processor - Handler = oop:get(This, handler), - - TF = oop:get(This, transportFactory), - PF = oop:get(This, protocolFactory), - - tErlAcceptor = oop:get(This, serverTransport), %% cpiro: only supported ServerTransport - - ServerPid = self(), - Acceptor = oop:start_new(tErlAcceptor, [ServerPid, TF, PF]), - ?C3(Acceptor, accept, ListenSocket, Processor, Handler), - - This1 = oop:set(This, acceptor, Acceptor), - - {Acceptor, This1}. diff --git a/lib/erl/src/server/tServer.erl b/lib/erl/src/server/tServer.erl deleted file mode 100644 index fc033310..00000000 --- a/lib/erl/src/server/tServer.erl +++ /dev/null @@ -1,81 +0,0 @@ -%%% 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(tServer). - --include("oop.hrl"). - --include("thrift.hrl"). --include("server/tServer.hrl"). --include("transport/tTransportFactory.hrl"). --include("protocol/tBinaryProtocolFactory.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/5, new/4, new/3, serve/1]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(handler); -?DEFINE_ATTR(processor); -?DEFINE_ATTR(serverTransport); -?DEFINE_ATTR(transportFactory); -?DEFINE_ATTR(protocolFactory). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - none. - -%%% inspect(This) -> string() - -inspect(This) -> - ?FORMAT_ATTR(handler) ++ ", " ++ - ?FORMAT_ATTR(processor) ++ ", " ++ - ?FORMAT_ATTR(serverTransport) ++ ", " ++ - ?FORMAT_ATTR(transportFactory) ++ ", " ++ - ?FORMAT_ATTR(protocolFactory). - -%%% -%%% class methods -%%% - -new(Handler, Processor, ServerTransport, TransportFactory, ProtocolFactory) -> - #?MODULE{handler=Handler, processor=Processor, serverTransport=ServerTransport, - - %% much ado about nothing but - %% subclasses pass nil too - transportFactory = - case TransportFactory of - nil -> tTransportFactory:new(); - _ -> TransportFactory - end, - - protocolFactory = - case ProtocolFactory of - nil -> tBinaryProtocolFactory:new(); - _ -> ProtocolFactory - end -}. - -new(Handler, Processor, ServerTransport) -> - new(Handler, Processor, ServerTransport, nil, nil). - -new(Handler, Processor, ServerTransport, TransportFactory) -> - new(Handler, Processor, ServerTransport, TransportFactory, nil). - -serve(_This) -> - ok. diff --git a/lib/erl/src/server/tSimpleServer.erl b/lib/erl/src/server/tSimpleServer.erl deleted file mode 100644 index 833fe5db..00000000 --- a/lib/erl/src/server/tSimpleServer.erl +++ /dev/null @@ -1,111 +0,0 @@ -%%% 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/ - -%%% NOTE: tSimpleServer's design isn't compatible with our concurrency model. -%%% It won't work in principle, and certainly not in practice. YMMV. - --module(tSimpleServer). - --include("oop.hrl"). - --include("thrift.hrl"). --include("transport/tTransportException.hrl"). --include("server/tSimpleServer.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/5, new/4, new/3, serve/1]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(super). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tServer. - -%%% inspect(This) -> string() - -inspect(_This) -> - "". - -%%% -%%% class methods -%%% - -new(Handler, Processor, ServerTransport, TransportFactory, ProtocolFactory) -> - Super = (super()):new(Handler, Processor, ServerTransport, TransportFactory, ProtocolFactory), - error_logger:warning_msg("tSimpleServer has an incompatable design and doesn't work. Promise."), - #?MODULE{super=Super}. - -new(Handler, Processor, ServerTransport) -> - new(Handler, Processor, ServerTransport, nil, nil). - -new(Handler, Processor, ServerTransport, TransportFactory) -> - new(Handler, Processor, ServerTransport, TransportFactory, nil). - -% - -serve(This) -> - exit(tSimpleServer_doesnt_work), - ST = oop:get(This, serverTransport), - ?R0(ST, effectful_listen), - - serve_loop(This). - -serve_loop(This) -> - error_logger:info_msg("ready.", []), - - ST = oop:get(This, serverTransport), - Client = ?RT0(ST, accept, infinity), - - TF = oop:get(This, transportFactory), - Trans = ?F1(TF, getTransport, Client), %% cpiro: OPAQUE!! Trans = Client - - PF = oop:get(This, protocolFactory), - Prot = ?F1(PF, getProtocol, Trans), %% cpiro: OPAQUE!! Prot = start_new(tBinaryProtocol, [Trans]) - - error_logger:info_msg("client accept()ed", []), - - serve_loop_loop(This, Prot), % giggle loop? - - ?R0(Trans, effectful_close), - - serve_loop(This). - -serve_loop_loop(This, Prot) -> - Next = - try - Handler = oop:get(This, handler), - Processor = oop:get(This, processor), - Val = apply(Processor, process, [Handler, Prot, Prot]), %% TODO(cpiro): make processor a gen_server instance - error_logger:info_msg("request processed: rv=~p", [Val]), - loop - catch - %% TODO(cpiro) case when is_record(...) to pick out our exception - %% records vs. normal erlang throws - E when is_record(E, tTransportException) -> - error_logger:info_msg("tTransportException (normal-ish?)", []), - close; - F -> - error_logger:info_msg("EXCEPTION: ~p", [F]), - close - end, - case Next of - loop -> serve_loop_loop(This, Prot); - close -> ok - end. diff --git a/lib/erl/src/tApplicationException.erl b/lib/erl/src/tApplicationException.erl deleted file mode 100644 index d99b0037..00000000 --- a/lib/erl/src/tApplicationException.erl +++ /dev/null @@ -1,114 +0,0 @@ -%%% 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(tApplicationException). - --include("thrift.hrl"). --include("tApplicationException.hrl"). - --include("oop.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/0, new/1, new/2, read/2, write/2]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(super). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tException. - -%%% inspect(This) -> string() - -inspect(This) -> - "". - -%%% -%%% class methods -%%% - -new(Type, Message) -> - Super = (super()):new(Type, Message), - #?MODULE{super=Super}. - -new() -> new(?tApplicationException_UNKNOWN, undefined). -new(Type) -> new(Type, undefined). - -%%% -%%% instance methods -%%% - -read(This, Iprot) -> - ?R0(Iprot, readStructBegin), - read_while_loop(This, Iprot), - ?R0(Iprot, readStructEnd), - ok. - -read_while_loop(This, Iprot) -> - {_Fname, Ftype, Fid} = ?R0(Iprot, readFieldBegin), - - if - Ftype == ?tType_STOP -> - ok; - - (Fid == 1) and (Ftype == ?tType_STRING) -> - Message1 = ?R0(Iprot, readString), - This1 = oop:set(This, message, Message1), - ?R0(Iprot, readFieldEnd), - read_while_loop(This1, Iprot); - - Fid == 1 -> - ?R0(Iprot, skip), - ?R0(Iprot, readFieldEnd), - read_while_loop(This, Iprot); - - (Fid == 2) and (Ftype == ?tType_I32) -> - Type1 = ?R0(Iprot, readI32), - This1 = oop:set(This, type, Type1), - ?R0(Iprot, readFieldEnd), - read_while_loop(This1, Iprot); - - true -> - ?R0(Iprot, skip), - ?R0(Iprot, readFieldEnd), - read_while_loop(This, Iprot) - end. - -write(This, Oprot) -> - ?R1(Oprot, writeStructBegin, "tApplicationException"), - Message = oop:get(This, message), - Type = oop:get(This, type), - - if Message /= undefined -> - ?R3(Oprot, writeFieldBegin, "message", ?tType_STRING, 1), - ?R1(Oprot, writeString, Message), - ?R0(Oprot, writeFieldEnd); - true -> ok - end, - - if Type /= undefined -> - ?R3(Oprot, writeFieldBegin, "type", ?tType_I32, 2), - ?R1(Oprot, writeI32, Type), - ?R0(Oprot, writeFieldEnd); - true -> ok - end, - - ?R0(Oprot, writeFieldStop), - ?R0(Oprot, writeStructEnd), - ok. diff --git a/lib/erl/src/tErlProcessor.erl b/lib/erl/src/tErlProcessor.erl deleted file mode 100644 index 2e88b6d3..00000000 --- a/lib/erl/src/tErlProcessor.erl +++ /dev/null @@ -1,63 +0,0 @@ -%%% 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(tErlProcessor). - --include("thrift.hrl"). --include("oop.hrl"). --include("tErlProcessor.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/2, process/3]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(super); -?DEFINE_ATTR(generatedProcessor); -?DEFINE_ATTR(handler). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tProcessor. - -%%% inspect(This) -> string() - -inspect(This) -> - ?FORMAT_ATTR(generatedProcessor) ++ ", " ++ - ?FORMAT_ATTR(handler). - -%%% -%%% class methods -%%% - -new(GP, Handler) -> - Super = (super()):new(), - #?MODULE{super = Super, generatedProcessor = GP, handler = Handler}. - -%% processor is generated code -%% handler is user code - -%%% -%%% instance methods -%%% - -process(This, Iprot, Oprot) -> - GP = oop:get(This, generatedProcessor), - Handler = oop:get(This, handler), - - GP:process(Handler, Iprot, Oprot). diff --git a/lib/erl/src/tException.erl b/lib/erl/src/tException.erl deleted file mode 100644 index 6dd30844..00000000 --- a/lib/erl/src/tException.erl +++ /dev/null @@ -1,93 +0,0 @@ -%%% 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(tException). - --include("oop.hrl"). --include("thrift.hrl"). --include("tException.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/2, add_backtrace_element/2, throw/2, inspect_with_backtrace/2, inspect_with_backtrace/3]). - --export([read/1]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(message); -?DEFINE_ATTR(type); -?DEFINE_ATTR(backtrace). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - none. - -%%% inspect(This) -> string() - -inspect(This) -> - BT = ?ATTR(backtrace), - Depth = - if - is_list(BT) -> integer_to_list(length(BT)); - true -> "?" - end, - ?FORMAT_ATTR(message) ++ ", " ++ - ?FORMAT_ATTR(type) ++ ", " - " backtrace:" ++ Depth. - -%%% -%%% class methods -%%% - -new(Type, Message) -> - #?MODULE{type=Type, message=Message, backtrace=[]}. - -add_backtrace_element(E, Info) -> - BT = oop:get(E, backtrace), - E1 = oop:set(E, backtrace, [Info|BT]), - E1. - -throw(Class, Args) -> - E = apply(Class, new, Args), - exit({thrift_exception, E}). - - -inspect_with_backtrace(E, Where, Info) -> - E1 = add_backtrace_element(E, Info), - inspect_with_backtrace(E1, Where). - -inspect_with_backtrace(E, Where) -> - thrift_utils:sformat("** ~s~n** ~s", [Where, oop:inspect(E)]) ++ - case oop:get(E, backtrace) of - [] -> - ""; - BT when is_list(BT) -> - thrift_utils:sformat("~n** trace = ~p", [lists:reverse(BT)]); - Else -> - thrift_utils:sformat("", [Else]) - end. - -read(E) -> - case oop:class(E) of - none -> - none; - Class -> - Type = oop:get(E, type), - BT = oop:get(E, backtrace), - {Class, Type, BT} - end. diff --git a/lib/erl/src/tProcessor.erl b/lib/erl/src/tProcessor.erl deleted file mode 100644 index b62e5ad0..00000000 --- a/lib/erl/src/tProcessor.erl +++ /dev/null @@ -1,50 +0,0 @@ -%%% 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(tProcessor). - --include("oop.hrl"). --include("tProcessor.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/0]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?ATTR_DUMMY. - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - none. - -%%% inspect(This) -> string() - -inspect(_This) -> - "". - -%%% -%%% class methods -%%% - -new() -> - #?MODULE{}. - -%%% -%%% instance methods -%%% - diff --git a/lib/erl/src/thrift.app.src b/lib/erl/src/thrift.app.src deleted file mode 100644 index 79055ca6..00000000 --- a/lib/erl/src/thrift.app.src +++ /dev/null @@ -1,46 +0,0 @@ -%%% -*- mode:erlang -*- -{application, %APP_NAME%, - [ - % A quick description of the application. - {description, "Thrift bindings"}, - - % The version of the applicaton - {vsn, "%VSN%"}, - - % All modules used by the application. - {modules, [ - %MODULES% - ]}, - - % All of the registered names the application uses. This can be ignored. - {registered, []}, - - % Applications that are to be started prior to this one. This can be ignored - % leave it alone unless you understand it well and let the .rel files in - % your release handle this. - {applications, - [ - kernel, - stdlib - ]}, - - % OTP application loader will load, but not start, included apps. Again - % this can be ignored as well. To load but not start an application it - % is easier to include it in the .rel file followed by the atom 'none' - {included_applications, []}, - - % configuration parameters similar to those in the config file specified - % on the command line. can be fetched with gas:get_env - {env, [ - {term_width, 110}, - {force_one_line, false}, - {omit_fmt, ["thrift ~p:new(~s) = ~s"]}, - {gen_server_messages, true}, - {show_pid, true}, - {lookup, false} % DNS - ]}, - - % The Module and Args used to start this application. - {mod, {thrift_app, []}} - ] -}. diff --git a/lib/erl/src/thrift.appup.src b/lib/erl/src/thrift.appup.src deleted file mode 100644 index 54a63833..00000000 --- a/lib/erl/src/thrift.appup.src +++ /dev/null @@ -1 +0,0 @@ -{"%VSN%",[],[]}. diff --git a/lib/erl/src/thrift.erl b/lib/erl/src/thrift.erl deleted file mode 100644 index ef2c1fa0..00000000 --- a/lib/erl/src/thrift.erl +++ /dev/null @@ -1,65 +0,0 @@ -%%% 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). - --export([start/0, stop/0, config/1, config/2, reconfig/1]). - --include("thrift.hrl"). - -%%% -%%% behavior definition -%%% - -start() -> - application:start(thrift). - -stop() -> - application:stop(thrift). - -%%% -%%% configuration -%%% - -config(Item) -> - config(?MODULE, Item). - -config(App, Item) -> - case application:get_env(App, Item) of - {ok, Value} -> - Value; - undefined -> - ?ERROR("configuration for ~p is unavailable", [Item]), - unconfigured_item, - exit({missing_config, App, Item}) - end. - -reconfig(Config) -> - BFName = filename:basename(Config, ".config"), - FName = filename:join(filename:dirname(Config), - BFName ++ ".config"), - - case file:consult(FName) of - {error, R={_,_,_}} -> - {error, file_error, file:format_error(R)}; - {error, Posix} -> - {error, file_error, Posix}; - {ok, [List]} when is_list(List) -> - reconfig1(List) - end. - -reconfig1([]) -> - ok; -reconfig1([{App, List}|Tl]) -> - reconfig2(List, App, 0), - reconfig1(Tl). - -reconfig2([], App, Count) -> - ?INFO("application ~p reconfigured: ~p keys updated", [App, Count]), - ok; -reconfig2([{Par, Val}|Tl], App, Count) -> - application:set_env(App, Par, Val), - reconfig2(Tl, App, Count+1). diff --git a/lib/erl/src/thrift_app.erl b/lib/erl/src/thrift_app.erl deleted file mode 100644 index 17a14cf1..00000000 --- a/lib/erl/src/thrift_app.erl +++ /dev/null @@ -1,25 +0,0 @@ -%%% 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 deleted file mode 100644 index 545ffa87..00000000 --- a/lib/erl/src/thrift_app_sup.erl +++ /dev/null @@ -1,19 +0,0 @@ -%%% 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 deleted file mode 100644 index e9963c02..00000000 --- a/lib/erl/src/thrift_logger.erl +++ /dev/null @@ -1,249 +0,0 @@ -%%% 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_logger). - --behaviour(gen_event). - --include("thrift.hrl"). --include("oop.hrl"). - -%% gen_event callbacks --export([init/1, handle_event/2, handle_call/2, - handle_info/2, terminate/2, code_change/3]). - --export([install/0, bin_trim/1]). - -%% - --record(state, {omit_formats=gb_sets:empty()}). - --define(GS_TERM_FORMAT, "** Generic server ~p terminating \n** Last message in was ~p~n** When Server state == ~p~n** Reason for termination == ~n** ~p~n"). - -%%% -%%% ensure the regular logger is out and ours is in -%%% - -install() -> - %% remove loggers - io:format("starting logger~n"), - lists:foreach(fun(Logger) -> - case Logger of - _ -> gen_event:delete_handler(error_logger, Logger, normal) - end end, - gen_event:which_handlers(error_logger)), - - %% TODO(cpiro): sasl someday? - %% gen_event:add_handler(error_logger, sasl_report_file_h, {LogFile, all}), - - gen_event:add_handler(error_logger, ?MODULE, []), - - ok. - -%%% -%%% init -%%% - -init([]) -> - OmitFormats = gb_sets:from_list(config(omit_fmt)), - State = #state{omit_formats = OmitFormats}, - {ok, State}. - -%%% -%%% handle_event -%%% - -handle_event2(Symbol, Pid, Type, Message, State) -> % Message must be a string - {ok, MessageSafe, NL} = regexp:gsub(Message, "[\n]+", " "), % collapse whitespace to one space - - Type1 = - case Type of - "" -> ""; - _ -> sformat("~p ", [Type]) - end, - - Banner = - case config(show_pid) of - true -> - sformat("~s ~p ~s", [Symbol, Pid, Type1]); - false -> - sformat("~s~i ~s", [Symbol, Pid, Type1]) - end, - BannerLen = length(Banner), - - %% there's no way to see if Message is a string? just try - Output = sformat("~s", [Message]), - OutputSafe = sformat("~s", [MessageSafe]), - - Length = - case (length(OutputSafe) + BannerLen) < config(term_width) of - true -> short; - false -> long - end, - - OneLine = - case NL == 0 of - true -> oneliner; - false -> multiline - end, - - case { config(force_one_line), Length, OneLine } of - %% one line and short ... print as is - {_, short, oneliner} -> - format("~s~s~n", [Banner, OutputSafe]); - - %% too long ... squash to one - {true, long, _} -> - O = Banner ++ OutputSafe, - Format = sformat("~~~ps >~n", [config(term_width)-2]), % e.g. "~80s >~n" - format(Format, [O]); - - %% short but multiline... collapse to one - {true, short, multiline} -> - format("~s~s~n", [Banner, OutputSafe]); - - %% just print it - _ -> - format("~s~n~s~n~n", [Banner, Output]) - end. - -%% - -bin_trim([]) -> - []; -bin_trim([H|T]) -> - [bin_trim(H) | bin_trim(T)]; -bin_trim({}) -> - {}; -bin_trim(T) when is_tuple(T) -> - list_to_tuple(bin_trim(tuple_to_list(T))); -bin_trim(Bin) when is_binary(Bin), size(Bin) > 100 -> - {Bin1,Rest} = split_binary(Bin, 100), - Bin1; -bin_trim(Term) -> - Term. - -handle_event1({What, _Gleader, {Ref, Format, Data}}, State = #state{omit_formats=OmitFormats}) - when is_list(Format) -> - Symbol = - case What of - error -> "!!"; - warning_msg -> "**"; - info_msg -> ".."; - _Else -> "??" - end, - - case {Format, Data} of - {?GS_TERM_FORMAT, [Ref, LastMessage, Obj, {Kind, E}]} when Kind == timeout; Kind == thrift_exception -> - ok; - - {?GS_TERM_FORMAT, [Ref, LastMessage, Obj, Reason]} -> - Format1 = "** gen_server terminating in message ~p~n** State = ~s~n** Reason = ~p~n", - Message = sformat(Format1, [LastMessage, bin_trim(oop:inspect(Obj)), Reason]), - handle_event2(Symbol, Ref, "", Message, State); - - {?GS_TERM_FORMAT, _Dta} -> - TrimData = bin_trim(Data), - Message = sformat("DATA DIDN'T MATCH: ~p~n", [TrimData]) ++ sformat(Format, TrimData), - handle_event2(Symbol, Ref, "", Message, State); - {_, _} -> - case gb_sets:is_member(Format, OmitFormats) of - true -> - ok; - false -> - Message = sformat(Format, bin_trim(Data)), - handle_event2(Symbol, Ref, "", Message, State) - end - end, - {ok, State}; - -handle_event1({What, _Gleader, {Pid, Type, Report}}, State) -> - Symbol = - case What of - error_report -> "!!"; - warning_report -> "**"; - info_report -> ".."; - _Else -> "??" - end, - - case Type of - crash_report -> - print_crash_report(Report); - progress -> - ok; - _ -> - Message = sformat("|| ~s", [oop:inspect(Report)]), - handle_event2(Symbol, Pid, Type, Message, State) - end, - {ok, State}; - -handle_event1(_Event, State) -> - handle_event2("??", "", "", _Event, State), - {ok, State}. - -handle_event(Event, State) -> - try - handle_event1(Event, State) - catch - _:E -> - format("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~n error logger error:~n ~p~n Event = ~p~n State = ~p~n ~p~n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~n", - [E, Event, State, erlang:get_stacktrace()]), - {ok, State} - end. - -%%% -%%% call, info, terminate, code_change -%%% - -handle_call(_Request, State) -> - Reply = ok, - {ok, Reply, State}. - -handle_info(_Info, State) -> - {ok, State}. - -terminate(normal, _State) -> - ok; -terminate(Reason, _State) -> - format("*****************~n~n frick, error logger terminating: ~p~n~n*****************~n~n", [Reason]), - ok. - -code_change(_OldVsn, State, _Extra) -> - {ok, State}. - -%%==================================================================== -%%% Internal functions -%%==================================================================== - -%% how to output -format(Format, Data) -> - io:format(Format, Data). - -%% convenience -sformat(Format, Data) -> - thrift_utils:sformat(Format, Data). - -config(Item) -> - thrift:config(Item). - -print_crash_report(Report) -> - case Report of - %% for R12B0 - [[_, _, {error_info, {exit, {thrift_exception, _}, _}} | _] | _] -> - ok; - [[_, _, {error_info, {exit, {timeout, _}, _}} | _] | _] -> - ok; - - %% for R11B5 - [[_,_,{error_info, {thrift_exception, _}}|_] | _] -> - ok; - [[_,_,{error_info, {timeout, _}}|_] | _] -> - ok; - - %% else - _ -> - io:format("~~~~ crash report: ~w~n", [Report]) - end. diff --git a/lib/erl/src/thrift_oop_server.erl b/lib/erl/src/thrift_oop_server.erl deleted file mode 100644 index ef512bc1..00000000 --- a/lib/erl/src/thrift_oop_server.erl +++ /dev/null @@ -1,152 +0,0 @@ -%%% 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_oop_server). - --behaviour(gen_server). - --include("oop.hrl"). - --include("thrift.hrl"). - --include("transport/tTransportException.hrl"). --include("protocol/tProtocolException.hrl"). - --export([ - start_link/0, - stop/0 - ]). - --export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). - --define(SERVER, ?MODULE). - -%%% -%%% api -%%% - -start_link() -> - gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). - -stop() -> - gen_server:cast(?SERVER, stop). - -%%% -%%% init -%%% - -init({Class, Args}) -> - process_flag(trap_exit, true), - try %% TODO use apply_if_defined - State = apply(Class, new, Args), - ?INFO("thrift ~p:new(~s) = ~s", [Class, thrift_utils:unbrack(Args), oop:inspect(State)]), - {ok, State} - catch - E -> {stop, {new_failed, E}} - end; - -init(_) -> - {stop, invalid_params}. - -%%% -%%% call and cast -%%% - -handle_call(Request, From, State) -> handle_call_cast(call, Request, From, State). -handle_cast(stop, State) -> {stop, normal, State}; -handle_cast({Method, Args}, State) -> handle_call_cast(cast, {Method, Args}, undefined, State). - -reply(call, Value, State) -> {reply, Value, State}; -reply(cast, _Value, State) -> {noreply, State}. - -handle_call_cast(Type, Request, From, State) -> - %% ?INFO("~p: ~p", [?SERVER, oop:inspect(State)]), - %% ?INFO("handle_call(Request=~p, From=~p, State)", [Request, From]), - - case Request of - {get, [Field]} -> - Value = oop:get(State, Field), - reply(Type, Value, State); - - {set, [Field, Value]} -> - State1 = oop:set(State, Field, Value), - reply(Type, Value, State1); - - {class, []} -> - reply(Type, ?CLASS(State), State); - - {Method, Args} -> - handle_method(Type, State, Method, Args); - - _ -> - ?ERROR("thrift no match for Request = ~p", [Request]), - {stop, server_error, State} - %% {reply, server_error, State} - end. - -handle_method(Type, State, Method, Args) -> - Is_effectful = lists:prefix("effectful_", atom_to_list(Method)), - - try {Is_effectful, oop:call(State, Method, Args)} of - {true, {Retval, State1}} -> - reply(Type, Retval, State1); - - {true, _MalformedReturn} -> - %% TODO(cpiro): bad match -- remove when we're done converting - ?ERROR("oop:call(effectful_*,..,..) malformed return value ~p", - [_MalformedReturn]), - {stop, server_error, State}; - %% {noreply, State}; - - {false, Retval} -> - reply(Type, Retval, State) - - catch - exit:{thrift_exception, E} -> handle_exception(E, nothing); - exit:{{thrift_exception, E}, Stack} -> handle_exception(E, Stack); - exit:normal -> exit(normal); - exit:(X = {timeout, _}) -> exit(X); - exit:Other -> - exit(Other) - end. - -handle_exception(E, Stack) -> - %% ?ERROR("texception ~p", [E]), - case {oop:is_a(E, tException), Stack} of - {true, nothing} -> % good - exit({thrift_exception, E}); - {true, _} -> % good - E1 = tException:add_backtrace_element(E, Stack), - exit({thrift_exception, E1}); - {false, _} -> % shit - ?ERROR("exception wasn't really a tException ~p", [E]), - exit(bum) - end. - -%%% -%%% info, terminate, and code_change -%%% - -handle_info({'EXIT', Pid, Except} = All, State) -> - case Except of - normal -> - {noreply, State}; - {normal, _} -> - {noreply, State}; - _unhandled -> - error_logger:format("unhandled exit ~p", [All]), - {stop, All, State} - end; - -handle_info(Info, State) -> - ?INFO("~p", [Info]), - {noreply, State}. - -terminate(Reason, State) -> - ok. - -code_change(OldVsn, State, Extra) -> - {ok, State}. diff --git a/lib/erl/src/thrift_sup.erl b/lib/erl/src/thrift_sup.erl deleted file mode 100644 index 8be57dfb..00000000 --- a/lib/erl/src/thrift_sup.erl +++ /dev/null @@ -1,45 +0,0 @@ -%%% 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), - case ?R0(Pid, effectful_serve) of - ok -> - ok; - {error, eaddrinuse} -> - exit(eaddrinuse) - end, - {ok, Pid}. diff --git a/lib/erl/src/thrift_utils.erl b/lib/erl/src/thrift_utils.erl deleted file mode 100644 index 1cbacc02..00000000 --- a/lib/erl/src/thrift_utils.erl +++ /dev/null @@ -1,51 +0,0 @@ -%%% 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_utils). - --include("transport/tTransportException.hrl"). - --export([tabulate/2, dict_size/1, sformat/2, unbrack/1, first_item/1, unnest_record/2]). - -%% tabulate -tabulate(N,F) -> - tabulate(0, N, F). - -tabulate(N,M,_) when N==M -> - []; -tabulate(N,M,F) -> - [F(N) | tabulate(N+1, M, F)]. - -%% makin me sad -dict_size(Dict) -> - dict:fold(fun (_,_,I) -> I+1 end,0,Dict). - -%% I CAN HAS EAZIER KTHX -sformat(Format, Data) when is_list(Data) -> - lists:flatten(io_lib:format(Format, Data)); -sformat(Format, Item) -> - error_logger:warning_msg("sformat called with non-list Data: (~p, ~p)", [Format, Item]), - sformat(Format, [Item]). - -%% render a list and pick off the square brackets -unbrack(List) -> - List1 = sformat("~w", [List]), - string:substr(List1, 2, length(List1)-2). - -first_item(DeepTuple) when is_tuple(DeepTuple) -> - first_item(element(1, DeepTuple)); -first_item(NotTuple) -> - NotTuple. - -unnest_record(Term, RecordTag) -> - case is_record(Term, RecordTag) of - true -> - {ok, Term}; - false when is_tuple(Term) -> - unnest_record(element(1, Term), RecordTag); - _ -> - error - end. diff --git a/lib/erl/src/transport/tBufferedTransport.erl b/lib/erl/src/transport/tBufferedTransport.erl deleted file mode 100644 index 2b3e0aa8..00000000 --- a/lib/erl/src/transport/tBufferedTransport.erl +++ /dev/null @@ -1,86 +0,0 @@ -%%% 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(tBufferedTransport). - --include("oop.hrl"). - --include("thrift.hrl"). --include("transport/tBufferedTransport.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/1, isOpen/1, effectful_open/1, effectful_close/1, read/2, effectful_write/2, effectful_flush/1]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(super); -?DEFINE_ATTR(transport); -?DEFINE_ATTR(wbuf). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tTransport. - -%%% inspect(This) -> string() - -inspect(This) -> - ?FORMAT_ATTR(transport) ++ ", " ++ - ?FORMAT_ATTR(wbuf). - -%%% -%%% class methods -%%% - -new(Transport) -> - Super = (super()):new(), - #?MODULE{super=Super, transport=Transport, wbuf=""}. - -%%% -%%% instance methods -%%% - -isOpen(This) -> - Transport = oop:get(This, transport), - ?R0(Transport, isOpen). - -effectful_open(This) -> - Transport = oop:get(This, transport), - ?R0(Transport, effectful_open), - {ok, This}. - -effectful_close(This) -> - Transport = oop:get(This, transport), - ?R0(Transport, effectful_close), - {ok, This}. - -read(This, Sz) -> - Transport = oop:get(This, transport), - ?R1(Transport, read, Sz). - -effectful_write(This, Data) -> % be sure to rebind This to the retval - Wbuf = oop:get(This, wbuf), - This1 = oop:set(This, wbuf, [Wbuf, Data]), % build an iolist() - {ok, This1}. - -effectful_flush(This) -> - Wbuf = oop:get(This, wbuf), - Transport = oop:get(This, transport), - ?R1(Transport, effectful_write, Wbuf), - ?R0(Transport, effectful_flush), - This1 = oop:set(This, wbuf, []), - {ok, This1}. diff --git a/lib/erl/src/transport/tBufferedTransportFactory.erl b/lib/erl/src/transport/tBufferedTransportFactory.erl deleted file mode 100644 index de2570e1..00000000 --- a/lib/erl/src/transport/tBufferedTransportFactory.erl +++ /dev/null @@ -1,54 +0,0 @@ -%%% 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(tBufferedTransportFactory). - --include("oop.hrl"). --include("transport/tBufferedTransport.hrl"). --include("transport/tBufferedTransportFactory.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/0, getTransport/2]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?ATTR_DUMMY. - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tTransportFactory. - -%%% inspect(This) -> string() - -inspect(_This) -> - "". - -%%% -%%% class methods -%%% - -new() -> - Super = (super()):new(), - #?MODULE{super=Super}. - -%%% -%%% instance methods -%%% - -getTransport(_This, Trans) -> - oop:start_new(tBufferedTransport, [Trans]). diff --git a/lib/erl/src/transport/tErlAcceptor.erl b/lib/erl/src/transport/tErlAcceptor.erl deleted file mode 100644 index c2c8f9cc..00000000 --- a/lib/erl/src/transport/tErlAcceptor.erl +++ /dev/null @@ -1,157 +0,0 @@ -%%% 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(tErlAcceptor). - --include("oop.hrl"). --include("thrift.hrl"). --include("tApplicationException.hrl"). --include("transport/tTransportException.hrl"). --include("protocol/tProtocolException.hrl"). --include("transport/tServerSocket.hrl"). --include("transport/tErlAcceptor.hrl"). - --include_lib("kernel/include/inet.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/3, accept/4]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(super); -?DEFINE_ATTR(serverPid); -?DEFINE_ATTR(transportFactory); -?DEFINE_ATTR(protocolFactory). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tServerTransport. - -%%% inspect(This) -> string() - -inspect(This) -> - ?FORMAT_ATTR(serverPid) ++ ", " ++ - ?FORMAT_ATTR(transportFactory) ++ ", " ++ - ?FORMAT_ATTR(protocolFactory). - -%%% -%%% class methods -%%% - -new(ServerPid, TF, PF) -> - Super = (super()):new(), - #?MODULE{super = Super, - serverPid = ServerPid, - transportFactory = TF, - protocolFactory = PF - }. - -%%% -%%% instance methods -%%% - -accept(This, ListenSocket, GP, Handler) -> - ServerPid = oop:get(This, serverPid), - - case catch gen_tcp:accept(ListenSocket) of - {ok, Socket} -> - ?C0(ServerPid, effectful_new_acceptor), % cast to create new acceptor - - AddrString = render_addr(Socket), - ?INFO("thrift connection accepted from ~s", [AddrString]), - - Client = oop:start_new(tSocket, []), - ?R1(Client, effectful_setHandle, Socket), - - %% cpiro: OPAQUE!! Trans = Client - TF = oop:get(This, transportFactory), - Trans = ?F1(TF, getTransport, Client), - - %% cpiro: OPAQUE!! Prot = start_new(tBinaryProtocol, [Trans]) - PF = oop:get(This, protocolFactory), - Prot = ?F1(PF, getProtocol, Trans), - - %% start_new(, ...) - Processor = oop:start_new(tErlProcessor, [GP, Handler]), - - try - receive_loop(This, Processor, Prot, Prot) - catch - exit:{timeout, _} -> - ?INFO("thrift connection timed out from ~s", [AddrString]); - - %% cpiro: i think the extra entry on the stack is always from receive_loop - %% the below case shouldn't happen then? if we move this catch inside - %% we'll probably need this case and not the next one - - %% exit:{thrift_exception, E} -> - %% handle_exception(E, AddrString, no2); - - exit:{{thrift_exception, E}, Stack1} -> - handle_exception(E, AddrString, Stack1); - - Class:Else -> - ?ERROR("some other error ~p in tErlAcceptor: ~p", [Class, Else]) - end, - exit(normal); - - Else -> - R = thrift_utils:sformat("accept() failed: ~p", [Else]), - tException:throw(tTransportException, [R]) - end. - - -handle_exception(E, AddrString, Stack1) -> - case tException:read(E) of - none -> % not a tException - ?ERROR("not really a tException: ~p", [exit, E]); - - {tProtocolException, ?tProtocolException_BAD_VERSION, _} -> - ?INFO("thrift missing version from ~s", [AddrString]); - - {tTransportException, ?tTransportException_NOT_OPEN, _} -> - ?INFO("thrift connection closed from ~s", [AddrString]); - - _ -> - Where = "thrift tErlAcceptor caught a tException", - ?ERROR("~s", [tException:inspect_with_backtrace(E, Where, Stack1)]) - end. - -%% always calls itself ... only way to escape is through an exit -receive_loop(This, Processor, Iprot, Oprot) -> - case ?R2(Processor, process, Iprot, Oprot) of - {error, Reason} -> - case tException:read(Reason) of - none -> - ?ERROR("thrift handler returned something weird: {error, ~p}", [Reason]); - _ -> - Where = "thrift processor/handler caught a tException", - ?ERROR("~s", [tException:inspect_with_backtrace(Reason, Where)]) - end, - receive_loop(This, Processor, Iprot, Oprot); - Value -> - ?INFO("thrift request: ~p", [Value]), - receive_loop(This, Processor, Iprot, Oprot) - end. - -%% helper functions - -%% @param Socket the socket in question -render_addr(Socket) -> - {ok, {{A,B,C,D}, Port}} = inet:peername(Socket), - thrift_utils:sformat("~p.~p.~p.~p:~p", [A,B,C,D,Port]). diff --git a/lib/erl/src/transport/tServerSocket.erl b/lib/erl/src/transport/tServerSocket.erl deleted file mode 100644 index 76257c11..00000000 --- a/lib/erl/src/transport/tServerSocket.erl +++ /dev/null @@ -1,96 +0,0 @@ -%%% 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(tServerSocket). - --include("oop.hrl"). --include("thrift.hrl"). --include("transport/tServerSocket.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/1, effectful_listen/1, accept/1, effectful_close/1]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(super); -?DEFINE_ATTR(port); -?DEFINE_ATTR(handle). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tServerTransport. - -%%% inspect(This) -> string() - -inspect(This) -> - ?FORMAT_ATTR(port) ++ ", " ++ - ?FORMAT_ATTR(handle). - -%%% -%%% class methods -%%% - -new(Port) -> - Super = (super()):new(), - #?MODULE{super = Super, port = Port, handle = nil}. - -%%% -%%% instance methods -%%% - -effectful_listen(This) -> - Port = oop:get(This, port), - Options = [binary, {packet, 0}, {active, false}], % was [] - - case gen_tcp:listen(Port, Options) of - {ok, ListenSocket} -> - This1 = oop:set(This, handle, ListenSocket), - {ok, This1} - - %% {error, _} -> - %% TODO: no error handling in Ruby version? - end. - -accept(This) -> - case oop:get(This, handle) of - nil -> - nil; % cpiro: sic the Ruby code - - Handle -> - case gen_tcp:accept(Handle) of - {ok, Sock} -> - Trans = oop:start_new(tSocket, []), - ?R1(Trans, effectful_setHandle, Sock), - Trans - %% {error, _} -> - %% TODO: no error handling in Ruby version? - end - end. - -effectful_close(This) -> - case oop:get(This, handle) of - nil -> - {nil, This}; - Handle -> - case gen_tcp:close(Handle) of - ok -> - {ok, This} % cpiro: sic the Ruby version: don't set handle to nil - %% {error, _} -> - %% TODO: no error handling in Ruby version? - end - end. diff --git a/lib/erl/src/transport/tServerTransport.erl b/lib/erl/src/transport/tServerTransport.erl deleted file mode 100644 index f007d54f..00000000 --- a/lib/erl/src/transport/tServerTransport.erl +++ /dev/null @@ -1,52 +0,0 @@ -%%% 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(tServerTransport). - --include("oop.hrl"). --include("transport/tServerTransport.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/0]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?ATTR_DUMMY. - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - none. - -%%% inspect(This) -> string() - -inspect(_This) -> - "". - -%%% -%%% class methods -%%% - -new() -> - #?MODULE{}. - -%%% -%%% instance methods -%%% - -getTransport(_This, Trans) -> - Trans. diff --git a/lib/erl/src/transport/tSocket.erl b/lib/erl/src/transport/tSocket.erl deleted file mode 100644 index 842fba38..00000000 --- a/lib/erl/src/transport/tSocket.erl +++ /dev/null @@ -1,134 +0,0 @@ -%%% 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(tSocket). - --include("oop.hrl"). - --include("thrift.hrl"). --include("transport/tTransportException.hrl"). --include("transport/tSocket.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/0, new/1, new/2, - effectful_setHandle/2, effectful_open/1, - isOpen/1, effectful_write/2, read/2, effectful_close/1]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(super); -?DEFINE_ATTR(host); -?DEFINE_ATTR(port); -?DEFINE_ATTR(handle). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tTransport. - -%%% inspect(This) -> string() - -inspect(This) -> - ?FORMAT_ATTR(host) ++ ", " ++ - ?FORMAT_ATTR(port) ++ ", " ++ - ?FORMAT_ATTR(handle). - -%%% -%%% class methods -%%% - -new(Host, Port) -> - Super = (super()):new(), - #?MODULE{super=Super, host=Host, port=Port, handle=nil}. - -new(Host) -> - new(Host, 9090). - -new() -> - new("localhost", 9090). - -%%% -%%% instance methods -%%% - -effectful_setHandle(This, Handle) -> - {ok, oop:set(This, handle, Handle)}. - -effectful_open(This) -> - Host = oop:get(This, host), - Port = oop:get(This, port), - Options = [binary, {packet, 0}, - {active, false}, - {reuseaddr, true}, - {nodelay, true}, - {send_timeout, case application:get_env(thrift, socket_send_timeout) of - {ok, Millis} when is_integer(Millis), Millis > 0 -> Millis; - _Else -> 5000 - end} - ], - case gen_tcp:connect(Host, Port, Options) of - {error, _} -> - tException:throw(tTransportException, - [?tTransportException_NOT_OPEN, "Could not connect to " ++ Host ++ ":" - ++ integer_to_list(Port)]); - {ok, Socket} -> - effectful_setHandle(This, Socket) - end. - -isOpen(This) -> - oop:get(This, handle) /= nil. - -effectful_write(This, Data) -> - Handle = oop:get(This, handle), - - case gen_tcp:send(Handle, Data) of - {error,timeout} -> - effectful_close(This), - tException:throw(tTransportException, [?tTransportException_NOT_OPEN, "in write"]); - {error, _} -> - effectful_close(This), - tException:throw(tTransportException, [?tTransportException_NOT_OPEN, "in write"]); - ok -> - {ok, This} - end. - -read(This, Sz) -> - Handle = oop:get(This, handle), - case gen_tcp:recv(Handle, Sz) of - {ok, []} -> - Host = oop:get(This, host), - Port = oop:get(This, port), - tException:throw(tTransportException, - [?tTransportException_UNKNOWN, - "TSocket: Could not read " ++ integer_to_list(Sz) ++ - "bytes from " ++ Host ++ ":" ++ integer_to_list(Port)]); - {ok, Data} -> - %% DEBUG - ?INFO("tSocket: read ~p", [Data]), - Data; - {error, Error} -> - tException:throw(tTransportException, [?tTransportException_NOT_OPEN, "in tSocket:read/2: gen_tcp:recv"]) - end. - -effectful_close(This) -> - case oop:get(This, handle) of - nil -> - {ok, This}; - Handle -> - gen_tcp:close(Handle), - {ok, oop:set(This, handle, nil)} - end. diff --git a/lib/erl/src/transport/tTransport.erl b/lib/erl/src/transport/tTransport.erl deleted file mode 100644 index 73bcf72d..00000000 --- a/lib/erl/src/transport/tTransport.erl +++ /dev/null @@ -1,99 +0,0 @@ -%%% 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(tTransport). - --include("oop.hrl"). - --include("thrift.hrl"). --include("transport/tTransport.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/0, isOpen/1, effectful_open/1, effectful_close/1, read/2, readAll/2, effectful_write/2, effectful_flush/1]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?ATTR_DUMMY. - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - none. - -%%% inspect(This) -> string() - -inspect(_This) -> - "". - -%%% -%%% class methods -%%% - -new() -> - #?MODULE{}. - -%%% -%%% instance methods -%%% - -e() -> - exit('tTransport is abstract'). - -isOpen(_This) -> - e(), - nil. - -effectful_open(This) -> - e(), - {nil, This}. - -effectful_close(This) -> - e(), - {nil, This}. - -read(_This, _Sz) -> - e(), - nil. - -readAll(This, Sz) -> - readAll_loop(This, Sz, "", 0). - -readAll_loop(This, Sz, Buff, Have) -> - if - Have < Sz -> - Chunk = ?L1(read, Sz - Have), - - %% man gen_tcp: - %% exactly Length bytes are returned, or an error; - %% possibly discarding less than Length bytes of data when - %% the socket gets closed from the other side. - - %% error_logger:info_msg("READ |~p|", [Chunk]), - - Have1 = Have + (Sz-Have), % length(Chunk) - Buff1 = Buff ++ Chunk, % TODO: ++ efficiency? - readAll_loop(This, Sz, Buff1, Have1); - true -> - Buff - end. - -effectful_write(This, _Buf) -> - e(), - {nil, This}. - -effectful_flush(This) -> - {nil, This}. diff --git a/lib/erl/src/transport/tTransportException.erl b/lib/erl/src/transport/tTransportException.erl deleted file mode 100644 index f81ae9b5..00000000 --- a/lib/erl/src/transport/tTransportException.erl +++ /dev/null @@ -1,57 +0,0 @@ -%%% 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(tTransportException). - --include("oop.hrl"). - --include("thrift.hrl"). --include("transport/tTransportException.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/0, new/1, new/2]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?DEFINE_ATTR(super). - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - tException. - -%%% inspect(This) -> string() - -inspect(This) -> - "". - -%%% -%%% class methods -%%% - -new(Type, Message) -> - Super = (super()):new(Type, Message), - #?MODULE{super=Super}. - -new() -> - new(?tTransportException_UNKNOWN, undefined). -new(Type) -> - new(Type, undefined). - -%%% -%%% instance methods -%%% diff --git a/lib/erl/src/transport/tTransportFactory.erl b/lib/erl/src/transport/tTransportFactory.erl deleted file mode 100644 index 77a9e010..00000000 --- a/lib/erl/src/transport/tTransportFactory.erl +++ /dev/null @@ -1,52 +0,0 @@ -%%% 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(tTransportFactory). - --include("oop.hrl"). --include("transport/tTransportFactory.hrl"). - --behavior(oop). - --export([attr/4, super/0, inspect/1]). - --export([new/0, getTransport/2]). - -%%% -%%% define attributes -%%% 'super' is required unless ?MODULE is a base class -%%% - -?ATTR_DUMMY. - -%%% -%%% behavior callbacks -%%% - -%%% super() -> SuperModule = atom() -%%% | none - -super() -> - none. - -%%% inspect(This) -> string() - -inspect(_This) -> - "". - -%%% -%%% class methods -%%% - -new() -> - #?MODULE{}. - -%%% -%%% instance methods -%%% - -getTransport(_This, Trans) -> - Trans. diff --git a/lib/erl/vsn.mk b/lib/erl/vsn.mk deleted file mode 100644 index d9b40014..00000000 --- a/lib/erl/vsn.mk +++ /dev/null @@ -1 +0,0 @@ -THRIFT_VSN=0.1 diff --git a/tutorial/erl/client.erl b/tutorial/erl/client.erl deleted file mode 100644 index 9e187467..00000000 --- a/tutorial/erl/client.erl +++ /dev/null @@ -1,73 +0,0 @@ --module(client). - --include("thrift.hrl"). --include("transport/tSocket.hrl"). --include("protocol/tBinaryProtocol.hrl"). - --include("calculator_thrift.hrl"). - --export([go/0]). - -p(X) -> - io:format("~p~n", [X]), - ok. - -t() -> - thrift:start(), - Host = "dev020", - Port = 9999, - - try - _Sock = oop:start_new(tSocket, [Host, Port]), - Trans = oop:start_new(tBufferedTransport, [_Sock]), - Prot = oop:start_new(tBinaryProtocol, [Trans]), - - ?R0(Trans, effectful_open), - - Client = calculator_thrift:new(Prot), - - calculator_thrift:ping(Client), - io:format("ping~n", []), - - Sum = calculator_thrift:add(Client, 1, 1), - io:format("1+1=~p~n", [Sum]), - - Sum1 = calculator_thrift:add(Client, 1, 4), - io:format("1+4=~p~n", [Sum1]), - - Work = #work{op=?tutorial_SUBTRACT, - num1=15, - num2=10}, - Diff = calculator_thrift:calculate(Client, 1, Work), - io:format("15-10=~p~n", [Diff]), - - %% xxx inheritance doesn't work - %% Log = sharedService_thrift:getStruct(Client, 1), - %% io:format("Log: ~p~n", [Log]), - - %% xxx neither do exceptions :( - try - Work1 = #work{op=?tutorial_DIVIDE, - num1=1, - num2=0}, - _Quot = (calculator_thrift:calculate(Client, 1, Work1)), - - io:format("LAME: exception handling is broken~n", []) - catch - Z -> - p(Z) - %% rescue InvalidOperation => io - %% print "InvalidOperation: ", io.why, "\n" - %% end - end, - - calculator_thrift:zip(Client), - io:format("zip~n", []), - - ?R0(Trans, effectful_close) - - catch - Y -> - p(Y) - end, - ok. diff --git a/tutorial/erl/client.sh b/tutorial/erl/client.sh deleted file mode 120000 index a417e0da..00000000 --- a/tutorial/erl/client.sh +++ /dev/null @@ -1 +0,0 @@ -server.sh \ No newline at end of file diff --git a/tutorial/erl/server.config b/tutorial/erl/server.config deleted file mode 100644 index 14ab752d..00000000 --- a/tutorial/erl/server.config +++ /dev/null @@ -1,28 +0,0 @@ -%% -*- erlang -*- - -[ %% begin config %% - -{thrift, [ - {term_width, 110}, - {force_one_line, false}, - - %% a list of ?INFO format strings that WILL NOT be output - {omit_fmt, [ -%"application ~p reconfigured: ~p keys updated" ,% ?INFO thrift.erl -"thrift connection accepted from ~s" ,% ?INFO tErlAcceptor.erl -"thrift connection closed from ~s" ,% ?INFO tErlAcceptor.erl -"thrift connection timed out from ~s" ,% ?INFO tErlAcceptor.erl -"thrift request: ~p" ,% ?INFO tErlAcceptor.erl -%"thrift server listening on port ~p" ,% ?INFO tErlServer.erl -"thrift ~p:new(~s) = ~s" ,% ?INFO thrift_oop_server.erl -"oop:call called: Obj=~p Func=~p ArgsProper=~p", -"tSocket: read ~p", - -"end of log filters"]}, - - {show_pid, true}, - {gen_server_messages, true}, - {lookup, true}, -{'end of config', thrift_logger}]} - -]. %% end config %% diff --git a/tutorial/erl/server.erl b/tutorial/erl/server.erl deleted file mode 100644 index 44f33ad5..00000000 --- a/tutorial/erl/server.erl +++ /dev/null @@ -1,76 +0,0 @@ --module(server). - --include("thrift.hrl"). --include("transport/tSocket.hrl"). --include("protocol/tBinaryProtocol.hrl"). - --include("server/tErlServer.hrl"). --include("transport/tErlAcceptor.hrl"). - --include("calculator_thrift.hrl"). - --export([start/0, start/1, stop/1, ping/0, add/2, calculate/2, getStruct/1, zip/0]). - -debug(Format, Data) -> - error_logger:info_msg(Format, Data). - -ping() -> - debug("ping()",[]), - ok. - -add(N1, N2) -> - debug("add(~p,~p)",[N1,N2]), - N1+N2. - -calculate(Logid, Work) -> - { Op, Num1, Num2 } = { Work#work.op, Work#work.num1, Work#work.num2 }, - debug("calculate(~p, {~p,~p,~p})", [Logid, Op, Num1, Num2]), - case Op of - ?tutorial_ADD -> Num1 + Num2; - ?tutorial_SUBTRACT -> Num1 - Num2; - ?tutorial_MULTIPLY -> Num1 * Num2; - - ?tutorial_DIVIDE when Num2 == 0 -> - throw(#invalidOperation{what=Op, why="Cannot divide by 0"}); - ?tutorial_DIVIDE -> - Num1 div Num2; - - _Else -> - throw(#invalidOperation{what=Op, why="Invalid operation"}) - end. - -getStruct(Key) -> - debug("getStruct(~p)", [Key]), - #sharedStruct{key=Key, value="RARG"}. - -zip() -> - debug("zip", []), - ok. - -%% - -start() -> - start(9090). - -start(Port) -> - thrift:start(), - - Handler = ?MODULE, - Processor = calculator_thrift, - - TF = tBufferedTransportFactory:new(), - PF = tBinaryProtocolFactory:new(), - - ServerTransport = tErlAcceptor, - ServerFlavor = tErlServer, - - Server = oop:start_new(ServerFlavor, [Port, Handler, Processor, ServerTransport, TF, PF]), - - case ?R0(Server, effectful_serve) of - ok -> Server; - Error -> Error - end. - -stop(Server) -> - ?C0(Server, stop), - ok. diff --git a/tutorial/erl/server.sh b/tutorial/erl/server.sh deleted file mode 100755 index 7ed611af..00000000 --- a/tutorial/erl/server.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -ERL_THRIFT=../../lib/erl - -if ! [ -d ${ERL_THRIFT}/ebin ]; then - echo "Please build the Thrift library by running \`make' in ${ERL_THRIFT}" - exit 1 -fi - -if ! [ -d ../gen-erl ]; then - echo "Please run thrift first to generate ../gen-erl/" - exit 1 -fi - - -erlc -I ${ERL_THRIFT}/include -I ../gen-erl -o ../gen-erl ../gen-erl/*.erl && - erlc -I ${ERL_THRIFT}/include -I ../gen-erl *.erl && - erl +K true -pa ${ERL_THRIFT}/ebin -pa ../gen-erl -config server.config -- 2.17.1