Skip to content
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
16 changes: 16 additions & 0 deletions 3rd/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
# 3rd
该目录主要用于下载/构建/安装依赖包使用

## 基于CMAKE安装依赖
进入代码库根目录执行以下命令:
```sh
cmake -S 3rd -B build_3rd -DCMAKE_INSTALL_PREFIX=output
cmake --build build_3rd -j --config Release
```

## 基于包管理安装依赖
进入代码库根目录执行以下命令:
```sh
mypm install --one-folder -p ${PWD}/output jsoncpp,1.9.5
mypm install --one-folder -p ${PWD}/output glog,0.6.0
# 需要编译python绑定时安装此依赖
mypm install --one-folder -p ${PWD}/output swig,4.3.1
```
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
cmake_minimum_required(VERSION 3.10)
if (POLICY CMP0091)
# Allow the user to specify the MSVC runtime
if (POLICY CMP0091) # >= 3.15
cmake_policy(SET CMP0091 NEW)
endif()
project(myframe
VERSION 0.9.9
VERSION 1.0.0
LANGUAGES CXX
)

Expand All @@ -14,6 +15,7 @@ option(MYFRAME_GENERATE_TEST "Generate test executable program" ON)
option(MYFRAME_INSTALL_TEMPLATE "Install template project" ON)
option(MYFRAME_INSTALL_LAUNCHER "Install launcher program" ON)
option(MYFRAME_ENABLE_ASAN "Enable ASAN" OFF)
option(MYFRAME_ENABLE_PYBIND "Enable Python bindings" OFF)

### cmake module
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
Expand Down Expand Up @@ -50,11 +52,16 @@ set(MYFRAME_LIB_DIR "lib")
set(MYFRAME_LOG_DIR "log")
set(MYFRAME_SERVICE_DIR "service")
set(MYFRAME_CONF_DIR "conf")
set(MYFRAME_PYTHON_DIR "lib/python")

### deps libs
find_package(Threads REQUIRED)
find_package(jsoncpp REQUIRED)
find_package(glog REQUIRED)
if (MYFRAME_ENABLE_PYBIND)
find_package(SWIG REQUIRED)
find_package(Python COMPONENTS Development REQUIRED)
endif()

get_target_property(glog_lib_type glog::glog TYPE)
get_target_property(jsoncpp_lib_type JsonCpp::JsonCpp TYPE)
Expand All @@ -70,6 +77,9 @@ endif()
if (MYFRAME_GENERATE_TEST)
add_subdirectory(test)
endif()
if (MYFRAME_ENABLE_PYBIND)
add_subdirectory(python)
endif()

### install file/dir
install(FILES
Expand All @@ -87,6 +97,10 @@ if (MYFRAME_INSTALL_TEMPLATE)
)
install(DIRECTORY templates DESTINATION .)
endif()
install(PROGRAMS
"tools/myframe_setup.sh"
DESTINATION ${MYFRAME_BIN_DIR}
)
install(DIRECTORY DESTINATION ${MYFRAME_LOG_DIR})
install(DIRECTORY DESTINATION ${MYFRAME_SERVICE_DIR})

Expand Down
7 changes: 6 additions & 1 deletion doc/development_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
"HelloActor": [
{
"instance_name": "1",
"instance_params": ""
"instance_config": {
"pending_queue_size":-1,
"run_queue_size":2
}
}
]
},
Expand All @@ -44,6 +47,8 @@
- 可以写简略库名,比如 Hello
- 也可以写库的全名,比如libHello.so, Hello,dll
- 创建1个actor实例,名称是 actor.HelloActor.1
- pending_queue_size是这个等待队列长度,-1是无限制
- run_queue_size是设置每次执行消费最大消息数量, -1是无限制
- 创建1个worker实例,名称是 worker.HelloReceiver.1
- 创建1个worker实例,名称是 worker.HelloSender.1

Expand Down
17 changes: 10 additions & 7 deletions launcher/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ int main(int argc, char** argv) {

// 初始化并启动线程
g_app = std::make_shared<myframe::App>();
if (false == g_app->Init(
lib_dir.string(),
module_args.GetThreadPoolSize(),
module_args.GetConnEventSize(),
module_args.GetWarningMsgSize(),
module_args.GetDefaultPendingQueueSize(),
module_args.GetDefaultRunQueueSize())) {
myframe::Arguments args;
args.SetStr(MYFRAME_KEY_SERVICE_LIB_DIR, lib_dir.string());
args.SetInt(MYFRAME_KEY_THREAD_POOL_SIZE, module_args.GetThreadPoolSize());
args.SetInt(MYFRAME_KEY_EVENT_CONNE_SIZE, module_args.GetConnEventSize());
args.SetInt(MYFRAME_KEY_WARNING_MSG_SIZE, module_args.GetWarningMsgSize());
args.SetInt(MYFRAME_KEY_PENDING_QUEUE_SIZE,
module_args.GetDefaultPendingQueueSize());
args.SetInt(MYFRAME_KEY_RUN_QUEUE_SIZE, module_args.GetDefaultRunQueueSize());
LOG(INFO) << "\n" << args.DebugString();
if (false == g_app->Init(args)) {
LOG(ERROR) << "Init failed";
return -1;
}
Expand Down
1 change: 1 addition & 0 deletions myframe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ file(GLOB header_files
export.h
macros.h
common.h
arguments.h
log.h
msg.h
mailbox.h
Expand Down
52 changes: 44 additions & 8 deletions myframe/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,55 @@ App::~App() {
LOG(INFO) << "app deconstruct";
}

bool App::Init(
const std::string& lib_dir,
int thread_pool_size,
int event_conn_size,
int warning_msg_size,
int default_pending_queue_size,
int default_run_queue_size) {
bool App::Init(const Arguments& args) {
if (state_.load() != State::kUninitialized) {
return true;
}
#if defined(MYFRAME_OS_WINDOWS)
std::string lib_dir = "bin";
#else
std::string lib_dir = "lib";
#endif
int thread_pool_size = 4;
int event_conn_size = 2;
int warning_msg_size = 10;
int default_pending_queue_size = -1;
int default_run_queue_size = 2;
for (const auto& arg : args) {
if (arg.type == Argument::ArgType::kArgString) {
if (arg.key == MYFRAME_KEY_SERVICE_LIB_DIR) {
lib_dir = arg.value_str;
}
}
if (arg.type == Argument::ArgType::kArgInteger) {
int value_int = arg.value_int;
if (arg.key == MYFRAME_KEY_THREAD_POOL_SIZE) {
thread_pool_size = value_int;
}
if (arg.key == MYFRAME_KEY_WARNING_MSG_SIZE) {
warning_msg_size = value_int;
}
if (arg.key == MYFRAME_KEY_PENDING_QUEUE_SIZE) {
default_pending_queue_size = value_int;
}
if (arg.key == MYFRAME_KEY_RUN_QUEUE_SIZE) {
default_run_queue_size = value_int;
}
if (arg.key == MYFRAME_KEY_EVENT_CONNE_SIZE) {
event_conn_size = value_int;
}
}
}

// LOG(INFO) << "lib dir: " << lib_dir;
// LOG(INFO) << "thread pool size: " << thread_pool_size;
// LOG(INFO) << "event conn size: " << event_conn_size;
// LOG(INFO) << "warning msg size: " << warning_msg_size;
// LOG(INFO) << "default pending queue size: " << default_pending_queue_size;
// LOG(INFO) << "default run queue size: " << default_run_queue_size;

bool ret = true;
lib_dir_ = lib_dir;
lib_dir_ = myframe::Common::GetAbsolutePath(lib_dir);
warning_msg_size_.store(warning_msg_size);
default_pending_queue_size_ = default_pending_queue_size;
default_run_queue_size_ = default_run_queue_size;
Expand Down
9 changes: 2 additions & 7 deletions myframe/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Author: 李柯鹏 <likepeng0418@163.com>
#include "myframe/event.h"
#include "myframe/export.h"
#include "myframe/common.h"
#include "myframe/arguments.h"

namespace myframe {

Expand Down Expand Up @@ -51,13 +52,7 @@ class MYFRAME_EXPORT App final : public std::enable_shared_from_this<App> {
App();
virtual ~App();

bool Init(
const std::string& lib_dir,
int thread_pool_size = 4,
int event_conn_size = 2,
int warning_msg_size = 10,
int default_pending_queue_size = -1,
int default_run_queue_size = 2);
bool Init(const Arguments& args);

int LoadServiceFromDir(const std::string& path);

Expand Down
50 changes: 50 additions & 0 deletions myframe/arguments.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/****************************************************************************
Copyright (c) 2019, 李柯鹏
All rights reserved.

Author: 李柯鹏 <likepeng0418@163.com>
****************************************************************************/
#include <sstream>
#include "myframe/arguments.h"

namespace myframe {

std::string Argument::DebugString() {
std::stringstream ss;
ss << key << "(";
if (type == Argument::ArgType::kArgInteger) {
ss << "int):";
ss << value_int;
}
if (type == Argument::ArgType::kArgString) {
ss << "string):";
ss << value_str;
}
return ss.str();
}

void Arguments::SetStr(const std::string& key, const std::string& value) {
Argument arg;
arg.type = Argument::ArgType::kArgString;
arg.key = key;
arg.value_str = value;
push_back(arg);
}

void Arguments::SetInt(const std::string& key, int value) {
Argument arg;
arg.type = Argument::ArgType::kArgInteger;
arg.key = key;
arg.value_int = value;
push_back(arg);
}

std::string Arguments::DebugString() {
std::stringstream ss;
for (auto it = begin(); it != end(); ++it) {
ss << it->DebugString() << std::endl;
}
return ss.str();
}

} // namespace myframe
52 changes: 52 additions & 0 deletions myframe/arguments.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/****************************************************************************
Copyright (c) 2019, 李柯鹏
All rights reserved.

Author: 李柯鹏 <likepeng0418@163.com>
****************************************************************************/
#pragma once
#include <cstdint>
#include <string>
#include <list>
#include <vector>

#include "myframe/export.h"

namespace myframe {

class MYFRAME_EXPORT Argument {
public:
enum class ArgType : std::uint8_t {
kArgString = 0,
kArgInteger,
};
ArgType type;
std::string key;
int value_int;
std::string value_str;

std::string DebugString();
};

class MYFRAME_EXPORT Arguments : public std::vector<Argument> {
public:
void SetStr(const std::string& key, const std::string& value);

void SetInt(const std::string& key, int value);

std::string DebugString();
};

#define MYFRAME_KEY_SERVICE_LIB_DIR "app.lib_dir"

#define MYFRAME_KEY_THREAD_POOL_SIZE "app.thread_pool_size"

#define MYFRAME_KEY_WARNING_MSG_SIZE "app.warning_msg_size"

#define MYFRAME_KEY_PENDING_QUEUE_SIZE "app.pending_queue_size"

#define MYFRAME_KEY_RUN_QUEUE_SIZE "app.run_queue_size"

#define MYFRAME_KEY_EVENT_CONNE_SIZE "app.event_conn_size"

} // namespace myframe
Loading
Loading