@@ -282,6 +282,148 @@ PoshRuntimeImpl::requestSubscriberFromRoudi(const IpcMessage& sendBuffer) noexce
282
282
return cxx::error<IpcMessageErrorType>(IpcMessageErrorType::REQUEST_SUBSCRIBER_WRONG_IPC_MESSAGE_RESPONSE);
283
283
}
284
284
285
+ popo::ClientPortUser::MemberType_t* PoshRuntimeImpl::getMiddlewareClient (const capro::ServiceDescription& service,
286
+ const popo::ClientOptions& clientOptions,
287
+ const PortConfigInfo& portConfigInfo) noexcept
288
+ {
289
+ IpcMessage sendBuffer;
290
+ sendBuffer << IpcMessageTypeToString (IpcMessageType::CREATE_CLIENT) << m_appName
291
+ << static_cast <cxx::Serialization>(service).toString () << clientOptions.serialize ().toString ()
292
+ << static_cast <cxx::Serialization>(portConfigInfo).toString ();
293
+
294
+ auto maybeClient = requestClientFromRoudi (sendBuffer);
295
+ if (maybeClient.has_error ())
296
+ {
297
+ switch (maybeClient.get_error ())
298
+ {
299
+ case IpcMessageErrorType::CLIENT_LIST_FULL:
300
+ LogWarn () << " Could not create client as we are out of memory for clients." ;
301
+ errorHandler (Error::kPOSH__RUNTIME_ROUDI_OUT_OF_CLIENTS , nullptr , iox::ErrorLevel::SEVERE);
302
+ break ;
303
+ case IpcMessageErrorType::REQUEST_CLIENT_WRONG_IPC_MESSAGE_RESPONSE:
304
+ LogWarn () << " Could not create client; received wrong IPC channel response." ;
305
+ errorHandler (Error::kPOSH__RUNTIME_ROUDI_REQUEST_CLIENT_WRONG_IPC_MESSAGE_RESPONSE ,
306
+ nullptr ,
307
+ iox::ErrorLevel::SEVERE);
308
+ break ;
309
+ default :
310
+ LogWarn () << " Unknown error occurred while creating client" ;
311
+ errorHandler (Error::kPOSH__RUNTIME_CLIENT_PORT_CREATION_UNKNOWN_ERROR , nullptr , iox::ErrorLevel::SEVERE);
312
+ break ;
313
+ }
314
+ return nullptr ;
315
+ }
316
+ return maybeClient.value ();
317
+ }
318
+
319
+ cxx::expected<popo::ClientPortUser::MemberType_t*, IpcMessageErrorType>
320
+ PoshRuntimeImpl::requestClientFromRoudi (const IpcMessage& sendBuffer) noexcept
321
+ {
322
+ IpcMessage receiveBuffer;
323
+ if (sendRequestToRouDi (sendBuffer, receiveBuffer) && (3U == receiveBuffer.getNumberOfElements ()))
324
+ {
325
+ std::string IpcMessage = receiveBuffer.getElementAtIndex (0U );
326
+
327
+ if (stringToIpcMessageType (IpcMessage.c_str ()) == IpcMessageType::CREATE_CLIENT_ACK)
328
+ {
329
+ rp::BaseRelativePointer::id_t segmentId{0U };
330
+ cxx::convert::fromString (receiveBuffer.getElementAtIndex (2U ).c_str (), segmentId);
331
+ rp::BaseRelativePointer::offset_t offset{0U };
332
+ cxx::convert::fromString (receiveBuffer.getElementAtIndex (1U ).c_str (), offset);
333
+ auto ptr = rp::BaseRelativePointer::getPtr (segmentId, offset);
334
+ return cxx::success<popo::ClientPortUser::MemberType_t*>(
335
+ reinterpret_cast <popo::ClientPortUser::MemberType_t*>(ptr));
336
+ }
337
+ }
338
+ else
339
+ {
340
+ if (receiveBuffer.getNumberOfElements () == 2U )
341
+ {
342
+ std::string IpcMessage1 = receiveBuffer.getElementAtIndex (0U );
343
+ std::string IpcMessage2 = receiveBuffer.getElementAtIndex (1U );
344
+ if (stringToIpcMessageType (IpcMessage1.c_str ()) == IpcMessageType::ERROR)
345
+ {
346
+ LogError () << " Request client received no valid client port from RouDi." ;
347
+ return cxx::error<IpcMessageErrorType>(stringToIpcMessageErrorType (IpcMessage2.c_str ()));
348
+ }
349
+ }
350
+ }
351
+
352
+ LogError () << " Request client got wrong response from IPC channel :'" << receiveBuffer.getMessage () << " '" ;
353
+ return cxx::error<IpcMessageErrorType>(IpcMessageErrorType::REQUEST_CLIENT_WRONG_IPC_MESSAGE_RESPONSE);
354
+ }
355
+
356
+ popo::ServerPortUser::MemberType_t* PoshRuntimeImpl::getMiddlewareServer (const capro::ServiceDescription& service,
357
+ const popo::ServerOptions& ServerOptions,
358
+ const PortConfigInfo& portConfigInfo) noexcept
359
+ {
360
+ IpcMessage sendBuffer;
361
+ sendBuffer << IpcMessageTypeToString (IpcMessageType::CREATE_SERVER) << m_appName
362
+ << static_cast <cxx::Serialization>(service).toString () << ServerOptions.serialize ().toString ()
363
+ << static_cast <cxx::Serialization>(portConfigInfo).toString ();
364
+
365
+ auto maybeServer = requestServerFromRoudi (sendBuffer);
366
+ if (maybeServer.has_error ())
367
+ {
368
+ switch (maybeServer.get_error ())
369
+ {
370
+ case IpcMessageErrorType::SERVER_LIST_FULL:
371
+ LogWarn () << " Could not create server as we are out of memory for servers." ;
372
+ errorHandler (Error::kPOSH__RUNTIME_ROUDI_OUT_OF_SERVERS , nullptr , iox::ErrorLevel::SEVERE);
373
+ break ;
374
+ case IpcMessageErrorType::REQUEST_SERVER_WRONG_IPC_MESSAGE_RESPONSE:
375
+ LogWarn () << " Could not create server; received wrong IPC channel response." ;
376
+ errorHandler (Error::kPOSH__RUNTIME_ROUDI_REQUEST_SERVER_WRONG_IPC_MESSAGE_RESPONSE ,
377
+ nullptr ,
378
+ iox::ErrorLevel::SEVERE);
379
+ break ;
380
+ default :
381
+ LogWarn () << " Unknown error occurred while creating server" ;
382
+ errorHandler (Error::kPOSH__RUNTIME_SERVER_PORT_CREATION_UNKNOWN_ERROR , nullptr , iox::ErrorLevel::SEVERE);
383
+ break ;
384
+ }
385
+ return nullptr ;
386
+ }
387
+ return maybeServer.value ();
388
+ }
389
+
390
+ cxx::expected<popo::ServerPortUser::MemberType_t*, IpcMessageErrorType>
391
+ PoshRuntimeImpl::requestServerFromRoudi (const IpcMessage& sendBuffer) noexcept
392
+ {
393
+ IpcMessage receiveBuffer;
394
+ if (sendRequestToRouDi (sendBuffer, receiveBuffer) && (3U == receiveBuffer.getNumberOfElements ()))
395
+ {
396
+ std::string IpcMessage = receiveBuffer.getElementAtIndex (0U );
397
+
398
+ if (stringToIpcMessageType (IpcMessage.c_str ()) == IpcMessageType::CREATE_SERVER_ACK)
399
+ {
400
+ rp::BaseRelativePointer::id_t segmentId{0U };
401
+ cxx::convert::fromString (receiveBuffer.getElementAtIndex (2U ).c_str (), segmentId);
402
+ rp::BaseRelativePointer::offset_t offset{0U };
403
+ cxx::convert::fromString (receiveBuffer.getElementAtIndex (1U ).c_str (), offset);
404
+ auto ptr = rp::BaseRelativePointer::getPtr (segmentId, offset);
405
+ return cxx::success<popo::ServerPortUser::MemberType_t*>(
406
+ reinterpret_cast <popo::ServerPortUser::MemberType_t*>(ptr));
407
+ }
408
+ }
409
+ else
410
+ {
411
+ if (receiveBuffer.getNumberOfElements () == 2U )
412
+ {
413
+ std::string IpcMessage1 = receiveBuffer.getElementAtIndex (0U );
414
+ std::string IpcMessage2 = receiveBuffer.getElementAtIndex (1U );
415
+ if (stringToIpcMessageType (IpcMessage1.c_str ()) == IpcMessageType::ERROR)
416
+ {
417
+ LogError () << " Request server received no valid server port from RouDi." ;
418
+ return cxx::error<IpcMessageErrorType>(stringToIpcMessageErrorType (IpcMessage2.c_str ()));
419
+ }
420
+ }
421
+ }
422
+
423
+ LogError () << " Request server got wrong response from IPC channel :'" << receiveBuffer.getMessage () << " '" ;
424
+ return cxx::error<IpcMessageErrorType>(IpcMessageErrorType::REQUEST_SERVER_WRONG_IPC_MESSAGE_RESPONSE);
425
+ }
426
+
285
427
popo::InterfacePortData* PoshRuntimeImpl::getMiddlewareInterface (const capro::Interfaces interface,
286
428
const NodeName_t& nodeName) noexcept
287
429
{
0 commit comments