Moving from govendor to dep, updated dependencies (#48)
* Moving from govendor to dep. * Making the pull request template more friendly. * Fixing akward space in PR template. * goimports run on whole project using ` goimports -w $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./gen-go/*")` source of command: https://gist.github.com/bgentry/fd1ffef7dbde01857f66
This commit is contained in:
parent
9631aa3aab
commit
8d445c1c77
2186 changed files with 400410 additions and 352 deletions
98
vendor/git.apache.org/thrift.git/tutorial/Makefile.am
generated
vendored
Executable file
98
vendor/git.apache.org/thrift.git/tutorial/Makefile.am
generated
vendored
Executable file
|
@ -0,0 +1,98 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
if MINGW
|
||||
# do nothing, just build the compiler
|
||||
else
|
||||
|
||||
if WITH_C_GLIB
|
||||
SUBDIRS += c_glib
|
||||
endif
|
||||
|
||||
if WITH_CPP
|
||||
SUBDIRS += cpp
|
||||
endif
|
||||
|
||||
if WITH_D
|
||||
SUBDIRS += d
|
||||
endif
|
||||
|
||||
if WITH_JAVA
|
||||
SUBDIRS += java
|
||||
SUBDIRS += js
|
||||
endif
|
||||
|
||||
if WITH_PYTHON
|
||||
SUBDIRS += py
|
||||
SUBDIRS += py.twisted
|
||||
SUBDIRS += py.tornado
|
||||
endif
|
||||
|
||||
if WITH_RUBY
|
||||
SUBDIRS += rb
|
||||
endif
|
||||
|
||||
if WITH_HASKELL
|
||||
SUBDIRS += hs
|
||||
endif
|
||||
|
||||
if WITH_HAXE
|
||||
SUBDIRS += haxe
|
||||
endif
|
||||
|
||||
if WITH_GO
|
||||
SUBDIRS += go
|
||||
endif
|
||||
|
||||
if WITH_NODEJS
|
||||
SUBDIRS += nodejs
|
||||
endif
|
||||
|
||||
if WITH_DART
|
||||
SUBDIRS += dart
|
||||
endif
|
||||
|
||||
#
|
||||
# generate html for ThriftTest.thrift
|
||||
#
|
||||
all-local:
|
||||
$(top_builddir)/compiler/cpp/thrift --gen html -r $(top_srcdir)/tutorial/tutorial.thrift
|
||||
|
||||
clean-local:
|
||||
rm -rf $(top_srcdir)/tutorial/gen-html
|
||||
|
||||
endif
|
||||
|
||||
# Any folders or files not listed above being added to SUBDIR need to be placed here in
|
||||
# EXTRA_DIST to be included in the release
|
||||
EXTRA_DIST = \
|
||||
as3 \
|
||||
csharp \
|
||||
d \
|
||||
delphi \
|
||||
erl \
|
||||
hs \
|
||||
ocaml \
|
||||
perl \
|
||||
php \
|
||||
shared.thrift \
|
||||
tutorial.thrift \
|
||||
README.md
|
42
vendor/git.apache.org/thrift.git/tutorial/README.md
generated
vendored
Normal file
42
vendor/git.apache.org/thrift.git/tutorial/README.md
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
Thrift Tutorial
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
|
||||
Tutorial
|
||||
========
|
||||
|
||||
1) First things first, you'll need to install the Thrift compiler and the
|
||||
language libraries. Do that using the instructions in the top level
|
||||
README.md file.
|
||||
|
||||
2) Read tutorial.thrift to learn about the syntax of a Thrift file
|
||||
|
||||
3) Compile the code for the language of your choice:
|
||||
|
||||
$ thrift
|
||||
$ thrift -r --gen cpp tutorial.thrift
|
||||
|
||||
4) Take a look at the generated code.
|
||||
|
||||
5) Look in the language directories for sample client/server code.
|
||||
|
||||
6) That's about it for now. This tutorial is intentionally brief. It should be
|
||||
just enough to get you started and ready to build your own project.
|
50
vendor/git.apache.org/thrift.git/tutorial/as3/build.xml
generated
vendored
Normal file
50
vendor/git.apache.org/thrift.git/tutorial/as3/build.xml
generated
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
<project name="tutorial" default="dist" basedir=".">
|
||||
|
||||
<description>Thrift actionscript 3.0 tutorial.</description>
|
||||
|
||||
<property name="gen" location="gen-as3" />
|
||||
<property name="src" location="src" />
|
||||
<property name="thrift.src" location="../../lib/as3/src/" />
|
||||
<property name="dist" location="dist" />
|
||||
|
||||
<property name="final.name" value="as3-tutorial" />
|
||||
<property name="swf.name" value="${dist}/${final.name}.swf" />
|
||||
|
||||
<target name="flex.check" unless="FLEX_HOME">
|
||||
<fail message='You must set the FLEX_HOME property pointing to your flex SDK, eg. ant -DFLEX_HOME="/Applications/Adobe Flex Builder 3/sdks/3.2.0"'/>
|
||||
</target>
|
||||
|
||||
<target name="flex.init" depends="flex.check" unless="flex.finished">
|
||||
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
|
||||
<property name="flex.finished" value="true"/>
|
||||
</target>
|
||||
|
||||
<target name="init">
|
||||
<tstamp />
|
||||
<mkdir dir="${dist}"/>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="generate, flex.init, init">
|
||||
<mxmlc output="${swf.name}" file="${src}/CalculatorUI.as">
|
||||
<source-path path-element="${gen}" />
|
||||
<source-path path-element="${src}" />
|
||||
<source-path path-element="${thrift.src}" />
|
||||
</mxmlc>
|
||||
</target>
|
||||
|
||||
<target name="generate">
|
||||
<!-- Generate the thrift gen-java source -->
|
||||
<exec executable="../../compiler/cpp/thrift" failonerror="true">
|
||||
<arg line="--gen as3 ../shared.thrift"/>
|
||||
</exec>
|
||||
<exec executable="../../compiler/cpp/thrift" failonerror="true">
|
||||
<arg line="--gen as3 ../tutorial.thrift"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${gen}"/>
|
||||
<delete dir="${dist}" />
|
||||
</target>
|
||||
|
||||
</project>
|
142
vendor/git.apache.org/thrift.git/tutorial/as3/src/CalculatorUI.as
generated
vendored
Normal file
142
vendor/git.apache.org/thrift.git/tutorial/as3/src/CalculatorUI.as
generated
vendored
Normal file
|
@ -0,0 +1,142 @@
|
|||
package {
|
||||
import flash.display.Sprite;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFieldType;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.system.Security;
|
||||
|
||||
import org.apache.thrift.transport.TSocket;
|
||||
import org.apache.thrift.transport.TTransport;
|
||||
import org.apache.thrift.protocol.TProtocol;
|
||||
import org.apache.thrift.protocol.TBinaryProtocol;
|
||||
|
||||
/**
|
||||
* Simple interface and connection logic implementation for tutorial.
|
||||
*/
|
||||
public class CalculatorUI extends Sprite {
|
||||
public static const BUTTON_PADDING:uint = 5;
|
||||
|
||||
private var mCalculatorClient:Calculator; // we use calculator through interface
|
||||
private var mTransport:TTransport; // Transport, used to comunicate with server
|
||||
|
||||
private var mAddButton:Sprite;
|
||||
private var mLeft:TextField;
|
||||
private var mRight:TextField;
|
||||
private var mResult:TextField;
|
||||
|
||||
private var pingButton:Sprite;
|
||||
|
||||
public function CalculatorUI() {
|
||||
buildInterface();
|
||||
initSecurity();
|
||||
initConnection();
|
||||
}
|
||||
|
||||
private function initSecurity():void {
|
||||
Security.loadPolicyFile("xmlsocket://127.0.0.1:9092");
|
||||
}
|
||||
|
||||
/**
|
||||
* Example of initializing connection.
|
||||
*/
|
||||
private function initConnection():void {
|
||||
mTransport = new TSocket("127.0.0.1", 9090); // we connect to server
|
||||
mTransport.open();
|
||||
// initialize protocol:
|
||||
var protocol:TProtocol = new TBinaryProtocol(mTransport, false, false);
|
||||
mCalculatorClient = new CalculatorImpl(protocol); // finally, we create calculator client instance
|
||||
}
|
||||
|
||||
private function onPingClick(me:MouseEvent):void {
|
||||
if(!mTransport.isOpen()) return;
|
||||
mCalculatorClient.ping(onPingError, onPingSuccess);
|
||||
}
|
||||
|
||||
private function onPingError(error:Error):void {
|
||||
trace("Error, while requesting ping.");
|
||||
throw error;
|
||||
}
|
||||
|
||||
private function onPingSuccess():void {
|
||||
trace("Ping returned successfully");
|
||||
}
|
||||
|
||||
private function onAddClick(me:MouseEvent):void {
|
||||
if(!mTransport.isOpen()) return;
|
||||
var num1:Number = Number(mLeft.text);
|
||||
var num2:Number = Number(mRight.text);
|
||||
mResult.text = "Processing...";
|
||||
mCalculatorClient.add(num1, num2, onAddError, onAddSuccess);
|
||||
}
|
||||
|
||||
private function onAddError(error:Error):void {
|
||||
trace("Error, while requesting add.");
|
||||
throw error;
|
||||
}
|
||||
|
||||
private function onAddSuccess(res:Number):void {
|
||||
mResult.text = String(res);
|
||||
}
|
||||
|
||||
private function buildInterface():void {
|
||||
addChild(pingButton = buildButton("PING"));
|
||||
pingButton.x = (stage.stageWidth - pingButton.width) / 2;
|
||||
pingButton.y = 10;
|
||||
pingButton.addEventListener(MouseEvent.CLICK, onPingClick);
|
||||
|
||||
var top:Number = pingButton.y + pingButton.height + 20;
|
||||
addChild(mLeft = buildDigitInput());
|
||||
mLeft.x = 15;
|
||||
mLeft.y = top + BUTTON_PADDING;
|
||||
addChild(mRight = buildDigitInput());
|
||||
mRight.x = mLeft.x + mLeft.width + 15;
|
||||
mRight.y = top + BUTTON_PADDING;
|
||||
addChild(mAddButton = buildButton("ADD"));
|
||||
mAddButton.x = mRight.x + mRight.width + 15;
|
||||
mAddButton.y = top;
|
||||
mAddButton.addEventListener(MouseEvent.CLICK, onAddClick);
|
||||
addChild(mResult = buildDigitInput());
|
||||
mResult.x = mAddButton.x + mAddButton.width + 15;
|
||||
mResult.y = top + BUTTON_PADDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple digit-only input field.
|
||||
*/
|
||||
private function buildDigitInput():TextField {
|
||||
var textField:TextField = new TextField;
|
||||
textField.width = 75;
|
||||
textField.height = 20;
|
||||
textField.restrict = "0987654321.";
|
||||
textField.type = TextFieldType.INPUT;
|
||||
textField.background = true;
|
||||
textField.backgroundColor = 0xaaaaff;
|
||||
textField.textColor = 0xffff00;
|
||||
return textField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple button drawing.
|
||||
*/
|
||||
private function buildButton(text:String):Sprite {
|
||||
var button:Sprite = new Sprite;
|
||||
var textField:TextField = new TextField;
|
||||
textField.width = 4000;
|
||||
textField.text = text;
|
||||
textField.textColor = 0xffff00;
|
||||
textField.width = textField.textWidth + 4;
|
||||
textField.height = textField.textHeight + 4;
|
||||
textField.mouseEnabled = false;
|
||||
button.graphics.beginFill(0x0000ff);
|
||||
button.graphics.lineStyle(0, 0x000000);
|
||||
button.graphics.drawRoundRect(0, 0, textField.width + BUTTON_PADDING * 2,
|
||||
textField.height + BUTTON_PADDING * 2, BUTTON_PADDING);
|
||||
button.graphics.endFill();
|
||||
button.addChild(textField);
|
||||
textField.x = BUTTON_PADDING;
|
||||
textField.y = BUTTON_PADDING;
|
||||
button.useHandCursor = button.buttonMode = true;
|
||||
return button;
|
||||
}
|
||||
}
|
||||
}
|
85
vendor/git.apache.org/thrift.git/tutorial/c_glib/Makefile.am
generated
vendored
Executable file
85
vendor/git.apache.org/thrift.git/tutorial/c_glib/Makefile.am
generated
vendored
Executable file
|
@ -0,0 +1,85 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
AUTOMAKE_OPTIONS = subdir-objects serial-tests
|
||||
|
||||
BUILT_SOURCES = \
|
||||
gen-c_glib/calculator.h \
|
||||
gen-c_glib/shared_service.h \
|
||||
gen-c_glib/shared_types.h \
|
||||
gen-c_glib/tutorial_types.h
|
||||
|
||||
AM_CFLAGS = -g -Wall -Wextra -pedantic $(GLIB_CFLAGS) $(GOBJECT_CFLAGS) @GCOV_CFLAGS@
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/lib/c_glib/src -Igen-c_glib
|
||||
AM_LDFLAGS = $(GLIB_LIBS) $(GOBJECT_LIBS) @GCOV_LDFLAGS@
|
||||
|
||||
THRIFT = $(top_builddir)/compiler/cpp/thrift
|
||||
|
||||
noinst_LTLIBRARIES = \
|
||||
libtutorialgencglib.la
|
||||
|
||||
nodist_libtutorialgencglib_la_SOURCES = \
|
||||
gen-c_glib/calculator.c \
|
||||
gen-c_glib/calculator.h \
|
||||
gen-c_glib/shared_service.c \
|
||||
gen-c_glib/shared_service.h \
|
||||
gen-c_glib/shared_types.c \
|
||||
gen-c_glib/shared_types.h \
|
||||
gen-c_glib/tutorial_types.c \
|
||||
gen-c_glib/tutorial_types.h
|
||||
|
||||
libtutorialgencglib_la_LIBADD = \
|
||||
$(top_builddir)/lib/c_glib/libthrift_c_glib.la
|
||||
|
||||
libtutorialgencglib_la_CFLAGS = \
|
||||
$(AM_CFLAGS) -Wno-unused-function
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
tutorial_server \
|
||||
tutorial_client
|
||||
|
||||
tutorial_server_SOURCES = \
|
||||
c_glib_server.c
|
||||
|
||||
tutorial_server_LDADD = \
|
||||
libtutorialgencglib.la \
|
||||
$(top_builddir)/lib/c_glib/libthrift_c_glib.la
|
||||
|
||||
tutorial_client_SOURCES = \
|
||||
c_glib_client.c
|
||||
|
||||
tutorial_client_LDADD = \
|
||||
libtutorialgencglib.la \
|
||||
$(top_builddir)/lib/c_glib/libthrift_c_glib.la
|
||||
|
||||
|
||||
gen-c_glib/calculator.c gen-c_glib/calculator.h gen-c_glib/shared_service.c gen-c_glib/shared_service.h gen-c_glib/shared_types.c gen-c_glib/shared_types.h gen-c_glib/tutorial_types.c gen-c_glib/tutorial_types.h: $(top_srcdir)/tutorial/tutorial.thrift
|
||||
$(THRIFT) --gen c_glib -r $<
|
||||
|
||||
clean-local:
|
||||
$(RM) gen-c_glib/*
|
||||
|
||||
tutorialserver: all
|
||||
./tutorial_server
|
||||
|
||||
tutorialclient: all
|
||||
./tutorial_client
|
||||
|
||||
EXTRA_DIST = \
|
||||
c_glib_server.c \
|
||||
c_glib_client.c
|
190
vendor/git.apache.org/thrift.git/tutorial/c_glib/c_glib_client.c
generated
vendored
Normal file
190
vendor/git.apache.org/thrift.git/tutorial/c_glib/c_glib_client.c
generated
vendored
Normal file
|
@ -0,0 +1,190 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <thrift/c_glib/protocol/thrift_binary_protocol.h>
|
||||
#include <thrift/c_glib/transport/thrift_buffered_transport.h>
|
||||
#include <thrift/c_glib/transport/thrift_socket.h>
|
||||
|
||||
#include "gen-c_glib/calculator.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
ThriftSocket *socket;
|
||||
ThriftTransport *transport;
|
||||
ThriftProtocol *protocol;
|
||||
CalculatorIf *client;
|
||||
|
||||
GError *error = NULL;
|
||||
InvalidOperation *invalid_operation = NULL;
|
||||
|
||||
Work *work;
|
||||
|
||||
gint32 sum;
|
||||
gint32 diff;
|
||||
|
||||
int exit_status = 0;
|
||||
|
||||
#if (!GLIB_CHECK_VERSION (2, 36, 0))
|
||||
g_type_init ();
|
||||
#endif
|
||||
|
||||
socket = g_object_new (THRIFT_TYPE_SOCKET,
|
||||
"hostname", "localhost",
|
||||
"port", 9090,
|
||||
NULL);
|
||||
transport = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT,
|
||||
"transport", socket,
|
||||
NULL);
|
||||
protocol = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL,
|
||||
"transport", transport,
|
||||
NULL);
|
||||
|
||||
thrift_transport_open (transport, &error);
|
||||
|
||||
|
||||
/* In the C (GLib) implementation of Thrift, service methods on the
|
||||
server are accessed via a generated client class that implements
|
||||
the service interface. In this tutorial, we access a Calculator
|
||||
service through an instance of CalculatorClient, which implements
|
||||
CalculatorIf. */
|
||||
client = g_object_new (TYPE_CALCULATOR_CLIENT,
|
||||
"input_protocol", protocol,
|
||||
"output_protocol", protocol,
|
||||
NULL);
|
||||
|
||||
/* Each of the client methods requires at least two parameters: A
|
||||
pointer to the client-interface implementation (the client
|
||||
object), and a handle to a GError structure to receive
|
||||
information about any error that occurs.
|
||||
|
||||
On success, client methods return TRUE. A return value of FALSE
|
||||
indicates an error occurred and the error parameter has been
|
||||
set. */
|
||||
if (!error && calculator_if_ping (client, &error)) {
|
||||
puts ("ping()");
|
||||
}
|
||||
|
||||
/* Service methods that return a value do so by passing the result
|
||||
back via an output parameter (here, "sum"). */
|
||||
if (!error && calculator_if_add (client, &sum, 1, 1, &error)) {
|
||||
printf ("1+1=%d\n", sum);
|
||||
}
|
||||
|
||||
/* Thrift structs are implemented as GObjects, with each of the
|
||||
struct's members exposed as an object property. */
|
||||
work = g_object_new (TYPE_WORK, NULL);
|
||||
|
||||
if (!error) {
|
||||
g_object_set (work,
|
||||
"num1", 1,
|
||||
"num2", 0,
|
||||
"op", OPERATION_DIVIDE,
|
||||
NULL);
|
||||
|
||||
/* Exceptions are passed back from service methods in a manner
|
||||
similar to return values. */
|
||||
if (calculator_if_calculate (client,
|
||||
NULL,
|
||||
1,
|
||||
work,
|
||||
&invalid_operation,
|
||||
&error)) {
|
||||
puts ("Whoa? We can divide by zero!");
|
||||
}
|
||||
else {
|
||||
if (invalid_operation) {
|
||||
gchar *why;
|
||||
|
||||
/* Like structs, exceptions are implemented as objects with
|
||||
properties. */
|
||||
g_object_get (invalid_operation, "why", &why, NULL);
|
||||
|
||||
printf ("InvalidOperation: %s\n", why);
|
||||
|
||||
if (why != NULL)
|
||||
g_free (why);
|
||||
g_object_unref (invalid_operation);
|
||||
invalid_operation = NULL;
|
||||
}
|
||||
|
||||
g_clear_error (&error);
|
||||
}
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
/* Struct objects can be reused across method invocations. */
|
||||
g_object_set (work,
|
||||
"num1", 15,
|
||||
"num2", 10,
|
||||
"op", OPERATION_SUBTRACT,
|
||||
NULL);
|
||||
|
||||
if (calculator_if_calculate (client,
|
||||
&diff,
|
||||
1,
|
||||
work,
|
||||
&invalid_operation,
|
||||
&error)) {
|
||||
printf ("15-10=%d\n", diff);
|
||||
}
|
||||
}
|
||||
|
||||
g_object_unref (work);
|
||||
|
||||
if (!error) {
|
||||
SharedStruct *shared_struct;
|
||||
gchar *value;
|
||||
|
||||
shared_struct = g_object_new (TYPE_SHARED_STRUCT, NULL);
|
||||
|
||||
/* As defined in the Thrift file, the Calculator service extends
|
||||
the SharedService service. Correspondingly, in the generated
|
||||
code CalculatorIf inherits from SharedServiceIf, and the parent
|
||||
service's methods are accessible through a simple cast. */
|
||||
if (shared_service_client_get_struct (SHARED_SERVICE_IF (client),
|
||||
&shared_struct,
|
||||
1,
|
||||
&error)) {
|
||||
g_object_get (shared_struct, "value", &value, NULL);
|
||||
printf ("Check log: %s\n", value);
|
||||
g_free (value);
|
||||
}
|
||||
|
||||
g_object_unref (shared_struct);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
printf ("ERROR: %s\n", error->message);
|
||||
g_clear_error (&error);
|
||||
|
||||
exit_status = 1;
|
||||
}
|
||||
|
||||
thrift_transport_close (transport, NULL);
|
||||
|
||||
g_object_unref (client);
|
||||
g_object_unref (protocol);
|
||||
g_object_unref (transport);
|
||||
g_object_unref (socket);
|
||||
|
||||
return exit_status;
|
||||
}
|
527
vendor/git.apache.org/thrift.git/tutorial/c_glib/c_glib_server.c
generated
vendored
Normal file
527
vendor/git.apache.org/thrift.git/tutorial/c_glib/c_glib_server.c
generated
vendored
Normal file
|
@ -0,0 +1,527 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <thrift/c_glib/thrift.h>
|
||||
#include <thrift/c_glib/protocol/thrift_binary_protocol_factory.h>
|
||||
#include <thrift/c_glib/protocol/thrift_protocol_factory.h>
|
||||
#include <thrift/c_glib/server/thrift_server.h>
|
||||
#include <thrift/c_glib/server/thrift_simple_server.h>
|
||||
#include <thrift/c_glib/transport/thrift_buffered_transport_factory.h>
|
||||
#include <thrift/c_glib/transport/thrift_server_socket.h>
|
||||
#include <thrift/c_glib/transport/thrift_server_transport.h>
|
||||
|
||||
#include "gen-c_glib/calculator.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* In the C (GLib) implementation of Thrift, the actual work done by a
|
||||
server---that is, the code that runs when a client invokes a
|
||||
service method---is defined in a separate "handler" class that
|
||||
implements the service interface. Here we define the
|
||||
TutorialCalculatorHandler class, which implements the CalculatorIf
|
||||
interface and provides the behavior expected by tutorial clients.
|
||||
(Typically this code would be placed in its own module but for
|
||||
clarity this tutorial is presented entirely in a single file.)
|
||||
|
||||
For each service the Thrift compiler generates an abstract base
|
||||
class from which handler implementations should inherit. In our
|
||||
case TutorialCalculatorHandler inherits from CalculatorHandler,
|
||||
defined in gen-c_glib/calculator.h.
|
||||
|
||||
If you're new to GObject, try not to be intimidated by the quantity
|
||||
of code here---much of it is boilerplate and can mostly be
|
||||
copied-and-pasted from existing work. For more information refer to
|
||||
the GObject Reference Manual, available online at
|
||||
https://developer.gnome.org/gobject/. */
|
||||
|
||||
#define TYPE_TUTORIAL_CALCULATOR_HANDLER \
|
||||
(tutorial_calculator_handler_get_type ())
|
||||
|
||||
#define TUTORIAL_CALCULATOR_HANDLER(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
||||
TYPE_TUTORIAL_CALCULATOR_HANDLER, \
|
||||
TutorialCalculatorHandler))
|
||||
#define TUTORIAL_CALCULATOR_HANDLER_CLASS(c) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((c), \
|
||||
TYPE_TUTORIAL_CALCULATOR_HANDLER, \
|
||||
TutorialCalculatorHandlerClass))
|
||||
#define IS_TUTORIAL_CALCULATOR_HANDLER(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
|
||||
TYPE_TUTORIAL_CALCULATOR_HANDLER))
|
||||
#define IS_TUTORIAL_CALCULATOR_HANDLER_CLASS(c) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((c), \
|
||||
TYPE_TUTORIAL_CALCULATOR_HANDLER))
|
||||
#define TUTORIAL_CALCULATOR_HANDLER_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
|
||||
TYPE_TUTORIAL_CALCULATOR_HANDLER, \
|
||||
TutorialCalculatorHandlerClass))
|
||||
|
||||
struct _TutorialCalculatorHandler {
|
||||
CalculatorHandler parent_instance;
|
||||
|
||||
/* private */
|
||||
GHashTable *log;
|
||||
};
|
||||
typedef struct _TutorialCalculatorHandler TutorialCalculatorHandler;
|
||||
|
||||
struct _TutorialCalculatorHandlerClass {
|
||||
CalculatorHandlerClass parent_class;
|
||||
};
|
||||
typedef struct _TutorialCalculatorHandlerClass TutorialCalculatorHandlerClass;
|
||||
|
||||
GType tutorial_calculator_handler_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
/* The implementation of TutorialCalculatorHandler follows. */
|
||||
|
||||
G_DEFINE_TYPE (TutorialCalculatorHandler,
|
||||
tutorial_calculator_handler,
|
||||
TYPE_CALCULATOR_HANDLER)
|
||||
|
||||
/* Each of a handler's methods accepts at least two parameters: A
|
||||
pointer to the service-interface implementation (the handler object
|
||||
itself) and a handle to a GError structure to receive information
|
||||
about any error that occurs.
|
||||
|
||||
On success, a handler method returns TRUE. A return value of FALSE
|
||||
indicates an error occurred and the error parameter has been
|
||||
set. (Methods should not return FALSE without first setting the
|
||||
error parameter.) */
|
||||
static gboolean
|
||||
tutorial_calculator_handler_ping (CalculatorIf *iface,
|
||||
GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (iface);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
|
||||
puts ("ping()");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Service-method parameters are passed through as parameters to the
|
||||
handler method.
|
||||
|
||||
If the service method returns a value an output parameter, _return,
|
||||
is additionally passed to the handler method. This parameter should
|
||||
be set appropriately before the method returns, whenever it
|
||||
succeeds.
|
||||
|
||||
The return value from this method happens to be of a base type,
|
||||
i32, but note if a method returns a complex type such as a map or
|
||||
list *_return will point to a pre-allocated data structure that
|
||||
does not need to be re-allocated and should not be destroyed. */
|
||||
static gboolean
|
||||
tutorial_calculator_handler_add (CalculatorIf *iface,
|
||||
gint32 *_return,
|
||||
const gint32 num1,
|
||||
const gint32 num2,
|
||||
GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (iface);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
|
||||
printf ("add(%d,%d)\n", num1, num2);
|
||||
*_return = num1 + num2;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Any handler method can return a ThriftApplicationException to the
|
||||
client by setting its error parameter appropriately and returning
|
||||
FALSE. See the ThriftApplicationExceptionError enumeration defined
|
||||
in thrift_application_exception.h for a list of recognized
|
||||
exception types (GError codes).
|
||||
|
||||
If a service method can also throw a custom exception (that is, one
|
||||
defined in the .thrift file) an additional output parameter will be
|
||||
provided (here, "ouch") to hold an instance of the exception, when
|
||||
necessary. Note there will be a separate parameter added for each
|
||||
type of exception the method can throw.
|
||||
|
||||
Unlike return values, exception objects are never pre-created; this
|
||||
is always the responsibility of the handler method. */
|
||||
static gboolean
|
||||
tutorial_calculator_handler_calculate (CalculatorIf *iface,
|
||||
gint32 *_return,
|
||||
const gint32 logid,
|
||||
const Work *w,
|
||||
InvalidOperation **ouch,
|
||||
GError **error)
|
||||
{
|
||||
TutorialCalculatorHandler *self;
|
||||
|
||||
gint *log_key;
|
||||
gchar log_value[12];
|
||||
SharedStruct *log_struct;
|
||||
|
||||
gint num1;
|
||||
gint num2;
|
||||
Operation op;
|
||||
gboolean result = TRUE;
|
||||
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
|
||||
g_return_val_if_fail (IS_TUTORIAL_CALCULATOR_HANDLER (iface),
|
||||
FALSE);
|
||||
self = TUTORIAL_CALCULATOR_HANDLER (iface);
|
||||
|
||||
/* Remember: Exception objects are never pre-created */
|
||||
g_assert (*ouch == NULL);
|
||||
|
||||
/* Fetch the contents of our Work parameter.
|
||||
|
||||
Note that integer properties of thirty-two bits or fewer in width
|
||||
are _always_ of type gint, regardless of the range of values they
|
||||
hold. A common error is trying to retrieve, say, a structure
|
||||
member defined in the .thrift file as type i16 into a variable of
|
||||
type gint16, which will clobber variables adjacent on the
|
||||
stack. Remember: If you're retrieving an integer property the
|
||||
receiving variable must be of either type gint or gint64, as
|
||||
appropriate. */
|
||||
g_object_get ((Work *)w,
|
||||
"num1", &num1,
|
||||
"num2", &num2,
|
||||
"op", &op,
|
||||
NULL);
|
||||
|
||||
printf ("calculate(%d,{%d,%d,%d})\n", logid, op, num1, num2);
|
||||
|
||||
switch (op) {
|
||||
case OPERATION_ADD:
|
||||
*_return = num1 + num2;
|
||||
break;
|
||||
|
||||
case OPERATION_SUBTRACT:
|
||||
*_return = num1 - num2;
|
||||
break;
|
||||
|
||||
case OPERATION_MULTIPLY:
|
||||
*_return = num1 * num2;
|
||||
break;
|
||||
|
||||
case OPERATION_DIVIDE:
|
||||
if (num2 == 0) {
|
||||
/* For each custom exception type a subclass of ThriftStruct is
|
||||
generated by the Thrift compiler. Throw an exception by
|
||||
setting the corresponding output parameter to a new instance
|
||||
of its type and returning FALSE. */
|
||||
*ouch = g_object_new (TYPE_INVALID_OPERATION,
|
||||
"whatOp", op,
|
||||
"why", g_strdup ("Cannot divide by 0"),
|
||||
NULL);
|
||||
result = FALSE;
|
||||
|
||||
/* Note the call to g_strdup above: All the memory used by a
|
||||
ThriftStruct's properties belongs to the object itself and
|
||||
will be freed on destruction. Removing this call to g_strdup
|
||||
will lead to a segmentation fault as the object tries to
|
||||
release memory allocated statically to the program. */
|
||||
}
|
||||
else {
|
||||
*_return = num1 / num2;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
*ouch = g_object_new (TYPE_INVALID_OPERATION,
|
||||
"whatOp", op,
|
||||
"why", g_strdup ("Invalid Operation"),
|
||||
NULL);
|
||||
result = FALSE;
|
||||
}
|
||||
|
||||
/* On success, log a record of the result to our hash table */
|
||||
if (result) {
|
||||
log_key = g_malloc (sizeof *log_key);
|
||||
*log_key = logid;
|
||||
|
||||
snprintf (log_value, sizeof log_value, "%d", *_return);
|
||||
|
||||
log_struct = g_object_new (TYPE_SHARED_STRUCT,
|
||||
"key", *log_key,
|
||||
"value", g_strdup (log_value),
|
||||
NULL);
|
||||
g_hash_table_replace (self->log, log_key, log_struct);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* A one-way method has the same signature as an equivalent, regular
|
||||
method that returns no value. */
|
||||
static gboolean
|
||||
tutorial_calculator_handler_zip (CalculatorIf *iface,
|
||||
GError **error)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (iface);
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
|
||||
puts ("zip()");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* As specified in the .thrift file (tutorial.thrift), the Calculator
|
||||
service extends the SharedService service. Correspondingly, in the
|
||||
generated code the Calculator interface, CalculatorIf, extends the
|
||||
SharedService interface, SharedServiceIf, and subclasses of
|
||||
CalculatorHandler should implement its methods as well.
|
||||
|
||||
Here we provide an implementation for the getStruct method from the
|
||||
parent service. */
|
||||
static gboolean
|
||||
tutorial_calculator_handler_get_struct (SharedServiceIf *iface,
|
||||
SharedStruct **_return,
|
||||
const gint32 key32,
|
||||
GError **error)
|
||||
{
|
||||
gint key = (gint)key32;
|
||||
TutorialCalculatorHandler *self;
|
||||
SharedStruct *log_struct;
|
||||
gint log_key;
|
||||
gchar *log_value;
|
||||
|
||||
THRIFT_UNUSED_VAR (error);
|
||||
|
||||
g_return_val_if_fail (IS_TUTORIAL_CALCULATOR_HANDLER (iface),
|
||||
FALSE);
|
||||
self = TUTORIAL_CALCULATOR_HANDLER (iface);
|
||||
|
||||
/* Remember: Complex return types are always pre-created and need
|
||||
only be populated */
|
||||
g_assert (*_return != NULL);
|
||||
|
||||
printf ("getStruct(%d)\n", key);
|
||||
|
||||
/* If the key exists in our log, return the corresponding logged
|
||||
data (or an empty SharedStruct structure if it does not).
|
||||
|
||||
Incidentally, note we _must_ here copy the values from the hash
|
||||
table into the return structure. All memory used by the return
|
||||
structure belongs to the structure itself and will be freed once
|
||||
a response is sent to the client. If we merely freed *_return and
|
||||
set it to point to our hash-table entry, that would mean memory
|
||||
would be released (effectively, data erased) out of the hash
|
||||
table! */
|
||||
log_struct = g_hash_table_lookup (self->log, &key);
|
||||
if (log_struct != NULL) {
|
||||
g_object_get (log_struct,
|
||||
"key", &log_key,
|
||||
"value", &log_value,
|
||||
NULL);
|
||||
g_object_set (*_return,
|
||||
"key", log_key,
|
||||
"value", g_strdup (log_value),
|
||||
NULL);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* TutorialCalculatorHandler's instance finalizer (destructor) */
|
||||
static void
|
||||
tutorial_calculator_handler_finalize (GObject *object)
|
||||
{
|
||||
TutorialCalculatorHandler *self =
|
||||
TUTORIAL_CALCULATOR_HANDLER (object);
|
||||
|
||||
/* Free our calculation-log hash table */
|
||||
g_hash_table_unref (self->log);
|
||||
self->log = NULL;
|
||||
|
||||
/* Chain up to the parent class */
|
||||
G_OBJECT_CLASS (tutorial_calculator_handler_parent_class)->
|
||||
finalize (object);
|
||||
}
|
||||
|
||||
/* TutorialCalculatorHandler's instance initializer (constructor) */
|
||||
static void
|
||||
tutorial_calculator_handler_init (TutorialCalculatorHandler *self)
|
||||
{
|
||||
/* Create our calculation-log hash table */
|
||||
self->log = g_hash_table_new_full (g_int_hash,
|
||||
g_int_equal,
|
||||
g_free,
|
||||
g_object_unref);
|
||||
}
|
||||
|
||||
/* TutorialCalculatorHandler's class initializer */
|
||||
static void
|
||||
tutorial_calculator_handler_class_init (TutorialCalculatorHandlerClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
SharedServiceHandlerClass *shared_service_handler_class =
|
||||
SHARED_SERVICE_HANDLER_CLASS (klass);
|
||||
CalculatorHandlerClass *calculator_handler_class =
|
||||
CALCULATOR_HANDLER_CLASS (klass);
|
||||
|
||||
/* Register our destructor */
|
||||
gobject_class->finalize = tutorial_calculator_handler_finalize;
|
||||
|
||||
/* Register our implementations of CalculatorHandler's methods */
|
||||
calculator_handler_class->ping =
|
||||
tutorial_calculator_handler_ping;
|
||||
calculator_handler_class->add =
|
||||
tutorial_calculator_handler_add;
|
||||
calculator_handler_class->calculate =
|
||||
tutorial_calculator_handler_calculate;
|
||||
calculator_handler_class->zip =
|
||||
tutorial_calculator_handler_zip;
|
||||
|
||||
/* Register our implementation of SharedServiceHandler's method */
|
||||
shared_service_handler_class->get_struct =
|
||||
tutorial_calculator_handler_get_struct;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
/* That ends the implementation of TutorialCalculatorHandler.
|
||||
Everything below is fairly generic code that sets up a minimal
|
||||
Thrift server for tutorial clients. */
|
||||
|
||||
|
||||
/* Our server object, declared globally so it is accessible within the
|
||||
SIGINT signal handler */
|
||||
ThriftServer *server = NULL;
|
||||
|
||||
/* A flag that indicates whether the server was interrupted with
|
||||
SIGINT (i.e. Ctrl-C) so we can tell whether its termination was
|
||||
abnormal */
|
||||
gboolean sigint_received = FALSE;
|
||||
|
||||
/* Handle SIGINT ("Ctrl-C") signals by gracefully stopping the
|
||||
server */
|
||||
static void
|
||||
sigint_handler (int signal_number)
|
||||
{
|
||||
THRIFT_UNUSED_VAR (signal_number);
|
||||
|
||||
/* Take note we were called */
|
||||
sigint_received = TRUE;
|
||||
|
||||
/* Shut down the server gracefully */
|
||||
if (server != NULL)
|
||||
thrift_server_stop (server);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
TutorialCalculatorHandler *handler;
|
||||
CalculatorProcessor *processor;
|
||||
|
||||
ThriftServerTransport *server_transport;
|
||||
ThriftTransportFactory *transport_factory;
|
||||
ThriftProtocolFactory *protocol_factory;
|
||||
|
||||
struct sigaction sigint_action;
|
||||
|
||||
GError *error = NULL;
|
||||
int exit_status = 0;
|
||||
|
||||
#if (!GLIB_CHECK_VERSION (2, 36, 0))
|
||||
g_type_init ();
|
||||
#endif
|
||||
|
||||
/* Create an instance of our handler, which provides the service's
|
||||
methods' implementation */
|
||||
handler =
|
||||
g_object_new (TYPE_TUTORIAL_CALCULATOR_HANDLER,
|
||||
NULL);
|
||||
|
||||
/* Create an instance of the service's processor, automatically
|
||||
generated by the Thrift compiler, which parses incoming messages
|
||||
and dispatches them to the appropriate method in the handler */
|
||||
processor =
|
||||
g_object_new (TYPE_CALCULATOR_PROCESSOR,
|
||||
"handler", handler,
|
||||
NULL);
|
||||
|
||||
/* Create our server socket, which binds to the specified port and
|
||||
listens for client connections */
|
||||
server_transport =
|
||||
g_object_new (THRIFT_TYPE_SERVER_SOCKET,
|
||||
"port", 9090,
|
||||
NULL);
|
||||
|
||||
/* Create our transport factory, used by the server to wrap "raw"
|
||||
incoming connections from the client (in this case with a
|
||||
ThriftBufferedTransport to improve performance) */
|
||||
transport_factory =
|
||||
g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT_FACTORY,
|
||||
NULL);
|
||||
|
||||
/* Create our protocol factory, which determines which wire protocol
|
||||
the server will use (in this case, Thrift's binary protocol) */
|
||||
protocol_factory =
|
||||
g_object_new (THRIFT_TYPE_BINARY_PROTOCOL_FACTORY,
|
||||
NULL);
|
||||
|
||||
/* Create the server itself */
|
||||
server =
|
||||
g_object_new (THRIFT_TYPE_SIMPLE_SERVER,
|
||||
"processor", processor,
|
||||
"server_transport", server_transport,
|
||||
"input_transport_factory", transport_factory,
|
||||
"output_transport_factory", transport_factory,
|
||||
"input_protocol_factory", protocol_factory,
|
||||
"output_protocol_factory", protocol_factory,
|
||||
NULL);
|
||||
|
||||
/* Install our SIGINT handler, which handles Ctrl-C being pressed by
|
||||
stopping the server gracefully (not strictly necessary, but a
|
||||
nice touch) */
|
||||
memset (&sigint_action, 0, sizeof (sigint_action));
|
||||
sigint_action.sa_handler = sigint_handler;
|
||||
sigint_action.sa_flags = SA_RESETHAND;
|
||||
sigaction (SIGINT, &sigint_action, NULL);
|
||||
|
||||
/* Start the server, which will run until its stop method is invoked
|
||||
(from within the SIGINT handler, in this case) */
|
||||
puts ("Starting the server...");
|
||||
thrift_server_serve (server, &error);
|
||||
|
||||
/* If the server stopped for any reason other than having been
|
||||
interrupted by the user, report the error */
|
||||
if (!sigint_received) {
|
||||
g_message ("thrift_server_serve: %s",
|
||||
error != NULL ? error->message : "(null)");
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
puts ("done.");
|
||||
|
||||
g_object_unref (server);
|
||||
g_object_unref (transport_factory);
|
||||
g_object_unref (protocol_factory);
|
||||
g_object_unref (server_transport);
|
||||
|
||||
g_object_unref (processor);
|
||||
g_object_unref (handler);
|
||||
|
||||
return exit_status;
|
||||
}
|
52
vendor/git.apache.org/thrift.git/tutorial/cpp/CMakeLists.txt
generated
vendored
Normal file
52
vendor/git.apache.org/thrift.git/tutorial/cpp/CMakeLists.txt
generated
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
|
||||
|
||||
#Make sure gen-cpp files can be included
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}/gen-cpp")
|
||||
include_directories("${PROJECT_SOURCE_DIR}/lib/cpp/src")
|
||||
|
||||
include(ThriftMacros)
|
||||
|
||||
set(tutorialgencpp_SOURCES
|
||||
gen-cpp/Calculator.cpp
|
||||
gen-cpp/SharedService.cpp
|
||||
gen-cpp/shared_constants.cpp
|
||||
gen-cpp/shared_types.cpp
|
||||
gen-cpp/tutorial_constants.cpp
|
||||
gen-cpp/tutorial_types.cpp
|
||||
)
|
||||
add_library(tutorialgencpp STATIC ${tutorialgencpp_SOURCES})
|
||||
LINK_AGAINST_THRIFT_LIBRARY(tutorialgencpp thrift)
|
||||
|
||||
add_custom_command(OUTPUT gen-cpp/Calculator.cpp gen-cpp/SharedService.cpp gen-cpp/shared_constants.cpp gen-cpp/shared_types.cpp gen-cpp/tutorial_constants.cpp gen-cpp/tutorial_types.cpp
|
||||
COMMAND ${THRIFT_COMPILER} --gen cpp -r ${PROJECT_SOURCE_DIR}/tutorial/tutorial.thrift
|
||||
)
|
||||
|
||||
add_executable(TutorialServer CppServer.cpp)
|
||||
target_link_libraries(TutorialServer tutorialgencpp)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(TutorialServer thrift)
|
||||
target_link_libraries(TutorialServer ${ZLIB_LIBRARIES})
|
||||
|
||||
add_executable(TutorialClient CppClient.cpp)
|
||||
target_link_libraries(TutorialClient tutorialgencpp)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(TutorialClient thrift)
|
||||
target_link_libraries(TutorialClient ${ZLIB_LIBRARIES})
|
80
vendor/git.apache.org/thrift.git/tutorial/cpp/CppClient.cpp
generated
vendored
Normal file
80
vendor/git.apache.org/thrift.git/tutorial/cpp/CppClient.cpp
generated
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <thrift/protocol/TBinaryProtocol.h>
|
||||
#include <thrift/transport/TSocket.h>
|
||||
#include <thrift/transport/TTransportUtils.h>
|
||||
|
||||
#include "../gen-cpp/Calculator.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace apache::thrift;
|
||||
using namespace apache::thrift::protocol;
|
||||
using namespace apache::thrift::transport;
|
||||
|
||||
using namespace tutorial;
|
||||
using namespace shared;
|
||||
|
||||
int main() {
|
||||
boost::shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
|
||||
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
|
||||
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
||||
CalculatorClient client(protocol);
|
||||
|
||||
try {
|
||||
transport->open();
|
||||
|
||||
client.ping();
|
||||
cout << "ping()" << endl;
|
||||
|
||||
cout << "1 + 1 = " << client.add(1, 1) << endl;
|
||||
|
||||
Work work;
|
||||
work.op = Operation::DIVIDE;
|
||||
work.num1 = 1;
|
||||
work.num2 = 0;
|
||||
|
||||
try {
|
||||
client.calculate(1, work);
|
||||
cout << "Whoa? We can divide by zero!" << endl;
|
||||
} catch (InvalidOperation& io) {
|
||||
cout << "InvalidOperation: " << io.why << endl;
|
||||
// or using generated operator<<: cout << io << endl;
|
||||
// or by using std::exception native method what(): cout << io.what() << endl;
|
||||
}
|
||||
|
||||
work.op = Operation::SUBTRACT;
|
||||
work.num1 = 15;
|
||||
work.num2 = 10;
|
||||
int32_t diff = client.calculate(1, work);
|
||||
cout << "15 - 10 = " << diff << endl;
|
||||
|
||||
// Note that C++ uses return by reference for complex types to avoid
|
||||
// costly copy construction
|
||||
SharedStruct ss;
|
||||
client.getStruct(ss, 1);
|
||||
cout << "Received log: " << ss << endl;
|
||||
|
||||
transport->close();
|
||||
} catch (TException& tx) {
|
||||
cout << "ERROR: " << tx.what() << endl;
|
||||
}
|
||||
}
|
181
vendor/git.apache.org/thrift.git/tutorial/cpp/CppServer.cpp
generated
vendored
Normal file
181
vendor/git.apache.org/thrift.git/tutorial/cpp/CppServer.cpp
generated
vendored
Normal file
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <thrift/concurrency/ThreadManager.h>
|
||||
#include <thrift/concurrency/PlatformThreadFactory.h>
|
||||
#include <thrift/protocol/TBinaryProtocol.h>
|
||||
#include <thrift/server/TSimpleServer.h>
|
||||
#include <thrift/server/TThreadPoolServer.h>
|
||||
#include <thrift/server/TThreadedServer.h>
|
||||
#include <thrift/transport/TServerSocket.h>
|
||||
#include <thrift/transport/TSocket.h>
|
||||
#include <thrift/transport/TTransportUtils.h>
|
||||
#include <thrift/TToString.h>
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
#include "../gen-cpp/Calculator.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace apache::thrift;
|
||||
using namespace apache::thrift::concurrency;
|
||||
using namespace apache::thrift::protocol;
|
||||
using namespace apache::thrift::transport;
|
||||
using namespace apache::thrift::server;
|
||||
|
||||
using namespace tutorial;
|
||||
using namespace shared;
|
||||
|
||||
class CalculatorHandler : public CalculatorIf {
|
||||
public:
|
||||
CalculatorHandler() {}
|
||||
|
||||
void ping() { cout << "ping()" << endl; }
|
||||
|
||||
int32_t add(const int32_t n1, const int32_t n2) {
|
||||
cout << "add(" << n1 << ", " << n2 << ")" << endl;
|
||||
return n1 + n2;
|
||||
}
|
||||
|
||||
int32_t calculate(const int32_t logid, const Work& work) {
|
||||
cout << "calculate(" << logid << ", " << work << ")" << endl;
|
||||
int32_t val;
|
||||
|
||||
switch (work.op) {
|
||||
case Operation::ADD:
|
||||
val = work.num1 + work.num2;
|
||||
break;
|
||||
case Operation::SUBTRACT:
|
||||
val = work.num1 - work.num2;
|
||||
break;
|
||||
case Operation::MULTIPLY:
|
||||
val = work.num1 * work.num2;
|
||||
break;
|
||||
case Operation::DIVIDE:
|
||||
if (work.num2 == 0) {
|
||||
InvalidOperation io;
|
||||
io.whatOp = work.op;
|
||||
io.why = "Cannot divide by 0";
|
||||
throw io;
|
||||
}
|
||||
val = work.num1 / work.num2;
|
||||
break;
|
||||
default:
|
||||
InvalidOperation io;
|
||||
io.whatOp = work.op;
|
||||
io.why = "Invalid Operation";
|
||||
throw io;
|
||||
}
|
||||
|
||||
SharedStruct ss;
|
||||
ss.key = logid;
|
||||
ss.value = to_string(val);
|
||||
|
||||
log[logid] = ss;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void getStruct(SharedStruct& ret, const int32_t logid) {
|
||||
cout << "getStruct(" << logid << ")" << endl;
|
||||
ret = log[logid];
|
||||
}
|
||||
|
||||
void zip() { cout << "zip()" << endl; }
|
||||
|
||||
protected:
|
||||
map<int32_t, SharedStruct> log;
|
||||
};
|
||||
|
||||
/*
|
||||
CalculatorIfFactory is code generated.
|
||||
CalculatorCloneFactory is useful for getting access to the server side of the
|
||||
transport. It is also useful for making per-connection state. Without this
|
||||
CloneFactory, all connections will end up sharing the same handler instance.
|
||||
*/
|
||||
class CalculatorCloneFactory : virtual public CalculatorIfFactory {
|
||||
public:
|
||||
virtual ~CalculatorCloneFactory() {}
|
||||
virtual CalculatorIf* getHandler(const ::apache::thrift::TConnectionInfo& connInfo)
|
||||
{
|
||||
boost::shared_ptr<TSocket> sock = boost::dynamic_pointer_cast<TSocket>(connInfo.transport);
|
||||
cout << "Incoming connection\n";
|
||||
cout << "\tSocketInfo: " << sock->getSocketInfo() << "\n";
|
||||
cout << "\tPeerHost: " << sock->getPeerHost() << "\n";
|
||||
cout << "\tPeerAddress: " << sock->getPeerAddress() << "\n";
|
||||
cout << "\tPeerPort: " << sock->getPeerPort() << "\n";
|
||||
return new CalculatorHandler;
|
||||
}
|
||||
virtual void releaseHandler( ::shared::SharedServiceIf* handler) {
|
||||
delete handler;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
TThreadedServer server(
|
||||
boost::make_shared<CalculatorProcessorFactory>(boost::make_shared<CalculatorCloneFactory>()),
|
||||
boost::make_shared<TServerSocket>(9090), //port
|
||||
boost::make_shared<TBufferedTransportFactory>(),
|
||||
boost::make_shared<TBinaryProtocolFactory>());
|
||||
|
||||
/*
|
||||
// if you don't need per-connection state, do the following instead
|
||||
TThreadedServer server(
|
||||
boost::make_shared<CalculatorProcessor>(boost::make_shared<CalculatorHandler>()),
|
||||
boost::make_shared<TServerSocket>(9090), //port
|
||||
boost::make_shared<TBufferedTransportFactory>(),
|
||||
boost::make_shared<TBinaryProtocolFactory>());
|
||||
*/
|
||||
|
||||
/**
|
||||
* Here are some alternate server types...
|
||||
|
||||
// This server only allows one connection at a time, but spawns no threads
|
||||
TSimpleServer server(
|
||||
boost::make_shared<CalculatorProcessor>(boost::make_shared<CalculatorHandler>()),
|
||||
boost::make_shared<TServerSocket>(9090),
|
||||
boost::make_shared<TBufferedTransportFactory>(),
|
||||
boost::make_shared<TBinaryProtocolFactory>());
|
||||
|
||||
const int workerCount = 4;
|
||||
|
||||
boost::shared_ptr<ThreadManager> threadManager =
|
||||
ThreadManager::newSimpleThreadManager(workerCount);
|
||||
threadManager->threadFactory(
|
||||
boost::make_shared<PlatformThreadFactory>());
|
||||
threadManager->start();
|
||||
|
||||
// This server allows "workerCount" connection at a time, and reuses threads
|
||||
TThreadPoolServer server(
|
||||
boost::make_shared<CalculatorProcessorFactory>(boost::make_shared<CalculatorCloneFactory>()),
|
||||
boost::make_shared<TServerSocket>(9090),
|
||||
boost::make_shared<TBufferedTransportFactory>(),
|
||||
boost::make_shared<TBinaryProtocolFactory>(),
|
||||
threadManager);
|
||||
*/
|
||||
|
||||
cout << "Starting the server..." << endl;
|
||||
server.serve();
|
||||
cout << "Done." << endl;
|
||||
return 0;
|
||||
}
|
88
vendor/git.apache.org/thrift.git/tutorial/cpp/Makefile.am
generated
vendored
Executable file
88
vendor/git.apache.org/thrift.git/tutorial/cpp/Makefile.am
generated
vendored
Executable file
|
@ -0,0 +1,88 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
AUTOMAKE_OPTIONS = subdir-objects serial-tests
|
||||
|
||||
BUILT_SOURCES = gen-cpp/shared_types.cpp \
|
||||
gen-cpp/tutorial_types.cpp
|
||||
|
||||
noinst_LTLIBRARIES = libtutorialgencpp.la
|
||||
nodist_libtutorialgencpp_la_SOURCES = \
|
||||
gen-cpp/Calculator.cpp \
|
||||
gen-cpp/Calculator.h \
|
||||
gen-cpp/SharedService.cpp \
|
||||
gen-cpp/SharedService.h \
|
||||
gen-cpp/shared_constants.cpp \
|
||||
gen-cpp/shared_constants.h \
|
||||
gen-cpp/shared_types.cpp \
|
||||
gen-cpp/shared_types.h \
|
||||
gen-cpp/tutorial_constants.cpp \
|
||||
gen-cpp/tutorial_constants.h \
|
||||
gen-cpp/tutorial_types.cpp \
|
||||
gen-cpp/tutorial_types.h
|
||||
|
||||
|
||||
|
||||
libtutorialgencpp_la_LIBADD = $(top_builddir)/lib/cpp/libthrift.la
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
TutorialServer \
|
||||
TutorialClient
|
||||
|
||||
TutorialServer_SOURCES = \
|
||||
CppServer.cpp
|
||||
|
||||
TutorialServer_LDADD = \
|
||||
libtutorialgencpp.la \
|
||||
$(top_builddir)/lib/cpp/libthrift.la
|
||||
|
||||
TutorialClient_SOURCES = \
|
||||
CppClient.cpp
|
||||
|
||||
TutorialClient_LDADD = \
|
||||
libtutorialgencpp.la \
|
||||
$(top_builddir)/lib/cpp/libthrift.la
|
||||
|
||||
#
|
||||
# Common thrift code generation rules
|
||||
#
|
||||
THRIFT = $(top_builddir)/compiler/cpp/thrift
|
||||
|
||||
gen-cpp/Calculator.cpp gen-cpp/SharedService.cpp gen-cpp/shared_constants.cpp gen-cpp/shared_types.cpp gen-cpp/tutorial_constants.cpp gen-cpp/tutorial_types.cpp: $(top_srcdir)/tutorial/tutorial.thrift
|
||||
$(THRIFT) --gen cpp -r $<
|
||||
|
||||
AM_CPPFLAGS = $(BOOST_CPPFLAGS) $(LIBEVENT_CPPFLAGS) -I$(top_srcdir)/lib/cpp/src -Igen-cpp
|
||||
AM_CXXFLAGS = -Wall -Wextra -pedantic
|
||||
AM_LDFLAGS = $(BOOST_LDFLAGS) $(LIBEVENT_LDFLAGS)
|
||||
|
||||
clean-local:
|
||||
$(RM) gen-cpp/*
|
||||
|
||||
tutorialserver: all
|
||||
./TutorialServer
|
||||
|
||||
tutorialclient: all
|
||||
./TutorialClient
|
||||
|
||||
style-local:
|
||||
$(CPPSTYLE_CMD)
|
||||
|
||||
EXTRA_DIST = \
|
||||
CMakeLists.txt \
|
||||
CppClient.cpp \
|
||||
CppServer.cpp
|
92
vendor/git.apache.org/thrift.git/tutorial/csharp/CsharpClient/CsharpClient.cs
generated
vendored
Normal file
92
vendor/git.apache.org/thrift.git/tutorial/csharp/CsharpClient/CsharpClient.cs
generated
vendored
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Thrift;
|
||||
using Thrift.Protocol;
|
||||
using Thrift.Server;
|
||||
using Thrift.Transport;
|
||||
|
||||
|
||||
namespace CSharpTutorial
|
||||
{
|
||||
public class CSharpClient
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
try
|
||||
{
|
||||
TTransport transport = new TSocket("localhost", 9090);
|
||||
TProtocol protocol = new TBinaryProtocol(transport);
|
||||
Calculator.Client client = new Calculator.Client(protocol);
|
||||
|
||||
transport.Open();
|
||||
try
|
||||
{
|
||||
client.ping();
|
||||
Console.WriteLine("ping()");
|
||||
|
||||
int sum = client.add(1, 1);
|
||||
Console.WriteLine("1+1={0}", sum);
|
||||
|
||||
Work work = new Work();
|
||||
|
||||
work.Op = Operation.DIVIDE;
|
||||
work.Num1 = 1;
|
||||
work.Num2 = 0;
|
||||
try
|
||||
{
|
||||
int quotient = client.calculate(1, work);
|
||||
Console.WriteLine("Whoa we can divide by 0");
|
||||
}
|
||||
catch (InvalidOperation io)
|
||||
{
|
||||
Console.WriteLine("Invalid operation: " + io.Why);
|
||||
}
|
||||
|
||||
work.Op = Operation.SUBTRACT;
|
||||
work.Num1 = 15;
|
||||
work.Num2 = 10;
|
||||
try
|
||||
{
|
||||
int diff = client.calculate(1, work);
|
||||
Console.WriteLine("15-10={0}", diff);
|
||||
}
|
||||
catch (InvalidOperation io)
|
||||
{
|
||||
Console.WriteLine("Invalid operation: " + io.Why);
|
||||
}
|
||||
|
||||
SharedStruct log = client.getStruct(1);
|
||||
Console.WriteLine("Check log: {0}", log.Value);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
transport.Close();
|
||||
}
|
||||
}
|
||||
catch (TApplicationException x)
|
||||
{
|
||||
Console.WriteLine(x.StackTrace);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
110
vendor/git.apache.org/thrift.git/tutorial/csharp/CsharpClient/CsharpClient.csproj
generated
vendored
Normal file
110
vendor/git.apache.org/thrift.git/tutorial/csharp/CsharpClient/CsharpClient.csproj
generated
vendored
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{18F24087-4760-43DA-ACAB-7B9F0E096B11}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>CsharpClient</RootNamespace>
|
||||
<AssemblyName>CsharpClient</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.DataSetExtensions">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\gen-csharp\Calculator.cs">
|
||||
<Link>Calculator.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\gen-csharp\InvalidOperation.cs">
|
||||
<Link>InvalidOperation.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\gen-csharp\Operation.cs">
|
||||
<Link>Operation.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\gen-csharp\SharedService.cs">
|
||||
<Link>SharedService.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\gen-csharp\SharedStruct.cs">
|
||||
<Link>SharedStruct.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\gen-csharp\tutorial.Constants.cs">
|
||||
<Link>tutorial.Constants.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\gen-csharp\Work.cs">
|
||||
<Link>Work.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="CsharpClient.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\lib\csharp\src\Thrift.csproj">
|
||||
<Project>{499eb63c-d74c-47e8-ae48-a2fc94538e9d}</Project>
|
||||
<Name>Thrift</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>pushd "$(SolutionDir)"
|
||||
thrift -gen csharp -r ../tutorial.thrift
|
||||
popd
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
55
vendor/git.apache.org/thrift.git/tutorial/csharp/CsharpClient/Properties/AssemblyInfo.cs
generated
vendored
Normal file
55
vendor/git.apache.org/thrift.git/tutorial/csharp/CsharpClient/Properties/AssemblyInfo.cs
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("CsharpClient")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("CsharpClient")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2010 The Apache Software Foundation")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1a461214-fa28-452a-bd1d-d23ca8e947e3")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.10.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.10.0.0")]
|
129
vendor/git.apache.org/thrift.git/tutorial/csharp/CsharpServer/CsharpServer.cs
generated
vendored
Normal file
129
vendor/git.apache.org/thrift.git/tutorial/csharp/CsharpServer/CsharpServer.cs
generated
vendored
Normal file
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Thrift.Server;
|
||||
using Thrift.Transport;
|
||||
|
||||
namespace CSharpTutorial
|
||||
{
|
||||
public class CalculatorHandler : Calculator.Iface
|
||||
{
|
||||
Dictionary<int, SharedStruct> log;
|
||||
|
||||
public CalculatorHandler()
|
||||
{
|
||||
log = new Dictionary<int, SharedStruct>();
|
||||
}
|
||||
|
||||
public void ping()
|
||||
{
|
||||
Console.WriteLine("ping()");
|
||||
}
|
||||
|
||||
public int add(int n1, int n2)
|
||||
{
|
||||
Console.WriteLine("add({0},{1})", n1, n2);
|
||||
return n1 + n2;
|
||||
}
|
||||
|
||||
public int calculate(int logid, Work work)
|
||||
{
|
||||
Console.WriteLine("calculate({0}, [{1},{2},{3}])", logid, work.Op, work.Num1, work.Num2);
|
||||
int val = 0;
|
||||
switch (work.Op)
|
||||
{
|
||||
case Operation.ADD:
|
||||
val = work.Num1 + work.Num2;
|
||||
break;
|
||||
|
||||
case Operation.SUBTRACT:
|
||||
val = work.Num1 - work.Num2;
|
||||
break;
|
||||
|
||||
case Operation.MULTIPLY:
|
||||
val = work.Num1 * work.Num2;
|
||||
break;
|
||||
|
||||
case Operation.DIVIDE:
|
||||
if (work.Num2 == 0)
|
||||
{
|
||||
InvalidOperation io = new InvalidOperation();
|
||||
io.WhatOp = (int)work.Op;
|
||||
io.Why = "Cannot divide by 0";
|
||||
throw io;
|
||||
}
|
||||
val = work.Num1 / work.Num2;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
InvalidOperation io = new InvalidOperation();
|
||||
io.WhatOp = (int)work.Op;
|
||||
io.Why = "Unknown operation";
|
||||
throw io;
|
||||
}
|
||||
}
|
||||
|
||||
SharedStruct entry = new SharedStruct();
|
||||
entry.Key = logid;
|
||||
entry.Value = val.ToString();
|
||||
log[logid] = entry;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public SharedStruct getStruct(int key)
|
||||
{
|
||||
Console.WriteLine("getStruct({0})", key);
|
||||
return log[key];
|
||||
}
|
||||
|
||||
public void zip()
|
||||
{
|
||||
Console.WriteLine("zip()");
|
||||
}
|
||||
}
|
||||
|
||||
public class CSharpServer
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
try
|
||||
{
|
||||
CalculatorHandler handler = new CalculatorHandler();
|
||||
Calculator.Processor processor = new Calculator.Processor(handler);
|
||||
TServerTransport serverTransport = new TServerSocket(9090);
|
||||
TServer server = new TSimpleServer(processor, serverTransport);
|
||||
|
||||
// Use this for a multithreaded server
|
||||
// server = new TThreadPoolServer(processor, serverTransport);
|
||||
|
||||
Console.WriteLine("Starting the server...");
|
||||
server.Serve();
|
||||
}
|
||||
catch (Exception x)
|
||||
{
|
||||
Console.WriteLine(x.StackTrace);
|
||||
}
|
||||
Console.WriteLine("done.");
|
||||
}
|
||||
}
|
||||
}
|
111
vendor/git.apache.org/thrift.git/tutorial/csharp/CsharpServer/CsharpServer.csproj
generated
vendored
Normal file
111
vendor/git.apache.org/thrift.git/tutorial/csharp/CsharpServer/CsharpServer.csproj
generated
vendored
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{66707BAE-BBF9-4F03-B53E-BE3AD58322F8}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>CsharpServer</RootNamespace>
|
||||
<AssemblyName>CsharpServer</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.DataSetExtensions">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\gen-csharp\Calculator.cs">
|
||||
<Link>Calculator.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\gen-csharp\InvalidOperation.cs">
|
||||
<Link>InvalidOperation.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\gen-csharp\Operation.cs">
|
||||
<Link>Operation.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\gen-csharp\SharedService.cs">
|
||||
<Link>SharedService.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\gen-csharp\SharedStruct.cs">
|
||||
<Link>SharedStruct.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\gen-csharp\tutorial.Constants.cs">
|
||||
<Link>tutorial.Constants.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\gen-csharp\Work.cs">
|
||||
<Link>Work.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="CsharpServer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\lib\csharp\src\Thrift.csproj">
|
||||
<Project>{499eb63c-d74c-47e8-ae48-a2fc94538e9d}</Project>
|
||||
<Name>Thrift</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>pushd "$(SolutionDir)"
|
||||
thrift -gen csharp -r ../tutorial.thrift
|
||||
popd
|
||||
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
55
vendor/git.apache.org/thrift.git/tutorial/csharp/CsharpServer/Properties/AssemblyInfo.cs
generated
vendored
Normal file
55
vendor/git.apache.org/thrift.git/tutorial/csharp/CsharpServer/Properties/AssemblyInfo.cs
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("CsharpServer")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("CsharpServer")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2010 The Apache Software Foundation")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("e3b428f4-b2e9-4fc1-8a34-84abc4339860")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.10.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.10.0.0")]
|
39
vendor/git.apache.org/thrift.git/tutorial/csharp/tutorial.sln
generated
vendored
Normal file
39
vendor/git.apache.org/thrift.git/tutorial/csharp/tutorial.sln
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Thrift", "..\..\lib\csharp\src\Thrift.csproj", "{499EB63C-D74C-47E8-AE48-A2FC94538E9D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsharpClient", "CsharpClient\CsharpClient.csproj", "{18F24087-4760-43DA-ACAB-7B9F0E096B11}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{499EB63C-D74C-47E8-AE48-A2FC94538E9D} = {499EB63C-D74C-47E8-AE48-A2FC94538E9D}
|
||||
{66707BAE-BBF9-4F03-B53E-BE3AD58322F8} = {66707BAE-BBF9-4F03-B53E-BE3AD58322F8}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsharpServer", "CsharpServer\CsharpServer.csproj", "{66707BAE-BBF9-4F03-B53E-BE3AD58322F8}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{499EB63C-D74C-47E8-AE48-A2FC94538E9D} = {499EB63C-D74C-47E8-AE48-A2FC94538E9D}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{18F24087-4760-43DA-ACAB-7B9F0E096B11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{18F24087-4760-43DA-ACAB-7B9F0E096B11}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{18F24087-4760-43DA-ACAB-7B9F0E096B11}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{18F24087-4760-43DA-ACAB-7B9F0E096B11}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{66707BAE-BBF9-4F03-B53E-BE3AD58322F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{66707BAE-BBF9-4F03-B53E-BE3AD58322F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{66707BAE-BBF9-4F03-B53E-BE3AD58322F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{66707BAE-BBF9-4F03-B53E-BE3AD58322F8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
46
vendor/git.apache.org/thrift.git/tutorial/d/Makefile.am
generated
vendored
Normal file
46
vendor/git.apache.org/thrift.git/tutorial/d/Makefile.am
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
LIB_D_DIR = $(top_srcdir)/lib/d
|
||||
|
||||
GEN_SRC = gen-d/share/SharedService.d gen-d/share/shared_types.d \
|
||||
gen-d/tutorial/tutorial_types.d gen-d/tutorial/Calculator.d
|
||||
|
||||
$(GEN_SRC): $(top_srcdir)/tutorial/tutorial.thrift
|
||||
$(top_builddir)/compiler/cpp/thrift --gen d -r $<
|
||||
|
||||
server: server.d $(GEN_SRC)
|
||||
$(DMD) -I${LIB_D_DIR}/src -L-L${LIB_D_DIR} -L-lthriftd server.d ${GEN_SRC}
|
||||
|
||||
client: client.d $(GEN_SRC)
|
||||
$(DMD) -I${LIB_D_DIR}/src -L-L${LIB_D_DIR} -L-lthriftd client.d ${GEN_SRC}
|
||||
|
||||
PROGS = server client
|
||||
|
||||
if WITH_D_EVENT_TESTS
|
||||
async_client: async_client.d $(GEN_SRC)
|
||||
$(DMD) -I${LIB_D_DIR}/src -L-L${LIB_D_DIR} -L-lthriftd-event -L-lthriftd -L-levent async_client.d ${GEN_SRC}
|
||||
|
||||
PROGS += async_client
|
||||
endif
|
||||
|
||||
all-local: $(PROGS)
|
||||
|
||||
clean:
|
||||
$(RM) -f $(PROGS)
|
86
vendor/git.apache.org/thrift.git/tutorial/d/async_client.d
generated
vendored
Normal file
86
vendor/git.apache.org/thrift.git/tutorial/d/async_client.d
generated
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
module async_client;
|
||||
|
||||
import std.exception;
|
||||
import std.stdio;
|
||||
import thrift.async.libevent;
|
||||
import thrift.async.socket;
|
||||
import thrift.base;
|
||||
import thrift.codegen.async_client;
|
||||
import thrift.protocol.binary;
|
||||
import thrift.transport.buffered;
|
||||
|
||||
import tutorial.Calculator;
|
||||
import tutorial.tutorial_types;
|
||||
|
||||
void main() {
|
||||
auto asyncManager = new TLibeventAsyncManager;
|
||||
|
||||
// If we are done, gracefully stop the async manager to avoid hanging on
|
||||
// appplication shutdown.
|
||||
scope (exit) asyncManager.stop();
|
||||
|
||||
auto socket = new TAsyncSocket(asyncManager, "localhost", 9090);
|
||||
auto client = new TAsyncClient!Calculator(
|
||||
socket,
|
||||
new TBufferedTransportFactory,
|
||||
new TBinaryProtocolFactory!TBufferedTransport
|
||||
);
|
||||
|
||||
socket.open();
|
||||
|
||||
// Invoke all the methods.
|
||||
auto pingResult = client.ping();
|
||||
|
||||
auto addResult = client.add(1, 1);
|
||||
|
||||
auto work = Work();
|
||||
work.op = Operation.DIVIDE;
|
||||
work.num1 = 1;
|
||||
work.num2 = 0;
|
||||
auto quotientResult = client.calculate(1, work);
|
||||
|
||||
work.op = Operation.SUBTRACT;
|
||||
work.num1 = 15;
|
||||
work.num2 = 10;
|
||||
auto diffResult = client.calculate(1, work);
|
||||
|
||||
auto logResult = client.getStruct(1);
|
||||
|
||||
// Await the responses.
|
||||
pingResult.waitGet();
|
||||
writeln("ping()");
|
||||
|
||||
int sum = addResult.waitGet();
|
||||
writefln("1 + 1 = %s", sum);
|
||||
|
||||
try {
|
||||
quotientResult.waitGet();
|
||||
writeln("Whoa we can divide by 0");
|
||||
} catch (InvalidOperation io) {
|
||||
writeln("Invalid operation: " ~ io.why);
|
||||
}
|
||||
|
||||
writefln("15 - 10 = %s", diffResult.waitGet());
|
||||
|
||||
// TFuture is implicitly convertible to the result type via »alias this«,
|
||||
// for which it (eagerly, of course) awaits completion.
|
||||
writefln("Check log: %s", logResult.value);
|
||||
}
|
64
vendor/git.apache.org/thrift.git/tutorial/d/client.d
generated
vendored
Normal file
64
vendor/git.apache.org/thrift.git/tutorial/d/client.d
generated
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
module client;
|
||||
|
||||
import std.stdio;
|
||||
import thrift.base;
|
||||
import thrift.codegen.client;
|
||||
import thrift.protocol.binary;
|
||||
import thrift.transport.buffered;
|
||||
import thrift.transport.socket;
|
||||
|
||||
import tutorial.Calculator;
|
||||
import tutorial.tutorial_types;
|
||||
|
||||
void main() {
|
||||
auto socket = new TSocket("localhost", 9090);
|
||||
auto transport = new TBufferedTransport(socket);
|
||||
auto protocol = tBinaryProtocol(transport);
|
||||
auto client = tClient!Calculator(protocol);
|
||||
|
||||
transport.open();
|
||||
|
||||
client.ping();
|
||||
writeln("ping()");
|
||||
|
||||
int sum = client.add(1, 1);
|
||||
writefln("1 + 1 = %s", sum);
|
||||
|
||||
auto work = Work();
|
||||
work.op = Operation.DIVIDE;
|
||||
work.num1 = 1;
|
||||
work.num2 = 0;
|
||||
try {
|
||||
int quotient = client.calculate(1, work);
|
||||
writeln("Whoa we can divide by 0");
|
||||
} catch (InvalidOperation io) {
|
||||
writeln("Invalid operation: " ~ io.why);
|
||||
}
|
||||
|
||||
work.op = Operation.SUBTRACT;
|
||||
work.num1 = 15;
|
||||
work.num2 = 10;
|
||||
int diff = client.calculate(1, work);
|
||||
writefln("15 - 10 = %s", diff);
|
||||
|
||||
auto log = client.getStruct(1);
|
||||
writefln("Check log: %s", log.value);
|
||||
}
|
111
vendor/git.apache.org/thrift.git/tutorial/d/server.d
generated
vendored
Normal file
111
vendor/git.apache.org/thrift.git/tutorial/d/server.d
generated
vendored
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
module server;
|
||||
|
||||
import std.conv : to;
|
||||
import std.stdio;
|
||||
import thrift.codegen.processor;
|
||||
import thrift.protocol.binary;
|
||||
import thrift.server.simple;
|
||||
import thrift.server.transport.socket;
|
||||
import thrift.transport.buffered;
|
||||
|
||||
import share.SharedService;
|
||||
import share.shared_types;
|
||||
import tutorial.Calculator;
|
||||
import tutorial.tutorial_types;
|
||||
|
||||
/**
|
||||
* The actual implementation of the Calculator interface that is called by
|
||||
* the server to answer the requests.
|
||||
*/
|
||||
class CalculatorHandler : Calculator {
|
||||
void ping() {
|
||||
writeln("ping()");
|
||||
}
|
||||
|
||||
int add(int n1, int n2) {
|
||||
writefln("add(%s,%s)", n1, n2);
|
||||
return n1 + n2;
|
||||
}
|
||||
|
||||
int calculate(int logid, ref const(Work) work) {
|
||||
writefln("calculate(%s, {%s, %s, %s})", logid, work.op, work.num1, work.num2);
|
||||
int val;
|
||||
|
||||
switch (work.op) {
|
||||
case Operation.ADD:
|
||||
val = work.num1 + work.num2;
|
||||
break;
|
||||
case Operation.SUBTRACT:
|
||||
val = work.num1 - work.num2;
|
||||
break;
|
||||
case Operation.MULTIPLY:
|
||||
val = work.num1 * work.num2;
|
||||
break;
|
||||
case Operation.DIVIDE:
|
||||
if (work.num2 == 0) {
|
||||
auto io = new InvalidOperation();
|
||||
io.whatOp = work.op;
|
||||
io.why = "Cannot divide by 0";
|
||||
throw io;
|
||||
}
|
||||
val = work.num1 / work.num2;
|
||||
break;
|
||||
default:
|
||||
auto io = new InvalidOperation();
|
||||
io.whatOp = work.op;
|
||||
io.why = "Invalid Operation";
|
||||
throw io;
|
||||
}
|
||||
|
||||
auto ss = SharedStruct();
|
||||
ss.key = logid;
|
||||
ss.value = to!string(val);
|
||||
log[logid] = ss;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
SharedStruct getStruct(int logid) {
|
||||
writefln("getStruct(%s)", logid);
|
||||
return log[logid];
|
||||
}
|
||||
|
||||
void zip() {
|
||||
writeln("zip()");
|
||||
}
|
||||
|
||||
protected:
|
||||
SharedStruct[int] log;
|
||||
}
|
||||
|
||||
void main() {
|
||||
auto protocolFactory = new TBinaryProtocolFactory!();
|
||||
auto processor = new TServiceProcessor!Calculator(new CalculatorHandler);
|
||||
auto serverTransport = new TServerSocket(9090);
|
||||
auto transportFactory = new TBufferedTransportFactory;
|
||||
|
||||
auto server = new TSimpleServer(
|
||||
processor, serverTransport, transportFactory, protocolFactory);
|
||||
|
||||
writeln("Starting the server on port 9090...");
|
||||
server.serve();
|
||||
writeln("done.");
|
||||
}
|
71
vendor/git.apache.org/thrift.git/tutorial/dart/Makefile.am
generated
vendored
Normal file
71
vendor/git.apache.org/thrift.git/tutorial/dart/Makefile.am
generated
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
BUILT_SOURCES = gen-dart/tutorial/lib/tutorial.dart gen-dart/shared/lib/shared.dart
|
||||
|
||||
THRIFT = $(top_builddir)/compiler/cpp/thrift
|
||||
|
||||
gen-dart/tutorial/lib/tutorial.dart gen-dart/shared/lib/shared.dart: $(top_srcdir)/tutorial/tutorial.thrift
|
||||
$(THRIFT) --gen dart -r $<
|
||||
|
||||
all-local: gen-dart/tutorial/lib/tutorial.dart pub-get
|
||||
|
||||
clean-local:
|
||||
$(RM) -r gen-*
|
||||
find . -type d -name "packages" | xargs $(RM) -r
|
||||
find . -type f -name ".packages" | xargs $(RM)
|
||||
|
||||
pub-get: pub-get-gen pub-get-client pub-get-console-client pub-get-server
|
||||
|
||||
pub-get-gen: pub-get-tutorial pub-get-shared
|
||||
|
||||
pub-get-tutorial: gen-dart/tutorial/lib/tutorial.dart
|
||||
cd gen-dart/tutorial; ${DARTPUB} get
|
||||
|
||||
pub-get-shared: gen-dart/shared/lib/shared.dart
|
||||
cd gen-dart/shared; ${DARTPUB} get
|
||||
|
||||
pub-get-client:
|
||||
cd client; ${DARTPUB} get
|
||||
|
||||
pub-get-console-client:
|
||||
cd console_client; ${DARTPUB} get
|
||||
|
||||
pub-get-server:
|
||||
cd server; ${DARTPUB} get
|
||||
|
||||
tutorialserver: pub-get-gen pub-get-server
|
||||
${DART} server/bin/main.dart
|
||||
|
||||
tutorialclient: pub-get-gen pub-get-client
|
||||
cd client; ${DARTPUB} serve
|
||||
|
||||
tutorialconsoleclient: pub-get-console-client
|
||||
${DART} console_client/bin/main.dart
|
||||
|
||||
EXTRA_DIST = \
|
||||
client/web/client.dart \
|
||||
client/web/index.html \
|
||||
client/web/styles.css \
|
||||
client/pubspec.yaml \
|
||||
console_client/bin/main.dart \
|
||||
console_client/pubspec.yaml \
|
||||
server/bin/main.dart \
|
||||
server/pubspec.yaml \
|
||||
build.sh
|
56
vendor/git.apache.org/thrift.git/tutorial/dart/build.sh
generated
vendored
Normal file
56
vendor/git.apache.org/thrift.git/tutorial/dart/build.sh
generated
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# 'License'); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
set -e;
|
||||
rm -r gen-dart || true;
|
||||
|
||||
thrift --gen dart ../shared.thrift;
|
||||
cd gen-dart/shared;
|
||||
pub get;
|
||||
cd ../..;
|
||||
|
||||
thrift --gen dart ../tutorial.thrift;
|
||||
cd gen-dart/tutorial;
|
||||
pub get;
|
||||
cd ../..;
|
||||
|
||||
cd client;
|
||||
pub get;
|
||||
cd ..;
|
||||
|
||||
cd console_client;
|
||||
pub get;
|
||||
cd ..;
|
||||
|
||||
cd server;
|
||||
pub get;
|
||||
cd ..;
|
||||
|
||||
dartfmt -w gen-dart;
|
||||
|
||||
echo "\nEnjoy the Dart tutorial!";
|
||||
echo "\nTo run the server:";
|
||||
echo "> dart server/bin/main.dart";
|
||||
echo "\nTo run the client:";
|
||||
echo "# Serve the app from the client directory and view in a browser";
|
||||
echo "> cd client;";
|
||||
echo "> pub serve;";
|
||||
echo "\nTo run the console client:";
|
||||
echo "> dart console_client/bin/main.dart";
|
||||
echo "";
|
2
vendor/git.apache.org/thrift.git/tutorial/dart/client/.analysis_options
generated
vendored
Normal file
2
vendor/git.apache.org/thrift.git/tutorial/dart/client/.analysis_options
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
analyzer:
|
||||
strong-mode: true
|
34
vendor/git.apache.org/thrift.git/tutorial/dart/client/pubspec.yaml
generated
vendored
Normal file
34
vendor/git.apache.org/thrift.git/tutorial/dart/client/pubspec.yaml
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# 'License'); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
name: tutorial_client
|
||||
version: 0.10.0
|
||||
description: A Dart client implementation of the Apache Thrift tutorial
|
||||
author: Apache Thrift Developers <dev@thrift.apache.org>
|
||||
homepage: http://thrift.apache.org
|
||||
|
||||
environment:
|
||||
sdk: ">=1.13.0 <2.0.0"
|
||||
|
||||
dependencies:
|
||||
browser: ^0.10.0
|
||||
shared:
|
||||
path: ../gen-dart/shared
|
||||
thrift:
|
||||
path: ../../../lib/dart
|
||||
tutorial:
|
||||
path: ../gen-dart/tutorial
|
278
vendor/git.apache.org/thrift.git/tutorial/dart/client/web/client.dart
generated
vendored
Normal file
278
vendor/git.apache.org/thrift.git/tutorial/dart/client/web/client.dart
generated
vendored
Normal file
|
@ -0,0 +1,278 @@
|
|||
/// Licensed to the Apache Software Foundation (ASF) under one
|
||||
/// or more contributor license agreements. See the NOTICE file
|
||||
/// distributed with this work for additional information
|
||||
/// regarding copyright ownership. The ASF licenses this file
|
||||
/// to you under the Apache License, Version 2.0 (the
|
||||
/// "License"); you may not use this file except in compliance
|
||||
/// with the License. You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing,
|
||||
/// software distributed under the License is distributed on an
|
||||
/// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
/// KIND, either express or implied. See the License for the
|
||||
/// specific language governing permissions and limitations
|
||||
/// under the License.
|
||||
|
||||
import 'dart:html';
|
||||
|
||||
import 'package:thrift/thrift.dart';
|
||||
import 'package:thrift/thrift_browser.dart';
|
||||
import 'package:shared/shared.dart';
|
||||
import 'package:tutorial/tutorial.dart';
|
||||
|
||||
/// Adapted from the AS3 tutorial
|
||||
void main() {
|
||||
new CalculatorUI(querySelector('#output')).start();
|
||||
}
|
||||
|
||||
class CalculatorUI {
|
||||
final DivElement output;
|
||||
|
||||
CalculatorUI(this.output);
|
||||
|
||||
TTransport _transport;
|
||||
Calculator _calculatorClient;
|
||||
|
||||
void start() {
|
||||
_buildInterface();
|
||||
_initConnection();
|
||||
}
|
||||
|
||||
void _validate() {
|
||||
if (!_transport.isOpen) {
|
||||
window.alert("The transport is not open!");
|
||||
}
|
||||
}
|
||||
|
||||
void _initConnection() {
|
||||
_transport = new TAsyncClientSocketTransport(
|
||||
new TWebSocket(Uri.parse('ws://127.0.0.1:9090/ws')),
|
||||
new TMessageReader(new TBinaryProtocolFactory()));
|
||||
TProtocol protocol = new TBinaryProtocol(_transport);
|
||||
_transport.open();
|
||||
|
||||
_calculatorClient = new CalculatorClient(protocol);
|
||||
}
|
||||
|
||||
void _buildInterface() {
|
||||
output.children.forEach((e) {
|
||||
e.remove();
|
||||
});
|
||||
|
||||
_buildPingComponent();
|
||||
|
||||
_buildAddComponent();
|
||||
|
||||
_buildCalculatorComponent();
|
||||
|
||||
_buildGetStructComponent();
|
||||
}
|
||||
|
||||
void _buildPingComponent() {
|
||||
output.append(new HeadingElement.h3()..text = "Ping");
|
||||
ButtonElement pingButton = new ButtonElement()
|
||||
..text = "PING"
|
||||
..onClick.listen(_onPingClick);
|
||||
output.append(pingButton);
|
||||
}
|
||||
|
||||
void _onPingClick(MouseEvent e) {
|
||||
_validate();
|
||||
|
||||
_calculatorClient.ping();
|
||||
}
|
||||
|
||||
void _buildAddComponent() {
|
||||
output.append(new HeadingElement.h3()..text = "Add");
|
||||
InputElement num1 = new InputElement()
|
||||
..id = "add1"
|
||||
..type = "number"
|
||||
..style.fontSize = "14px"
|
||||
..style.width = "50px";
|
||||
output.append(num1);
|
||||
SpanElement op = new SpanElement()
|
||||
..text = "+"
|
||||
..style.fontSize = "14px"
|
||||
..style.marginLeft = "10px";
|
||||
output.append(op);
|
||||
InputElement num2 = new InputElement()
|
||||
..id = "add2"
|
||||
..type = "number"
|
||||
..style.fontSize = "14px"
|
||||
..style.width = "50px"
|
||||
..style.marginLeft = "10px";
|
||||
output.append(num2);
|
||||
ButtonElement addButton = new ButtonElement()
|
||||
..text = "="
|
||||
..style.fontSize = "14px"
|
||||
..style.marginLeft = "10px"
|
||||
..onClick.listen(_onAddClick);
|
||||
output.append(addButton);
|
||||
SpanElement result = new SpanElement()
|
||||
..id = "addResult"
|
||||
..style.fontSize = "14px"
|
||||
..style.marginLeft = "10px";
|
||||
output.append(result);
|
||||
}
|
||||
|
||||
void _onAddClick(MouseEvent e) {
|
||||
_validate();
|
||||
|
||||
InputElement num1 = querySelector("#add1");
|
||||
InputElement num2 = querySelector("#add2");
|
||||
SpanElement result = querySelector("#addResult");
|
||||
|
||||
_calculatorClient
|
||||
.add(int.parse(num1.value), int.parse(num2.value))
|
||||
.then((int n) {
|
||||
result.text = "$n";
|
||||
});
|
||||
}
|
||||
|
||||
void _buildCalculatorComponent() {
|
||||
output.append(new HeadingElement.h3()..text = "Calculator");
|
||||
InputElement num1 = new InputElement()
|
||||
..id = "calc1"
|
||||
..type = "number"
|
||||
..style.fontSize = "14px"
|
||||
..style.width = "50px";
|
||||
output.append(num1);
|
||||
SelectElement op = new SelectElement()
|
||||
..id = "calcOp"
|
||||
..multiple = false
|
||||
..selectedIndex = 0
|
||||
..style.fontSize = "16px"
|
||||
..style.marginLeft = "10px"
|
||||
..style.width = "50px";
|
||||
OptionElement addOp = new OptionElement()
|
||||
..text = "+"
|
||||
..value = Operation.ADD.toString();
|
||||
op.add(addOp, 0);
|
||||
OptionElement subtractOp = new OptionElement()
|
||||
..text = "-"
|
||||
..value = Operation.SUBTRACT.toString();
|
||||
op.add(subtractOp, 1);
|
||||
OptionElement multiplyOp = new OptionElement()
|
||||
..text = "*"
|
||||
..value = Operation.MULTIPLY.toString();
|
||||
op.add(multiplyOp, 2);
|
||||
OptionElement divideOp = new OptionElement()
|
||||
..text = "/"
|
||||
..value = Operation.DIVIDE.toString();
|
||||
op.add(divideOp, 3);
|
||||
output.append(op);
|
||||
InputElement num2 = new InputElement()
|
||||
..id = "calc2"
|
||||
..type = "number"
|
||||
..style.fontSize = "14px"
|
||||
..style.width = "50px"
|
||||
..style.marginLeft = "10px";
|
||||
output.append(num2);
|
||||
ButtonElement calcButton = new ButtonElement()
|
||||
..text = "="
|
||||
..style.fontSize = "14px"
|
||||
..style.marginLeft = "10px"
|
||||
..onClick.listen(_onCalcClick);
|
||||
output.append(calcButton);
|
||||
SpanElement result = new SpanElement()
|
||||
..id = "calcResult"
|
||||
..style.fontSize = "14px"
|
||||
..style.marginLeft = "10px";
|
||||
output.append(result);
|
||||
output.append(new BRElement());
|
||||
output.append(new BRElement());
|
||||
LabelElement logIdLabel = new LabelElement()
|
||||
..text = "Log ID:"
|
||||
..style.fontSize = "14px";
|
||||
output.append(logIdLabel);
|
||||
InputElement logId = new InputElement()
|
||||
..id = "logId"
|
||||
..type = "number"
|
||||
..value = "1"
|
||||
..style.fontSize = "14px"
|
||||
..style.width = "50px"
|
||||
..style.marginLeft = "10px";
|
||||
output.append(logId);
|
||||
LabelElement commentLabel = new LabelElement()
|
||||
..text = "Comment:"
|
||||
..style.fontSize = "14px"
|
||||
..style.marginLeft = "10px";
|
||||
output.append(commentLabel);
|
||||
InputElement comment = new InputElement()
|
||||
..id = "comment"
|
||||
..style.fontSize = "14px"
|
||||
..style.width = "100px"
|
||||
..style.marginLeft = "10px";
|
||||
output.append(comment);
|
||||
}
|
||||
|
||||
void _onCalcClick(MouseEvent e) {
|
||||
_validate();
|
||||
|
||||
InputElement num1 = querySelector("#calc1");
|
||||
InputElement num2 = querySelector("#calc2");
|
||||
SelectElement op = querySelector("#calcOp");
|
||||
SpanElement result = querySelector("#calcResult");
|
||||
InputElement logId = querySelector("#logId");
|
||||
InputElement comment = querySelector("#comment");
|
||||
|
||||
int logIdValue = int.parse(logId.value);
|
||||
logId.value = (logIdValue + 1).toString();
|
||||
|
||||
Work work = new Work();
|
||||
work.num1 = int.parse(num1.value);
|
||||
work.num2 = int.parse(num2.value);
|
||||
work.op = int.parse(op.options[op.selectedIndex].value);
|
||||
work.comment = comment.value;
|
||||
|
||||
_calculatorClient.calculate(logIdValue, work).then((int n) {
|
||||
result.text = "$n";
|
||||
});
|
||||
}
|
||||
|
||||
void _buildGetStructComponent() {
|
||||
output.append(new HeadingElement.h3()..text = "Get Struct");
|
||||
LabelElement logIdLabel = new LabelElement()
|
||||
..text = "Struct Key:"
|
||||
..style.fontSize = "14px";
|
||||
output.append(logIdLabel);
|
||||
InputElement logId = new InputElement()
|
||||
..id = "structKey"
|
||||
..type = "number"
|
||||
..value = "1"
|
||||
..style.fontSize = "14px"
|
||||
..style.width = "50px"
|
||||
..style.marginLeft = "10px";
|
||||
output.append(logId);
|
||||
ButtonElement getStructButton = new ButtonElement()
|
||||
..text = "GET"
|
||||
..style.fontSize = "14px"
|
||||
..style.marginLeft = "10px"
|
||||
..onClick.listen(_onGetStructClick);
|
||||
output.append(getStructButton);
|
||||
output.append(new BRElement());
|
||||
output.append(new BRElement());
|
||||
TextAreaElement result = new TextAreaElement()
|
||||
..id = "getStructResult"
|
||||
..style.fontSize = "14px"
|
||||
..style.width = "300px"
|
||||
..style.height = "50px"
|
||||
..style.marginLeft = "10px";
|
||||
output.append(result);
|
||||
}
|
||||
|
||||
void _onGetStructClick(MouseEvent e) {
|
||||
_validate();
|
||||
|
||||
InputElement structKey = querySelector("#structKey");
|
||||
TextAreaElement result = querySelector("#getStructResult");
|
||||
|
||||
_calculatorClient
|
||||
.getStruct(int.parse(structKey.value))
|
||||
.then((SharedStruct s) {
|
||||
result.text = "${s.toString()}";
|
||||
});
|
||||
}
|
||||
}
|
36
vendor/git.apache.org/thrift.git/tutorial/dart/client/web/index.html
generated
vendored
Normal file
36
vendor/git.apache.org/thrift.git/tutorial/dart/client/web/index.html
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
<!--
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Thrift Tutorial</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
<script async src="client.dart" type="application/dart"></script>
|
||||
<script async src="packages/browser/dart.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="output"></div>
|
||||
|
||||
</body>
|
||||
</html>
|
33
vendor/git.apache.org/thrift.git/tutorial/dart/client/web/styles.css
generated
vendored
Normal file
33
vendor/git.apache.org/thrift.git/tutorial/dart/client/web/styles.css
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
@import url(https://fonts.googleapis.com/css?family=Roboto);
|
||||
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 10px;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
}
|
||||
|
||||
h3 {
|
||||
border-bottom: solid;
|
||||
border-width: thin;
|
||||
padding-top: 20px;
|
||||
}
|
2
vendor/git.apache.org/thrift.git/tutorial/dart/console_client/.analysis_options
generated
vendored
Normal file
2
vendor/git.apache.org/thrift.git/tutorial/dart/console_client/.analysis_options
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
analyzer:
|
||||
strong-mode: true
|
149
vendor/git.apache.org/thrift.git/tutorial/dart/console_client/bin/main.dart
generated
vendored
Normal file
149
vendor/git.apache.org/thrift.git/tutorial/dart/console_client/bin/main.dart
generated
vendored
Normal file
|
@ -0,0 +1,149 @@
|
|||
/// Licensed to the Apache Software Foundation (ASF) under one
|
||||
/// or more contributor license agreements. See the NOTICE file
|
||||
/// distributed with this work for additional information
|
||||
/// regarding copyright ownership. The ASF licenses this file
|
||||
/// to you under the Apache License, Version 2.0 (the
|
||||
/// "License"); you may not use this file except in compliance
|
||||
/// with the License. You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing,
|
||||
/// software distributed under the License is distributed on an
|
||||
/// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
/// KIND, either express or implied. See the License for the
|
||||
/// specific language governing permissions and limitations
|
||||
/// under the License.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:thrift/thrift.dart';
|
||||
import 'package:thrift/thrift_console.dart';
|
||||
import 'package:tutorial/tutorial.dart';
|
||||
|
||||
TTransport _transport;
|
||||
Calculator _calculator;
|
||||
int logid = 0;
|
||||
|
||||
const Map<String, int> operationLookup = const {
|
||||
'+': Operation.ADD,
|
||||
'-': Operation.SUBTRACT,
|
||||
'*': Operation.MULTIPLY,
|
||||
'/': Operation.DIVIDE
|
||||
};
|
||||
|
||||
main(List<String> args) {
|
||||
Logger.root.level = Level.ALL;
|
||||
Logger.root.onRecord.listen((LogRecord rec) {
|
||||
print('${rec.level.name}: ${rec.time}: ${rec.message}');
|
||||
});
|
||||
|
||||
var parser = new ArgParser();
|
||||
parser.addOption('port', defaultsTo: '9090', help: 'The port to connect to');
|
||||
|
||||
ArgResults results;
|
||||
try {
|
||||
results = parser.parse(args);
|
||||
} catch (e) {
|
||||
results = null;
|
||||
}
|
||||
|
||||
if (results == null) {
|
||||
print(parser.usage);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int port = int.parse(results['port']);
|
||||
|
||||
_initConnection(port).then((_) => _run());
|
||||
}
|
||||
|
||||
Future _initConnection(int port) async {
|
||||
var socket = await Socket.connect('127.0.0.1', port);
|
||||
_transport = new TAsyncClientSocketTransport(
|
||||
new TTcpSocket(socket), new TMessageReader(new TBinaryProtocolFactory()));
|
||||
TProtocol protocol = new TBinaryProtocol(_transport);
|
||||
await _transport.open();
|
||||
|
||||
_calculator = new CalculatorClient(protocol);
|
||||
}
|
||||
|
||||
Future _run() async {
|
||||
_help();
|
||||
|
||||
while (true) {
|
||||
stdout.write("> ");
|
||||
var input = stdin.readLineSync();
|
||||
var parts = input.split(' ');
|
||||
var command = parts[0];
|
||||
var args = parts.length > 1 ? parts.sublist(1) : [];
|
||||
|
||||
switch (command) {
|
||||
case 'ping':
|
||||
await _ping();
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
await _add(int.parse(args[0]), int.parse(args[1]));
|
||||
break;
|
||||
|
||||
case 'calc':
|
||||
int op = operationLookup[args[1]];
|
||||
if (!Operation.VALID_VALUES.contains(op)) {
|
||||
stdout.writeln('Unknown operator ${args[1]}');
|
||||
break;
|
||||
}
|
||||
|
||||
var work = new Work()
|
||||
..num1 = int.parse(args[0])
|
||||
..op = op
|
||||
..num2 = int.parse(args[2])
|
||||
..comment = args.length > 3 ? args[3] : '';
|
||||
|
||||
await _calc(work);
|
||||
break;
|
||||
|
||||
case 'struct':
|
||||
await _struct(int.parse(args[0]));
|
||||
break;
|
||||
|
||||
case 'help':
|
||||
default:
|
||||
_help();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _help() {
|
||||
stdout.writeln('Commands:');
|
||||
stdout.writeln(' help');
|
||||
stdout.writeln(' ping');
|
||||
stdout.writeln(' add x y');
|
||||
stdout.writeln(' calc x op y [comment]');
|
||||
stdout.writeln(' struct id');
|
||||
stdout.writeln('');
|
||||
}
|
||||
|
||||
Future _ping() async {
|
||||
await _calculator.ping();
|
||||
stdout.writeln('ping succeeded');
|
||||
}
|
||||
|
||||
Future _add(int x, int y) async {
|
||||
int result = await _calculator.add(x, y);
|
||||
stdout.writeln('= $result');
|
||||
}
|
||||
|
||||
Future _calc(Work work) async {
|
||||
int result = await _calculator.calculate(logid++, work);
|
||||
stdout.writeln('= $result');
|
||||
}
|
||||
|
||||
Future _struct(int key) async {
|
||||
var struct = await _calculator.getStruct(key);
|
||||
stdout.writeln(struct.toString());
|
||||
}
|
36
vendor/git.apache.org/thrift.git/tutorial/dart/console_client/pubspec.yaml
generated
vendored
Normal file
36
vendor/git.apache.org/thrift.git/tutorial/dart/console_client/pubspec.yaml
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# 'License'); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
name: tutorial_console_client
|
||||
version: 0.10.0
|
||||
description: >
|
||||
A Dart console client to implementation of the Apache Thrift tutorial
|
||||
author: Apache Thrift Developers <dev@thrift.apache.org>
|
||||
homepage: http://thrift.apache.org
|
||||
|
||||
environment:
|
||||
sdk: ">=1.13.0 <2.0.0"
|
||||
|
||||
dependencies:
|
||||
args: ^0.13.0
|
||||
collection: ^1.1.0
|
||||
shared:
|
||||
path: ../gen-dart/shared
|
||||
thrift:
|
||||
path: ../../../lib/dart
|
||||
tutorial:
|
||||
path: ../gen-dart/tutorial
|
2
vendor/git.apache.org/thrift.git/tutorial/dart/server/.analysis_options
generated
vendored
Normal file
2
vendor/git.apache.org/thrift.git/tutorial/dart/server/.analysis_options
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
analyzer:
|
||||
strong-mode: true
|
163
vendor/git.apache.org/thrift.git/tutorial/dart/server/bin/main.dart
generated
vendored
Normal file
163
vendor/git.apache.org/thrift.git/tutorial/dart/server/bin/main.dart
generated
vendored
Normal file
|
@ -0,0 +1,163 @@
|
|||
/// Licensed to the Apache Software Foundation (ASF) under one
|
||||
/// or more contributor license agreements. See the NOTICE file
|
||||
/// distributed with this work for additional information
|
||||
/// regarding copyright ownership. The ASF licenses this file
|
||||
/// to you under the Apache License, Version 2.0 (the
|
||||
/// "License"); you may not use this file except in compliance
|
||||
/// with the License. You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing,
|
||||
/// software distributed under the License is distributed on an
|
||||
/// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
/// KIND, either express or implied. See the License for the
|
||||
/// specific language governing permissions and limitations
|
||||
/// under the License.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:thrift/thrift.dart';
|
||||
import 'package:thrift/thrift_console.dart';
|
||||
import 'package:tutorial/tutorial.dart';
|
||||
import 'package:shared/shared.dart';
|
||||
|
||||
TProtocol _protocol;
|
||||
TProcessor _processor;
|
||||
WebSocket _webSocket;
|
||||
|
||||
main(List<String> args) {
|
||||
Logger.root.level = Level.ALL;
|
||||
Logger.root.onRecord.listen((LogRecord rec) {
|
||||
print('${rec.level.name}: ${rec.time}: ${rec.message}');
|
||||
});
|
||||
|
||||
var parser = new ArgParser();
|
||||
parser.addOption('port', defaultsTo: '9090', help: 'The port to listen on');
|
||||
parser.addOption('type',
|
||||
defaultsTo: 'ws',
|
||||
allowed: ['ws', 'tcp'],
|
||||
help: 'The type of socket',
|
||||
allowedHelp: {'ws': 'WebSocket', 'tcp': 'TCP Socket'});
|
||||
|
||||
ArgResults results;
|
||||
try {
|
||||
results = parser.parse(args);
|
||||
} catch (e) {
|
||||
results = null;
|
||||
}
|
||||
|
||||
if (results == null) {
|
||||
print(parser.usage);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int port = int.parse(results['port']);
|
||||
String socketType = results['type'];
|
||||
|
||||
if (socketType == 'tcp') {
|
||||
_runTcpServer(port);
|
||||
} else if (socketType == 'ws') {
|
||||
_runWebSocketServer(port);
|
||||
}
|
||||
}
|
||||
|
||||
Future _runWebSocketServer(int port) async {
|
||||
var httpServer = await HttpServer.bind('127.0.0.1', port);
|
||||
print('listening for WebSocket connections on $port');
|
||||
|
||||
httpServer.listen((HttpRequest request) async {
|
||||
if (request.uri.path == '/ws') {
|
||||
_webSocket = await WebSocketTransformer.upgrade(request);
|
||||
await _initProcessor(new TWebSocket(_webSocket));
|
||||
} else {
|
||||
print('Invalid path: ${request.uri.path}');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future _runTcpServer(int port) async {
|
||||
var serverSocket = await ServerSocket.bind('127.0.0.1', port);
|
||||
print('listening for TCP connections on $port');
|
||||
|
||||
Socket socket = await serverSocket.first;
|
||||
await _initProcessor(new TTcpSocket(socket));
|
||||
}
|
||||
|
||||
Future _initProcessor(TSocket socket) async {
|
||||
TServerSocketTransport transport = new TServerSocketTransport(socket);
|
||||
transport.onIncomingMessage.listen(_processMessage);
|
||||
_processor = new CalculatorProcessor(new CalculatorServer());
|
||||
_protocol = new TBinaryProtocol(transport);
|
||||
await _protocol.transport.open();
|
||||
|
||||
print('connected');
|
||||
}
|
||||
|
||||
Future _processMessage(_) async {
|
||||
_processor.process(_protocol, _protocol);
|
||||
}
|
||||
|
||||
class CalculatorServer implements Calculator {
|
||||
final Map<int, SharedStruct> _log = {};
|
||||
|
||||
Future ping() async {
|
||||
print('ping()');
|
||||
}
|
||||
|
||||
Future<int> add(int num1, int num2) async {
|
||||
print('add($num1, $num2)');
|
||||
|
||||
return num1 + num2;
|
||||
}
|
||||
|
||||
Future<int> calculate(int logid, Work work) async {
|
||||
print('calulate($logid, ${work.toString()})');
|
||||
|
||||
int val;
|
||||
|
||||
switch (work.op) {
|
||||
case Operation.ADD:
|
||||
val = work.num1 + work.num2;
|
||||
break;
|
||||
|
||||
case Operation.SUBTRACT:
|
||||
val = work.num1 - work.num2;
|
||||
break;
|
||||
|
||||
case Operation.MULTIPLY:
|
||||
val = work.num1 * work.num2;
|
||||
break;
|
||||
|
||||
case Operation.DIVIDE:
|
||||
if (work.num2 == 0) {
|
||||
var x = new InvalidOperation();
|
||||
x.whatOp = work.op;
|
||||
x.why = 'Cannot divide by 0';
|
||||
throw x;
|
||||
}
|
||||
val = (work.num1 / work.num2).floor();
|
||||
break;
|
||||
}
|
||||
|
||||
var log = new SharedStruct();
|
||||
log.key = logid;
|
||||
log.value = '$val "${work.comment}"';
|
||||
this._log[logid] = log;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
Future zip() async {
|
||||
print('zip()');
|
||||
}
|
||||
|
||||
Future<SharedStruct> getStruct(int key) async {
|
||||
print('getStruct($key)');
|
||||
|
||||
return _log[key];
|
||||
}
|
||||
}
|
34
vendor/git.apache.org/thrift.git/tutorial/dart/server/pubspec.yaml
generated
vendored
Normal file
34
vendor/git.apache.org/thrift.git/tutorial/dart/server/pubspec.yaml
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# 'License'); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
name: tutorial_server
|
||||
version: 0.10.0
|
||||
description: A Dart server to support the Apache Thrift tutorial
|
||||
author: Apache Thrift Developers <dev@thrift.apache.org>
|
||||
homepage: http://thrift.apache.org
|
||||
|
||||
environment:
|
||||
sdk: ">=1.13.0 <2.0.0"
|
||||
|
||||
dependencies:
|
||||
args: ^0.13.0
|
||||
shared:
|
||||
path: ../gen-dart/shared
|
||||
thrift:
|
||||
path: ../../../lib/dart
|
||||
tutorial:
|
||||
path: ../gen-dart/tutorial
|
114
vendor/git.apache.org/thrift.git/tutorial/delphi/DelphiClient/DelphiClient.dpr
generated
vendored
Normal file
114
vendor/git.apache.org/thrift.git/tutorial/delphi/DelphiClient/DelphiClient.dpr
generated
vendored
Normal file
|
@ -0,0 +1,114 @@
|
|||
(*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*)
|
||||
program DelphiClient;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
{$D 'Copyright (c) 2012 The Apache Software Foundation'}
|
||||
|
||||
uses
|
||||
SysUtils,
|
||||
Generics.Collections,
|
||||
Thrift in '..\..\..\lib\delphi\src\Thrift.pas',
|
||||
Thrift.Collections in '..\..\..\lib\delphi\src\Thrift.Collections.pas',
|
||||
Thrift.Console in '..\..\..\lib\delphi\src\Thrift.Console.pas',
|
||||
Thrift.Utils in '..\..\..\lib\delphi\src\Thrift.Utils.pas',
|
||||
Thrift.Stream in '..\..\..\lib\delphi\src\Thrift.Stream.pas',
|
||||
Thrift.Protocol in '..\..\..\lib\delphi\src\Thrift.Protocol.pas',
|
||||
Thrift.Server in '..\..\..\lib\delphi\src\Thrift.Server.pas',
|
||||
Thrift.Transport in '..\..\..\lib\delphi\src\Thrift.Transport.pas',
|
||||
Shared in '..\..\gen-delphi\Shared.pas',
|
||||
Tutorial in '..\..\gen-delphi\Tutorial.pas';
|
||||
|
||||
|
||||
type
|
||||
DelphiTutorialClient = class
|
||||
public
|
||||
class procedure Main;
|
||||
end;
|
||||
|
||||
|
||||
//--- DelphiTutorialClient ---------------------------------------
|
||||
|
||||
|
||||
class procedure DelphiTutorialClient.Main;
|
||||
var transport : ITransport;
|
||||
protocol : IProtocol;
|
||||
client : TCalculator.Iface;
|
||||
work : IWork;
|
||||
sum, quotient, diff : Integer;
|
||||
log : ISharedStruct;
|
||||
begin
|
||||
try
|
||||
transport := TSocketImpl.Create( 'localhost', 9090);
|
||||
protocol := TBinaryProtocolImpl.Create( transport);
|
||||
client := TCalculator.TClient.Create( protocol);
|
||||
|
||||
transport.Open;
|
||||
|
||||
client.ping;
|
||||
Console.WriteLine('ping()');
|
||||
|
||||
sum := client.add( 1, 1);
|
||||
Console.WriteLine( Format( '1+1=%d', [sum]));
|
||||
|
||||
work := TWorkImpl.Create;
|
||||
|
||||
work.Op := TOperation.DIVIDE;
|
||||
work.Num1 := 1;
|
||||
work.Num2 := 0;
|
||||
try
|
||||
quotient := client.calculate(1, work);
|
||||
Console.WriteLine( 'Whoa we can divide by 0');
|
||||
Console.WriteLine( Format('1/0=%d',[quotient]));
|
||||
except
|
||||
on io: TInvalidOperation
|
||||
do Console.WriteLine( 'Invalid operation: ' + io.Why);
|
||||
end;
|
||||
|
||||
work.Op := TOperation.SUBTRACT;
|
||||
work.Num1 := 15;
|
||||
work.Num2 := 10;
|
||||
try
|
||||
diff := client.calculate( 1, work);
|
||||
Console.WriteLine( Format('15-10=%d', [diff]));
|
||||
except
|
||||
on io: TInvalidOperation
|
||||
do Console.WriteLine( 'Invalid operation: ' + io.Why);
|
||||
end;
|
||||
|
||||
log := client.getStruct(1);
|
||||
Console.WriteLine( Format( 'Check log: %s', [log.Value]));
|
||||
|
||||
transport.Close();
|
||||
|
||||
except
|
||||
on e : Exception
|
||||
do Console.WriteLine( e.ClassName+': '+e.Message);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
begin
|
||||
try
|
||||
DelphiTutorialClient.Main;
|
||||
except
|
||||
on E: Exception do
|
||||
Writeln(E.ClassName, ': ', E.Message);
|
||||
end;
|
||||
end.
|
119
vendor/git.apache.org/thrift.git/tutorial/delphi/DelphiClient/DelphiClient.dproj
generated
vendored
Normal file
119
vendor/git.apache.org/thrift.git/tutorial/delphi/DelphiClient/DelphiClient.dproj
generated
vendored
Normal file
|
@ -0,0 +1,119 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{2B8FB3A1-2F9E-4883-8C53-0F56220B34F6}</ProjectGuid>
|
||||
<MainSource>DelphiClient.dpr</MainSource>
|
||||
<ProjectVersion>12.3</ProjectVersion>
|
||||
<Basis>True</Basis>
|
||||
<Config Condition="'$(Config)'==''">Debug</Config>
|
||||
<Platform>Win32</Platform>
|
||||
<AppType>Console</AppType>
|
||||
<FrameworkType>None</FrameworkType>
|
||||
<DCC_DCCCompiler>DCC32</DCC_DCCCompiler>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Config)'=='Basis' or '$(Base)'!=''">
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_1)'!=''">
|
||||
<Cfg_1>true</Cfg_1>
|
||||
<CfgParent>Base</CfgParent>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''">
|
||||
<Cfg_2>true</Cfg_2>
|
||||
<CfgParent>Base</CfgParent>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Base)'!=''">
|
||||
<DCC_UnitSearchPath>..\..\..\lib\delphi\src;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
|
||||
<DCC_ImageBase>00400000</DCC_ImageBase>
|
||||
<DCC_DcuOutput>.\dcu\$(Config)\$(Platform)</DCC_DcuOutput>
|
||||
<DCC_UnitAlias>WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;$(DCC_UnitAlias)</DCC_UnitAlias>
|
||||
<DCC_ExeOutput>..\bin\$(Config)\$(Platform)</DCC_ExeOutput>
|
||||
<DCC_E>false</DCC_E>
|
||||
<DCC_N>false</DCC_N>
|
||||
<DCC_S>false</DCC_S>
|
||||
<DCC_F>false</DCC_F>
|
||||
<DCC_K>false</DCC_K>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Cfg_1)'!=''">
|
||||
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
|
||||
<DCC_Optimize>false</DCC_Optimize>
|
||||
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Cfg_2)'!=''">
|
||||
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
|
||||
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
|
||||
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
|
||||
<DCC_DebugInformation>false</DCC_DebugInformation>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<DelphiCompile Include="DelphiClient.dpr">
|
||||
<MainSource>MainSource</MainSource>
|
||||
</DelphiCompile>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Collections.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Console.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Utils.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Stream.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Protocol.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Server.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Transport.pas"/>
|
||||
<DCCReference Include="..\..\gen-delphi\Shared.pas"/>
|
||||
<DCCReference Include="..\..\gen-delphi\Tutorial.pas"/>
|
||||
<BuildConfiguration Include="Release">
|
||||
<Key>Cfg_2</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
</BuildConfiguration>
|
||||
<BuildConfiguration Include="Basis">
|
||||
<Key>Base</Key>
|
||||
</BuildConfiguration>
|
||||
<BuildConfiguration Include="Debug">
|
||||
<Key>Cfg_1</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
</BuildConfiguration>
|
||||
</ItemGroup>
|
||||
<Import Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')" Project="$(BDS)\Bin\CodeGear.Delphi.Targets"/>
|
||||
<Import Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')" Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj"/>
|
||||
<ProjectExtensions>
|
||||
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
|
||||
<Borland.ProjectType/>
|
||||
<BorlandProject>
|
||||
<Delphi.Personality>
|
||||
<VersionInfo>
|
||||
<VersionInfo Name="IncludeVerInfo">True</VersionInfo>
|
||||
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
|
||||
<VersionInfo Name="MajorVer">1</VersionInfo>
|
||||
<VersionInfo Name="MinorVer">0</VersionInfo>
|
||||
<VersionInfo Name="Release">0</VersionInfo>
|
||||
<VersionInfo Name="Build">0</VersionInfo>
|
||||
<VersionInfo Name="Debug">False</VersionInfo>
|
||||
<VersionInfo Name="PreRelease">False</VersionInfo>
|
||||
<VersionInfo Name="Special">False</VersionInfo>
|
||||
<VersionInfo Name="Private">False</VersionInfo>
|
||||
<VersionInfo Name="DLL">False</VersionInfo>
|
||||
<VersionInfo Name="Locale">1033</VersionInfo>
|
||||
<VersionInfo Name="CodePage">1252</VersionInfo>
|
||||
</VersionInfo>
|
||||
<VersionInfoKeys>
|
||||
<VersionInfoKeys Name="CompanyName"/>
|
||||
<VersionInfoKeys Name="FileDescription">Thrift Tutorial</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="InternalName">DelphiClient</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="LegalCopyright">Copyright © 2012 The Apache Software Foundation</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="LegalTrademarks"/>
|
||||
<VersionInfoKeys Name="OriginalFilename">DelphiClient.exe</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="ProductName">Thrift</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="Comments"/>
|
||||
</VersionInfoKeys>
|
||||
<Source>
|
||||
<Source Name="MainSource">DelphiClient.dpr</Source>
|
||||
</Source>
|
||||
</Delphi.Personality>
|
||||
<Platforms>
|
||||
<Platform value="Win32">True</Platform>
|
||||
</Platforms>
|
||||
</BorlandProject>
|
||||
<ProjectFileVersion>12</ProjectFileVersion>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
173
vendor/git.apache.org/thrift.git/tutorial/delphi/DelphiServer/DelphiServer.dpr
generated
vendored
Normal file
173
vendor/git.apache.org/thrift.git/tutorial/delphi/DelphiServer/DelphiServer.dpr
generated
vendored
Normal file
|
@ -0,0 +1,173 @@
|
|||
(*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*)
|
||||
program DelphiServer;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
{$D 'Copyright (c) 2012 The Apache Software Foundation'}
|
||||
|
||||
{$Q+} // throws exceptions on numeric overflows
|
||||
|
||||
uses
|
||||
SysUtils,
|
||||
Generics.Collections,
|
||||
Thrift in '..\..\..\lib\delphi\src\Thrift.pas',
|
||||
Thrift.Collections in '..\..\..\lib\delphi\src\Thrift.Collections.pas',
|
||||
Thrift.Console in '..\..\..\lib\delphi\src\Thrift.Console.pas',
|
||||
Thrift.Utils in '..\..\..\lib\delphi\src\Thrift.Utils.pas',
|
||||
Thrift.Stream in '..\..\..\lib\delphi\src\Thrift.Stream.pas',
|
||||
Thrift.Protocol in '..\..\..\lib\delphi\src\Thrift.Protocol.pas',
|
||||
Thrift.Server in '..\..\..\lib\delphi\src\Thrift.Server.pas',
|
||||
Thrift.Transport in '..\..\..\lib\delphi\src\Thrift.Transport.pas',
|
||||
Shared in '..\..\gen-delphi\Shared.pas',
|
||||
Tutorial in '..\..\gen-delphi\Tutorial.pas';
|
||||
|
||||
|
||||
type
|
||||
TCalculatorHandler = class( TInterfacedObject, TCalculator.Iface)
|
||||
protected
|
||||
FLog : TDictionary< Integer, ISharedStruct>;
|
||||
|
||||
// TSharedService.Iface
|
||||
function getStruct(key: Integer): ISharedStruct;
|
||||
|
||||
// TCalculator.Iface
|
||||
procedure ping();
|
||||
function add(num1: Integer; num2: Integer): Integer;
|
||||
function calculate(logid: Integer; const w: IWork): Integer;
|
||||
procedure zip();
|
||||
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
|
||||
end;
|
||||
|
||||
DelphiTutorialServer = class
|
||||
public
|
||||
class procedure Main;
|
||||
end;
|
||||
|
||||
|
||||
//--- TCalculatorHandler ---------------------------------------------------
|
||||
|
||||
|
||||
constructor TCalculatorHandler.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
FLog := TDictionary< Integer, ISharedStruct>.Create();
|
||||
end;
|
||||
|
||||
|
||||
destructor TCalculatorHandler.Destroy;
|
||||
begin
|
||||
try
|
||||
FreeAndNil( FLog);
|
||||
finally
|
||||
inherited Destroy;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TCalculatorHandler.ping;
|
||||
begin
|
||||
Console.WriteLine( 'ping()');
|
||||
end;
|
||||
|
||||
|
||||
function TCalculatorHandler.add(num1: Integer; num2: Integer): Integer;
|
||||
begin
|
||||
Console.WriteLine( Format( 'add( %d, %d)', [num1, num2]));
|
||||
result := num1 + num2;
|
||||
end;
|
||||
|
||||
|
||||
function TCalculatorHandler.calculate(logid: Integer; const w: IWork): Integer;
|
||||
var entry : ISharedStruct;
|
||||
begin
|
||||
try
|
||||
Console.WriteLine( Format('calculate( %d, [%d,%d,%d])', [logid, Ord(w.Op), w.Num1, w.Num2]));
|
||||
|
||||
case w.Op of
|
||||
TOperation.ADD : result := w.Num1 + w.Num2;
|
||||
TOperation.SUBTRACT : result := w.Num1 - w.Num2;
|
||||
TOperation.MULTIPLY : result := w.Num1 * w.Num2;
|
||||
TOperation.DIVIDE : result := Round( w.Num1 / w.Num2);
|
||||
else
|
||||
raise TInvalidOperation.Create( Ord(w.Op), 'Unknown operation');
|
||||
end;
|
||||
|
||||
except
|
||||
on e:Thrift.TException do raise; // let Thrift Exceptions pass through
|
||||
on e:Exception do raise TInvalidOperation.Create( Ord(w.Op), e.Message); // repackage all other
|
||||
end;
|
||||
|
||||
entry := TSharedStructImpl.Create;
|
||||
entry.Key := logid;
|
||||
entry.Value := IntToStr( result);
|
||||
FLog.AddOrSetValue( logid, entry);
|
||||
end;
|
||||
|
||||
|
||||
function TCalculatorHandler.getStruct(key: Integer): ISharedStruct;
|
||||
begin
|
||||
Console.WriteLine( Format( 'getStruct(%d)', [key]));
|
||||
result := FLog[key];
|
||||
end;
|
||||
|
||||
|
||||
procedure TCalculatorHandler.zip;
|
||||
begin
|
||||
Console.WriteLine( 'zip()');
|
||||
end;
|
||||
|
||||
|
||||
//--- DelphiTutorialServer ----------------------------------------------------------------------
|
||||
|
||||
|
||||
class procedure DelphiTutorialServer.Main;
|
||||
var handler : TCalculator.Iface;
|
||||
processor : IProcessor;
|
||||
transport : IServerTransport;
|
||||
server : IServer;
|
||||
begin
|
||||
try
|
||||
handler := TCalculatorHandler.Create;
|
||||
processor := TCalculator.TProcessorImpl.Create( handler);
|
||||
transport := TServerSocketImpl.Create( 9090);
|
||||
server := TSimpleServer.Create( processor, transport);
|
||||
|
||||
Console.WriteLine( 'Starting the server...');
|
||||
server.Serve();
|
||||
|
||||
except
|
||||
on e: Exception do Console.WriteLine( e.Message);
|
||||
end;
|
||||
|
||||
Console.WriteLine('done.');
|
||||
end;
|
||||
|
||||
|
||||
begin
|
||||
try
|
||||
DelphiTutorialServer.Main;
|
||||
except
|
||||
on E: Exception do
|
||||
Writeln(E.ClassName, ': ', E.Message);
|
||||
end;
|
||||
end.
|
118
vendor/git.apache.org/thrift.git/tutorial/delphi/DelphiServer/DelphiServer.dproj
generated
vendored
Normal file
118
vendor/git.apache.org/thrift.git/tutorial/delphi/DelphiServer/DelphiServer.dproj
generated
vendored
Normal file
|
@ -0,0 +1,118 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{2B8FB3A1-2F9E-4883-8C53-0F56220B34F6}</ProjectGuid>
|
||||
<MainSource>DelphiServer.dpr</MainSource>
|
||||
<ProjectVersion>12.3</ProjectVersion>
|
||||
<Basis>True</Basis>
|
||||
<Config Condition="'$(Config)'==''">Debug</Config>
|
||||
<Platform>Win32</Platform>
|
||||
<AppType>Console</AppType>
|
||||
<FrameworkType>None</FrameworkType>
|
||||
<DCC_DCCCompiler>DCC32</DCC_DCCCompiler>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Config)'=='Basis' or '$(Base)'!=''">
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_1)'!=''">
|
||||
<Cfg_1>true</Cfg_1>
|
||||
<CfgParent>Base</CfgParent>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''">
|
||||
<Cfg_2>true</Cfg_2>
|
||||
<CfgParent>Base</CfgParent>
|
||||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Base)'!=''">
|
||||
<DCC_ImageBase>00400000</DCC_ImageBase>
|
||||
<DCC_DcuOutput>.\dcu\$(Config)\$(Platform)</DCC_DcuOutput>
|
||||
<DCC_UnitAlias>WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;$(DCC_UnitAlias)</DCC_UnitAlias>
|
||||
<DCC_ExeOutput>..\bin\$(Config)\$(Platform)</DCC_ExeOutput>
|
||||
<DCC_E>false</DCC_E>
|
||||
<DCC_N>false</DCC_N>
|
||||
<DCC_S>false</DCC_S>
|
||||
<DCC_F>false</DCC_F>
|
||||
<DCC_K>false</DCC_K>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Cfg_1)'!=''">
|
||||
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
|
||||
<DCC_Optimize>false</DCC_Optimize>
|
||||
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Cfg_2)'!=''">
|
||||
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
|
||||
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
|
||||
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
|
||||
<DCC_DebugInformation>false</DCC_DebugInformation>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<DelphiCompile Include="DelphiServer.dpr">
|
||||
<MainSource>MainSource</MainSource>
|
||||
</DelphiCompile>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Collections.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Console.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Utils.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Stream.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Protocol.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Server.pas"/>
|
||||
<DCCReference Include="..\..\..\lib\delphi\src\Thrift.Transport.pas"/>
|
||||
<DCCReference Include="..\..\gen-delphi\Shared.pas"/>
|
||||
<DCCReference Include="..\..\gen-delphi\Tutorial.pas"/>
|
||||
<BuildConfiguration Include="Release">
|
||||
<Key>Cfg_2</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
</BuildConfiguration>
|
||||
<BuildConfiguration Include="Basis">
|
||||
<Key>Base</Key>
|
||||
</BuildConfiguration>
|
||||
<BuildConfiguration Include="Debug">
|
||||
<Key>Cfg_1</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
</BuildConfiguration>
|
||||
</ItemGroup>
|
||||
<Import Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')" Project="$(BDS)\Bin\CodeGear.Delphi.Targets"/>
|
||||
<Import Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')" Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj"/>
|
||||
<ProjectExtensions>
|
||||
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
|
||||
<Borland.ProjectType/>
|
||||
<BorlandProject>
|
||||
<Delphi.Personality>
|
||||
<VersionInfo>
|
||||
<VersionInfo Name="IncludeVerInfo">True</VersionInfo>
|
||||
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
|
||||
<VersionInfo Name="MajorVer">1</VersionInfo>
|
||||
<VersionInfo Name="MinorVer">0</VersionInfo>
|
||||
<VersionInfo Name="Release">0</VersionInfo>
|
||||
<VersionInfo Name="Build">0</VersionInfo>
|
||||
<VersionInfo Name="Debug">False</VersionInfo>
|
||||
<VersionInfo Name="PreRelease">False</VersionInfo>
|
||||
<VersionInfo Name="Special">False</VersionInfo>
|
||||
<VersionInfo Name="Private">False</VersionInfo>
|
||||
<VersionInfo Name="DLL">False</VersionInfo>
|
||||
<VersionInfo Name="Locale">1033</VersionInfo>
|
||||
<VersionInfo Name="CodePage">1252</VersionInfo>
|
||||
</VersionInfo>
|
||||
<VersionInfoKeys>
|
||||
<VersionInfoKeys Name="CompanyName"/>
|
||||
<VersionInfoKeys Name="FileDescription">Thrift Tutorial</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="InternalName">DelphiServer</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="LegalCopyright">Copyright © 2012 The Apache Software Foundation</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="LegalTrademarks"/>
|
||||
<VersionInfoKeys Name="OriginalFilename">DelphiServer.exe</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="ProductName">Thrift</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="Comments"/>
|
||||
</VersionInfoKeys>
|
||||
<Source>
|
||||
<Source Name="MainSource">DelphiServer.dpr</Source>
|
||||
</Source>
|
||||
</Delphi.Personality>
|
||||
<Platforms>
|
||||
<Platform value="Win32">True</Platform>
|
||||
</Platforms>
|
||||
</BorlandProject>
|
||||
<ProjectFileVersion>12</ProjectFileVersion>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
48
vendor/git.apache.org/thrift.git/tutorial/delphi/Tutorial.groupproj
generated
vendored
Normal file
48
vendor/git.apache.org/thrift.git/tutorial/delphi/Tutorial.groupproj
generated
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{3D042C7F-3EF2-4574-8304-AB7FB79F814C}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Projects Include="DelphiServer\DelphiServer.dproj">
|
||||
<Dependencies/>
|
||||
</Projects>
|
||||
<Projects Include="DelphiClient\DelphiClient.dproj">
|
||||
<Dependencies/>
|
||||
</Projects>
|
||||
</ItemGroup>
|
||||
<ProjectExtensions>
|
||||
<Borland.Personality>Default.Personality.12</Borland.Personality>
|
||||
<Borland.ProjectType/>
|
||||
<BorlandProject>
|
||||
<Default.Personality/>
|
||||
</BorlandProject>
|
||||
</ProjectExtensions>
|
||||
<Target Name="DelphiServer">
|
||||
<MSBuild Projects="DelphiServer\DelphiServer.dproj"/>
|
||||
</Target>
|
||||
<Target Name="DelphiServer:Clean">
|
||||
<MSBuild Projects="DelphiServer\DelphiServer.dproj" Targets="Clean"/>
|
||||
</Target>
|
||||
<Target Name="DelphiServer:Make">
|
||||
<MSBuild Projects="DelphiServer\DelphiServer.dproj" Targets="Make"/>
|
||||
</Target>
|
||||
<Target Name="DelphiClient">
|
||||
<MSBuild Projects="DelphiClient\DelphiClient.dproj"/>
|
||||
</Target>
|
||||
<Target Name="DelphiClient:Clean">
|
||||
<MSBuild Projects="DelphiClient\DelphiClient.dproj" Targets="Clean"/>
|
||||
</Target>
|
||||
<Target Name="DelphiClient:Make">
|
||||
<MSBuild Projects="DelphiClient\DelphiClient.dproj" Targets="Make"/>
|
||||
</Target>
|
||||
<Target Name="Build">
|
||||
<CallTarget Targets="DelphiServer;DelphiClient"/>
|
||||
</Target>
|
||||
<Target Name="Clean">
|
||||
<CallTarget Targets="DelphiServer:Clean;DelphiClient:Clean"/>
|
||||
</Target>
|
||||
<Target Name="Make">
|
||||
<CallTarget Targets="DelphiServer:Make;DelphiClient:Make"/>
|
||||
</Target>
|
||||
<Import Condition="Exists('$(BDS)\Bin\CodeGear.Group.Targets')" Project="$(BDS)\Bin\CodeGear.Group.Targets"/>
|
||||
</Project>
|
8
vendor/git.apache.org/thrift.git/tutorial/erl/README.md
generated
vendored
Normal file
8
vendor/git.apache.org/thrift.git/tutorial/erl/README.md
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
To try things out, run
|
||||
|
||||
% ./server.sh
|
||||
Erlang R14B (erts-5.8.1) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false]
|
||||
|
||||
Eshell V5.8.1 (abort with ^G)
|
||||
> server:start().
|
||||
> client:t().
|
78
vendor/git.apache.org/thrift.git/tutorial/erl/client.erl
generated
vendored
Normal file
78
vendor/git.apache.org/thrift.git/tutorial/erl/client.erl
generated
vendored
Normal file
|
@ -0,0 +1,78 @@
|
|||
%%
|
||||
%% Licensed to the Apache Software Foundation (ASF) under one
|
||||
%% or more contributor license agreements. See the NOTICE file
|
||||
%% distributed with this work for additional information
|
||||
%% regarding copyright ownership. The ASF licenses this file
|
||||
%% to you under the Apache License, Version 2.0 (the
|
||||
%% "License"); you may not use this file except in compliance
|
||||
%% with the License. You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing,
|
||||
%% software distributed under the License is distributed on an
|
||||
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
%% KIND, either express or implied. See the License for the
|
||||
%% specific language governing permissions and limitations
|
||||
%% under the License.
|
||||
%%
|
||||
|
||||
-module(client).
|
||||
|
||||
-include("calculator_thrift.hrl").
|
||||
|
||||
-export([t/0]).
|
||||
|
||||
p(X) ->
|
||||
io:format("~p~n", [X]),
|
||||
ok.
|
||||
|
||||
t() ->
|
||||
Port = 9999,
|
||||
|
||||
{ok, Client0} = thrift_client_util:new("127.0.0.1",
|
||||
Port,
|
||||
calculator_thrift,
|
||||
[]),
|
||||
|
||||
{Client1, {ok, ok}} = thrift_client:call(Client0, ping, []),
|
||||
io:format("ping~n", []),
|
||||
|
||||
{Client2, {ok, Sum}} = thrift_client:call(Client1, add, [1, 1]),
|
||||
io:format("1+1=~p~n", [Sum]),
|
||||
|
||||
{Client3, {ok, Sum1}} = thrift_client:call(Client2, add, [1, 4]),
|
||||
io:format("1+4=~p~n", [Sum1]),
|
||||
|
||||
Work = #work{op=?tutorial_Operation_SUBTRACT,
|
||||
num1=15,
|
||||
num2=10},
|
||||
{Client4, {ok, Diff}} = thrift_client:call(Client3, calculate, [1, Work]),
|
||||
io:format("15-10=~p~n", [Diff]),
|
||||
|
||||
{Client5, {ok, Log}} = thrift_client:call(Client4, getStruct, [1]),
|
||||
io:format("Log: ~p~n", [Log]),
|
||||
|
||||
Client6 =
|
||||
try
|
||||
Work1 = #work{op=?tutorial_Operation_DIVIDE,
|
||||
num1=1,
|
||||
num2=0},
|
||||
{ClientS1, {ok, _Quot}} = thrift_client:call(Client5, calculate, [2, Work1]),
|
||||
|
||||
io:format("LAME: exception handling is broken~n", []),
|
||||
ClientS1
|
||||
catch
|
||||
throw:{ClientS2, Z} ->
|
||||
io:format("Got exception where expecting - the " ++
|
||||
"following is NOT a problem!!!~n"),
|
||||
p(Z),
|
||||
ClientS2
|
||||
end,
|
||||
|
||||
|
||||
{Client7, {ok, ok}} = thrift_client:call(Client6, zip, []),
|
||||
io:format("zip~n", []),
|
||||
|
||||
{_Client8, ok} = thrift_client:close(Client7),
|
||||
ok.
|
1
vendor/git.apache.org/thrift.git/tutorial/erl/client.sh
generated
vendored
Symbolic link
1
vendor/git.apache.org/thrift.git/tutorial/erl/client.sh
generated
vendored
Symbolic link
|
@ -0,0 +1 @@
|
|||
server.sh
|
89
vendor/git.apache.org/thrift.git/tutorial/erl/json_client.erl
generated
vendored
Normal file
89
vendor/git.apache.org/thrift.git/tutorial/erl/json_client.erl
generated
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
%%
|
||||
%% Licensed to the Apache Software Foundation (ASF) under one
|
||||
%% or more contributor license agreements. See the NOTICE file
|
||||
%% distributed with this work for additional information
|
||||
%% regarding copyright ownership. The ASF licenses this file
|
||||
%% to you under the Apache License, Version 2.0 (the
|
||||
%% "License"); you may not use this file except in compliance
|
||||
%% with the License. You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing,
|
||||
%% software distributed under the License is distributed on an
|
||||
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
%% KIND, either express or implied. See the License for the
|
||||
%% specific language governing permissions and limitations
|
||||
%% under the License.
|
||||
%%
|
||||
%% The JSON protocol over HTTP implementation was created by
|
||||
%% Peter Neumark <neumark.peter@gmail.com> based on
|
||||
%% the binary protocol + socket tutorial. Use with the same server
|
||||
%% that the Javascript tutorial uses!
|
||||
|
||||
-module(json_client).
|
||||
|
||||
-include("calculator_thrift.hrl").
|
||||
|
||||
-export([t/0]).
|
||||
|
||||
%% Client constructor for the http transports
|
||||
%% with the json protocol
|
||||
new_client(Host, Path, Service, _Options) ->
|
||||
{ProtoOpts, TransOpts} = {[],[]},
|
||||
TransportFactory = fun() -> thrift_http_transport:new(Host, Path, TransOpts) end,
|
||||
{ok, ProtocolFactory} = thrift_json_protocol:new_protocol_factory(
|
||||
TransportFactory, ProtoOpts),
|
||||
{ok, Protocol} = ProtocolFactory(),
|
||||
thrift_client:new(Protocol, Service).
|
||||
|
||||
p(X) ->
|
||||
io:format("~p~n", [X]),
|
||||
ok.
|
||||
|
||||
t() ->
|
||||
inets:start(),
|
||||
{ok, Client0} = new_client("127.0.0.1:8088", "/thrift/service/tutorial/",
|
||||
calculator_thrift,
|
||||
[]),
|
||||
{Client1, {ok, ok}} = thrift_client:call(Client0, ping, []),
|
||||
io:format("ping~n", []),
|
||||
|
||||
{Client2, {ok, Sum}} = thrift_client:call(Client1, add, [1, 1]),
|
||||
io:format("1+1=~p~n", [Sum]),
|
||||
|
||||
{Client3, {ok, Sum1}} = thrift_client:call(Client2, add, [1, 4]),
|
||||
io:format("1+4=~p~n", [Sum1]),
|
||||
|
||||
Work = #work{op=?tutorial_Operation_SUBTRACT,
|
||||
num1=15,
|
||||
num2=10},
|
||||
{Client4, {ok, Diff}} = thrift_client:call(Client3, calculate, [1, Work]),
|
||||
io:format("15-10=~p~n", [Diff]),
|
||||
|
||||
{Client5, {ok, Log}} = thrift_client:call(Client4, getStruct, [1]),
|
||||
io:format("Log: ~p~n", [Log]),
|
||||
|
||||
Client6 =
|
||||
try
|
||||
Work1 = #work{op=?tutorial_Operation_DIVIDE,
|
||||
num1=1,
|
||||
num2=0},
|
||||
{ClientS1, {ok, _Quot}} = thrift_client:call(Client5, calculate, [2, Work1]),
|
||||
|
||||
io:format("LAME: exception handling is broken~n", []),
|
||||
ClientS1
|
||||
catch
|
||||
throw:{ClientS2, Z} ->
|
||||
io:format("Got exception where expecting - the " ++
|
||||
"following is NOT a problem!!!~n"),
|
||||
p(Z),
|
||||
ClientS2
|
||||
end,
|
||||
|
||||
|
||||
{Client7, {ok, ok}} = thrift_client:call(Client6, zip, []),
|
||||
io:format("zip~n", []),
|
||||
|
||||
{_Client8, ok} = thrift_client:close(Client7),
|
||||
ok.
|
82
vendor/git.apache.org/thrift.git/tutorial/erl/server.erl
generated
vendored
Normal file
82
vendor/git.apache.org/thrift.git/tutorial/erl/server.erl
generated
vendored
Normal file
|
@ -0,0 +1,82 @@
|
|||
%%
|
||||
%% Licensed to the Apache Software Foundation (ASF) under one
|
||||
%% or more contributor license agreements. See the NOTICE file
|
||||
%% distributed with this work for additional information
|
||||
%% regarding copyright ownership. The ASF licenses this file
|
||||
%% to you under the Apache License, Version 2.0 (the
|
||||
%% "License"); you may not use this file except in compliance
|
||||
%% with the License. You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing,
|
||||
%% software distributed under the License is distributed on an
|
||||
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
%% KIND, either express or implied. See the License for the
|
||||
%% specific language governing permissions and limitations
|
||||
%% under the License.
|
||||
%%
|
||||
|
||||
-module(server).
|
||||
|
||||
-include("calculator_thrift.hrl").
|
||||
|
||||
-export([start/0, start/1, handle_function/2,
|
||||
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_Operation_ADD -> Num1 + Num2;
|
||||
?tutorial_Operation_SUBTRACT -> Num1 - Num2;
|
||||
?tutorial_Operation_MULTIPLY -> Num1 * Num2;
|
||||
|
||||
?tutorial_Operation_DIVIDE when Num2 == 0 ->
|
||||
throw(#invalidOperation{whatOp=Op, why="Cannot divide by 0"});
|
||||
?tutorial_Operation_DIVIDE ->
|
||||
Num1 div Num2;
|
||||
|
||||
_Else ->
|
||||
throw(#invalidOperation{whatOp=Op, why="Invalid operation"})
|
||||
end.
|
||||
|
||||
getStruct(Key) ->
|
||||
debug("getStruct(~p)", [Key]),
|
||||
#sharedStruct{key=Key, value="RARG"}.
|
||||
|
||||
zip() ->
|
||||
debug("zip", []),
|
||||
ok.
|
||||
|
||||
%%
|
||||
|
||||
start() ->
|
||||
start(9999).
|
||||
|
||||
start(Port) ->
|
||||
Handler = ?MODULE,
|
||||
thrift_socket_server:start([{handler, Handler},
|
||||
{service, calculator_thrift},
|
||||
{port, Port},
|
||||
{name, tutorial_server}]).
|
||||
|
||||
stop(Server) ->
|
||||
thrift_socket_server:stop(Server).
|
||||
|
||||
handle_function(Function, Args) when is_atom(Function), is_tuple(Args) ->
|
||||
case apply(?MODULE, Function, tuple_to_list(Args)) of
|
||||
ok -> ok;
|
||||
Reply -> {reply, Reply}
|
||||
end.
|
37
vendor/git.apache.org/thrift.git/tutorial/erl/server.sh
generated
vendored
Executable file
37
vendor/git.apache.org/thrift.git/tutorial/erl/server.sh
generated
vendored
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
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
|
||||
../../compiler/cpp/thrift -r --gen erl ../tutorial.thrift
|
||||
fi
|
||||
|
||||
|
||||
erlc -I ${ERL_THRIFT}/include -I ${ERL_THRIFT}/ebin \
|
||||
-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
|
61
vendor/git.apache.org/thrift.git/tutorial/go/Makefile.am
generated
vendored
Normal file
61
vendor/git.apache.org/thrift.git/tutorial/go/Makefile.am
generated
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
THRIFT = $(top_builddir)/compiler/cpp/thrift
|
||||
|
||||
gen-go/tutorial/calculator.go gen-go/shared/shared_service.go: $(top_srcdir)/tutorial/tutorial.thrift
|
||||
$(THRIFT) --gen go -r $<
|
||||
|
||||
all-local: gen-go/tutorial/calculator.go
|
||||
|
||||
|
||||
check: src/git.apache.org/thrift.git/lib/go/thrift
|
||||
$(THRIFT) -r --gen go $(top_srcdir)/tutorial/tutorial.thrift
|
||||
cp -r gen-go/* src/
|
||||
GOPATH=`pwd` $(GO) build ./...
|
||||
GOPATH=`pwd` $(GO) build -o go-tutorial src/*.go
|
||||
GOPATH=`pwd` $(GO) build -o calculator-remote src/tutorial/calculator-remote/calculator-remote.go
|
||||
|
||||
src/git.apache.org/thrift.git/lib/go/thrift:
|
||||
mkdir -p src/git.apache.org/thrift.git/lib/go
|
||||
ln -sf $(realpath $(top_srcdir)/lib/go/thrift) src/git.apache.org/thrift.git/lib/go/thrift
|
||||
|
||||
tutorialserver: all
|
||||
GOPATH=`pwd` $(GO) run src/*.go -server=true
|
||||
|
||||
tutorialclient: all
|
||||
GOPATH=`pwd` $(GO) run src/*.go
|
||||
|
||||
tutorialsecureserver: all
|
||||
GOPATH=`pwd` $(GO) run src/*.go -server=true -secure=true
|
||||
|
||||
tutorialsecureclient: all
|
||||
GOPATH=`pwd` $(GO) run src/*.go -secure=true
|
||||
|
||||
clean-local:
|
||||
$(RM) -r gen-* src/shared src/tutorial src/git.apache.org go-tutorial calculator-remote
|
||||
|
||||
EXTRA_DIST = \
|
||||
src/client.go \
|
||||
src/handler.go \
|
||||
src/server.go \
|
||||
src/main.go \
|
||||
server.crt \
|
||||
server.key
|
||||
|
25
vendor/git.apache.org/thrift.git/tutorial/go/server.crt
generated
vendored
Normal file
25
vendor/git.apache.org/thrift.git/tutorial/go/server.crt
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIENzCCAx+gAwIBAgIJAOYfYfw7NCOcMA0GCSqGSIb3DQEBBQUAMIGxMQswCQYD
|
||||
VQQGEwJVUzERMA8GA1UECAwITWFyeWxhbmQxFDASBgNVBAcMC0ZvcmVzdCBIaWxs
|
||||
MScwJQYDVQQKDB5UaGUgQXBhY2hlIFNvZnR3YXJlIEZvdW5kYXRpb24xFjAUBgNV
|
||||
BAsMDUFwYWNoZSBUaHJpZnQxEjAQBgNVBAMMCWxvY2FsaG9zdDEkMCIGCSqGSIb3
|
||||
DQEJARYVZGV2QHRocmlmdC5hcGFjaGUub3JnMB4XDTE0MDQwNzE4NTgwMFoXDTIy
|
||||
MDYyNDE4NTgwMFowgbExCzAJBgNVBAYTAlVTMREwDwYDVQQIDAhNYXJ5bGFuZDEU
|
||||
MBIGA1UEBwwLRm9yZXN0IEhpbGwxJzAlBgNVBAoMHlRoZSBBcGFjaGUgU29mdHdh
|
||||
cmUgRm91bmRhdGlvbjEWMBQGA1UECwwNQXBhY2hlIFRocmlmdDESMBAGA1UEAwwJ
|
||||
bG9jYWxob3N0MSQwIgYJKoZIhvcNAQkBFhVkZXZAdGhyaWZ0LmFwYWNoZS5vcmcw
|
||||
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCqE9TE9wEXp5LRtLQVDSGQ
|
||||
GV78+7ZtP/I/ZaJ6Q6ZGlfxDFvZjFF73seNhAvlKlYm/jflIHYLnNOCySN8I2Xw6
|
||||
L9MbC+jvwkEKfQo4eDoxZnOZjNF5J1/lZtBeOowMkhhzBMH1Rds351/HjKNg6ZKg
|
||||
2Cldd0j7HbDtEixOLgLbPRpBcaYrLrNMasf3Hal+x8/b8ue28x93HSQBGmZmMIUw
|
||||
AinEu/fNP4lLGl/0kZb76TnyRpYSPYojtS6CnkH+QLYnsRREXJYwD1Xku62LipkX
|
||||
wCkRTnZ5nUsDMX6FPKgjQFQCWDXG/N096+PRUQAChhrXsJ+gF3NqWtDmtrhVQF4n
|
||||
AgMBAAGjUDBOMB0GA1UdDgQWBBQo8v0wzQPx3EEexJPGlxPK1PpgKjAfBgNVHSME
|
||||
GDAWgBQo8v0wzQPx3EEexJPGlxPK1PpgKjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3
|
||||
DQEBBQUAA4IBAQBGFRiJslcX0aJkwZpzTwSUdgcfKbpvNEbCNtVohfQVTI4a/oN5
|
||||
U+yqDZJg3vOaOuiAZqyHcIlZ8qyesCgRN314Tl4/JQ++CW8mKj1meTgo5YFxcZYm
|
||||
T9vsI3C+Nzn84DINgI9mx6yktIt3QOKZRDpzyPkUzxsyJ8J427DaimDrjTR+fTwD
|
||||
1Dh09xeeMnSa5zeV1HEDyJTqCXutLetwQ/IyfmMBhIx+nvB5f67pz/m+Dv6V0r3I
|
||||
p4HCcdnDUDGJbfqtoqsAATQQWO+WWuswB6mOhDbvPTxhRpZq6AkgWqv4S+u3M2GO
|
||||
r5p9FrBgavAw5bKO54C0oQKpN/5fta5l6Ws0
|
||||
-----END CERTIFICATE-----
|
28
vendor/git.apache.org/thrift.git/tutorial/go/server.key
generated
vendored
Normal file
28
vendor/git.apache.org/thrift.git/tutorial/go/server.key
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCqE9TE9wEXp5LR
|
||||
tLQVDSGQGV78+7ZtP/I/ZaJ6Q6ZGlfxDFvZjFF73seNhAvlKlYm/jflIHYLnNOCy
|
||||
SN8I2Xw6L9MbC+jvwkEKfQo4eDoxZnOZjNF5J1/lZtBeOowMkhhzBMH1Rds351/H
|
||||
jKNg6ZKg2Cldd0j7HbDtEixOLgLbPRpBcaYrLrNMasf3Hal+x8/b8ue28x93HSQB
|
||||
GmZmMIUwAinEu/fNP4lLGl/0kZb76TnyRpYSPYojtS6CnkH+QLYnsRREXJYwD1Xk
|
||||
u62LipkXwCkRTnZ5nUsDMX6FPKgjQFQCWDXG/N096+PRUQAChhrXsJ+gF3NqWtDm
|
||||
trhVQF4nAgMBAAECggEAW/y52YYW6ypROGbZ94DQpFV0kLO7qT8q0Ksxw5sPNaIt
|
||||
fEPRIymDa8ikyHWJS5Oxmw84wo5jnJV26jaLmwe2Lupq7Xf1lqej8f5LJtuv7cQR
|
||||
xfzp1vM65KJFFJHp6WqjGqJ6HSSZOpVDsnQYcXQjQCdpyAmaSWd3p+FqYSZ1mQmD
|
||||
bFNI7jqpczWSZhTdotQ7p7Hn9TVCehflP3yGIB3bQ+wCcCB85dOBz201L+YgaIck
|
||||
Sz43A4NvWaQIRLRDw7s9GW4jY5T0Jv282WIeAlVpVxLIwu48r4R4yGTIx9Ydowvq
|
||||
57+Y5iPPjAXxu0V9t00oS3bYxDaKh2DUfc/5zowq8QKBgQDYNVPXmaG0aIH4vjQ9
|
||||
7fRdw/UDkYcQbn6CnglQOu77/S8ogQzpKCVJgJgkZNqOVtQMEPzekGEcLTbje1gU
|
||||
8Bky2k+PL9UwbFy0emnOVh4rqrNXHsRvJcehNT/PRb5hjF3MUMFV/0iD4b+naFaE
|
||||
jrSWiZ2ZXj2qfwAK52GFbtOuBQKBgQDJYQuGiY0r22E4waJmCSKczoBT3cwlVzWj
|
||||
V2ljgA9RHLNTVkvNNYQLGu2qngFrtwpeaSnsMDerVG4wKAQWyCnYzxVrlnC4uDrJ
|
||||
HXuFEltBWi9Ffbgfsnd3749AT0oBP1NT2tMleguyf5DFgjCR3VRJLdrVaaZ8row/
|
||||
LqKcFMqnOwKBgB+OIO99l7E584Y3VG6ZdSneOLtNmRXX2pT7tcZE465ZdHGH7Dd3
|
||||
SYHhx9K/+Xn+yDH+pLli/xlarAEldmSP6k2WuTfftlC78AfTOfAId5zN7CDR9791
|
||||
Fx67I9X/itq33tS8EIuZl57P6uXm/4GXRloWOa8xpvRkVsBApuYPl8t1AoGATQDS
|
||||
y2sllDObBXzlgGbV2WgNIgSZ311toTv3jJiXQsjauW8yJRHln+l4H9mzaWDgkiFc
|
||||
ang1kUoDqF5k0eFQPxtQcYdhKwEnWWfwp33RbzfxA32DPnubuzzbZhfrkHaKgnIW
|
||||
cyor9uFYlm2l7ODZLfJez2RKyTplXnOSsmQw6akCgYAz3dj9Hskyj+HVJ+ht1OcE
|
||||
c7ai/ESkSA7Vajp0tjJp0EKjW/zq8DvUSXOtcdnJgkKycFluLwbmnaN4txBds1C1
|
||||
Qr8Rt2sUCCBNZe1L6DHe3XBdbkJe9sgZVNTjtUSQrzy8UhvsCqG4YWeCu07Szcbc
|
||||
rdPUV9/uQkdx8VrShxlD8A==
|
||||
-----END PRIVATE KEY-----
|
99
vendor/git.apache.org/thrift.git/tutorial/go/src/client.go
generated
vendored
Normal file
99
vendor/git.apache.org/thrift.git/tutorial/go/src/client.go
generated
vendored
Normal file
|
@ -0,0 +1,99 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"git.apache.org/thrift.git/lib/go/thrift"
|
||||
"tutorial"
|
||||
)
|
||||
|
||||
func handleClient(client *tutorial.CalculatorClient) (err error) {
|
||||
client.Ping()
|
||||
fmt.Println("ping()")
|
||||
|
||||
sum, _ := client.Add(1, 1)
|
||||
fmt.Print("1+1=", sum, "\n")
|
||||
|
||||
work := tutorial.NewWork()
|
||||
work.Op = tutorial.Operation_DIVIDE
|
||||
work.Num1 = 1
|
||||
work.Num2 = 0
|
||||
quotient, err := client.Calculate(1, work)
|
||||
if err != nil {
|
||||
switch v := err.(type) {
|
||||
case *tutorial.InvalidOperation:
|
||||
fmt.Println("Invalid operation:", v)
|
||||
default:
|
||||
fmt.Println("Error during operation:", err)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
fmt.Println("Whoa we can divide by 0 with new value:", quotient)
|
||||
}
|
||||
|
||||
work.Op = tutorial.Operation_SUBTRACT
|
||||
work.Num1 = 15
|
||||
work.Num2 = 10
|
||||
diff, err := client.Calculate(1, work)
|
||||
if err != nil {
|
||||
switch v := err.(type) {
|
||||
case *tutorial.InvalidOperation:
|
||||
fmt.Println("Invalid operation:", v)
|
||||
default:
|
||||
fmt.Println("Error during operation:", err)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
fmt.Print("15-10=", diff, "\n")
|
||||
}
|
||||
|
||||
log, err := client.GetStruct(1)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to get struct:", err)
|
||||
return err
|
||||
} else {
|
||||
fmt.Println("Check log:", log.Value)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
|
||||
var transport thrift.TTransport
|
||||
var err error
|
||||
if secure {
|
||||
cfg := new(tls.Config)
|
||||
cfg.InsecureSkipVerify = true
|
||||
transport, err = thrift.NewTSSLSocket(addr, cfg)
|
||||
} else {
|
||||
transport, err = thrift.NewTSocket(addr)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println("Error opening socket:", err)
|
||||
return err
|
||||
}
|
||||
transport = transportFactory.GetTransport(transport)
|
||||
defer transport.Close()
|
||||
if err := transport.Open(); err != nil {
|
||||
return err
|
||||
}
|
||||
return handleClient(tutorial.NewCalculatorClientFactory(transport, protocolFactory))
|
||||
}
|
101
vendor/git.apache.org/thrift.git/tutorial/go/src/handler.go
generated
vendored
Normal file
101
vendor/git.apache.org/thrift.git/tutorial/go/src/handler.go
generated
vendored
Normal file
|
@ -0,0 +1,101 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"shared"
|
||||
"strconv"
|
||||
"tutorial"
|
||||
)
|
||||
|
||||
type CalculatorHandler struct {
|
||||
log map[int]*shared.SharedStruct
|
||||
}
|
||||
|
||||
func NewCalculatorHandler() *CalculatorHandler {
|
||||
return &CalculatorHandler{log: make(map[int]*shared.SharedStruct)}
|
||||
}
|
||||
|
||||
func (p *CalculatorHandler) Ping() (err error) {
|
||||
fmt.Print("ping()\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *CalculatorHandler) Add(num1 int32, num2 int32) (retval17 int32, err error) {
|
||||
fmt.Print("add(", num1, ",", num2, ")\n")
|
||||
return num1 + num2, nil
|
||||
}
|
||||
|
||||
func (p *CalculatorHandler) Calculate(logid int32, w *tutorial.Work) (val int32, err error) {
|
||||
fmt.Print("calculate(", logid, ", {", w.Op, ",", w.Num1, ",", w.Num2, "})\n")
|
||||
switch w.Op {
|
||||
case tutorial.Operation_ADD:
|
||||
val = w.Num1 + w.Num2
|
||||
break
|
||||
case tutorial.Operation_SUBTRACT:
|
||||
val = w.Num1 - w.Num2
|
||||
break
|
||||
case tutorial.Operation_MULTIPLY:
|
||||
val = w.Num1 * w.Num2
|
||||
break
|
||||
case tutorial.Operation_DIVIDE:
|
||||
if w.Num2 == 0 {
|
||||
ouch := tutorial.NewInvalidOperation()
|
||||
ouch.WhatOp = int32(w.Op)
|
||||
ouch.Why = "Cannot divide by 0"
|
||||
err = ouch
|
||||
return
|
||||
}
|
||||
val = w.Num1 / w.Num2
|
||||
break
|
||||
default:
|
||||
ouch := tutorial.NewInvalidOperation()
|
||||
ouch.WhatOp = int32(w.Op)
|
||||
ouch.Why = "Unknown operation"
|
||||
err = ouch
|
||||
return
|
||||
}
|
||||
entry := shared.NewSharedStruct()
|
||||
entry.Key = logid
|
||||
entry.Value = strconv.Itoa(int(val))
|
||||
k := int(logid)
|
||||
/*
|
||||
oldvalue, exists := p.log[k]
|
||||
if exists {
|
||||
fmt.Print("Replacing ", oldvalue, " with ", entry, " for key ", k, "\n")
|
||||
} else {
|
||||
fmt.Print("Adding ", entry, " for key ", k, "\n")
|
||||
}
|
||||
*/
|
||||
p.log[k] = entry
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (p *CalculatorHandler) GetStruct(key int32) (*shared.SharedStruct, error) {
|
||||
fmt.Print("getStruct(", key, ")\n")
|
||||
v, _ := p.log[int(key)]
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (p *CalculatorHandler) Zip() (err error) {
|
||||
fmt.Print("zip()\n")
|
||||
return nil
|
||||
}
|
82
vendor/git.apache.org/thrift.git/tutorial/go/src/main.go
generated
vendored
Normal file
82
vendor/git.apache.org/thrift.git/tutorial/go/src/main.go
generated
vendored
Normal file
|
@ -0,0 +1,82 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"git.apache.org/thrift.git/lib/go/thrift"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Usage() {
|
||||
fmt.Fprint(os.Stderr, "Usage of ", os.Args[0], ":\n")
|
||||
flag.PrintDefaults()
|
||||
fmt.Fprint(os.Stderr, "\n")
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = Usage
|
||||
server := flag.Bool("server", false, "Run server")
|
||||
protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)")
|
||||
framed := flag.Bool("framed", false, "Use framed transport")
|
||||
buffered := flag.Bool("buffered", false, "Use buffered transport")
|
||||
addr := flag.String("addr", "localhost:9090", "Address to listen to")
|
||||
secure := flag.Bool("secure", false, "Use tls secure transport")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
var protocolFactory thrift.TProtocolFactory
|
||||
switch *protocol {
|
||||
case "compact":
|
||||
protocolFactory = thrift.NewTCompactProtocolFactory()
|
||||
case "simplejson":
|
||||
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
|
||||
case "json":
|
||||
protocolFactory = thrift.NewTJSONProtocolFactory()
|
||||
case "binary", "":
|
||||
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
|
||||
default:
|
||||
fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
|
||||
Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var transportFactory thrift.TTransportFactory
|
||||
if *buffered {
|
||||
transportFactory = thrift.NewTBufferedTransportFactory(8192)
|
||||
} else {
|
||||
transportFactory = thrift.NewTTransportFactory()
|
||||
}
|
||||
|
||||
if *framed {
|
||||
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
|
||||
}
|
||||
|
||||
if *server {
|
||||
if err := runServer(transportFactory, protocolFactory, *addr, *secure); err != nil {
|
||||
fmt.Println("error running server:", err)
|
||||
}
|
||||
} else {
|
||||
if err := runClient(transportFactory, protocolFactory, *addr, *secure); err != nil {
|
||||
fmt.Println("error running client:", err)
|
||||
}
|
||||
}
|
||||
}
|
54
vendor/git.apache.org/thrift.git/tutorial/go/src/server.go
generated
vendored
Normal file
54
vendor/git.apache.org/thrift.git/tutorial/go/src/server.go
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"git.apache.org/thrift.git/lib/go/thrift"
|
||||
"tutorial"
|
||||
)
|
||||
|
||||
func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
|
||||
var transport thrift.TServerTransport
|
||||
var err error
|
||||
if secure {
|
||||
cfg := new(tls.Config)
|
||||
if cert, err := tls.LoadX509KeyPair("server.crt", "server.key"); err == nil {
|
||||
cfg.Certificates = append(cfg.Certificates, cert)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
transport, err = thrift.NewTSSLServerSocket(addr, cfg)
|
||||
} else {
|
||||
transport, err = thrift.NewTServerSocket(addr)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%T\n", transport)
|
||||
handler := NewCalculatorHandler()
|
||||
processor := tutorial.NewCalculatorProcessor(handler)
|
||||
server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
|
||||
|
||||
fmt.Println("Starting the simple server... on ", addr)
|
||||
return server.Serve()
|
||||
}
|
98
vendor/git.apache.org/thrift.git/tutorial/haxe/Makefile.am
generated
vendored
Normal file
98
vendor/git.apache.org/thrift.git/tutorial/haxe/Makefile.am
generated
vendored
Normal file
|
@ -0,0 +1,98 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
THRIFT = $(top_builddir)/compiler/cpp/thrift
|
||||
|
||||
BIN_CPP = bin/Main-debug
|
||||
BIN_PHP = bin/php/Main-debug.php
|
||||
BIN_PHP_WEB = bin/php-web-server/Main-debug.php
|
||||
|
||||
|
||||
gen-haxe/tutorial/calculator.hx gen-haxe/shared/shared_service.hx: $(top_srcdir)/tutorial/tutorial.thrift
|
||||
$(THRIFT) --gen haxe -r $<
|
||||
|
||||
all-local: $(BIN_CPP) $(BIN_PHP) $(BIN_PHP_WEB)
|
||||
|
||||
check: gen-haxe/tutorial/calculator.hx
|
||||
|
||||
$(BIN_CPP): \
|
||||
src/*.hx \
|
||||
../../lib/haxe/src/org/apache/thrift/**/*.hx \
|
||||
gen-haxe/tutorial/calculator.hx
|
||||
$(HAXE) --cwd . cpp.hxml
|
||||
|
||||
$(BIN_PHP): \
|
||||
src/*.hx \
|
||||
../../lib/haxe/src/org/apache/thrift/**/*.hx \
|
||||
gen-haxe/tutorial/calculator.hx
|
||||
$(HAXE) --cwd . php.hxml
|
||||
|
||||
$(BIN_PHP_WEB): \
|
||||
src/*.hx \
|
||||
../../lib/haxe/src/org/apache/thrift/**/*.hx \
|
||||
gen-haxe/tutorial/calculator.hx
|
||||
$(HAXE) --cwd . php-web-server.hxml
|
||||
|
||||
tutorialserver: all
|
||||
$(BIN_CPP) server
|
||||
|
||||
tutorialserver_php: all
|
||||
php -f $(BIN_PHP) server
|
||||
|
||||
tutorialclient: all
|
||||
$(BIN_CPP)
|
||||
|
||||
tutorialclient_php: all
|
||||
php -f $(BIN_PHP)
|
||||
|
||||
tutorialsecureserver: all
|
||||
$(BIN_CPP) server secure
|
||||
|
||||
tutorialsecureserver_php: all
|
||||
php -f $(BIN_PHP) server secure
|
||||
|
||||
tutorialsecureclient: all
|
||||
$(BIN_CPP) secure
|
||||
|
||||
tutorialsecureclient_php: all
|
||||
php -f $(BIN_PHP) secure
|
||||
|
||||
tutorialserver_php_http: all
|
||||
php -S 127.0.0.1:9090 router.php
|
||||
|
||||
tutorialclient_http: all
|
||||
$(BIN_CPP) client http
|
||||
|
||||
clean-local:
|
||||
$(RM) -r gen-haxe bin
|
||||
|
||||
EXTRA_DIST = \
|
||||
src \
|
||||
cpp.hxml \
|
||||
csharp.hxml \
|
||||
flash.hxml \
|
||||
java.hxml \
|
||||
javascript.hxml \
|
||||
neko.hxml \
|
||||
php.hxml \
|
||||
python.hxml \
|
||||
project.hide \
|
||||
Tutorial.hxproj \
|
||||
make_all.bat \
|
||||
make_all.sh
|
67
vendor/git.apache.org/thrift.git/tutorial/haxe/Tutorial.hxproj
generated
vendored
Normal file
67
vendor/git.apache.org/thrift.git/tutorial/haxe/Tutorial.hxproj
generated
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project version="2">
|
||||
<!-- Output SWF options -->
|
||||
<output>
|
||||
<movie outputType="Application" />
|
||||
<movie input="" />
|
||||
<movie path="bin/HaxeTutorial" />
|
||||
<movie fps="30" />
|
||||
<movie width="800" />
|
||||
<movie height="600" />
|
||||
<movie version="1" />
|
||||
<movie minorVersion="0" />
|
||||
<movie platform="C++" />
|
||||
<movie background="#FFFFFF" />
|
||||
</output>
|
||||
<!-- Other classes to be compiled into your SWF -->
|
||||
<classpaths>
|
||||
<class path="src" />
|
||||
<class path="gen-haxe" />
|
||||
<class path="../../lib/haxe/src" />
|
||||
</classpaths>
|
||||
<!-- Build options -->
|
||||
<build>
|
||||
<option directives="" />
|
||||
<option flashStrict="False" />
|
||||
<option noInlineOnDebug="False" />
|
||||
<option mainClass="Main" />
|
||||
<option enabledebug="False" />
|
||||
<option additional="" />
|
||||
</build>
|
||||
<!-- haxelib libraries -->
|
||||
<haxelib>
|
||||
<!-- example: <library name="..." /> -->
|
||||
</haxelib>
|
||||
<!-- Class files to compile (other referenced classes will automatically be included) -->
|
||||
<compileTargets>
|
||||
<!-- example: <compile path="..." /> -->
|
||||
</compileTargets>
|
||||
<!-- Paths to exclude from the Project Explorer tree -->
|
||||
<hiddenPaths>
|
||||
<hidden path="obj" />
|
||||
<hidden path="cpp.hxml" />
|
||||
<hidden path="csharp.hxml" />
|
||||
<hidden path="flash.hxml" />
|
||||
<hidden path="java.hxml" />
|
||||
<hidden path="javascript.hxml" />
|
||||
<hidden path="make_all.bat" />
|
||||
<hidden path="make_all.sh" />
|
||||
<hidden path="Makefile.am" />
|
||||
<hidden path="neko.hxml" />
|
||||
<hidden path="php.hxml" />
|
||||
<hidden path="project.hide" />
|
||||
<hidden path="python.hxml" />
|
||||
</hiddenPaths>
|
||||
<!-- Executed before build -->
|
||||
<preBuildCommand>thrift -r -gen haxe ../tutorial.thrift</preBuildCommand>
|
||||
<!-- Executed after build -->
|
||||
<postBuildCommand alwaysRun="False" />
|
||||
<!-- Other project options -->
|
||||
<options>
|
||||
<option showHiddenPaths="False" />
|
||||
<option testMovie="Unknown" />
|
||||
<option testMovieCommand="" />
|
||||
</options>
|
||||
<!-- Plugin storage -->
|
||||
<storage />
|
||||
</project>
|
41
vendor/git.apache.org/thrift.git/tutorial/haxe/cpp.hxml
generated
vendored
Normal file
41
vendor/git.apache.org/thrift.git/tutorial/haxe/cpp.hxml
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#CPP target
|
||||
-cpp bin
|
||||
|
||||
#To produce 64 bit binaries the file should define the HXCPP_M64 compile variable:
|
||||
#-D HXCPP_M64
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
38
vendor/git.apache.org/thrift.git/tutorial/haxe/csharp.hxml
generated
vendored
Normal file
38
vendor/git.apache.org/thrift.git/tutorial/haxe/csharp.hxml
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#CSHARP target
|
||||
-cs bin/Tutorial.exe
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
41
vendor/git.apache.org/thrift.git/tutorial/haxe/flash.hxml
generated
vendored
Normal file
41
vendor/git.apache.org/thrift.git/tutorial/haxe/flash.hxml
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#Flash target
|
||||
-swf bin/Tutorial.swf
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
# we need some goodies from sys.net
|
||||
# --macro allowPackage("sys")
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
38
vendor/git.apache.org/thrift.git/tutorial/haxe/java.hxml
generated
vendored
Normal file
38
vendor/git.apache.org/thrift.git/tutorial/haxe/java.hxml
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#Java target
|
||||
-java bin/Tutorial.jar
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
44
vendor/git.apache.org/thrift.git/tutorial/haxe/javascript.hxml
generated
vendored
Normal file
44
vendor/git.apache.org/thrift.git/tutorial/haxe/javascript.hxml
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#JavaScript target
|
||||
-js bin/Tutorial.js
|
||||
|
||||
#You can use -D source-map-content (requires Haxe 3.1+) to have the .hx
|
||||
#files directly embedded into the map file, this way you only have to
|
||||
#upload it, and it will be always in sync with the compiled .js even if
|
||||
#you modify your .hx files.
|
||||
-D source-map-content
|
||||
|
||||
#Generate source map and add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
68
vendor/git.apache.org/thrift.git/tutorial/haxe/make_all.bat
generated
vendored
Normal file
68
vendor/git.apache.org/thrift.git/tutorial/haxe/make_all.bat
generated
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
@echo off
|
||||
rem /*
|
||||
rem * Licensed to the Apache Software Foundation (ASF) under one
|
||||
rem * or more contributor license agreements. See the NOTICE file
|
||||
rem * distributed with this work for additional information
|
||||
rem * regarding copyright ownership. The ASF licenses this file
|
||||
rem * to you under the Apache License, Version 2.0 (the
|
||||
rem * "License"); you may not use this file except in compliance
|
||||
rem * with the License. You may obtain a copy of the License at
|
||||
rem *
|
||||
rem * http://www.apache.org/licenses/LICENSE-2.0
|
||||
rem *
|
||||
rem * Unless required by applicable law or agreed to in writing,
|
||||
rem * software distributed under the License is distributed on an
|
||||
rem * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
rem * KIND, either express or implied. See the License for the
|
||||
rem * specific language governing permissions and limitations
|
||||
rem * under the License.
|
||||
rem */
|
||||
|
||||
setlocal
|
||||
if "%HOMEDRIVE%"=="" goto MISSINGVARS
|
||||
if "%HOMEPATH%"=="" goto MISSINGVARS
|
||||
if "%HAXEPATH%"=="" goto NOTINSTALLED
|
||||
|
||||
set path=%HAXEPATH%;%HAXEPATH%\..\neko;%path%
|
||||
|
||||
rem # invoke Thrift comnpiler
|
||||
thrift -r -gen haxe ..\tutorial.thrift
|
||||
if errorlevel 1 goto STOP
|
||||
|
||||
rem # invoke Haxe compiler for all targets
|
||||
for %%a in (*.hxml) do (
|
||||
rem * filter Python, as it is not supported by Haxe 3.1.3 (but will be in 3.1.4)
|
||||
if not "%%a"=="python.hxml" (
|
||||
echo --------------------------
|
||||
echo Building %%a ...
|
||||
echo --------------------------
|
||||
haxe --cwd . %%a
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
echo.
|
||||
echo done.
|
||||
pause
|
||||
goto eof
|
||||
|
||||
:NOTINSTALLED
|
||||
echo FATAL: Either Haxe is not installed, or the HAXEPATH variable is not set.
|
||||
pause
|
||||
goto eof
|
||||
|
||||
:MISSINGVARS
|
||||
echo FATAL: Unable to locate home folder.
|
||||
echo.
|
||||
echo Both HOMEDRIVE and HOMEPATH need to be set to point to your Home folder.
|
||||
echo The current values are:
|
||||
echo HOMEDRIVE=%HOMEDRIVE%
|
||||
echo HOMEPATH=%HOMEPATH%
|
||||
pause
|
||||
goto eof
|
||||
|
||||
:STOP
|
||||
pause
|
||||
goto eof
|
||||
|
||||
:eof
|
41
vendor/git.apache.org/thrift.git/tutorial/haxe/make_all.sh
generated
vendored
Normal file
41
vendor/git.apache.org/thrift.git/tutorial/haxe/make_all.sh
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
# invoke Thrift comnpiler
|
||||
thrift -r -gen haxe ../tutorial.thrift
|
||||
|
||||
# output folder
|
||||
if [ ! -d bin ]; then
|
||||
mkdir bin
|
||||
fi
|
||||
|
||||
# invoke Haxe compoiler
|
||||
for target in *.hxml; do
|
||||
echo --------------------------
|
||||
echo Building ${target} ...
|
||||
echo --------------------------
|
||||
if [ ! -d bin/${target} ]; then
|
||||
mkdir bin/${target}
|
||||
fi
|
||||
haxe --cwd . ${target}
|
||||
done
|
||||
|
||||
|
||||
#eof
|
38
vendor/git.apache.org/thrift.git/tutorial/haxe/neko.hxml
generated
vendored
Normal file
38
vendor/git.apache.org/thrift.git/tutorial/haxe/neko.hxml
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#neko target
|
||||
-neko bin/Tutorial.n
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
43
vendor/git.apache.org/thrift.git/tutorial/haxe/php-web-server.hxml
generated
vendored
Normal file
43
vendor/git.apache.org/thrift.git/tutorial/haxe/php-web-server.hxml
generated
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#PHP target
|
||||
-php bin/php-web-server/
|
||||
--php-front Main-debug.php
|
||||
|
||||
#defines
|
||||
-D phpwebserver
|
||||
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
39
vendor/git.apache.org/thrift.git/tutorial/haxe/php.hxml
generated
vendored
Normal file
39
vendor/git.apache.org/thrift.git/tutorial/haxe/php.hxml
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#PHP target
|
||||
-php bin/php/
|
||||
--php-front Main-debug.php
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
105
vendor/git.apache.org/thrift.git/tutorial/haxe/project.hide
generated
vendored
Normal file
105
vendor/git.apache.org/thrift.git/tutorial/haxe/project.hide
generated
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
{
|
||||
"type" : 0
|
||||
,"target" : 4
|
||||
,"name" : "Apache Thrift Tutorial"
|
||||
,"main" : null
|
||||
,"projectPackage" : ""
|
||||
,"company" : "Apache Software Foundation (ASF)"
|
||||
,"license" : "Apache License, Version 2.0"
|
||||
,"url" : "http://www.apache.org/licenses/LICENSE-2.0"
|
||||
,"targetData" : [
|
||||
{
|
||||
"pathToHxml" : "flash.hxml"
|
||||
,"runActionType" : 1
|
||||
,"runActionText" : "bin/Tutorial.swf"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "javascript.hxml"
|
||||
,"runActionType" : 1
|
||||
,"runActionText" : "bin\\index.html"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "neko.hxml"
|
||||
,"runActionType" : 2
|
||||
,"runActionText" : "neko bin/Tutorial.n"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "php.hxml"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "cpp.hxml"
|
||||
,"runActionType" : 2
|
||||
,"runActionText" : "bin/Main-debug.exe"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "java.hxml"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "csharp.hxml"
|
||||
,"runActionType" : 2
|
||||
,"runActionText" : "bin\\Tutorial.exe\\bin\\Main-Debug.exe"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "python.hxml"
|
||||
,"runActionType" : 2
|
||||
,"runActionText" : "python bin/Tutorial.py"
|
||||
}
|
||||
]
|
||||
,"files" : [
|
||||
{
|
||||
"path" : "src\\org\\apache\\thrift\\server\\TServer.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 76
|
||||
}
|
||||
,{
|
||||
"path" : "src\\org\\apache\\thrift\\server\\TSimpleServer.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 100
|
||||
}
|
||||
,{
|
||||
"path" : "src\\shared\\SharedServiceProcessor.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 20
|
||||
}
|
||||
,{
|
||||
"path" : "src\\tutorial\\CalculatorProcessor.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 79
|
||||
}
|
||||
,{
|
||||
"path" : "src\\Main.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 0
|
||||
}
|
||||
]
|
||||
,"activeFile" : "src\\Main.hx"
|
||||
,"openFLTarget" : null
|
||||
,"openFLBuildMode" : "Debug"
|
||||
,"runActionType" : null
|
||||
,"runActionText" : null
|
||||
,"buildActionCommand" : null
|
||||
,"hiddenItems" : [
|
||||
|
||||
]
|
||||
,"showHiddenItems" : false
|
||||
}
|
38
vendor/git.apache.org/thrift.git/tutorial/haxe/python.hxml
generated
vendored
Normal file
38
vendor/git.apache.org/thrift.git/tutorial/haxe/python.hxml
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#Python target
|
||||
-python bin/Tutorial.py
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
31
vendor/git.apache.org/thrift.git/tutorial/haxe/router.php
generated
vendored
Normal file
31
vendor/git.apache.org/thrift.git/tutorial/haxe/router.php
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* @package thrift
|
||||
*/
|
||||
|
||||
|
||||
|
||||
//router file to run testing web server
|
||||
|
||||
//set_time_limit(1);
|
||||
|
||||
require_once dirname(__FILE__) . '/bin/php-web-server/Main-debug.php';
|
||||
|
||||
|
101
vendor/git.apache.org/thrift.git/tutorial/haxe/src/CalculatorHandler.hx
generated
vendored
Normal file
101
vendor/git.apache.org/thrift.git/tutorial/haxe/src/CalculatorHandler.hx
generated
vendored
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package;
|
||||
|
||||
import haxe.ds.IntMap;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.server.*;
|
||||
import org.apache.thrift.meta_data.*;
|
||||
|
||||
import tutorial.*;
|
||||
import shared.*;
|
||||
|
||||
|
||||
class CalculatorHandler implements Calculator {
|
||||
|
||||
private var log = new IntMap<SharedStruct>();
|
||||
|
||||
public function new() {
|
||||
}
|
||||
|
||||
public function ping() : Void {
|
||||
trace("ping()");
|
||||
}
|
||||
|
||||
|
||||
public function add( num1 : haxe.Int32, num2 : haxe.Int32) : haxe.Int32 {
|
||||
trace('add( $num1, $num2)');
|
||||
return num1 + num2;
|
||||
}
|
||||
|
||||
public function calculate( logid : haxe.Int32, work : Work) : haxe.Int32 {
|
||||
trace('calculate( $logid, '+work.op+","+work.num1+","+work.num2+")");
|
||||
|
||||
var val : haxe.Int32 = 0;
|
||||
switch (work.op)
|
||||
{
|
||||
case Operation.ADD:
|
||||
val = work.num1 + work.num2;
|
||||
|
||||
case Operation.SUBTRACT:
|
||||
val = work.num1 - work.num2;
|
||||
|
||||
case Operation.MULTIPLY:
|
||||
val = work.num1 * work.num2;
|
||||
|
||||
case Operation.DIVIDE:
|
||||
if (work.num2 == 0)
|
||||
{
|
||||
var io = new InvalidOperation();
|
||||
io.whatOp = work.op;
|
||||
io.why = "Cannot divide by 0";
|
||||
throw io;
|
||||
}
|
||||
val = Std.int( work.num1 / work.num2);
|
||||
|
||||
default:
|
||||
var io = new InvalidOperation();
|
||||
io.whatOp = work.op;
|
||||
io.why = "Unknown operation";
|
||||
throw io;
|
||||
}
|
||||
|
||||
var entry = new SharedStruct();
|
||||
entry.key = logid;
|
||||
entry.value = '$val';
|
||||
log.set(logid, entry);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public function getStruct( key : haxe.Int32) : SharedStruct {
|
||||
trace('getStruct($key)');
|
||||
return log.get(key);
|
||||
}
|
||||
|
||||
// oneway method, no args
|
||||
public function zip() : Void {
|
||||
trace("zip()");
|
||||
}
|
||||
|
||||
}
|
375
vendor/git.apache.org/thrift.git/tutorial/haxe/src/Main.hx
generated
vendored
Normal file
375
vendor/git.apache.org/thrift.git/tutorial/haxe/src/Main.hx
generated
vendored
Normal file
|
@ -0,0 +1,375 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.server.*;
|
||||
import org.apache.thrift.meta_data.*;
|
||||
|
||||
import tutorial.*;
|
||||
import shared.*;
|
||||
|
||||
|
||||
enum Prot {
|
||||
binary;
|
||||
json;
|
||||
}
|
||||
|
||||
enum Trns {
|
||||
socket;
|
||||
http;
|
||||
}
|
||||
|
||||
class Main {
|
||||
|
||||
private static var server : Bool = false;
|
||||
private static var framed : Bool = false;
|
||||
private static var buffered : Bool = false;
|
||||
private static var prot : Prot = binary;
|
||||
private static var trns : Trns = socket;
|
||||
|
||||
private static var targetHost : String = "localhost";
|
||||
private static var targetPort : Int = 9090;
|
||||
|
||||
static function main() {
|
||||
|
||||
#if ! (flash || js || phpwebserver)
|
||||
try {
|
||||
ParseArgs();
|
||||
} catch (e : String) {
|
||||
trace(e);
|
||||
trace(GetHelp());
|
||||
return;
|
||||
}
|
||||
|
||||
#elseif phpwebserver
|
||||
//forcing server
|
||||
server = true;
|
||||
trns = http;
|
||||
initPhpWebServer();
|
||||
//check method
|
||||
if(php.Web.getMethod() != 'POST') {
|
||||
Sys.println('http endpoint for thrift test server');
|
||||
return;
|
||||
}
|
||||
#end
|
||||
|
||||
try {
|
||||
if (server)
|
||||
RunServer();
|
||||
else
|
||||
RunClient();
|
||||
} catch (e : String) {
|
||||
trace(e);
|
||||
}
|
||||
|
||||
trace("Completed.");
|
||||
}
|
||||
|
||||
#if phpwebserver
|
||||
private static function initPhpWebServer()
|
||||
{
|
||||
//remap trace to error log
|
||||
haxe.Log.trace = function(v:Dynamic, ?infos:haxe.PosInfos)
|
||||
{
|
||||
// handle trace
|
||||
var newValue : Dynamic;
|
||||
if (infos != null && infos.customParams!=null) {
|
||||
var extra:String = "";
|
||||
for( v in infos.customParams )
|
||||
extra += "," + v;
|
||||
newValue = v + extra;
|
||||
}
|
||||
else {
|
||||
newValue = v;
|
||||
}
|
||||
var msg = infos != null ? infos.fileName + ':' + infos.lineNumber + ': ' : '';
|
||||
Sys.stderr().writeString('${msg}${newValue}\n');
|
||||
}
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
#if ! (flash || js)
|
||||
|
||||
private static function GetHelp() : String {
|
||||
return Sys.executablePath()+" modus trnsOption transport protocol\n"
|
||||
+"Options:\n"
|
||||
+" modus: client, server (default: client)\n"
|
||||
+" trnsOption: framed, buffered (default: none)\n"
|
||||
+" transport: socket, http (default: socket)\n"
|
||||
+" protocol: binary, json (default: binary)\n"
|
||||
+"\n"
|
||||
+"All arguments are optional.\n";
|
||||
}
|
||||
|
||||
|
||||
private static function ParseArgs() : Void {
|
||||
var step = 0;
|
||||
for (arg in Sys.args()) {
|
||||
|
||||
// server|client
|
||||
switch(step) {
|
||||
case 0:
|
||||
++step;
|
||||
if ( arg == "client")
|
||||
server = false;
|
||||
else if ( arg == "server")
|
||||
server = true;
|
||||
else
|
||||
throw "First argument must be 'server' or 'client'";
|
||||
|
||||
case 1:
|
||||
if ( arg == "framed") {
|
||||
framed = true;
|
||||
} else if ( arg == "buffered") {
|
||||
buffered = true;
|
||||
} else if ( arg == "socket") {
|
||||
trns = socket;
|
||||
++step;
|
||||
} else if ( arg == "http") {
|
||||
trns = http;
|
||||
++step;
|
||||
} else {
|
||||
throw "Unknown transport "+arg;
|
||||
}
|
||||
|
||||
case 2:
|
||||
if ( arg == "binary") {
|
||||
prot = binary;
|
||||
++step;
|
||||
} else if ( arg == "json") {
|
||||
prot = json;
|
||||
++step;
|
||||
} else {
|
||||
throw "Unknown protocol "+arg;
|
||||
}
|
||||
|
||||
default:
|
||||
throw "Unexpected argument "+arg;
|
||||
}
|
||||
|
||||
if ( framed && buffered)
|
||||
{
|
||||
trace("WN: framed supersedes buffered");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
private static function ClientSetup() : Calculator {
|
||||
trace("Client configuration:");
|
||||
|
||||
// endpoint transport
|
||||
var transport : TTransport;
|
||||
switch(trns)
|
||||
{
|
||||
case socket:
|
||||
trace('- socket transport $targetHost:$targetPort');
|
||||
transport = new TSocket( targetHost, targetPort);
|
||||
case http:
|
||||
var uri = 'http://${targetHost}:${targetPort}';
|
||||
trace('- HTTP transport $uri');
|
||||
transport = new THttpClient(uri);
|
||||
default:
|
||||
throw "Unhandled transport";
|
||||
}
|
||||
|
||||
|
||||
// optinal layered transport
|
||||
if ( framed) {
|
||||
trace("- framed transport");
|
||||
transport = new TFramedTransport(transport);
|
||||
} else if ( buffered) {
|
||||
trace("- buffered transport");
|
||||
transport = new TBufferedTransport(transport);
|
||||
}
|
||||
|
||||
|
||||
// protocol
|
||||
var protocol : TProtocol;
|
||||
switch(prot)
|
||||
{
|
||||
case binary:
|
||||
trace("- binary protocol");
|
||||
protocol = new TBinaryProtocol( transport);
|
||||
case json:
|
||||
trace("- JSON protocol");
|
||||
protocol = new TJSONProtocol( transport);
|
||||
default:
|
||||
throw "Unhandled protocol";
|
||||
}
|
||||
|
||||
|
||||
// put everything together
|
||||
transport.open();
|
||||
return new CalculatorImpl(protocol,protocol);
|
||||
}
|
||||
|
||||
|
||||
private static function RunClient() : Void {
|
||||
var client = ClientSetup();
|
||||
|
||||
try {
|
||||
client.ping();
|
||||
trace("ping() successful");
|
||||
} catch(error : TException) {
|
||||
trace('ping() failed: $error');
|
||||
} catch(error : Dynamic) {
|
||||
trace('ping() failed: $error');
|
||||
}
|
||||
|
||||
try {
|
||||
var sum = client.add( 1, 1);
|
||||
trace('1+1=$sum');
|
||||
} catch(error : TException) {
|
||||
trace('add() failed: $error');
|
||||
} catch(error : Dynamic) {
|
||||
trace('add() failed: $error');
|
||||
}
|
||||
|
||||
|
||||
var work = new tutorial.Work();
|
||||
work.op = tutorial.Operation.DIVIDE;
|
||||
work.num1 = 1;
|
||||
work.num2 = 0;
|
||||
try {
|
||||
var quotient = client.calculate( 1, work);
|
||||
trace('Whoa we can divide by 0! Result = $quotient');
|
||||
} catch(error : TException) {
|
||||
trace('calculate() failed: $error');
|
||||
} catch(error : Dynamic) {
|
||||
trace('calculate() failed: $error');
|
||||
}
|
||||
|
||||
work.op = tutorial.Operation.SUBTRACT;
|
||||
work.num1 = 15;
|
||||
work.num2 = 10;
|
||||
try {
|
||||
var diff = client.calculate( 1, work);
|
||||
trace('15-10=$diff');
|
||||
} catch(error : TException) {
|
||||
trace('calculate() failed: $error');
|
||||
} catch(error : Dynamic) {
|
||||
trace('calculate() failed: $error');
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
var log : SharedStruct = client.getStruct( 1);
|
||||
var logval = log.value;
|
||||
trace('Check log: $logval');
|
||||
} catch(error : TException) {
|
||||
trace('getStruct() failed: $error');
|
||||
} catch(error : Dynamic) {
|
||||
trace('getStruct() failed: $error');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static function ServerSetup() : TServer {
|
||||
trace("Server configuration:");
|
||||
|
||||
// endpoint transport
|
||||
var transport : TServerTransport = null;
|
||||
switch(trns)
|
||||
{
|
||||
case socket:
|
||||
#if (flash || js)
|
||||
throw 'current platform does not support socket servers';
|
||||
#else
|
||||
trace('- socket transport port $targetPort');
|
||||
transport = new TServerSocket( targetPort);
|
||||
#end
|
||||
case http:
|
||||
#if !phpwebserver
|
||||
throw "HTTP server not implemented yet";
|
||||
//trace("- http transport");
|
||||
//transport = new THttpClient( targetHost);
|
||||
#else
|
||||
trace("- http transport");
|
||||
transport = new TWrappingServerTransport(
|
||||
new TStreamTransport(
|
||||
new TFileStream("php://input", Read),
|
||||
new TFileStream("php://output", Append)
|
||||
)
|
||||
);
|
||||
|
||||
#end
|
||||
default:
|
||||
throw "Unhandled transport";
|
||||
}
|
||||
|
||||
// optional: layered transport
|
||||
var transfactory : TTransportFactory = null;
|
||||
if ( framed) {
|
||||
trace("- framed transport");
|
||||
transfactory = new TFramedTransportFactory();
|
||||
} else if ( buffered) {
|
||||
trace("- buffered transport");
|
||||
transfactory = new TBufferedTransportFactory();
|
||||
}
|
||||
|
||||
// protocol
|
||||
var protfactory : TProtocolFactory = null;
|
||||
switch(prot)
|
||||
{
|
||||
case binary:
|
||||
trace("- binary protocol");
|
||||
protfactory = new TBinaryProtocolFactory();
|
||||
case json:
|
||||
trace("- JSON protocol");
|
||||
protfactory = new TJSONProtocolFactory();
|
||||
default:
|
||||
throw "Unhandled protocol";
|
||||
}
|
||||
|
||||
var handler = new CalculatorHandler();
|
||||
var processor = new CalculatorProcessor(handler);
|
||||
var server = new TSimpleServer( processor, transport, transfactory, protfactory);
|
||||
#if phpwebserver
|
||||
server.runOnce = true;
|
||||
#end
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
|
||||
private static function RunServer() : Void {
|
||||
try
|
||||
{
|
||||
var server = ServerSetup();
|
||||
|
||||
trace("\nStarting the server...");
|
||||
server.Serve();
|
||||
}
|
||||
catch( e : Dynamic)
|
||||
{
|
||||
trace('RunServer() failed: $e');
|
||||
}
|
||||
trace("done.");
|
||||
}
|
||||
|
||||
}
|
||||
|
76
vendor/git.apache.org/thrift.git/tutorial/hs/HaskellClient.hs
generated
vendored
Normal file
76
vendor/git.apache.org/thrift.git/tutorial/hs/HaskellClient.hs
generated
vendored
Normal file
|
@ -0,0 +1,76 @@
|
|||
--
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
--
|
||||
|
||||
import qualified Calculator
|
||||
import qualified Calculator_Client as Client
|
||||
import qualified SharedService_Client as SClient
|
||||
import Tutorial_Types
|
||||
import SharedService_Iface
|
||||
import Shared_Types
|
||||
|
||||
import Thrift
|
||||
import Thrift.Protocol.Binary
|
||||
import Thrift.Transport
|
||||
import Thrift.Transport.Handle
|
||||
import Thrift.Server
|
||||
|
||||
import Control.Exception
|
||||
import Data.Maybe
|
||||
import Data.Text.Lazy
|
||||
import Text.Printf
|
||||
import Network
|
||||
|
||||
main = do
|
||||
transport <- hOpen ("localhost", PortNumber 9090)
|
||||
let binProto = BinaryProtocol transport
|
||||
let client = (binProto, binProto)
|
||||
|
||||
Client.ping client
|
||||
print "ping()"
|
||||
|
||||
sum <- Client.add client 1 1
|
||||
printf "1+1=%d\n" sum
|
||||
|
||||
|
||||
let work = Work { work_op = DIVIDE,
|
||||
work_num1 = 1,
|
||||
work_num2 = 0,
|
||||
work_comment = Nothing
|
||||
}
|
||||
|
||||
Control.Exception.catch (printf "1/0=%d\n" =<< Client.calculate client 1 work)
|
||||
(\e -> printf "InvalidOperation %s\n" (show (e :: InvalidOperation)))
|
||||
|
||||
|
||||
let work = Work { work_op = SUBTRACT,
|
||||
work_num1 = 15,
|
||||
work_num2 = 10,
|
||||
work_comment = Nothing
|
||||
}
|
||||
|
||||
diff <- Client.calculate client 1 work
|
||||
printf "15-10=%d\n" diff
|
||||
|
||||
log <- SClient.getStruct client 1
|
||||
printf "Check log: %s\n" $ unpack $ sharedStruct_value log
|
||||
|
||||
-- Close!
|
||||
tClose transport
|
||||
|
||||
|
103
vendor/git.apache.org/thrift.git/tutorial/hs/HaskellServer.hs
generated
vendored
Normal file
103
vendor/git.apache.org/thrift.git/tutorial/hs/HaskellServer.hs
generated
vendored
Normal file
|
@ -0,0 +1,103 @@
|
|||
--
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
--
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
import qualified Calculator
|
||||
import Calculator_Iface
|
||||
import Tutorial_Types
|
||||
import SharedService_Iface
|
||||
import Shared_Types
|
||||
|
||||
import Thrift
|
||||
import Thrift.Protocol.Binary
|
||||
import Thrift.Transport
|
||||
import Thrift.Server
|
||||
|
||||
import Data.Int
|
||||
import Data.String
|
||||
import Data.Maybe
|
||||
import Text.Printf
|
||||
import Control.Exception (throw)
|
||||
import Control.Concurrent.MVar
|
||||
import qualified Data.Map as M
|
||||
import Data.Map ((!))
|
||||
import Data.Monoid
|
||||
|
||||
data CalculatorHandler = CalculatorHandler {mathLog :: MVar (M.Map Int32 SharedStruct)}
|
||||
|
||||
newCalculatorHandler = do
|
||||
log <- newMVar mempty
|
||||
return $ CalculatorHandler log
|
||||
|
||||
instance SharedService_Iface CalculatorHandler where
|
||||
getStruct self k = do
|
||||
myLog <- readMVar (mathLog self)
|
||||
return $ (myLog ! k)
|
||||
|
||||
|
||||
instance Calculator_Iface CalculatorHandler where
|
||||
ping _ =
|
||||
print "ping()"
|
||||
|
||||
add _ n1 n2 = do
|
||||
printf "add(%d,%d)\n" n1 n2
|
||||
return (n1 + n2)
|
||||
|
||||
calculate self mlogid mwork = do
|
||||
printf "calculate(%d, %s)\n" logid (show work)
|
||||
|
||||
let val = case op work of
|
||||
ADD ->
|
||||
num1 work + num2 work
|
||||
SUBTRACT ->
|
||||
num1 work - num2 work
|
||||
MULTIPLY ->
|
||||
num1 work * num2 work
|
||||
DIVIDE ->
|
||||
if num2 work == 0 then
|
||||
throw $
|
||||
InvalidOperation {
|
||||
invalidOperation_whatOp = fromIntegral $ fromEnum $ op work,
|
||||
invalidOperation_why = "Cannot divide by 0"
|
||||
}
|
||||
else
|
||||
num1 work `div` num2 work
|
||||
|
||||
let logEntry = SharedStruct logid (fromString $ show $ val)
|
||||
modifyMVar_ (mathLog self) $ return .(M.insert logid logEntry)
|
||||
|
||||
return $! val
|
||||
|
||||
where
|
||||
-- stupid dynamic languages f'ing it up
|
||||
num1 = work_num1
|
||||
num2 = work_num2
|
||||
op = work_op
|
||||
logid = mlogid
|
||||
work = mwork
|
||||
|
||||
zip _ =
|
||||
print "zip()"
|
||||
|
||||
main = do
|
||||
handler <- newCalculatorHandler
|
||||
print "Starting the server..."
|
||||
runBasicServer handler Calculator.process 9090
|
||||
print "done."
|
39
vendor/git.apache.org/thrift.git/tutorial/hs/Makefile.am
generated
vendored
Executable file
39
vendor/git.apache.org/thrift.git/tutorial/hs/Makefile.am
generated
vendored
Executable file
|
@ -0,0 +1,39 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
all-local:
|
||||
$(top_builddir)/compiler/cpp/thrift --gen hs -r $(top_srcdir)/tutorial/tutorial.thrift
|
||||
$(CABAL) install
|
||||
|
||||
install-exec-hook:
|
||||
$(CABAL) install
|
||||
|
||||
# Make sure this doesn't fail if Haskell is not configured.
|
||||
clean-local:
|
||||
$(CABAL) clean
|
||||
$(RM) -r gen-*
|
||||
|
||||
check-local:
|
||||
$(CABAL) check
|
||||
|
||||
tutorialserver: all
|
||||
dist/build/HaskellServer/HaskellServer
|
||||
|
||||
tutorialclient: all
|
||||
dist/build/HaskellClient/HaskellClient
|
21
vendor/git.apache.org/thrift.git/tutorial/hs/Setup.lhs
generated
vendored
Normal file
21
vendor/git.apache.org/thrift.git/tutorial/hs/Setup.lhs
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env runhaskell
|
||||
|
||||
> -- Licensed to the Apache Software Foundation (ASF) under one
|
||||
> -- or more contributor license agreements. See the NOTICE file
|
||||
> -- distributed with this work for additional information
|
||||
> -- regarding copyright ownership. The ASF licenses this file
|
||||
> -- to you under the Apache License, Version 2.0 (the
|
||||
> -- "License"); you may not use this file except in compliance
|
||||
> -- with the License. You may obtain a copy of the License at
|
||||
> --
|
||||
> -- http://www.apache.org/licenses/LICENSE-2.0
|
||||
> --
|
||||
> -- Unless required by applicable law or agreed to in writing,
|
||||
> -- software distributed under the License is distributed on an
|
||||
> -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
> -- KIND, either express or implied. See the License for the
|
||||
> -- specific language governing permissions and limitations
|
||||
> -- under the License.
|
||||
|
||||
> import Distribution.Simple
|
||||
> main = defaultMain
|
73
vendor/git.apache.org/thrift.git/tutorial/hs/ThriftTutorial.cabal
generated
vendored
Executable file
73
vendor/git.apache.org/thrift.git/tutorial/hs/ThriftTutorial.cabal
generated
vendored
Executable file
|
@ -0,0 +1,73 @@
|
|||
--
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
--
|
||||
|
||||
Name: ThriftTutorial
|
||||
Version: 0.10.0
|
||||
Cabal-Version: >= 1.4
|
||||
License: OtherLicense
|
||||
Category: Foreign
|
||||
Build-Type: Simple
|
||||
Synopsis: Thrift Tutorial library package
|
||||
Homepage: http://thrift.apache.org
|
||||
Bug-Reports: https://issues.apache.org/jira/browse/THRIFT
|
||||
Maintainer: dev@thrift.apache.org
|
||||
License-File: ../../LICENSE
|
||||
|
||||
Description:
|
||||
Haskell tutorial for the Apache Thrift RPC system. Requires the use of the thrift code generator.
|
||||
|
||||
flag network-uri
|
||||
description: Get Network.URI from the network-uri package
|
||||
default: True
|
||||
|
||||
Executable HaskellServer
|
||||
Main-is: HaskellServer.hs
|
||||
Hs-Source-Dirs:
|
||||
., gen-hs/
|
||||
Build-Depends:
|
||||
base >= 4, base < 5, ghc-prim, containers, thrift, vector, unordered-containers, text, hashable, bytestring, QuickCheck
|
||||
Extensions:
|
||||
DeriveDataTypeable,
|
||||
ExistentialQuantification,
|
||||
FlexibleInstances,
|
||||
KindSignatures,
|
||||
MagicHash,
|
||||
RankNTypes,
|
||||
ScopedTypeVariables,
|
||||
TypeSynonymInstances
|
||||
|
||||
Executable HaskellClient
|
||||
Main-is: HaskellClient.hs
|
||||
Hs-Source-Dirs:
|
||||
., gen-hs/
|
||||
Build-Depends:
|
||||
base >= 4, base < 5, ghc-prim, containers, thrift, vector, QuickCheck
|
||||
if flag(network-uri)
|
||||
build-depends: network-uri >= 2.6, network >= 2.6
|
||||
else
|
||||
build-depends: network < 2.6
|
||||
Extensions:
|
||||
DeriveDataTypeable,
|
||||
ExistentialQuantification,
|
||||
FlexibleInstances,
|
||||
KindSignatures,
|
||||
MagicHash,
|
||||
RankNTypes,
|
||||
ScopedTypeVariables,
|
||||
TypeSynonymInstances
|
45
vendor/git.apache.org/thrift.git/tutorial/java/Makefile.am
generated
vendored
Executable file
45
vendor/git.apache.org/thrift.git/tutorial/java/Makefile.am
generated
vendored
Executable file
|
@ -0,0 +1,45 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
export CLASSPATH
|
||||
|
||||
# Make sure this doesn't fail if ant is not configured.
|
||||
clean-local:
|
||||
ANT=$(ANT) ; if test -z "$$ANT" ; then ANT=: ; fi ; \
|
||||
$$ANT $(ANT_FLAGS) clean
|
||||
|
||||
all-local:
|
||||
$(ANT) $(ANT_FLAGS) compile
|
||||
|
||||
check-local: all
|
||||
$(ANT) $(ANT_FLAGS) test
|
||||
|
||||
tutorial: all
|
||||
$(ANT) $(ANT_FLAGS) tutorial
|
||||
|
||||
tutorialserver: all
|
||||
$(ANT) $(ANT_FLAGS) tutorialserver
|
||||
|
||||
tutorialclient: all
|
||||
$(ANT) $(ANT_FLAGS) tutorialclient
|
||||
|
||||
EXTRA_DIST = \
|
||||
build.xml \
|
||||
src \
|
||||
README.md
|
24
vendor/git.apache.org/thrift.git/tutorial/java/README.md
generated
vendored
Normal file
24
vendor/git.apache.org/thrift.git/tutorial/java/README.md
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
Thrift Java Tutorial
|
||||
==================================================
|
||||
1) Compile the Java library
|
||||
|
||||
thrift/lib/java$ make
|
||||
or:
|
||||
|
||||
thrift/lib/java$ ant
|
||||
|
||||
4) Run the tutorial:
|
||||
|
||||
start server and client with one step:
|
||||
|
||||
thrift/tutorial/java$ make tutorial
|
||||
|
||||
or:
|
||||
|
||||
thrift/tutorial/java$ make tutorialserver
|
||||
thrift/tutorial/java$ make tutorialclient
|
||||
|
||||
or:
|
||||
|
||||
thrift/tutorial/java$ ant tutorialserver
|
||||
thrift/tutorial/java$ ant tutorialclient
|
113
vendor/git.apache.org/thrift.git/tutorial/java/build.xml
generated
vendored
Normal file
113
vendor/git.apache.org/thrift.git/tutorial/java/build.xml
generated
vendored
Normal file
|
@ -0,0 +1,113 @@
|
|||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<project name="tutorial" default="tutorial" basedir=".">
|
||||
|
||||
<description>Thrift Java Tutorial</description>
|
||||
|
||||
<property name="src" location="src" />
|
||||
<property name="gen" location="gen-java" />
|
||||
<property name="build" location="build" />
|
||||
|
||||
<path id="libs.classpath">
|
||||
<fileset dir="../../lib/java/build">
|
||||
<include name="*.jar" />
|
||||
<exclude name="-test.jar" />
|
||||
</fileset>
|
||||
<fileset dir="../../lib/java/build/lib">
|
||||
<include name="*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
<path id="build.classpath">
|
||||
<path refid="libs.classpath" />
|
||||
<pathelement path="${gen}" />
|
||||
</path>
|
||||
<path id="tutorial.classpath">
|
||||
<path refid="build.classpath" />
|
||||
<pathelement path="${build}" />
|
||||
<pathelement path="tutorial.jar" />
|
||||
</path>
|
||||
|
||||
<target name="init">
|
||||
<tstamp />
|
||||
<mkdir dir="${build}"/>
|
||||
<mkdir dir="${build}/log"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init, generate">
|
||||
<javac includeantruntime="false" srcdir="${gen}" destdir="${build}" classpathref="libs.classpath" />
|
||||
<javac includeantruntime="false" srcdir="${src}" destdir="${build}" classpathref="build.classpath" />
|
||||
</target>
|
||||
|
||||
<target name="test" depends="tutorial" />
|
||||
|
||||
<target name="tutorial" description="Run the tutorial" depends="compile">
|
||||
<jar jarfile="tutorial.jar" basedir="${build}"/>
|
||||
<parallel>
|
||||
<java classname="JavaServer" fork="true" timeout="10000"
|
||||
classpathref="tutorial.classpath" failonerror="false" output="${build}/log/tutorial.log">
|
||||
</java>
|
||||
<sequential>
|
||||
<sleep seconds="2"/>
|
||||
<echo>tutorial client simple:</echo>
|
||||
<java classname="JavaClient"
|
||||
classpathref="tutorial.classpath" failonerror="true">
|
||||
<arg line="simple"/>
|
||||
</java>
|
||||
<echo>tutorial client secure:</echo>
|
||||
<java classname="JavaClient"
|
||||
classpathref="tutorial.classpath" failonerror="true">
|
||||
<arg line="secure"/>
|
||||
</java>
|
||||
</sequential>
|
||||
</parallel>
|
||||
</target>
|
||||
|
||||
<target name="generate">
|
||||
<!-- Generate the thrift gen-java source -->
|
||||
<exec executable="../../compiler/cpp/thrift" failonerror="true">
|
||||
<arg line="--gen java -r ../tutorial.thrift"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="tutorialclient" description="Run a tutorial client" depends="compile">
|
||||
<echo>tutorial client simple:</echo>
|
||||
<java classname="JavaClient"
|
||||
classpathref="tutorial.classpath" failonerror="true">
|
||||
<arg line="simple"/>
|
||||
</java>
|
||||
<echo>tutorial client secure:</echo>
|
||||
<java classname="JavaClient"
|
||||
classpathref="tutorial.classpath" failonerror="true">
|
||||
<arg line="secure"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="tutorialserver" description="Run a tutorial server" depends="compile">
|
||||
<java classname="JavaServer" fork="true"
|
||||
classpathref="tutorial.classpath" failonerror="false" output="${build}/log/tutorial.log">
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${build}" />
|
||||
<delete dir="${gen}"/>
|
||||
<delete file="tutorial.jar" />
|
||||
</target>
|
||||
|
||||
</project>
|
92
vendor/git.apache.org/thrift.git/tutorial/java/src/CalculatorHandler.java
generated
vendored
Normal file
92
vendor/git.apache.org/thrift.git/tutorial/java/src/CalculatorHandler.java
generated
vendored
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.thrift.TException;
|
||||
|
||||
// Generated code
|
||||
import tutorial.*;
|
||||
import shared.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CalculatorHandler implements Calculator.Iface {
|
||||
|
||||
private HashMap<Integer,SharedStruct> log;
|
||||
|
||||
public CalculatorHandler() {
|
||||
log = new HashMap<Integer, SharedStruct>();
|
||||
}
|
||||
|
||||
public void ping() {
|
||||
System.out.println("ping()");
|
||||
}
|
||||
|
||||
public int add(int n1, int n2) {
|
||||
System.out.println("add(" + n1 + "," + n2 + ")");
|
||||
return n1 + n2;
|
||||
}
|
||||
|
||||
public int calculate(int logid, Work work) throws InvalidOperation {
|
||||
System.out.println("calculate(" + logid + ", {" + work.op + "," + work.num1 + "," + work.num2 + "})");
|
||||
int val = 0;
|
||||
switch (work.op) {
|
||||
case ADD:
|
||||
val = work.num1 + work.num2;
|
||||
break;
|
||||
case SUBTRACT:
|
||||
val = work.num1 - work.num2;
|
||||
break;
|
||||
case MULTIPLY:
|
||||
val = work.num1 * work.num2;
|
||||
break;
|
||||
case DIVIDE:
|
||||
if (work.num2 == 0) {
|
||||
InvalidOperation io = new InvalidOperation();
|
||||
io.whatOp = work.op.getValue();
|
||||
io.why = "Cannot divide by 0";
|
||||
throw io;
|
||||
}
|
||||
val = work.num1 / work.num2;
|
||||
break;
|
||||
default:
|
||||
InvalidOperation io = new InvalidOperation();
|
||||
io.whatOp = work.op.getValue();
|
||||
io.why = "Unknown operation";
|
||||
throw io;
|
||||
}
|
||||
|
||||
SharedStruct entry = new SharedStruct();
|
||||
entry.key = logid;
|
||||
entry.value = Integer.toString(val);
|
||||
log.put(logid, entry);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public SharedStruct getStruct(int key) {
|
||||
System.out.println("getStruct(" + key + ")");
|
||||
return log.get(key);
|
||||
}
|
||||
|
||||
public void zip() {
|
||||
System.out.println("zip()");
|
||||
}
|
||||
|
||||
}
|
||||
|
106
vendor/git.apache.org/thrift.git/tutorial/java/src/JavaClient.java
generated
vendored
Normal file
106
vendor/git.apache.org/thrift.git/tutorial/java/src/JavaClient.java
generated
vendored
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
// Generated code
|
||||
import tutorial.*;
|
||||
import shared.*;
|
||||
|
||||
import org.apache.thrift.TException;
|
||||
import org.apache.thrift.transport.TSSLTransportFactory;
|
||||
import org.apache.thrift.transport.TTransport;
|
||||
import org.apache.thrift.transport.TSocket;
|
||||
import org.apache.thrift.transport.TSSLTransportFactory.TSSLTransportParameters;
|
||||
import org.apache.thrift.protocol.TBinaryProtocol;
|
||||
import org.apache.thrift.protocol.TProtocol;
|
||||
|
||||
public class JavaClient {
|
||||
public static void main(String [] args) {
|
||||
|
||||
if (args.length != 1) {
|
||||
System.out.println("Please enter 'simple' or 'secure'");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
try {
|
||||
TTransport transport;
|
||||
if (args[0].contains("simple")) {
|
||||
transport = new TSocket("localhost", 9090);
|
||||
transport.open();
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* Similar to the server, you can use the parameters to setup client parameters or
|
||||
* use the default settings. On the client side, you will need a TrustStore which
|
||||
* contains the trusted certificate along with the public key.
|
||||
* For this example it's a self-signed cert.
|
||||
*/
|
||||
TSSLTransportParameters params = new TSSLTransportParameters();
|
||||
params.setTrustStore("../../lib/java/test/.truststore", "thrift", "SunX509", "JKS");
|
||||
/*
|
||||
* Get a client transport instead of a server transport. The connection is opened on
|
||||
* invocation of the factory method, no need to specifically call open()
|
||||
*/
|
||||
transport = TSSLTransportFactory.getClientSocket("localhost", 9091, 0, params);
|
||||
}
|
||||
|
||||
TProtocol protocol = new TBinaryProtocol(transport);
|
||||
Calculator.Client client = new Calculator.Client(protocol);
|
||||
|
||||
perform(client);
|
||||
|
||||
transport.close();
|
||||
} catch (TException x) {
|
||||
x.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void perform(Calculator.Client client) throws TException
|
||||
{
|
||||
client.ping();
|
||||
System.out.println("ping()");
|
||||
|
||||
int sum = client.add(1,1);
|
||||
System.out.println("1+1=" + sum);
|
||||
|
||||
Work work = new Work();
|
||||
|
||||
work.op = Operation.DIVIDE;
|
||||
work.num1 = 1;
|
||||
work.num2 = 0;
|
||||
try {
|
||||
int quotient = client.calculate(1, work);
|
||||
System.out.println("Whoa we can divide by 0");
|
||||
} catch (InvalidOperation io) {
|
||||
System.out.println("Invalid operation: " + io.why);
|
||||
}
|
||||
|
||||
work.op = Operation.SUBTRACT;
|
||||
work.num1 = 15;
|
||||
work.num2 = 10;
|
||||
try {
|
||||
int diff = client.calculate(1, work);
|
||||
System.out.println("15-10=" + diff);
|
||||
} catch (InvalidOperation io) {
|
||||
System.out.println("Invalid operation: " + io.why);
|
||||
}
|
||||
|
||||
SharedStruct log = client.getStruct(1);
|
||||
System.out.println("Check log: " + log.value);
|
||||
}
|
||||
}
|
110
vendor/git.apache.org/thrift.git/tutorial/java/src/JavaServer.java
generated
vendored
Normal file
110
vendor/git.apache.org/thrift.git/tutorial/java/src/JavaServer.java
generated
vendored
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.thrift.server.TServer;
|
||||
import org.apache.thrift.server.TServer.Args;
|
||||
import org.apache.thrift.server.TSimpleServer;
|
||||
import org.apache.thrift.server.TThreadPoolServer;
|
||||
import org.apache.thrift.transport.TSSLTransportFactory;
|
||||
import org.apache.thrift.transport.TServerSocket;
|
||||
import org.apache.thrift.transport.TServerTransport;
|
||||
import org.apache.thrift.transport.TSSLTransportFactory.TSSLTransportParameters;
|
||||
|
||||
// Generated code
|
||||
import tutorial.*;
|
||||
import shared.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class JavaServer {
|
||||
|
||||
public static CalculatorHandler handler;
|
||||
|
||||
public static Calculator.Processor processor;
|
||||
|
||||
public static void main(String [] args) {
|
||||
try {
|
||||
handler = new CalculatorHandler();
|
||||
processor = new Calculator.Processor(handler);
|
||||
|
||||
Runnable simple = new Runnable() {
|
||||
public void run() {
|
||||
simple(processor);
|
||||
}
|
||||
};
|
||||
Runnable secure = new Runnable() {
|
||||
public void run() {
|
||||
secure(processor);
|
||||
}
|
||||
};
|
||||
|
||||
new Thread(simple).start();
|
||||
new Thread(secure).start();
|
||||
} catch (Exception x) {
|
||||
x.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void simple(Calculator.Processor processor) {
|
||||
try {
|
||||
TServerTransport serverTransport = new TServerSocket(9090);
|
||||
TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
|
||||
|
||||
// Use this for a multithreaded server
|
||||
// TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
|
||||
|
||||
System.out.println("Starting the simple server...");
|
||||
server.serve();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void secure(Calculator.Processor processor) {
|
||||
try {
|
||||
/*
|
||||
* Use TSSLTransportParameters to setup the required SSL parameters. In this example
|
||||
* we are setting the keystore and the keystore password. Other things like algorithms,
|
||||
* cipher suites, client auth etc can be set.
|
||||
*/
|
||||
TSSLTransportParameters params = new TSSLTransportParameters();
|
||||
// The Keystore contains the private key
|
||||
params.setKeyStore("../../lib/java/test/.keystore", "thrift", null, null);
|
||||
|
||||
/*
|
||||
* Use any of the TSSLTransportFactory to get a server transport with the appropriate
|
||||
* SSL configuration. You can use the default settings if properties are set in the command line.
|
||||
* Ex: -Djavax.net.ssl.keyStore=.keystore and -Djavax.net.ssl.keyStorePassword=thrift
|
||||
*
|
||||
* Note: You need not explicitly call open(). The underlying server socket is bound on return
|
||||
* from the factory class.
|
||||
*/
|
||||
TServerTransport serverTransport = TSSLTransportFactory.getServerSocket(9091, 0, null, params);
|
||||
TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
|
||||
|
||||
// Use this for a multi threaded server
|
||||
// TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
|
||||
|
||||
System.out.println("Starting the secure server...");
|
||||
server.serve();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
39
vendor/git.apache.org/thrift.git/tutorial/js/Makefile.am
generated
vendored
Executable file
39
vendor/git.apache.org/thrift.git/tutorial/js/Makefile.am
generated
vendored
Executable file
|
@ -0,0 +1,39 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
export CLASSPATH
|
||||
|
||||
# Make sure this doesn't fail if ant is not configured.
|
||||
clean-local:
|
||||
ANT=$(ANT) ; if test -z "$$ANT" ; then ANT=: ; fi ; \
|
||||
$$ANT $(ANT_FLAGS) clean
|
||||
|
||||
all-local:
|
||||
$(ANT) $(ANT_FLAGS) compile
|
||||
|
||||
check-local: all
|
||||
$(ANT) $(ANT_FLAGS) test
|
||||
|
||||
tutorialserver: all
|
||||
$(ANT) $(ANT_FLAGS) tutorialserver
|
||||
|
||||
EXTRA_DIST = \
|
||||
build.xml \
|
||||
src \
|
||||
tutorial.html
|
90
vendor/git.apache.org/thrift.git/tutorial/js/build.xml
generated
vendored
Normal file
90
vendor/git.apache.org/thrift.git/tutorial/js/build.xml
generated
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<project name="tutorial" default="test" basedir=".">
|
||||
|
||||
<description>Thrift JavaScript Tutorial</description>
|
||||
|
||||
<property name="src" location="src" />
|
||||
<property name="javasrc" location="../java/src" />
|
||||
<property name="gen" location="../java/gen-java" />
|
||||
<property name="build" location="build" />
|
||||
|
||||
<!-- the root directory, where you unpack thrift distibution (e.g. thrift-0.x.x.tar.gz) -->
|
||||
<property name="thrift.dir" location="../../" />
|
||||
<!-- JavaScript tutorial depends on the java tutorial thrift handler and server infrastructure -->
|
||||
<property name="thrift.java.dir" location="${thrift.dir}/lib/java" />
|
||||
|
||||
<path id="libs.classpath">
|
||||
<fileset dir="../../lib/java/build">
|
||||
<include name="*.jar" />
|
||||
<exclude name="-test.jar" />
|
||||
</fileset>
|
||||
<fileset dir="../../lib/java/build/lib">
|
||||
<include name="*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
<path id="build.classpath">
|
||||
<path refid="libs.classpath" />
|
||||
<pathelement path="${gen}" />
|
||||
<pathelement path="${build}" />
|
||||
</path>
|
||||
|
||||
<target name="init">
|
||||
<tstamp />
|
||||
<mkdir dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init">
|
||||
<javac includeantruntime="false" srcdir="${gen}" destdir="${build}" classpathref="libs.classpath" />
|
||||
<javac includeantruntime="false" srcdir="${javasrc}" destdir="${build}" classpathref="build.classpath">
|
||||
<exclude name="JavaClient.java"/>
|
||||
<exclude name="JavaServer.java"/>
|
||||
<include name="CalculatorHandler.java"/>
|
||||
</javac>
|
||||
<javac includeantruntime="false" srcdir="${src}" destdir="${build}" classpathref="build.classpath">
|
||||
<compilerarg value="-Xlint:all"/>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="test" depends="tutorial" />
|
||||
|
||||
<target name="tutorial" depends="compile">
|
||||
<jar jarfile="tutorial-js.jar" basedir="${build}"/>
|
||||
</target>
|
||||
|
||||
<target name="tutorialserver" description="run the test server" depends="tutorial, generate">
|
||||
<java classname="Httpd" fork="true"
|
||||
classpathref="build.classpath" failonerror="true">
|
||||
<arg value="../../" />
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="generate">
|
||||
<exec executable="../../compiler/cpp/thrift" failonerror="true">
|
||||
<arg line="--gen js -r ../tutorial.thrift"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${build}" />
|
||||
<delete dir="gen-js"/>
|
||||
<delete file="tutorial-js.jar" />
|
||||
</target>
|
||||
|
||||
</project>
|
299
vendor/git.apache.org/thrift.git/tutorial/js/src/Httpd.java
generated
vendored
Normal file
299
vendor/git.apache.org/thrift.git/tutorial/js/src/Httpd.java
generated
vendored
Normal file
|
@ -0,0 +1,299 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.http.ConnectionClosedException;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpServerConnection;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.MethodNotSupportedException;
|
||||
import org.apache.http.entity.ContentProducer;
|
||||
import org.apache.http.entity.EntityTemplate;
|
||||
import org.apache.http.entity.FileEntity;
|
||||
import org.apache.http.impl.DefaultHttpResponseFactory;
|
||||
import org.apache.http.impl.DefaultHttpServerConnection;
|
||||
import org.apache.http.impl.NoConnectionReuseStrategy;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.CoreConnectionPNames;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.BasicHttpProcessor;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpProcessor;
|
||||
import org.apache.http.protocol.HttpRequestHandler;
|
||||
import org.apache.http.protocol.HttpRequestHandlerRegistry;
|
||||
import org.apache.http.protocol.HttpService;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.thrift.TProcessor;
|
||||
import org.apache.thrift.protocol.TJSONProtocol;
|
||||
import org.apache.thrift.protocol.TProtocol;
|
||||
import org.apache.thrift.transport.TMemoryBuffer;
|
||||
|
||||
// Generated code
|
||||
import tutorial.*;
|
||||
import shared.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Basic, yet fully functional and spec compliant, HTTP/1.1 file server.
|
||||
* <p>
|
||||
* Please note the purpose of this application is demonstrate the usage of
|
||||
* HttpCore APIs. It is NOT intended to demonstrate the most efficient way of
|
||||
* building an HTTP file server.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class Httpd {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length < 1) {
|
||||
System.err.println("Please specify document root directory");
|
||||
System.exit(1);
|
||||
}
|
||||
Thread t = new RequestListenerThread(8088, args[0]);
|
||||
t.setDaemon(false);
|
||||
t.start();
|
||||
}
|
||||
|
||||
static class HttpFileHandler implements HttpRequestHandler {
|
||||
|
||||
private final String docRoot;
|
||||
|
||||
public HttpFileHandler(final String docRoot) {
|
||||
super();
|
||||
this.docRoot = docRoot;
|
||||
}
|
||||
|
||||
public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException {
|
||||
|
||||
String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
|
||||
if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) {
|
||||
throw new MethodNotSupportedException(method + " method not supported");
|
||||
}
|
||||
String target = request.getRequestLine().getUri();
|
||||
|
||||
if (request instanceof HttpEntityEnclosingRequest && target.equals("/thrift/service/tutorial/")) {
|
||||
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
|
||||
byte[] entityContent = EntityUtils.toByteArray(entity);
|
||||
System.out.println("Incoming content: " + new String(entityContent));
|
||||
|
||||
final String output = this.thriftRequest(entityContent);
|
||||
|
||||
System.out.println("Outgoing content: "+output);
|
||||
|
||||
EntityTemplate body = new EntityTemplate(new ContentProducer() {
|
||||
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
|
||||
writer.write(output);
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
});
|
||||
body.setContentType("text/html; charset=UTF-8");
|
||||
response.setEntity(body);
|
||||
} else {
|
||||
final File file = new File(this.docRoot, URLDecoder.decode(target, "UTF-8"));
|
||||
if (!file.exists()) {
|
||||
|
||||
response.setStatusCode(HttpStatus.SC_NOT_FOUND);
|
||||
EntityTemplate body = new EntityTemplate(new ContentProducer() {
|
||||
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
|
||||
writer.write("<html><body><h1>");
|
||||
writer.write("File ");
|
||||
writer.write(file.getPath());
|
||||
writer.write(" not found");
|
||||
writer.write("</h1></body></html>");
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
});
|
||||
body.setContentType("text/html; charset=UTF-8");
|
||||
response.setEntity(body);
|
||||
System.out.println("File " + file.getPath() + " not found");
|
||||
|
||||
} else if (!file.canRead() || file.isDirectory()) {
|
||||
|
||||
response.setStatusCode(HttpStatus.SC_FORBIDDEN);
|
||||
EntityTemplate body = new EntityTemplate(new ContentProducer() {
|
||||
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
|
||||
writer.write("<html><body><h1>");
|
||||
writer.write("Access denied");
|
||||
writer.write("</h1></body></html>");
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
});
|
||||
body.setContentType("text/html; charset=UTF-8");
|
||||
response.setEntity(body);
|
||||
System.out.println("Cannot read file " + file.getPath());
|
||||
|
||||
} else {
|
||||
|
||||
response.setStatusCode(HttpStatus.SC_OK);
|
||||
FileEntity body = new FileEntity(file, "text/html");
|
||||
response.setEntity(body);
|
||||
System.out.println("Serving file " + file.getPath());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String thriftRequest(byte[] input){
|
||||
try{
|
||||
|
||||
//Input
|
||||
TMemoryBuffer inbuffer = new TMemoryBuffer(input.length);
|
||||
inbuffer.write(input);
|
||||
TProtocol inprotocol = new TJSONProtocol(inbuffer);
|
||||
|
||||
//Output
|
||||
TMemoryBuffer outbuffer = new TMemoryBuffer(100);
|
||||
TProtocol outprotocol = new TJSONProtocol(outbuffer);
|
||||
|
||||
TProcessor processor = new Calculator.Processor(new CalculatorHandler());
|
||||
processor.process(inprotocol, outprotocol);
|
||||
|
||||
byte[] output = new byte[outbuffer.length()];
|
||||
outbuffer.readAll(output, 0, output.length);
|
||||
|
||||
return new String(output,"UTF-8");
|
||||
}catch(Throwable t){
|
||||
return "Error:"+t.getMessage();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class RequestListenerThread extends Thread {
|
||||
|
||||
private final ServerSocket serversocket;
|
||||
private final HttpParams params;
|
||||
private final HttpService httpService;
|
||||
|
||||
public RequestListenerThread(int port, final String docroot) throws IOException {
|
||||
this.serversocket = new ServerSocket(port);
|
||||
this.params = new BasicHttpParams();
|
||||
this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 1000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
|
||||
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
|
||||
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
|
||||
|
||||
// Set up the HTTP protocol processor
|
||||
HttpProcessor httpproc = new BasicHttpProcessor();
|
||||
|
||||
// Set up request handlers
|
||||
HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
|
||||
reqistry.register("*", new HttpFileHandler(docroot));
|
||||
|
||||
// Set up the HTTP service
|
||||
this.httpService = new HttpService(httpproc, new NoConnectionReuseStrategy(), new DefaultHttpResponseFactory());
|
||||
this.httpService.setParams(this.params);
|
||||
this.httpService.setHandlerResolver(reqistry);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
System.out.println("Listening on port " + this.serversocket.getLocalPort());
|
||||
System.out.println("Point your browser to http://localhost:8088/tutorial/js/tutorial.html");
|
||||
|
||||
while (!Thread.interrupted()) {
|
||||
try {
|
||||
// Set up HTTP connection
|
||||
Socket socket = this.serversocket.accept();
|
||||
DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
|
||||
System.out.println("Incoming connection from " + socket.getInetAddress());
|
||||
conn.bind(socket, this.params);
|
||||
|
||||
// Start worker thread
|
||||
Thread t = new WorkerThread(this.httpService, conn);
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
} catch (InterruptedIOException ex) {
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
System.err.println("I/O error initialising connection thread: " + e.getMessage());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class WorkerThread extends Thread {
|
||||
|
||||
private final HttpService httpservice;
|
||||
private final HttpServerConnection conn;
|
||||
|
||||
public WorkerThread(final HttpService httpservice, final HttpServerConnection conn) {
|
||||
super();
|
||||
this.httpservice = httpservice;
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
System.out.println("New connection thread");
|
||||
HttpContext context = new BasicHttpContext(null);
|
||||
try {
|
||||
while (!Thread.interrupted() && this.conn.isOpen()) {
|
||||
this.httpservice.handleRequest(this.conn, context);
|
||||
}
|
||||
} catch (ConnectionClosedException ex) {
|
||||
System.err.println("Client closed connection");
|
||||
} catch (IOException ex) {
|
||||
System.err.println("I/O error: " + ex.getMessage());
|
||||
} catch (HttpException ex) {
|
||||
System.err.println("Unrecoverable HTTP protocol violation: " + ex.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
this.conn.shutdown();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
109
vendor/git.apache.org/thrift.git/tutorial/js/tutorial.html
generated
vendored
Executable file
109
vendor/git.apache.org/thrift.git/tutorial/js/tutorial.html
generated
vendored
Executable file
|
@ -0,0 +1,109 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>Thrift Javascript Bindings - Tutorial Example</title>
|
||||
|
||||
<script src="../../lib/js/src/thrift.js" type="text/javascript"></script>
|
||||
<script src="gen-js/tutorial_types.js" type="text/javascript"></script>
|
||||
<script src="gen-js/shared_types.js" type="text/javascript"></script>
|
||||
<script src="gen-js/SharedService.js" type="text/javascript"></script>
|
||||
<script src="gen-js/Calculator.js" type="text/javascript"></script>
|
||||
|
||||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
|
||||
|
||||
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
//<![CDATA[
|
||||
$(document).ready(function(){
|
||||
// remove pseudo child required for valid xhtml strict
|
||||
$("#op").children().remove();
|
||||
// add operations to it's dropdown menu
|
||||
$.each(Operation, function(key, value) {
|
||||
$('#op').append($("<option></option>").attr("value",value).text(key));
|
||||
});
|
||||
|
||||
$('table.calculator').attr('width', 500);
|
||||
});
|
||||
|
||||
function calc() {
|
||||
var transport = new Thrift.Transport("/thrift/service/tutorial/");
|
||||
var protocol = new Thrift.Protocol(transport);
|
||||
var client = new CalculatorClient(protocol);
|
||||
|
||||
var work = new Work();
|
||||
work.num1 = $("#num1").val();
|
||||
work.num2 = $("#num2").val();
|
||||
work.op = $("#op").val();
|
||||
|
||||
try {
|
||||
result = client.calculate(1, work);
|
||||
$('#result').val(result);
|
||||
$('#result').css('color', 'black');
|
||||
} catch(ouch){
|
||||
$('#result').val(ouch.why);
|
||||
$('#result').css('color', 'red');
|
||||
}
|
||||
}
|
||||
|
||||
function auto_calc() {
|
||||
if ($('#autoupdate:checked').val() !== undefined) {
|
||||
calc();
|
||||
}
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h2>Thrift Javascript Bindings</h2>
|
||||
<form action="">
|
||||
<table class="calculator">
|
||||
<tr>
|
||||
<td>num1</td>
|
||||
<td><input type="text" id="num1" value="20" onkeyup="javascript:auto_calc();"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Operation</td>
|
||||
<td><select id="op" size="1" onchange="javascript:auto_calc();"><option></option></select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>num2</td>
|
||||
<td><input type="text" id="num2" value="5" onkeyup="javascript:auto_calc();"/></td></tr>
|
||||
<tr>
|
||||
<td>result</td>
|
||||
<td><input type="text" id="result" value=""/></td></tr>
|
||||
<tr>
|
||||
<td><input type="checkbox" id="autoupdate" checked="checked"/>autoupdate</td>
|
||||
<td><input type="button" id="calculate" value="calculate" onclick="javascript:calc();"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<p>This Java Script example uses <a href="https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob;f=tutorial/tutorial.thrift;hb=HEAD">tutorial.thrift</a> and a Thrift server using JSON protocol and HTTP transport.
|
||||
</p>
|
||||
<p>
|
||||
<a href="http://validator.w3.org/check/referer"><img
|
||||
src="http://www.w3.org/Icons/valid-xhtml10"
|
||||
alt="Valid XHTML 1.0!" height="31" width="88" /></a>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
47
vendor/git.apache.org/thrift.git/tutorial/nodejs/Makefile.am
generated
vendored
Normal file
47
vendor/git.apache.org/thrift.git/tutorial/nodejs/Makefile.am
generated
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
THRIFT = $(top_builddir)/compiler/cpp/thrift
|
||||
|
||||
gen-nodejs/Calculator.js gen-nodejs/SharedService.js: $(top_srcdir)/tutorial/tutorial.thrift
|
||||
$(THRIFT) --gen js:node -r $<
|
||||
|
||||
all-local: gen-nodejs/Calculator.js
|
||||
|
||||
tutorialserver: all
|
||||
NODE_PATH="$(top_builddir)/lib/nodejs:$(top_builddir)/lib/nodejs/lib:$(NODEPATH)" $(NODEJS) NodeServer.js
|
||||
|
||||
tutorialclient: all
|
||||
NODE_PATH="$(top_builddir)/lib/nodejs:$(top_builddir)/lib/nodejs/lib:$(NODEPATH)" $(NODEJS) NodeClient.js
|
||||
|
||||
tutorialserver_promise: all
|
||||
NODE_PATH="$(top_builddir)/lib/nodejs:$(top_builddir)/lib/nodejs/lib:$(NODEPATH)" $(NODEJS) NodeServerPromise.js
|
||||
|
||||
tutorialclient_promise: all
|
||||
NODE_PATH="$(top_builddir)/lib/nodejs:$(top_builddir)/lib/nodejs/lib:$(NODEPATH)" $(NODEJS) NodeClientPromise.js
|
||||
|
||||
|
||||
clean-local:
|
||||
$(RM) -r gen-*
|
||||
|
||||
EXTRA_DIST = \
|
||||
NodeServer.js \
|
||||
NodeClient.js \
|
||||
NodeServerPromise.js \
|
||||
NodeClientPromise.js
|
77
vendor/git.apache.org/thrift.git/tutorial/nodejs/NodeClient.js
generated
vendored
Normal file
77
vendor/git.apache.org/thrift.git/tutorial/nodejs/NodeClient.js
generated
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var thrift = require('thrift');
|
||||
var Calculator = require('./gen-nodejs/Calculator');
|
||||
var ttypes = require('./gen-nodejs/tutorial_types');
|
||||
|
||||
|
||||
var transport = thrift.TBufferedTransport;
|
||||
var protocol = thrift.TBinaryProtocol;
|
||||
|
||||
var connection = thrift.createConnection("localhost", 9090, {
|
||||
transport : transport,
|
||||
protocol : protocol
|
||||
});
|
||||
|
||||
connection.on('error', function(err) {
|
||||
assert(false, err);
|
||||
});
|
||||
|
||||
// Create a Calculator client with the connection
|
||||
var client = thrift.createClient(Calculator, connection);
|
||||
|
||||
|
||||
client.ping(function(err, response) {
|
||||
console.log('ping()');
|
||||
});
|
||||
|
||||
|
||||
client.add(1,1, function(err, response) {
|
||||
console.log("1+1=" + response);
|
||||
});
|
||||
|
||||
|
||||
work = new ttypes.Work();
|
||||
work.op = ttypes.Operation.DIVIDE;
|
||||
work.num1 = 1;
|
||||
work.num2 = 0;
|
||||
|
||||
client.calculate(1, work, function(err, message) {
|
||||
if (err) {
|
||||
console.log("InvalidOperation " + err);
|
||||
} else {
|
||||
console.log('Whoa? You know how to divide by zero?');
|
||||
}
|
||||
});
|
||||
|
||||
work.op = ttypes.Operation.SUBTRACT;
|
||||
work.num1 = 15;
|
||||
work.num2 = 10;
|
||||
|
||||
client.calculate(1, work, function(err, message) {
|
||||
console.log('15-10=' + message);
|
||||
|
||||
client.getStruct(1, function(err, message){
|
||||
console.log('Check log: ' + message.value);
|
||||
|
||||
//close the connection once we're done
|
||||
connection.end();
|
||||
});
|
||||
});
|
80
vendor/git.apache.org/thrift.git/tutorial/nodejs/NodeClientPromise.js
generated
vendored
Normal file
80
vendor/git.apache.org/thrift.git/tutorial/nodejs/NodeClientPromise.js
generated
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var thrift = require('thrift');
|
||||
var Calculator = require('./gen-nodejs/Calculator');
|
||||
var ttypes = require('./gen-nodejs/tutorial_types');
|
||||
|
||||
|
||||
var transport = thrift.TBufferedTransport;
|
||||
var protocol = thrift.TBinaryProtocol;
|
||||
|
||||
var connection = thrift.createConnection("localhost", 9090, {
|
||||
transport : transport,
|
||||
protocol : protocol
|
||||
});
|
||||
|
||||
connection.on('error', function(err) {
|
||||
assert(false, err);
|
||||
});
|
||||
|
||||
// Create a Calculator client with the connection
|
||||
var client = thrift.createClient(Calculator, connection);
|
||||
|
||||
|
||||
client.ping()
|
||||
.then(function() {
|
||||
console.log('ping()');
|
||||
});
|
||||
|
||||
client.add(1,1)
|
||||
.then(function(response) {
|
||||
console.log("1+1=" + response);
|
||||
});
|
||||
|
||||
work = new ttypes.Work();
|
||||
work.op = ttypes.Operation.DIVIDE;
|
||||
work.num1 = 1;
|
||||
work.num2 = 0;
|
||||
|
||||
client.calculate(1, work)
|
||||
.then(function(message) {
|
||||
console.log('Whoa? You know how to divide by zero?');
|
||||
})
|
||||
.fail(function(err) {
|
||||
console.log("InvalidOperation " + err);
|
||||
});
|
||||
|
||||
|
||||
work.op = ttypes.Operation.SUBTRACT;
|
||||
work.num1 = 15;
|
||||
work.num2 = 10;
|
||||
|
||||
client.calculate(1, work)
|
||||
.then(function(value) {
|
||||
console.log('15-10=' + value);
|
||||
return client.getStruct(1);
|
||||
})
|
||||
.then(function(message) {
|
||||
console.log('Check log: ' + message.value);
|
||||
})
|
||||
.fin(function() {
|
||||
//close the connection once we're done
|
||||
connection.end();
|
||||
});
|
85
vendor/git.apache.org/thrift.git/tutorial/nodejs/NodeServer.js
generated
vendored
Normal file
85
vendor/git.apache.org/thrift.git/tutorial/nodejs/NodeServer.js
generated
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var thrift = require("thrift");
|
||||
var Calculator = require("./gen-nodejs/Calculator");
|
||||
var ttypes = require("./gen-nodejs/tutorial_types");
|
||||
var SharedStruct = require("./gen-nodejs/shared_types").SharedStruct;
|
||||
|
||||
var data = {};
|
||||
|
||||
var server = thrift.createServer(Calculator, {
|
||||
ping: function(result) {
|
||||
console.log("ping()");
|
||||
result(null);
|
||||
},
|
||||
|
||||
add: function(n1, n2, result) {
|
||||
console.log("add(", n1, ",", n2, ")");
|
||||
result(null, n1 + n2);
|
||||
},
|
||||
|
||||
calculate: function(logid, work, result) {
|
||||
console.log("calculate(", logid, ",", work, ")");
|
||||
|
||||
var val = 0;
|
||||
if (work.op == ttypes.Operation.ADD) {
|
||||
val = work.num1 + work.num2;
|
||||
} else if (work.op === ttypes.Operation.SUBTRACT) {
|
||||
val = work.num1 - work.num2;
|
||||
} else if (work.op === ttypes.Operation.MULTIPLY) {
|
||||
val = work.num1 * work.num2;
|
||||
} else if (work.op === ttypes.Operation.DIVIDE) {
|
||||
if (work.num2 === 0) {
|
||||
var x = new ttypes.InvalidOperation();
|
||||
x.whatOp = work.op;
|
||||
x.why = 'Cannot divide by 0';
|
||||
result(x);
|
||||
return;
|
||||
}
|
||||
val = work.num1 / work.num2;
|
||||
} else {
|
||||
var x = new ttypes.InvalidOperation();
|
||||
x.whatOp = work.op;
|
||||
x.why = 'Invalid operation';
|
||||
result(x);
|
||||
return;
|
||||
}
|
||||
|
||||
var entry = new SharedStruct();
|
||||
entry.key = logid;
|
||||
entry.value = ""+val;
|
||||
data[logid] = entry;
|
||||
|
||||
result(null, val);
|
||||
},
|
||||
|
||||
getStruct: function(key, result) {
|
||||
console.log("getStruct(", key, ")");
|
||||
result(null, data[key]);
|
||||
},
|
||||
|
||||
zip: function() {
|
||||
console.log("zip()");
|
||||
result(null);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
server.listen(9090);
|
80
vendor/git.apache.org/thrift.git/tutorial/nodejs/NodeServerPromise.js
generated
vendored
Normal file
80
vendor/git.apache.org/thrift.git/tutorial/nodejs/NodeServerPromise.js
generated
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
var thrift = require("thrift");
|
||||
var Calculator = require("./gen-nodejs/Calculator");
|
||||
var ttypes = require("./gen-nodejs/tutorial_types");
|
||||
var SharedStruct = require("./gen-nodejs/shared_types").SharedStruct;
|
||||
|
||||
var data = {};
|
||||
|
||||
var server = thrift.createServer(Calculator, {
|
||||
ping: function() {
|
||||
console.log("ping()");
|
||||
},
|
||||
|
||||
add: function(n1, n2) {
|
||||
console.log("add(", n1, ",", n2, ")");
|
||||
return n1 + n2;
|
||||
},
|
||||
|
||||
calculate: function(logid, work) {
|
||||
console.log("calculate(", logid, ",", work, ")");
|
||||
|
||||
var val = 0;
|
||||
if (work.op == ttypes.Operation.ADD) {
|
||||
val = work.num1 + work.num2;
|
||||
} else if (work.op === ttypes.Operation.SUBTRACT) {
|
||||
val = work.num1 - work.num2;
|
||||
} else if (work.op === ttypes.Operation.MULTIPLY) {
|
||||
val = work.num1 * work.num2;
|
||||
} else if (work.op === ttypes.Operation.DIVIDE) {
|
||||
if (work.num2 === 0) {
|
||||
var x = new ttypes.InvalidOperation();
|
||||
x.whatOp = work.op;
|
||||
x.why = 'Cannot divide by 0';
|
||||
throw x;
|
||||
}
|
||||
val = work.num1 / work.num2;
|
||||
} else {
|
||||
var x = new ttypes.InvalidOperation();
|
||||
x.whatOp = work.op;
|
||||
x.why = 'Invalid operation';
|
||||
throw x;
|
||||
}
|
||||
|
||||
var entry = new SharedStruct();
|
||||
entry.key = logid;
|
||||
entry.value = ""+val;
|
||||
data[logid] = entry;
|
||||
return val;
|
||||
},
|
||||
|
||||
getStruct: function(key) {
|
||||
console.log("getStruct(", key, ")");
|
||||
return data[key];
|
||||
},
|
||||
|
||||
zip: function() {
|
||||
console.log("zip()");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
server.listen(9090);
|
74
vendor/git.apache.org/thrift.git/tutorial/ocaml/CalcClient.ml
generated
vendored
Executable file
74
vendor/git.apache.org/thrift.git/tutorial/ocaml/CalcClient.ml
generated
vendored
Executable file
|
@ -0,0 +1,74 @@
|
|||
(*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*)
|
||||
|
||||
open Arg
|
||||
open Thrift
|
||||
open Tutorial_types
|
||||
open Shared_types
|
||||
|
||||
exception Die;;
|
||||
let sod = function
|
||||
Some v -> v
|
||||
| None -> raise Die;;
|
||||
|
||||
type connection = {
|
||||
trans : Transport.t ;
|
||||
proto : Thrift.Protocol.t;
|
||||
calc : Calculator.client ;
|
||||
}
|
||||
|
||||
let connect ~host port =
|
||||
let tx = new TSocket.t host port in
|
||||
let proto = new TBinaryProtocol.t tx in
|
||||
let calc = new Calculator.client proto proto in
|
||||
tx#opn;
|
||||
{ trans = tx ; proto = proto; calc = calc }
|
||||
;;
|
||||
|
||||
let doclient () =
|
||||
let cli = connect ~host:"127.0.0.1" 9090 in
|
||||
try
|
||||
cli.calc#ping ;
|
||||
Printf.printf "ping()\n" ; flush stdout ;
|
||||
(let sum = cli.calc#add (Int32.of_int 1) (Int32.of_int 1) in
|
||||
Printf.printf "1+1=%ld\n" sum ;
|
||||
flush stdout) ;
|
||||
(let w = new work in
|
||||
w#set_op Operation.DIVIDE ;
|
||||
w#set_num1 (Int32.of_int 1) ;
|
||||
w#set_num2 (Int32.of_int 0) ;
|
||||
try
|
||||
let quotient = cli.calc#calculate (Int32.of_int 1) w in
|
||||
Printf.printf "Whoa? We can divide by zero!\n" ; flush stdout
|
||||
with InvalidOperation io ->
|
||||
Printf.printf "InvalidOperation: %s\n" io#grab_why ; flush stdout) ;
|
||||
(let w = new work in
|
||||
w#set_op Operation.SUBTRACT ;
|
||||
w#set_num1 (Int32.of_int 15) ;
|
||||
w#set_num2 (Int32.of_int 10) ;
|
||||
let diff = cli.calc#calculate (Int32.of_int 1) w in
|
||||
Printf.printf "15-10=%ld\n" diff ; flush stdout) ;
|
||||
(let ss = cli.calc#getStruct (Int32.of_int 1) in
|
||||
Printf.printf "Check log: %s\n" ss#grab_value ; flush stdout) ;
|
||||
cli.trans#close
|
||||
with Transport.E (_,what) ->
|
||||
Printf.printf "ERROR: %s\n" what ; flush stdout
|
||||
;;
|
||||
|
||||
doclient();;
|
89
vendor/git.apache.org/thrift.git/tutorial/ocaml/CalcServer.ml
generated
vendored
Executable file
89
vendor/git.apache.org/thrift.git/tutorial/ocaml/CalcServer.ml
generated
vendored
Executable file
|
@ -0,0 +1,89 @@
|
|||
(*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*)
|
||||
|
||||
open Arg
|
||||
open Thrift
|
||||
open Tutorial_types
|
||||
open Shared_types
|
||||
|
||||
exception Die;;
|
||||
let sod = function
|
||||
Some v -> v
|
||||
| None -> raise Die;;
|
||||
|
||||
class calc_handler =
|
||||
object (self)
|
||||
inherit Calculator.iface
|
||||
val log = Hashtbl.create 23
|
||||
method ping = Printf.printf "ping()\n" ; flush stdout
|
||||
method add a b =
|
||||
Printf.printf"add(%ld,%ld)\n" (sod a) (sod b); flush stdout ;
|
||||
Int32.add (sod a) (sod b)
|
||||
method calculate logid w =
|
||||
let w = sod w in
|
||||
Printf.printf "calculate(%ld,{%ld,%ld,%ld})\n" (sod logid) (Operation.to_i w#grab_op) w#grab_num1 w#grab_num2; flush stdout ;
|
||||
let rv =
|
||||
match w#grab_op with
|
||||
Operation.ADD ->
|
||||
Int32.add w#grab_num1 w#grab_num2
|
||||
| Operation.SUBTRACT ->
|
||||
Int32.sub w#grab_num1 w#grab_num2
|
||||
| Operation.MULTIPLY ->
|
||||
Int32.mul w#grab_num1 w#grab_num2
|
||||
| Operation.DIVIDE ->
|
||||
if w#grab_num2 = Int32.zero then
|
||||
let io = new invalidOperation in
|
||||
io#set_whatOp (Operation.to_i w#grab_op) ;
|
||||
io#set_why "Cannot divide by 0" ;
|
||||
raise (InvalidOperation io)
|
||||
else
|
||||
Int32.div w#grab_num1 w#grab_num2 in
|
||||
|
||||
let ss = new sharedStruct in
|
||||
ss#set_key (sod logid) ;
|
||||
let buffer = Int32.to_string rv in
|
||||
ss#set_value buffer ;
|
||||
Hashtbl.add log (sod logid) ss ;
|
||||
rv
|
||||
|
||||
method zip =
|
||||
Printf.printf "zip()\n"; flush stdout
|
||||
|
||||
method getStruct logid =
|
||||
Printf.printf "getStruct(%ld)\n" (sod logid) ; flush stdout ;
|
||||
Hashtbl.find log (sod logid)
|
||||
|
||||
end
|
||||
|
||||
let doserver () =
|
||||
let h = new calc_handler in
|
||||
let proc = new Calculator.processor h in
|
||||
let port = 9090 in
|
||||
let pf = new TBinaryProtocol.factory in
|
||||
let server = new TThreadedServer.t
|
||||
proc
|
||||
(new TServerSocket.t port)
|
||||
(new Transport.factory)
|
||||
pf
|
||||
pf
|
||||
in
|
||||
server#serve
|
||||
;;
|
||||
|
||||
doserver();;
|
15
vendor/git.apache.org/thrift.git/tutorial/ocaml/README.md
generated
vendored
Normal file
15
vendor/git.apache.org/thrift.git/tutorial/ocaml/README.md
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
This is the ocaml tutorial example. It assumes that you've already
|
||||
built and installed the thrift ocaml runtime libraries in lib/ocaml.
|
||||
|
||||
To compile this, you will need to generate the Thrift sources for
|
||||
ocaml in this directory (due to limitations in the OASIS build-tool):
|
||||
|
||||
% thrift -r --gen ocaml ../tutorial.thrift
|
||||
% oasis setup
|
||||
% make
|
||||
|
||||
This will produce two executables Calc{Server,Client}.<type> where
|
||||
<type> is one of "byte" or "native", depending on your ocaml
|
||||
installation. Just run the server in the background, then the client
|
||||
(as you would do for the C++ example).
|
32
vendor/git.apache.org/thrift.git/tutorial/ocaml/_oasis
generated
vendored
Normal file
32
vendor/git.apache.org/thrift.git/tutorial/ocaml/_oasis
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
Name: tutorial
|
||||
Version: 0.10.0
|
||||
OASISFormat: 0.3
|
||||
Synopsis: OCaml Tutorial example
|
||||
Authors: Apache Thrift Developers <dev@thrift.apache.org>
|
||||
License: Apache-2.0
|
||||
Homepage: http://thrift.apache.org
|
||||
BuildTools: ocamlbuild
|
||||
Plugins: META (0.3),
|
||||
DevFiles (0.3)
|
||||
|
||||
Library tutorial_thrift
|
||||
Path: gen-ocaml
|
||||
FindlibName: tutorial_thrift
|
||||
buildTools: ocamlbuild
|
||||
BuildDepends: threads,thrift
|
||||
Modules: Calculator,Shared_consts,Tutorial_consts,SharedService,Shared_types,Tutorial_types
|
||||
XMETARequires: threads
|
||||
|
||||
Executable CalcClient
|
||||
Path: .
|
||||
MainIs: CalcClient.ml
|
||||
Build$: true
|
||||
CompiledObject: best
|
||||
BuildDepends: thrift, tutorial_thrift, threads
|
||||
|
||||
Executable CalcServer
|
||||
Path: .
|
||||
MainIs: CalcServer.ml
|
||||
Build$: true
|
||||
CompiledObject: best
|
||||
BuildDepends: thrift, tutorial_thrift, threads
|
82
vendor/git.apache.org/thrift.git/tutorial/perl/PerlClient.pl
generated
vendored
Normal file
82
vendor/git.apache.org/thrift.git/tutorial/perl/PerlClient.pl
generated
vendored
Normal file
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use lib '../../lib/perl/lib';
|
||||
use lib '../gen-perl';
|
||||
|
||||
use Thrift;
|
||||
use Thrift::BinaryProtocol;
|
||||
use Thrift::Socket;
|
||||
use Thrift::BufferedTransport;
|
||||
|
||||
use shared::SharedService;
|
||||
use tutorial::Calculator;
|
||||
use shared::Types;
|
||||
use tutorial::Types;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
my $socket = new Thrift::Socket('localhost',9090);
|
||||
my $transport = new Thrift::BufferedTransport($socket,1024,1024);
|
||||
my $protocol = new Thrift::BinaryProtocol($transport);
|
||||
my $client = new tutorial::CalculatorClient($protocol);
|
||||
|
||||
|
||||
eval{
|
||||
$transport->open();
|
||||
|
||||
$client->ping();
|
||||
print "ping()\n";
|
||||
|
||||
|
||||
my $sum = $client->add(1,1);
|
||||
print "1+1=$sum\n";
|
||||
|
||||
my $work = new tutorial::Work();
|
||||
|
||||
$work->op(tutorial::Operation::DIVIDE);
|
||||
$work->num1(1);
|
||||
$work->num2(0);
|
||||
|
||||
eval {
|
||||
$client->calculate(1, $work);
|
||||
print "Whoa! We can divide by zero?\n";
|
||||
}; if($@) {
|
||||
warn "InvalidOperation: ".Dumper($@);
|
||||
}
|
||||
|
||||
$work->op(tutorial::Operation::SUBTRACT);
|
||||
$work->num1(15);
|
||||
$work->num2(10);
|
||||
my $diff = $client->calculate(1, $work);
|
||||
print "15-10=$diff\n";
|
||||
|
||||
my $log = $client->getStruct(1);
|
||||
print "Log: $log->{value}\n";
|
||||
|
||||
$transport->close();
|
||||
|
||||
}; if($@){
|
||||
warn(Dumper($@));
|
||||
}
|
124
vendor/git.apache.org/thrift.git/tutorial/perl/PerlServer.pl
generated
vendored
Normal file
124
vendor/git.apache.org/thrift.git/tutorial/perl/PerlServer.pl
generated
vendored
Normal file
|
@ -0,0 +1,124 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
use strict;
|
||||
use lib '../gen-perl';
|
||||
use Thrift::Socket;
|
||||
use Thrift::Server;
|
||||
use tutorial::Calculator;
|
||||
|
||||
package CalculatorHandler;
|
||||
use base qw(tutorial::CalculatorIf);
|
||||
|
||||
sub new {
|
||||
my $classname = shift;
|
||||
my $self = {};
|
||||
|
||||
return bless($self,$classname);
|
||||
}
|
||||
|
||||
|
||||
sub ping
|
||||
{
|
||||
print "ping()\n";
|
||||
}
|
||||
|
||||
sub add
|
||||
{
|
||||
my($self, $n1, $n2) = @_;
|
||||
printf("add(%d,%d)\n", $n1, $n2);
|
||||
return $n1 + $n2;
|
||||
}
|
||||
|
||||
sub calculate
|
||||
{
|
||||
my($self, $logid, $work) = @_;
|
||||
my $op = $work->{op};
|
||||
my $num1 = $work->{num1};
|
||||
my $num2 = $work->{num2};
|
||||
printf("calculate(%d, %d %d %d)\n", $logid, $num1, $num2, $op);
|
||||
|
||||
my $val;
|
||||
|
||||
if ($op == tutorial::Operation::ADD) {
|
||||
$val = $num1 + $num2;
|
||||
} elsif ($op == tutorial::Operation::SUBTRACT) {
|
||||
$val = $num1 - $num2;
|
||||
} elsif ($op == tutorial::Operation::MULTIPLY) {
|
||||
$val = $num1 * $num2;
|
||||
} elsif ($op == tutorial::Operation::DIVIDE) {
|
||||
if ($num2 == 0)
|
||||
{
|
||||
my $x = new tutorial::InvalidOperation;
|
||||
$x->whatOp($op);
|
||||
$x->why('Cannot divide by 0');
|
||||
die $x;
|
||||
}
|
||||
$val = $num1 / $num2;
|
||||
} else {
|
||||
my $x = new tutorial::InvalidOperation;
|
||||
$x->whatOp($op);
|
||||
$x->why('Invalid operation');
|
||||
die $x;
|
||||
}
|
||||
|
||||
my $log = new shared::SharedStruct;
|
||||
$log->key($logid);
|
||||
$log->value(int($val));
|
||||
$self->{log}->{$logid} = $log;
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
sub getStruct
|
||||
{
|
||||
my($self, $key) = @_;
|
||||
printf("getStruct(%d)\n", $key);
|
||||
return $self->{log}->{$key};
|
||||
}
|
||||
|
||||
sub zip
|
||||
{
|
||||
my($self) = @_;
|
||||
print "zip()\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
eval {
|
||||
my $handler = new CalculatorHandler;
|
||||
my $processor = new tutorial::CalculatorProcessor($handler);
|
||||
my $serversocket = new Thrift::ServerSocket(9090);
|
||||
my $forkingserver = new Thrift::ForkingServer($processor, $serversocket);
|
||||
print "Starting the server...\n";
|
||||
$forkingserver->serve();
|
||||
print "done.\n";
|
||||
}; if ($@) {
|
||||
if ($@ =~ m/TException/ and exists $@->{message}) {
|
||||
my $message = $@->{message};
|
||||
my $code = $@->{code};
|
||||
my $out = $code . ':' . $message;
|
||||
die $out;
|
||||
} else {
|
||||
die $@;
|
||||
}
|
||||
}
|
||||
|
91
vendor/git.apache.org/thrift.git/tutorial/php/PhpClient.php
generated
vendored
Executable file
91
vendor/git.apache.org/thrift.git/tutorial/php/PhpClient.php
generated
vendored
Executable file
|
@ -0,0 +1,91 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
namespace tutorial\php;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__.'/../../lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php';
|
||||
|
||||
use Thrift\ClassLoader\ThriftClassLoader;
|
||||
|
||||
$GEN_DIR = realpath(dirname(__FILE__).'/..').'/gen-php';
|
||||
|
||||
$loader = new ThriftClassLoader();
|
||||
$loader->registerNamespace('Thrift', __DIR__ . '/../../lib/php/lib');
|
||||
$loader->registerDefinition('shared', $GEN_DIR);
|
||||
$loader->registerDefinition('tutorial', $GEN_DIR);
|
||||
$loader->register();
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
use Thrift\Protocol\TBinaryProtocol;
|
||||
use Thrift\Transport\TSocket;
|
||||
use Thrift\Transport\THttpClient;
|
||||
use Thrift\Transport\TBufferedTransport;
|
||||
use Thrift\Exception\TException;
|
||||
|
||||
try {
|
||||
if (array_search('--http', $argv)) {
|
||||
$socket = new THttpClient('localhost', 8080, '/php/PhpServer.php');
|
||||
} else {
|
||||
$socket = new TSocket('localhost', 9090);
|
||||
}
|
||||
$transport = new TBufferedTransport($socket, 1024, 1024);
|
||||
$protocol = new TBinaryProtocol($transport);
|
||||
$client = new \tutorial\CalculatorClient($protocol);
|
||||
|
||||
$transport->open();
|
||||
|
||||
$client->ping();
|
||||
print "ping()\n";
|
||||
|
||||
$sum = $client->add(1,1);
|
||||
print "1+1=$sum\n";
|
||||
|
||||
$work = new \tutorial\Work();
|
||||
|
||||
$work->op = \tutorial\Operation::DIVIDE;
|
||||
$work->num1 = 1;
|
||||
$work->num2 = 0;
|
||||
|
||||
try {
|
||||
$client->calculate(1, $work);
|
||||
print "Whoa! We can divide by zero?\n";
|
||||
} catch (\tutorial\InvalidOperation $io) {
|
||||
print "InvalidOperation: $io->why\n";
|
||||
}
|
||||
|
||||
$work->op = \tutorial\Operation::SUBTRACT;
|
||||
$work->num1 = 15;
|
||||
$work->num2 = 10;
|
||||
$diff = $client->calculate(1, $work);
|
||||
print "15-10=$diff\n";
|
||||
|
||||
$log = $client->getStruct(1);
|
||||
print "Log: $log->value\n";
|
||||
|
||||
$transport->close();
|
||||
|
||||
} catch (TException $tx) {
|
||||
print 'TException: '.$tx->getMessage()."\n";
|
||||
}
|
||||
|
||||
?>
|
130
vendor/git.apache.org/thrift.git/tutorial/php/PhpServer.php
generated
vendored
Executable file
130
vendor/git.apache.org/thrift.git/tutorial/php/PhpServer.php
generated
vendored
Executable file
|
@ -0,0 +1,130 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
namespace tutorial\php;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__.'/../../lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php';
|
||||
|
||||
use Thrift\ClassLoader\ThriftClassLoader;
|
||||
|
||||
$GEN_DIR = realpath(dirname(__FILE__).'/..').'/gen-php';
|
||||
|
||||
$loader = new ThriftClassLoader();
|
||||
$loader->registerNamespace('Thrift', __DIR__ . '/../../lib/php/lib');
|
||||
$loader->registerDefinition('shared', $GEN_DIR);
|
||||
$loader->registerDefinition('tutorial', $GEN_DIR);
|
||||
$loader->register();
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is not a stand-alone server. It should be run as a normal
|
||||
* php web script (like through Apache's mod_php) or as a cgi script
|
||||
* (like with the included runserver.py). You can connect to it with
|
||||
* THttpClient in any language that supports it. The PHP tutorial client
|
||||
* will work if you pass it the argument "--http".
|
||||
*/
|
||||
|
||||
if (php_sapi_name() == 'cli') {
|
||||
ini_set("display_errors", "stderr");
|
||||
}
|
||||
|
||||
use Thrift\Protocol\TBinaryProtocol;
|
||||
use Thrift\Transport\TPhpStream;
|
||||
use Thrift\Transport\TBufferedTransport;
|
||||
|
||||
class CalculatorHandler implements \tutorial\CalculatorIf {
|
||||
protected $log = array();
|
||||
|
||||
public function ping() {
|
||||
error_log("ping()");
|
||||
}
|
||||
|
||||
public function add($num1, $num2) {
|
||||
error_log("add({$num1}, {$num2})");
|
||||
return $num1 + $num2;
|
||||
}
|
||||
|
||||
public function calculate($logid, \tutorial\Work $w) {
|
||||
error_log("calculate({$logid}, {{$w->op}, {$w->num1}, {$w->num2}})");
|
||||
switch ($w->op) {
|
||||
case \tutorial\Operation::ADD:
|
||||
$val = $w->num1 + $w->num2;
|
||||
break;
|
||||
case \tutorial\Operation::SUBTRACT:
|
||||
$val = $w->num1 - $w->num2;
|
||||
break;
|
||||
case \tutorial\Operation::MULTIPLY:
|
||||
$val = $w->num1 * $w->num2;
|
||||
break;
|
||||
case \tutorial\Operation::DIVIDE:
|
||||
if ($w->num2 == 0) {
|
||||
$io = new \tutorial\InvalidOperation();
|
||||
$io->whatOp = $w->op;
|
||||
$io->why = "Cannot divide by 0";
|
||||
throw $io;
|
||||
}
|
||||
$val = $w->num1 / $w->num2;
|
||||
break;
|
||||
default:
|
||||
$io = new \tutorial\InvalidOperation();
|
||||
$io->whatOp = $w->op;
|
||||
$io->why = "Invalid Operation";
|
||||
throw $io;
|
||||
}
|
||||
|
||||
$log = new \shared\SharedStruct();
|
||||
$log->key = $logid;
|
||||
$log->value = (string)$val;
|
||||
$this->log[$logid] = $log;
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
public function getStruct($key) {
|
||||
error_log("getStruct({$key})");
|
||||
// This actually doesn't work because the PHP interpreter is
|
||||
// restarted for every request.
|
||||
//return $this->log[$key];
|
||||
return new \shared\SharedStruct(array("key" => $key, "value" => "PHP is stateless!"));
|
||||
}
|
||||
|
||||
public function zip() {
|
||||
error_log("zip()");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
header('Content-Type', 'application/x-thrift');
|
||||
if (php_sapi_name() == 'cli') {
|
||||
echo "\r\n";
|
||||
}
|
||||
|
||||
$handler = new CalculatorHandler();
|
||||
$processor = new \tutorial\CalculatorProcessor($handler);
|
||||
|
||||
$transport = new TBufferedTransport(new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W));
|
||||
$protocol = new TBinaryProtocol($transport, true, true);
|
||||
|
||||
$transport->open();
|
||||
$processor->process($protocol, $protocol);
|
||||
$transport->close();
|
33
vendor/git.apache.org/thrift.git/tutorial/php/runserver.py
generated
vendored
Executable file
33
vendor/git.apache.org/thrift.git/tutorial/php/runserver.py
generated
vendored
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import os
|
||||
import BaseHTTPServer
|
||||
import CGIHTTPServer
|
||||
|
||||
# chdir(2) into the tutorial directory.
|
||||
os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
|
||||
|
||||
|
||||
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
|
||||
cgi_directories = ['/php']
|
||||
|
||||
BaseHTTPServer.HTTPServer(('', 8080), Handler).serve_forever()
|
38
vendor/git.apache.org/thrift.git/tutorial/py.tornado/Makefile.am
generated
vendored
Executable file
38
vendor/git.apache.org/thrift.git/tutorial/py.tornado/Makefile.am
generated
vendored
Executable file
|
@ -0,0 +1,38 @@
|
|||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
THRIFT = $(top_builddir)/compiler/cpp/thrift
|
||||
|
||||
gen-py.tornado/tutorial/Calculator.py gen-py.tornado/shared/SharedService.py: $(top_srcdir)/tutorial/tutorial.thrift
|
||||
$(THRIFT) --gen py:tornado -r $<
|
||||
|
||||
all-local: gen-py.tornado/tutorial/Calculator.py
|
||||
|
||||
tutorialserver: all
|
||||
${PYTHON} PythonServer.py
|
||||
|
||||
tutorialclient: all
|
||||
${PYTHON} PythonClient.py
|
||||
|
||||
clean-local:
|
||||
$(RM) -r gen-*
|
||||
|
||||
EXTRA_DIST = \
|
||||
PythonServer.py \
|
||||
PythonClient.py
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue