├── README.md
├── bin
├── Makefile
├── ctrl.config
├── default.conf
├── main.cpp
├── pyctrl
│ ├── main.py
│ ├── msg
│ │ ├── __init__.py
│ │ └── ffengine
│ │ │ ├── __init__.py
│ │ │ ├── constants.py
│ │ │ └── ttypes.py
│ └── msg_def
│ │ ├── __init__.py
│ │ ├── constants.py
│ │ └── ttypes.py
├── pylib
│ ├── event_bus.py
│ ├── ffext.py
│ ├── google
│ │ ├── __init__.py
│ │ └── protobuf
│ │ │ ├── __init__.py
│ │ │ ├── compiler
│ │ │ ├── __init__.py
│ │ │ └── plugin_pb2.py
│ │ │ ├── descriptor.py
│ │ │ ├── descriptor_database.py
│ │ │ ├── descriptor_pb2.py
│ │ │ ├── descriptor_pool.py
│ │ │ ├── internal
│ │ │ ├── __init__.py
│ │ │ ├── api_implementation.py
│ │ │ ├── containers.py
│ │ │ ├── cpp_message.py
│ │ │ ├── decoder.py
│ │ │ ├── encoder.py
│ │ │ ├── enum_type_wrapper.py
│ │ │ ├── message_listener.py
│ │ │ ├── python_message.py
│ │ │ ├── type_checkers.py
│ │ │ └── wire_format.py
│ │ │ ├── message.py
│ │ │ ├── message_factory.py
│ │ │ ├── reflection.py
│ │ │ ├── service.py
│ │ │ ├── service_reflection.py
│ │ │ └── text_format.py
│ ├── id_generator.py
│ ├── pkg_resources.py
│ ├── protobuf_example
│ │ ├── msg.proto
│ │ ├── msg_pb2.py
│ │ └── protobuf_example.py
│ ├── thrift
│ │ ├── TSCons.py
│ │ ├── TSerialization.py
│ │ ├── Thrift.py
│ │ ├── __init__.py
│ │ ├── protocol
│ │ │ ├── TBase.py
│ │ │ ├── TBinaryProtocol.py
│ │ │ ├── TCompactProtocol.py
│ │ │ ├── TJSONProtocol.py
│ │ │ ├── TProtocol.py
│ │ │ ├── __init__.py
│ │ │ └── fastbinary.c
│ │ ├── server
│ │ │ ├── THttpServer.py
│ │ │ ├── TNonblockingServer.py
│ │ │ ├── TProcessPoolServer.py
│ │ │ ├── TServer.py
│ │ │ └── __init__.py
│ │ └── transport
│ │ │ ├── THttpClient.py
│ │ │ ├── TSSLSocket.py
│ │ │ ├── TSocket.py
│ │ │ ├── TTransport.py
│ │ │ ├── TTwisted.py
│ │ │ ├── TZlibTransport.py
│ │ │ └── __init__.py
│ ├── thrift_example
│ │ ├── __init__.py
│ │ ├── ff
│ │ │ ├── __init__.py
│ │ │ ├── constants.py
│ │ │ └── ttypes.py
│ │ └── thrift_example.py
│ └── wrods_filter.py
└── pyproject
│ ├── echo_msg_def
│ ├── __init__.py
│ ├── constants.py
│ └── ttypes.py
│ ├── handler
│ ├── __init__.py
│ └── player_handler.py
│ ├── main-bk.py
│ ├── main.py
│ ├── model
│ ├── __init__.py
│ ├── db_service.py
│ └── player_model.py
│ ├── msg_def
│ ├── __init__.py
│ ├── constants.py
│ └── ttypes.py
│ └── user_data
│ ├── __init__.py
│ ├── constants.py
│ └── ttypes.py
├── example
├── client
│ ├── Makefile
│ └── main.cpp
├── game
│ ├── Makefile
│ ├── ctrl.config
│ ├── default.conf
│ ├── main.cpp
│ ├── main.lua
│ ├── pyctrl
│ │ ├── main.py
│ │ ├── msg
│ │ │ ├── __init__.py
│ │ │ └── ffengine
│ │ │ │ ├── __init__.py
│ │ │ │ ├── constants.py
│ │ │ │ └── ttypes.py
│ │ └── msg_def
│ │ │ ├── __init__.py
│ │ │ ├── constants.py
│ │ │ └── ttypes.py
│ ├── pylib
│ │ ├── event_bus.py
│ │ ├── ffext.py
│ │ ├── google
│ │ │ ├── __init__.py
│ │ │ └── protobuf
│ │ │ │ ├── __init__.py
│ │ │ │ ├── compiler
│ │ │ │ ├── __init__.py
│ │ │ │ └── plugin_pb2.py
│ │ │ │ ├── descriptor.py
│ │ │ │ ├── descriptor_database.py
│ │ │ │ ├── descriptor_pb2.py
│ │ │ │ ├── descriptor_pool.py
│ │ │ │ ├── internal
│ │ │ │ ├── __init__.py
│ │ │ │ ├── api_implementation.py
│ │ │ │ ├── containers.py
│ │ │ │ ├── cpp_message.py
│ │ │ │ ├── decoder.py
│ │ │ │ ├── encoder.py
│ │ │ │ ├── enum_type_wrapper.py
│ │ │ │ ├── message_listener.py
│ │ │ │ ├── python_message.py
│ │ │ │ ├── type_checkers.py
│ │ │ │ └── wire_format.py
│ │ │ │ ├── message.py
│ │ │ │ ├── message_factory.py
│ │ │ │ ├── reflection.py
│ │ │ │ ├── service.py
│ │ │ │ ├── service_reflection.py
│ │ │ │ └── text_format.py
│ │ ├── id_generator.py
│ │ ├── pkg_resources.py
│ │ ├── protobuf_example
│ │ │ ├── msg.proto
│ │ │ ├── msg_pb2.py
│ │ │ └── protobuf_example.py
│ │ ├── thrift
│ │ │ ├── TSCons.py
│ │ │ ├── TSerialization.py
│ │ │ ├── Thrift.py
│ │ │ ├── __init__.py
│ │ │ ├── protocol
│ │ │ │ ├── TBase.py
│ │ │ │ ├── TBinaryProtocol.py
│ │ │ │ ├── TCompactProtocol.py
│ │ │ │ ├── TJSONProtocol.py
│ │ │ │ ├── TProtocol.py
│ │ │ │ ├── __init__.py
│ │ │ │ └── fastbinary.c
│ │ │ ├── server
│ │ │ │ ├── THttpServer.py
│ │ │ │ ├── TNonblockingServer.py
│ │ │ │ ├── TProcessPoolServer.py
│ │ │ │ ├── TServer.py
│ │ │ │ └── __init__.py
│ │ │ └── transport
│ │ │ │ ├── THttpClient.py
│ │ │ │ ├── TSSLSocket.py
│ │ │ │ ├── TSocket.py
│ │ │ │ ├── TTransport.py
│ │ │ │ ├── TTwisted.py
│ │ │ │ ├── TZlibTransport.py
│ │ │ │ └── __init__.py
│ │ ├── thrift_example
│ │ │ ├── __init__.py
│ │ │ ├── ff
│ │ │ │ ├── __init__.py
│ │ │ │ ├── constants.py
│ │ │ │ └── ttypes.py
│ │ │ └── thrift_example.py
│ │ └── wrods_filter.py
│ └── pyproject
│ │ ├── echo_msg_def
│ │ ├── __init__.py
│ │ ├── constants.py
│ │ └── ttypes.py
│ │ ├── handler
│ │ ├── __init__.py
│ │ └── player_handler.py
│ │ ├── main-bk.py
│ │ ├── main.py
│ │ ├── model
│ │ ├── __init__.py
│ │ ├── db_service.py
│ │ └── player_model.py
│ │ ├── msg_def
│ │ ├── __init__.py
│ │ ├── constants.py
│ │ └── ttypes.py
│ │ └── user_data
│ │ ├── __init__.py
│ │ ├── constants.py
│ │ └── ttypes.py
├── php_sdk
│ ├── Thrift
│ │ ├── Base
│ │ │ └── TBase.php
│ │ ├── ClassLoader
│ │ │ └── ThriftClassLoader.php
│ │ ├── Exception
│ │ │ ├── TApplicationException.php
│ │ │ ├── TException.php
│ │ │ ├── TProtocolException.php
│ │ │ └── TTransportException.php
│ │ ├── Factory
│ │ │ ├── TBinaryProtocolFactory.php
│ │ │ ├── TCompactProtocolFactory.php
│ │ │ ├── TJSONProtocolFactory.php
│ │ │ ├── TProtocolFactory.php
│ │ │ ├── TStringFuncFactory.php
│ │ │ └── TTransportFactory.php
│ │ ├── Protocol
│ │ │ ├── JSON
│ │ │ │ ├── BaseContext.php
│ │ │ │ ├── ListContext.php
│ │ │ │ ├── LookaheadReader.php
│ │ │ │ └── PairContext.php
│ │ │ ├── TBinaryProtocol.php
│ │ │ ├── TBinaryProtocolAccelerated.php
│ │ │ ├── TCompactProtocol.php
│ │ │ ├── TJSONProtocol.php
│ │ │ └── TProtocol.php
│ │ ├── Serializer
│ │ │ └── TBinarySerializer.php
│ │ ├── Server
│ │ │ ├── TForkingServer.php
│ │ │ ├── TServer.php
│ │ │ ├── TServerSocket.php
│ │ │ ├── TServerTransport.php
│ │ │ └── TSimpleServer.php
│ │ ├── StringFunc
│ │ │ ├── Core.php
│ │ │ ├── Mbstring.php
│ │ │ └── TStringFunc.php
│ │ ├── Transport
│ │ │ ├── TBufferedTransport.php
│ │ │ ├── TFramedTransport.php
│ │ │ ├── THttpClient.php
│ │ │ ├── TMemoryBuffer.php
│ │ │ ├── TNullTransport.php
│ │ │ ├── TPhpStream.php
│ │ │ ├── TSocket.php
│ │ │ ├── TSocketPool.php
│ │ │ └── TTransport.php
│ │ ├── Type
│ │ │ ├── TMessageType.php
│ │ │ └── TType.php
│ │ └── ffrpc_msg
│ │ │ └── Types.php
│ ├── ff
│ │ └── Types.php
│ └── ffrpc.php
├── python_sdk
│ ├── ff
│ │ ├── __init__.py
│ │ ├── constants.py
│ │ ├── gen-py
│ │ │ ├── __init__.py
│ │ │ └── echo
│ │ │ │ ├── __init__.py
│ │ │ │ ├── constants.py
│ │ │ │ └── ttypes.py
│ │ ├── server.py
│ │ └── ttypes.py
│ ├── ffrpc.py
│ ├── gen_py
│ │ ├── __init__.py
│ │ ├── echo.thrift
│ │ ├── echo
│ │ │ ├── __init__.py
│ │ │ ├── constants.py
│ │ │ └── ttypes.py
│ │ └── thrift-0.9.1.exe
│ └── thrift
│ │ ├── TSCons.py
│ │ ├── TSerialization.py
│ │ ├── Thrift.py
│ │ ├── __init__.py
│ │ ├── msg_def
│ │ ├── __init__.py
│ │ ├── constants.py
│ │ └── ttypes.py
│ │ ├── protocol
│ │ ├── TBase.py
│ │ ├── TBinaryProtocol.py
│ │ ├── TCompactProtocol.py
│ │ ├── TJSONProtocol.py
│ │ ├── TProtocol.py
│ │ ├── __init__.py
│ │ └── fastbinary.c
│ │ ├── server
│ │ ├── THttpServer.py
│ │ ├── TNonblockingServer.py
│ │ ├── TProcessPoolServer.py
│ │ ├── TServer.py
│ │ └── __init__.py
│ │ └── transport
│ │ ├── THttpClient.py
│ │ ├── TSSLSocket.py
│ │ ├── TSocket.py
│ │ ├── TTransport.py
│ │ ├── TTwisted.py
│ │ ├── TZlibTransport.py
│ │ └── __init__.py
└── tutorial
│ ├── Makefile
│ ├── echo.pb.cc
│ ├── echo.pb.h
│ ├── echo.proto
│ ├── echo.thrift
│ ├── echo_constants.cpp
│ ├── echo_constants.h
│ ├── echo_test.h
│ ├── echo_types.cpp
│ ├── echo_types.h
│ ├── gen-php
│ └── ff
│ │ └── Types.php
│ ├── main.cpp
│ ├── protobuf.Makefile
│ ├── protobuf_test.h
│ ├── thrift-0.9.0.exe
│ ├── thrift.Makefile
│ └── thrift_test.h
├── fflib
├── base
│ ├── arg_helper.h
│ ├── atomic_op.h
│ ├── daemon_tool.h
│ ├── ffslot.h
│ ├── fftype.h
│ ├── lock.cpp
│ ├── lock.h
│ ├── log.cpp
│ ├── log.h
│ ├── obj_pool.h
│ ├── os_tool.h
│ ├── performance_daemon.cpp
│ ├── performance_daemon.h
│ ├── signal_helper.h
│ ├── singleton.h
│ ├── smart_ptr.h
│ ├── strtool.h
│ ├── task_queue_i.h
│ ├── task_queue_impl.h
│ ├── thread.cpp
│ ├── thread.h
│ ├── time_tool.h
│ └── timer_service.h
├── db
│ ├── db_ops.h
│ ├── ffcrud.h
│ ├── ffdb.cpp
│ ├── ffdb.h
│ ├── mysql_ops.cpp
│ ├── mysql_ops.h
│ ├── sqlite3.c
│ ├── sqlite3.h
│ ├── sqlite3ext.h
│ ├── sqlite_ops.cpp
│ └── sqlite_ops.h
├── lua
│ ├── fflua.h
│ ├── fflua_register.h
│ └── fflua_type.h
├── net
│ ├── acceptor_i.h
│ ├── acceptor_impl.cpp
│ ├── acceptor_impl.h
│ ├── base_heartbeat.h
│ ├── codec.cpp
│ ├── codec.h
│ ├── common_socket_controller.cpp
│ ├── common_socket_controller.h
│ ├── connector.h
│ ├── epoll_i.h
│ ├── epoll_impl.cpp
│ ├── epoll_impl.h
│ ├── gateway_acceptor.cpp
│ ├── gateway_acceptor.h
│ ├── gateway_socket_controller.cpp
│ ├── gateway_socket_controller.h
│ ├── http_acceptor.cpp
│ ├── http_acceptor.h
│ ├── message.h
│ ├── msg_handler_i.h
│ ├── msg_sender.h
│ ├── net_factory.h
│ ├── net_stat.cpp
│ ├── net_stat.h
│ ├── netbase.h
│ ├── socket_controller_i.h
│ ├── socket_i.h
│ ├── socket_impl.cpp
│ ├── socket_impl.h
│ ├── socket_op.h
│ ├── text_socket_controller_impl.cpp
│ ├── text_socket_controller_impl.h
│ └── udp_socket.h
├── python
│ └── ffpython.h
├── rpc
│ ├── ffbroker.cpp
│ ├── ffbroker.h
│ ├── ffrpc.cpp
│ ├── ffrpc.h
│ ├── ffrpc_ops.h
│ └── msg_def
│ │ ├── ffrpc_msg_constants.cpp
│ │ ├── ffrpc_msg_constants.h
│ │ ├── ffrpc_msg_types.cpp
│ │ └── ffrpc_msg_types.h
├── server
│ ├── db_mgr.cpp
│ ├── db_mgr.h
│ ├── ffcurl.cpp
│ ├── ffcurl.h
│ ├── ffgate.cpp
│ ├── ffgate.h
│ ├── fflua_json_traits.h
│ ├── fflua_mod.cpp
│ ├── fflua_mod.h
│ ├── ffscene.cpp
│ ├── ffscene.h
│ ├── ffscene_lua.cpp
│ ├── ffscene_lua.h
│ ├── ffscene_python.cpp
│ ├── ffscene_python.h
│ └── fftask_processor.h
└── xml
│ ├── ffxml.cpp
│ ├── ffxml.h
│ ├── tinystr.cpp
│ ├── tinystr.h
│ ├── tinyxml.cpp
│ ├── tinyxml.h
│ ├── tinyxmlerror.cpp
│ └── tinyxmlparser.cpp
└── lib3party
├── rapidjson
├── document.h
├── filestream.h
├── internal
│ ├── pow10.h
│ ├── stack.h
│ └── strfunc.h
├── prettywriter.h
├── rapidjson.h
├── reader.h
├── stringbuffer.h
└── writer.h
└── thrift
├── FFThrift.h
├── TApplicationException.h
├── Thrift.h
├── ThriftConfig.h
├── cxxfunctional.h
├── protocol
├── TBinaryProtocol.h
├── TProtocol.h
├── TProtocolException.h
└── TVirtualProtocol.h
└── transport
├── FFTransport.h
├── TTransport.h
├── TTransportException.h
└── TVirtualTransport.h
/bin/Makefile:
--------------------------------------------------------------------------------
1 | #交叉编译器路径
2 | CROSS=
3 | CP=/bin/cp
4 | RM=-/bin/rm -rf
5 | LN=/bin/ln -s
6 | #是否开启sqlite的支持,如需要关闭,设置为空字符串
7 | FF_ENABLE_SQLITE_FLAG =-DFF_ENABLE_SQLITE
8 | FF_ENABLE_CURL_FLAG =
9 | #-DFF_ENABLE_CURL
10 | CFLAGS=-g -Wall $(FF_ENABLE_CURL_FLAG) $(FF_ENABLE_SQLITE_FLAG)
11 | LDFLAGS= -O2 -lpthread -ldl -lpython2.6 -lmysqlclient
12 | #-lcurl
13 | #-llua
14 | #链接库名
15 | LIB_NAME=
16 | #链接库版本
17 | LIB_VER=1.0.0
18 | #平台
19 | ARCH=
20 | # 二进制目标
21 | BIN=app_ffengine
22 |
23 | #源文件目录
24 | SrcDir= . ../fflib/base ../fflib/net ../fflib/rpc ../fflib/rpc/msg_def ../fflib/db ../fflib/xml ../fflib/server
25 | #头文件目录
26 | IncDir= ../fflib/ ../lib3party /usr/include/python2.7/ /usr/include/python2.6/
27 | #连接库目录
28 | LibDir= /usr/local/lib /usr/lib/mysql /usr/lib64/mysql
29 | SRCS=$(foreach dir,$(SrcDir),$(wildcard $(dir)/*.cpp))
30 | #INCS=$(foreach dir,$(IncDir),$(wildcard $(dir)/*.h))
31 | INCS=$(foreach dir,$(IncDir),$(addprefix -I,$(dir)))
32 | LINKS=$(foreach dir,$(LibDir),$(addprefix -L,$(dir)))
33 | CFLAGS := $(CFLAGS) $(INCS)
34 | LDFLAGS:= $(LINKS) $(LDFLAGS)
35 | CC=gcc
36 | ARCH=PC
37 | OBJS = $(SRCS:%.cpp=%.o)
38 | .PHONY:all clean
39 |
40 | all:$(BIN)
41 | $(BIN):$(OBJS)
42 | ifeq ($(FF_ENABLE_SQLITE_FLAG),-DFF_ENABLE_SQLITE)
43 | gcc -c ../fflib/db/sqlite3.c -o sqlite3.o
44 | g++ -o $(BIN) $(OBJS) sqlite3.o $(LDFLAGS)
45 | else
46 | g++ -o $(BIN) $(OBJS) $(LDFLAGS)
47 | endif
48 | @echo " OK! Compile $@ "
49 | # @$(LN) $(shell pwd)/$(LIB_NAME).$(LIB_VER) /lib/$(LIB_NAME)
50 |
51 | %.o:%.cpp
52 | @echo "[$(ARCH)] Compile $@..."
53 | @$(CC) $(CFLAGS) -c $< -o $@
54 |
55 | .PHONY: clean
56 | clean:
57 | @echo "[$(ARCH)] Cleaning files..."
58 | @$(RM) $(OBJS) $(BIN)
59 | @$(RM) sqlite3.o
60 |
--------------------------------------------------------------------------------
/bin/ctrl.config:
--------------------------------------------------------------------------------
1 |
2 | #关于broker相关的配置, master_broker如果被设置表示该broker为slave broker, 如果需要跨组通信需要设置bridge_broker
3 | -broker tcp://*:1281
4 | #-master_broker tcp://127.0.0.1:20241
5 | #-bridge_broker tcp://127.0.0.1:30241
6 |
7 | #关于gate相关的配置,-gate 为gate的名称, gate_listen为监听的ip端口
8 | #-gate gate@0 -gate_listen tcp://*:30242 -heartbeat_timeout 600
9 |
10 | #scene 相关的配置 scene 为scene的名称, python_path为python的路径
11 | -scene ffEngine@0 -python_path ./pyctrl
12 | #-lua_scene scene@1 -lua_path ./luaproject
13 | #-lua_mod fflua@1
14 |
15 | #日志相关的配置 级别最大为debug=6,trace=5, info=4, warn=3, error=2, fatal=1
16 | -log_path ./log -log_filename fflog
17 | #-log_class DB_MGR,XX,BROKER,FFSCENE,FFSCENE_PYTHON,FFNET,PY
18 | -log_class DB_MGR,FFSCENE_PYTHON,FFSCENE_LUA,PY,BROKER
19 | -log_print_screen true -log_print_file true
20 | -log_level 5
21 |
22 |
23 | #性能监控单位秒
24 | -perf_timeout 3600
25 | #是否启动为守护进程
26 | #-d
27 | ##数据库相关的配置 账号/密码/数据库
28 | -db mysql://127.0.0.1:3306/root/acegame/pcgame
29 | #如果使用单独的账号系统,使用此db配置
30 | #-user_db mysql://127.0.0.1:3306/root/acegame/pcgame
31 |
--------------------------------------------------------------------------------
/bin/default.conf:
--------------------------------------------------------------------------------
1 |
2 | #关于broker相关的配置, master_broker如果被设置表示该broker为slave broker, 如果需要跨组通信需要设置bridge_broker
3 | -broker tcp://127.0.0.1:40241
4 | #-master_broker tcp://127.0.0.1:20241
5 | #-bridge_broker tcp://127.0.0.1:30241
6 |
7 | #关于gate相关的配置,-gate 为gate的名称, gate_listen为监听的ip端口
8 | -gate gate@0 -gate_listen tcp://*:30242 -heartbeat_timeout 600
9 |
10 | #scene 相关的配置 scene 为scene的名称, python_path为python的路径
11 | -scene scene@0 -python_path ./pyproject
12 | #-lua_scene scene@1 -lua_path ./luaproject
13 | #-lua_mod fflua@1
14 |
15 | #日志相关的配置 级别最大为debug=6,trace=5, info=4, warn=3, error=2, fatal=1
16 | -log_path ./log -log_filename fflog
17 | #-log_class DB_MGR,XX,BROKER,FFSCENE,FFSCENE_PYTHON,FFNET,PY
18 | -log_class DB_MGR,FFSCENE_PYTHON,FFGATE,FFSCENE,FFSCENE_LUA,PY
19 | -log_print_screen true -log_print_file true
20 | -log_level 5
21 |
22 |
23 | #性能监控单位秒
24 | -perf_timeout 3600
25 | #是否启动为守护进程
26 | #-d
27 | ##数据库相关的配置 账号/密码/数据库
28 | -db sqlite://./ff_demo.db
29 | -group_name demo
30 |
--------------------------------------------------------------------------------
/bin/pyctrl/msg/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pyctrl/msg/__init__.py
--------------------------------------------------------------------------------
/bin/pyctrl/msg/ffengine/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/bin/pyctrl/msg/ffengine/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.0)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/bin/pyctrl/msg_def/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/bin/pyctrl/msg_def/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.0)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/bin/pylib/event_bus.py:
--------------------------------------------------------------------------------
1 | # coding=UTF-8
2 | import traceback
3 |
4 | class event_bus_t(object):
5 | def __init__(self):
6 | #key event class, value is dict of consumer function
7 | self.event_consumer = {}
8 | #processing list, cache event
9 | self.event_cache_list = []#fifo
10 | def default_except_handler(exception_):
11 | traceback.print_exc()
12 | self.exception_handler = default_except_handler
13 | def set_exception_handler(func_):
14 | self.exception_handler = func_
15 | def get_key_name(self, event_obj_):
16 | return event_obj_.__class__
17 | def bind_event(self, event_class_, consumer_func):
18 | key = event_class_
19 | consumer_name = consumer_func.__module__ + '.' + consumer_func.__name__
20 | dest_dict = self.event_consumer.get(key)
21 | if dest_dict == None:
22 | dest_dict = {}
23 | self.event_consumer[key] = dest_dict
24 | dest_dict[consumer_name] = consumer_func
25 | def post(self, event_):
26 | self.event_cache_list.insert(0, event_)
27 | size = len(self.event_cache_list)
28 | if size > 1:
29 | return True
30 |
31 | while len(self.event_cache_list) > 0:
32 | next_event = self.event_cache_list[len(self.event_cache_list) - 1]
33 | key = self.get_key_name(next_event)
34 | dest_dict = self.event_consumer.get(key)
35 | if None != dest_dict:
36 | for k, func in dest_dict.iteritems():
37 | try:
38 | func(event_)
39 | except Exception, e:
40 | self.exception_handler(e)
41 | except:
42 | pass
43 | self.event_cache_list.pop()
44 |
45 | def dump(self):
46 | print(self.event_consumer)
47 |
48 | event_bus = event_bus_t()
49 | def instance():
50 | return event_bus
51 |
52 | def bind_event(event_class_):
53 | bind_list = []
54 | if event_class_.__class__ == list:
55 | bind_list = event_class_
56 | else:
57 | bind_list.append(event_class_)
58 | def wraper(func_):
59 | ebus = instance()
60 | for k in bind_list:
61 | ebus.bind_event(k, func_)
62 | return func_
63 | return wraper
64 |
65 | def post(event_):
66 | instance().post(event_)
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/bin/pylib/google/__init__.py:
--------------------------------------------------------------------------------
1 | __import__('pkg_resources').declare_namespace(__name__)
2 |
--------------------------------------------------------------------------------
/bin/pylib/google/protobuf/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pylib/google/protobuf/__init__.py
--------------------------------------------------------------------------------
/bin/pylib/google/protobuf/compiler/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pylib/google/protobuf/compiler/__init__.py
--------------------------------------------------------------------------------
/bin/pylib/google/protobuf/internal/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pylib/google/protobuf/internal/__init__.py
--------------------------------------------------------------------------------
/bin/pylib/id_generator.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pylib/id_generator.py
--------------------------------------------------------------------------------
/bin/pylib/protobuf_example/msg.proto:
--------------------------------------------------------------------------------
1 |
2 | message TestMsg
3 | {
4 | required int32 id=1;
5 | required int32 time=2;
6 | optional string note=3;
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/bin/pylib/protobuf_example/msg_pb2.py:
--------------------------------------------------------------------------------
1 | # Generated by the protocol buffer compiler. DO NOT EDIT!
2 | # source: msg.proto
3 |
4 | from google.protobuf import descriptor as _descriptor
5 | from google.protobuf import message as _message
6 | from google.protobuf import reflection as _reflection
7 | from google.protobuf import descriptor_pb2
8 | # @@protoc_insertion_point(imports)
9 |
10 |
11 |
12 |
13 | DESCRIPTOR = _descriptor.FileDescriptor(
14 | name='msg.proto',
15 | package='',
16 | serialized_pb='\n\tmsg.proto\"1\n\x07TestMsg\x12\n\n\x02id\x18\x01 \x02(\x05\x12\x0c\n\x04time\x18\x02 \x02(\x05\x12\x0c\n\x04note\x18\x03 \x01(\t')
17 |
18 |
19 |
20 |
21 | _TESTMSG = _descriptor.Descriptor(
22 | name='TestMsg',
23 | full_name='TestMsg',
24 | filename=None,
25 | file=DESCRIPTOR,
26 | containing_type=None,
27 | fields=[
28 | _descriptor.FieldDescriptor(
29 | name='id', full_name='TestMsg.id', index=0,
30 | number=1, type=5, cpp_type=1, label=2,
31 | has_default_value=False, default_value=0,
32 | message_type=None, enum_type=None, containing_type=None,
33 | is_extension=False, extension_scope=None,
34 | options=None),
35 | _descriptor.FieldDescriptor(
36 | name='time', full_name='TestMsg.time', index=1,
37 | number=2, type=5, cpp_type=1, label=2,
38 | has_default_value=False, default_value=0,
39 | message_type=None, enum_type=None, containing_type=None,
40 | is_extension=False, extension_scope=None,
41 | options=None),
42 | _descriptor.FieldDescriptor(
43 | name='note', full_name='TestMsg.note', index=2,
44 | number=3, type=9, cpp_type=9, label=1,
45 | has_default_value=False, default_value=unicode("", "utf-8"),
46 | message_type=None, enum_type=None, containing_type=None,
47 | is_extension=False, extension_scope=None,
48 | options=None),
49 | ],
50 | extensions=[
51 | ],
52 | nested_types=[],
53 | enum_types=[
54 | ],
55 | options=None,
56 | is_extendable=False,
57 | extension_ranges=[],
58 | serialized_start=13,
59 | serialized_end=62,
60 | )
61 |
62 | DESCRIPTOR.message_types_by_name['TestMsg'] = _TESTMSG
63 |
64 | class TestMsg(_message.Message):
65 | __metaclass__ = _reflection.GeneratedProtocolMessageType
66 | DESCRIPTOR = _TESTMSG
67 |
68 | # @@protoc_insertion_point(class_scope:TestMsg)
69 |
70 |
71 | # @@protoc_insertion_point(module_scope)
72 |
--------------------------------------------------------------------------------
/bin/pylib/protobuf_example/protobuf_example.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pylib/protobuf_example/protobuf_example.py
--------------------------------------------------------------------------------
/bin/pylib/thrift/TSCons.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | from os import path
21 | from SCons.Builder import Builder
22 |
23 |
24 | def scons_env(env, add=''):
25 | opath = path.dirname(path.abspath('$TARGET'))
26 | lstr = 'thrift --gen cpp -o ' + opath + ' ' + add + ' $SOURCE'
27 | cppbuild = Builder(action=lstr)
28 | env.Append(BUILDERS={'ThriftCpp': cppbuild})
29 |
30 |
31 | def gen_cpp(env, dir, file):
32 | scons_env(env)
33 | suffixes = ['_types.h', '_types.cpp']
34 | targets = map(lambda s: 'gen-cpp/' + file + s, suffixes)
35 | return env.ThriftCpp(targets, dir + file + '.thrift')
36 |
--------------------------------------------------------------------------------
/bin/pylib/thrift/TSerialization.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | from protocol import TBinaryProtocol
21 | from transport import TTransport
22 |
23 |
24 | def serialize(thrift_object,
25 | protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
26 | transport = TTransport.TMemoryBuffer()
27 | protocol = protocol_factory.getProtocol(transport)
28 | thrift_object.write(protocol)
29 | return transport.getvalue()
30 |
31 |
32 | def deserialize(base,
33 | buf,
34 | protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
35 | transport = TTransport.TMemoryBuffer(buf)
36 | protocol = protocol_factory.getProtocol(transport)
37 | base.read(protocol)
38 | return base
39 |
--------------------------------------------------------------------------------
/bin/pylib/thrift/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | __all__ = ['Thrift', 'TSCons']
21 |
--------------------------------------------------------------------------------
/bin/pylib/thrift/protocol/TBase.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | from thrift.Thrift import *
21 | from thrift.protocol import TBinaryProtocol
22 | from thrift.transport import TTransport
23 |
24 | try:
25 | from thrift.protocol import fastbinary
26 | except:
27 | fastbinary = None
28 |
29 |
30 | class TBase(object):
31 | __slots__ = []
32 |
33 | def __repr__(self):
34 | L = ['%s=%r' % (key, getattr(self, key))
35 | for key in self.__slots__]
36 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
37 |
38 | def __eq__(self, other):
39 | if not isinstance(other, self.__class__):
40 | return False
41 | for attr in self.__slots__:
42 | my_val = getattr(self, attr)
43 | other_val = getattr(other, attr)
44 | if my_val != other_val:
45 | return False
46 | return True
47 |
48 | def __ne__(self, other):
49 | return not (self == other)
50 |
51 | def read(self, iprot):
52 | if (iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
53 | isinstance(iprot.trans, TTransport.CReadableTransport) and
54 | self.thrift_spec is not None and
55 | fastbinary is not None):
56 | fastbinary.decode_binary(self,
57 | iprot.trans,
58 | (self.__class__, self.thrift_spec))
59 | return
60 | iprot.readStruct(self, self.thrift_spec)
61 |
62 | def write(self, oprot):
63 | if (oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
64 | self.thrift_spec is not None and
65 | fastbinary is not None):
66 | oprot.trans.write(
67 | fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
68 | return
69 | oprot.writeStruct(self, self.thrift_spec)
70 |
71 |
72 | class TExceptionBase(Exception):
73 | # old style class so python2.4 can raise exceptions derived from this
74 | # This can't inherit from TBase because of that limitation.
75 | __slots__ = []
76 |
77 | __repr__ = TBase.__repr__.im_func
78 | __eq__ = TBase.__eq__.im_func
79 | __ne__ = TBase.__ne__.im_func
80 | read = TBase.read.im_func
81 | write = TBase.write.im_func
82 |
--------------------------------------------------------------------------------
/bin/pylib/thrift/protocol/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | __all__ = ['TProtocol', 'TBinaryProtocol', 'fastbinary', 'TBase']
21 |
--------------------------------------------------------------------------------
/bin/pylib/thrift/server/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | __all__ = ['TServer', 'TNonblockingServer']
21 |
--------------------------------------------------------------------------------
/bin/pylib/thrift/transport/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | __all__ = ['TTransport', 'TSocket', 'THttpClient', 'TZlibTransport']
21 |
--------------------------------------------------------------------------------
/bin/pylib/thrift_example/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pylib/thrift_example/__init__.py
--------------------------------------------------------------------------------
/bin/pylib/thrift_example/ff/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/bin/pylib/thrift_example/ff/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.0)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/bin/pylib/thrift_example/ff/ttypes.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.0)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 |
11 | from thrift.transport import TTransport
12 | from thrift.protocol import TBinaryProtocol, TProtocol
13 | try:
14 | from thrift.protocol import fastbinary
15 | except:
16 | fastbinary = None
17 |
18 |
19 |
20 | class foo_t:
21 | """
22 | Attributes:
23 | - num
24 | """
25 |
26 | thrift_spec = (
27 | None, # 0
28 | (1, TType.I32, 'num', None, 100, ), # 1
29 | )
30 |
31 | def __init__(self, num=thrift_spec[1][4],):
32 | self.num = num
33 |
34 | def read(self, iprot):
35 | if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
36 | fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
37 | return
38 | iprot.readStructBegin()
39 | while True:
40 | (fname, ftype, fid) = iprot.readFieldBegin()
41 | if ftype == TType.STOP:
42 | break
43 | if fid == 1:
44 | if ftype == TType.I32:
45 | self.num = iprot.readI32();
46 | else:
47 | iprot.skip(ftype)
48 | else:
49 | iprot.skip(ftype)
50 | iprot.readFieldEnd()
51 | iprot.readStructEnd()
52 |
53 | def write(self, oprot):
54 | if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
55 | oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
56 | return
57 | oprot.writeStructBegin('foo_t')
58 | if self.num is not None:
59 | oprot.writeFieldBegin('num', TType.I32, 1)
60 | oprot.writeI32(self.num)
61 | oprot.writeFieldEnd()
62 | oprot.writeFieldStop()
63 | oprot.writeStructEnd()
64 |
65 | def validate(self):
66 | return
67 |
68 |
69 | def __repr__(self):
70 | L = ['%s=%r' % (key, value)
71 | for key, value in self.__dict__.iteritems()]
72 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
73 |
74 | def __eq__(self, other):
75 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
76 |
77 | def __ne__(self, other):
78 | return not (self == other)
79 |
--------------------------------------------------------------------------------
/bin/pylib/thrift_example/thrift_example.py:
--------------------------------------------------------------------------------
1 |
2 | import thrift.Thrift as Thrift
3 | import thrift.protocol.TBinaryProtocol as TBinaryProtocol
4 | import thrift.protocol.TCompactProtocol as TCompactProtocol
5 |
6 | import thrift.transport.TTransport as TTransport
7 | import gen.ff.ttypes as ttypes
8 |
9 | mb = TTransport.TMemoryBuffer()
10 | #bp = TBinaryProtocol.TBinaryProtocol(mb)
11 | bp = TCompactProtocol.TCompactProtocol(mb)
12 |
13 | foo= ttypes.foo_t()
14 | print(foo)
15 | foo.write(bp)
16 |
17 |
18 | ret = mb.getvalue()
19 | print(len(ret))
20 |
21 | mb2 = TTransport.TMemoryBuffer(ret)
22 | #bp2 = TBinaryProtocol.TBinaryProtocol(mb2)
23 | bp2 = TCompactProtocol.TCompactProtocol(mb2)
24 | foo2= ttypes.foo_t()
25 | foo2.read(bp2);
26 |
27 | print(foo2)
28 |
29 |
30 |
--------------------------------------------------------------------------------
/bin/pylib/wrods_filter.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | dest_code = 'utf-8'
4 | class words_filter_t:
5 | def __init__(self, words_list_):
6 | self.word_index = {}# {one word -> []}
7 | self.all_words = {}
8 | for w in words_list_:
9 | word = unicode(w, dest_code, 'ignore')
10 | word_len = len(word)
11 | if word_len == 0:
12 | continue
13 | dest_array = self.word_index.get(word[0])
14 | if None == dest_array:
15 | dest_array = []
16 | #print(__name__, 'filer')
17 | #print(word[0])
18 | self.word_index[word[0]] = dest_array
19 | if word_len not in dest_array:
20 | dest_array.append(word_len)
21 | dest_array.sort(reverse=True)
22 | self.all_words[word] = True
23 | print(__name__, "load filter words %d"%(len(self.all_words)))
24 | def dump(self, ):
25 | print (self.word_index, self.all_words)
26 |
27 | def filter(self, src_, replace_ = '*'):
28 | ret = unicode('', dest_code, 'ignore')
29 | word_src = unicode(src_, dest_code, 'ignore')
30 | i = 0
31 | while i < len(word_src):
32 | w = word_src[i]
33 | #print(__name__, 'filer')
34 | #print(w)
35 | dest_list = self.word_index.get(w)
36 | if None == dest_list:
37 | i += 1
38 | ret += w
39 | continue
40 | replace_num = 0
41 | for dest_len in dest_list:
42 | check_word = word_src[i:i + dest_len]
43 | #print('check_word', check_word)
44 | if None != self.all_words.get(check_word):
45 | i += dest_len
46 | #print('del', check_word)
47 | replace_num = len(check_word)#len(check_word.encode(dest_code))
48 | break
49 | if replace_num == 0:
50 | ret += w
51 | i += 1
52 | else:
53 | ret += replace_ * replace_num
54 | return ret.encode(dest_code)
55 |
56 | word_filter = None
57 | def init(src_file_):
58 | global word_filter
59 | wlist = []
60 | f = open(src_file_)
61 | for line in f.readlines():
62 | tmp = line.split('\n')
63 | wlist.append(tmp[0])
64 | word_filter = words_filter_t(wlist)
65 |
66 | def filter(src, replace_ = '*'):
67 | global word_filter
68 | return word_filter.filter(src, replace_)
69 |
70 |
71 | #init('fw.txt')
72 |
73 |
--------------------------------------------------------------------------------
/bin/pyproject/echo_msg_def/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/bin/pyproject/echo_msg_def/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.1)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/bin/pyproject/handler/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pyproject/handler/__init__.py
--------------------------------------------------------------------------------
/bin/pyproject/main-bk.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pyproject/main-bk.py
--------------------------------------------------------------------------------
/bin/pyproject/main.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | import ffext
3 | import handler.player_handler
4 | from model import db_service
5 |
6 | import echo_msg_def.ttypes as ttypes
7 |
8 | def init():
9 | print('init......')
10 | if db_service.init() == False:
11 | return -1
12 |
13 | return 0
14 |
15 |
16 | def cleanup():
17 | print('cleanup.....')
18 | return 0
19 |
20 |
21 | @ffext.ff_reg_scene_interfacee(ttypes.echo_thrift_in_t, ttypes.echo_thrift_out_t)
22 | def test_echo(req):
23 | ret_msg = ttypes.echo_thrift_out_t()
24 | ret_msg.data = req.msg.data
25 | req.response(ret_msg)
26 | print('test_echo', req.msg)
27 | return
28 |
--------------------------------------------------------------------------------
/bin/pyproject/model/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pyproject/model/__init__.py
--------------------------------------------------------------------------------
/bin/pyproject/model/db_service.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import ffext
4 | import id_generator
5 |
6 | g_async_db = None
7 | def get_async_db():
8 | global g_async_db
9 | return g_async_db
10 |
11 | def init():
12 | global g_async_db
13 | #g_sync_db = ffext.ffdb_create('mysql://localhost:3306/root/acegame/pcgame')
14 | db_config = ffext.get_config('-db')
15 | print('db_config=%s'%(db_config))
16 | g_async_db = ffext.ffdb_create(db_config)
17 | if None == g_async_db:
18 | return False
19 | sql = '''create table IF NOT EXISTS player_info
20 | (
21 | UID bigint not null,
22 | NAME varchar(255) not null,
23 | X int not null,
24 | Y int not null,
25 | primary key(UID)
26 | )'''
27 | g_async_db.query(sql)
28 | return True
29 |
30 | def load_by_name(name_, callback):
31 | sql = "select * from player_info where NAME='%s' limit 1"%(name_)
32 | def cb(ret):
33 | retData = {}
34 | if ret.flag == False or len(ret.result) == 0:
35 | callback(retData)
36 | return
37 | for i in range(0, len(ret.column)):
38 | retData[ret.column[i]] = ret.result[0][i]
39 | callback(retData)
40 | return
41 | get_async_db().query(sql, cb)
42 | return
43 |
44 | def insert_player(field_data):
45 | sql = ''
46 | values = ''
47 | for k, v in field_data.iteritems():
48 | if sql == '':
49 | sql = "insert into player_info ({0}".format(k)
50 | values = ") values ('{0}'".format(v)
51 | else:
52 | sql += ", {0}".format(k)
53 | values += ", '{0}'".format(v)
54 | sql += values + ')'
55 | print(sql)
56 | g_async_db.query(sql)
57 | return
58 |
59 | def update_player(uid, field_data):
60 | sql = ''
61 | for k, v in field_data.iteritems():
62 | if sql == '':
63 | sql = "update player_info set {0} = '{1}'".format(k, v)
64 | else:
65 | sql += ", {0} = '{1}'".format(k, v)
66 | sql += " where uid = '{0}'".format(uid)
67 | print(sql)
68 | g_async_db.query(sql)
69 | return
70 |
71 |
--------------------------------------------------------------------------------
/bin/pyproject/model/player_model.py:
--------------------------------------------------------------------------------
1 | import time
2 |
3 | class player_t:
4 | def __init__(self):
5 | self.id = 0
6 | self.name = ''
7 | self.x = 0
8 | self.y = 0
9 | self.last_move_tm = time.time()
10 |
11 |
--------------------------------------------------------------------------------
/bin/pyproject/msg_def/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/bin/pyproject/msg_def/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.0)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/bin/pyproject/user_data/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/bin/pyproject/user_data/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.1)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/example/client/Makefile:
--------------------------------------------------------------------------------
1 | #交叉编译器路径
2 | CROSS=
3 | CP=/bin/cp
4 | RM=-/bin/rm -rf
5 | LN=/bin/ln -s
6 | #是否开启sqlite的支持,如需要关闭,设置为空字符串
7 | FF_ENABLE_SQLITE_FLAG =
8 | #-DFF_ENABLE_SQLITE
9 | FF_ENABLE_CURL_FLAG =
10 | #-DFF_ENABLE_CURL
11 | CFLAGS=-g -Wall $(FF_ENABLE_CURL_FLAG) $(FF_ENABLE_SQLITE_FLAG)
12 | LDFLAGS= -O2 -lpthread -ldl -lpython2.6 -lmysqlclient
13 | #-lcurl
14 | #-llua
15 | #链接库名
16 | LIB_NAME=
17 | #链接库版本
18 | LIB_VER=1.0.0
19 | #平台
20 | ARCH=
21 | # 二进制目标
22 | BIN=app_game
23 |
24 | #源文件目录
25 | SrcDir= . ../../fflib/base ../../fflib/net ../../fflib/rpc ../../fflib/db ../../fflib/xml ../../fflib/server
26 | #头文件目录
27 | IncDir= ../../fflib/ ../../lib3party /usr/include/python2.7/ /usr/include/python2.6/
28 | #连接库目录
29 | LibDir= /usr/local/lib /usr/lib/mysql /usr/lib64/mysql
30 | SRCS=$(foreach dir,$(SrcDir),$(wildcard $(dir)/*.cpp))
31 | #INCS=$(foreach dir,$(IncDir),$(wildcard $(dir)/*.h))
32 | INCS=$(foreach dir,$(IncDir),$(addprefix -I,$(dir)))
33 | LINKS=$(foreach dir,$(LibDir),$(addprefix -L,$(dir)))
34 | CFLAGS := $(CFLAGS) $(INCS)
35 | LDFLAGS:= $(LINKS) $(LDFLAGS)
36 | CC=gcc
37 | ARCH=PC
38 | OBJS = $(SRCS:%.cpp=%.o)
39 | .PHONY:all clean
40 |
41 | all:$(BIN)
42 | $(BIN):$(OBJS)
43 | ifeq ($(FF_ENABLE_SQLITE_FLAG),-DFF_ENABLE_SQLITE)
44 | gcc -c ../../fflib/db/sqlite3.c -o sqlite3.o
45 | g++ -o $(BIN) $(OBJS) sqlite3.o $(LDFLAGS)
46 | else
47 | g++ -o $(BIN) $(OBJS) $(LDFLAGS)
48 | endif
49 | @echo " OK! Compile $@ "
50 | # @$(LN) $(shell pwd)/$(LIB_NAME).$(LIB_VER) /lib/$(LIB_NAME)
51 |
52 | %.o:%.cpp
53 | @echo "[$(ARCH)] Compile $@..."
54 | @$(CC) $(CFLAGS) -c $< -o $@
55 |
56 | .PHONY: clean
57 | clean:
58 | @echo "[$(ARCH)] Cleaning files..."
59 | @$(RM) $(OBJS) $(BIN)
60 | @$(RM) sqlite3.o
61 |
--------------------------------------------------------------------------------
/example/game/Makefile:
--------------------------------------------------------------------------------
1 | #交叉编译器路径
2 | CROSS=
3 | CP=/bin/cp
4 | RM=-/bin/rm -rf
5 | LN=/bin/ln -s
6 | #是否开启sqlite的支持,如需要关闭,设置为空字符串
7 | FF_ENABLE_SQLITE_FLAG =-DFF_ENABLE_SQLITE
8 | FF_ENABLE_CURL_FLAG =
9 | #-DFF_ENABLE_CURL
10 | CFLAGS=-g -Wall $(FF_ENABLE_CURL_FLAG) $(FF_ENABLE_SQLITE_FLAG)
11 | LDFLAGS= -O2 -lpthread -ldl -lpython2.6 -lmysqlclient
12 | #-lcurl
13 | #-llua
14 | #链接库名
15 | LIB_NAME=
16 | #链接库版本
17 | LIB_VER=1.0.0
18 | #平台
19 | ARCH=
20 | # 二进制目标
21 | BIN=app_game
22 |
23 | #源文件目录
24 | SrcDir= . ../../fflib/base ../../fflib/net ../../fflib/rpc ../../fflib/rpc/msg_def ../../fflib/db ../../fflib/xml ../../fflib/server
25 | #头文件目录
26 | IncDir= ../../fflib/ ../../lib3party /usr/include/python2.7/ /usr/include/python2.6/
27 | #连接库目录
28 | LibDir= /usr/local/lib /usr/lib/mysql /usr/lib64/mysql
29 | SRCS=$(foreach dir,$(SrcDir),$(wildcard $(dir)/*.cpp))
30 | #INCS=$(foreach dir,$(IncDir),$(wildcard $(dir)/*.h))
31 | INCS=$(foreach dir,$(IncDir),$(addprefix -I,$(dir)))
32 | LINKS=$(foreach dir,$(LibDir),$(addprefix -L,$(dir)))
33 | CFLAGS := $(CFLAGS) $(INCS)
34 | LDFLAGS:= $(LINKS) $(LDFLAGS)
35 | CC=gcc
36 | ARCH=PC
37 | OBJS = $(SRCS:%.cpp=%.o)
38 | .PHONY:all clean
39 |
40 | all:$(BIN)
41 | $(BIN):$(OBJS)
42 | ifeq ($(FF_ENABLE_SQLITE_FLAG),-DFF_ENABLE_SQLITE)
43 | gcc -c ../../fflib/db/sqlite3.c -o sqlite3.o
44 | g++ -o $(BIN) $(OBJS) sqlite3.o $(LDFLAGS)
45 | else
46 | g++ -o $(BIN) $(OBJS) $(LDFLAGS)
47 | endif
48 | @echo " OK! Compile $@ "
49 | # @$(LN) $(shell pwd)/$(LIB_NAME).$(LIB_VER) /lib/$(LIB_NAME)
50 |
51 | %.o:%.cpp
52 | @echo "[$(ARCH)] Compile $@..."
53 | @$(CC) $(CFLAGS) -c $< -o $@
54 |
55 | .PHONY: clean
56 | clean:
57 | @echo "[$(ARCH)] Cleaning files..."
58 | @$(RM) $(OBJS) $(BIN)
59 | @$(RM) sqlite3.o
60 |
--------------------------------------------------------------------------------
/example/game/ctrl.config:
--------------------------------------------------------------------------------
1 |
2 | #关于broker相关的配置, master_broker如果被设置表示该broker为slave broker, 如果需要跨组通信需要设置bridge_broker
3 | -broker tcp://*:1281
4 | #-master_broker tcp://127.0.0.1:20241
5 | #-bridge_broker tcp://127.0.0.1:30241
6 |
7 | #关于gate相关的配置,-gate 为gate的名称, gate_listen为监听的ip端口
8 | #-gate gate@0 -gate_listen tcp://*:30242 -heartbeat_timeout 600
9 |
10 | #scene 相关的配置 scene 为scene的名称, python_path为python的路径
11 | -scene ffEngine@0 -python_path ./pyctrl
12 | #-lua_scene scene@1 -lua_path ./luaproject
13 | #-lua_mod fflua@1
14 |
15 | #日志相关的配置 级别最大为debug=6,trace=5, info=4, warn=3, error=2, fatal=1
16 | -log_path ./log -log_filename fflog
17 | #-log_class DB_MGR,XX,BROKER,FFSCENE,FFSCENE_PYTHON,FFNET,PY
18 | -log_class DB_MGR,FFSCENE_PYTHON,FFSCENE_LUA,PY,BROKER
19 | -log_print_screen true -log_print_file true
20 | -log_level 5
21 |
22 |
23 | #性能监控单位秒
24 | -perf_timeout 3600
25 | #是否启动为守护进程
26 | #-d
27 | ##数据库相关的配置 账号/密码/数据库
28 | -db mysql://127.0.0.1:3306/root/acegame/pcgame
29 | #如果使用单独的账号系统,使用此db配置
30 | #-user_db mysql://127.0.0.1:3306/root/acegame/pcgame
31 |
--------------------------------------------------------------------------------
/example/game/default.conf:
--------------------------------------------------------------------------------
1 |
2 | #关于broker相关的配置, master_broker如果被设置表示该broker为slave broker, 如果需要跨组通信需要设置bridge_broker
3 | -broker tcp://127.0.0.1:40241
4 | #-master_broker tcp://127.0.0.1:20241
5 | #-bridge_broker tcp://127.0.0.1:30241
6 |
7 | #关于gate相关的配置,-gate 为gate的名称, gate_listen为监听的ip端口
8 | -gate gate@0 -gate_listen tcp://*:30242 -heartbeat_timeout 600
9 |
10 | #scene 相关的配置 scene 为scene的名称, python_path为python的路径
11 | -scene scene@0 -python_path ./pyproject
12 | #-lua_scene scene@1 -lua_path ./luaproject
13 | #-lua_mod fflua@1
14 |
15 | #日志相关的配置 级别最大为debug=6,trace=5, info=4, warn=3, error=2, fatal=1
16 | -log_path ./log -log_filename fflog
17 | #-log_class DB_MGR,XX,BROKER,FFSCENE,FFSCENE_PYTHON,FFNET,PY
18 | -log_class DB_MGR,FFSCENE_PYTHON,FFGATE,FFSCENE,FFSCENE_LUA,PY
19 | -log_print_screen true -log_print_file true
20 | -log_level 5
21 |
22 |
23 | #性能监控单位秒
24 | -perf_timeout 3600
25 | #是否启动为守护进程
26 | #-d
27 | ##数据库相关的配置 账号/密码/数据库
28 | -db sqlite://./ff_demo.db
29 | -group_name demo
30 |
--------------------------------------------------------------------------------
/example/game/main.lua:
--------------------------------------------------------------------------------
1 |
2 |
3 | function foo()
4 | end
5 |
6 |
7 |
--------------------------------------------------------------------------------
/example/game/pyctrl/msg/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pyctrl/msg/__init__.py
--------------------------------------------------------------------------------
/example/game/pyctrl/msg/ffengine/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/example/game/pyctrl/msg/ffengine/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.0)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/example/game/pyctrl/msg_def/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/example/game/pyctrl/msg_def/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.0)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/example/game/pylib/event_bus.py:
--------------------------------------------------------------------------------
1 | # coding=UTF-8
2 | import traceback
3 |
4 | class event_bus_t(object):
5 | def __init__(self):
6 | #key event class, value is dict of consumer function
7 | self.event_consumer = {}
8 | #processing list, cache event
9 | self.event_cache_list = []#fifo
10 | def default_except_handler(exception_):
11 | traceback.print_exc()
12 | self.exception_handler = default_except_handler
13 | def set_exception_handler(func_):
14 | self.exception_handler = func_
15 | def get_key_name(self, event_obj_):
16 | return event_obj_.__class__
17 | def bind_event(self, event_class_, consumer_func):
18 | key = event_class_
19 | consumer_name = consumer_func.__module__ + '.' + consumer_func.__name__
20 | dest_dict = self.event_consumer.get(key)
21 | if dest_dict == None:
22 | dest_dict = {}
23 | self.event_consumer[key] = dest_dict
24 | dest_dict[consumer_name] = consumer_func
25 | def post(self, event_):
26 | self.event_cache_list.insert(0, event_)
27 | size = len(self.event_cache_list)
28 | if size > 1:
29 | return True
30 |
31 | while len(self.event_cache_list) > 0:
32 | next_event = self.event_cache_list[len(self.event_cache_list) - 1]
33 | key = self.get_key_name(next_event)
34 | dest_dict = self.event_consumer.get(key)
35 | if None != dest_dict:
36 | for k, func in dest_dict.iteritems():
37 | try:
38 | func(event_)
39 | except Exception, e:
40 | self.exception_handler(e)
41 | except:
42 | pass
43 | self.event_cache_list.pop()
44 |
45 | def dump(self):
46 | print(self.event_consumer)
47 |
48 | event_bus = event_bus_t()
49 | def instance():
50 | return event_bus
51 |
52 | def bind_event(event_class_):
53 | bind_list = []
54 | if event_class_.__class__ == list:
55 | bind_list = event_class_
56 | else:
57 | bind_list.append(event_class_)
58 | def wraper(func_):
59 | ebus = instance()
60 | for k in bind_list:
61 | ebus.bind_event(k, func_)
62 | return func_
63 | return wraper
64 |
65 | def post(event_):
66 | instance().post(event_)
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/example/game/pylib/google/__init__.py:
--------------------------------------------------------------------------------
1 | __import__('pkg_resources').declare_namespace(__name__)
2 |
--------------------------------------------------------------------------------
/example/game/pylib/google/protobuf/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pylib/google/protobuf/__init__.py
--------------------------------------------------------------------------------
/example/game/pylib/google/protobuf/compiler/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pylib/google/protobuf/compiler/__init__.py
--------------------------------------------------------------------------------
/example/game/pylib/google/protobuf/internal/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pylib/google/protobuf/internal/__init__.py
--------------------------------------------------------------------------------
/example/game/pylib/id_generator.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pylib/id_generator.py
--------------------------------------------------------------------------------
/example/game/pylib/protobuf_example/msg.proto:
--------------------------------------------------------------------------------
1 |
2 | message TestMsg
3 | {
4 | required int32 id=1;
5 | required int32 time=2;
6 | optional string note=3;
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/example/game/pylib/protobuf_example/msg_pb2.py:
--------------------------------------------------------------------------------
1 | # Generated by the protocol buffer compiler. DO NOT EDIT!
2 | # source: msg.proto
3 |
4 | from google.protobuf import descriptor as _descriptor
5 | from google.protobuf import message as _message
6 | from google.protobuf import reflection as _reflection
7 | from google.protobuf import descriptor_pb2
8 | # @@protoc_insertion_point(imports)
9 |
10 |
11 |
12 |
13 | DESCRIPTOR = _descriptor.FileDescriptor(
14 | name='msg.proto',
15 | package='',
16 | serialized_pb='\n\tmsg.proto\"1\n\x07TestMsg\x12\n\n\x02id\x18\x01 \x02(\x05\x12\x0c\n\x04time\x18\x02 \x02(\x05\x12\x0c\n\x04note\x18\x03 \x01(\t')
17 |
18 |
19 |
20 |
21 | _TESTMSG = _descriptor.Descriptor(
22 | name='TestMsg',
23 | full_name='TestMsg',
24 | filename=None,
25 | file=DESCRIPTOR,
26 | containing_type=None,
27 | fields=[
28 | _descriptor.FieldDescriptor(
29 | name='id', full_name='TestMsg.id', index=0,
30 | number=1, type=5, cpp_type=1, label=2,
31 | has_default_value=False, default_value=0,
32 | message_type=None, enum_type=None, containing_type=None,
33 | is_extension=False, extension_scope=None,
34 | options=None),
35 | _descriptor.FieldDescriptor(
36 | name='time', full_name='TestMsg.time', index=1,
37 | number=2, type=5, cpp_type=1, label=2,
38 | has_default_value=False, default_value=0,
39 | message_type=None, enum_type=None, containing_type=None,
40 | is_extension=False, extension_scope=None,
41 | options=None),
42 | _descriptor.FieldDescriptor(
43 | name='note', full_name='TestMsg.note', index=2,
44 | number=3, type=9, cpp_type=9, label=1,
45 | has_default_value=False, default_value=unicode("", "utf-8"),
46 | message_type=None, enum_type=None, containing_type=None,
47 | is_extension=False, extension_scope=None,
48 | options=None),
49 | ],
50 | extensions=[
51 | ],
52 | nested_types=[],
53 | enum_types=[
54 | ],
55 | options=None,
56 | is_extendable=False,
57 | extension_ranges=[],
58 | serialized_start=13,
59 | serialized_end=62,
60 | )
61 |
62 | DESCRIPTOR.message_types_by_name['TestMsg'] = _TESTMSG
63 |
64 | class TestMsg(_message.Message):
65 | __metaclass__ = _reflection.GeneratedProtocolMessageType
66 | DESCRIPTOR = _TESTMSG
67 |
68 | # @@protoc_insertion_point(class_scope:TestMsg)
69 |
70 |
71 | # @@protoc_insertion_point(module_scope)
72 |
--------------------------------------------------------------------------------
/example/game/pylib/protobuf_example/protobuf_example.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pylib/protobuf_example/protobuf_example.py
--------------------------------------------------------------------------------
/example/game/pylib/thrift/TSCons.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | from os import path
21 | from SCons.Builder import Builder
22 |
23 |
24 | def scons_env(env, add=''):
25 | opath = path.dirname(path.abspath('$TARGET'))
26 | lstr = 'thrift --gen cpp -o ' + opath + ' ' + add + ' $SOURCE'
27 | cppbuild = Builder(action=lstr)
28 | env.Append(BUILDERS={'ThriftCpp': cppbuild})
29 |
30 |
31 | def gen_cpp(env, dir, file):
32 | scons_env(env)
33 | suffixes = ['_types.h', '_types.cpp']
34 | targets = map(lambda s: 'gen-cpp/' + file + s, suffixes)
35 | return env.ThriftCpp(targets, dir + file + '.thrift')
36 |
--------------------------------------------------------------------------------
/example/game/pylib/thrift/TSerialization.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | from protocol import TBinaryProtocol
21 | from transport import TTransport
22 |
23 |
24 | def serialize(thrift_object,
25 | protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
26 | transport = TTransport.TMemoryBuffer()
27 | protocol = protocol_factory.getProtocol(transport)
28 | thrift_object.write(protocol)
29 | return transport.getvalue()
30 |
31 |
32 | def deserialize(base,
33 | buf,
34 | protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
35 | transport = TTransport.TMemoryBuffer(buf)
36 | protocol = protocol_factory.getProtocol(transport)
37 | base.read(protocol)
38 | return base
39 |
--------------------------------------------------------------------------------
/example/game/pylib/thrift/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | __all__ = ['Thrift', 'TSCons']
21 |
--------------------------------------------------------------------------------
/example/game/pylib/thrift/protocol/TBase.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | from thrift.Thrift import *
21 | from thrift.protocol import TBinaryProtocol
22 | from thrift.transport import TTransport
23 |
24 | try:
25 | from thrift.protocol import fastbinary
26 | except:
27 | fastbinary = None
28 |
29 |
30 | class TBase(object):
31 | __slots__ = []
32 |
33 | def __repr__(self):
34 | L = ['%s=%r' % (key, getattr(self, key))
35 | for key in self.__slots__]
36 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
37 |
38 | def __eq__(self, other):
39 | if not isinstance(other, self.__class__):
40 | return False
41 | for attr in self.__slots__:
42 | my_val = getattr(self, attr)
43 | other_val = getattr(other, attr)
44 | if my_val != other_val:
45 | return False
46 | return True
47 |
48 | def __ne__(self, other):
49 | return not (self == other)
50 |
51 | def read(self, iprot):
52 | if (iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
53 | isinstance(iprot.trans, TTransport.CReadableTransport) and
54 | self.thrift_spec is not None and
55 | fastbinary is not None):
56 | fastbinary.decode_binary(self,
57 | iprot.trans,
58 | (self.__class__, self.thrift_spec))
59 | return
60 | iprot.readStruct(self, self.thrift_spec)
61 |
62 | def write(self, oprot):
63 | if (oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
64 | self.thrift_spec is not None and
65 | fastbinary is not None):
66 | oprot.trans.write(
67 | fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
68 | return
69 | oprot.writeStruct(self, self.thrift_spec)
70 |
71 |
72 | class TExceptionBase(Exception):
73 | # old style class so python2.4 can raise exceptions derived from this
74 | # This can't inherit from TBase because of that limitation.
75 | __slots__ = []
76 |
77 | __repr__ = TBase.__repr__.im_func
78 | __eq__ = TBase.__eq__.im_func
79 | __ne__ = TBase.__ne__.im_func
80 | read = TBase.read.im_func
81 | write = TBase.write.im_func
82 |
--------------------------------------------------------------------------------
/example/game/pylib/thrift/protocol/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | __all__ = ['TProtocol', 'TBinaryProtocol', 'fastbinary', 'TBase']
21 |
--------------------------------------------------------------------------------
/example/game/pylib/thrift/server/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | __all__ = ['TServer', 'TNonblockingServer']
21 |
--------------------------------------------------------------------------------
/example/game/pylib/thrift/transport/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | __all__ = ['TTransport', 'TSocket', 'THttpClient', 'TZlibTransport']
21 |
--------------------------------------------------------------------------------
/example/game/pylib/thrift_example/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pylib/thrift_example/__init__.py
--------------------------------------------------------------------------------
/example/game/pylib/thrift_example/ff/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/example/game/pylib/thrift_example/ff/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.0)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/example/game/pylib/thrift_example/ff/ttypes.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.0)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 |
11 | from thrift.transport import TTransport
12 | from thrift.protocol import TBinaryProtocol, TProtocol
13 | try:
14 | from thrift.protocol import fastbinary
15 | except:
16 | fastbinary = None
17 |
18 |
19 |
20 | class foo_t:
21 | """
22 | Attributes:
23 | - num
24 | """
25 |
26 | thrift_spec = (
27 | None, # 0
28 | (1, TType.I32, 'num', None, 100, ), # 1
29 | )
30 |
31 | def __init__(self, num=thrift_spec[1][4],):
32 | self.num = num
33 |
34 | def read(self, iprot):
35 | if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
36 | fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
37 | return
38 | iprot.readStructBegin()
39 | while True:
40 | (fname, ftype, fid) = iprot.readFieldBegin()
41 | if ftype == TType.STOP:
42 | break
43 | if fid == 1:
44 | if ftype == TType.I32:
45 | self.num = iprot.readI32();
46 | else:
47 | iprot.skip(ftype)
48 | else:
49 | iprot.skip(ftype)
50 | iprot.readFieldEnd()
51 | iprot.readStructEnd()
52 |
53 | def write(self, oprot):
54 | if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
55 | oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
56 | return
57 | oprot.writeStructBegin('foo_t')
58 | if self.num is not None:
59 | oprot.writeFieldBegin('num', TType.I32, 1)
60 | oprot.writeI32(self.num)
61 | oprot.writeFieldEnd()
62 | oprot.writeFieldStop()
63 | oprot.writeStructEnd()
64 |
65 | def validate(self):
66 | return
67 |
68 |
69 | def __repr__(self):
70 | L = ['%s=%r' % (key, value)
71 | for key, value in self.__dict__.iteritems()]
72 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
73 |
74 | def __eq__(self, other):
75 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
76 |
77 | def __ne__(self, other):
78 | return not (self == other)
79 |
--------------------------------------------------------------------------------
/example/game/pylib/thrift_example/thrift_example.py:
--------------------------------------------------------------------------------
1 |
2 | import thrift.Thrift as Thrift
3 | import thrift.protocol.TBinaryProtocol as TBinaryProtocol
4 | import thrift.protocol.TCompactProtocol as TCompactProtocol
5 |
6 | import thrift.transport.TTransport as TTransport
7 | import gen.ff.ttypes as ttypes
8 |
9 | mb = TTransport.TMemoryBuffer()
10 | #bp = TBinaryProtocol.TBinaryProtocol(mb)
11 | bp = TCompactProtocol.TCompactProtocol(mb)
12 |
13 | foo= ttypes.foo_t()
14 | print(foo)
15 | foo.write(bp)
16 |
17 |
18 | ret = mb.getvalue()
19 | print(len(ret))
20 |
21 | mb2 = TTransport.TMemoryBuffer(ret)
22 | #bp2 = TBinaryProtocol.TBinaryProtocol(mb2)
23 | bp2 = TCompactProtocol.TCompactProtocol(mb2)
24 | foo2= ttypes.foo_t()
25 | foo2.read(bp2);
26 |
27 | print(foo2)
28 |
29 |
30 |
--------------------------------------------------------------------------------
/example/game/pylib/wrods_filter.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | dest_code = 'utf-8'
4 | class words_filter_t:
5 | def __init__(self, words_list_):
6 | self.word_index = {}# {one word -> []}
7 | self.all_words = {}
8 | for w in words_list_:
9 | word = unicode(w, dest_code, 'ignore')
10 | word_len = len(word)
11 | if word_len == 0:
12 | continue
13 | dest_array = self.word_index.get(word[0])
14 | if None == dest_array:
15 | dest_array = []
16 | #print(__name__, 'filer')
17 | #print(word[0])
18 | self.word_index[word[0]] = dest_array
19 | if word_len not in dest_array:
20 | dest_array.append(word_len)
21 | dest_array.sort(reverse=True)
22 | self.all_words[word] = True
23 | print(__name__, "load filter words %d"%(len(self.all_words)))
24 | def dump(self, ):
25 | print (self.word_index, self.all_words)
26 |
27 | def filter(self, src_, replace_ = '*'):
28 | ret = unicode('', dest_code, 'ignore')
29 | word_src = unicode(src_, dest_code, 'ignore')
30 | i = 0
31 | while i < len(word_src):
32 | w = word_src[i]
33 | #print(__name__, 'filer')
34 | #print(w)
35 | dest_list = self.word_index.get(w)
36 | if None == dest_list:
37 | i += 1
38 | ret += w
39 | continue
40 | replace_num = 0
41 | for dest_len in dest_list:
42 | check_word = word_src[i:i + dest_len]
43 | #print('check_word', check_word)
44 | if None != self.all_words.get(check_word):
45 | i += dest_len
46 | #print('del', check_word)
47 | replace_num = len(check_word)#len(check_word.encode(dest_code))
48 | break
49 | if replace_num == 0:
50 | ret += w
51 | i += 1
52 | else:
53 | ret += replace_ * replace_num
54 | return ret.encode(dest_code)
55 |
56 | word_filter = None
57 | def init(src_file_):
58 | global word_filter
59 | wlist = []
60 | f = open(src_file_)
61 | for line in f.readlines():
62 | tmp = line.split('\n')
63 | wlist.append(tmp[0])
64 | word_filter = words_filter_t(wlist)
65 |
66 | def filter(src, replace_ = '*'):
67 | global word_filter
68 | return word_filter.filter(src, replace_)
69 |
70 |
71 | #init('fw.txt')
72 |
73 |
--------------------------------------------------------------------------------
/example/game/pyproject/echo_msg_def/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/example/game/pyproject/echo_msg_def/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.1)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/example/game/pyproject/handler/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pyproject/handler/__init__.py
--------------------------------------------------------------------------------
/example/game/pyproject/main-bk.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pyproject/main-bk.py
--------------------------------------------------------------------------------
/example/game/pyproject/main.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | import ffext
3 | import handler.player_handler
4 | from model import db_service
5 |
6 | import echo_msg_def.ttypes as ttypes
7 |
8 | def init():
9 | print('init......')
10 | if db_service.init() == False:
11 | return -1
12 |
13 | return 0
14 |
15 |
16 | def cleanup():
17 | print('cleanup.....')
18 | return 0
19 |
20 |
21 | @ffext.ff_reg_scene_interfacee(ttypes.echo_thrift_in_t, ttypes.echo_thrift_out_t)
22 | def test_echo(req):
23 | ret_msg = ttypes.echo_thrift_out_t()
24 | ret_msg.data = req.msg.data
25 | req.response(ret_msg)
26 | print('test_echo', req.msg)
27 | return
28 |
--------------------------------------------------------------------------------
/example/game/pyproject/model/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pyproject/model/__init__.py
--------------------------------------------------------------------------------
/example/game/pyproject/model/db_service.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import ffext
4 | import id_generator
5 |
6 | g_async_db = None
7 | def get_async_db():
8 | global g_async_db
9 | return g_async_db
10 |
11 | def init():
12 | global g_async_db
13 | #g_sync_db = ffext.ffdb_create('mysql://localhost:3306/root/acegame/pcgame')
14 | db_config = ffext.get_config('-db')
15 | print('db_config=%s'%(db_config))
16 | g_async_db = ffext.ffdb_create(db_config)
17 | if None == g_async_db:
18 | return False
19 | sql = '''create table IF NOT EXISTS player_info
20 | (
21 | UID bigint not null,
22 | NAME varchar(255) not null,
23 | X int not null,
24 | Y int not null,
25 | primary key(UID)
26 | )'''
27 | g_async_db.query(sql)
28 | return True
29 |
30 | def load_by_name(name_, callback):
31 | sql = "select * from player_info where NAME='%s' limit 1"%(name_)
32 | def cb(ret):
33 | retData = {}
34 | if ret.flag == False or len(ret.result) == 0:
35 | callback(retData)
36 | return
37 | for i in range(0, len(ret.column)):
38 | retData[ret.column[i]] = ret.result[0][i]
39 | callback(retData)
40 | return
41 | get_async_db().query(sql, cb)
42 | return
43 |
44 | def insert_player(field_data):
45 | sql = ''
46 | values = ''
47 | for k, v in field_data.iteritems():
48 | if sql == '':
49 | sql = "insert into player_info ({0}".format(k)
50 | values = ") values ('{0}'".format(v)
51 | else:
52 | sql += ", {0}".format(k)
53 | values += ", '{0}'".format(v)
54 | sql += values + ')'
55 | print(sql)
56 | g_async_db.query(sql)
57 | return
58 |
59 | def update_player(uid, field_data):
60 | sql = ''
61 | for k, v in field_data.iteritems():
62 | if sql == '':
63 | sql = "update player_info set {0} = '{1}'".format(k, v)
64 | else:
65 | sql += ", {0} = '{1}'".format(k, v)
66 | sql += " where uid = '{0}'".format(uid)
67 | print(sql)
68 | g_async_db.query(sql)
69 | return
70 |
71 |
--------------------------------------------------------------------------------
/example/game/pyproject/model/player_model.py:
--------------------------------------------------------------------------------
1 | import time
2 |
3 | class player_t:
4 | def __init__(self):
5 | self.id = 0
6 | self.name = ''
7 | self.x = 0
8 | self.y = 0
9 | self.last_move_tm = time.time()
10 |
11 |
--------------------------------------------------------------------------------
/example/game/pyproject/msg_def/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/example/game/pyproject/msg_def/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.0)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/example/game/pyproject/user_data/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/example/game/pyproject/user_data/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.1)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/Exception/TApplicationException.php:
--------------------------------------------------------------------------------
1 | array('var' => 'message',
31 | 'type' => TType::STRING),
32 | 2 => array('var' => 'code',
33 | 'type' => TType::I32));
34 |
35 | const UNKNOWN = 0;
36 | const UNKNOWN_METHOD = 1;
37 | const INVALID_MESSAGE_TYPE = 2;
38 | const WRONG_METHOD_NAME = 3;
39 | const BAD_SEQUENCE_ID = 4;
40 | const MISSING_RESULT = 5;
41 | const INTERNAL_ERROR = 6;
42 | const PROTOCOL_ERROR = 7;
43 | const INVALID_TRANSFORM = 8;
44 | const INVALID_PROTOCOL = 9;
45 | const UNSUPPORTED_CLIENT_TYPE = 10;
46 |
47 | function __construct($message=null, $code=0) {
48 | parent::__construct($message, $code);
49 | }
50 |
51 | public function read($output) {
52 | return $this->_read('TApplicationException', self::$_TSPEC, $output);
53 | }
54 |
55 | public function write($output) {
56 | $xfer = 0;
57 | $xfer += $output->writeStructBegin('TApplicationException');
58 | if ($message = $this->getMessage()) {
59 | $xfer += $output->writeFieldBegin('message', TType::STRING, 1);
60 | $xfer += $output->writeString($message);
61 | $xfer += $output->writeFieldEnd();
62 | }
63 | if ($code = $this->getCode()) {
64 | $xfer += $output->writeFieldBegin('type', TType::I32, 2);
65 | $xfer += $output->writeI32($code);
66 | $xfer += $output->writeFieldEnd();
67 | }
68 | $xfer += $output->writeFieldStop();
69 | $xfer += $output->writeStructEnd();
70 | return $xfer;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/Exception/TProtocolException.php:
--------------------------------------------------------------------------------
1 | strictRead_ = $strictRead;
37 | $this->strictWrite_ = $strictWrite;
38 | }
39 |
40 | public function getProtocol($trans) {
41 | return new TBinaryProtocol($trans, $this->strictRead_, $this->strictWrite_);
42 | }
43 | }
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/Factory/TCompactProtocolFactory.php:
--------------------------------------------------------------------------------
1 | p_ = $p;
35 | }
36 |
37 | public function write() {
38 | if ($this->first_) {
39 | $this->first_ = false;
40 | } else {
41 | $this->p_->getTransport()->write(TJSONProtocol::COMMA);
42 | }
43 | }
44 |
45 | public function read() {
46 | if ($this->first_) {
47 | $this->first_ = false;
48 | } else {
49 | $this->p_->readJSONSyntaxChar(TJSONProtocol::COMMA);
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/Protocol/JSON/LookaheadReader.php:
--------------------------------------------------------------------------------
1 | p_ = $p;
34 | }
35 |
36 | public function read() {
37 | if ($this->hasData_) {
38 | $this->hasData_ = false;
39 | } else {
40 | $this->data_ = $this->p_->getTransport()->readAll(1);
41 | }
42 |
43 | return substr($this->data_, 0, 1);
44 | }
45 |
46 | public function peek() {
47 | if (!$this->hasData_) {
48 | $this->data_ = $this->p_->getTransport()->readAll(1);
49 | }
50 |
51 | $this->hasData_ = true;
52 | return substr($this->data_, 0, 1);
53 | }
54 | }
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/Protocol/JSON/PairContext.php:
--------------------------------------------------------------------------------
1 | p_ = $p;
35 | }
36 |
37 | public function write() {
38 | if ($this->first_) {
39 | $this->first_ = false;
40 | $this->colon_ = true;
41 | } else {
42 | $this->p_->getTransport()->write($this->colon_ ? TJSONProtocol::COLON : TJSONProtocol::COMMA);
43 | $this->colon_ = !$this->colon_;
44 | }
45 | }
46 |
47 | public function read() {
48 | if ($this->first_) {
49 | $this->first_ = false;
50 | $this->colon_ = true;
51 | } else {
52 | $this->p_->readJSONSyntaxChar($this->colon_ ? TJSONProtocol::COLON : TJSONProtocol::COMMA);
53 | $this->colon_ = !$this->colon_;
54 | }
55 | }
56 |
57 | public function escapeNum() {
58 | return $this->colon_;
59 | }
60 | }
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/Protocol/TBinaryProtocolAccelerated.php:
--------------------------------------------------------------------------------
1 | strictRead_;
43 | }
44 | public function isStrictWrite() {
45 | return $this->strictWrite_;
46 | }
47 | }
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/Server/TServer.php:
--------------------------------------------------------------------------------
1 | processor_ = $processor;
77 | $this->transport_ = $transport;
78 | $this->inputTransportFactory_ = $inputTransportFactory;
79 | $this->outputTransportFactory_ = $outputTransportFactory;
80 | $this->inputProtocolFactory_ = $inputProtocolFactory;
81 | $this->outputProtocolFactory_ = $outputProtocolFactory;
82 | }
83 |
84 | /**
85 | * Serves the server. This should never return
86 | * unless a problem permits it to do so or it
87 | * is interrupted intentionally
88 | *
89 | * @abstract
90 | * @return void
91 | */
92 | abstract public function serve();
93 |
94 | /**
95 | * Stops the server serving
96 | *
97 | * @abstract
98 | * @return void
99 | */
100 | abstract public function stop();
101 | }
102 |
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/Server/TServerSocket.php:
--------------------------------------------------------------------------------
1 | host_ = $host;
52 | $this->port_ = $port;
53 | }
54 |
55 | /**
56 | * Sets the accept timeout
57 | *
58 | * @param int $acceptTimeout
59 | * @return void
60 | */
61 | public function setAcceptTimeout($acceptTimeout) {
62 | $this->acceptTimeout_ = $acceptTimeout;
63 | }
64 |
65 | /**
66 | * Opens a new socket server handle
67 | *
68 | * @return void
69 | */
70 | public function listen() {
71 | $this->listener_ = stream_socket_server('tcp://' . $this->host_ . ':' . $this->port_);
72 | }
73 |
74 | /**
75 | * Closes the socket server handle
76 | *
77 | * @return void
78 | */
79 | public function close() {
80 | @fclose($this->listener_);
81 | $this->listener_ = null;
82 | }
83 |
84 | /**
85 | * Implementation of accept. If not client is accepted in the given time
86 | *
87 | * @return TSocket
88 | */
89 | protected function acceptImpl() {
90 | $handle = @stream_socket_accept($this->listener_, $this->acceptTimeout_ / 1000.0);
91 | if(!$handle) return null;
92 |
93 | $socket = new TSocket();
94 | $socket->setHandle($handle);
95 |
96 | return $socket;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/Server/TServerTransport.php:
--------------------------------------------------------------------------------
1 | acceptImpl();
47 |
48 | if ($transport == null) {
49 | throw new TTransportException("accept() may not return NULL");
50 | }
51 |
52 | return $transport;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/Server/TSimpleServer.php:
--------------------------------------------------------------------------------
1 | transport_->listen();
30 |
31 | while (!$this->stop_) {
32 | try {
33 | $transport = $this->transport_->accept();
34 |
35 | if ($transport != null) {
36 | $inputTransport = $this->inputTransportFactory_->getTransport($transport);
37 | $outputTransport = $this->outputTransportFactory_->getTransport($transport);
38 | $inputProtocol = $this->inputProtocolFactory_->getProtocol($inputTransport);
39 | $outputProtocol = $this->outputProtocolFactory_->getProtocol($outputTransport);
40 | while ($this->processor_->process($inputProtocol, $outputProtocol)) { }
41 | }
42 | }
43 | catch (TTransportException $e) { }
44 | }
45 | }
46 |
47 | /**
48 | * Stops the server running. Kills the transport
49 | * and then stops the main serving loop
50 | *
51 | * @return void
52 | */
53 | public function stop() {
54 | $this->transport_->close();
55 | $this->stop_ = true;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/StringFunc/Core.php:
--------------------------------------------------------------------------------
1 | strlen($str) - $start;
37 | }
38 |
39 | return mb_substr($str, $start, $length, '8bit');
40 | }
41 |
42 | public function strlen($str) {
43 | return mb_strlen($str, '8bit');
44 | }
45 | }
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/StringFunc/TStringFunc.php:
--------------------------------------------------------------------------------
1 | buf_ = $buf;
45 | }
46 |
47 | protected $buf_ = '';
48 |
49 | public function isOpen() {
50 | return true;
51 | }
52 |
53 | public function open() {}
54 |
55 | public function close() {}
56 |
57 | public function write($buf) {
58 | $this->buf_ .= $buf;
59 | }
60 |
61 | public function read($len) {
62 | $bufLength = TStringFuncFactory::create()->strlen($this->buf_);
63 |
64 | if ($bufLength === 0) {
65 | throw new TTransportException('TMemoryBuffer: Could not read ' .
66 | $len . ' bytes from buffer.',
67 | TTransportException::UNKNOWN);
68 | }
69 |
70 | if ($bufLength <= $len) {
71 | $ret = $this->buf_;
72 | $this->buf_ = '';
73 | return $ret;
74 | }
75 |
76 | $ret = TStringFuncFactory::create()->substr($this->buf_, 0, $len);
77 | $this->buf_ = TStringFuncFactory::create()->substr($this->buf_, $len);
78 |
79 | return $ret;
80 | }
81 |
82 | function getBuffer() {
83 | return $this->buf_;
84 | }
85 |
86 | public function available() {
87 | return TStringFuncFactory::create()->strlen($this->buf_);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/Transport/TNullTransport.php:
--------------------------------------------------------------------------------
1 | read($len);
70 |
71 | $data = '';
72 | $got = 0;
73 | while (($got = TStringFuncFactory::create()->strlen($data)) < $len) {
74 | $data .= $this->read($len - $got);
75 | }
76 | return $data;
77 | }
78 |
79 | /**
80 | * Writes the given data out.
81 | *
82 | * @param string $buf The data to write
83 | * @throws TTransportException if writing fails
84 | */
85 | public abstract function write($buf);
86 |
87 | /**
88 | * Flushes any pending data out of a buffer
89 | *
90 | * @throws TTransportException if a writing error occurs
91 | */
92 | public function flush() {}
93 | }
94 |
--------------------------------------------------------------------------------
/example/php_sdk/Thrift/Type/TMessageType.php:
--------------------------------------------------------------------------------
1 | '
13 |
14 | while 1:
15 | print 'waiting for connection'
16 | clientsock, addr = serversock.accept()
17 | print 'connected from:', addr
18 |
19 | data = ''
20 | while 1:
21 | try:
22 | data = clientsock.recv(BUFSIZ)
23 | except:
24 | print('error')
25 | break
26 | if not data: break
27 | print('*'*20, datetime.datetime.now())
28 | print('recv len:', len(data))
29 | clientsock.send(data)
30 |
31 | clientsock.close()
32 |
33 | serversock.close()
34 |
--------------------------------------------------------------------------------
/example/python_sdk/ff/ttypes.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.0)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 |
11 | from thrift.transport import TTransport
12 | from thrift.protocol import TBinaryProtocol, TProtocol
13 | try:
14 | from thrift.protocol import fastbinary
15 | except:
16 | fastbinary = None
17 |
18 |
19 |
20 | class foo_t:
21 | """
22 | Attributes:
23 | - num
24 | """
25 |
26 | thrift_spec = (
27 | None, # 0
28 | (1, TType.I32, 'num', None, 100, ), # 1
29 | )
30 |
31 | def __init__(self, num=thrift_spec[1][4],):
32 | self.num = num
33 |
34 | def read(self, iprot):
35 | if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
36 | fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
37 | return
38 | iprot.readStructBegin()
39 | while True:
40 | (fname, ftype, fid) = iprot.readFieldBegin()
41 | if ftype == TType.STOP:
42 | break
43 | if fid == 1:
44 | if ftype == TType.I32:
45 | self.num = iprot.readI32();
46 | else:
47 | iprot.skip(ftype)
48 | else:
49 | iprot.skip(ftype)
50 | iprot.readFieldEnd()
51 | iprot.readStructEnd()
52 |
53 | def write(self, oprot):
54 | if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
55 | oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
56 | return
57 | oprot.writeStructBegin('foo_t')
58 | if self.num is not None:
59 | oprot.writeFieldBegin('num', TType.I32, 1)
60 | oprot.writeI32(self.num)
61 | oprot.writeFieldEnd()
62 | oprot.writeFieldStop()
63 | oprot.writeStructEnd()
64 |
65 | def validate(self):
66 | return
67 |
68 |
69 | def __repr__(self):
70 | L = ['%s=%r' % (key, value)
71 | for key, value in self.__dict__.iteritems()]
72 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
73 |
74 | def __eq__(self, other):
75 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
76 |
77 | def __ne__(self, other):
78 | return not (self == other)
79 |
--------------------------------------------------------------------------------
/example/python_sdk/gen_py/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/python_sdk/gen_py/__init__.py
--------------------------------------------------------------------------------
/example/python_sdk/gen_py/echo.thrift:
--------------------------------------------------------------------------------
1 | namespace cpp ff
2 |
3 | struct echo_thrift_in_t {
4 | 1: string data
5 | }
6 |
7 | struct echo_thrift_out_t {
8 | 1: string data
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/example/python_sdk/gen_py/echo/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/example/python_sdk/gen_py/echo/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.1)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/example/python_sdk/gen_py/thrift-0.9.1.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/python_sdk/gen_py/thrift-0.9.1.exe
--------------------------------------------------------------------------------
/example/python_sdk/thrift/TSCons.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | from os import path
21 | from SCons.Builder import Builder
22 |
23 |
24 | def scons_env(env, add=''):
25 | opath = path.dirname(path.abspath('$TARGET'))
26 | lstr = 'thrift --gen cpp -o ' + opath + ' ' + add + ' $SOURCE'
27 | cppbuild = Builder(action=lstr)
28 | env.Append(BUILDERS={'ThriftCpp': cppbuild})
29 |
30 |
31 | def gen_cpp(env, dir, file):
32 | scons_env(env)
33 | suffixes = ['_types.h', '_types.cpp']
34 | targets = map(lambda s: 'gen-cpp/' + file + s, suffixes)
35 | return env.ThriftCpp(targets, dir + file + '.thrift')
36 |
--------------------------------------------------------------------------------
/example/python_sdk/thrift/TSerialization.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | from protocol import TBinaryProtocol
21 | from transport import TTransport
22 |
23 |
24 | def serialize(thrift_object,
25 | protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
26 | transport = TTransport.TMemoryBuffer()
27 | protocol = protocol_factory.getProtocol(transport)
28 | thrift_object.write(protocol)
29 | return transport.getvalue()
30 |
31 |
32 | def deserialize(base,
33 | buf,
34 | protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
35 | transport = TTransport.TMemoryBuffer(buf)
36 | protocol = protocol_factory.getProtocol(transport)
37 | base.read(protocol)
38 | return base
39 |
--------------------------------------------------------------------------------
/example/python_sdk/thrift/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | __all__ = ['Thrift', 'TSCons']
21 |
--------------------------------------------------------------------------------
/example/python_sdk/thrift/msg_def/__init__.py:
--------------------------------------------------------------------------------
1 | __all__ = ['ttypes', 'constants']
2 |
--------------------------------------------------------------------------------
/example/python_sdk/thrift/msg_def/constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Autogenerated by Thrift Compiler (0.9.0)
3 | #
4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | #
6 | # options string: py
7 | #
8 |
9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException
10 | from ttypes import *
11 |
12 |
--------------------------------------------------------------------------------
/example/python_sdk/thrift/protocol/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | __all__ = ['TProtocol', 'TBinaryProtocol', 'fastbinary', 'TBase']
21 |
--------------------------------------------------------------------------------
/example/python_sdk/thrift/server/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | __all__ = ['TServer', 'TNonblockingServer']
21 |
--------------------------------------------------------------------------------
/example/python_sdk/thrift/transport/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | __all__ = ['TTransport', 'TSocket', 'THttpClient', 'TZlibTransport']
21 |
--------------------------------------------------------------------------------
/example/tutorial/Makefile:
--------------------------------------------------------------------------------
1 | #交叉编译器路径
2 | CROSS=
3 | CP=/bin/cp
4 | RM=-/bin/rm -rf
5 | LN=/bin/ln -s
6 | CFLAGS=-g -Wall
7 | LDFLAGS= -lpthread
8 | #链接库名
9 | LIB_NAME=
10 | #链接库版本
11 | LIB_VER=1.0.0
12 | #平台
13 | ARCH=
14 | # 二进制目标
15 | BIN=app_rpc
16 |
17 | #源文件目录
18 | SrcDir= ./gen-cpp/ . ../../fflib/base ../../fflib/net ../../fflib/rpc
19 | #头文件目录
20 | IncDir= ../../lib3party ../../fflib/ ./
21 | #连接库目录
22 | LibDir= /usr/local/lib
23 | SRCS=$(foreach dir,$(SrcDir),$(wildcard $(dir)/*.cpp))
24 | #INCS=$(foreach dir,$(IncDir),$(wildcard $(dir)/*.h))
25 | INCS=$(foreach dir,$(IncDir),$(addprefix -I,$(dir)))
26 | LINKS=$(foreach dir,$(LibDir),$(addprefix -L,$(dir)))
27 | CFLAGS := $(CFLAGS) $(INCS)
28 | LDFLAGS:= $(LINKS) $(LDFLAGS)
29 | CC=gcc
30 | ARCH=PC
31 | OBJS = $(SRCS:%.cpp=%.o)
32 | .PHONY:all clean
33 |
34 | all:$(BIN)
35 | $(BIN):$(OBJS)
36 | g++ -o $(BIN) $(OBJS) $(LDFLAGS)
37 | @echo -e " OK!\tCompile $@ "
38 | # @$(LN) $(shell pwd)/$(LIB_NAME).$(LIB_VER) /lib/$(LIB_NAME)
39 |
40 | %.o:%.cpp
41 | @echo -e "[$(ARCH)] \t\tCompile $@..."
42 | @$(CC) $(CFLAGS) -c $< -o $@
43 |
44 | .PHONY: clean
45 | clean:
46 | @echo -e "[$(ARCH)] \tCleaning files..."
47 | @$(RM) $(OBJS) $(BIN)
48 |
--------------------------------------------------------------------------------
/example/tutorial/echo.proto:
--------------------------------------------------------------------------------
1 | // See README.txt for information and build instructions.
2 |
3 | package ff;
4 |
5 | message pb_echo_in_t {
6 | required string data = 1;
7 | }
8 | message pb_echo_out_t {
9 | required string data = 1;
10 | }
11 |
--------------------------------------------------------------------------------
/example/tutorial/echo.thrift:
--------------------------------------------------------------------------------
1 | namespace cpp ff
2 | namespace py ff
3 | namespace php ff
4 |
5 | struct echo_thrift_in_t {
6 | 1: string data
7 | }
8 |
9 | struct echo_thrift_out_t {
10 | 1: string data
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/example/tutorial/echo_constants.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * Autogenerated by Thrift Compiler (0.9.1)
3 | *
4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | * @generated
6 | */
7 | #include "echo_constants.h"
8 |
9 | namespace ff {
10 |
11 | const echoConstants g_echo_constants;
12 |
13 | echoConstants::echoConstants() {
14 | }
15 |
16 | } // namespace
17 |
18 |
--------------------------------------------------------------------------------
/example/tutorial/echo_constants.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Autogenerated by Thrift Compiler (0.9.1)
3 | *
4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5 | * @generated
6 | */
7 | #ifndef echo_CONSTANTS_H
8 | #define echo_CONSTANTS_H
9 |
10 | #include "echo_types.h"
11 |
12 | namespace ff {
13 |
14 | class echoConstants {
15 | public:
16 | echoConstants();
17 |
18 | };
19 |
20 | extern const echoConstants g_echo_constants;
21 |
22 | } // namespace
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/example/tutorial/echo_test.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/tutorial/echo_test.h
--------------------------------------------------------------------------------
/example/tutorial/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "base/daemon_tool.h"
3 | #include "base/arg_helper.h"
4 | #include "base/strtool.h"
5 | #include "base/smart_ptr.h"
6 |
7 | #include "rpc/ffrpc.h"
8 | #include "rpc/ffbroker.h"
9 | #include "base/log.h"
10 | #include "base/signal_helper.h"
11 | #include "echo_test.h"
12 | #include "protobuf_test.h"
13 | #include "thrift_test.h"
14 |
15 | using namespace ff;
16 |
17 | int main(int argc, char* argv[])
18 | {
19 | //! 美丽的日志组件,shell输出是彩色滴!!
20 | LOG.start("-log_path ./log -log_filename log -log_class XX,BROKER,FFRPC -log_print_screen true -log_print_file false -log_level 4");
21 |
22 | if (argc == 1)
23 | {
24 | printf("usage: %s -broker tcp://127.0.0.1:10241\n", argv[0]);
25 | return 1;
26 | }
27 | arg_helper_t arg_helper(argc, argv);
28 |
29 | //! 启动broker,负责网络相关的操作,如消息转发,节点注册,重连等
30 |
31 | ffbroker_t ffbroker;
32 | if (ffbroker.open(arg_helper))
33 | {
34 | return -1;
35 | }
36 |
37 | sleep(1);
38 | if (arg_helper.is_enable_option("-echo_test"))
39 | {
40 | run_echo_test(arg_helper);
41 | }
42 | else if (arg_helper.is_enable_option("-protobuf_test"))
43 | {
44 | run_protobuf_test(arg_helper);
45 | }
46 | else if (arg_helper.is_enable_option("-thrift_test"))
47 | {
48 | run_thrift_test(arg_helper);
49 | }
50 | else
51 | {
52 | printf("usage %s -broker tcp://127.0.0.1:10241 -echo_test\n", argv[0]);
53 | return -1;
54 | }
55 |
56 | ffbroker.close();
57 | return 0;
58 | }
59 |
--------------------------------------------------------------------------------
/example/tutorial/protobuf.Makefile:
--------------------------------------------------------------------------------
1 | #交叉编译器路径
2 | CROSS=
3 | CP=/bin/cp
4 | RM=-/bin/rm -rf
5 | LN=/bin/ln -s
6 | CFLAGS=-g -Wall -DFF_ENABLE_PROTOCOLBUF
7 | LDFLAGS= -lpthread -lprotobuf
8 | #链接库名
9 | LIB_NAME=
10 | #链接库版本
11 | LIB_VER=1.0.0
12 | #平台
13 | ARCH=
14 | # 二进制目标
15 | BIN=app_rpc
16 |
17 | #源文件目录
18 | SrcDir= . ../../fflib/base ../../fflib/net ../../fflib/rpc
19 | #头文件目录
20 | IncDir= ../../fflib/ ../../lib3party ./
21 | #连接库目录
22 | LibDir= /usr/local/lib
23 | SRCS=$(foreach dir,$(SrcDir),$(wildcard $(dir)/*.cpp))
24 | #INCS=$(foreach dir,$(IncDir),$(wildcard $(dir)/*.h))
25 | INCS=$(foreach dir,$(IncDir),$(addprefix -I,$(dir)))
26 | LINKS=$(foreach dir,$(LibDir),$(addprefix -L,$(dir)))
27 | CFLAGS := $(CFLAGS) $(INCS)
28 | LDFLAGS:= $(LINKS) $(LDFLAGS)
29 | CC=gcc
30 | ARCH=PC
31 | OBJS = $(SRCS:%.cpp=%.o)
32 | .PHONY:all clean
33 |
34 | all:$(BIN)
35 | $(BIN):$(OBJS)
36 | @$(CC) $(CFLAGS) -c echo.pb.cc -o echo.pb.o
37 | g++ -o $(BIN) $(OBJS) echo.pb.o $(LDFLAGS)
38 | @echo -e " OK!\tCompile $@ "
39 | # @$(LN) $(shell pwd)/$(LIB_NAME).$(LIB_VER) /lib/$(LIB_NAME)
40 |
41 | %.o:%.cpp
42 | @echo -e "[$(ARCH)] \t\tCompile $@..."
43 | @$(CC) $(CFLAGS) -c $< -o $@
44 |
45 | .PHONY: clean
46 | clean:
47 | @echo -e "[$(ARCH)] \tCleaning files..."
48 | @$(RM) $(OBJS) $(BIN)
49 |
--------------------------------------------------------------------------------
/example/tutorial/protobuf_test.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/tutorial/protobuf_test.h
--------------------------------------------------------------------------------
/example/tutorial/thrift-0.9.0.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/tutorial/thrift-0.9.0.exe
--------------------------------------------------------------------------------
/example/tutorial/thrift.Makefile:
--------------------------------------------------------------------------------
1 | #交叉编译器路径
2 | CROSS=
3 | CP=/bin/cp
4 | RM=-/bin/rm -rf
5 | LN=/bin/ln -s
6 | CFLAGS=-g -Wall -DFF_ENABLE_THRIFT
7 | LDFLAGS= -lpthread
8 | #链接库名
9 | LIB_NAME=
10 | #链接库版本
11 | LIB_VER=1.0.0
12 | #平台
13 | ARCH=
14 | # 二进制目标
15 | BIN=app_rpc
16 |
17 | #源文件目录
18 | SrcDir= . ../../fflib/base ../../fflib/net ../../fflib/rpc
19 | #头文件目录
20 | IncDir= ../../fflib/ ../../lib3party ./
21 | #连接库目录
22 | LibDir= /usr/local/lib
23 | SRCS=$(foreach dir,$(SrcDir),$(wildcard $(dir)/*.cpp))
24 | #INCS=$(foreach dir,$(IncDir),$(wildcard $(dir)/*.h))
25 | INCS=$(foreach dir,$(IncDir),$(addprefix -I,$(dir)))
26 | LINKS=$(foreach dir,$(LibDir),$(addprefix -L,$(dir)))
27 | CFLAGS := $(CFLAGS) $(INCS)
28 | LDFLAGS:= $(LINKS) $(LDFLAGS)
29 | CC=gcc
30 | ARCH=PC
31 | OBJS = $(SRCS:%.cpp=%.o)
32 | .PHONY:all clean
33 |
34 | all:$(BIN)
35 | $(BIN):$(OBJS)
36 | g++ -o $(BIN) $(OBJS) $(LDFLAGS)
37 | @echo -e " OK!\tCompile $@ "
38 | # @$(LN) $(shell pwd)/$(LIB_NAME).$(LIB_VER) /lib/$(LIB_NAME)
39 |
40 | %.o:%.cpp
41 | @echo -e "[$(ARCH)] \t\tCompile $@..."
42 | @$(CC) $(CFLAGS) -c $< -o $@
43 |
44 | .PHONY: clean
45 | clean:
46 | @echo -e "[$(ARCH)] \tCleaning files..."
47 | @$(RM) $(OBJS) $(BIN)
48 |
--------------------------------------------------------------------------------
/example/tutorial/thrift_test.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/tutorial/thrift_test.h
--------------------------------------------------------------------------------
/fflib/base/arg_helper.h:
--------------------------------------------------------------------------------
1 | #ifndef _ARG_HELPER_H_
2 | #define _ARG_HELPER_H_
3 |
4 | #include
5 | #include
6 | #include
7 | using namespace std;
8 |
9 | #include "base/strtool.h"
10 |
11 | class arg_helper_t
12 | {
13 | public:
14 | arg_helper_t(int argc, char* argv[])
15 | {
16 | for (int i = 0; i < argc; ++i)
17 | {
18 | m_args.push_back(argv[i]);
19 | }
20 | if (is_enable_option("-f"))
21 | {
22 | load_from_file(get_option_value("-f"));
23 | }
24 | }
25 | arg_helper_t(string arg_str_)
26 | {
27 | vector v;
28 | strtool::split(arg_str_, v, " ");
29 | m_args.insert(m_args.end(), v.begin(), v.end());
30 | if (is_enable_option("-f"))
31 | {
32 | load_from_file(get_option_value("-f"));
33 | }
34 | }
35 | string get_option(int idx_) const
36 | {
37 | if ((size_t)idx_ >= m_args.size())
38 | {
39 | return "";
40 | }
41 | return m_args[idx_];
42 | }
43 | bool is_enable_option(string opt_) const
44 | {
45 | for (size_t i = 0; i < m_args.size(); ++i)
46 | {
47 | if (opt_ == m_args[i])
48 | {
49 | return true;
50 | }
51 | }
52 | return false;
53 | }
54 |
55 | string get_option_value(string opt_) const
56 | {
57 | string ret;
58 | for (size_t i = 0; i < m_args.size(); ++i)
59 | {
60 | if (opt_ == m_args[i])
61 | {
62 | size_t value_idx = ++ i;
63 | if (value_idx >= m_args.size())
64 | {
65 | return ret;
66 | }
67 | ret = m_args[value_idx];
68 | return ret;
69 | }
70 | }
71 | return ret;
72 | }
73 | int load_from_file(const string& file_)
74 | {
75 | ifstream inf(file_.c_str());
76 | string all;
77 | string tmp;
78 | while (inf.eof() == false)
79 | {
80 | if (!getline(inf, tmp))
81 | {
82 | break;
83 | }
84 | if (tmp.empty() == false && tmp[0] == '#')//!过滤注释
85 | {
86 | continue;
87 | }
88 | //printf("get:%s\n", tmp.c_str());
89 | //sleep(1);
90 | all += tmp + " ";
91 | tmp.clear();
92 | }
93 | vector v;
94 | strtool::split(all, v, " ");
95 | m_args.insert(m_args.end(), v.begin(), v.end());
96 | return 0;
97 | }
98 | private:
99 | vector m_args;
100 | };
101 |
102 | #endif
103 |
104 |
--------------------------------------------------------------------------------
/fflib/base/atomic_op.h:
--------------------------------------------------------------------------------
1 | #ifndef _FF_ATOMIC_H_
2 | #define _FF_ATOMIC_H_
3 |
4 | namespace ff {
5 | //! windows.h
6 | //! InterlockedIncrement
7 | //! InterlockedDecrement
8 |
9 | #define ATOMIC_ADD(src_ptr, v) (void)__sync_add_and_fetch(src_ptr, v)
10 | #define ATOMIC_SUB_AND_FETCH(src_ptr, v) __sync_sub_and_fetch(src_ptr, v)
11 | #define ATOMIC_ADD_AND_FETCH(src_ptr, v) __sync_add_and_fetch(src_ptr, v)
12 | #define ATOMIC_FETCH(src_ptr) __sync_add_and_fetch(src_ptr, 0)
13 | #define ATOMIC_SET(src_ptr, v) (void)__sync_bool_compare_and_swap(src_ptr, *(src_ptr), v)
14 |
15 | class ref_count_t
16 | {
17 | typedef volatile long atomic_t;
18 | public:
19 | ref_count_t():
20 | m_ref_num(0)
21 | {}
22 | ~ref_count_t()
23 | {}
24 |
25 | inline void inc(int n = 1)
26 | {
27 | ATOMIC_ADD(&m_ref_num, n);
28 | }
29 | inline bool dec_and_check_zero(int n = 1)
30 | {
31 | return 0 == ATOMIC_SUB_AND_FETCH(&m_ref_num, n);
32 | }
33 | inline atomic_t inc_and_fetch(int n = 1)
34 | {
35 | return ATOMIC_ADD_AND_FETCH(&m_ref_num, n);
36 | }
37 | inline atomic_t value()
38 | {
39 | return ATOMIC_FETCH(&m_ref_num);
40 | }
41 |
42 | private:
43 | atomic_t m_ref_num;
44 | };
45 |
46 | }
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/fflib/base/daemon_tool.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef _DAEMON_TOOL_H_
3 | #define _DAEMON_TOOL_H_
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | namespace ff
17 | {
18 | class daemon_tool_t
19 | {
20 | public:
21 | static void daemon()
22 | {
23 | daemon(NULL);
24 | }
25 |
26 | static void daemon(const char* uname_)
27 | {
28 | pid_t pid, sid;
29 |
30 | if ((pid = fork()) < 0)
31 | {
32 | printf("daemon fork failed:%s\n", strerror(errno));
33 | exit(EXIT_FAILURE);
34 | }
35 | else if(pid != 0)
36 | {
37 | exit(EXIT_SUCCESS);
38 | }
39 |
40 | char buffer[1024];
41 | getcwd(buffer, sizeof(buffer));
42 |
43 | if(chdir(buffer) == -1)
44 | {
45 | printf("chdir failed:%s", strerror(errno));
46 | exit(EXIT_FAILURE);
47 | }
48 |
49 | if(uname_ != NULL)
50 | {
51 | int uid = get_uid(uname_);
52 | if(uid == -1)
53 | {
54 | printf("get_uid failed:%s", strerror(errno));
55 | exit(EXIT_FAILURE);
56 | }
57 | if(setuid(uid) == -1)
58 | {
59 | printf("setuid failed:%s", strerror(errno));
60 | exit(EXIT_FAILURE);
61 | }
62 | }
63 |
64 | sid = setsid();
65 | if (sid < 0)
66 | {
67 | printf("daemon setsid failed:%s", strerror(errno));
68 | exit (EXIT_FAILURE);
69 | }
70 |
71 | umask (022);
72 |
73 | for (int i = getdtablesize() - 1; i >= 0; --i)
74 | {
75 | (void)close(i);
76 | }
77 |
78 | int fd_dev = open("/dev/null", O_RDWR);
79 | (void)dup(fd_dev);
80 | (void)dup(fd_dev);
81 | }
82 |
83 | static int get_uid(const char* uname_)
84 | {
85 | struct passwd *user = NULL;
86 | user = getpwnam(uname_);
87 | if(user == NULL)
88 | {
89 | return -1;
90 | }
91 | return user->pw_uid;
92 | }
93 | };
94 |
95 | }
96 | #endif
97 |
98 |
--------------------------------------------------------------------------------
/fflib/base/obj_pool.h:
--------------------------------------------------------------------------------
1 | #ifndef _OBJ_POOL_H_
2 | #define _OBJ_POOL_H_
3 |
4 | #include
5 | #include
6 | #include
7 | using namespace std;
8 |
9 | namespace ff {
10 |
11 | template
12 | class ff_obj_pool_t
13 | {
14 | public:
15 | ff_obj_pool_t(){
16 | }
17 | virtual ~ff_obj_pool_t() {
18 | for (typename list::iterator it = m_free.begin(); it != m_free.end(); ++it){
19 | ::free(*it);
20 | }
21 | m_free.clear();
22 | }
23 | T* alloc(){
24 | if (false == m_free.empty()){
25 | T* pret = m_free.front();
26 | m_free.pop_front();
27 | pret = new (pret) T;
28 | return pret;
29 | }
30 | else{
31 | void* p = ::malloc(sizeof(T));
32 | T* pret = new (p) T;
33 | return pret;
34 | }
35 | return NULL;
36 | }
37 | void release(T* p){
38 | p->~T();
39 | ::memset((void*)p, 0, sizeof(T));
40 | m_free.push_back(p);
41 | }
42 |
43 | protected:
44 | list m_free;
45 | };
46 |
47 |
48 | }
49 |
50 | #endif
51 |
52 | //!
53 |
--------------------------------------------------------------------------------
/fflib/base/os_tool.h:
--------------------------------------------------------------------------------
1 | #ifndef _FF_OS_TOOL_H_
2 | #define _FF_OS_TOOL_H_
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include
11 | #include
12 | using namespace std;
13 |
14 | namespace ff
15 | {
16 |
17 | struct os_tool_t
18 | {
19 | static int ls(const string& path_, vector& ret_)
20 | {
21 | const char* dir = path_.c_str();
22 | DIR *dp;
23 | struct dirent *entry;
24 |
25 | if((dp = opendir(dir)) == NULL) {
26 | fprintf(stderr,"cannot open directory: %s\n", dir);
27 | return -1;
28 | }
29 |
30 | while((entry = readdir(dp)) != NULL) {
31 | if(strcmp(".",entry->d_name) == 0 || strcmp("..",entry->d_name) == 0)
32 | continue;
33 | ret_.push_back(entry->d_name);
34 | }
35 | closedir(dp);
36 | return 0;
37 | }
38 | static bool is_dir(const string& name_)
39 | {
40 | struct stat s;
41 | if(lstat(name_.c_str(), &s) < 0){
42 | return false;
43 | }
44 | return S_ISDIR(s.st_mode);
45 | }
46 | };
47 | }
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/fflib/base/signal_helper.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef _SIGNAL_HELPER_H_
3 | #define _SIGNAL_HELPER_H_
4 |
5 |
6 | #include
7 |
8 | #include