Skip to content

Commit 39a1056

Browse files
committed
Merge branch 'develop'
2 parents 59c39b2 + db62bb0 commit 39a1056

34 files changed

+1336
-13
lines changed

CONTRIBUTORS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ _If we have forgotten your name, please contact us_
44

55
* Hevake Lee
66
* Lucas Law
7+
* Sky Hou
8+
* DuanYH
79
* Gwill
810
* MacroModel
9-
* Sky Hou

examples/network/stdio_stream/01_stdin_out/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ int main()
3232
auto sp_stdin = new network::StdinStream(sp_loop);
3333
auto sp_stdout = new network::StdoutStream(sp_loop);
3434

35+
sp_stdin->initialize();
36+
sp_stdout->initialize();
37+
3538
sp_stdin->bind(sp_stdout);
3639

3740
sp_stdin->enable();

examples/network/stdio_stream/02_stdio/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ int main()
3131
auto sp_loop = event::Loop::New();
3232
auto sp_stdio = new network::StdioStream(sp_loop);
3333

34+
sp_stdio->initialize();
35+
3436
sp_stdio->bind(sp_stdio);
3537
sp_stdio->enable();
3638

@@ -53,3 +55,4 @@ int main()
5355
delete sp_loop;
5456
return 0;
5557
}
58+

examples/terminal/build_nodes.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ void BuildNodes(TerminalNodes &term, Loop *wp_loop)
137137

138138
term.mountNode(dir1_1_token, term.rootNode(), "root"); //! 循环引用
139139

140+
//! 演示使用 AddFuncNode() 函数直接添加函数结点
140141
auto add_func_dir_node = term.createDirNode();
141142
term.mountNode(term.rootNode(), add_func_dir_node, "add_func");
142143

@@ -145,4 +146,44 @@ void BuildNodes(TerminalNodes &term, Loop *wp_loop)
145146
AddFuncNode(term, add_func_dir_node, "int_value", int_value, 0, 100);
146147
AddFuncNode(term, add_func_dir_node, "double_value", double_value, 0, 1);
147148
AddFuncNode(term, add_func_dir_node, "str_value", str_value);
149+
150+
//! 演示使用 XxxxxFuncNodeProfile 来添加函数结点
151+
auto profile_func_dir_node = term.createDirNode();
152+
term.mountNode(term.rootNode(), profile_func_dir_node, "profile_func");
153+
154+
{
155+
BooleanFuncNodeProfile profile;
156+
profile.set_func = [&] (bool value) { bool_value = value; return true; };
157+
profile.get_func = [&] () { return bool_value; };
158+
159+
AddFuncNode(term, profile_func_dir_node, "bool_value", profile);
160+
}
161+
162+
{
163+
StringFuncNodeProfile profile;
164+
profile.set_func = [&] (const std::string &value) { str_value = value; return true; };
165+
profile.get_func = [&] () { return str_value; };
166+
167+
AddFuncNode(term, profile_func_dir_node, "str_value", profile);
168+
}
169+
170+
{
171+
IntegerFuncNodeProfile profile;
172+
profile.set_func = [&] (int value) { int_value = value; return true; };
173+
profile.get_func = [&] () { return int_value; };
174+
profile.min_value = 1;
175+
profile.max_value = 5;
176+
177+
AddFuncNode(term, profile_func_dir_node, "int_value", profile);
178+
}
179+
180+
{
181+
DoubleFuncNodeProfile profile;
182+
profile.set_func = [&] (double value) { double_value = value; return true; };
183+
profile.get_func = [&] () { return double_value; };
184+
profile.min_value = -1;
185+
profile.max_value = 1;
186+
187+
AddFuncNode(term, profile_func_dir_node, "double_value", profile);
188+
}
148189
}

examples/terminal/stdio/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# .============.
3+
# // M A K E / \
4+
# // C++ DEV / \
5+
# // E A S Y / \/ \
6+
# ++ ----------. \/\ .
7+
# \\ \ \ /\ /
8+
# \\ \ \ /
9+
# \\ \ \ /
10+
# -============'
11+
#
12+
# Copyright (c) 2018 Hevake and contributors, all rights reserved.
13+
#
14+
# This file is part of cpp-tbox (https://github.com/cpp-main/cpp-tbox)
15+
# Use of this source code is governed by MIT license that can be found
16+
# in the LICENSE file in the root of the source tree. All contributing
17+
# project authors may be found in the CONTRIBUTORS.md file in the root
18+
# of the source tree.
19+
#
20+
21+
PROJECT := examples/terminal/stdio
22+
EXE_NAME := ${PROJECT}
23+
24+
CPP_SRC_FILES := main.cpp ../build_nodes.cpp
25+
26+
CXXFLAGS := -DMODULE_ID='"$(EXE_NAME)"' $(CXXFLAGS)
27+
LDFLAGS += \
28+
-ltbox_terminal \
29+
-ltbox_network \
30+
-ltbox_event \
31+
-ltbox_util \
32+
-ltbox_base \
33+
-ldl
34+
35+
include $(TOP_DIR)/mk/exe_common.mk

examples/terminal/stdio/main.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* .============.
3+
* // M A K E / \
4+
* // C++ DEV / \
5+
* // E A S Y / \/ \
6+
* ++ ----------. \/\ .
7+
* \\ \ \ /\ /
8+
* \\ \ \ /
9+
* \\ \ \ /
10+
* -============'
11+
*
12+
* Copyright (c) 2025 Hevake and contributors, all rights reserved.
13+
*
14+
* This file is part of cpp-tbox (https://github.com/cpp-main/cpp-tbox)
15+
* Use of this source code is governed by MIT license that can be found
16+
* in the LICENSE file in the root of the source tree. All contributing
17+
* project authors may be found in the CONTRIBUTORS.md file in the root
18+
* of the source tree.
19+
*/
20+
#include <string>
21+
#include <signal.h>
22+
23+
#include <tbox/base/scope_exit.hpp>
24+
#include <tbox/base/log_output.h>
25+
26+
#include <tbox/event/loop.h>
27+
#include <tbox/event/signal_event.h>
28+
29+
#include <tbox/terminal/terminal.h>
30+
#include <tbox/terminal/service/stdio.h>
31+
32+
using namespace tbox;
33+
34+
void BuildNodes(terminal::TerminalNodes &term, event::Loop *wp_loop);
35+
36+
int main()
37+
{
38+
//LogOutput_Enable();
39+
auto sp_loop = event::Loop::New();
40+
SetScopeExitAction([sp_loop] { delete sp_loop; });
41+
42+
terminal::Terminal term(sp_loop);
43+
terminal::Stdio stdio(sp_loop, &term);
44+
stdio.initialize();
45+
46+
term.setWelcomeText("Welcome to Terminal STDIO demo! \r\n");
47+
48+
//! 注册ctrl+C停止信号
49+
auto *sp_stop_ev = sp_loop->newSignalEvent();
50+
SetScopeExitAction([sp_stop_ev] { delete sp_stop_ev; });
51+
sp_stop_ev->initialize({SIGINT,SIGTERM}, event::Event::Mode::kOneshot);
52+
//! 指定ctrl+C时要做的事务
53+
sp_stop_ev->setCallback(
54+
[&] (int) {
55+
stdio.stop();
56+
sp_loop->exitLoop(); //! (3) 退出事件循环
57+
}
58+
);
59+
sp_stop_ev->enable();
60+
61+
BuildNodes(term, sp_loop);
62+
63+
stdio.start();
64+
65+
sp_loop->runLoop();
66+
67+
stdio.cleanup();
68+
return 0;
69+
}

modules/flow/actions/switch_action.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
#include "switch_action.h"
2121

22+
#include <sstream>
23+
2224
#include <tbox/base/assert.h>
2325
#include <tbox/base/defines.h>
2426
#include <tbox/base/json.hpp>

modules/log/async_sink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void AsyncSink::onLogBackEnd(const LogContent &content)
9393
char buff[1024];
9494
size_t len = 0;
9595

96-
udpateTimestampStr(content.timestamp.sec);
96+
updateTimestampStr(content.timestamp.sec);
9797

9898
//! 开启色彩,显示日志等级
9999
if (enable_color_) {

modules/log/sink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void Sink::handleLog(const LogContent *content)
102102
onLogFrontEnd(content);
103103
}
104104

105-
void Sink::udpateTimestampStr(uint32_t sec)
105+
void Sink::updateTimestampStr(uint32_t sec)
106106
{
107107
if (timestamp_sec_ != sec) {
108108
time_t ts_sec = sec;

modules/log/sink.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Sink {
5656
static void HandleLog(const LogContent *content, void *ptr);
5757
bool filter(int level, const std::string &module);
5858

59-
void udpateTimestampStr(uint32_t sec);
59+
void updateTimestampStr(uint32_t sec);
6060

6161
protected:
6262
bool enable_color_ = false;

0 commit comments

Comments
 (0)