Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.9.3 #32

Merged
merged 12 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ jobs:
if: steps.cache-jsoncpp.outputs.cache-hit != 'true'
run: |
cmake -S jsoncpp-1.9.5 -B build-jsoncpp \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_STATIC_LIBS=OFF \
-DBUILD_OBJECT_LIBS=OFF \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/jsoncpp \
-DBUILD_OBJECT_LIBS=OFF \
-DJSONCPP_WITH_TESTS=OFF \
-DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF \
-DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF \
Expand All @@ -69,6 +71,7 @@ jobs:
if: steps.cache-glog.outputs.cache-hit != 'true'
run: |
cmake -S glog-0.6.0 -B build-glog \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/glog \
-DWITH_PKGCONFIG=OFF \
Expand All @@ -85,6 +88,7 @@ jobs:
# 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}} \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DMYFRAME_USE_CV=OFF \
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ jobs:
if: steps.cache-jsoncpp.outputs.cache-hit != 'true'
run: |
cmake -S jsoncpp-1.9.5 -B build-jsoncpp \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_STATIC_LIBS=OFF \
-DBUILD_OBJECT_LIBS=OFF \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/jsoncpp \
-DBUILD_OBJECT_LIBS=OFF \
-DJSONCPP_WITH_TESTS=OFF \
-DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF \
-DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF \
Expand Down Expand Up @@ -94,6 +96,7 @@ jobs:
if: steps.cache-glog.outputs.cache-hit != 'true'
run: |
cmake -S glog-0.6.0 -B build-glog \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DWITH_PKGCONFIG=OFF \
-DWITH_GTEST=OFF \
Expand Down
81 changes: 42 additions & 39 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ jobs:
if: steps.cache-jsoncpp.outputs.cache-hit != 'true'
run: |
cmake -S jsoncpp-1.9.5 -B build-jsoncpp `
-A ${{matrix.arch}} `
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} `
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/jsoncpp `
-DBUILD_OBJECT_LIBS=OFF `
-DJSONCPP_WITH_TESTS=OFF `
-DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF `
-DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF
-A ${{matrix.arch}} `
-DBUILD_SHARED_LIBS=ON `
-DBUILD_STATIC_LIBS=OFF `
-DBUILD_OBJECT_LIBS=OFF `
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} `
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/jsoncpp `
-DJSONCPP_WITH_TESTS=OFF `
-DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF `
-DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF
cmake --build build-jsoncpp `
--config ${{matrix.build_type}} `
--target install
--config ${{matrix.build_type}} `
--target install

- name: Cache gflags
id: cache-gflags
Expand All @@ -75,12 +77,12 @@ jobs:
if: steps.cache-gflags.outputs.cache-hit != 'true'
run: |
cmake -S gflags-2.2.2 -B build-gflags `
-A ${{matrix.arch}} `
-DBUILD_SHARED_LIBS=ON `
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/gflags
-A ${{matrix.arch}} `
-DBUILD_SHARED_LIBS=ON `
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/gflags
cmake --build build-gflags `
--config ${{matrix.build_type}} `
--target install
--config ${{matrix.build_type}} `
--target install

- name: Cache glog
id: cache-glog
Expand All @@ -99,39 +101,40 @@ jobs:
if: steps.cache-glog.outputs.cache-hit != 'true'
run: |
cmake -S glog-0.6.0 -B build-glog `
-A ${{matrix.arch}} `
-DBUILD_SHARED_LIBS=ON `
-DWITH_GTEST=OFF `
-DWITH_PKGCONFIG=OFF `
-DCMAKE_PREFIX_PATH="${{github.workspace}}/gflags" `
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/glog
-A ${{matrix.arch}} `
-DBUILD_SHARED_LIBS=ON `
-DWITH_GTEST=OFF `
-DWITH_PKGCONFIG=OFF `
-DCMAKE_PREFIX_PATH="${{github.workspace}}/gflags" `
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/glog
cmake --build build-glog `
--config ${{matrix.build_type}} `
--target install
--config ${{matrix.build_type}} `
--target install

- name: Configure
run: |
cmake -S . -B build_${{matrix.build_type}} `
-A ${{matrix.arch}} `
-DMYFRAME_USE_CV=ON `
-DBUILD_SHARED_LIBS=ON `
-DCMAKE_CXX_EXTENSIONS=OFF `
-DCMAKE_CXX_STANDARD=${{matrix.std}} `
-DCMAKE_CXX_STANDARD_REQUIRED=ON `
-DCMAKE_EXE_LINKER_FLAGS='/NOIMPLIB' `
-DCMAKE_EXE_LINKER_FLAGS_RELEASE='/INCREMENTAL:NO /DEBUG' `
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/myframe `
-DCMAKE_PREFIX_PATH="${{github.workspace}}/jsoncpp;${{github.workspace}}/glog;${{github.workspace}}/gflags" `
-DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded$<$<CONFIG:Debug>:Debug>DLL' `
-G "${{matrix.generator}}" `
-Werror
-A ${{matrix.arch}} `
-DMYFRAME_USE_CV=ON `
-DBUILD_SHARED_LIBS=ON `
-DCMAKE_CXX_EXTENSIONS=OFF `
-DCMAKE_CXX_STANDARD=${{matrix.std}} `
-DCMAKE_CXX_STANDARD_REQUIRED=ON `
-DCMAKE_EXE_LINKER_FLAGS='/NOIMPLIB' `
-DCMAKE_EXE_LINKER_FLAGS_RELEASE='/INCREMENTAL:NO /DEBUG' `
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/myframe `
-DCMAKE_PREFIX_PATH="${{github.workspace}}/jsoncpp;${{github.workspace}}/glog;${{github.workspace}}/gflags" `
-DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded$<$<CONFIG:Debug>:Debug>DLL' `
-G "${{matrix.generator}}" `
-Werror

- name: Build
run: cmake --build build_${{matrix.build_type}} `
--config ${{matrix.build_type}}
run: |
cmake --build build_${{matrix.build_type}} `
--config ${{matrix.build_type}}

- name: Install
run: |
cmake --build build_${{matrix.build_type}} `
--config ${{matrix.build_type}} `
--target install
--config ${{matrix.build_type}} `
--target install
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ launcher/launcher_config.h
test/performance_test_config.h
myframe/export.h
myframe/config.h
3rd/pkg/
3rd/src/
3rd/build/
output/
67 changes: 67 additions & 0 deletions 3rd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
cmake_minimum_required(VERSION 3.10)
if (POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
project(myframe_deps VERSION 1.0.0)

include(ExternalProject)

set(DEPS_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
set(DEPS_DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/pkg)

ExternalProject_Add(
gflags
URL https://github.com/gflags/gflags/archive/refs/tags/v2.2.2.tar.gz
URL_MD5 1a865b93bacfa963201af3f75b7bd64c
DOWNLOAD_NAME "gflags.tar.gz"
PREFIX ${CMAKE_BINARY_DIR}
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}
SOURCE_DIR "${DEPS_SOURCE_DIR}/gflags"
UPDATE_COMMAND ""
PATCH_COMMAND ""
CMAKE_ARGS
-DBUILD_SHARED_LIBS=ON
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)

ExternalProject_Add(
glog
URL https://github.com/google/glog/archive/refs/tags/v0.6.0.tar.gz
URL_MD5 c98a6068bc9b8ad9cebaca625ca73aa2
DOWNLOAD_NAME "glog.tar.gz"
PREFIX ${CMAKE_BINARY_DIR}
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}
SOURCE_DIR "${DEPS_SOURCE_DIR}/glog"
UPDATE_COMMAND ""
PATCH_COMMAND ""
CMAKE_ARGS
-DBUILD_SHARED_LIBS=ON
-DCMAKE_BUILD_TYPE=Release
-DWITH_PKGCONFIG=OFF
-DWITH_GTEST=OFF
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}
)
ExternalProject_Add_StepDependencies(glog install gflags)

ExternalProject_Add(
jsoncpp
URL https://github.com/open-source-parsers/jsoncpp/archive/refs/tags/1.9.5.tar.gz
URL_MD5 d6c8c609f2162eff373db62b90a051c7
DOWNLOAD_NAME "jsoncpp.tar.gz"
PREFIX ${CMAKE_BINARY_DIR}
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}
SOURCE_DIR "${DEPS_SOURCE_DIR}/jsoncpp"
UPDATE_COMMAND ""
PATCH_COMMAND ""
CMAKE_ARGS
-DBUILD_SHARED_LIBS=ON
-DBUILD_STATIC_LIBS=OFF
-DBUILD_OBJECT_LIBS=OFF
-DCMAKE_BUILD_TYPE=Release
-DJSONCPP_WITH_TESTS=OFF
-DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF
-DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)
2 changes: 2 additions & 0 deletions 3rd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 3rd
该目录主要用于下载/构建/安装依赖包使用
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.10)
project(myframe VERSION 0.9.2)
if (POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
project(myframe VERSION 0.9.3)

### option
option(MYFRAME_USE_CV "Using conditional variables for thread communication" ON)
Expand All @@ -13,15 +16,16 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
### compile option
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (CMAKE_CXX_STANDARD_REQUIRED)
message(STATUS "Set cxx standard ${CMAKE_CXX_STANDARD}")
else()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
message(STATUS "Set default cxx standard 17")
endif()
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>")

### install path
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@ worker自驱动,可以通过消息与actor交互;
| Windows |
| macOS |

## 构建
## github构建
* [github ci linux](.github/workflows/linux.yml)
* [github ci windows](.github/workflows/windows.yml)
* [github ci macOS](.github/workflows/macos.yml)

## 快速本地构建
```sh
# 下载/构建/安装依赖库
cd 3rd
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=../output
cmake --build build -j
# 构建安装
cd ..
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=./output -DCMAKE_PREFIX_PATH=./output
cmake --build build -j --config Release --target install
```

### Hello,World 示例
```c
#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion myframe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ target_link_libraries(${PROJECT_NAME}
PUBLIC
Threads::Threads
glog::glog
jsoncpp_lib
JsonCpp::JsonCpp
)
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})
Expand Down
30 changes: 14 additions & 16 deletions myframe/actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Author: 李柯鹏 <[email protected]>
****************************************************************************/

#include "myframe/actor.h"
#include <utility>

#include "myframe/log.h"
#include "myframe/app.h"
Expand Down Expand Up @@ -33,11 +34,10 @@ const std::string& Actor::GetModName() const {
bool Actor::IsFromLib() const { return is_from_lib_; }

Mailbox* Actor::GetMailbox() {
auto ctx = ctx_.lock();
if (ctx == nullptr) {
if (ctx_ == nullptr) {
return nullptr;
}
return ctx->GetMailbox();
return ctx_->GetMailbox();
}

const std::string& Actor::GetTypeName() const { return actor_name_; }
Expand All @@ -53,12 +53,11 @@ void Actor::SetTypeName(const std::string& name) { actor_name_ = name; }
void Actor::SetInstName(const std::string& name) { instance_name_ = name; }

int Actor::Timeout(const std::string& timer_name, int expired) {
auto ctx = ctx_.lock();
if (ctx == nullptr) {
if (ctx_ == nullptr) {
LOG(ERROR) << "actor context is nullptr";
return -1;
}
auto app = ctx->GetApp();
auto app = ctx_->GetApp();
if (app == nullptr) {
LOG(ERROR) << "app is nullptr";
return -1;
Expand All @@ -71,22 +70,22 @@ int Actor::Timeout(const std::string& timer_name, int expired) {
return timer_worker->SetTimeout(GetActorName(), timer_name, expired);
}

bool Actor::Subscribe(const std::string& name) {
auto ctx = ctx_.lock();
if (ctx == nullptr) {
bool Actor::Subscribe(const std::string& addr, const std::string& msg_type) {
if (ctx_ == nullptr) {
return false;
}
if (name == GetActorName()) {
if (addr == GetActorName()) {
return false;
}
auto msg = std::make_shared<Msg>();
msg->SetType("SUBSCRIBE");
auto mailbox = ctx->GetMailbox();
mailbox->Send(name, msg);
msg->SetDesc(msg_type);
auto mailbox = ctx_->GetMailbox();
mailbox->Send(addr, std::move(msg));
return true;
}

void Actor::SetContext(std::shared_ptr<ActorContext> c) { ctx_ = c; }
void Actor::SetContext(ActorContext* c) { ctx_ = c; }

const Json::Value* Actor::GetConfig() const {
return &config_;
Expand All @@ -97,11 +96,10 @@ void Actor::SetConfig(const Json::Value& conf) {
}

std::shared_ptr<App> Actor::GetApp() {
auto ctx = ctx_.lock();
if (ctx == nullptr) {
if (ctx_ == nullptr) {
return nullptr;
}
return ctx->GetApp();
return ctx_->GetApp();
}

} // namespace myframe
Loading
Loading