Skip to content

Commit

Permalink
避免kBroadcastLogEvent被外部引用新增接口,Assert_Throw实现从zlmediakit迁移置此,两者均依赖 (#236)
Browse files Browse the repository at this point in the history
Co-authored-by: baiyfcu <[email protected]>
  • Loading branch information
xia-chu and baiyfcu authored Jul 25, 2024
1 parent fb695d2 commit fdd3450
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Util/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ void EventChannel::write(const Logger &logger, const LogContextPtr &ctx) {
NOTICE_EMIT(BroadcastLogEventArgs, kBroadcastLogEvent, logger, ctx);
}

const std::string &EventChannel::getBroadcastLogEventName() { return kBroadcastLogEvent;}

///////////////////ConsoleChannel///////////////////

ConsoleChannel::ConsoleChannel(const string &name, LogLevel level) : LogChannel(name, level) {}
Expand Down
2 changes: 2 additions & 0 deletions src/Util/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ class EventChannel : public LogChannel {
public:
//输出日志时的广播名
static const std::string kBroadcastLogEvent;
//toolkit目前仅只有一处全局变量被外部引用,减少导出相关定义,导出以下函数避免导出kBroadcastLogEvent
static const std::string& getBroadcastLogEventName();
//日志广播参数类型和列表
#define BroadcastLogEventArgs const Logger &logger, const LogContextPtr &ctx

Expand Down
14 changes: 14 additions & 0 deletions src/Util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,17 @@ void Creator::onDestoryException(const type_info &info, const exception &ex) {

} // namespace toolkit


extern "C" {
void Assert_Throw(int failed, const char *exp, const char *func, const char *file, int line, const char *str) {
if (failed) {
toolkit::_StrPrinter printer;
printer << "Assertion failed: (" << exp ;
if(str && *str){
printer << ", " << str;
}
printer << "), function " << func << ", file " << file << ", line " << line << ".";
throw toolkit::AssertFailedException(printer);
}
}
}
15 changes: 15 additions & 0 deletions src/Util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ class ObjectStatistic{
return instance; \
}

class AssertFailedException : public std::runtime_error {
public:
template<typename ...T>
AssertFailedException(T && ...args) : std::runtime_error(std::forward<T>(args)...) {}
};

std::string makeRandStr(int sz, bool printable = true);
std::string hexdump(const void *buf, size_t len);
std::string hexmem(const void* buf, size_t len);
Expand Down Expand Up @@ -432,4 +438,13 @@ class AnyStorage : public std::unordered_map<std::string, Any> {
};

} // namespace toolkit

#ifdef __cplusplus
extern "C" {
#endif
extern void Assert_Throw(int failed, const char *exp, const char *func, const char *file, int line, const char *str);
#ifdef __cplusplus
}
#endif

#endif /* UTIL_UTIL_H_ */

0 comments on commit fdd3450

Please sign in to comment.