44#include < dbus2http/WebService.h>
55#include < dbus2http/entity/DbusSerialization.h>
66
7- #include < utility>
87#include < ranges>
8+ #include < utility>
99
1010// #embed "../dbus2http_openapi.yaml" as dbus2http_openapi_yaml
1111
@@ -18,7 +18,6 @@ bool WebService::parse_dbus_request_path(const std::string& path,
1818 std::string& object_path,
1919 std::string& interface_name,
2020 std::string& method) {
21-
2221 std::string rem = path;
2322 const auto first_slash = rem.find (' /' );
2423 if (first_slash == std::string::npos) {
@@ -100,22 +99,20 @@ WebService::WebService(DbusCaller& caller) : caller_(caller) {
10099)" ;
101100
102101 bool ret = server_.set_mount_point (" /" , " /opt/cosmos/var/www/dbus2http" );
103- if (not ret)
104- PLOGW << " set mount point failed" ;
102+ if (not ret) PLOGW << " set mount point failed" ;
105103
106104 // List DBus services
107105 server_.Get (" /dbus/service" , [this ](const auto & req, auto & res) {
108106 nlohmann::json j;
109107 j[" services" ] = nlohmann::json::array ();
110- for (const auto & service_name :
111- caller_.context ().object_paths | std::views::keys) {
108+ for (const auto & service_name : caller_.context ().get_service_names ()) {
112109 j[" services" ].push_back (service_name);
113110 }
114111 res.set_content (j.dump (), " application/json" );
115112 });
116113 server_.Get (" /dbus/html" , [&, header, footer](const auto & req, auto & res) {
117114 res.set_content (
118- header + Dbus2Html::to_html (caller_.context (). object_paths ) + footer,
115+ header + Dbus2Html::to_html (caller_.context ()) + footer,
119116 " text/html" );
120117 });
121118 server_.Get (R"( /dbus/interface/html/(.*))" , [&, header, footer](
@@ -124,9 +121,9 @@ WebService::WebService(DbusCaller& caller) : caller_(caller) {
124121 Dbus2Html::set_ws_port (std::to_string (ws_port_));
125122 if (suffix.find (' /' ) == std::string::npos) {
126123 const std::string& interface_name = suffix;
127- if (caller_.context ().interfaces . contains (interface_name)) {
124+ if (caller_.context ().contains_interface (interface_name)) {
128125 const Interface& interface =
129- caller_.context ().interfaces . at (interface_name);
126+ caller_.context ().get_interfaces (interface_name);
130127 res.set_content (header + Dbus2Html::to_html (interface) + footer,
131128 " text/html" );
132129 } else {
@@ -139,8 +136,8 @@ WebService::WebService(DbusCaller& caller) : caller_(caller) {
139136 std::string suffix = req.matches [1 ];
140137 if (suffix.find (' /' ) == std::string::npos) {
141138 const std::string& interface_name = suffix;
142- if (caller_.context ().interfaces . contains (interface_name)) {
143- nlohmann::json j = caller_.context ().interfaces . at (interface_name);
139+ if (caller_.context ().contains_interface (interface_name)) {
140+ nlohmann::json j = caller_.context ().get_interfaces (interface_name);
144141 res.set_content (j.dump (2 ), " application/json" );
145142 } else {
146143 res.status = 404 ;
@@ -197,7 +194,8 @@ WebService::WebService(DbusCaller& caller) : caller_(caller) {
197194 res.set_content (R"( {"message": ")" + what + " \" }" , " application/json" );
198195 }
199196 });
200- server_.Get (R"( /dbus/try/(.*))" , [this , try_html](const auto & req, auto & res) {
197+ server_.Get (R"( /dbus/try/(.*))" , [this , try_html](const auto & req,
198+ auto & res) {
201199 std::string service_name, object_path, interface_name, method;
202200 if (!parse_dbus_request_path (req.matches [1 ], service_name, object_path,
203201 interface_name, method)) {
@@ -224,8 +222,10 @@ WebService::WebService(DbusCaller& caller) : caller_(caller) {
224222 filled_html = replaceAll (filled_html, " $method_name$" , method);
225223 const auto & method_type =
226224 caller_.context ().get <Method>(interface_name, method);
227- filled_html = replaceAll (filled_html, " $request_signature$" , method_type.in_signature ());
228- filled_html = replaceAll (filled_html, " $response_signature$" , method_type.out_signature ());
225+ filled_html = replaceAll (filled_html, " $request_signature$" ,
226+ method_type.in_signature ());
227+ filled_html = replaceAll (filled_html, " $response_signature$" ,
228+ method_type.out_signature ());
229229 res.set_content (filled_html, " text/html" );
230230 } catch (const std::exception& e) {
231231 res.status = 500 ;
0 commit comments