Move HTML page handlers into HtmlServer class - #133
Conversation
Declares the class skeleton: constructor, register_early_handlers(), register_handlers(), per-handler private methods, static wrappers, and graph family static methods. Assisted-by: Claude Sonnet 4.6 (claude.ai) Model: claude-sonnet-4-6 Prompt: Write the HtmlServer class declaration for html.h including public registration methods, private page handler methods, static wrapper functions for SWILL registration, and static graph handler methods. Output: The complete HtmlServer class block added to html.h
Introduce HtmlServer class in html.cpp/html.h to encapsulate all HTML web UI page handlers previously scattered as free functions in cscout.cpp.
dspinellis
left a comment
There was a problem hiding this comment.
The HtmlServer class has no state associated with it, so I don't see gaining anything by encapsulating callbacks and utility functions. Plain static C functions should be enough and closer to the original design of SWILL and CScout. This will also make it easier to create a simple polymorphic server in the future that contains the actual functionality needed to differentiate between HTML and REST.
So, before doing mass changes, I recommend to design and prototype a couple of functions that
- abstract some existing CScout UI functionality (e.g.
xiquery_pageand one more) without embedding HTML-specific code - a way to use these functions to provide both an HTML and a REST interface.
|
Hi @dspinellis thank you for the feedback. I understand. Would identifier_page be a good second candidate alongside xiquery_page, or do you have another in mind? |
That's the one I had in mind. But I wanted you to think for yourself. |
dspinellis
left a comment
There was a problem hiding this comment.
Can you see the boilerplate in the class definition? It points to a design that can be improved. I leave you to think about it, but we can definitely discuss it if you want, even before our scheduled meeting. Or add in a comment a sketch of the proposed design.
Summary
All HTML page handlers previously scattered as free functions in
cscout.cppnow live inhtml.cpp, encapsulated inHtmlServer.Testing
All existing tests pass.
Planned for Follow-up
HtmlServerrealCscoutEngine &engineandCscoutOptions &optsconstructor members, replacing direct global access in handler bodies.write_quit_pageintoCscoutEngine::save_files()returning aSaveResultstruct, so the engine stays free of HTML dependencies and the same method can later serve the REST apply endpoint.register_early_handlers()withregister_progress_handlers()which registers a single new JSON endpoint returning analysis status.