AAO DRAMA/DRAMA2 C++ Interface
DRAMA C++11 and later interface
bulkdata.hh
Go to the documentation of this file.
1#ifndef _DRAMA2_BULKDATA_INC
2#define _DRAMA2_BULKDATA_INC
3
18/*
19 * History:
20 19-Feb-2015 - TJF - Original version
21
22 * The above ID is for Doxygen, this one has the format ACMM is looking for.
23 * "@(#) $Id$"
24 */
25#include "DitsBulk.h"
26//#define BULK_DEBUG1 // Uncomment to output debugging on BulkData class
27//#define BULK_DEBUG2 // Uncomment to output debugging on BulkDataArg class
28
29#if defined(BULK_DEBUG1) || defined(BULK_DEBUG2)
30#include <stdio.h>
31#endif
32
33namespace drama {
34
45 enum class ShareType {
46 Default = 0,
48#ifdef VxWorks
50#endif
51#ifdef DUNIX
54#endif
55 };
56
57
94 class BulkData {
95 private:
96
97 /*
98 * Pointer to the DRAMA task we are part of.
99 */
100 std::weak_ptr<Task> _theTask;
101
102 // Do we call DitsReleaseShared when destroying this object? Depends
103 // on how we were constructed.
104 bool _releaseOnDestruct = true;
105 // When calling DitsReleseShared, do we specify that the segment is
106 // to be deleted.
107 bool _deleteOnDestruct = false;
108 // DITS Shared memory details.
109 DitsSharedMemInfoType _memInfo;
110 // Address of memory itself.
111 void * _memAddress = nullptr;
112 // Size of memory in bytes.
113 unsigned long _size = 0;
114
115 // Clean up code called by destructor and move operators.
116 virtual void CleanUp() noexcept;
117
118 protected:
123 void * RawDataAddr() const {
124 return _memAddress;
125 }
130 unsigned long SizeBytes() const {
131 return _size;
132 }
133
134
135 public:
142 BulkData() {
143#ifdef BULK_DEBUG1
144 fprintf(stderr,"BulkData::Constructed empty item at address %p\n",
145 static_cast<void *>(this));
146#endif
147 }
185 BulkData(std::weak_ptr<Task> theTask,
186 long Size,
188 bool Create = true,
189 bool DeleteOnDestruct = true,
190 void *Address=nullptr,
191 const std::string & Name="",
192 int Key=0);
193
194
217 BulkData(std::weak_ptr<Task> theTask, const DitsBulkReportInfoType &info);
218
219
228 virtual ~BulkData() {
229#ifdef BULK_DEBUG1
230 fprintf(stderr,"BulkData:Destructor for item at address %p\n",
231 static_cast<void *>(this));
232#endif
233 CleanUp();
234 }
235
241 BulkData& operator=(const BulkData &rhs) = delete;
247 BulkData(const BulkData &source) = delete;
248
256 BulkData& operator=(BulkData &&rhs) noexcept {
257 if (this == &rhs) return (*this);
258#ifdef BULK_DEBUG1
259 fprintf(stderr,"BulkData:Move assignment item at address %p to %p\n",
260 static_cast<void *>(&rhs), static_cast<void *>(this));
261#endif
262 CleanUp();
263
264 _theTask = rhs._theTask;
265 _releaseOnDestruct = rhs._releaseOnDestruct;
266 _deleteOnDestruct = rhs._deleteOnDestruct;
267 _memInfo = rhs._memInfo;
268 _memAddress = rhs._memAddress;
269 _size = rhs._size;
270 rhs._memAddress = nullptr;
271 return *this;
272 }
280 _theTask(std::move(source._theTask)),
281 _releaseOnDestruct(std::move(source._releaseOnDestruct)),
282 _deleteOnDestruct(std::move(source._deleteOnDestruct)),
283 _memInfo(std::move(source._memInfo)),
284 _memAddress(std::move(source._memAddress)),
285 _size(std::move(source._size)) {
286 source._memAddress = nullptr;
287
288#ifdef BULK_DEBUG1
289 fprintf(stderr,"BulkData:Move copy item at address %p to %p\n",
290 static_cast<void *>(&source), static_cast<void *>(this));
291#endif
292
293 }
311 template <typename T>
312 T * Data(unsigned long *nitems=nullptr) {
313 /*
314 * Confirm the data type is a POD type.
315 * From C++20, std::is_pod<>() is depreciated, we can replace
316 * by std::is_standard_layout<>::value && std::is_trivial<>::value
317 */
318 static_assert(
319 (std::is_standard_layout<T>::value && std::is_trivial<T>::value) ,
320 "The type T must be a standard layout and trivial (POD) type");
321
322 // Do we have a valid item.
323 if (_memAddress == nullptr)
324 {
326 "Failed to create shared memory segement");
327
328 }
329 // Calculate the number of items.
330 if (nitems)
331 {
332 *nitems = _size / sizeof(T);
333 }
334#ifdef BULK_DEBUG1
335 fprintf(stderr,"BulkData:Accessing %p, data %p, size %lu, item size %u\n",
336 static_cast<void *>(this),
337 _memAddress,
338 _size, sizeof(T));
339#endif
340
341
342 return static_cast<T *>(_memAddress);
343 }
344
356
357 if (_memAddress == nullptr)
358 {
360 "Failed to create shared memory segement");
361
362 }
363 return _memInfo;
364 }
365
366
367 }; // class BulkData
368
407 class BulkDataSds : public BulkData, public sds::Id {
408
409 public:
416 BulkDataSds() {
417#ifdef BULK_DEBUG1
418 fprintf(stderr,"BulkDataSds::Constructed empty item at address %p\n",
419 static_cast<void *>(this));
420#endif
421 }
467 BulkDataSds(std::weak_ptr<Task> theTask,
468 const sds::Id &SdsTemplate,
470 bool Create = true,
471 bool DeleteOnDestruct = true,
472 void *Address=nullptr,
473 const std::string & Name="",
474 int Key=0);
475
476 }; // class BulkDataSds
477
486 class BulkDataArg : public BulkData {
487
488 std::weak_ptr<Task> _theTask; // Pointer to the DRAMA task we are part of.
489 bool _release = false; // Should item be released by destructor.
490 unsigned long _notifyBytes = 0; // Suggested notification interval.
491 DitsBulkReportInfoType _bulkInfo; // Bulk argument information
492
493 // Clean up code called by destructor and move operators.
494 virtual void ArgCleanUp() noexcept;
495 public:
502 BulkDataArg() {
503#ifdef BULK_DEBUG2
504 fprintf(stderr,"BulkDataArg::Constructed empty item at address %p\n",
505 static_cast<void *>(this));
506#endif
507 }
508 virtual ~BulkDataArg();
509
523 BulkDataArg(std::weak_ptr<Task> theTask);
524
532 BulkDataArg& operator=(BulkDataArg &&rhs) noexcept {
533#ifdef BULK_DEBUG2
535 "BulkDataArg:Move assignment item at address %p to %p\n",
536 static_cast<void *>(&rhs), static_cast<void *>(this));
537#endif
538 if (this == &rhs) return (*this);
539 ArgCleanUp();
540 // This is how we move the parent class.
541 BulkData::operator=(std::move(rhs));
542
543 _theTask = rhs._theTask;
544 _release = rhs._release;
545
546 return *this;
547 }
555 BulkData(std::move(source)),
556 _theTask(std::move(source._theTask)),
557 _release(std::move(source._release)) {
558#ifdef BULK_DEBUG2
560 "BulkDataArg:Move copy item at address %p to %p\n",
561 static_cast<void *>(&source), static_cast<void *>(this));
562#endif
563
564 }
572 unsigned long GetNotifyBytes() const {
573 return _notifyBytes;
574 }
575
589 void Report(unsigned bytes);
590
591 }; // BulkDataArg
592
605 class BulkDataArgSds : public BulkDataArg, public sds::Id {
606 public:
614#ifdef BULK_DEBUG2
615 fprintf(stderr,"BulkDataArgSds::Constructed empty item at address %p\n",
616 static_cast<void *>(this));
617#endif
618 }
619
633 BulkDataArgSds(std::weak_ptr<Task> theTask);
634
635
636 }; // BulkDataArgSds
637} // namespace drama
638
639#endif
BulkDataArgSds(std::weak_ptr< Task > theTask)
Constructor - creates a BulkDataArgSds item by calling DitsBulkArgInfo() and then access the item wit...
BulkDataArgSds()
Default constructor.
Definition bulkdata.hh:640
Class used to access SDS structure in bulk data arguments.
Definition bulkdata.hh:632
BulkDataArg(BulkDataArg &&source) noexcept
Move copy constructor.
Definition bulkdata.hh:581
BulkDataArg(std::weak_ptr< Task > theTask)
Constructor - creates a BulkDataArg item by calling DitsBulkArgInfo().
void Report(unsigned bytes)
Notify DRAMA of the number of bulk data bytes used/processed.
BulkDataArg()
Default constructor.
Definition bulkdata.hh:529
BulkDataArg & operator=(BulkDataArg &&rhs) noexcept
Move assignment operator.
Definition bulkdata.hh:559
unsigned long GetNotifyBytes() const
Returns the notification size.
Definition bulkdata.hh:599
A class used to manage a bulk data argument to an action.
Definition bulkdata.hh:513
BulkDataSds()
Default constructor.
Definition bulkdata.hh:443
BulkDataSds(std::weak_ptr< Task > theTask, const sds::Id &SdsTemplate, ShareType type=ShareType::Create, bool Create=true, bool DeleteOnDestruct=true, void *Address=nullptr, const std::string &Name="", int Key=0)
Define a bulk data shared memory segment of the specified type for use with DRAMA 2 methods which can...
Defines and optionally creates a shared memory section containing an SDS structure.
Definition bulkdata.hh:434
BulkData & operator=(const BulkData &rhs)=delete
Assignment operator - deleted.
BulkData(std::weak_ptr< Task > theTask, long Size, ShareType type=ShareType::Create, bool Create=true, bool DeleteOnDestruct=true, void *Address=nullptr, const std::string &Name="", int Key=0)
Define a bulk data shared memory segment of the specified type for use with DRAMA 2 methods which can...
BulkData(const BulkData &source)=delete
Copy constructor - deleted.
void * RawDataAddr() const
Returns the raw address of the data.
Definition bulkdata.hh:150
T * Data(unsigned long *nitems=nullptr)
Return a pointer to the actual data.
Definition bulkdata.hh:339
virtual ~BulkData()
Destructor.
Definition bulkdata.hh:255
BulkData & operator=(BulkData &&rhs) noexcept
Move assignment operator.
Definition bulkdata.hh:283
BulkData(BulkData &&source) noexcept
Move copy constructor.
Definition bulkdata.hh:306
BulkData(std::weak_ptr< Task > theTask, const DitsBulkReportInfoType &info)
Define a bulk data shared memory segment based on a DitsBulkReportInfoType item.
unsigned long SizeBytes() const
Return the size of the data in bytes.
Definition bulkdata.hh:157
BulkData()
Default constructor.
Definition bulkdata.hh:169
DitsSharedMemInfoType & GetDitsSharedMemInfo()
Return a reference to the DitsSharedMemInfoType object managed by this.
Definition bulkdata.hh:382
Defines and optionally creates a shared memory section.
Definition bulkdata.hh:121
A C++ Interface to the handling SDS structures.
Definition sds.hh:428
#define DramaTHROW(status_, message_)
Throw a Drama exception.
Definition exception.hh:93
ShareType
Share memory type codes.
Definition bulkdata.hh:72
@ Create
Create any temporary memory section.
@ Default
System default type.
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1322
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:93