GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tech/cxx_gateservices.cpp
Date: 2026-12-03 19:36:00
Exec Total Coverage
Lines: 177 240 73.8%
Functions: 48 64 75.0%
Branches: 46 130 35.4%

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 3 ServiceHost::ServiceHost(ServiceHost const& src)
45 3 : object_impl_t(src)
46 {
47 3 }
48 1 ServiceHost::ServiceHost()
49 1 : object_impl_t(gate_servicehost_create())
50 {
51 1 }
52 1 ServiceHost& ServiceHost::operator=(ServiceHost const& src)
53 {
54
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (this != &src)
55 {
56 2 ServiceHost that(src);
57 1 this->swap(that);
58 }
59 1 return *this;
60 }
61 5 ServiceHost::~ServiceHost() noexcept
62 {
63 5 }
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 1 void ServiceHost::unsubscribeMessages(String const& sourceAddress, String const& destinationAddress, String const& msgId, MicroService& subScriber, void* userData)
88 {
89 1 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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
93 1 }
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 1 Array<String> ServiceHost::getFactoryServiceNames()
132 {
133 2 GenericArray names;
134
1/2
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 result_t result = gate_servicehost_get_factory_service_names(this->c_impl(), names.c_impl());
135
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_ERROR(result);
136
137
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 ArrayList<String> ret = gate::util::convertStringArray(*names.c_impl());
138
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return ret.toArray();
139 }
140
141 2 void ServiceHost::removeFactory(String const& factoryName)
142 {
143 2 result_t result = gate_servicehost_remove_factory(this->c_impl(), factoryName.c_impl());
144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_ERROR(result);
145 2 }
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 1 Array<String> ServiceHost::getServiceAddresses()
158 {
159 1 gate_array_t names = GATE_INIT_EMPTY;
160
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 result_t result = gate_servicehost_get_service_addresses(this->c_impl(), &names);
161
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_ERROR(result);
162
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 ArrayList<String> list = util::createStringArray(names);
163
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return list.toArray();
164 }
165
166 2 MicroService ServiceHost::getService(String const& serviceAddress)
167 {
168 2 gate_microservice_t* ptrService = NULL;
169
1/2
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 result_t result = gate_servicehost_get_service(this->c_impl(), serviceAddress.c_impl(), &ptrService);
170
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_EXCEPTION(result);
171 4 return MicroService(ptrService);
172 }
173
174 1 Value ServiceHost::getServiceConfig(String const& serviceAddress, ConfigTypeEnum configType)
175 {
176 1 Value ret;
177
1/2
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 result_t result = gate_servicehost_get_service_config(
178 this->c_impl(), serviceAddress.c_impl(), static_cast<enumint_t>(configType), ret.c_impl());
179
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
180 1 return ret;
181 }
182
183 2 void ServiceHost::setServiceConfig(String const& serviceAddress, ConfigTypeEnum configType, Value const& value)
184 {
185 2 result_t result = gate_servicehost_set_service_config(
186 this->c_impl(), serviceAddress.c_impl(), static_cast<enumint_t>(configType), value.c_impl());
187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
188 2 }
189
190 2 void ServiceHost::startService(String const& serviceAddress)
191 {
192 2 result_t result = gate_servicehost_start_service(this->c_impl(), serviceAddress.c_impl());
193
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
194 2 }
195
196 3 void ServiceHost::stopService(String const& serviceAddress)
197 {
198 3 result_t result = gate_servicehost_stop_service(this->c_impl(), serviceAddress.c_impl());
199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 GATEXX_CHECK_EXCEPTION(result);
200 3 }
201
202 ✗ void ServiceHost::releaseService(String const& serviceAddress)
203 {
204 ✗ result_t result = gate_servicehost_release_service(this->c_impl(), serviceAddress.c_impl());
205 ✗ GATEXX_CHECK_ERROR(result);
206 ✗ }
207
208 1 void ServiceHost::startup()
209 {
210 1 result_t result = gate_servicehost_startup(this->c_impl());
211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
212 1 }
213 1 void ServiceHost::shutdown(bool_t releaseServices)
214 {
215 1 result_t result = gate_servicehost_shutdown(this->c_impl(), releaseServices);
216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
217 1 }
218
219 1 ServiceHost ServiceHost::create()
220 {
221 1 gate_servicehost_t* host = gate_servicehost_create();
222
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (NULL == host)
223 {
224 ✗ GATEXX_RAISE_ERROR(results::OutOfResources);
225 }
226 1 return ServiceHost(host);
227 }
228
229
230 1 void ServiceHost::loadConfig(Stream& sourceStream, ConfigFormat format, Config& targetConfig)
231 {
232 1 result_t result = gate_servicehost_load_config(sourceStream.c_impl(), static_cast<enumint_t>(format), targetConfig.c_instance());
233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
234 1 }
235 1 void ServiceHost::saveConfig(Config const& sourceConfig, ConfigFormat format, Stream& targetStream)
236 {
237 1 result_t result = gate_servicehost_save_config(sourceConfig.c_instance(), static_cast<enumint_t>(format), targetStream.c_impl());
238
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
239 1 }
240
241 1 MicroFactory ServiceHost::getEssentialsFactory()
242 {
243 1 gate_microfactory_t* ptrFactory = gate_servicehost_essentials_factory();
244
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!ptrFactory)
245 {
246 ✗ GATEXX_RAISE_EXCEPTION(results::NotAvailable, "Essential microservices factory not available", 0);
247 }
248 1 return MicroFactory(ptrFactory);
249 }
250
251 static StaticString const name_webcontent = GATE_MICROSERVICE_NAME_WEBCONTENT;
252
253 class GATE_TECH_CPP_API ExtensionFactory : public MicroFactoryBase
254 {
255 public:
256 1 ExtensionFactory()
257 1 {
258 1 }
259
260 4 virtual ~ExtensionFactory() noexcept
261 2 {
262 4 }
263
264 ✗ virtual Array<String> getSupportedServiceNames() override
265 {
266 ✗ ArrayList<String> lst;
267 ✗ lst.add(name_webcontent);
268 ✗ return lst.toArray();
269 }
270
271 ✗ virtual MicroService createService(String const& serviceName) override
272 {
273 ✗ if (serviceName == name_webcontent)
274 {
275 ✗ gate_microservice_t* ptr = gate_microservice_webcontent_create();
276 ✗ if (!ptr)
277 {
278 ✗ gate::raiseError(results::OutOfMemory);
279 }
280 ✗ return MicroService(ptr);
281 }
282 ✗ gate::raiseException(results::NoMatch);
283 ✗ return MicroService(NULL);
284 }
285 };
286
287 1 MicroFactory ServiceHost::getEssentialsExtensionsFactory()
288 {
289
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 ExtensionFactory* ptr = new ExtensionFactory();
290 1 return ptr->getInstance();
291 }
292
293 1 void ServiceHost::importConfig(Config const& cfg)
294 {
295 1 result_t result = gate_servicehost_import_config(this->c_impl(), cfg.c_instance());
296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
297 1 }
298 1 void ServiceHost::exportConfig(Config& cfg)
299 {
300 1 result_t result = gate_servicehost_export_config(this->c_impl(), cfg.c_instance());
301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
302 1 }
303
304 1 void ServiceHost::releaseServices()
305 {
306 1 result_t result = gate_servicehost_release_services(this->c_impl());
307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
308 1 }
309
310
311
312
313
314
315
316 1 ServiceHost::ConfigService::ConfigService()
317 1 : struct_instance_t(&gate_servicehost_config_service_init)
318 {
319 1 }
320 1 ServiceHost::ConfigService::ConfigService(gate_servicehost_config_service_t const& src)
321 1 : struct_instance_t(src)
322 {
323 1 }
324
325
326 1 String ServiceHost::ConfigService::getName() const
327 {
328 1 return String::duplicate((*this)->name);
329 }
330 1 void ServiceHost::ConfigService::setName(String const& value)
331 {
332 1 String::assign((*this)->name, value);
333 1 }
334
335 1 String ServiceHost::ConfigService::getInstance() const
336 {
337 1 return String::duplicate((*this)->instance);
338 }
339 1 void ServiceHost::ConfigService::setInstance(String const& value)
340 {
341 1 String::assign((*this)->instance, value);
342 1 }
343
344 ✗ ArrayList<String> ServiceHost::ConfigService::getMessageSubscriptions() const
345 {
346 ✗ ArrayList<String> tmp = util::convertStringArray((*this)->msg_subscriptions);
347 ✗ return tmp;
348 }
349 1 void ServiceHost::ConfigService::setMessageSubscriptions(ArrayList<String> const& value)
350 {
351
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_arraylist_t list = util::convertStringArray(value);
352
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 gate_arraylist_release(&((*this)->msg_subscriptions));
353
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 (*this)->msg_subscriptions = list;
354 1 }
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 1 String ServiceHost::ConfigService::getServiceGroup() const
369 {
370 1 return String::duplicate((*this)->service_group);
371 }
372 1 void ServiceHost::ConfigService::setServiceGroup(String const& value)
373 {
374 1 String::assign((*this)->service_group, value);
375 1 }
376 1 bool ServiceHost::ConfigService::getAutostart() const
377 {
378 1 return (*this)->autostart;
379 }
380 1 void ServiceHost::ConfigService::setAutostart(bool const& value)
381 {
382 1 (*this)->autostart = value;
383 1 }
384 1 uint32_t ServiceHost::ConfigService::getStartOrder() const
385 {
386 1 return (*this)->startorder;
387 }
388 1 void ServiceHost::ConfigService::setStartOrder(uint32_t const& value)
389 {
390 1 (*this)->startorder = value;
391 1 }
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 2 ServiceHost::Config::Config()
403 2 : struct_instance_t(&gate_servicehost_config_init)
404 {
405 2 }
406
407 ✗ ServiceHost::Config::Config(gate_servicehost_config_t const& src)
408 ✗ : struct_instance_t(src)
409 {
410 ✗ }
411
412
413 1 String ServiceHost::Config::getId() const
414 {
415 1 return String::duplicate((*this)->id);
416 }
417 ✗ void ServiceHost::Config::setId(String const& value)
418 {
419 ✗ String::assign((*this)->id, value);
420 ✗ }
421
422 1 String ServiceHost::Config::getVersion() const
423 {
424 1 return String::duplicate((*this)->version);
425 }
426 ✗ void ServiceHost::Config::setVersion(String const& value)
427 {
428 ✗ String::assign((*this)->version, value);
429 ✗ }
430
431 1 ArrayList<ServiceHost::ConfigService> ServiceHost::Config::getServices() const
432 {
433 1 ArrayList<ServiceHost::ConfigService> ret;
434
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 ret.importFrom<gate_servicehost_config_service_t>(this->c_instance()->services);
435 1 return ret;
436 }
437 1 void ServiceHost::Config::setServices(ArrayList<ServiceHost::ConfigService> const& value)
438 {
439 GenericArrayList arr(sizeof(gate_servicehost_config_service_t), NULL, 0,
440
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 &gate_servicehost_config_service_copy_constructor, &gate_struct_destructor);
441
442 1 ArrayList<ServiceHost::ConfigService>::const_iterator iter = value.begin();
443 1 ArrayList<ServiceHost::ConfigService>::const_iterator end = value.end();
444
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (; iter != end; ++iter)
445 {
446
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 arr.add(iter->c_instance());
447 }
448
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 gate_arraylist_release(&this->c_instance()->services);
449
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 this->c_instance()->services = arr.c_impl();
450
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 gate_arraylist_retain(&arr.c_impl());
451 1 }
452
453
454 } // end of namespace sys
455 } // end of namespace gate
456