diff --git a/Makefile b/Makefile index 727af72198fd54b9a1e060e013f55a205aaad499..c9d328b2e3e1990fbdbc937c2d26af126c07ef39 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,17 @@ include build_env.mk -.PHONY: all clean distclean +.PHONY: all modules examples test clean distclean CCFLAGS := -Wall ifeq ($(RELEASE), 1) CCFLAGS += -O2 -Os else -CCFLAGS += -fsanitize=address -fno-omit-frame-pointer -DDEBUG=1 -O0 -ggdb +CCFLAGS += -DDEBUG=1 -O0 -ggdb +endif + +ifeq ($(ENABLE_ASAN), 1) +CCFLAGS += -fsanitize=address -fno-omit-frame-pointer LDFLAGS += -fsanitize=address -static-libasan endif @@ -21,13 +25,17 @@ CFLAGS := $(CCFLAGS) $(CFLAGS) APPS_DIR := $(PWD) export CC CXX CFLAGS CXXFLAGS LDFLAGS APPS_DIR +export MODULES include config.mk -all test: - @for i in $(app_y); do \ - [ ! -d $$i ] || $(MAKE) -C $$i $@ || exit $$? ; \ - done +all: modules + +modules examples: + $(MAKE) -C $@ + +test: + $(MAKE) -C modules test clean: -rm -rf $(OUTPUT_DIR) diff --git a/config.mk b/config.mk index 7b1b536f02301510d65097dc58c6bc13febc44f2..38a137d7bfd8116ced429a4b90f96de652a7dbdb 100644 --- a/config.mk +++ b/config.mk @@ -1,12 +1,11 @@ -app_y += base -app_y += util -app_y += event -app_y += eventx -app_y += log -app_y += network -app_y += http -app_y += coroutine -app_y += mqtt -app_y += terminal -app_y += main -app_y += sample +MODULES += base +MODULES += util +MODULES += event +MODULES += eventx +MODULES += log +MODULES += network +MODULES += http +MODULES += coroutine +MODULES += mqtt +MODULES += terminal +MODULES += main diff --git a/event/example/basic/.gitignore b/event/example/basic/.gitignore deleted file mode 100644 index 9613aa834bdc7df261acbdbd94816b332faf4387..0000000000000000000000000000000000000000 --- a/event/example/basic/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/*demo -/*_example diff --git a/event/example/basic/Makefile b/event/example/basic/Makefile deleted file mode 100644 index 06ad74fb60b898c1a0b6bc9534e3d8b288e56782..0000000000000000000000000000000000000000 --- a/event/example/basic/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -include ../build_env.mk - -TARGETS=io_example timer_example signal_example \ - run_in_loop_demo stdin_timer_signal_demo \ - run_next_seq_demo delay_delete_demo - -CXXFLAGS += -ggdb -#LDFLAGS += -ltbox_event -ltbox_base -levent_core -lev -lpthread -LDFLAGS += -ltbox_event -ltbox_base -lpthread - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all: $(TARGETS) - -stdin_timer_signal_demo : stdin_timer_signal_demo.o - $(CXX) -o $@ $^ $(LDFLAGS) - -run_in_loop_demo : run_in_loop_demo.o - $(CXX) -o $@ $^ $(LDFLAGS) - -run_next_seq_demo : run_next_seq_demo.o - $(CXX) -o $@ $^ $(LDFLAGS) - -timer_example : timer_example.o - $(CXX) -o $@ $^ $(LDFLAGS) - -signal_example : signal_example.o - $(CXX) -o $@ $^ $(LDFLAGS) - -io_example : io_example.o - $(CXX) -o $@ $^ $(LDFLAGS) - -delay_delete_demo : delay_delete_demo.o - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf *.o - -distclean : clean - rm $(TARGETS) - -install: - -uninstall: diff --git a/event/example/build_env.mk b/event/example/build_env.mk deleted file mode 100644 index 58481118dd79b3db71ee35ab91baf0bfe01358c0..0000000000000000000000000000000000000000 --- a/event/example/build_env.mk +++ /dev/null @@ -1,29 +0,0 @@ -STAGING_DIR := ../../../.staging - -STAGING_INCLUDE := $(STAGING_DIR)/include -STAGING_LIB := $(STAGING_DIR)/lib - -CCFLAGS := -I$(STAGING_INCLUDE) -I$(CONSTANT_INCLUDE) -CFLAGS := $(CCFLAGS) -std=c99 -CXXFLAGS := $(CCFLAGS) -std=c++11 -LDFLAGS := -L$(STAGING_LIB) -INSTALL_DIR := $(STAGING_DIR) -DESTDIR := $(STAGING_DIR) -prefix := - -TOOLCHAIN_PREFIX := -AR := $(TOOLCHAIN_PREFIX)ar -AS := $(TOOLCHAIN_PREFIX)as -CXX := $(TOOLCHAIN_PREFIX)g++ -CC := $(TOOLCHAIN_PREFIX)gcc -NM := $(TOOLCHAIN_PREFIX)nm -OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy -OBJDUMP := $(TOOLCHAIN_PREFIX)objdump -STRINGS := $(TOOLCHAIN_PREFIX)strings -SSTRIP := $(TOOLCHAIN_PREFIX)sstrip -LSTRIP := $(TOOLCHAIN_PREFIX)lstrip -STRIP := $(TOOLCHAIN_PREFIX)strip - -export STAGING_INCLUDE STAGING_LIB INSTALL_DIR DESTDIR prefix -export AR AS CC NM OBJCOPY OBJDUMP CXX STRIP SSTRIP STRINGS LSTRIP -export CFLAGS CXXFLAGS LDFLAGS diff --git a/event/example/calc_game/.gitignore b/event/example/calc_game/.gitignore deleted file mode 100644 index be7c9491699e4aaa5042501d337ab1db65a2369a..0000000000000000000000000000000000000000 --- a/event/example/calc_game/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/calc_game diff --git a/event/example/calc_game/Makefile b/event/example/calc_game/Makefile deleted file mode 100644 index 9a4eecb3d66a72f06521989438d4e7f1d17bd15d..0000000000000000000000000000000000000000 --- a/event/example/calc_game/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -include ../build_env.mk - -TARGET := calc_game -OBJECTS := main.o game.o game_lite.o -LDFLAGS += -L.. -ltbox_event -ltbox_base -levent_core -lev - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGET) - -$(TARGET) : $(OBJECTS) - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf $(OBJECTS) - -distclean: clean - rm -f $(TARGET) diff --git a/eventx/example/build_env.mk b/eventx/example/build_env.mk deleted file mode 100644 index 58481118dd79b3db71ee35ab91baf0bfe01358c0..0000000000000000000000000000000000000000 --- a/eventx/example/build_env.mk +++ /dev/null @@ -1,29 +0,0 @@ -STAGING_DIR := ../../../.staging - -STAGING_INCLUDE := $(STAGING_DIR)/include -STAGING_LIB := $(STAGING_DIR)/lib - -CCFLAGS := -I$(STAGING_INCLUDE) -I$(CONSTANT_INCLUDE) -CFLAGS := $(CCFLAGS) -std=c99 -CXXFLAGS := $(CCFLAGS) -std=c++11 -LDFLAGS := -L$(STAGING_LIB) -INSTALL_DIR := $(STAGING_DIR) -DESTDIR := $(STAGING_DIR) -prefix := - -TOOLCHAIN_PREFIX := -AR := $(TOOLCHAIN_PREFIX)ar -AS := $(TOOLCHAIN_PREFIX)as -CXX := $(TOOLCHAIN_PREFIX)g++ -CC := $(TOOLCHAIN_PREFIX)gcc -NM := $(TOOLCHAIN_PREFIX)nm -OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy -OBJDUMP := $(TOOLCHAIN_PREFIX)objdump -STRINGS := $(TOOLCHAIN_PREFIX)strings -SSTRIP := $(TOOLCHAIN_PREFIX)sstrip -LSTRIP := $(TOOLCHAIN_PREFIX)lstrip -STRIP := $(TOOLCHAIN_PREFIX)strip - -export STAGING_INCLUDE STAGING_LIB INSTALL_DIR DESTDIR prefix -export AR AS CC NM OBJCOPY OBJDUMP CXX STRIP SSTRIP STRINGS LSTRIP -export CFLAGS CXXFLAGS LDFLAGS diff --git a/eventx/example/thread-pool/.gitignore b/eventx/example/thread-pool/.gitignore deleted file mode 100644 index 69ff7396662e25b7bcacccf28267d6573e901777..0000000000000000000000000000000000000000 --- a/eventx/example/thread-pool/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/demo diff --git a/eventx/example/thread-pool/Makefile b/eventx/example/thread-pool/Makefile deleted file mode 100644 index e106c2a987356e5cd4cd07fe9b10c304fccb7d90..0000000000000000000000000000000000000000 --- a/eventx/example/thread-pool/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -include ../build_env.mk - -TARGET := demo -OBJECTS := main.o -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_eventx -ltbox_event -ltbox_base -levent_core -lev -lpthread - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGET) - -$(TARGET) : $(OBJECTS) - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf $(OBJECTS) diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..1b05fb46a7d6d9a29731b6119a8b6841927e469c --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,4 @@ +all test: + @for i in $(MODULES); do \ + [ ! -d $$i ] || $(MAKE) -C $$i $@ || exit $$? ; \ + done diff --git a/examples/event/01-io/Makefile b/examples/event/01-io/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..6341ab222ed6330c174513bdd2ba468c882f484e --- /dev/null +++ b/examples/event/01-io/Makefile @@ -0,0 +1,10 @@ +EXE_NAME := example/event/01-io + +CPP_SRC_FILES := main.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/event/example/basic/io_example.cpp b/examples/event/01-io/main.cpp similarity index 100% rename from event/example/basic/io_example.cpp rename to examples/event/01-io/main.cpp diff --git a/examples/event/02-timer/Makefile b/examples/event/02-timer/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..174e5d9141a94f9099cb3750cb0fe87b30863d8c --- /dev/null +++ b/examples/event/02-timer/Makefile @@ -0,0 +1,10 @@ +EXE_NAME := example/event/02-timer + +CPP_SRC_FILES := main.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/event/example/basic/timer_example.cpp b/examples/event/02-timer/main.cpp similarity index 100% rename from event/example/basic/timer_example.cpp rename to examples/event/02-timer/main.cpp diff --git a/examples/event/03-signal/Makefile b/examples/event/03-signal/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..14b436aa0acf8cd406b543c22d349778172ddfdb --- /dev/null +++ b/examples/event/03-signal/Makefile @@ -0,0 +1,10 @@ +EXE_NAME := example/event/03-signal + +CPP_SRC_FILES := main.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/event/example/basic/signal_example.cpp b/examples/event/03-signal/main.cpp similarity index 96% rename from event/example/basic/signal_example.cpp rename to examples/event/03-signal/main.cpp index b59942f730a5b654b7273da125549f8fe9339c06..1e64bde2cf89a5b28fd2edf163e3ad31e39c1bcd 100644 --- a/event/example/basic/signal_example.cpp +++ b/examples/event/03-signal/main.cpp @@ -7,7 +7,7 @@ using namespace std; using namespace tbox; using namespace tbox::event; -void SignalCallback() +void SignalCallback(int signo) { cout << "Got interupt signal" << endl; } diff --git a/examples/event/04-run-in-loop/Makefile b/examples/event/04-run-in-loop/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..2148b13d2607034db56a89eb8469a9cbd7723061 --- /dev/null +++ b/examples/event/04-run-in-loop/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/event/04-run-in-loop + +CPP_SRC_FILES := main.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_event \ + -ltbox_base \ + -lpthread \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/event/example/basic/run_in_loop_demo.cpp b/examples/event/04-run-in-loop/main.cpp similarity index 100% rename from event/example/basic/run_in_loop_demo.cpp rename to examples/event/04-run-in-loop/main.cpp diff --git a/examples/event/05-run-next-seq/Makefile b/examples/event/05-run-next-seq/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..c8b21baadb27b564652fe25164143ede8511d131 --- /dev/null +++ b/examples/event/05-run-next-seq/Makefile @@ -0,0 +1,10 @@ +EXE_NAME := example/event/05-run-next-seq + +CPP_SRC_FILES := main.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/event/example/basic/run_next_seq_demo.cpp b/examples/event/05-run-next-seq/main.cpp similarity index 100% rename from event/example/basic/run_next_seq_demo.cpp rename to examples/event/05-run-next-seq/main.cpp diff --git a/examples/event/06-stdin-timer-signal/Makefile b/examples/event/06-stdin-timer-signal/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..8f8f46bc40452f0d1d2b9ee161e45d8d7aa35af7 --- /dev/null +++ b/examples/event/06-stdin-timer-signal/Makefile @@ -0,0 +1,10 @@ +EXE_NAME := example/event/06-stdin-timer-signal + +CPP_SRC_FILES := main.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/event/example/basic/stdin_timer_signal_demo.cpp b/examples/event/06-stdin-timer-signal/main.cpp similarity index 100% rename from event/example/basic/stdin_timer_signal_demo.cpp rename to examples/event/06-stdin-timer-signal/main.cpp diff --git a/examples/event/07-delay-delete/Makefile b/examples/event/07-delay-delete/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..6c24cf73184510fbf7a97a3d428b5ae5ffb79838 --- /dev/null +++ b/examples/event/07-delay-delete/Makefile @@ -0,0 +1,10 @@ +EXE_NAME := example/event/07-delay-delete + +CPP_SRC_FILES := main.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/event/example/basic/delay_delete_demo.cpp b/examples/event/07-delay-delete/main.cpp similarity index 100% rename from event/example/basic/delay_delete_demo.cpp rename to examples/event/07-delay-delete/main.cpp diff --git a/examples/event/08-calc-game/Makefile b/examples/event/08-calc-game/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f98a4667539fc7116257ac7f3b49cef57898977f --- /dev/null +++ b/examples/event/08-calc-game/Makefile @@ -0,0 +1,12 @@ +EXE_NAME := example/event/08-calc-game + +CPP_SRC_FILES := \ + main.cpp \ + game.cpp \ + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/event/example/calc_game/game.cpp b/examples/event/08-calc-game/game.cpp similarity index 100% rename from event/example/calc_game/game.cpp rename to examples/event/08-calc-game/game.cpp diff --git a/event/example/calc_game/game.h b/examples/event/08-calc-game/game.h similarity index 100% rename from event/example/calc_game/game.h rename to examples/event/08-calc-game/game.h diff --git a/event/example/calc_game/game_lite.cpp b/examples/event/08-calc-game/game_lite.cpp similarity index 100% rename from event/example/calc_game/game_lite.cpp rename to examples/event/08-calc-game/game_lite.cpp diff --git a/event/example/calc_game/game_lite.h b/examples/event/08-calc-game/game_lite.h similarity index 100% rename from event/example/calc_game/game_lite.h rename to examples/event/08-calc-game/game_lite.h diff --git a/event/example/calc_game/main.cpp b/examples/event/08-calc-game/main.cpp similarity index 100% rename from event/example/calc_game/main.cpp rename to examples/event/08-calc-game/main.cpp diff --git a/examples/event/Makefile b/examples/event/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/event/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/eventx/Makefile b/examples/eventx/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/eventx/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/eventx/thread-pool/Makefile b/examples/eventx/thread-pool/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..eff9390d10f245b2ad068970eb07d0d660d9166e --- /dev/null +++ b/examples/eventx/thread-pool/Makefile @@ -0,0 +1,12 @@ +EXE_NAME := example/eventx/thread-pool + +CPP_SRC_FILES := main.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_eventx \ + -ltbox_event \ + -ltbox_base \ + -lpthread \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/eventx/example/thread-pool/main.cpp b/examples/eventx/thread-pool/main.cpp similarity index 100% rename from eventx/example/thread-pool/main.cpp rename to examples/eventx/thread-pool/main.cpp diff --git a/examples/http/Makefile b/examples/http/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/http/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/http/server/Makefile b/examples/http/server/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/http/server/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/http/server/async_respond/Makefile b/examples/http/server/async_respond/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..49f3f7978f19173a5b82f85dde7ba965afa553c1 --- /dev/null +++ b/examples/http/server/async_respond/Makefile @@ -0,0 +1,15 @@ +EXE_NAME := example/http/server/async_respond + +CPP_SRC_FILES := async_respond.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_http \ + -ltbox_network \ + -ltbox_eventx \ + -ltbox_event \ + -ltbox_log \ + -ltbox_util \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/http/example/server/async_respond.cpp b/examples/http/server/async_respond/async_respond.cpp similarity index 100% rename from http/example/server/async_respond.cpp rename to examples/http/server/async_respond/async_respond.cpp diff --git a/examples/http/server/router/Makefile b/examples/http/server/router/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..4d71f20fb4f954296f037717c6cc9b38424c68ab --- /dev/null +++ b/examples/http/server/router/Makefile @@ -0,0 +1,15 @@ +EXE_NAME := example/http/server/router + +CPP_SRC_FILES := router.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_http \ + -ltbox_network \ + -ltbox_eventx \ + -ltbox_event \ + -ltbox_log \ + -ltbox_util \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/http/example/server/router.cpp b/examples/http/server/router/router.cpp similarity index 100% rename from http/example/server/router.cpp rename to examples/http/server/router/router.cpp diff --git a/examples/http/server/simple/Makefile b/examples/http/server/simple/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..91df7aa333538b596144d2795bec14ca8fee5053 --- /dev/null +++ b/examples/http/server/simple/Makefile @@ -0,0 +1,15 @@ +EXE_NAME := example/http/server/simple + +CPP_SRC_FILES := simple.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_http \ + -ltbox_network \ + -ltbox_eventx \ + -ltbox_event \ + -ltbox_log \ + -ltbox_util \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/http/example/server/simple.cpp b/examples/http/server/simple/simple.cpp similarity index 100% rename from http/example/server/simple.cpp rename to examples/http/server/simple/simple.cpp diff --git a/examples/main/00_empty/Makefile b/examples/main/00_empty/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..6ac3306f2ee49546e15e12537ed5af1ca163865e --- /dev/null +++ b/examples/main/00_empty/Makefile @@ -0,0 +1,18 @@ +EXE_NAME := example/main/00_empty + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_main \ + -ltbox_terminal \ + -ltbox_network \ + -ltbox_eventx \ + -ltbox_eventx \ + -ltbox_event \ + -ltbox_log \ + -ltbox_util \ + -ltbox_base \ + -lpthread \ + -ldl \ + -rdynamic + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/examples/main/01_one_app/Makefile b/examples/main/01_one_app/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..0206ff7a4e557c55aecbeb5f17b5efcccb8cd879 --- /dev/null +++ b/examples/main/01_one_app/Makefile @@ -0,0 +1,22 @@ +EXE_NAME := example/main/01_one_app + +CPP_SRC_FILES = \ + app.cpp \ + main.cpp \ + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_main \ + -ltbox_terminal \ + -ltbox_network \ + -ltbox_eventx \ + -ltbox_eventx \ + -ltbox_event \ + -ltbox_log \ + -ltbox_util \ + -ltbox_base \ + -lpthread \ + -ldl \ + -rdynamic + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/main/example/01_one_app/app.cpp b/examples/main/01_one_app/app.cpp similarity index 100% rename from main/example/01_one_app/app.cpp rename to examples/main/01_one_app/app.cpp diff --git a/main/example/01_one_app/app.h b/examples/main/01_one_app/app.h similarity index 100% rename from main/example/01_one_app/app.h rename to examples/main/01_one_app/app.h diff --git a/main/example/01_one_app/main.cpp b/examples/main/01_one_app/main.cpp similarity index 100% rename from main/example/01_one_app/main.cpp rename to examples/main/01_one_app/main.cpp diff --git a/main/example/02_more_than_one_apps/Makefile b/examples/main/02_more_than_one_apps/Makefile similarity index 32% rename from main/example/02_more_than_one_apps/Makefile rename to examples/main/02_more_than_one_apps/Makefile index 92b8ff5af6fa254db2d3c33cf4689f85e3bb3a54..e42e8b602975c0919623ef1a94dc2d1fe063bf90 100644 --- a/main/example/02_more_than_one_apps/Makefile +++ b/examples/main/02_more_than_one_apps/Makefile @@ -1,36 +1,25 @@ -include ../build_env.mk +EXE_NAME := example/main/02_more_than_one_apps -.PHONY : all clean distclean +CPP_SRC_FILES = \ + main.cpp \ -TARGET := sample -OBJECTS := main.o - -include app1/app.mk -include app2/app.mk -include app3/app.mk - -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. \ +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ -ltbox_main \ - -ltbox_log \ -ltbox_terminal \ -ltbox_network \ -ltbox_eventx \ + -ltbox_eventx \ -ltbox_event \ + -ltbox_log \ -ltbox_util \ -ltbox_base \ - -lpthread - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGET) - -$(TARGET): $(OBJECTS) - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) + -lpthread \ + -ldl \ + -rdynamic -clean: - rm -rf $(OBJECTS) +include app1/app.mk +include app2/app.mk +include app3/app.mk -distclean: clean - rm -rf $(TARGET) +include ${TOP_DIR}/tools/exe_common.mk diff --git a/main/example/02_more_than_one_apps/app1/app.cpp b/examples/main/02_more_than_one_apps/app1/app.cpp similarity index 100% rename from main/example/02_more_than_one_apps/app1/app.cpp rename to examples/main/02_more_than_one_apps/app1/app.cpp diff --git a/main/example/02_more_than_one_apps/app1/app.h b/examples/main/02_more_than_one_apps/app1/app.h similarity index 100% rename from main/example/02_more_than_one_apps/app1/app.h rename to examples/main/02_more_than_one_apps/app1/app.h diff --git a/examples/main/02_more_than_one_apps/app1/app.mk b/examples/main/02_more_than_one_apps/app1/app.mk new file mode 100644 index 0000000000000000000000000000000000000000..8c1e5b03229e5169f481a372a64901efc7e6c296 --- /dev/null +++ b/examples/main/02_more_than_one_apps/app1/app.mk @@ -0,0 +1,3 @@ +CPP_SRC_FILES += \ + app1/app.cpp \ + app1/sub.cpp \ diff --git a/main/example/02_more_than_one_apps/app1/sub.cpp b/examples/main/02_more_than_one_apps/app1/sub.cpp similarity index 100% rename from main/example/02_more_than_one_apps/app1/sub.cpp rename to examples/main/02_more_than_one_apps/app1/sub.cpp diff --git a/main/example/02_more_than_one_apps/app1/sub.h b/examples/main/02_more_than_one_apps/app1/sub.h similarity index 100% rename from main/example/02_more_than_one_apps/app1/sub.h rename to examples/main/02_more_than_one_apps/app1/sub.h diff --git a/main/example/02_more_than_one_apps/app2/app.cpp b/examples/main/02_more_than_one_apps/app2/app.cpp similarity index 100% rename from main/example/02_more_than_one_apps/app2/app.cpp rename to examples/main/02_more_than_one_apps/app2/app.cpp diff --git a/main/example/02_more_than_one_apps/app2/app.h b/examples/main/02_more_than_one_apps/app2/app.h similarity index 100% rename from main/example/02_more_than_one_apps/app2/app.h rename to examples/main/02_more_than_one_apps/app2/app.h diff --git a/examples/main/02_more_than_one_apps/app2/app.mk b/examples/main/02_more_than_one_apps/app2/app.mk new file mode 100644 index 0000000000000000000000000000000000000000..0647038be4fe8fc6e0ce683908fa932d8d4106aa --- /dev/null +++ b/examples/main/02_more_than_one_apps/app2/app.mk @@ -0,0 +1,2 @@ +CPP_SRC_FILES += \ + app2/app.cpp \ diff --git a/main/example/02_more_than_one_apps/app3/app.cpp b/examples/main/02_more_than_one_apps/app3/app.cpp similarity index 100% rename from main/example/02_more_than_one_apps/app3/app.cpp rename to examples/main/02_more_than_one_apps/app3/app.cpp diff --git a/main/example/02_more_than_one_apps/app3/app.h b/examples/main/02_more_than_one_apps/app3/app.h similarity index 100% rename from main/example/02_more_than_one_apps/app3/app.h rename to examples/main/02_more_than_one_apps/app3/app.h diff --git a/examples/main/02_more_than_one_apps/app3/app.mk b/examples/main/02_more_than_one_apps/app3/app.mk new file mode 100644 index 0000000000000000000000000000000000000000..6aaae2b07c2fbe4bb33c489c3f11cf34bc8780d3 --- /dev/null +++ b/examples/main/02_more_than_one_apps/app3/app.mk @@ -0,0 +1,2 @@ +CPP_SRC_FILES += \ + app3/app.cpp \ diff --git a/main/example/02_more_than_one_apps/main.cpp b/examples/main/02_more_than_one_apps/main.cpp similarity index 100% rename from main/example/02_more_than_one_apps/main.cpp rename to examples/main/02_more_than_one_apps/main.cpp diff --git a/main/example/03_nc_client_and_echo_server/Makefile b/examples/main/03_nc_client_and_echo_server/Makefile similarity index 31% rename from main/example/03_nc_client_and_echo_server/Makefile rename to examples/main/03_nc_client_and_echo_server/Makefile index 3b9206c5eaafeca2165a9173c454c8402f0d8eae..0b1046148f7280b244dde68f92bc3e5de0d6d63c 100644 --- a/main/example/03_nc_client_and_echo_server/Makefile +++ b/examples/main/03_nc_client_and_echo_server/Makefile @@ -1,35 +1,24 @@ -include ../build_env.mk +EXE_NAME := example/main/03_nc_client_and_echo_server -.PHONY : all clean distclean +CPP_SRC_FILES = \ + main.cpp \ -TARGET := sample -OBJECTS := main.o - -include nc_client/app.mk -include echo_server/app.mk - -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. \ +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ -ltbox_main \ - -ltbox_log \ -ltbox_terminal \ -ltbox_network \ -ltbox_eventx \ + -ltbox_eventx \ -ltbox_event \ + -ltbox_log \ -ltbox_util \ -ltbox_base \ - -lpthread - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGET) + -lpthread \ + -ldl \ + -rdynamic -$(TARGET): $(OBJECTS) - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) - -clean: - rm -rf $(OBJECTS) +include echo_server/app.mk +include nc_client/app.mk -distclean: clean - rm -rf $(TARGET) +include ${TOP_DIR}/tools/exe_common.mk diff --git a/main/example/03_nc_client_and_echo_server/README.md b/examples/main/03_nc_client_and_echo_server/README.md similarity index 100% rename from main/example/03_nc_client_and_echo_server/README.md rename to examples/main/03_nc_client_and_echo_server/README.md diff --git a/main/example/03_nc_client_and_echo_server/echo_server/app.cpp b/examples/main/03_nc_client_and_echo_server/echo_server/app.cpp similarity index 100% rename from main/example/03_nc_client_and_echo_server/echo_server/app.cpp rename to examples/main/03_nc_client_and_echo_server/echo_server/app.cpp diff --git a/main/example/03_nc_client_and_echo_server/echo_server/app.h b/examples/main/03_nc_client_and_echo_server/echo_server/app.h similarity index 100% rename from main/example/03_nc_client_and_echo_server/echo_server/app.h rename to examples/main/03_nc_client_and_echo_server/echo_server/app.h diff --git a/main/example/03_nc_client_and_echo_server/echo_server/app.mk b/examples/main/03_nc_client_and_echo_server/echo_server/app.mk similarity index 41% rename from main/example/03_nc_client_and_echo_server/echo_server/app.mk rename to examples/main/03_nc_client_and_echo_server/echo_server/app.mk index 04bddb88b6f8dd32ca1dd8c2b1999eca981ff1aa..1ee8975a259d1ea7cd71d5cd2e0cce9597717ef3 100644 --- a/main/example/03_nc_client_and_echo_server/echo_server/app.mk +++ b/examples/main/03_nc_client_and_echo_server/echo_server/app.mk @@ -1,2 +1,2 @@ -OBJECTS += echo_server/app.o +CPP_SRC_FILES += echo_server/app.cpp LDFLAGS += -ltbox_network diff --git a/main/example/03_nc_client_and_echo_server/main.cpp b/examples/main/03_nc_client_and_echo_server/main.cpp similarity index 100% rename from main/example/03_nc_client_and_echo_server/main.cpp rename to examples/main/03_nc_client_and_echo_server/main.cpp diff --git a/main/example/03_nc_client_and_echo_server/nc_client/app.cpp b/examples/main/03_nc_client_and_echo_server/nc_client/app.cpp similarity index 100% rename from main/example/03_nc_client_and_echo_server/nc_client/app.cpp rename to examples/main/03_nc_client_and_echo_server/nc_client/app.cpp diff --git a/main/example/03_nc_client_and_echo_server/nc_client/app.h b/examples/main/03_nc_client_and_echo_server/nc_client/app.h similarity index 100% rename from main/example/03_nc_client_and_echo_server/nc_client/app.h rename to examples/main/03_nc_client_and_echo_server/nc_client/app.h diff --git a/main/example/03_nc_client_and_echo_server/nc_client/app.mk b/examples/main/03_nc_client_and_echo_server/nc_client/app.mk similarity index 42% rename from main/example/03_nc_client_and_echo_server/nc_client/app.mk rename to examples/main/03_nc_client_and_echo_server/nc_client/app.mk index f857239c904bae918aa3d8afe9e0849c330dddf8..948c4056b80bdec1d4b44345a082e87ea25e2a82 100644 --- a/main/example/03_nc_client_and_echo_server/nc_client/app.mk +++ b/examples/main/03_nc_client_and_echo_server/nc_client/app.mk @@ -1,2 +1,2 @@ -OBJECTS += nc_client/app.o +CPP_SRC_FILES += nc_client/app.cpp LDFLAGS += -ltbox_network diff --git a/examples/main/04_initiate_runtime_error/Makefile b/examples/main/04_initiate_runtime_error/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..0111078a9c18153658d870b46dd9a9cc0bed9f98 --- /dev/null +++ b/examples/main/04_initiate_runtime_error/Makefile @@ -0,0 +1,21 @@ +EXE_NAME := example/main/04_initiate_runtime_error + +CPP_SRC_FILES = \ + main.cpp \ + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_main \ + -ltbox_terminal \ + -ltbox_network \ + -ltbox_eventx \ + -ltbox_eventx \ + -ltbox_event \ + -ltbox_log \ + -ltbox_util \ + -ltbox_base \ + -lpthread \ + -ldl \ + -rdynamic + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/main/example/04_initiate_runtime_error/README.txt b/examples/main/04_initiate_runtime_error/README.txt similarity index 100% rename from main/example/04_initiate_runtime_error/README.txt rename to examples/main/04_initiate_runtime_error/README.txt diff --git a/main/example/04_initiate_runtime_error/main.cpp b/examples/main/04_initiate_runtime_error/main.cpp similarity index 100% rename from main/example/04_initiate_runtime_error/main.cpp rename to examples/main/04_initiate_runtime_error/main.cpp diff --git a/examples/main/Makefile b/examples/main/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/main/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/main/example/README.md b/examples/main/README.md similarity index 100% rename from main/example/README.md rename to examples/main/README.md diff --git a/sample/Makefile b/examples/main/sample/Makefile similarity index 91% rename from sample/Makefile rename to examples/main/sample/Makefile index b22e4d3f66fcba8580415077ebd24d413c29f2c4..2e338345f1b92ffcaa6d6139591cef8826134a03 100644 --- a/sample/Makefile +++ b/examples/main/sample/Makefile @@ -21,6 +21,7 @@ LDFLAGS += \ -ltbox_util \ -ltbox_base \ -lpthread \ + -ldl \ -rdynamic TEST_LDFLAGS += $(LDFLAGS) @@ -28,4 +29,4 @@ TEST_LDFLAGS += $(LDFLAGS) pre_build : touch build_time.cpp -include ../tools/exe_common.mk +include $(TOP_DIR)/tools/exe_common.mk diff --git a/sample/README.md b/examples/main/sample/README.md similarity index 100% rename from sample/README.md rename to examples/main/sample/README.md diff --git a/sample/app1/app.cpp b/examples/main/sample/app1/app.cpp similarity index 100% rename from sample/app1/app.cpp rename to examples/main/sample/app1/app.cpp diff --git a/sample/app1/app.h b/examples/main/sample/app1/app.h similarity index 100% rename from sample/app1/app.h rename to examples/main/sample/app1/app.h diff --git a/sample/app1/app.mk b/examples/main/sample/app1/app.mk similarity index 100% rename from sample/app1/app.mk rename to examples/main/sample/app1/app.mk diff --git a/sample/app2/app.cpp b/examples/main/sample/app2/app.cpp similarity index 100% rename from sample/app2/app.cpp rename to examples/main/sample/app2/app.cpp diff --git a/sample/app2/app.h b/examples/main/sample/app2/app.h similarity index 100% rename from sample/app2/app.h rename to examples/main/sample/app2/app.h diff --git a/sample/app2/app.mk b/examples/main/sample/app2/app.mk similarity index 100% rename from sample/app2/app.mk rename to examples/main/sample/app2/app.mk diff --git a/sample/app_main.cpp b/examples/main/sample/app_main.cpp similarity index 100% rename from sample/app_main.cpp rename to examples/main/sample/app_main.cpp diff --git a/sample/build_time.cpp b/examples/main/sample/build_time.cpp similarity index 100% rename from sample/build_time.cpp rename to examples/main/sample/build_time.cpp diff --git a/sample/default.conf b/examples/main/sample/default.conf similarity index 100% rename from sample/default.conf rename to examples/main/sample/default.conf diff --git a/examples/mqtt/Makefile b/examples/mqtt/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/mqtt/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/mqtt/conn/Makefile b/examples/mqtt/conn/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..ba1ac102b11bb0f8cef42c91bb9f88a254cf0dfa --- /dev/null +++ b/examples/mqtt/conn/Makefile @@ -0,0 +1,13 @@ +EXE_NAME := example/mqtt/conn + +CPP_SRC_FILES := conn.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_mqtt \ + -ltbox_event \ + -ltbox_base \ + -lmosquitto \ + -lpthread \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/mqtt/example/basic/conn.cpp b/examples/mqtt/conn/conn.cpp similarity index 97% rename from mqtt/example/basic/conn.cpp rename to examples/mqtt/conn/conn.cpp index f5f409aa38ef452c88608b1fb00d06b2f0ceaaf3..68974f42e9f16fdd1454df84b88f5607c26db1c5 100644 --- a/mqtt/example/basic/conn.cpp +++ b/examples/mqtt/conn/conn.cpp @@ -51,7 +51,7 @@ int main(int argc, char **argv) stop_ev->initialize(SIGINT, Event::Mode::kOneshot); stop_ev->enable(); stop_ev->setCallback( - [sp_loop, &mqtt] { + [sp_loop, &mqtt] (int) { mqtt.stop(); sp_loop->exitLoop(); } diff --git a/examples/mqtt/pub/Makefile b/examples/mqtt/pub/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..44b2136b818fb1a16b83bce4c17f266be55690ca --- /dev/null +++ b/examples/mqtt/pub/Makefile @@ -0,0 +1,13 @@ +EXE_NAME := example/mqtt/pub + +CPP_SRC_FILES := pub.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_mqtt \ + -ltbox_event \ + -ltbox_base \ + -lmosquitto \ + -lpthread \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/mqtt/example/basic/pub.cpp b/examples/mqtt/pub/pub.cpp similarity index 100% rename from mqtt/example/basic/pub.cpp rename to examples/mqtt/pub/pub.cpp diff --git a/examples/mqtt/sub/Makefile b/examples/mqtt/sub/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f1bda80d14b9ef8347b4473feff509649d811e48 --- /dev/null +++ b/examples/mqtt/sub/Makefile @@ -0,0 +1,13 @@ +EXE_NAME := example/mqtt/sub + +CPP_SRC_FILES := sub.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_mqtt \ + -ltbox_event \ + -ltbox_base \ + -lmosquitto \ + -lpthread \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/mqtt/example/basic/sub.cpp b/examples/mqtt/sub/sub.cpp similarity index 98% rename from mqtt/example/basic/sub.cpp rename to examples/mqtt/sub/sub.cpp index 5f34f5f020725a96faf49a5be07e32281afbc747..28792427e1dcbc19944522842e031dff1b6aab70 100644 --- a/mqtt/example/basic/sub.cpp +++ b/examples/mqtt/sub/sub.cpp @@ -58,7 +58,7 @@ int main(int argc, char **argv) stop_ev->initialize(SIGINT, Event::Mode::kOneshot); stop_ev->enable(); stop_ev->setCallback( - [sp_loop, &mqtt] { + [sp_loop, &mqtt] (int) { mqtt.stop(); sp_loop->exitLoop(); } diff --git a/examples/network/Makefile b/examples/network/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/network/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/network/buffered_fd/Makefile b/examples/network/buffered_fd/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f28b8aace46a5e567c2ff0e706575f18f608cf70 --- /dev/null +++ b/examples/network/buffered_fd/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/01-io-echo + +CPP_SRC_FILES := io_echo.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/buffered_fd/io_echo.cpp b/examples/network/buffered_fd/io_echo.cpp similarity index 98% rename from network/example/buffered_fd/io_echo.cpp rename to examples/network/buffered_fd/io_echo.cpp index d2d974c197dfaa04d749c8b45231d8e27f07186e..55f39d2f68637302e803d6ecfa5a2fb4219af843 100644 --- a/network/example/buffered_fd/io_echo.cpp +++ b/examples/network/buffered_fd/io_echo.cpp @@ -26,7 +26,7 @@ int main() auto sp_exit = sp_loop->newSignalEvent(); sp_exit->initialize(SIGINT, event::Event::Mode::kOneshot); sp_exit->setCallback( - [=] { + [=] (int) { cout << "Info: Exit Loop" << endl; sp_loop->exitLoop(); } diff --git a/examples/network/stdio_stream/01-stdin-out/Makefile b/examples/network/stdio_stream/01-stdin-out/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..67792069579c112aec8a31bcd53ff6852b5cbd6a --- /dev/null +++ b/examples/network/stdio_stream/01-stdin-out/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/stdio_stream/01-stdin-out + +CPP_SRC_FILES := main.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/stdio_stream/io_echo_1.cpp b/examples/network/stdio_stream/01-stdin-out/main.cpp similarity index 97% rename from network/example/stdio_stream/io_echo_1.cpp rename to examples/network/stdio_stream/01-stdin-out/main.cpp index 2ea763cd2ba472fc0c0da2db869cf7117e7e4e73..7b1cc8f4a9ba03760038bf3bc9873da121aba956 100644 --- a/network/example/stdio_stream/io_echo_1.cpp +++ b/examples/network/stdio_stream/01-stdin-out/main.cpp @@ -21,7 +21,7 @@ int main() auto sp_exit = sp_loop->newSignalEvent(); sp_exit->initialize(SIGINT, event::Event::Mode::kOneshot); sp_exit->setCallback( - [=] { + [=] (int) { cout << "Info: Exit Loop" << endl; sp_loop->exitLoop(); } diff --git a/examples/network/stdio_stream/02-stdio/Makefile b/examples/network/stdio_stream/02-stdio/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..0afe82601b4e971f7886568c7a4841cf7297573f --- /dev/null +++ b/examples/network/stdio_stream/02-stdio/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/stdio_stream/02-stdio + +CPP_SRC_FILES := main.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/stdio_stream/io_echo_2.cpp b/examples/network/stdio_stream/02-stdio/main.cpp similarity index 97% rename from network/example/stdio_stream/io_echo_2.cpp rename to examples/network/stdio_stream/02-stdio/main.cpp index c19a353b0e0d44f7a8748214efc6b09ec8323dca..4a48389c4691c441e755d8b64cfe588f33b67140 100644 --- a/network/example/stdio_stream/io_echo_2.cpp +++ b/examples/network/stdio_stream/02-stdio/main.cpp @@ -18,7 +18,7 @@ int main() auto sp_exit = sp_loop->newSignalEvent(); sp_exit->initialize(SIGINT, event::Event::Mode::kOneshot); sp_exit->setCallback( - [=] { + [=] (int) { cout << "Info: Exit Loop" << endl; sp_loop->exitLoop(); } diff --git a/examples/network/stdio_stream/Makefile b/examples/network/stdio_stream/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/network/stdio_stream/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/network/tcp_acceptor/Makefile b/examples/network/tcp_acceptor/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/network/tcp_acceptor/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/network/tcp_acceptor/tcp_echo/Makefile b/examples/network/tcp_acceptor/tcp_echo/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..9d27e9832b918701bf798ad48bb0fc767d43269f --- /dev/null +++ b/examples/network/tcp_acceptor/tcp_echo/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/tcp_acceptor/tcp_echo + +CPP_SRC_FILES := tcp_echo.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/tcp_acceptor/tcp_echo.cpp b/examples/network/tcp_acceptor/tcp_echo/tcp_echo.cpp similarity index 97% rename from network/example/tcp_acceptor/tcp_echo.cpp rename to examples/network/tcp_acceptor/tcp_echo/tcp_echo.cpp index f668b03d77448a4748a15a28317a3ab7c97b011b..f13af595f057c5939ba5c0ad14ef07c669d26d36 100644 --- a/network/example/tcp_acceptor/tcp_echo.cpp +++ b/examples/network/tcp_acceptor/tcp_echo/tcp_echo.cpp @@ -44,7 +44,7 @@ int main(int argc, char **argv) set conns; TcpAcceptor acceptor(sp_loop); - acceptor.initialize(bind_addr); + acceptor.initialize(bind_addr, 1); //! 指定有Client连接上了该做的事务 acceptor.setNewConnectionCallback( [&] (TcpConnection *new_conn) { @@ -67,7 +67,7 @@ int main(int argc, char **argv) sp_stop_ev->initialize(SIGINT, Event::Mode::kOneshot); //! 指定ctrl+C时要做的事务 sp_stop_ev->setCallback( - [sp_loop, &conns] { + [sp_loop, &conns] (int) { for (auto conn : conns) { conn->disconnect(); //! (1) 主动断开连接 delete conn; //! (2) 销毁Client对象。思考:为什么这里可以直接delete,而L51不可以? diff --git a/examples/network/tcp_acceptor/tcp_nc_server/Makefile b/examples/network/tcp_acceptor/tcp_nc_server/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..07074bef77fe4edfb3c813e0112adbfc5507d333 --- /dev/null +++ b/examples/network/tcp_acceptor/tcp_nc_server/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/tcp_acceptor/tcp_nc_server + +CPP_SRC_FILES := tcp_nc_server.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/tcp_acceptor/tcp_nc_server.cpp b/examples/network/tcp_acceptor/tcp_nc_server/tcp_nc_server.cpp similarity index 97% rename from network/example/tcp_acceptor/tcp_nc_server.cpp rename to examples/network/tcp_acceptor/tcp_nc_server/tcp_nc_server.cpp index 683eb080caca6742056b9998549a28b9ad7e8300..fffa0c33ce197a93a1190262569256b41cc178db 100644 --- a/network/example/tcp_acceptor/tcp_nc_server.cpp +++ b/examples/network/tcp_acceptor/tcp_nc_server/tcp_nc_server.cpp @@ -56,7 +56,7 @@ int main(int argc, char **argv) ); TcpAcceptor acceptor(sp_loop); - acceptor.initialize(bind_addr); + acceptor.initialize(bind_addr, 1); //! 指定有Client连接上了该做的事务 acceptor.setNewConnectionCallback( [&] (TcpConnection *new_conn) { @@ -79,7 +79,7 @@ int main(int argc, char **argv) sp_stop_ev->initialize(SIGINT, Event::Mode::kOneshot); //! 指定ctrl+C时要做的事务 sp_stop_ev->setCallback( - [sp_loop, &conns] { + [sp_loop, &conns] (int) { for (auto conn : conns) { conn->disconnect(); //! (1) 主动断开连接 delete conn; //! (2) 销毁Client对象。思考:为什么这里可以直接delete,而L51不可以? diff --git a/examples/network/tcp_client/Makefile b/examples/network/tcp_client/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/network/tcp_client/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/network/tcp_client/tcp_echo/Makefile b/examples/network/tcp_client/tcp_echo/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..82c1492c608c5ec222dea7401d4e1dee7691fa3a --- /dev/null +++ b/examples/network/tcp_client/tcp_echo/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/tcp_client/tcp_echo + +CPP_SRC_FILES := tcp_echo.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/tcp_client/tcp_echo.cpp b/examples/network/tcp_client/tcp_echo/tcp_echo.cpp similarity index 98% rename from network/example/tcp_client/tcp_echo.cpp rename to examples/network/tcp_client/tcp_echo/tcp_echo.cpp index c88d57075eb85d8d283f8eb694ba9fa73a6af09d..a572cb038403c3ece8c46ee5f57d7434a147fc5c 100644 --- a/network/example/tcp_client/tcp_echo.cpp +++ b/examples/network/tcp_client/tcp_echo/tcp_echo.cpp @@ -51,7 +51,7 @@ int main(int argc, char **argv) sp_stop_ev->initialize(SIGINT, Event::Mode::kOneshot); //! 指定ctrl+C时要做的事务 sp_stop_ev->setCallback( - [sp_loop, &client] { + [sp_loop, &client] (int) { client.stop(); sp_loop->exitLoop(); //! (3) 退出事件循环 } diff --git a/examples/network/tcp_client/tcp_hex_client/Makefile b/examples/network/tcp_client/tcp_hex_client/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..32e11beeae73d88b34bd25383cbd7a8e216d72e4 --- /dev/null +++ b/examples/network/tcp_client/tcp_hex_client/Makefile @@ -0,0 +1,12 @@ +EXE_NAME := example/network/tcp_client/tcp_hex_client + +CPP_SRC_FILES := tcp_hex_client.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_util \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/tcp_client/tcp_hex_client.cpp b/examples/network/tcp_client/tcp_hex_client/tcp_hex_client.cpp similarity index 99% rename from network/example/tcp_client/tcp_hex_client.cpp rename to examples/network/tcp_client/tcp_hex_client/tcp_hex_client.cpp index 0ca51914c73b05e6a96ea40d2372b7887fc1d0dd..717e6eaaecb35218b5ecd67dcbc06625d6d7367b 100644 --- a/network/example/tcp_client/tcp_hex_client.cpp +++ b/examples/network/tcp_client/tcp_hex_client/tcp_hex_client.cpp @@ -123,7 +123,7 @@ int main(int argc, char **argv) sp_stop_ev->initialize(SIGINT, Event::Mode::kOneshot); //! 指定ctrl+C时要做的事务 sp_stop_ev->setCallback( - [sp_loop, &client] { + [sp_loop, &client] (int) { client.stop(); sp_loop->exitLoop(); //! (3) 退出事件循环 } diff --git a/examples/network/tcp_client/tcp_nc_client/Makefile b/examples/network/tcp_client/tcp_nc_client/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..ac14ce359d1b0f49c64bf3a53fe23b60530603f8 --- /dev/null +++ b/examples/network/tcp_client/tcp_nc_client/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/tcp_client/tcp_nc_client + +CPP_SRC_FILES := tcp_nc_client.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/tcp_client/tcp_nc_client.cpp b/examples/network/tcp_client/tcp_nc_client/tcp_nc_client.cpp similarity index 98% rename from network/example/tcp_client/tcp_nc_client.cpp rename to examples/network/tcp_client/tcp_nc_client/tcp_nc_client.cpp index 0310c925bcc1fedaed11c3f39d0d93e47bb33545..8ff0024b37d8eb64ff04c21f58bc2ff91496943c 100644 --- a/network/example/tcp_client/tcp_nc_client.cpp +++ b/examples/network/tcp_client/tcp_nc_client/tcp_nc_client.cpp @@ -57,7 +57,7 @@ int main(int argc, char **argv) sp_stop_ev->initialize(SIGINT, Event::Mode::kOneshot); //! 指定ctrl+C时要做的事务 sp_stop_ev->setCallback( - [sp_loop, &client] { + [sp_loop, &client] (int) { client.stop(); sp_loop->exitLoop(); //! (3) 退出事件循环 } diff --git a/examples/network/tcp_connector/Makefile b/examples/network/tcp_connector/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/network/tcp_connector/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/network/tcp_connector/tcp_echo/Makefile b/examples/network/tcp_connector/tcp_echo/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d5144c8d20e3b31c18101c60c8b083c03dd9f0f9 --- /dev/null +++ b/examples/network/tcp_connector/tcp_echo/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/tcp_connector/tcp_echo + +CPP_SRC_FILES := tcp_echo.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/tcp_connector/tcp_echo.cpp b/examples/network/tcp_connector/tcp_echo/tcp_echo.cpp similarity index 98% rename from network/example/tcp_connector/tcp_echo.cpp rename to examples/network/tcp_connector/tcp_echo/tcp_echo.cpp index bacabc88e0dd9af34b7a1841e9c8ff533178684a..31f26234eda8b9af1deb5849d9abe562245d46df 100644 --- a/network/example/tcp_connector/tcp_echo.cpp +++ b/examples/network/tcp_connector/tcp_echo/tcp_echo.cpp @@ -89,7 +89,7 @@ int main(int argc, char **argv) sp_stop_ev->initialize(SIGINT, Event::Mode::kOneshot); //! 指定ctrl+C时要做的事务 sp_stop_ev->setCallback( - [sp_loop, &sp_curr] { + [sp_loop, &sp_curr] (int) { if (sp_curr != nullptr) { sp_curr->disconnect(); //! (1) 主动断开连接 delete sp_curr; //! (2) 销毁Client对象。思考:为什么这里可以直接delete,而L51不可以? diff --git a/examples/network/tcp_connector/tcp_nc_client/Makefile b/examples/network/tcp_connector/tcp_nc_client/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..0140305a30a2b75b5d2569b478e312cf92ec7151 --- /dev/null +++ b/examples/network/tcp_connector/tcp_nc_client/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/tcp_connector/tcp_nc_client + +CPP_SRC_FILES := tcp_nc_client.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/tcp_connector/tcp_nc_client.cpp b/examples/network/tcp_connector/tcp_nc_client/tcp_nc_client.cpp similarity index 98% rename from network/example/tcp_connector/tcp_nc_client.cpp rename to examples/network/tcp_connector/tcp_nc_client/tcp_nc_client.cpp index 954f9c954d6545c87ab9c37c0368f55b80ab3b5d..b5494161aad40657fba76fe829ac9cf793ed1778 100644 --- a/network/example/tcp_connector/tcp_nc_client.cpp +++ b/examples/network/tcp_connector/tcp_nc_client/tcp_nc_client.cpp @@ -94,7 +94,7 @@ int main(int argc, char **argv) sp_stop_ev->initialize(SIGINT, Event::Mode::kOneshot); //! 指定ctrl+C时要做的事务 sp_stop_ev->setCallback( - [sp_loop, &sp_curr] { + [sp_loop, &sp_curr] (int) { if (sp_curr != nullptr) { sp_curr->disconnect(); //! (1) 主动断开连接 delete sp_curr; //! (2) 销毁Client对象。思考:为什么这里可以直接delete,而L51不可以? diff --git a/examples/network/tcp_server/Makefile b/examples/network/tcp_server/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/network/tcp_server/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/network/tcp_server/tcp_echo/Makefile b/examples/network/tcp_server/tcp_echo/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f1ea2eb479ff244056d7a8c54eb0b27c2f60172a --- /dev/null +++ b/examples/network/tcp_server/tcp_echo/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/tcp_server/tcp_echo + +CPP_SRC_FILES := tcp_echo.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/tcp_server/tcp_echo.cpp b/examples/network/tcp_server/tcp_echo/tcp_echo.cpp similarity index 96% rename from network/example/tcp_server/tcp_echo.cpp rename to examples/network/tcp_server/tcp_echo/tcp_echo.cpp index a09a6354b4b649ac6627b1f3888f215f553aa6be..c59c32bd7396a0f31178be57b27b3cc5691bc74a 100644 --- a/network/example/tcp_server/tcp_echo.cpp +++ b/examples/network/tcp_server/tcp_echo/tcp_echo.cpp @@ -38,7 +38,7 @@ int main(int argc, char **argv) SetScopeExitAction([sp_loop] { delete sp_loop; }); TcpServer server(sp_loop); - server.initialize(bind_addr); + server.initialize(bind_addr, 1); //! 当收到数据时,直接往client指定对象发回去 server.setReceiveCallback( [&server] (const TcpServer::ConnToken &client, Buffer &buff) { @@ -54,7 +54,7 @@ int main(int argc, char **argv) sp_stop_ev->initialize(SIGINT, Event::Mode::kOneshot); //! 指定ctrl+C时要做的事务 sp_stop_ev->setCallback( - [sp_loop, &server] { + [sp_loop, &server] (int) { server.stop(); sp_loop->exitLoop(); //! (3) 退出事件循环 } diff --git a/examples/network/tcp_server/tcp_nc_server/Makefile b/examples/network/tcp_server/tcp_nc_server/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..695aa35d803123c40ecfd4c45e2643edb6c445eb --- /dev/null +++ b/examples/network/tcp_server/tcp_nc_server/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/tcp_server/tcp_nc_server + +CPP_SRC_FILES := tcp_nc_server.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/tcp_server/tcp_nc_server.cpp b/examples/network/tcp_server/tcp_nc_server/tcp_nc_server.cpp similarity index 97% rename from network/example/tcp_server/tcp_nc_server.cpp rename to examples/network/tcp_server/tcp_nc_server/tcp_nc_server.cpp index 562317aba9db5618fbbd93a8e5d93a4591595c1d..35450d92952a5f8df2119ee4e8464fc1a07ec982 100644 --- a/network/example/tcp_server/tcp_nc_server.cpp +++ b/examples/network/tcp_server/tcp_nc_server/tcp_nc_server.cpp @@ -44,7 +44,7 @@ int main(int argc, char **argv) stdio.enable(); TcpServer server(sp_loop); - server.initialize(bind_addr); + server.initialize(bind_addr, 1); server.start(); @@ -91,7 +91,7 @@ int main(int argc, char **argv) sp_stop_ev->initialize(SIGINT, Event::Mode::kOneshot); //! 指定ctrl+C时要做的事务 sp_stop_ev->setCallback( - [sp_loop, &server, &clients] { + [sp_loop, &server, &clients] (int) { clients.clear(); server.stop(); sp_loop->exitLoop(); //! (3) 退出事件循环 diff --git a/examples/network/uart/Makefile b/examples/network/uart/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/network/uart/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/network/uart/uart_to_uart/Makefile b/examples/network/uart/uart_to_uart/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..93ecc8f7ef92508874369352c8977108ed6718bf --- /dev/null +++ b/examples/network/uart/uart_to_uart/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/uart/uart_to_uart + +CPP_SRC_FILES := uart_to_uart.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/uart/uart_to_uart.cpp b/examples/network/uart/uart_to_uart/uart_to_uart.cpp similarity index 98% rename from network/example/uart/uart_to_uart.cpp rename to examples/network/uart/uart_to_uart/uart_to_uart.cpp index 6bc3d979e4e0744acb0e07e388fb9b07482d7f5c..ecb13e4f0f44621bc9d4ec1ace149eb48a748443 100644 --- a/network/example/uart/uart_to_uart.cpp +++ b/examples/network/uart/uart_to_uart/uart_to_uart.cpp @@ -48,7 +48,7 @@ int main(int argc, char **argv) sp_exit->initialize(SIGINT, event::Event::Mode::kOneshot); sp_exit->enable(); sp_exit->setCallback( - [=] { + [=] (int) { cout << "Info: Exit Loop" << endl; sp_loop->exitLoop(); } diff --git a/examples/network/uart/uart_tool/Makefile b/examples/network/uart/uart_tool/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..5fdc817744e8853a131b322f46f4119531a76bf1 --- /dev/null +++ b/examples/network/uart/uart_tool/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/uart/uart_tool + +CPP_SRC_FILES := uart_tool.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/uart/uart_tool.cpp b/examples/network/uart/uart_tool/uart_tool.cpp similarity index 98% rename from network/example/uart/uart_tool.cpp rename to examples/network/uart/uart_tool/uart_tool.cpp index 8a985644d293e8df8f050922214e97904afb0124..1dd7e4d8f7a0c0f8c698c137f034e2e04cfabe9b 100644 --- a/network/example/uart/uart_tool.cpp +++ b/examples/network/uart/uart_tool/uart_tool.cpp @@ -47,7 +47,7 @@ int main(int argc, char **argv) sp_exit->initialize(SIGINT, event::Event::Mode::kOneshot); sp_exit->enable(); sp_exit->setCallback( - [=] { + [=] (int) { cout << "Info: Exit Loop" << endl; sp_loop->exitLoop(); } diff --git a/examples/network/udp_socket/Makefile b/examples/network/udp_socket/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/network/udp_socket/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/network/udp_socket/ping_pong/Makefile b/examples/network/udp_socket/ping_pong/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..a8044406f48aef529460355a887c52ea9b53cad7 --- /dev/null +++ b/examples/network/udp_socket/ping_pong/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/udp_socket/ping_pong + +CPP_SRC_FILES := ping_pong.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/udp_socket/ping_pong.cpp b/examples/network/udp_socket/ping_pong/ping_pong.cpp similarity index 100% rename from network/example/udp_socket/ping_pong.cpp rename to examples/network/udp_socket/ping_pong/ping_pong.cpp diff --git a/examples/network/udp_socket/recv_only/Makefile b/examples/network/udp_socket/recv_only/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..802321fced85f287cc0df14c68e582909691e9c1 --- /dev/null +++ b/examples/network/udp_socket/recv_only/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/udp_socket/recv_only + +CPP_SRC_FILES := recv_only.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/udp_socket/recv_only.cpp b/examples/network/udp_socket/recv_only/recv_only.cpp similarity index 100% rename from network/example/udp_socket/recv_only.cpp rename to examples/network/udp_socket/recv_only/recv_only.cpp diff --git a/examples/network/udp_socket/request/Makefile b/examples/network/udp_socket/request/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..0b12593d0c05c890f7d818c46ccaeb58d4e6229d --- /dev/null +++ b/examples/network/udp_socket/request/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/udp_socket/request + +CPP_SRC_FILES := request.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/udp_socket/request.cpp b/examples/network/udp_socket/request/request.cpp similarity index 100% rename from network/example/udp_socket/request.cpp rename to examples/network/udp_socket/request/request.cpp diff --git a/examples/network/udp_socket/respond/Makefile b/examples/network/udp_socket/respond/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..3752fc0602241ae9c5353e643280aa6af9121c21 --- /dev/null +++ b/examples/network/udp_socket/respond/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/udp_socket/respond + +CPP_SRC_FILES := respond.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/udp_socket/respond.cpp b/examples/network/udp_socket/respond/respond.cpp similarity index 100% rename from network/example/udp_socket/respond.cpp rename to examples/network/udp_socket/respond/respond.cpp diff --git a/examples/network/udp_socket/send_only/Makefile b/examples/network/udp_socket/send_only/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..9d066b390bbcffde70b178068cd48b88d46238ca --- /dev/null +++ b/examples/network/udp_socket/send_only/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/network/udp_socket/send_only + +CPP_SRC_FILES := send_only.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_network \ + -ltbox_event \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/network/example/udp_socket/send_only.cpp b/examples/network/udp_socket/send_only/send_only.cpp similarity index 100% rename from network/example/udp_socket/send_only.cpp rename to examples/network/udp_socket/send_only/send_only.cpp diff --git a/examples/terminal/Makefile b/examples/terminal/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/terminal/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/terminal/tcp_rpc/Makefile b/examples/terminal/tcp_rpc/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..18d088e5d6395081d970ae828f4814fbfede1602 --- /dev/null +++ b/examples/terminal/tcp_rpc/Makefile @@ -0,0 +1,13 @@ +EXE_NAME := example/terminal/tcp_rpc + +CPP_SRC_FILES := main.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_terminal \ + -ltbox_network \ + -ltbox_event \ + -ltbox_util \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/terminal/example/tcp_rpc/main.cpp b/examples/terminal/tcp_rpc/main.cpp similarity index 100% rename from terminal/example/tcp_rpc/main.cpp rename to examples/terminal/tcp_rpc/main.cpp diff --git a/examples/terminal/telnetd/Makefile b/examples/terminal/telnetd/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..5f45b0310db2a73790ec951fcf60f7ea262b3cde --- /dev/null +++ b/examples/terminal/telnetd/Makefile @@ -0,0 +1,13 @@ +EXE_NAME := example/terminal/telnetd + +CPP_SRC_FILES := main.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_terminal \ + -ltbox_network \ + -ltbox_event \ + -ltbox_util \ + -ltbox_base \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/terminal/example/telnetd/main.cpp b/examples/terminal/telnetd/main.cpp similarity index 100% rename from terminal/example/telnetd/main.cpp rename to examples/terminal/telnetd/main.cpp diff --git a/examples/util/Makefile b/examples/util/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..31374b4729edded3f2e0f72ac1912092891f0e39 --- /dev/null +++ b/examples/util/Makefile @@ -0,0 +1,6 @@ +all test clean distclean: + @for i in $(shell ls) ; do \ + if [ -d $$i ]; then \ + $(MAKE) -C $$i $@ || exit $$? ; \ + fi \ + done diff --git a/examples/util/backtrace/Makefile b/examples/util/backtrace/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..a862a733a75177e4bbccd2e728e42ce2e3747810 --- /dev/null +++ b/examples/util/backtrace/Makefile @@ -0,0 +1,11 @@ +EXE_NAME := example/util/backstrace + +CPP_SRC_FILES := sample.cpp + +CXXFLAGS := -DLOG_MODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS) +LDFLAGS += \ + -ltbox_util \ + -ltbox_base \ + -ldl \ + +include ${TOP_DIR}/tools/exe_common.mk diff --git a/util/example/backtrace/sample.cpp b/examples/util/backtrace/sample.cpp similarity index 100% rename from util/example/backtrace/sample.cpp rename to examples/util/backtrace/sample.cpp diff --git a/http/example/build_env.mk b/http/example/build_env.mk deleted file mode 100644 index 58481118dd79b3db71ee35ab91baf0bfe01358c0..0000000000000000000000000000000000000000 --- a/http/example/build_env.mk +++ /dev/null @@ -1,29 +0,0 @@ -STAGING_DIR := ../../../.staging - -STAGING_INCLUDE := $(STAGING_DIR)/include -STAGING_LIB := $(STAGING_DIR)/lib - -CCFLAGS := -I$(STAGING_INCLUDE) -I$(CONSTANT_INCLUDE) -CFLAGS := $(CCFLAGS) -std=c99 -CXXFLAGS := $(CCFLAGS) -std=c++11 -LDFLAGS := -L$(STAGING_LIB) -INSTALL_DIR := $(STAGING_DIR) -DESTDIR := $(STAGING_DIR) -prefix := - -TOOLCHAIN_PREFIX := -AR := $(TOOLCHAIN_PREFIX)ar -AS := $(TOOLCHAIN_PREFIX)as -CXX := $(TOOLCHAIN_PREFIX)g++ -CC := $(TOOLCHAIN_PREFIX)gcc -NM := $(TOOLCHAIN_PREFIX)nm -OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy -OBJDUMP := $(TOOLCHAIN_PREFIX)objdump -STRINGS := $(TOOLCHAIN_PREFIX)strings -SSTRIP := $(TOOLCHAIN_PREFIX)sstrip -LSTRIP := $(TOOLCHAIN_PREFIX)lstrip -STRIP := $(TOOLCHAIN_PREFIX)strip - -export STAGING_INCLUDE STAGING_LIB INSTALL_DIR DESTDIR prefix -export AR AS CC NM OBJCOPY OBJDUMP CXX STRIP SSTRIP STRINGS LSTRIP -export CFLAGS CXXFLAGS LDFLAGS diff --git a/http/example/server/.gitignore b/http/example/server/.gitignore deleted file mode 100644 index 546e590d45b5a2d08f16ae4167ec1d75bc9b887f..0000000000000000000000000000000000000000 --- a/http/example/server/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/simple -/async_respond -/router -*.o diff --git a/http/example/server/Makefile b/http/example/server/Makefile deleted file mode 100644 index e624455b52b3035c2e619df2c7f5ee674c1cdede..0000000000000000000000000000000000000000 --- a/http/example/server/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include ../build_env.mk - -TARGET := simple async_respond router - -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"main"' -LDFLAGS += -ltbox_http -ltbox_network -ltbox_log -ltbox_eventx -ltbox_event -ltbox_util -ltbox_base - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGET) - -simple : simple.o - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) - -async_respond : async_respond.o - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) - -router: router.o - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) - -clean: - rm -rf *.o $(TARGET) diff --git a/main/example/00_empty/.gitignore b/main/example/00_empty/.gitignore deleted file mode 100644 index ae6321f86df48737f7a584bc524e879d019a5b2d..0000000000000000000000000000000000000000 --- a/main/example/00_empty/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/sample diff --git a/main/example/00_empty/Makefile b/main/example/00_empty/Makefile deleted file mode 100644 index 6bdfcde406d66b06f8d22941cc3017bf07d75bfa..0000000000000000000000000000000000000000 --- a/main/example/00_empty/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -include ../build_env.mk - -.PHONY : all clean distclean - -TARGET := sample -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. \ - -ltbox_main \ - -ltbox_log \ - -ltbox_terminal \ - -ltbox_network \ - -ltbox_eventx \ - -ltbox_event \ - -ltbox_util \ - -ltbox_base \ - -lpthread - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGET) - -$(TARGET): $(OBJECTS) - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) - -clean: - rm -rf $(OBJECTS) - -distclean: clean - rm -rf $(TARGET) diff --git a/main/example/01_one_app/.gitignore b/main/example/01_one_app/.gitignore deleted file mode 100644 index ae6321f86df48737f7a584bc524e879d019a5b2d..0000000000000000000000000000000000000000 --- a/main/example/01_one_app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/sample diff --git a/main/example/01_one_app/Makefile b/main/example/01_one_app/Makefile deleted file mode 100644 index 577137db66bfca1b12eb2c8ad68a02438d6afc5d..0000000000000000000000000000000000000000 --- a/main/example/01_one_app/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -include ../build_env.mk - -.PHONY : all clean distclean - -TARGET := sample -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. \ - -ltbox_main \ - -ltbox_log \ - -ltbox_terminal \ - -ltbox_network \ - -ltbox_eventx \ - -ltbox_event \ - -ltbox_util \ - -ltbox_base \ - -lpthread - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan -OBJECTS := main.o app.o - -all : $(TARGET) - -$(TARGET): $(OBJECTS) - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) - -clean: - rm -rf $(OBJECTS) - -distclean: clean - rm -rf $(TARGET) diff --git a/main/example/02_more_than_one_apps/.gitignore b/main/example/02_more_than_one_apps/.gitignore deleted file mode 100644 index ae6321f86df48737f7a584bc524e879d019a5b2d..0000000000000000000000000000000000000000 --- a/main/example/02_more_than_one_apps/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/sample diff --git a/main/example/02_more_than_one_apps/app1/app.mk b/main/example/02_more_than_one_apps/app1/app.mk deleted file mode 100644 index b321eda620d730b8e04117d4e75f193f2a08dc44..0000000000000000000000000000000000000000 --- a/main/example/02_more_than_one_apps/app1/app.mk +++ /dev/null @@ -1 +0,0 @@ -OBJECTS += app1/app.o app1/sub.o diff --git a/main/example/02_more_than_one_apps/app2/app.mk b/main/example/02_more_than_one_apps/app2/app.mk deleted file mode 100644 index fbe78ca1b15dcd15c87c166c4fadbc609ae6e82c..0000000000000000000000000000000000000000 --- a/main/example/02_more_than_one_apps/app2/app.mk +++ /dev/null @@ -1 +0,0 @@ -OBJECTS += app2/app.o diff --git a/main/example/02_more_than_one_apps/app3/app.mk b/main/example/02_more_than_one_apps/app3/app.mk deleted file mode 100644 index f36524152d4554da3011b9b1928b3f09cf6939dd..0000000000000000000000000000000000000000 --- a/main/example/02_more_than_one_apps/app3/app.mk +++ /dev/null @@ -1 +0,0 @@ -OBJECTS += app3/app.o diff --git a/main/example/03_nc_client_and_echo_server/.gitignore b/main/example/03_nc_client_and_echo_server/.gitignore deleted file mode 100644 index ae6321f86df48737f7a584bc524e879d019a5b2d..0000000000000000000000000000000000000000 --- a/main/example/03_nc_client_and_echo_server/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/sample diff --git a/main/example/04_initiate_runtime_error/.gitignore b/main/example/04_initiate_runtime_error/.gitignore deleted file mode 100644 index ae6321f86df48737f7a584bc524e879d019a5b2d..0000000000000000000000000000000000000000 --- a/main/example/04_initiate_runtime_error/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/sample diff --git a/main/example/04_initiate_runtime_error/Makefile b/main/example/04_initiate_runtime_error/Makefile deleted file mode 100644 index 494b8430b398d924352009575e3b2bbcf9a87066..0000000000000000000000000000000000000000 --- a/main/example/04_initiate_runtime_error/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -include ../build_env.mk - -.PHONY : all clean distclean - -TARGET := sample -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. \ - -ltbox_main \ - -ltbox_log \ - -ltbox_terminal \ - -ltbox_network \ - -ltbox_eventx \ - -ltbox_event \ - -ltbox_util \ - -ltbox_base \ - -lpthread \ - -rdynamic \ - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan -OBJECTS := main.o - -all : $(TARGET) - -$(TARGET): $(OBJECTS) - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) - -clean: - rm -rf $(OBJECTS) - -distclean: clean - rm -rf $(TARGET) diff --git a/main/example/build_env.mk b/main/example/build_env.mk deleted file mode 100644 index 58481118dd79b3db71ee35ab91baf0bfe01358c0..0000000000000000000000000000000000000000 --- a/main/example/build_env.mk +++ /dev/null @@ -1,29 +0,0 @@ -STAGING_DIR := ../../../.staging - -STAGING_INCLUDE := $(STAGING_DIR)/include -STAGING_LIB := $(STAGING_DIR)/lib - -CCFLAGS := -I$(STAGING_INCLUDE) -I$(CONSTANT_INCLUDE) -CFLAGS := $(CCFLAGS) -std=c99 -CXXFLAGS := $(CCFLAGS) -std=c++11 -LDFLAGS := -L$(STAGING_LIB) -INSTALL_DIR := $(STAGING_DIR) -DESTDIR := $(STAGING_DIR) -prefix := - -TOOLCHAIN_PREFIX := -AR := $(TOOLCHAIN_PREFIX)ar -AS := $(TOOLCHAIN_PREFIX)as -CXX := $(TOOLCHAIN_PREFIX)g++ -CC := $(TOOLCHAIN_PREFIX)gcc -NM := $(TOOLCHAIN_PREFIX)nm -OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy -OBJDUMP := $(TOOLCHAIN_PREFIX)objdump -STRINGS := $(TOOLCHAIN_PREFIX)strings -SSTRIP := $(TOOLCHAIN_PREFIX)sstrip -LSTRIP := $(TOOLCHAIN_PREFIX)lstrip -STRIP := $(TOOLCHAIN_PREFIX)strip - -export STAGING_INCLUDE STAGING_LIB INSTALL_DIR DESTDIR prefix -export AR AS CC NM OBJCOPY OBJDUMP CXX STRIP SSTRIP STRINGS LSTRIP -export CFLAGS CXXFLAGS LDFLAGS diff --git a/modules/Makefile b/modules/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..1b05fb46a7d6d9a29731b6119a8b6841927e469c --- /dev/null +++ b/modules/Makefile @@ -0,0 +1,4 @@ +all test: + @for i in $(MODULES); do \ + [ ! -d $$i ] || $(MAKE) -C $$i $@ || exit $$? ; \ + done diff --git a/base/Makefile b/modules/base/Makefile similarity index 92% rename from base/Makefile rename to modules/base/Makefile index 5b2264a9841fc041bf05e3e346208dd61fc6e680..b81565bbd4091734a7be775fe9a5d41bb6f8e733 100644 --- a/base/Makefile +++ b/modules/base/Makefile @@ -33,4 +33,4 @@ TEST_LDFLAGS := $(LDFLAGS) ENABLE_SHARED_LIB = no -include ../tools/lib_common.mk +include $(TOP_DIR)/tools/lib_common.mk diff --git a/base/cabinet.hpp b/modules/base/cabinet.hpp similarity index 100% rename from base/cabinet.hpp rename to modules/base/cabinet.hpp diff --git a/base/cabinet_test.cpp b/modules/base/cabinet_test.cpp similarity index 100% rename from base/cabinet_test.cpp rename to modules/base/cabinet_test.cpp diff --git a/base/cabinet_token.h b/modules/base/cabinet_token.h similarity index 100% rename from base/cabinet_token.h rename to modules/base/cabinet_token.h diff --git a/base/defines.h b/modules/base/defines.h similarity index 100% rename from base/defines.h rename to modules/base/defines.h diff --git a/base/json.hpp b/modules/base/json.hpp similarity index 100% rename from base/json.hpp rename to modules/base/json.hpp diff --git a/base/json_fwd.h b/modules/base/json_fwd.h similarity index 100% rename from base/json_fwd.h rename to modules/base/json_fwd.h diff --git a/base/json_test.cpp b/modules/base/json_test.cpp similarity index 100% rename from base/json_test.cpp rename to modules/base/json_test.cpp diff --git a/base/log.h b/modules/base/log.h similarity index 100% rename from base/log.h rename to modules/base/log.h diff --git a/base/log_imp.cpp b/modules/base/log_imp.cpp similarity index 87% rename from base/log_imp.cpp rename to modules/base/log_imp.cpp index 19088d82c408fc6fa79150d85c116ef577d7fb66..3a54c0f59881bb4341f97f83cb961272ed414845 100644 --- a/base/log_imp.cpp +++ b/modules/base/log_imp.cpp @@ -8,12 +8,10 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +namespace { -static std::mutex _lock; -static uint32_t _id_alloc = 0; +std::mutex _lock; +uint32_t _id_alloc = 0; struct OutputChannel { uint32_t id; @@ -21,7 +19,19 @@ struct OutputChannel { void *ptr; }; -static std::vector _output_channels; +std::vector _output_channels; + +const char* Basename(const char *full_path) +{ + const char *p_last = full_path; + for (const char *p = full_path; *p; ++p) { + if (*p == '/') + p_last = p + 1; + } + return p_last; +} + +} /** * \brief 日志格式化打印接口的实现 @@ -52,7 +62,7 @@ void LogPrintfFunc(const char *module_id, const char *func_name, const char *fil }, .module_id = module_id_be_print, .func_name = func_name, - .file_name = file_name, + .file_name = Basename(file_name), .line = line, .level = level, .with_args = with_args, @@ -103,6 +113,3 @@ bool LogRemovePrintfFunc(uint32_t id) return false; } -#ifdef __cplusplus -} -#endif diff --git a/base/log_imp.h b/modules/base/log_imp.h similarity index 100% rename from base/log_imp.h rename to modules/base/log_imp.h diff --git a/base/log_output.cpp b/modules/base/log_output.cpp similarity index 100% rename from base/log_output.cpp rename to modules/base/log_output.cpp diff --git a/base/log_output.h b/modules/base/log_output.h similarity index 100% rename from base/log_output.h rename to modules/base/log_output.h diff --git a/base/log_output_test.cpp b/modules/base/log_output_test.cpp similarity index 100% rename from base/log_output_test.cpp rename to modules/base/log_output_test.cpp diff --git a/base/memblock.h b/modules/base/memblock.h similarity index 100% rename from base/memblock.h rename to modules/base/memblock.h diff --git a/base/scope_exit.hpp b/modules/base/scope_exit.hpp similarity index 100% rename from base/scope_exit.hpp rename to modules/base/scope_exit.hpp diff --git a/base/scope_exit_test.cpp b/modules/base/scope_exit_test.cpp similarity index 76% rename from base/scope_exit_test.cpp rename to modules/base/scope_exit_test.cpp index 08ae702a270717f83dcead8a57f99708c0d21b1e..0342dbc99312b2f932a84894d13d23e8b1b049ad 100644 --- a/base/scope_exit_test.cpp +++ b/modules/base/scope_exit_test.cpp @@ -14,6 +14,16 @@ TEST(ScopeExitAction, no_name) EXPECT_TRUE(tag); } +TEST(ScopeExitAction, no_name_1) +{ + int count = 3; + { + SetScopeExitAction([&] { ++count; }); + SetScopeExitAction([&] { count *= 2; }); + } + EXPECT_EQ(count, 7); +} + TEST(ScopeExitAction, named) { bool tag = false; diff --git a/coroutine/Makefile b/modules/coroutine/Makefile similarity index 93% rename from coroutine/Makefile rename to modules/coroutine/Makefile index cd249292a1f2697b27cc7e856eec7460a55a5acf..0eb2f88ab52fae3186a84378d1a8591aa8931eb8 100644 --- a/coroutine/Makefile +++ b/modules/coroutine/Makefile @@ -28,4 +28,4 @@ TEST_LDFLAGS := $(LDFLAGS) -ltbox_event -ltbox_base -levent_core -lev ENABLE_SHARED_LIB = no -include ../tools/lib_common.mk +include $(TOP_DIR)/tools/lib_common.mk diff --git a/coroutine/README.md b/modules/coroutine/README.md similarity index 100% rename from coroutine/README.md rename to modules/coroutine/README.md diff --git a/coroutine/broadcast.hpp b/modules/coroutine/broadcast.hpp similarity index 100% rename from coroutine/broadcast.hpp rename to modules/coroutine/broadcast.hpp diff --git a/coroutine/broadcast_test.cpp b/modules/coroutine/broadcast_test.cpp similarity index 100% rename from coroutine/broadcast_test.cpp rename to modules/coroutine/broadcast_test.cpp diff --git a/coroutine/channel.hpp b/modules/coroutine/channel.hpp similarity index 100% rename from coroutine/channel.hpp rename to modules/coroutine/channel.hpp diff --git a/coroutine/channel_test.cpp b/modules/coroutine/channel_test.cpp similarity index 100% rename from coroutine/channel_test.cpp rename to modules/coroutine/channel_test.cpp diff --git a/coroutine/condition.hpp b/modules/coroutine/condition.hpp similarity index 100% rename from coroutine/condition.hpp rename to modules/coroutine/condition.hpp diff --git a/coroutine/condition_test.cpp b/modules/coroutine/condition_test.cpp similarity index 100% rename from coroutine/condition_test.cpp rename to modules/coroutine/condition_test.cpp diff --git a/coroutine/mutex.hpp b/modules/coroutine/mutex.hpp similarity index 100% rename from coroutine/mutex.hpp rename to modules/coroutine/mutex.hpp diff --git a/coroutine/mutex_test.cpp b/modules/coroutine/mutex_test.cpp similarity index 100% rename from coroutine/mutex_test.cpp rename to modules/coroutine/mutex_test.cpp diff --git a/coroutine/scheduler.cpp b/modules/coroutine/scheduler.cpp similarity index 100% rename from coroutine/scheduler.cpp rename to modules/coroutine/scheduler.cpp diff --git a/coroutine/scheduler.h b/modules/coroutine/scheduler.h similarity index 100% rename from coroutine/scheduler.h rename to modules/coroutine/scheduler.h diff --git a/coroutine/scheduler_test.cpp b/modules/coroutine/scheduler_test.cpp similarity index 100% rename from coroutine/scheduler_test.cpp rename to modules/coroutine/scheduler_test.cpp diff --git a/coroutine/semaphore.hpp b/modules/coroutine/semaphore.hpp similarity index 100% rename from coroutine/semaphore.hpp rename to modules/coroutine/semaphore.hpp diff --git a/coroutine/semaphore_test.cpp b/modules/coroutine/semaphore_test.cpp similarity index 100% rename from coroutine/semaphore_test.cpp rename to modules/coroutine/semaphore_test.cpp diff --git a/event/Makefile b/modules/event/Makefile similarity index 97% rename from event/Makefile rename to modules/event/Makefile index c5e7bb05eeacf1f62a19bb548d2af34f0ddb2cd4..c20161c6f27e3416d78851daf864b406843799d5 100644 --- a/event/Makefile +++ b/modules/event/Makefile @@ -70,4 +70,4 @@ endif ENABLE_SHARED_LIB = no -include ../tools/lib_common.mk +include $(TOP_DIR)/tools/lib_common.mk diff --git a/event/common_loop.cpp b/modules/event/common_loop.cpp similarity index 100% rename from event/common_loop.cpp rename to modules/event/common_loop.cpp diff --git a/event/common_loop.h b/modules/event/common_loop.h similarity index 100% rename from event/common_loop.h rename to modules/event/common_loop.h diff --git a/event/common_loop_run.cpp b/modules/event/common_loop_run.cpp similarity index 100% rename from event/common_loop_run.cpp rename to modules/event/common_loop_run.cpp diff --git a/event/common_loop_signal.cpp b/modules/event/common_loop_signal.cpp similarity index 93% rename from event/common_loop_signal.cpp rename to modules/event/common_loop_signal.cpp index 64f01f3beac2d605ff3372c8df15214cd751969c..8586dce8f85299ec0f03b8b86a225fdc669eda25 100644 --- a/event/common_loop_signal.cpp +++ b/modules/event/common_loop_signal.cpp @@ -102,8 +102,10 @@ void CommonLoop::HandleSignal(int signo) { //LogTrace("got signal :%d", signo); auto &this_signal_fds = _signal_write_fds_[signo]; - for (int fd : this_signal_fds) - write(fd, &signo, sizeof(signo)); + for (int fd : this_signal_fds) { + auto wsize = write(fd, &signo, sizeof(signo)); + (void)wsize; //! 消除编译警告 + } } void CommonLoop::onSignal() @@ -119,7 +121,8 @@ void CommonLoop::onSignal() //LogTrace("signo:%d", signo); auto iter = all_signals_subscribers_.find(signo); if (iter != all_signals_subscribers_.end()) { - for (auto s : iter->second) { + auto todo = iter->second; //!FIXME:Crash if SignalSubscribuer be deleted in callback + for (auto s : todo) { s->onSignal(signo); } } diff --git a/event/common_loop_test.cpp b/modules/event/common_loop_test.cpp similarity index 100% rename from event/common_loop_test.cpp rename to modules/event/common_loop_test.cpp diff --git a/event/config.mk b/modules/event/config.mk similarity index 100% rename from event/config.mk rename to modules/event/config.mk diff --git a/event/engins/epoll/fd_event.cpp b/modules/event/engins/epoll/fd_event.cpp similarity index 93% rename from event/engins/epoll/fd_event.cpp rename to modules/event/engins/epoll/fd_event.cpp index f341b4074c09aaf1b4b7b602a06d48ec6dedbeca..d1c21e3cb91a271678583b7fdf29f202bd5f7ede 100644 --- a/event/engins/epoll/fd_event.cpp +++ b/modules/event/engins/epoll/fd_event.cpp @@ -28,10 +28,12 @@ EpollFdEvent::~EpollFdEvent() disable(); - --d_->ref; - if (d_->ref == 0) { - wp_loop_->removeFdSharedData(fd_); - delete d_; + if (d_ != nullptr) { + --d_->ref; + if (d_->ref == 0) { + wp_loop_->removeFdSharedData(fd_); + delete d_; + } } } @@ -139,14 +141,13 @@ void EpollFdEvent::onEvent(short events) { wp_loop_->beginEventProcess(); - if (cb_) { + if (is_stop_after_trigger_) + disable(); + if (cb_) { ++cb_level_; cb_(events); --cb_level_; - - if (is_stop_after_trigger_) - disable(); } wp_loop_->endEventProcess(); diff --git a/event/engins/epoll/fd_event.h b/modules/event/engins/epoll/fd_event.h similarity index 100% rename from event/engins/epoll/fd_event.h rename to modules/event/engins/epoll/fd_event.h diff --git a/event/engins/epoll/loop.cpp b/modules/event/engins/epoll/loop.cpp similarity index 100% rename from event/engins/epoll/loop.cpp rename to modules/event/engins/epoll/loop.cpp diff --git a/event/engins/epoll/loop.h b/modules/event/engins/epoll/loop.h similarity index 100% rename from event/engins/epoll/loop.h rename to modules/event/engins/epoll/loop.h diff --git a/event/engins/epoll/timer_event.cpp b/modules/event/engins/epoll/timer_event.cpp similarity index 93% rename from event/engins/epoll/timer_event.cpp rename to modules/event/engins/epoll/timer_event.cpp index 908a4bb884bfa5ab9417e0523c06f57be67c0655..81d6ae0b94ca3b15102f273e606099e8815d4814 100644 --- a/event/engins/epoll/timer_event.cpp +++ b/modules/event/engins/epoll/timer_event.cpp @@ -80,6 +80,11 @@ void EpollTimerEvent::onEvent() { wp_loop_->beginEventProcess(); + if (mode_ == Mode::kOneshot) { + is_enabled_ = false; + token_.reset(); + } + if (cb_) { ++cb_level_; cb_(); diff --git a/event/engins/epoll/timer_event.h b/modules/event/engins/epoll/timer_event.h similarity index 100% rename from event/engins/epoll/timer_event.h rename to modules/event/engins/epoll/timer_event.h diff --git a/event/engins/libev/fd_event.cpp b/modules/event/engins/libev/fd_event.cpp similarity index 100% rename from event/engins/libev/fd_event.cpp rename to modules/event/engins/libev/fd_event.cpp diff --git a/event/engins/libev/fd_event.h b/modules/event/engins/libev/fd_event.h similarity index 100% rename from event/engins/libev/fd_event.h rename to modules/event/engins/libev/fd_event.h diff --git a/event/engins/libev/loop.cpp b/modules/event/engins/libev/loop.cpp similarity index 100% rename from event/engins/libev/loop.cpp rename to modules/event/engins/libev/loop.cpp diff --git a/event/engins/libev/loop.h b/modules/event/engins/libev/loop.h similarity index 100% rename from event/engins/libev/loop.h rename to modules/event/engins/libev/loop.h diff --git a/event/engins/libev/timer_event.cpp b/modules/event/engins/libev/timer_event.cpp similarity index 100% rename from event/engins/libev/timer_event.cpp rename to modules/event/engins/libev/timer_event.cpp diff --git a/event/engins/libev/timer_event.h b/modules/event/engins/libev/timer_event.h similarity index 100% rename from event/engins/libev/timer_event.h rename to modules/event/engins/libev/timer_event.h diff --git a/event/engins/libevent/common.cpp b/modules/event/engins/libevent/common.cpp similarity index 100% rename from event/engins/libevent/common.cpp rename to modules/event/engins/libevent/common.cpp diff --git a/event/engins/libevent/common.h b/modules/event/engins/libevent/common.h similarity index 100% rename from event/engins/libevent/common.h rename to modules/event/engins/libevent/common.h diff --git a/event/engins/libevent/fd_event.cpp b/modules/event/engins/libevent/fd_event.cpp similarity index 100% rename from event/engins/libevent/fd_event.cpp rename to modules/event/engins/libevent/fd_event.cpp diff --git a/event/engins/libevent/fd_event.h b/modules/event/engins/libevent/fd_event.h similarity index 100% rename from event/engins/libevent/fd_event.h rename to modules/event/engins/libevent/fd_event.h diff --git a/event/engins/libevent/loop.cpp b/modules/event/engins/libevent/loop.cpp similarity index 100% rename from event/engins/libevent/loop.cpp rename to modules/event/engins/libevent/loop.cpp diff --git a/event/engins/libevent/loop.h b/modules/event/engins/libevent/loop.h similarity index 100% rename from event/engins/libevent/loop.h rename to modules/event/engins/libevent/loop.h diff --git a/event/engins/libevent/timer_event.cpp b/modules/event/engins/libevent/timer_event.cpp similarity index 100% rename from event/engins/libevent/timer_event.cpp rename to modules/event/engins/libevent/timer_event.cpp diff --git a/event/engins/libevent/timer_event.h b/modules/event/engins/libevent/timer_event.h similarity index 100% rename from event/engins/libevent/timer_event.h rename to modules/event/engins/libevent/timer_event.h diff --git a/event/event.h b/modules/event/event.h similarity index 100% rename from event/event.h rename to modules/event/event.h diff --git a/event/fd_event.h b/modules/event/fd_event.h similarity index 100% rename from event/fd_event.h rename to modules/event/fd_event.h diff --git a/event/fd_event_test.cpp b/modules/event/fd_event_test.cpp similarity index 100% rename from event/fd_event_test.cpp rename to modules/event/fd_event_test.cpp diff --git a/event/forward.h b/modules/event/forward.h similarity index 100% rename from event/forward.h rename to modules/event/forward.h diff --git a/event/loop.cpp b/modules/event/loop.cpp similarity index 100% rename from event/loop.cpp rename to modules/event/loop.cpp diff --git a/event/loop.h b/modules/event/loop.h similarity index 100% rename from event/loop.h rename to modules/event/loop.h diff --git a/event/misc.cpp b/modules/event/misc.cpp similarity index 100% rename from event/misc.cpp rename to modules/event/misc.cpp diff --git a/event/misc.h b/modules/event/misc.h similarity index 100% rename from event/misc.h rename to modules/event/misc.h diff --git a/event/signal_event.h b/modules/event/signal_event.h similarity index 100% rename from event/signal_event.h rename to modules/event/signal_event.h diff --git a/event/signal_event_impl.cpp b/modules/event/signal_event_impl.cpp similarity index 100% rename from event/signal_event_impl.cpp rename to modules/event/signal_event_impl.cpp diff --git a/event/signal_event_impl.h b/modules/event/signal_event_impl.h similarity index 100% rename from event/signal_event_impl.h rename to modules/event/signal_event_impl.h diff --git a/event/signal_event_test.cpp b/modules/event/signal_event_test.cpp similarity index 100% rename from event/signal_event_test.cpp rename to modules/event/signal_event_test.cpp diff --git a/event/stat.cpp b/modules/event/stat.cpp similarity index 100% rename from event/stat.cpp rename to modules/event/stat.cpp diff --git a/event/stat.h b/modules/event/stat.h similarity index 100% rename from event/stat.h rename to modules/event/stat.h diff --git a/event/stat_test.cpp b/modules/event/stat_test.cpp similarity index 100% rename from event/stat_test.cpp rename to modules/event/stat_test.cpp diff --git a/event/timer_event.h b/modules/event/timer_event.h similarity index 100% rename from event/timer_event.h rename to modules/event/timer_event.h diff --git a/event/timer_event_test.cpp b/modules/event/timer_event_test.cpp similarity index 97% rename from event/timer_event_test.cpp rename to modules/event/timer_event_test.cpp index 776e3298957b057c802b948000e9e359f102947e..610893fd9845eb9cb5f131a30c975173f710ebe0 100644 --- a/event/timer_event_test.cpp +++ b/modules/event/timer_event_test.cpp @@ -27,6 +27,7 @@ TEST(TimerEvent, Oneshot) sp_loop->runLoop(); EXPECT_EQ(run_time, 1); + EXPECT_FALSE(timer_event->isEnabled()); delete timer_event; delete sp_loop; @@ -50,6 +51,7 @@ TEST(TimerEvent, Persist) sp_loop->runLoop(); EXPECT_EQ(run_time, 10); + EXPECT_TRUE(timer_event->isEnabled()); delete timer_event; delete sp_loop; diff --git a/event/version.cpp b/modules/event/version.cpp similarity index 100% rename from event/version.cpp rename to modules/event/version.cpp diff --git a/event/version.h b/modules/event/version.h similarity index 100% rename from event/version.h rename to modules/event/version.h diff --git a/eventx/Makefile b/modules/eventx/Makefile similarity index 92% rename from eventx/Makefile rename to modules/eventx/Makefile index 09809626967d6c77001c66eaa006d233f0400fda..02eb5001309d1664fcd07b863a19f0f8e50d9d1b 100644 --- a/eventx/Makefile +++ b/modules/eventx/Makefile @@ -25,4 +25,4 @@ TEST_CPP_SRC_FILES = \ TEST_LDFLAGS := $(LDFLAGS) -ltbox_event -ltbox_base -levent_core -lev ENABLE_SHARED_LIB = no -include ../tools/lib_common.mk +include $(TOP_DIR)/tools/lib_common.mk diff --git a/eventx/request_pool.hpp b/modules/eventx/request_pool.hpp similarity index 100% rename from eventx/request_pool.hpp rename to modules/eventx/request_pool.hpp diff --git a/eventx/request_pool_test.cpp b/modules/eventx/request_pool_test.cpp similarity index 100% rename from eventx/request_pool_test.cpp rename to modules/eventx/request_pool_test.cpp diff --git a/eventx/thread_pool.cpp b/modules/eventx/thread_pool.cpp similarity index 100% rename from eventx/thread_pool.cpp rename to modules/eventx/thread_pool.cpp diff --git a/eventx/thread_pool.h b/modules/eventx/thread_pool.h similarity index 100% rename from eventx/thread_pool.h rename to modules/eventx/thread_pool.h diff --git a/eventx/thread_pool_test.cpp b/modules/eventx/thread_pool_test.cpp similarity index 100% rename from eventx/thread_pool_test.cpp rename to modules/eventx/thread_pool_test.cpp diff --git a/eventx/timeout_monitor.cpp b/modules/eventx/timeout_monitor.cpp similarity index 100% rename from eventx/timeout_monitor.cpp rename to modules/eventx/timeout_monitor.cpp diff --git a/eventx/timeout_monitor.h b/modules/eventx/timeout_monitor.h similarity index 100% rename from eventx/timeout_monitor.h rename to modules/eventx/timeout_monitor.h diff --git a/eventx/timeout_monitor_test.cpp b/modules/eventx/timeout_monitor_test.cpp similarity index 100% rename from eventx/timeout_monitor_test.cpp rename to modules/eventx/timeout_monitor_test.cpp diff --git a/eventx/timer_pool.cpp b/modules/eventx/timer_pool.cpp similarity index 100% rename from eventx/timer_pool.cpp rename to modules/eventx/timer_pool.cpp diff --git a/eventx/timer_pool.h b/modules/eventx/timer_pool.h similarity index 100% rename from eventx/timer_pool.h rename to modules/eventx/timer_pool.h diff --git a/eventx/timer_pool_test.cpp b/modules/eventx/timer_pool_test.cpp similarity index 100% rename from eventx/timer_pool_test.cpp rename to modules/eventx/timer_pool_test.cpp diff --git a/http/Makefile b/modules/http/Makefile similarity index 95% rename from http/Makefile rename to modules/http/Makefile index 0199b4b126e32bd558554a17100e303af57f1590..035a338d0e95b125991b879f82e498fd8207057d 100644 --- a/http/Makefile +++ b/modules/http/Makefile @@ -40,4 +40,4 @@ TEST_LDFLAGS := $(LDFLAGS) -ltbox_network -ltbox_log -ltbox_event -ltbox_util -l ENABLE_SHARED_LIB = no -include ../tools/lib_common.mk +include $(TOP_DIR)/tools/lib_common.mk diff --git a/http/README.md b/modules/http/README.md similarity index 100% rename from http/README.md rename to modules/http/README.md diff --git a/http/client/client.cpp b/modules/http/client/client.cpp similarity index 100% rename from http/client/client.cpp rename to modules/http/client/client.cpp diff --git a/http/client/client.h b/modules/http/client/client.h similarity index 100% rename from http/client/client.h rename to modules/http/client/client.h diff --git a/http/common.cpp b/modules/http/common.cpp similarity index 100% rename from http/common.cpp rename to modules/http/common.cpp diff --git a/http/common.h b/modules/http/common.h similarity index 100% rename from http/common.h rename to modules/http/common.h diff --git a/http/common_test.cpp b/modules/http/common_test.cpp similarity index 100% rename from http/common_test.cpp rename to modules/http/common_test.cpp diff --git a/http/request.cpp b/modules/http/request.cpp similarity index 100% rename from http/request.cpp rename to modules/http/request.cpp diff --git a/http/request.h b/modules/http/request.h similarity index 100% rename from http/request.h rename to modules/http/request.h diff --git a/http/request_test.cpp b/modules/http/request_test.cpp similarity index 100% rename from http/request_test.cpp rename to modules/http/request_test.cpp diff --git a/http/respond.cpp b/modules/http/respond.cpp similarity index 100% rename from http/respond.cpp rename to modules/http/respond.cpp diff --git a/http/respond.h b/modules/http/respond.h similarity index 100% rename from http/respond.h rename to modules/http/respond.h diff --git a/http/respond_test.cpp b/modules/http/respond_test.cpp similarity index 100% rename from http/respond_test.cpp rename to modules/http/respond_test.cpp diff --git a/http/server/context.cpp b/modules/http/server/context.cpp similarity index 100% rename from http/server/context.cpp rename to modules/http/server/context.cpp diff --git a/http/server/context.h b/modules/http/server/context.h similarity index 100% rename from http/server/context.h rename to modules/http/server/context.h diff --git a/http/server/middleware.h b/modules/http/server/middleware.h similarity index 100% rename from http/server/middleware.h rename to modules/http/server/middleware.h diff --git a/http/server/request_parser.cpp b/modules/http/server/request_parser.cpp similarity index 100% rename from http/server/request_parser.cpp rename to modules/http/server/request_parser.cpp diff --git a/http/server/request_parser.h b/modules/http/server/request_parser.h similarity index 100% rename from http/server/request_parser.h rename to modules/http/server/request_parser.h diff --git a/http/server/request_parser_test.cpp b/modules/http/server/request_parser_test.cpp similarity index 100% rename from http/server/request_parser_test.cpp rename to modules/http/server/request_parser_test.cpp diff --git a/http/server/router.cpp b/modules/http/server/router.cpp similarity index 100% rename from http/server/router.cpp rename to modules/http/server/router.cpp diff --git a/http/server/router.h b/modules/http/server/router.h similarity index 100% rename from http/server/router.h rename to modules/http/server/router.h diff --git a/http/server/server.cpp b/modules/http/server/server.cpp similarity index 100% rename from http/server/server.cpp rename to modules/http/server/server.cpp diff --git a/http/server/server.h b/modules/http/server/server.h similarity index 100% rename from http/server/server.h rename to modules/http/server/server.h diff --git a/http/server/server_imp.cpp b/modules/http/server/server_imp.cpp similarity index 100% rename from http/server/server_imp.cpp rename to modules/http/server/server_imp.cpp diff --git a/http/server/server_imp.h b/modules/http/server/server_imp.h similarity index 100% rename from http/server/server_imp.h rename to modules/http/server/server_imp.h diff --git a/http/server/types.h b/modules/http/server/types.h similarity index 100% rename from http/server/types.h rename to modules/http/server/types.h diff --git a/http/url.cpp b/modules/http/url.cpp similarity index 100% rename from http/url.cpp rename to modules/http/url.cpp diff --git a/http/url.h b/modules/http/url.h similarity index 100% rename from http/url.h rename to modules/http/url.h diff --git a/http/url_test.cpp b/modules/http/url_test.cpp similarity index 100% rename from http/url_test.cpp rename to modules/http/url_test.cpp diff --git a/log/Makefile b/modules/log/Makefile similarity index 93% rename from log/Makefile rename to modules/log/Makefile index 5f7ba956131c72b39dae4c4c4c6dea9174efdeb9..46bc0453952b7effff151a5074aa9bdd3e236a50 100644 --- a/log/Makefile +++ b/modules/log/Makefile @@ -28,4 +28,4 @@ TEST_CPP_SRC_FILES = \ TEST_LDFLAGS := $(LDFLAGS) -ltbox_util -ltbox_event -ltbox_base ENABLE_SHARED_LIB = no -include ../tools/lib_common.mk +include $(TOP_DIR)/tools/lib_common.mk diff --git a/log/async_channel.cpp b/modules/log/async_channel.cpp similarity index 100% rename from log/async_channel.cpp rename to modules/log/async_channel.cpp diff --git a/log/async_channel.h b/modules/log/async_channel.h similarity index 100% rename from log/async_channel.h rename to modules/log/async_channel.h diff --git a/log/async_channel_test.cpp b/modules/log/async_channel_test.cpp similarity index 100% rename from log/async_channel_test.cpp rename to modules/log/async_channel_test.cpp diff --git a/log/channel.cpp b/modules/log/channel.cpp similarity index 100% rename from log/channel.cpp rename to modules/log/channel.cpp diff --git a/log/channel.h b/modules/log/channel.h similarity index 100% rename from log/channel.h rename to modules/log/channel.h diff --git a/log/file_async_channel.cpp b/modules/log/file_async_channel.cpp similarity index 97% rename from log/file_async_channel.cpp rename to modules/log/file_async_channel.cpp index 169fb4011357e46462070e1bd09b6ed8677ec1fe..7366a4cde110fcde50a2ceb9e6c6fca932454cab 100644 --- a/log/file_async_channel.cpp +++ b/modules/log/file_async_channel.cpp @@ -56,7 +56,7 @@ void FileAsyncChannel::onLogBackEnd(const std::string &log_text) ofs_ << log_text << endl << flush; - if (ofs_.tellp() >= file_max_size_) + if (static_cast(ofs_.tellp()) >= file_max_size_) ofs_.close(); } diff --git a/log/file_async_channel.h b/modules/log/file_async_channel.h similarity index 100% rename from log/file_async_channel.h rename to modules/log/file_async_channel.h diff --git a/log/file_async_channel_test.cpp b/modules/log/file_async_channel_test.cpp similarity index 100% rename from log/file_async_channel_test.cpp rename to modules/log/file_async_channel_test.cpp diff --git a/log/stdout_channel.cpp b/modules/log/stdout_channel.cpp similarity index 100% rename from log/stdout_channel.cpp rename to modules/log/stdout_channel.cpp diff --git a/log/stdout_channel.h b/modules/log/stdout_channel.h similarity index 100% rename from log/stdout_channel.h rename to modules/log/stdout_channel.h diff --git a/log/stdout_channel_test.cpp b/modules/log/stdout_channel_test.cpp similarity index 100% rename from log/stdout_channel_test.cpp rename to modules/log/stdout_channel_test.cpp diff --git a/log/syslog_channel.cpp b/modules/log/syslog_channel.cpp similarity index 100% rename from log/syslog_channel.cpp rename to modules/log/syslog_channel.cpp diff --git a/log/syslog_channel.h b/modules/log/syslog_channel.h similarity index 100% rename from log/syslog_channel.h rename to modules/log/syslog_channel.h diff --git a/log/syslog_channel_test.cpp b/modules/log/syslog_channel_test.cpp similarity index 100% rename from log/syslog_channel_test.cpp rename to modules/log/syslog_channel_test.cpp diff --git a/main/Makefile b/modules/main/Makefile similarity index 92% rename from main/Makefile rename to modules/main/Makefile index f07ab87aef103cd92d1f8618097f1690887aaac3..cd612a3ab00de797f13ffa7dbadccc4c78bcb5fd 100644 --- a/main/Makefile +++ b/modules/main/Makefile @@ -33,4 +33,4 @@ TEST_LDFLAGS := $(LDFLAGS) \ ENABLE_SHARED_LIB = no -include ../tools/lib_common.mk +include $(TOP_DIR)/tools/lib_common.mk diff --git a/main/README.md b/modules/main/README.md similarity index 100% rename from main/README.md rename to modules/main/README.md diff --git a/main/args.cpp b/modules/main/args.cpp similarity index 100% rename from main/args.cpp rename to modules/main/args.cpp diff --git a/main/args.h b/modules/main/args.h similarity index 100% rename from main/args.h rename to modules/main/args.h diff --git a/main/context.h b/modules/main/context.h similarity index 100% rename from main/context.h rename to modules/main/context.h diff --git a/main/context_imp.cpp b/modules/main/context_imp.cpp similarity index 100% rename from main/context_imp.cpp rename to modules/main/context_imp.cpp diff --git a/main/context_imp.h b/modules/main/context_imp.h similarity index 100% rename from main/context_imp.h rename to modules/main/context_imp.h diff --git a/main/log.cpp b/modules/main/log.cpp similarity index 86% rename from main/log.cpp rename to modules/main/log.cpp index 260f302d917268de8167c6f5e13433eaf85142c2..eb932e5c6f8791b472baf8ab8841ed93933ae310 100644 --- a/main/log.cpp +++ b/modules/main/log.cpp @@ -27,17 +27,20 @@ void Log::fillDefaultConfig(Json &cfg) const { "stdout": { "enable": true, - "enable_color": true + "enable_color": true, + "levels": {"":6} }, "filelog": { - "enable": true, + "enable": false, + "enable_color": false, + "levels": {"":3}, "prefix": "sample", "path": "/tmp/tbox", - "max_size": 1024, - "enable_color": false + "max_size": 1024 }, "syslog": { - "enable": false + "enable": false, + "levels": {"":3} } } )"_json; @@ -71,6 +74,16 @@ bool Log::initialize(const char *proc_name, Context &ctx, const Json &cfg) cerr << "WARN: stdout.enable_color not boolean." << endl; } } + + if (js.contains("levels")) { + auto &js_levels = js.at("levels"); + if (js_levels.is_object()) { + for (auto it = js_levels.begin(); it != js_levels.end(); ++it) + stdout_.setLevel(it.value(), it.key()); + } else { + cerr << "WARN: stdout.levels not object." << endl; + } + } } if (js_log.contains("syslog")) { @@ -86,6 +99,16 @@ bool Log::initialize(const char *proc_name, Context &ctx, const Json &cfg) cerr << "WARN: syslog.enable not boolean." << endl; } } + + if (js.contains("levels")) { + auto &js_levels = js.at("levels"); + if (js_levels.is_object()) { + for (auto it = js_levels.begin(); it != js_levels.end(); ++it) + syslog_.setLevel(it.value(), it.key()); + } else { + cerr << "WARN: stdout.levels not object." << endl; + } + } } do { @@ -98,6 +121,35 @@ bool Log::initialize(const char *proc_name, Context &ctx, const Json &cfg) break; } + if (js.contains("enable")) { + auto &js_enable = js.at("enable"); + if (js_enable.is_boolean()) { + if (js_enable.get()) + filelog_.enable(); + else + filelog_.disable(); + } else + cerr << "WARN: filelog.enable not boolean" << endl; + } + + if (js.contains("enable_color")) { + auto &js_enable = js.at("enable_color"); + if (js_enable.is_boolean()) { + filelog_.enableColor(js_enable.get()); + } else + cerr << "WARN: filelog.enable_color not boolean" << endl; + } + + if (js.contains("levels")) { + auto &js_levels = js.at("levels"); + if (js_levels.is_object()) { + for (auto it = js_levels.begin(); it != js_levels.end(); ++it) + filelog_.setLevel(it.value(), it.key()); + } else { + cerr << "WARN: stdout.levels not object." << endl; + } + } + auto &js_path = js.at("path"); if (!js_path.is_string()) { cerr << "WARN: filelog.path not string." << endl; @@ -125,25 +177,6 @@ bool Log::initialize(const char *proc_name, Context &ctx, const Json &cfg) else cerr << "WARN: filelog.max_size not number" << endl; } - - if (js.contains("enable")) { - auto &js_enable = js.at("enable"); - if (js_enable.is_boolean()) { - if (js_enable.get()) - filelog_.enable(); - else - filelog_.disable(); - } else - cerr << "WARN: filelog.enable not boolean" << endl; - } - - if (js.contains("enable_color")) { - auto &js_enable = js.at("enable_color"); - if (js_enable.is_boolean()) { - filelog_.enableColor(js_enable.get()); - } else - cerr << "WARN: filelog.enable_color not boolean" << endl; - } } while (false); } @@ -153,6 +186,7 @@ bool Log::initialize(const char *proc_name, Context &ctx, const Json &cfg) void Log::cleanup() { filelog_.cleanup(); + filelog_.disable(); } void Log::buildTerminalNodes(TerminalNodes &term) diff --git a/main/log.h b/modules/main/log.h similarity index 100% rename from main/log.h rename to modules/main/log.h diff --git a/main/main.cpp b/modules/main/main.cpp similarity index 99% rename from main/main.cpp rename to modules/main/main.cpp index 52c7bb8e31afe8fae4ef1a9ceabea82be7180397..8da7fcd76805da80dcec4f170532e6c64607c913 100644 --- a/main/main.cpp +++ b/modules/main/main.cpp @@ -104,8 +104,6 @@ int Main(int argc, char **argv) } LogInfo("Bye!"); - - log.cleanup(); return 0; } diff --git a/main/main.h b/modules/main/main.h similarity index 100% rename from main/main.h rename to modules/main/main.h diff --git a/main/misc.cpp b/modules/main/misc.cpp similarity index 100% rename from main/misc.cpp rename to modules/main/misc.cpp diff --git a/main/module.cpp b/modules/main/module.cpp similarity index 100% rename from main/module.cpp rename to modules/main/module.cpp diff --git a/main/module.h b/modules/main/module.h similarity index 100% rename from main/module.h rename to modules/main/module.h diff --git a/main/signal.cpp b/modules/main/signal.cpp similarity index 100% rename from main/signal.cpp rename to modules/main/signal.cpp diff --git a/mqtt/Makefile b/modules/mqtt/Makefile similarity index 88% rename from mqtt/Makefile rename to modules/mqtt/Makefile index 8efb1ebba8302a6f950a2598683c5278342dbaeb..a63747f22dea23c6130c8b6ec3961765f04f67be 100644 --- a/mqtt/Makefile +++ b/modules/mqtt/Makefile @@ -15,4 +15,4 @@ TEST_LDFLAGS := $(LDFLAGS) -ltbox_event -ltbox_base -lmosquitto -levent_core -le ENABLE_SHARED_LIB = no -include ../tools/lib_common.mk +include $(TOP_DIR)/tools/lib_common.mk diff --git a/mqtt/client.cpp b/modules/mqtt/client.cpp similarity index 100% rename from mqtt/client.cpp rename to modules/mqtt/client.cpp diff --git a/mqtt/client.h b/modules/mqtt/client.h similarity index 100% rename from mqtt/client.h rename to modules/mqtt/client.h diff --git a/network/Makefile b/modules/network/Makefile similarity index 95% rename from network/Makefile rename to modules/network/Makefile index 0e4267ca94314d859be71c78b57047f8df2fd07d..939411f0aede9f27dafeaef175cdfe3fcc707bbb 100644 --- a/network/Makefile +++ b/modules/network/Makefile @@ -51,4 +51,4 @@ TEST_LDFLAGS := $(LDFLAGS) -ltbox_event -ltbox_base ENABLE_SHARED_LIB = no -include ../tools/lib_common.mk +include $(TOP_DIR)/tools/lib_common.mk diff --git a/network/README b/modules/network/README similarity index 100% rename from network/README rename to modules/network/README diff --git a/network/buffer.cpp b/modules/network/buffer.cpp similarity index 100% rename from network/buffer.cpp rename to modules/network/buffer.cpp diff --git a/network/buffer.h b/modules/network/buffer.h similarity index 100% rename from network/buffer.h rename to modules/network/buffer.h diff --git a/network/buffer_test.cpp b/modules/network/buffer_test.cpp similarity index 100% rename from network/buffer_test.cpp rename to modules/network/buffer_test.cpp diff --git a/network/buffered_fd.cpp b/modules/network/buffered_fd.cpp similarity index 100% rename from network/buffered_fd.cpp rename to modules/network/buffered_fd.cpp diff --git a/network/buffered_fd.h b/modules/network/buffered_fd.h similarity index 100% rename from network/buffered_fd.h rename to modules/network/buffered_fd.h diff --git a/network/buffered_fd_test.cpp b/modules/network/buffered_fd_test.cpp similarity index 100% rename from network/buffered_fd_test.cpp rename to modules/network/buffered_fd_test.cpp diff --git a/network/byte_stream.h b/modules/network/byte_stream.h similarity index 100% rename from network/byte_stream.h rename to modules/network/byte_stream.h diff --git a/network/fd.cpp b/modules/network/fd.cpp similarity index 100% rename from network/fd.cpp rename to modules/network/fd.cpp diff --git a/network/fd.h b/modules/network/fd.h similarity index 100% rename from network/fd.h rename to modules/network/fd.h diff --git a/network/fd_test.cpp b/modules/network/fd_test.cpp similarity index 100% rename from network/fd_test.cpp rename to modules/network/fd_test.cpp diff --git a/network/ip_address.cpp b/modules/network/ip_address.cpp similarity index 100% rename from network/ip_address.cpp rename to modules/network/ip_address.cpp diff --git a/network/ip_address.h b/modules/network/ip_address.h similarity index 100% rename from network/ip_address.h rename to modules/network/ip_address.h diff --git a/network/ip_address_test.cpp b/modules/network/ip_address_test.cpp similarity index 100% rename from network/ip_address_test.cpp rename to modules/network/ip_address_test.cpp diff --git a/network/sockaddr.cpp b/modules/network/sockaddr.cpp similarity index 100% rename from network/sockaddr.cpp rename to modules/network/sockaddr.cpp diff --git a/network/sockaddr.h b/modules/network/sockaddr.h similarity index 100% rename from network/sockaddr.h rename to modules/network/sockaddr.h diff --git a/network/sockaddr_test.cpp b/modules/network/sockaddr_test.cpp similarity index 100% rename from network/sockaddr_test.cpp rename to modules/network/sockaddr_test.cpp diff --git a/network/socket_fd.cpp b/modules/network/socket_fd.cpp similarity index 100% rename from network/socket_fd.cpp rename to modules/network/socket_fd.cpp diff --git a/network/socket_fd.h b/modules/network/socket_fd.h similarity index 100% rename from network/socket_fd.h rename to modules/network/socket_fd.h diff --git a/network/stdio_stream.cpp b/modules/network/stdio_stream.cpp similarity index 100% rename from network/stdio_stream.cpp rename to modules/network/stdio_stream.cpp diff --git a/network/stdio_stream.h b/modules/network/stdio_stream.h similarity index 100% rename from network/stdio_stream.h rename to modules/network/stdio_stream.h diff --git a/network/tcp_acceptor.cpp b/modules/network/tcp_acceptor.cpp similarity index 100% rename from network/tcp_acceptor.cpp rename to modules/network/tcp_acceptor.cpp diff --git a/network/tcp_acceptor.h b/modules/network/tcp_acceptor.h similarity index 100% rename from network/tcp_acceptor.h rename to modules/network/tcp_acceptor.h diff --git a/network/tcp_client.cpp b/modules/network/tcp_client.cpp similarity index 100% rename from network/tcp_client.cpp rename to modules/network/tcp_client.cpp diff --git a/network/tcp_client.h b/modules/network/tcp_client.h similarity index 100% rename from network/tcp_client.h rename to modules/network/tcp_client.h diff --git a/network/tcp_connection.cpp b/modules/network/tcp_connection.cpp similarity index 100% rename from network/tcp_connection.cpp rename to modules/network/tcp_connection.cpp diff --git a/network/tcp_connection.h b/modules/network/tcp_connection.h similarity index 100% rename from network/tcp_connection.h rename to modules/network/tcp_connection.h diff --git a/network/tcp_connector.cpp b/modules/network/tcp_connector.cpp similarity index 100% rename from network/tcp_connector.cpp rename to modules/network/tcp_connector.cpp diff --git a/network/tcp_connector.h b/modules/network/tcp_connector.h similarity index 100% rename from network/tcp_connector.h rename to modules/network/tcp_connector.h diff --git a/network/tcp_server.cpp b/modules/network/tcp_server.cpp similarity index 100% rename from network/tcp_server.cpp rename to modules/network/tcp_server.cpp diff --git a/network/tcp_server.h b/modules/network/tcp_server.h similarity index 100% rename from network/tcp_server.h rename to modules/network/tcp_server.h diff --git a/network/uart.cpp b/modules/network/uart.cpp similarity index 100% rename from network/uart.cpp rename to modules/network/uart.cpp diff --git a/network/uart.h b/modules/network/uart.h similarity index 100% rename from network/uart.h rename to modules/network/uart.h diff --git a/network/uart_test.cpp b/modules/network/uart_test.cpp similarity index 100% rename from network/uart_test.cpp rename to modules/network/uart_test.cpp diff --git a/network/udp_socket.cpp b/modules/network/udp_socket.cpp similarity index 100% rename from network/udp_socket.cpp rename to modules/network/udp_socket.cpp diff --git a/network/udp_socket.h b/modules/network/udp_socket.h similarity index 100% rename from network/udp_socket.h rename to modules/network/udp_socket.h diff --git a/network/udp_socket_test.cpp b/modules/network/udp_socket_test.cpp similarity index 100% rename from network/udp_socket_test.cpp rename to modules/network/udp_socket_test.cpp diff --git a/terminal/Makefile b/modules/terminal/Makefile similarity index 95% rename from terminal/Makefile rename to modules/terminal/Makefile index b80a7006f0ac2ed43ee86ea84722d1be9991906d..60ea789609625057c73ac43b4ad3bb63b7a535c6 100644 --- a/terminal/Makefile +++ b/modules/terminal/Makefile @@ -36,4 +36,4 @@ TEST_CPP_SRC_FILES = \ TEST_LDFLAGS := $(LDFLAGS) -ltbox_network -ltbox_event -ltbox_util -ltbox_base -levent_core -lev ENABLE_SHARED_LIB = no -include ../tools/lib_common.mk +include $(TOP_DIR)/tools/lib_common.mk diff --git a/terminal/README.md b/modules/terminal/README.md similarity index 100% rename from terminal/README.md rename to modules/terminal/README.md diff --git a/terminal/connection.h b/modules/terminal/connection.h similarity index 100% rename from terminal/connection.h rename to modules/terminal/connection.h diff --git a/terminal/impl/dir_node.cpp b/modules/terminal/impl/dir_node.cpp similarity index 100% rename from terminal/impl/dir_node.cpp rename to modules/terminal/impl/dir_node.cpp diff --git a/terminal/impl/dir_node.h b/modules/terminal/impl/dir_node.h similarity index 100% rename from terminal/impl/dir_node.h rename to modules/terminal/impl/dir_node.h diff --git a/terminal/impl/func_node.cpp b/modules/terminal/impl/func_node.cpp similarity index 100% rename from terminal/impl/func_node.cpp rename to modules/terminal/impl/func_node.cpp diff --git a/terminal/impl/func_node.h b/modules/terminal/impl/func_node.h similarity index 100% rename from terminal/impl/func_node.h rename to modules/terminal/impl/func_node.h diff --git a/terminal/impl/inner_types.h b/modules/terminal/impl/inner_types.h similarity index 100% rename from terminal/impl/inner_types.h rename to modules/terminal/impl/inner_types.h diff --git a/terminal/impl/key_event_scanner.cpp b/modules/terminal/impl/key_event_scanner.cpp similarity index 100% rename from terminal/impl/key_event_scanner.cpp rename to modules/terminal/impl/key_event_scanner.cpp diff --git a/terminal/impl/key_event_scanner.h b/modules/terminal/impl/key_event_scanner.h similarity index 100% rename from terminal/impl/key_event_scanner.h rename to modules/terminal/impl/key_event_scanner.h diff --git a/terminal/impl/key_event_scanner_test.cpp b/modules/terminal/impl/key_event_scanner_test.cpp similarity index 100% rename from terminal/impl/key_event_scanner_test.cpp rename to modules/terminal/impl/key_event_scanner_test.cpp diff --git a/terminal/impl/node.h b/modules/terminal/impl/node.h similarity index 100% rename from terminal/impl/node.h rename to modules/terminal/impl/node.h diff --git a/terminal/impl/service/tcp_rpc.cpp b/modules/terminal/impl/service/tcp_rpc.cpp similarity index 100% rename from terminal/impl/service/tcp_rpc.cpp rename to modules/terminal/impl/service/tcp_rpc.cpp diff --git a/terminal/impl/service/tcp_rpc.h b/modules/terminal/impl/service/tcp_rpc.h similarity index 100% rename from terminal/impl/service/tcp_rpc.h rename to modules/terminal/impl/service/tcp_rpc.h diff --git a/terminal/impl/service/telnetd.cpp b/modules/terminal/impl/service/telnetd.cpp similarity index 100% rename from terminal/impl/service/telnetd.cpp rename to modules/terminal/impl/service/telnetd.cpp diff --git a/terminal/impl/service/telnetd.h b/modules/terminal/impl/service/telnetd.h similarity index 100% rename from terminal/impl/service/telnetd.h rename to modules/terminal/impl/service/telnetd.h diff --git a/terminal/impl/session_context.h b/modules/terminal/impl/session_context.h similarity index 100% rename from terminal/impl/session_context.h rename to modules/terminal/impl/session_context.h diff --git a/terminal/impl/terminal.cpp b/modules/terminal/impl/terminal.cpp similarity index 100% rename from terminal/impl/terminal.cpp rename to modules/terminal/impl/terminal.cpp diff --git a/terminal/impl/terminal.h b/modules/terminal/impl/terminal.h similarity index 100% rename from terminal/impl/terminal.h rename to modules/terminal/impl/terminal.h diff --git a/terminal/impl/terminal_commands.cpp b/modules/terminal/impl/terminal_commands.cpp similarity index 100% rename from terminal/impl/terminal_commands.cpp rename to modules/terminal/impl/terminal_commands.cpp diff --git a/terminal/impl/terminal_key_events.cpp b/modules/terminal/impl/terminal_key_events.cpp similarity index 100% rename from terminal/impl/terminal_key_events.cpp rename to modules/terminal/impl/terminal_key_events.cpp diff --git a/terminal/impl/terminal_nodes.cpp b/modules/terminal/impl/terminal_nodes.cpp similarity index 100% rename from terminal/impl/terminal_nodes.cpp rename to modules/terminal/impl/terminal_nodes.cpp diff --git a/terminal/service/tcp_rpc.cpp b/modules/terminal/service/tcp_rpc.cpp similarity index 100% rename from terminal/service/tcp_rpc.cpp rename to modules/terminal/service/tcp_rpc.cpp diff --git a/terminal/service/tcp_rpc.h b/modules/terminal/service/tcp_rpc.h similarity index 100% rename from terminal/service/tcp_rpc.h rename to modules/terminal/service/tcp_rpc.h diff --git a/terminal/service/telnetd.cpp b/modules/terminal/service/telnetd.cpp similarity index 100% rename from terminal/service/telnetd.cpp rename to modules/terminal/service/telnetd.cpp diff --git a/terminal/service/telnetd.h b/modules/terminal/service/telnetd.h similarity index 100% rename from terminal/service/telnetd.h rename to modules/terminal/service/telnetd.h diff --git a/terminal/session.cpp b/modules/terminal/session.cpp similarity index 100% rename from terminal/session.cpp rename to modules/terminal/session.cpp diff --git a/terminal/session.h b/modules/terminal/session.h similarity index 100% rename from terminal/session.h rename to modules/terminal/session.h diff --git a/terminal/terminal.cpp b/modules/terminal/terminal.cpp similarity index 100% rename from terminal/terminal.cpp rename to modules/terminal/terminal.cpp diff --git a/terminal/terminal.h b/modules/terminal/terminal.h similarity index 100% rename from terminal/terminal.h rename to modules/terminal/terminal.h diff --git a/terminal/terminal_interact.h b/modules/terminal/terminal_interact.h similarity index 100% rename from terminal/terminal_interact.h rename to modules/terminal/terminal_interact.h diff --git a/terminal/terminal_nodes.h b/modules/terminal/terminal_nodes.h similarity index 96% rename from terminal/terminal_nodes.h rename to modules/terminal/terminal_nodes.h index ad9ae0e855a91d1b800d18fe4ce713e3f3186105..b09b052078d5bead4ee696dfd5c164d5b9a30c47 100644 --- a/terminal/terminal_nodes.h +++ b/modules/terminal/terminal_nodes.h @@ -2,6 +2,7 @@ #define TBOX_TERMINAL_NODES_H_20220214 #include "types.h" +#include "session.h" namespace tbox { namespace terminal { diff --git a/terminal/types.h b/modules/terminal/types.h similarity index 100% rename from terminal/types.h rename to modules/terminal/types.h diff --git a/util/Makefile b/modules/util/Makefile similarity index 90% rename from util/Makefile rename to modules/util/Makefile index 797633b004400c443c0619d01c0eef2a4c076c67..22563a64d7d4babf245b77264233633916f4f95f 100644 --- a/util/Makefile +++ b/modules/util/Makefile @@ -43,8 +43,8 @@ TEST_CPP_SRC_FILES = \ state_machine_test.cpp \ async_pipe_test.cpp \ -TEST_LDFLAGS := $(LDFLAGS) -ltbox_base +TEST_LDFLAGS := $(LDFLAGS) -ltbox_base -ldl ENABLE_SHARED_LIB = no -include ../tools/lib_common.mk +include $(TOP_DIR)/tools/lib_common.mk diff --git a/util/argument_parser.cpp b/modules/util/argument_parser.cpp similarity index 100% rename from util/argument_parser.cpp rename to modules/util/argument_parser.cpp diff --git a/util/argument_parser.h b/modules/util/argument_parser.h similarity index 100% rename from util/argument_parser.h rename to modules/util/argument_parser.h diff --git a/util/argument_parser_test.cpp b/modules/util/argument_parser_test.cpp similarity index 100% rename from util/argument_parser_test.cpp rename to modules/util/argument_parser_test.cpp diff --git a/util/async_pipe.cpp b/modules/util/async_pipe.cpp similarity index 100% rename from util/async_pipe.cpp rename to modules/util/async_pipe.cpp diff --git a/util/async_pipe.h b/modules/util/async_pipe.h similarity index 100% rename from util/async_pipe.h rename to modules/util/async_pipe.h diff --git a/util/async_pipe_test.cpp b/modules/util/async_pipe_test.cpp similarity index 100% rename from util/async_pipe_test.cpp rename to modules/util/async_pipe_test.cpp diff --git a/util/backtrace.cpp b/modules/util/backtrace.cpp similarity index 100% rename from util/backtrace.cpp rename to modules/util/backtrace.cpp diff --git a/util/backtrace.h b/modules/util/backtrace.h similarity index 100% rename from util/backtrace.h rename to modules/util/backtrace.h diff --git a/util/fs.cpp b/modules/util/fs.cpp similarity index 100% rename from util/fs.cpp rename to modules/util/fs.cpp diff --git a/util/fs.h b/modules/util/fs.h similarity index 100% rename from util/fs.h rename to modules/util/fs.h diff --git a/util/fs_test.cpp b/modules/util/fs_test.cpp similarity index 100% rename from util/fs_test.cpp rename to modules/util/fs_test.cpp diff --git a/util/pid_file.cpp b/modules/util/pid_file.cpp similarity index 100% rename from util/pid_file.cpp rename to modules/util/pid_file.cpp diff --git a/util/pid_file.h b/modules/util/pid_file.h similarity index 100% rename from util/pid_file.h rename to modules/util/pid_file.h diff --git a/util/pid_file_test.cpp b/modules/util/pid_file_test.cpp similarity index 100% rename from util/pid_file_test.cpp rename to modules/util/pid_file_test.cpp diff --git a/util/serializer.cpp b/modules/util/serializer.cpp similarity index 83% rename from util/serializer.cpp rename to modules/util/serializer.cpp index a354e2ea676907ea71256ea69c1d8b53b9ab03a9..853295a28857cadb176eb04fd08aad1ca5a45c8e 100644 --- a/util/serializer.cpp +++ b/modules/util/serializer.cpp @@ -22,6 +22,18 @@ Serializer::Serializer(std::vector &block, Endian endian) : endian_(endian) { } +bool Serializer::extendSize(size_t need_size) +{ + size_t whole_size = pos_ + need_size; + if (type_ == kRaw) + return whole_size <= size_; + else { + p_block_->resize(whole_size); + start_ = p_block_->data(); + return true; + } +} + bool Serializer::append(uint8_t in) { if (!extendSize(1)) @@ -107,25 +119,35 @@ bool Serializer::append(const void *p_in, size_t size) if (!extendSize(size)) return false; - uint8_t *p = start_ + pos_; - memcpy(p, p_in, size); + uint8_t *p_out = start_ + pos_; + memcpy(p_out, p_in, size); pos_ += size; return true; } -bool Serializer::extendSize(size_t need_size) +bool Serializer::appendPOD(const void *p, size_t size) { - size_t whole_size = pos_ + need_size; - if (type_ == kRaw) - return whole_size <= size_; - else { - p_block_->resize(whole_size); - start_ = p_block_->data(); - return true; + if (!extendSize(size)) + return false; + + uint8_t *p_out = start_ + pos_; + if (endian_ == Endian::kLittle) { + memcpy(p_out, p, size); + } else { + //! 倒序写入 + const uint8_t *p_in = static_cast(p); + p_out += size - 1; + size_t times = size; + while (times-- > 0) + *p_out-- = *p_in++; } + + pos_ += size; + return true; } + ////////////// // 反序列化 // ////////////// @@ -137,6 +159,11 @@ Deserializer::Deserializer(const void *start, size_t size, Endian endian) : pos_(0) { } +bool Deserializer::checkSize(size_t need_size) const +{ + return (pos_ + need_size) <= size_; +} + bool Deserializer::fetch(uint8_t &out) { if (!checkSize(1)) @@ -219,13 +246,33 @@ bool Deserializer::fetch(uint64_t &out) return true; } -bool Deserializer::fetch(void *p_out, size_t size) +bool Deserializer::fetch(void *p, size_t size) { if (!checkSize(size)) return false; - const uint8_t *p = start_ + pos_; - memcpy(p_out, p, size); + const uint8_t *p_in = start_ + pos_; + memcpy(p, p_in, size); + + pos_ += size; + return true; +} + +bool Deserializer::fetchPOD(void *p, size_t size) +{ + if (!checkSize(size)) + return false; + + const uint8_t *p_in = start_ + pos_; + if (endian_ == Endian::kLittle) { + memcpy(p, p_in, size); + } else { + //! 倒序读出 + uint8_t *p_out = static_cast(p) + size - 1; + size_t times = size; + while (times-- > 0) + *p_out-- = *p_in++; + } pos_ += size; return true; @@ -242,11 +289,6 @@ const void* Deserializer::fetchNoCopy(size_t size) return p; } -bool Deserializer::checkSize(size_t need_size) const -{ - return (pos_ + need_size) <= size_; -} - } } @@ -261,8 +303,8 @@ Serializer& operator << (Serializer &s, uint32_t in) { s.append(in); return s; } Serializer& operator << (Serializer &s, int32_t in) { s.append(static_cast(in)); return s; } Serializer& operator << (Serializer &s, uint64_t in) { s.append(in); return s; } Serializer& operator << (Serializer &s, int64_t in) { s.append(static_cast(in)); return s; } -Serializer& operator << (Serializer &s, float in) { s.append(*reinterpret_cast(&in)); return s; } -Serializer& operator << (Serializer &s, double in) { s.append(*reinterpret_cast(&in)); return s; } +Serializer& operator << (Serializer &s, float in) { s.appendPOD(&in, sizeof(in)); return s; } +Serializer& operator << (Serializer &s, double in) { s.appendPOD(&in, sizeof(in)); return s; } Deserializer& operator >> (Deserializer &s, Endian endian) { s.setEndian(endian); return s; } Deserializer& operator >> (Deserializer &s, uint8_t &out) { s.fetch(out); return s; } @@ -273,5 +315,5 @@ Deserializer& operator >> (Deserializer &s, uint32_t &out) { s.fetch(out); retur Deserializer& operator >> (Deserializer &s, int32_t &out) { s.fetch(*((uint32_t*)&out)); return s; } Deserializer& operator >> (Deserializer &s, uint64_t &out) { s.fetch(out); return s; } Deserializer& operator >> (Deserializer &s, int64_t &out) { s.fetch(*((uint64_t*)&out)); return s; } -Deserializer& operator >> (Deserializer &s, float &out) { s.fetch(*reinterpret_cast(&out)); return s; } -Deserializer& operator >> (Deserializer &s, double &out) { s.fetch(*reinterpret_cast(&out)); return s; } +Deserializer& operator >> (Deserializer &s, float &out) { s.fetchPOD(&out, sizeof(out)); return s; } +Deserializer& operator >> (Deserializer &s, double &out) { s.fetchPOD(&out, sizeof(out)); return s; } diff --git a/util/serializer.h b/modules/util/serializer.h similarity index 97% rename from util/serializer.h rename to modules/util/serializer.h index 6788e83271c6b3358e3677acbd43b6dc7aea83b9..a056bf51d726a983bf26fd6fd9758b44a2ab0d18 100644 --- a/util/serializer.h +++ b/modules/util/serializer.h @@ -23,6 +23,7 @@ class Serializer { bool append(uint32_t in); bool append(uint64_t in); bool append(const void *p, size_t s); + bool appendPOD(const void *p, size_t s); protected: bool extendSize(size_t size); @@ -50,6 +51,7 @@ class Deserializer { bool fetch(uint32_t &out); bool fetch(uint64_t &out); bool fetch(void *p, size_t s); + bool fetchPOD(void *p, size_t s); const void* fetchNoCopy(size_t s); protected: diff --git a/util/serializer_test.cpp b/modules/util/serializer_test.cpp similarity index 100% rename from util/serializer_test.cpp rename to modules/util/serializer_test.cpp diff --git a/util/split_cmdline.cpp b/modules/util/split_cmdline.cpp similarity index 100% rename from util/split_cmdline.cpp rename to modules/util/split_cmdline.cpp diff --git a/util/split_cmdline.h b/modules/util/split_cmdline.h similarity index 100% rename from util/split_cmdline.h rename to modules/util/split_cmdline.h diff --git a/util/split_cmdline_test.cpp b/modules/util/split_cmdline_test.cpp similarity index 100% rename from util/split_cmdline_test.cpp rename to modules/util/split_cmdline_test.cpp diff --git a/util/state_machine.cpp b/modules/util/state_machine.cpp similarity index 99% rename from util/state_machine.cpp rename to modules/util/state_machine.cpp index a83cb35a891be0b188de541ec3809037849d7ce7..a6fbff665bc8062d6a4860f5023b304802df41a2 100644 --- a/util/state_machine.cpp +++ b/modules/util/state_machine.cpp @@ -122,7 +122,7 @@ bool StateMachine::isTerminated() const /////////////////////// -StateMachine::Impl::State StateMachine::Impl::_term_state_ = { 0 }; +StateMachine::Impl::State StateMachine::Impl::_term_state_ = { 0, nullptr, nullptr, nullptr, { } }; StateMachine::Impl::~Impl() { @@ -142,7 +142,7 @@ bool StateMachine::Impl::newState(StateID state_id, const ActionFunc &enter_acti return false; } - auto new_state = new State { state_id, enter_action, exit_action, nullptr }; + auto new_state = new State { state_id, enter_action, exit_action, nullptr, { } }; states_[state_id] = new_state; return true; diff --git a/util/state_machine.h b/modules/util/state_machine.h similarity index 100% rename from util/state_machine.h rename to modules/util/state_machine.h diff --git a/util/state_machine_test.cpp b/modules/util/state_machine_test.cpp similarity index 100% rename from util/state_machine_test.cpp rename to modules/util/state_machine_test.cpp diff --git a/util/string.cpp b/modules/util/string.cpp similarity index 100% rename from util/string.cpp rename to modules/util/string.cpp diff --git a/util/string.h b/modules/util/string.h similarity index 100% rename from util/string.h rename to modules/util/string.h diff --git a/util/string_test.cpp b/modules/util/string_test.cpp similarity index 100% rename from util/string_test.cpp rename to modules/util/string_test.cpp diff --git a/util/thread_wdog.cpp b/modules/util/thread_wdog.cpp similarity index 100% rename from util/thread_wdog.cpp rename to modules/util/thread_wdog.cpp diff --git a/util/thread_wdog.h b/modules/util/thread_wdog.h similarity index 100% rename from util/thread_wdog.h rename to modules/util/thread_wdog.h diff --git a/util/thread_wdog_test.cpp b/modules/util/thread_wdog_test.cpp similarity index 100% rename from util/thread_wdog_test.cpp rename to modules/util/thread_wdog_test.cpp diff --git a/util/time_counter.cpp b/modules/util/time_counter.cpp similarity index 63% rename from util/time_counter.cpp rename to modules/util/time_counter.cpp index c8fc0062ae3487f49833f2d4cb37ec2640c46abc..b850df91354e2ba2f5bb13b1c97b24f5434cd17f 100644 --- a/util/time_counter.cpp +++ b/modules/util/time_counter.cpp @@ -1,9 +1,10 @@ #include "time_counter.h" -#include +#include namespace tbox { namespace util { +using namespace std; using namespace std::chrono; TimeCounter::TimeCounter(const char *file_name, const char *func_name, int line) : @@ -21,11 +22,13 @@ TimeCounter::~TimeCounter() void TimeCounter::stop() { + auto now = steady_clock::now(); + if (stoped_) return; - auto cost_us = duration_cast(steady_clock::now() - start_time_point_).count(); - LogPrintfFunc("TC", func_name_, file_name_, line_, LOG_LEVEL_TRACE, true, "timecost: %u us", cost_us); + auto cost = now - start_time_point_; + cout << "TimeCounter at " << file_name_ << ",L" << line_ << " in " << func_name_ << "(): " << cost.count() << " ns" << endl; stoped_ = true; } diff --git a/util/time_counter.h b/modules/util/time_counter.h similarity index 87% rename from util/time_counter.h rename to modules/util/time_counter.h index 0dd717fe88efcb601f0fd9ec9172f8dc8e565235..87e27133818d1fb66807adfe0149d97e7ea76d19 100644 --- a/util/time_counter.h +++ b/modules/util/time_counter.h @@ -26,7 +26,8 @@ class TimeCounter { } //! 无名计时器,用行号命名 -#define _TimeCounter_0(file,func,line) tbox::util::TimeCounter _timer_counter_at_##line(file,func,line) +#define _TimeCounter_1(file,func,line) tbox::util::TimeCounter _timer_counter_at_##line(file,func,line) +#define _TimeCounter_0(file,func,line) _TimeCounter_1(file,func,line) #define SetTimeCounter() _TimeCounter_0(__FILE__, __func__, __LINE__) //! 有名计时器 diff --git a/util/time_counter_test.cpp b/modules/util/time_counter_test.cpp similarity index 96% rename from util/time_counter_test.cpp rename to modules/util/time_counter_test.cpp index 5418912d8bbdd8262186ea7cee2cdfbde10eb6fd..3ea9a957c88f7efb8e15db125ce03a56e0db2300 100644 --- a/util/time_counter_test.cpp +++ b/modules/util/time_counter_test.cpp @@ -10,6 +10,7 @@ TEST(TimeCounter, basic) SetTimeCounter(); std::this_thread::sleep_for(std::chrono::seconds(1)); + SetTimeCounter(); } TEST(TimeCounter, stop) diff --git a/mqtt/example/basic/.gitignore b/mqtt/example/basic/.gitignore deleted file mode 100644 index 3359baffe28daca6692ee2a3c46c71700b21a114..0000000000000000000000000000000000000000 --- a/mqtt/example/basic/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/sub -/pub -/conn diff --git a/mqtt/example/basic/Makefile b/mqtt/example/basic/Makefile deleted file mode 100644 index c3b8f606211e76825d2f1f9bc406fc7b4c91f3ba..0000000000000000000000000000000000000000 --- a/mqtt/example/basic/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -include ../build_env.mk - -TARGET := sub pub conn -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_mqtt -ltbox_event -ltbox_base -lmosquitto -lpthread - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGET) - -sub : sub.cpp - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) - -pub : pub.cpp - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) - -conn : conn.cpp - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) - -clean: - rm -rf $(TARGET) diff --git a/mqtt/example/build_env.mk b/mqtt/example/build_env.mk deleted file mode 100644 index 58481118dd79b3db71ee35ab91baf0bfe01358c0..0000000000000000000000000000000000000000 --- a/mqtt/example/build_env.mk +++ /dev/null @@ -1,29 +0,0 @@ -STAGING_DIR := ../../../.staging - -STAGING_INCLUDE := $(STAGING_DIR)/include -STAGING_LIB := $(STAGING_DIR)/lib - -CCFLAGS := -I$(STAGING_INCLUDE) -I$(CONSTANT_INCLUDE) -CFLAGS := $(CCFLAGS) -std=c99 -CXXFLAGS := $(CCFLAGS) -std=c++11 -LDFLAGS := -L$(STAGING_LIB) -INSTALL_DIR := $(STAGING_DIR) -DESTDIR := $(STAGING_DIR) -prefix := - -TOOLCHAIN_PREFIX := -AR := $(TOOLCHAIN_PREFIX)ar -AS := $(TOOLCHAIN_PREFIX)as -CXX := $(TOOLCHAIN_PREFIX)g++ -CC := $(TOOLCHAIN_PREFIX)gcc -NM := $(TOOLCHAIN_PREFIX)nm -OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy -OBJDUMP := $(TOOLCHAIN_PREFIX)objdump -STRINGS := $(TOOLCHAIN_PREFIX)strings -SSTRIP := $(TOOLCHAIN_PREFIX)sstrip -LSTRIP := $(TOOLCHAIN_PREFIX)lstrip -STRIP := $(TOOLCHAIN_PREFIX)strip - -export STAGING_INCLUDE STAGING_LIB INSTALL_DIR DESTDIR prefix -export AR AS CC NM OBJCOPY OBJDUMP CXX STRIP SSTRIP STRINGS LSTRIP -export CFLAGS CXXFLAGS LDFLAGS diff --git a/network/example/buffered_fd/.gitignore b/network/example/buffered_fd/.gitignore deleted file mode 100644 index 95cbf8c615c93901fcaa17023ad6d436d88a8b6b..0000000000000000000000000000000000000000 --- a/network/example/buffered_fd/.gitignore +++ /dev/null @@ -1 +0,0 @@ -io_echo diff --git a/network/example/buffered_fd/Makefile b/network/example/buffered_fd/Makefile deleted file mode 100644 index 57fd8decaf757c6d5da6269964bccb1d0a1085a9..0000000000000000000000000000000000000000 --- a/network/example/buffered_fd/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -include ../build_env.mk - -TARGET := io_echo -OBJECTS := io_echo.o -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_network -ltbox_eventx -ltbox_event -ltbox_base -levent_core -lev -lpthread - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGET) - -$(TARGET) : $(OBJECTS) - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf $(OBJECTS) - -distclean: clean - rm -f $(TARGET) diff --git a/network/example/build_env.mk b/network/example/build_env.mk deleted file mode 100644 index 58481118dd79b3db71ee35ab91baf0bfe01358c0..0000000000000000000000000000000000000000 --- a/network/example/build_env.mk +++ /dev/null @@ -1,29 +0,0 @@ -STAGING_DIR := ../../../.staging - -STAGING_INCLUDE := $(STAGING_DIR)/include -STAGING_LIB := $(STAGING_DIR)/lib - -CCFLAGS := -I$(STAGING_INCLUDE) -I$(CONSTANT_INCLUDE) -CFLAGS := $(CCFLAGS) -std=c99 -CXXFLAGS := $(CCFLAGS) -std=c++11 -LDFLAGS := -L$(STAGING_LIB) -INSTALL_DIR := $(STAGING_DIR) -DESTDIR := $(STAGING_DIR) -prefix := - -TOOLCHAIN_PREFIX := -AR := $(TOOLCHAIN_PREFIX)ar -AS := $(TOOLCHAIN_PREFIX)as -CXX := $(TOOLCHAIN_PREFIX)g++ -CC := $(TOOLCHAIN_PREFIX)gcc -NM := $(TOOLCHAIN_PREFIX)nm -OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy -OBJDUMP := $(TOOLCHAIN_PREFIX)objdump -STRINGS := $(TOOLCHAIN_PREFIX)strings -SSTRIP := $(TOOLCHAIN_PREFIX)sstrip -LSTRIP := $(TOOLCHAIN_PREFIX)lstrip -STRIP := $(TOOLCHAIN_PREFIX)strip - -export STAGING_INCLUDE STAGING_LIB INSTALL_DIR DESTDIR prefix -export AR AS CC NM OBJCOPY OBJDUMP CXX STRIP SSTRIP STRINGS LSTRIP -export CFLAGS CXXFLAGS LDFLAGS diff --git a/network/example/stdio_stream/.gitignore b/network/example/stdio_stream/.gitignore deleted file mode 100644 index af4bfae01f3964c046daeada0fe874f4bb5ac842..0000000000000000000000000000000000000000 --- a/network/example/stdio_stream/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/io_echo_1 -/io_echo_2 diff --git a/network/example/stdio_stream/Makefile b/network/example/stdio_stream/Makefile deleted file mode 100644 index ff580babcb0c1f1a5ab65d1b8f5fe9fe3c6098e3..0000000000000000000000000000000000000000 --- a/network/example/stdio_stream/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -include ../build_env.mk - -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_network -ltbox_eventx -ltbox_event -ltbox_base -levent_core -lev -lpthread - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : io_echo_1 io_echo_2 - -io_echo_1 : io_echo_1.o - $(CXX) -o $@ $^ $(LDFLAGS) - -io_echo_2 : io_echo_2.o - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf *.o - -distclean: clean - rm -f io_echo_1 io_echo_2 diff --git a/network/example/tcp_acceptor/.gitignore b/network/example/tcp_acceptor/.gitignore deleted file mode 100644 index 5aa354c633fd8bc3642da8ce2c126292262d968e..0000000000000000000000000000000000000000 --- a/network/example/tcp_acceptor/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/tcp_echo -/tcp_nc_server diff --git a/network/example/tcp_acceptor/Makefile b/network/example/tcp_acceptor/Makefile deleted file mode 100644 index a2352c0695c6d476254b4e0f670f4d9056043a98..0000000000000000000000000000000000000000 --- a/network/example/tcp_acceptor/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -include ../build_env.mk - -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_network -ltbox_eventx -ltbox_event -ltbox_base -levent_core -lev -lpthread -TARGETS = tcp_echo tcp_nc_server - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGETS) - -tcp_echo : tcp_echo.o - $(CXX) -o $@ $^ $(LDFLAGS) - -tcp_nc_server : tcp_nc_server.o - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf *.o - -distclean: clean - rm -f $(TARGETS) diff --git a/network/example/tcp_client/.gitignore b/network/example/tcp_client/.gitignore deleted file mode 100644 index 88e0b1b4b0255b3ce792b6d4e3a70b998634070e..0000000000000000000000000000000000000000 --- a/network/example/tcp_client/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/tcp_echo -/tcp_nc_client -/tcp_hex_client diff --git a/network/example/tcp_client/Makefile b/network/example/tcp_client/Makefile deleted file mode 100644 index 061edb8c959bb301dc51e25a361750c3b53d2378..0000000000000000000000000000000000000000 --- a/network/example/tcp_client/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -include ../build_env.mk - -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_network -ltbox_eventx -ltbox_event -ltbox_util -ltbox_base -levent_core -lev -lpthread -TARGETS = tcp_echo tcp_nc_client tcp_hex_client - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGETS) - -tcp_echo : tcp_echo.o - $(CXX) -o $@ $^ $(LDFLAGS) - -tcp_nc_client : tcp_nc_client.o - $(CXX) -o $@ $^ $(LDFLAGS) - -tcp_hex_client : tcp_hex_client.o - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf *.o - -distclean: clean - rm -f $(TARGETS) diff --git a/network/example/tcp_connector/.gitignore b/network/example/tcp_connector/.gitignore deleted file mode 100644 index d94f52123521a2cc776cfc6af2ce973363f94f51..0000000000000000000000000000000000000000 --- a/network/example/tcp_connector/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/tcp_echo -/tcp_nc_client diff --git a/network/example/tcp_connector/Makefile b/network/example/tcp_connector/Makefile deleted file mode 100644 index dea16c8b834321a10149be9c80c4a4b99df27420..0000000000000000000000000000000000000000 --- a/network/example/tcp_connector/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -include ../build_env.mk - -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_network -ltbox_eventx -ltbox_event -ltbox_base -levent_core -lev -lpthread -TARGETS = tcp_echo tcp_nc_client - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGETS) - -tcp_echo : tcp_echo.o - $(CXX) -o $@ $^ $(LDFLAGS) - -tcp_nc_client : tcp_nc_client.o - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf *.o - -distclean: clean - rm -f $(TARGETS) diff --git a/network/example/tcp_server/.gitignore b/network/example/tcp_server/.gitignore deleted file mode 100644 index 5aa354c633fd8bc3642da8ce2c126292262d968e..0000000000000000000000000000000000000000 --- a/network/example/tcp_server/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/tcp_echo -/tcp_nc_server diff --git a/network/example/tcp_server/Makefile b/network/example/tcp_server/Makefile deleted file mode 100644 index a2352c0695c6d476254b4e0f670f4d9056043a98..0000000000000000000000000000000000000000 --- a/network/example/tcp_server/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -include ../build_env.mk - -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_network -ltbox_eventx -ltbox_event -ltbox_base -levent_core -lev -lpthread -TARGETS = tcp_echo tcp_nc_server - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGETS) - -tcp_echo : tcp_echo.o - $(CXX) -o $@ $^ $(LDFLAGS) - -tcp_nc_server : tcp_nc_server.o - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf *.o - -distclean: clean - rm -f $(TARGETS) diff --git a/network/example/uart/.gitignore b/network/example/uart/.gitignore deleted file mode 100644 index 40f9c3359e516b5e9c4830842966acd08dc3d516..0000000000000000000000000000000000000000 --- a/network/example/uart/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/uart_tool -/uart_to_uart diff --git a/network/example/uart/Makefile b/network/example/uart/Makefile deleted file mode 100644 index 495f59b6279082d8a14993c975d94ab7ff75101a..0000000000000000000000000000000000000000 --- a/network/example/uart/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -include ../build_env.mk - -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_network -ltbox_eventx -ltbox_event -ltbox_base -levent_core -lev -lpthread - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : uart_tool uart_to_uart - -uart_tool: uart_tool.o - $(CXX) -o $@ $^ $(LDFLAGS) - -uart_to_uart : uart_to_uart.o - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf *.o - -distclean: clean - rm -f uart_tool uart_to_uart diff --git a/network/example/udp_socket/.gitignore b/network/example/udp_socket/.gitignore deleted file mode 100644 index f0b849264f8c72ee00d80f408e2608f539658491..0000000000000000000000000000000000000000 --- a/network/example/udp_socket/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/send_only -/recv_only -/request -/respond -/ping_pong -*.o diff --git a/network/example/udp_socket/Makefile b/network/example/udp_socket/Makefile deleted file mode 100644 index 2962e6684c7ab75b70c5f6fe28ad3b58d621174f..0000000000000000000000000000000000000000 --- a/network/example/udp_socket/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -include ../build_env.mk - -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_network -ltbox_eventx -ltbox_event -ltbox_base -levent_core -lev -lpthread -TARGETS = send_only recv_only request respond ping_pong - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGETS) - -send_only : send_only.o - $(CXX) -o $@ $^ $(LDFLAGS) - -recv_only : recv_only.o - $(CXX) -o $@ $^ $(LDFLAGS) - -request : request.o - $(CXX) -o $@ $^ $(LDFLAGS) - -respond : respond.o - $(CXX) -o $@ $^ $(LDFLAGS) - -ping_pong : ping_pong.o - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf *.o - -distclean: clean - rm -f $(TARGETS) diff --git a/terminal/example/build_env.mk b/terminal/example/build_env.mk deleted file mode 100644 index 58481118dd79b3db71ee35ab91baf0bfe01358c0..0000000000000000000000000000000000000000 --- a/terminal/example/build_env.mk +++ /dev/null @@ -1,29 +0,0 @@ -STAGING_DIR := ../../../.staging - -STAGING_INCLUDE := $(STAGING_DIR)/include -STAGING_LIB := $(STAGING_DIR)/lib - -CCFLAGS := -I$(STAGING_INCLUDE) -I$(CONSTANT_INCLUDE) -CFLAGS := $(CCFLAGS) -std=c99 -CXXFLAGS := $(CCFLAGS) -std=c++11 -LDFLAGS := -L$(STAGING_LIB) -INSTALL_DIR := $(STAGING_DIR) -DESTDIR := $(STAGING_DIR) -prefix := - -TOOLCHAIN_PREFIX := -AR := $(TOOLCHAIN_PREFIX)ar -AS := $(TOOLCHAIN_PREFIX)as -CXX := $(TOOLCHAIN_PREFIX)g++ -CC := $(TOOLCHAIN_PREFIX)gcc -NM := $(TOOLCHAIN_PREFIX)nm -OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy -OBJDUMP := $(TOOLCHAIN_PREFIX)objdump -STRINGS := $(TOOLCHAIN_PREFIX)strings -SSTRIP := $(TOOLCHAIN_PREFIX)sstrip -LSTRIP := $(TOOLCHAIN_PREFIX)lstrip -STRIP := $(TOOLCHAIN_PREFIX)strip - -export STAGING_INCLUDE STAGING_LIB INSTALL_DIR DESTDIR prefix -export AR AS CC NM OBJCOPY OBJDUMP CXX STRIP SSTRIP STRINGS LSTRIP -export CFLAGS CXXFLAGS LDFLAGS diff --git a/terminal/example/tcp_rpc/.gitignore b/terminal/example/tcp_rpc/.gitignore deleted file mode 100644 index 69ff7396662e25b7bcacccf28267d6573e901777..0000000000000000000000000000000000000000 --- a/terminal/example/tcp_rpc/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/demo diff --git a/terminal/example/tcp_rpc/Makefile b/terminal/example/tcp_rpc/Makefile deleted file mode 100644 index bb4d9fa9c4d8c26e8130f5c7d6944622e61e9936..0000000000000000000000000000000000000000 --- a/terminal/example/tcp_rpc/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -include ../build_env.mk - -TARGET := demo -OBJECTS := main.o -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_terminal -ltbox_util -ltbox_network -ltbox_event -ltbox_base -lpthread - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGET) - -$(TARGET) : $(OBJECTS) - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf $(OBJECTS) diff --git a/terminal/example/telnetd/.gitignore b/terminal/example/telnetd/.gitignore deleted file mode 100644 index 69ff7396662e25b7bcacccf28267d6573e901777..0000000000000000000000000000000000000000 --- a/terminal/example/telnetd/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/demo diff --git a/terminal/example/telnetd/Makefile b/terminal/example/telnetd/Makefile deleted file mode 100644 index bb4d9fa9c4d8c26e8130f5c7d6944622e61e9936..0000000000000000000000000000000000000000 --- a/terminal/example/telnetd/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -include ../build_env.mk - -TARGET := demo -OBJECTS := main.o -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_terminal -ltbox_util -ltbox_network -ltbox_event -ltbox_base -lpthread - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : $(TARGET) - -$(TARGET) : $(OBJECTS) - $(CXX) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf $(OBJECTS) diff --git a/util/example/backtrace/.gitignore b/util/example/backtrace/.gitignore deleted file mode 100644 index ae6321f86df48737f7a584bc524e879d019a5b2d..0000000000000000000000000000000000000000 --- a/util/example/backtrace/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/sample diff --git a/util/example/backtrace/Makefile b/util/example/backtrace/Makefile deleted file mode 100644 index 6b5404849aa8ee8aeae35a2e484bff7f1de274a5..0000000000000000000000000000000000000000 --- a/util/example/backtrace/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -include ../build_env.mk - -CXXFLAGS += -ggdb -DLOG_MODULE_ID='"demo"' -LDFLAGS += -L.. -ltbox_util - -CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer -LDFLAGS += -fsanitize=address -static-libasan - -all : sample - -sample: sample.o - $(CXX) -o $@ $^ $(LDFLAGS) -rdynamic - -clean: - rm -rf *.o - -distclean: clean - rm -f sample diff --git a/util/example/build_env.mk b/util/example/build_env.mk deleted file mode 100644 index 58481118dd79b3db71ee35ab91baf0bfe01358c0..0000000000000000000000000000000000000000 --- a/util/example/build_env.mk +++ /dev/null @@ -1,29 +0,0 @@ -STAGING_DIR := ../../../.staging - -STAGING_INCLUDE := $(STAGING_DIR)/include -STAGING_LIB := $(STAGING_DIR)/lib - -CCFLAGS := -I$(STAGING_INCLUDE) -I$(CONSTANT_INCLUDE) -CFLAGS := $(CCFLAGS) -std=c99 -CXXFLAGS := $(CCFLAGS) -std=c++11 -LDFLAGS := -L$(STAGING_LIB) -INSTALL_DIR := $(STAGING_DIR) -DESTDIR := $(STAGING_DIR) -prefix := - -TOOLCHAIN_PREFIX := -AR := $(TOOLCHAIN_PREFIX)ar -AS := $(TOOLCHAIN_PREFIX)as -CXX := $(TOOLCHAIN_PREFIX)g++ -CC := $(TOOLCHAIN_PREFIX)gcc -NM := $(TOOLCHAIN_PREFIX)nm -OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy -OBJDUMP := $(TOOLCHAIN_PREFIX)objdump -STRINGS := $(TOOLCHAIN_PREFIX)strings -SSTRIP := $(TOOLCHAIN_PREFIX)sstrip -LSTRIP := $(TOOLCHAIN_PREFIX)lstrip -STRIP := $(TOOLCHAIN_PREFIX)strip - -export STAGING_INCLUDE STAGING_LIB INSTALL_DIR DESTDIR prefix -export AR AS CC NM OBJCOPY OBJDUMP CXX STRIP SSTRIP STRINGS LSTRIP -export CFLAGS CXXFLAGS LDFLAGS