Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A complete Linux application software development tool library and runtime framework, aim at make C++ development easy.

License

NotificationsYou must be signed in to change notification settings

cpp-main/cpp-tbox

Repository files navigation

cpp-tbox logo

LicenseLanguagePlatform

[中文]

C++ Treasure Box is a service-orienteddevelopment framework andcomponent library based on the Reactor model, aim at make C++ development easy.

Application field

  • Intelligent hardware, such as: robots (sweepers, commercial service robots), IPC, drones, vehicles, etc.;
  • Edge computing components, such as: smart home gateway, IOT edge gateway, etc.;
  • Service, such as: SOCK5, Middleware.

See projects:

Features

1. Based on the Reactor

See the Node.js Reactor pattern.
The main thread handles non-blocking IO events in Reactor mode, and cooperates with ThreadPool to perform large calculations and blocking operations.

This mode avoids the annoyance of competing locking in multi-thread mode, and the program is stable and reliable.

2. Contains main framework, easy to use

All non-business-related work is handled using the built-in main framework. You don't need to care about such trivial things as how to output the log, how to parse the parameters, how to exit the program, and how to write the main function. The main frame is all handled for you.
You only need to derive thetbox::main::Module class, fill in the business code, and then register to the framework.

3. With Shell-like terminal

You can interact with the running service through telnet, make it print internal data, or perform specific actions. This greatly reduces the difficulty of debugging.
shell interaction

4. With completely log system

1) There are three log sink: stdout + filelog + syslog

  • stdout,Output the log to the terminal viastd::cout;
  • syslog,Output logs to syslog viasyslog();
  • filelog,Write the log to the specified directory, in the format:<PRIFIX>.YYMMDD_HHMMSS.<PID>.log. If the file size exceeds 1M, a new log file will be created. Due to the low efficiency of writing files, the output channel adopts the front-end and back-end modes.

One or more of the three sink can be selected in the startup parameters, and can also be changed through the terminal during operation.

2) Different level different color
The log content includes: level, time (accurate to microseconds), thread number, module name, function name, text, file name, line number.
It is convenient and quick to locate the problem.log show

3) Flexible log output filter
The log level can be set separately for different modules when the program is running, as follows:
set log level

5. Flexible parameter system

Parameters are provided in JSON format, and any format of running parameters can be passed in, including: integers, decimals, strings, arrays, and combination parameters, meeting almost all parameter passing requirements:
paremeter help
You can use-c your_cfg_file.json to import a configuration file in JSON format at execution time. At the same time, you can also use-s 'xx.yy.zz=vvv' to specify parameters temporarily.
The configuration file in JSON format also supports the include command to include other configuration files when loading.

6. Assign tasks across threads without locking

The child thread entrusts the main thread to execute:
runInLoop example
The main thread entrusts the child thread to execute:
ThreadPool example

7. Graceful exit process

When receiving signals: SIGINT, SIGTERM, SIGQUIT, SIGPWR, it will execute the exit process in an orderly manner and release resources. Do a clean exit.
graceful exit

8. Comprehensive exception capture mechanism

When various program exceptions occur in the program, such as: segment fault, assertion, bus error, exception not caught, etc., the framework will capture and print the complete call stack in the log system. Facing program crashes, no longer look blank. The effect is as follows:
stack print

9. Visualized trace module

The trace module can record the time and duration of each execution of the marked function, and can export the flame graph for display:
trace fire graph
It is a great tool for performance analysis and event blocking problem troubleshooting.

10. Simple and visualized state machine

It abandons the cumbersome inheritance and derivation of the traditional state mode, and uses it directly in a combined way, which is simple and convenient. It can also export the state machine diagram to achieve what you see is what you get:
visualized state machine

11. Visualized behavior tree

It contains an event-driven behavior tree that can realize sequential, branching, and cyclic action processes in an asynchronous environment, and can export a visual tree diagram in real time:
visualized behavior tree

12. Rich components

NameWhat
baseIncluding log printing, common tools, etc.
utilAccessibility module
eventRealized IO, Timer, Signal three kinds of event-driven, which is the heart of the whole framework
eventxIncluding ThreadPool thread pool, WorkThread worker thread, TimerPool timer pool and other modules
logRealized efficient and reliable terminal, syslog, and log output in the form of files
traceRealized outputting traces to files in real time
networkRealized serial port, terminal, UDP, TCP communication module
terminalA shell-like command terminal that enables command interaction with programs during runtime
mainRealized a complete program startup process and framework, so that developers only need to care about business code
runIt's an ELF. It loads one or more lib*.so file which specified by parameter-l xxx, then run Modules in side
mqttMQTT Client
coroutinecoroutine function
httpImplemented HTTP Server and Client modules on the basis of network
alarmRealized 4 commonly used alarm clocks: CRON alarm clock, single alarm clock, weekly cycle alarm clock, weekday alarm clock
flowContains multi-level state machine and behavior tree to solve the problem of action flow in asynchronous mode
cryptoImplemented the commonly used AES and MD5 encryption and decryption calculations
dbusImplemented the function of integrating dbus into event to process transactions in a non-blocking manner

Environment

  • Linux series operating system;
  • C++11 or above.

Download & build

Prepare

sudo apt updatesudo apt install build-essentialsudo apt install libgtest-dev libgmock-devsudo apt install libmosquitto-devsudo apt install libdbus-1-devgit clone https://gitee.com/cpp-master/cpp-tbox.gitcd cpp-tbox

Using GNU Make

make 3rd-party modules RELEASE=1

After completion, the header files and library files are in the .staging directory.
Of course, you can also specify the generation path of header files and library files by specifyingSTAGING_DIR.
like:

make 3rd-party modules RELEASE=1 STAGING_DIR=$HOME/.tbox

After completion, the header files and library files are in the $HOME/.tbox path.

Using CMake

cmake -B buildcmake --build buildcmake --install build

Customize the installation directory by specifyingCMAKE_INSTALL_PREFIX (installed in /usr/local by default):

cmake -B build -DCMAKE_INSTALL_PREFIX=$HOME/.tbox

Tutorial

For details on how to use cpp-tbox to develop your own programs, see the tutorial:
cpp-tbox-tutorials

For example to usefind_package:

cmake_minimum_required(VERSION 3.10)project(tbox-find_package)find_package(tbox COMPONENTS base util alarm event eventx)add_executable(demo main.cpp)target_link_libraries(demo PRIVATE tbox::tbox_base tbox::tbox_util tbox::tbox_alarm tbox::tbox_event tbox::tbox_eventx)

Dependencies

NameDependent moduleRequiredUseInstall
libgtest-devallnounit testingsudo apt install libgtest-dev
libgmock-devallnounit testingsudo apt install libgmock-dev
libmosquitto-devmqttnoMQTTsudo apt install libmosquitto-dev
libdbus-1-devdbusnoDBussudo apt install libdbus-1-dev

Configure

Open the config.mk file, you don’t need to block the modules corresponding toapp_y += xxx, but pay attention to the dependencies between modules.

License

MIT, Free for use.

Feedback

  • Issue: Any questions are welcome to communicate in issue
  • WeChat: hevake_lee (Note: cpp-tbox)
  • QQ Group: 738084942 (cpp-tbox 技术交流)

Encourage us

If this project makes your work easier and you leave work earlier, please give me more encouragement.You can do these:

  • Light up three combos for it: Star, Watch, Fork;
  • Recommend to colleagues and partners around you, and recommend to your readers in technical forums;
  • Join the above QQ group, add me on WeChat to enter the WeChat group;
  • Positive feedback on issues and suggestions;
  • Participate in the development of the project and contribute your strength;
  • Let me know which projects it is used in;

About

A complete Linux application software development tool library and runtime framework, aim at make C++ development easy.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp