GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tech/microservices/webcontent_service.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 50 0.0%
Functions: 0 16 0.0%
Branches: 0 26 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/tech/microservices/webcontent_service.h"
30
31 #include "gate/tech/microservices.hpp"
32 #include "gate/tech/microservices/webserver_service.h"
33 #include "gate/blobs.hpp"
34
35 namespace gate
36 {
37 namespace tech
38 {
39
40 /// @brief
41 class GATE_TECH_CPP_API WebContentService : public MicroServiceBase
42 {
43 public:
44 WebContentService();
45 virtual ~WebContentService() noexcept;
46
47 protected:
48 virtual void onStart() override;
49 virtual void onStop() override;
50 virtual void onDestroy() override;
51 virtual void onMessageReceived(String const& source, String const& destination, String const& msgId, String const& message) override;
52 virtual void onObjectReceived(String const& source, String const& destination, String const& objId, Object& obj) override;
53 virtual void onInvoke(String const& method, ConstStruct const& request, MutableStruct& response) override;
54
55 };
56
57 static StaticString const webcontent_name = "webcontent";
58
59 WebContentService::WebContentService()
60 : MicroServiceBase(webcontent_name)
61 {
62 }
63 WebContentService::~WebContentService() noexcept
64 {
65 }
66
67 void WebContentService::onStart()
68 {
69 }
70 void WebContentService::onStop()
71 {
72 }
73 void WebContentService::onDestroy()
74 {
75 }
76 void WebContentService::onMessageReceived(String const& source, String const& destination, String const& msgId, String const& message)
77 {
78 }
79 void WebContentService::onObjectReceived(String const& source, String const& destination, String const& objId, Object& obj)
80 {
81 }
82
83
84 class WebServiceResponse
85 {
86 public:
87 WebServiceResponse(gate_microservice_webservice_response_t& ref_response);
88
89 uint32_t getStatus() const;
90 void setStatus(uint32_t status);
91
92 Blob getContent() const;
93 void setContent(Blob const& blob);
94
95 String getContentType() const;
96 void setContentType(String const& value);
97
98 private:
99 gate_microservice_webservice_response_t& response;
100 };
101
102 WebServiceResponse::WebServiceResponse(gate_microservice_webservice_response_t& ref_response)
103 : response(ref_response)
104 {
105 }
106
107 uint32_t WebServiceResponse::getStatus() const
108 {
109 return this->response.status_code;
110 }
111 void WebServiceResponse::setStatus(uint32_t status)
112 {
113 this->response.status_code = status;
114 }
115
116 Blob WebServiceResponse::getContent() const
117 {
118 return Blob(this->response.content);
119 }
120 void WebServiceResponse::setContent(Blob const& blob)
121 {
122 gate_blob_release(&this->response.content);
123 gate_blob_create_clone(&this->response.content, blob.c_impl());
124 }
125
126 String WebServiceResponse::getContentType() const
127 {
128 return String(this->response.content_type);
129 }
130 void WebServiceResponse::setContentType(String const& value)
131 {
132 gate_string_release(&this->response.content_type);
133 gate_string_clone(&this->response.content_type, value.c_impl());
134 }
135
136
137
138 void WebContentService::onInvoke(String const& method, ConstStruct const& requestStruct, MutableStruct& responseStruct)
139 {
140 if (responseStruct.getStructName() == WEBSERVER_WEBSERVICE_RESPONSE)
141 {
142 WebServiceResponse response(*(gate_microservice_webservice_response_t*)responseStruct.c_impl());
143 char const* data = "<html><body>Hello World</body></html>";
144 Blob content(data, gate_str_length(data));
145 response.setContent(content);
146 response.setStatus(200);
147 }
148 }
149 }
150 }
151
152 #define GATE_TECH_
153
154 gate_microservice_t* gate_microservice_webcontent_create()
155 {
156 gate::tech::MicroServiceBase* ptr = new gate::tech::WebContentService();
157 gate::tech::MicroService ms = ptr->getInstance();
158 gate_microservice_t* impl = ms.c_impl();
159 if (impl)
160 {
161 gate_object_retain(impl);
162 }
163 return impl;
164 }
165