-
Notifications
You must be signed in to change notification settings - Fork 7
Btwxt error handling #460
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
Btwxt error handling #460
Conversation
|
Here's how I would design this: In class RSYSBtwxtLogger : public Courierr::Courierr
{
public:
explicit RSYSBtwxtLogger(std::string rgi_name_in, RSYS* pRSYS_in) : rgi_name(rgi_name_in), pRSYS(pRSYS_in) {}
void error(const std::string_view message) override { pRSYS->oer(format_message(message)); }
void warning(const std::string_view message) override { pRSYS->oWarn(format_message(message)); }
void info(const std::string_view message) override { pRSYS->oInfo(format_message(message)); }
void debug(const std::string_view message) override { pRSYS->oInfo(format_message(message)); }
private:
RSYS* pRSYS;
std::string rgi_name;
std::string format_message(std::string message) { return fmt::format("btwxt '{}' -- {}", rgi_name, message)}
}and I'd make a similar one for CHDW. You could even put |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider changes. I won't push too hard on my suggestions if you want to merge anyway.
| class CourierMsgHandler : public CourierMsgHandlerBase | ||
| { | ||
| public: | ||
| using MsgCallbackFunc = void(void* pContext, MSGTY msgty, const char* msg); | ||
|
|
||
| CourierMsgHandler(MsgCallbackFunc* pMsgCallbackFunc,void* context) | ||
| : cmh_pMsgCallbackFunc(pMsgCallbackFunc), cmh_context( context) | ||
| { } | ||
|
|
||
| private: | ||
| virtual void forward_message(MSGTY msgty, const std::string& crMsg) override | ||
| { | ||
| const char* msg = crMsg.c_str(); | ||
| if (cmh_pMsgCallbackFunc) | ||
| (*cmh_pMsgCallbackFunc)(cmh_context, msgty, msg); | ||
| else | ||
| err(PABT, "nullptr cmh_pMsgCallbackFunc '%s'", msg); | ||
|
|
||
| } | ||
|
|
||
| private: | ||
| void* cmh_context; // caller context | ||
| MsgCallbackFunc* cmh_pMsgCallbackFunc; // pointer to callback function | ||
|
|
||
| }; // class CourierMsgHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought is that void* context and a MsgCallbackFunc* are very "C". There is a lot of indirection for people trying to read the code. My preference would be to make a new class for each different context with a specific forward_message override.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Don't want 10 essentially identical implementations. Maybe there is a way to template this to make it clearer? In any case, there is going to be a "callable" somewhere aka a pointer.
- Additionally, what is wrong with C? CSE is small and fast, partially due to using lots of C stuff.
- I recently learned about a "dependency injection" scheme which might be very useful here.
| char* strt_string_view( // copy string_view to temporary | ||
| std::string_view sv) // string view | ||
| { | ||
| // strncpy0 handles sv.size() = 0 | ||
| char* sRet = strncpy0( nullptr, sv.data(), sv.size()+1); | ||
| return sRet; | ||
| } // :: strt_string_view | ||
| // ==================================================================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not right now, but I made it and tested it. It is tiny and likely useful soon given the ever-growing interaction with other libraries. So I say leave it.
| char * FC strtmp( const char *s); | ||
| char * CDEC strtcat( const char *s, ... ); | ||
| char * CDEC strntcat( int n, ...); | ||
| char* strt_string_view(std::string_view sv); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see previous question.
Description
Motivation: capture and report btwxt error messages.
Implemented several classes derived from Courier. Updated all btwxt uses.
No results changes. No documentation changes.