31 #include <ArmarXCore/interface/core/ManagedIceObjectDefinitions.h>
32 #include <ArmarXCore/interface/core/SharedMemory.h>
49 template <
class MemoryObject,
class MemoryObjectMetaInfo = MetaInfoSizeBase>
52 virtual public SharedMemoryConsumerInterface
67 this->
object = object;
68 this->providerName = providerName;
69 memoryName = providerName +
"Memory" + nameSuffix;
70 transferMode = eSharedMem;
72 object->usingProxy(providerName);
88 if (object->
getState() < eManagedIceObjectStarting)
98 if (transferMode == eIce)
100 ARMARX_INFO_S <<
"Transfer mode already set. Skipping autodetection";
105 ARMARX_WARNING_S <<
"Unable to determine hardware id. Using ice memory transfer as fallback.";
112 transferMode = eSharedMem;
115 catch (std::exception& e)
118 ARMARX_WARNING <<
"Initialization of shared memory '" << providerName <<
"' failed - failing back to Ice memory transfer - reason: " << e.what();
132 typename MemoryObjectMetaInfo::PointerType info;
142 void getData(std::vector<MemoryObject>&
data,
typename MemoryObjectMetaInfo::PointerType& info)
144 if (transferMode == eSharedMem)
146 return getDataSharedMemory(
data, info);
150 return getDataIce(
data, info);
156 if (transferMode == eSharedMem)
159 typename MemoryObjectMetaInfo::PointerType info = sharedMemoryConsumer->getMetaInfo();
164 return memoryProxy->getMetaInfo();
175 if (transferMode == eSharedMem)
177 return sharedMemoryConsumer->getSize();
181 return memoryProxy->getSize();
215 void initIce(Ice::ObjectPrx providerProxy)
219 memoryProxy =
object->getProxy<SharedMemoryProviderInterfacePrx>(memoryName,
true);
221 catch (std::exception& e)
224 <<
"\nOriginal exception: " << e.what();
241 void initSharedMemory()
250 void getDataSharedMemory(std::vector<MemoryObject>&
data,
typename MemoryObjectMetaInfo::PointerType& info)
255 auto p = this->sharedMemoryConsumer->getMetaInfo(
false);
259 using Ptr =
typename MemoryObjectMetaInfo::PointerType;
260 info = Ptr::dynamicCast(
new typename SharedMemoryType::Wrapper(*p));
264 throw exceptions::local::SharedMemoryConnectionFailure(memoryName,
"Info pointer is null.");
269 memcpy(
data.data(), sharedMemoryConsumer->getMemory(), size);
275 void getDataIce(std::vector<MemoryObject>&
data,
typename MemoryObjectMetaInfo::PointerType& info)
278 auto baseInfo = MetaInfoSizeBasePtr::dynamicCast(info);
280 if (!baseInfo && info)
282 throw exceptions::local::SharedMemoryConnectionFailure(memoryName,
"Error casting info var to base type.");
288 blob = memoryProxy->getData(baseInfo);
293 data.resize(baseInfo->size);
297 throw exceptions::local::SharedMemoryConnectionFailure(memoryName,
"Error retrieving data from shared memory proxy: " +
GetHandledExceptionString());
300 using Ptr =
typename MemoryObjectMetaInfo::PointerType;
301 info = Ptr::dynamicCast(baseInfo);
303 if (!info && baseInfo)
305 throw exceptions::local::SharedMemoryConnectionFailure(memoryName,
"Error casting back info var to desired type.");
308 memcpy(
data.data(), blob.data(), info->size);
316 SharedMemoryProviderInterfacePrx memoryProxy;
317 std::string memoryName;
318 std::string providerName;
321 using SharedMemoryType = SharedMemoryConsumer<MemoryObject, MemoryObjectMetaInfo>;
325 TransferMode transferMode;
326 ManagedIceObject* object;