Skip to content

Commit

Permalink
Merge pull request #19 from lkpworkspace/dev
Browse files Browse the repository at this point in the history
- api:
  - CmdChannel GetOwnerFd修改为GetOwnerHandle,GetMainFd修改为GetMainHandle
  - 所有的枚举类型放置到class内部
  - app删除AddEvent/DelEvent/GetActorContextManager函数
  - event函数GetFd修改为GetHandle,删除ListenIOType/RetListenIOType,增加GetName函数
- fix
  - 修复ExampleWorkerInteractiveWith3rdFrame中使用CmdChannel的错误使用方法
  - 修复launcher加载错误的配置文件程序退出出core问题
- ci
  - 只支持ubuntu least构建
  - 编译参数从cmake中放到ci配置文件
- doc
  - 添加组件工程更详细的构建说明
- other:
  - mod_lib改为shared_library,只用作加载/卸载动态库,获取符号
  - 将epoll独立出来单独管理
  - 将所有集成event的对象统一使用EventManager管理
  - 所有的pthread读写锁改为使用c++17标准的读写锁
  - 安装头文件目录inc修改为include
  - 产出版本文件增加最后提交日期
  • Loading branch information
lkpworkspace authored Jul 24, 2023
2 parents bef206f + 3a3b3db commit 3ff7ec6
Show file tree
Hide file tree
Showing 47 changed files with 922 additions and 887 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.h linguist-language=C++
90 changes: 0 additions & 90 deletions .github/workflows/cmake.yml

This file was deleted.

13 changes: 13 additions & 0 deletions .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: codestyle

on: [push, pull_request]

jobs:
Ubuntu-latest:
name: codestyle
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Check code style
run: bash ${{github.workspace}}/cpplint.bash
50 changes: 50 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Linux

on: [push, pull_request]

jobs:
Ubuntu-latest:
name: GCC-C++${{matrix.std}}-${{matrix.build_type}}
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
build_type: [Release, Debug]
std: [17, 20]

steps:
- uses: actions/checkout@v3
- run: sudo apt update
- run: sudo apt install build-essential cmake ninja-build
- run: sudo apt install libjsoncpp-dev libgflags-dev libgtest-dev libgoogle-glog-dev libunwind-dev

- name: Setup Ninja
uses: ashutoshvarma/setup-ninja@master
with:
version: 1.10.0

- name: Configure CMake
env:
# glog option:
# -DNDEBUG
# -DDCHECK_ALWAYS_ON
# unit test option:
# -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined
CXXFLAGS: ${{env.CXXFLAGS}} -DNDEBUG -fPIC -Wall -Wextra -Werror -pedantic-errors -Wswitch-default -Wfloat-equal -Wshadow -Wcast-qual -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wsign-promo -Wsuggest-override
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: |
cmake -S . -B ${{github.workspace}}/build_${{matrix.build_type}} \
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install \
-G Ninja \
-Werror
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build_${{matrix.build_type}} --config ${{matrix.build_type}}
1 change: 0 additions & 1 deletion 3rd/README.md

This file was deleted.

36 changes: 10 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,6 @@ if (CMAKE_COMPILER_IS_GNUCC)
endif ()

### cpp option
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
# glog option:
# -DNDEBUG
# -DDCHECK_ALWAYS_ON
# unit test option:
# -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined
set(CMAKE_C_FLAGS
"-fPIC -Wall -Wextra -Werror -pedantic-errors \
-Wswitch-default -Wfloat-equal -Wshadow -Wcast-qual \
-DNDEBUG"
)
set(CMAKE_CXX_FLAGS
"-fPIC -Wall -Wextra -Werror -pedantic-errors \
-Wswitch-default -Wfloat-equal -Wshadow -Wcast-qual \
-Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wsign-promo -Wsuggest-override \
-DNDEBUG"
)
if (GCC_VERSION GREATER "8.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra-semi")
endif ()
Expand All @@ -46,11 +27,11 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${MYFRAME_OUTPUT_ROOT}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MYFRAME_OUTPUT_ROOT}/bin)

### install path
set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/${CMAKE_PROJECT_NAME}")
# set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/${CMAKE_PROJECT_NAME}")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(MYFRAME_TEST_DIR "test")
set(MYFRAME_BIN_DIR "bin")
set(MYFRAME_INC_DIR "inc")
set(MYFRAME_INC_DIR "include")
set(MYFRAME_LIB_DIR "lib")
set(MYFRAME_LOG_DIR "log")
set(MYFRAME_SERVICE_DIR "service")
Expand Down Expand Up @@ -89,10 +70,7 @@ endif()
### install file/dir
install(FILES
"LICENSE"
PERMISSIONS
OWNER_READ
GROUP_READ
WORLD_READ
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
DESTINATION .
)
install(DIRECTORY templates DESTINATION .)
Expand All @@ -112,8 +90,14 @@ execute_process(
OUTPUT_VARIABLE GIT_COMMIT_ID
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git show -s --format=%ci HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
install(CODE "
file(
WRITE ${CMAKE_INSTALL_PREFIX}/version.txt
\"${GIT_BRANCH}\n${GIT_COMMIT_ID}\n\")
\"${GIT_BRANCH}\n${GIT_COMMIT_ID}\n${GIT_COMMIT_DATE}\n\")
")
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,19 @@
![myframe](doc/pics/myframe.png)

## 概述
C++实现的actors框架,程序由actor和worker组成;
C++实现的组件化的编程框架,程序由actor和worker组成;
actor基于消息驱动,actor之间可以进行消息传递;
worker自驱动,可以通过消息与actor交互;
组件化的编程模式可以提高代码复用,降低程序耦合度。
适用于构建中大型项目.

## 开发/运行环境
操作系统: Ubuntu 18.04+
开发语言:C++17

## 安装依赖
参考 [github ci](.github/workflows/cmake.yml)

## 构建
```sh
mkdir build
cd build
cmake ..
# 默认安装到HOME目录
make -j4 install
```
参考 [github ci](.github/workflows/linux.yml)

## 运行
## 运行所有的example
```sh
cd ~/myframe/bin
./launcher -p app
Expand Down Expand Up @@ -102,4 +93,3 @@ extern "C" std::shared_ptr<Actor> actor_create(const std::string& actor_name) {
- [Discussions](https://github.com/lkpworkspace/myframe/discussions)
- [WIKI](https://github.com/lkpworkspace/myframe/wiki)
- [FAQ](https://github.com/lkpworkspace/myframe/wiki/FAQs)
- [TODOLIST](doc/TODOLIST.md)
4 changes: 2 additions & 2 deletions cpplint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function main() {
set -e
cd "$PWD0"
# shellcheck disable=SC2038
find '(' \
find . '(' \
-name "*.c" -or \
-name "*.cc" -or \
-name "*.h" -or \
Expand All @@ -18,7 +18,7 @@ function main() {
-name "*.hxx" -or \
-name "*.cxx" -or \
-name "*.cuh" \
')' | xargs ./cpplint.py
')' | xargs python3 ./cpplint.py
}

main "$@"
1 change: 0 additions & 1 deletion doc/TODOLIST.md

This file was deleted.

19 changes: 17 additions & 2 deletions doc/development_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,20 @@ python3 ~/myframe/tools/gen_mod_proj.py --dir="/path/to/proj_dir/" --name="mod_n
- 配置文件:
- Template.json:Service配置

### 安装
通过make install安装到框架中的组件目录中
### 组件工程构建安装
```sh
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=${myframe目录}
make -C build -j "$(nproc)" install
```

### 运行组件
```sh
cd ${myframe目录}/bin
./launcher -c ${组件名}.json -p app
```

### 查看运行日志
```sh
cd ${myframe目录}/log
vi ${日志}
```
27 changes: 12 additions & 15 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,36 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.10)

### actor
add_library(example_actor_helloworld SHARED example_actor_helloworld.cpp)
target_link_libraries(example_actor_helloworld myframe)
target_link_libraries(example_actor_helloworld ${PROJECT_NAME})
add_library(example_actor_timer SHARED example_actor_timer.cpp)
target_link_libraries(example_actor_timer myframe)
target_link_libraries(example_actor_timer ${PROJECT_NAME})
add_library(example_actor_serial SHARED example_actor_serial.cpp)
target_link_libraries(example_actor_serial myframe)
target_link_libraries(example_actor_serial ${PROJECT_NAME})
add_library(example_actor_concurrent SHARED example_actor_concurrent.cpp)
target_link_libraries(example_actor_concurrent myframe)
target_link_libraries(example_actor_concurrent ${PROJECT_NAME})

### worker
add_library(example_worker_publish SHARED example_worker_publish.cpp)
target_link_libraries(example_worker_publish myframe)
target_link_libraries(example_worker_publish ${PROJECT_NAME})
add_library(example_worker_talk SHARED example_worker_talk.cpp)
target_link_libraries(example_worker_talk myframe)
target_link_libraries(example_worker_talk ${PROJECT_NAME})
add_library(example_worker_actor_interactive SHARED example_worker_actor_interactive.cpp)
target_link_libraries(example_worker_actor_interactive myframe)
target_link_libraries(example_worker_actor_interactive ${PROJECT_NAME})
add_library(example_worker_interactive_with_3rd_frame SHARED example_worker_interactive_with_3rd_frame.cpp)
target_link_libraries(example_worker_interactive_with_3rd_frame myframe)
target_link_libraries(example_worker_interactive_with_3rd_frame ${PROJECT_NAME})
add_library(example_worker_quit SHARED example_worker_quit.cpp)
target_link_libraries(example_worker_quit myframe)
target_link_libraries(example_worker_quit ${PROJECT_NAME})

add_library(example_config SHARED example_config.cpp)
target_link_libraries(example_config myframe)
target_link_libraries(example_config ${PROJECT_NAME})
add_library(example_trans_obj SHARED example_trans_obj.cpp)
target_link_libraries(example_trans_obj myframe)
target_link_libraries(example_trans_obj ${PROJECT_NAME})

### install
FILE(GLOB conf_files "*.json")
INSTALL(FILES
${conf_files}
PERMISSIONS
OWNER_READ
GROUP_READ
WORLD_READ
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
DESTINATION ${MYFRAME_SERVICE_DIR}
)
INSTALL(TARGETS
Expand Down
Loading

0 comments on commit 3ff7ec6

Please sign in to comment.