1+ #!/usr/bin/wsjcpp-safe-scripting
2+
3+ # log_info rootdir
4+ # log_info script_filename
5+
6+ make_dir "src"
7+
8+ var http_handler_name
9+ set_value http_handler_name arg1
10+ normalize_class_name http_handler_name
11+ convert_CamelCase_to_snake_case http_handler_name http_handler_name
12+
13+ var class_name
14+ concat class_name "LightWebHttpHandler" arg1
15+ normalize_class_name class_name
16+
17+ var base_filename
18+ convert_CamelCase_to_snake_case class_name base_filename
19+ # log_info base_filename
20+
21+ var filename_cpp
22+ concat filename_cpp "./src/" base_filename ".cpp"
23+
24+ var filename_h
25+ concat filename_h "./src/" base_filename ".h"
26+
27+ var ifndef_header
28+ set_value ifndef_header base_filename
29+ concat ifndef_header "_H"
30+
31+ to_upper_case ifndef_header
32+
33+ var content_header
34+ concat content_header "#ifndef " ifndef_header "
35+ #define " ifndef_header "
36+
37+ #include <wsjcpp_light_web_server.h>
38+
39+ class " class_name " : public WSJCppLightWebHttpHandlerBase {
40+ public:
41+ " class_name "();
42+ virtual bool canHandle(const std::string &sWorkerId, WSJCppLightWebHttpRequest *pRequest);
43+ virtual bool handle(const std::string &sWorkerId, WSJCppLightWebHttpRequest *pRequest);
44+
45+ private:
46+ std::string TAG;
47+ };
48+
49+ #endif // " ifndef_header
50+
51+
52+ var content_source
53+ concat content_source "
54+ #include \"" base_filename ".h\"
55+ #include <wsjcpp_core.h>
56+
57+ // ---------------------------------------------------------------------
58+ // " class_name "
59+
60+ " class_name "::" class_name "()
61+ : WSJCppLightWebHttpHandlerBase(\"" http_handler_name "\") {
62+ TAG = \"" class_name "\";
63+ }
64+
65+ // ---------------------------------------------------------------------
66+
67+ bool " class_name "::canHandle(const std::string &sWorkerId, WSJCppLightWebHttpRequest *pRequest) {
68+ std::string _tag = TAG + \"-\" + sWorkerId;
69+ std::string sRequestPath = pRequest->getRequestPath();
70+ WSJCppLog::warn(_tag, \"canHandle: \" + sRequestPath);
71+
72+ // TODO
73+ WSJCppLog::err(TAG, \"Not implemented\");
74+ return false;
75+ }
76+
77+ // ---------------------------------------------------------------------
78+
79+ bool " class_name "::handle(const std::string &sWorkerId, WSJCppLightWebHttpRequest *pRequest) {
80+ std::string _tag = TAG + \"-\" + sWorkerId;
81+ std::string sRequestPath = pRequest->getRequestPath();
82+ WSJCppLog::warn(_tag, sRequestPath);
83+ WSJCppLightWebHttpResponse resp(pRequest->getSockFd());
84+ resp.noCache().notImplemented().sendEmpty();
85+ return true;
86+ }
87+
88+ "
89+
90+ var file_source
91+ concat file_source "src/" filename_cpp
92+
93+ write_file filename_h content_header
94+ write_file filename_cpp content_source
95+
96+ log_info "
97+ ======
98+ Generated class:
99+ - " class_name "
100+ Generated files:
101+ - " filename_h "
102+ - " filename_cpp "
103+ ======
104+ "
105+
106+ cmakelists_txt_append_wsjcpp filename_h
107+ cmakelists_txt_append_wsjcpp filename_cpp
0 commit comments