GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tech/cxx_gateservices.cpp
Date: 2026-10-19 17:06:30
Exec Total Coverage
Lines: 60 240 25.0%
Functions: 16 64 25.0%
Branches: 14 130 10.8%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2026, 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/gateservices.hpp"
30 #include "gate/exceptions.hpp"
31 #include "gate/utilities.hpp"
32 #include "gate/tech/microservices/webcontent_service.h"
33
34 namespace gate
35 {
36 namespace tech
37 {
38
39 1 ServiceHost::ServiceHost(gate_servicehost_t* host)
40 1 : object_impl_t(host)
41 {
42 1 }
43
44 ✗ ServiceHost::ServiceHost(ServiceHost const& src)
45 ✗ : object_impl_t(src)
46 {
47 ✗ }
48 ✗ ServiceHost::ServiceHost()
49 ✗ : object_impl_t(gate_servicehost_create())
50 {
51 ✗ }
52 ✗ ServiceHost& ServiceHost::operator=(ServiceHost const& src)
53 {
54 ✗ if (this != &src)
55 {
56 ✗ ServiceHost that(src);
57 ✗ this->swap(that);
58 }
59 ✗ return *this;
60 }
61 1 ServiceHost::~ServiceHost() noexcept
62 {
63 1 }
64
65 1 void ServiceHost::publishMessage(String const& sourceAddress, String const& destinationAddress, String const& msgId, String const& message)
66 {
67 1 result_t result = gate_servicehost_publish_message(this->c_impl(),
68 sourceAddress.c_impl(), destinationAddress.c_impl(),
69 msgId.c_impl(), message.c_impl());
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
71 1 }
72 ✗ void ServiceHost::publishObject(String const& sourceAddress, String const& destinationAddress, String const& objId, Object& obj)
73 {
74 ✗ result_t result = gate_servicehost_publish_object(this->c_impl(),
75 sourceAddress.c_impl(), destinationAddress.c_impl(),
76 objId.c_impl(), obj.c_impl());
77 ✗ GATEXX_CHECK_EXCEPTION(result);
78 ✗ }
79
80 1 void ServiceHost::subscribeMessages(String const& sourceAddress, String const& destinationAddress, String const& msgId, MicroService& subScriber, void* userData)
81 {
82 1 result_t result = gate_servicehost_subscribe_messages(this->c_impl(),
83 sourceAddress.c_impl(), destinationAddress.c_impl(),
84 msgId.c_impl(), subScriber.c_impl(), userData);
85
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
86 1 }
87 ✗ void ServiceHost::unsubscribeMessages(String const& sourceAddress, String const& destinationAddress, String const& msgId, MicroService& subScriber, void* userData)
88 {
89 ✗ result_t result = gate_servicehost_unsubscribe_messages(this->c_impl(),
90 sourceAddress.c_impl(), destinationAddress.c_impl(),
91 msgId.c_impl(), subScriber.c_impl(), userData);
92 ✗ GATEXX_CHECK_EXCEPTION(result);
93 ✗ }
94
95 ✗ void ServiceHost::subscribeOjbects(String const& sourceAddress, String const& destinationAddress, String const& objId, MicroService& subscriber, void* userData)
96 {
97 ✗ result_t result = gate_servicehost_subscribe_objects(this->c_impl(),
98 sourceAddress.c_impl(), destinationAddress.c_impl(),
99 objId.c_impl(), subscriber.c_impl(), userData);
100 ✗ GATEXX_CHECK_EXCEPTION(result);
101 ✗ }
102 ✗ void ServiceHost::unsubscribeObjects(String const& sourceAddress, String const& destinationAddress, String const& objId, MicroService& subscriber, void* userData)
103 {
104 ✗ result_t result = gate_servicehost_unsubscribe_objects(this->c_impl(),
105 sourceAddress.c_impl(), destinationAddress.c_impl(),
106 objId.c_impl(), subscriber.c_impl(), userData);
107 ✗ GATEXX_CHECK_EXCEPTION(result);
108 ✗ }
109
110 ✗ void ServiceHost::remoteInvoke(String const& destinationAddress, String const& method, ConstStruct const& inputData, MutableStruct& outputData)
111 {
112 ✗ result_t result = gate_servicehost_remote_invoke(this->c_impl(),
113 destinationAddress.c_impl(), method.c_impl(),
114 inputData.c_impl(), outputData.c_impl());
115 ✗ GATEXX_CHECK_EXCEPTION(result);
116 ✗ }
117
118 ✗ void ServiceHost::log(uint32_t logType, result_t resultCode, int32_t nativeCode, String const& origin, String const& message)
119 {
120 ✗ result_t result = gate_servicehost_log(this->c_impl(),
121 logType, resultCode, nativeCode,
122 origin.c_impl(), message.c_impl());
123 ✗ GATEXX_CHECK_EXCEPTION(result);
124 ✗ }
125
126 2 void ServiceHost::addFactory(MicroFactory& factory, String const& factoryName)
127 {
128 2 result_t result = gate_servicehost_add_factory(this->c_impl(), factory.c_impl(), factoryName.c_impl());
129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_ERROR(result);
130 2 }
131 ✗ Array<String> ServiceHost::getFactoryServiceNames()
132 {
133 ✗ GenericArray names;
134 ✗ result_t result = gate_servicehost_get_factory_service_names(this->c_impl(), names.c_impl());
135 ✗ GATEXX_CHECK_ERROR(result);
136
137 ✗ ArrayList<String> ret = gate::util::convertStringArray(*names.c_impl());
138 ✗ return ret.toArray();
139 }
140
141 ✗ void ServiceHost::removeFactory(String const& factoryName)
142 {
143 ✗ result_t result = gate_servicehost_remove_factory(this->c_impl(), factoryName.c_impl());
144 ✗ GATEXX_CHECK_ERROR(result);
145 ✗ }
146
147 3 String ServiceHost::createService(String const& serviceName, String const& serviceInstance)
148 {
149 3 gate_string_t address = GATE_STRING_INIT_EMPTY;
150
1/2
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 result_t result = gate_servicehost_create_service(this->c_impl(),
151 serviceName.c_impl(), serviceInstance.c_impl(),
152 &address);
153
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
3 GATEXX_CHECK_ERROR(result);
154 6 return String::createFrom(address);
155 }
156
157 ✗ Array<String> ServiceHost::getServiceAddresses()
158 {
159 ✗ gate_array_t names = GATE_INIT_EMPTY;
160 ✗ result_t result = gate_servicehost_get_service_addresses(this->c_impl(), &names);
161 ✗ GATEXX_CHECK_ERROR(result);
162 ✗ ArrayList<String> list = util::createStringArray(names);
163 ✗ return list.toArray();
164 }
165
166 1 MicroService ServiceHost::getService(String const& serviceAddress)
167 {
168 1 gate_microservice_t* ptrService = NULL;
169
1/2
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 result_t result = gate_servicehost_get_service(this->c_impl(), serviceAddress.c_impl(), &ptrService);
170
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
171 2 return MicroService(ptrService);
172 }
173
174 ✗ Value ServiceHost::getServiceConfig(String const& serviceAddress, uint32_t configType)
175 {
176 ✗ Value ret;
177 ✗ result_t result = gate_servicehost_get_service_config(this->c_impl(), serviceAddress.c_impl(), configType, ret.c_impl());
178 ✗ GATEXX_CHECK_EXCEPTION(result);
179 ✗ return ret;
180 }
181
182 ✗ void ServiceHost::setServiceConfig(String const& serviceAddress, uint32_t configType, Value const& value)
183 {
184 ✗ result_t result = gate_servicehost_set_service_config(this->c_impl(), serviceAddress.c_impl(), configType, value.c_impl());
185 ✗ GATEXX_CHECK_EXCEPTION(result);
186 ✗ }
187
188 3 void ServiceHost::startService(String const& serviceAddress)
189 {
190 3 result_t result = gate_servicehost_start_service(this->c_impl(), serviceAddress.c_impl());
191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 GATEXX_CHECK_EXCEPTION(result);
192 3 }
193
194 3 void ServiceHost::stopService(String const& serviceAddress)
195 {
196 3 result_t result = gate_servicehost_stop_service(this->c_impl(), serviceAddress.c_impl());
197
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 GATEXX_CHECK_EXCEPTION(result);
198 3 }
199
200 ✗ void ServiceHost::releaseService(String const& serviceAddress)
201 {
202 ✗ result_t result = gate_servicehost_release_service(this->c_impl(), serviceAddress.c_impl());
203 ✗ GATEXX_CHECK_ERROR(result);
204 ✗ }
205
206 1 void ServiceHost::startup()
207 {
208 1 result_t result = gate_servicehost_startup(this->c_impl());
209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
210 1 }
211 1 void ServiceHost::shutdown(bool_t releaseServices)
212 {
213 1 result_t result = gate_servicehost_shutdown(this->c_impl(), releaseServices);
214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
215 1 }
216
217 1 ServiceHost ServiceHost::create()
218 {
219 1 gate_servicehost_t* host = gate_servicehost_create();
220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (NULL == host)
221 {
222 ✗ GATEXX_RAISE_ERROR(results::OutOfResources);
223 }
224 1 return ServiceHost(host);
225 }
226
227
228 ✗ void ServiceHost::loadConfig(Stream& sourceStream, uint32_t format, Config& targetConfig)
229 {
230 ✗ result_t result = gate_servicehost_load_config(sourceStream.c_impl(), format, targetConfig.c_instance());
231 ✗ GATEXX_CHECK_EXCEPTION(result);
232 ✗ }
233 ✗ void ServiceHost::saveConfig(Config const& sourceConfig, uint32_t format, Stream& targetStream)
234 {
235 ✗ result_t result = gate_servicehost_save_config(sourceConfig.c_instance(), format, targetStream.c_impl());
236 ✗ GATEXX_CHECK_EXCEPTION(result);
237 ✗ }
238
239 1 MicroFactory ServiceHost::getEssentialsFactory()
240 {
241 1 gate_microfactory_t* ptrFactory = gate_servicehost_essentials_factory();
242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!ptrFactory)
243 {
244 ✗ GATEXX_RAISE_EXCEPTION(results::NotAvailable, "Essential microservices factory not available", 0);
245 }
246 1 return MicroFactory(ptrFactory);
247 }
248
249 static StaticString const name_webcontent = GATE_MICROSERVICE_NAME_WEBCONTENT;
250
251 class GATE_TECH_CPP_API ExtensionFactory : public MicroFactoryBase
252 {
253 public:
254 1 ExtensionFactory()
255 1 {
256 1 }
257 4 virtual ~ExtensionFactory() noexcept
258 2 {
259
260 4 }
261
262 ✗ virtual Array<String> getSupportedServiceNames() override
263 {
264 ✗ ArrayList<String> lst;
265 ✗ lst.add(name_webcontent);
266 ✗ return lst.toArray();
267 }
268
269 ✗ virtual MicroService createService(String const& serviceName) override
270 {
271 ✗ if (serviceName == name_webcontent)
272 {
273 ✗ gate_microservice_t* ptr = gate_microservice_webcontent_create();
274 ✗ if (!ptr)
275 {
276 ✗ gate::raiseError(results::OutOfMemory);
277 }
278 ✗ return MicroService(ptr);
279 }
280 ✗ gate::raiseException(results::NoMatch);
281 ✗ return MicroService(NULL);
282 }
283 };
284
285 1 MicroFactory ServiceHost::getEssentialsExtensionsFactory()
286 {
287
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 ExtensionFactory* ptr = new ExtensionFactory();
288 1 return ptr->getInstance();
289 }
290
291
292
293 ✗ void ServiceHost::importConfig(Config const& cfg)
294 {
295 ✗ result_t result = gate_servicehost_import_config(this->c_impl(), cfg.c_instance());
296 ✗ GATEXX_CHECK_EXCEPTION(result);
297 ✗ }
298 ✗ void ServiceHost::exportConfig(Config& cfg)
299 {
300 ✗ result_t result = gate_servicehost_export_config(this->c_impl(), cfg.c_instance());
301 ✗ GATEXX_CHECK_EXCEPTION(result);
302 ✗ }
303
304 ✗ void ServiceHost::releaseServices()
305 {
306 ✗ result_t result = gate_servicehost_release_services(this->c_impl());
307 ✗ GATEXX_CHECK_ERROR(result);
308 ✗ }
309
310
311
312
313
314
315
316 ✗ ServiceHost::ConfigService::ConfigService()
317 ✗ : struct_instance_t(&gate_servicehost_config_service_init)
318 {
319 ✗ }
320 ✗ ServiceHost::ConfigService::ConfigService(gate_servicehost_config_service_t const& src)
321 ✗ : struct_instance_t(src)
322 {
323 ✗ }
324
325
326 ✗ String ServiceHost::ConfigService::getName() const
327 {
328 ✗ return String::duplicate((*this)->name);
329 }
330 ✗ void ServiceHost::ConfigService::setName(String const& value)
331 {
332 ✗ String::assign((*this)->name, value);
333 ✗ }
334
335 ✗ String ServiceHost::ConfigService::getInstance() const
336 {
337 ✗ return String::duplicate((*this)->instance);
338 }
339 ✗ void ServiceHost::ConfigService::setInstance(String const& value)
340 {
341 ✗ String::assign((*this)->instance, value);
342 ✗ }
343
344 ✗ ArrayList<String> ServiceHost::ConfigService::getMessageSubscriptions() const
345 {
346 ✗ ArrayList<String> tmp = util::convertStringArray((*this)->msg_subscriptions);
347 ✗ return tmp;
348 }
349 ✗ void ServiceHost::ConfigService::setMessageSubscriptions(ArrayList<String> const& value)
350 {
351 ✗ gate_arraylist_t list = util::convertStringArray(value);
352 ✗ gate_arraylist_release(&((*this)->msg_subscriptions));
353 ✗ (*this)->msg_subscriptions = list;
354 ✗ }
355
356 ✗ ArrayList<String> ServiceHost::ConfigService::getObjectSubscriptions() const
357 {
358 ✗ ArrayList<String> tmp = util::convertStringArray((*this)->obj_subscriptions);
359 ✗ return tmp;
360 }
361 ✗ void ServiceHost::ConfigService::setObjectSubscriptions(ArrayList<String> const& value)
362 {
363 ✗ gate_arraylist_t list = util::convertStringArray(value);
364 ✗ gate_arraylist_release(&((*this)->obj_subscriptions));
365 ✗ (*this)->obj_subscriptions = list;
366 ✗ }
367
368 ✗ String ServiceHost::ConfigService::getServiceGroup() const
369 {
370 ✗ return String::duplicate((*this)->service_group);
371 }
372 ✗ void ServiceHost::ConfigService::setServiceGroup(String const& value)
373 {
374 ✗ String::assign((*this)->service_group, value);
375 ✗ }
376 ✗ bool ServiceHost::ConfigService::getAutostart() const
377 {
378 ✗ return (*this)->autostart;
379 }
380 ✗ void ServiceHost::ConfigService::setAutostart(bool const& value)
381 {
382 ✗ (*this)->autostart = value;
383 ✗ }
384 ✗ uint32_t ServiceHost::ConfigService::getStartOrder() const
385 {
386 ✗ return (*this)->startorder;
387 }
388 ✗ void ServiceHost::ConfigService::setStartOrder(uint32_t const& value)
389 {
390 ✗ (*this)->startorder = value;
391 ✗ }
392
393 ✗ Property ServiceHost::ConfigService::getParameters() const
394 {
395 ✗ return Property((*this)->parameters);
396 }
397 ✗ void ServiceHost::ConfigService::setParameters(Property const& value)
398 {
399 ✗ Property::assignCopy((*this)->parameters, value);
400 ✗ }
401
402 ✗ ServiceHost::Config::Config()
403 ✗ : struct_instance_t(&gate_servicehost_config_init)
404 {
405 ✗ }
406
407 ✗ ServiceHost::Config::Config(gate_servicehost_config_t const& src)
408 ✗ : struct_instance_t(src)
409 {
410 ✗ }
411
412
413 ✗ String ServiceHost::Config::getId() const
414 {
415 ✗ return String::duplicate((*this)->id);
416 }
417 ✗ void ServiceHost::Config::setId(String const& value)
418 {
419 ✗ String::assign((*this)->id, value);
420 ✗ }
421
422 ✗ String ServiceHost::Config::getVersion() const
423 {
424 ✗ return String::duplicate((*this)->version);
425 }
426 ✗ void ServiceHost::Config::setVersion(String const& value)
427 {
428 ✗ String::assign((*this)->version, value);
429 ✗ }
430
431 ✗ ArrayList<ServiceHost::ConfigService> ServiceHost::Config::getServices() const
432 {
433 ✗ ArrayList<ServiceHost::ConfigService> ret;
434 ✗ ret.importFrom<gate_servicehost_config_service_t>(this->c_instance()->services);
435 ✗ return ret;
436 }
437 ✗ void ServiceHost::Config::setServices(ArrayList<ServiceHost::ConfigService> const& value)
438 {
439 GenericArrayList arr(sizeof(gate_servicehost_config_service_t), NULL, 0,
440 ✗ &gate_servicehost_config_service_copy_constructor, &gate_struct_destructor);
441
442 ✗ ArrayList<ServiceHost::ConfigService>::const_iterator iter = value.begin();
443 ✗ ArrayList<ServiceHost::ConfigService>::const_iterator end = value.end();
444 ✗ for (; iter != end; ++iter)
445 {
446 ✗ arr.add(iter->c_instance());
447 }
448 ✗ gate_arraylist_release(&this->c_instance()->services);
449 ✗ this->c_instance()->services = arr.c_impl();
450 ✗ gate_arraylist_retain(&arr.c_impl());
451 ✗ }
452
453
454 } // end of namespace sys
455 } // end of namespace gate
456