dataexchange.h
Go to the documentation of this file.
259 BlockUploader,
261 IncreaseQueueSize,
263 SignalUploader
685 NoNotificationBlocking,
688 QtEvent,
690 Callback
839 class FARSA_UTIL_TEMPLATE DataUploaderDownloader : public DataUploader<UploadedData_t>, public DataDownloader<DownloadedData_t>
860 typedef typename DataDownloader<DownloadedData>::NewDatumAvailableBehavior NewDatumAvailableBehavior;
881 DataUploaderDownloader(unsigned int uploadQueueSize, FullQueueBehavior fullQueueBehavior, NewDatumAvailableBehavior newDatumAvailableBehavior) :
903 DataUploaderDownloader(unsigned int uploadQueueSize, FullQueueBehavior fullQueueBehavior, QObject* o) :
925 DataUploaderDownloader(unsigned int uploadQueueSize, FullQueueBehavior fullQueueBehavior, NewDatumNotifiable<DownloadedData>* o) :
979 static void associate(DataUploaderDownloader<DataType1, DataType2>* first, DataUploaderDownloader<DataType2, DataType1>* second);
1048 void internalAssociate(DataUploader<DataType>* uploader, DataDownloader<DataType>* downloader);
1058 void internalAssociate(DataUploaderDownloader<DataType1, DataType2>* first, DataUploaderDownloader<DataType2, DataType1>* second);
1473 throw UploaderDownloaderAssociationNotPresentException(UploaderDownloaderAssociationNotPresentException::DownloaderNotPresent);
1544 // Putting the new datum in the queue, extracting the next element and moving the uploader iterator forward
1553 // To update the variables with available space and data in queue, we have to check if the queue was full
1554 // and then check which is the FullQueueBehavior, to undestand what has been done in createDatum()
1561 // The downloader has downloaded one datum before we could add the new one, so we have to update the counters
1566 // The queue has grown, but still there is no space left. We only have to increase numDataInQueue
1581 // Waking up the downloader, in case it was sleeping. This doesn't conflict with sendNotification() because if the
1587 // If the downloader expects a callback to be called, we have to release the lock, otherwise a deadlock
1614 if ((m_newDatumAvailableBehavior != NoNotification) && (m_newDatumAvailableBehavior != NoNotificationBlocking)) {
1616 throw InvalidNewDatumAvailableBehaviorException("when the NewDatumAvailableBehavior is \"QtEvent\" you must specify the QObject that receives the event");
1618 throw InvalidNewDatumAvailableBehaviorException("when the NewDatumAvailableBehavior is \"Callback\" you must specify the NewDatumNotifiable object whose callback is called");
1632 throw InvalidNewDatumAvailableBehaviorException("when the NewDatumAvailableBehavior is \"QtEvent\" you must specify a valid (i.e. not NULL) QObject");
1645 throw InvalidNewDatumAvailableBehaviorException("when the NewDatumAvailableBehavior is \"Callback\" you must specify a valid (i.e. not NULL) NewDatumNotifiable");
1680 throw UploaderDownloaderAssociationNotPresentException(UploaderDownloaderAssociationNotPresentException::UploaderNotPresent);
1696 throw UploaderDownloaderAssociationNotPresentException(UploaderDownloaderAssociationNotPresentException::UploaderNotPresent);
1730 // We can return the current datum. We have to put back in the queue the datum that was downloaded before and move
1773 void GlobalUploaderDownloader::associate(DataUploader<DataType>* uploader, DataDownloader<DataType>* downloader)
1779 void GlobalUploaderDownloader::associate(DataUploaderDownloader<DataType1, DataType2>* first, DataUploaderDownloader<DataType2, DataType1>* second)
1797 void GlobalUploaderDownloader::detach(DataUploaderDownloader<DataType1, DataType2>* uploaderDownloader)
1803 void GlobalUploaderDownloader::internalAssociate(DataUploader<DataType>* uploader, DataDownloader<DataType>* downloader)
1816 throw UploaderDownloaderAssociationNotUniqueException(UploaderDownloaderAssociationNotUniqueException::UploaderAlreadyAssociated);
1818 throw UploaderDownloaderAssociationNotUniqueException(UploaderDownloaderAssociationNotUniqueException::DownloaderAlreadyAssociated);
1821 // No need to check whether a datum has been created but not uploaded as both ends are not associated!
1823 // Creating the association. The old queue in the downloader is deleted by QExplicitlySharedDataPointer
1836 void GlobalUploaderDownloader::internalAssociate(DataUploaderDownloader<DataType1, DataType2>* first, DataUploaderDownloader<DataType2, DataType1>* second)
1855 throw UploaderDownloaderAssociationNotUniqueException(UploaderDownloaderAssociationNotUniqueException::UploaderAlreadyAssociated);
1857 throw UploaderDownloaderAssociationNotUniqueException(UploaderDownloaderAssociationNotUniqueException::DownloaderAlreadyAssociated);
1859 throw UploaderDownloaderAssociationNotUniqueException(UploaderDownloaderAssociationNotUniqueException::UploaderAlreadyAssociated);
1861 throw UploaderDownloaderAssociationNotUniqueException(UploaderDownloaderAssociationNotUniqueException::DownloaderAlreadyAssociated);
1864 // No need to check whether a datum has been created but not uploaded as both ends are not associated!
1866 // Creating the association. The old queue in downloaders is deleted by QExplicitlySharedDataPointer
1941 void GlobalUploaderDownloader::internalDetach(DataUploaderDownloader<DataType1, DataType2>* uploaderDownloader)
1945 // the queue and we do this without locking. This is fine because the pointer to the downloader
Definition: utilitiesexceptions.h:282
The event sent to downloader when a new datum is ready.
Definition: dataexchange.h:573
NewDatumAvailableBehavior
The possible behaviors when a new datum arrives.
Definition: dataexchange.h:683
bool uploaderPresent() const
Returns true if we are associated with an uploader.
Definition: dataexchange.h:1661
static void detach(DataUploader< DataType > *uploader)
Removes an association.
Definition: dataexchange.h:1785
const DataType * operator->() const
Overloading of the -> operator to access the datum (const version)
Definition: dataexchange.h:499
DataUploaderDownloader(unsigned int uploadQueueSize, FullQueueBehavior fullQueueBehavior, QObject *o)
Constructor.
Definition: dataexchange.h:903
Definition: utilitiesexceptions.h:279
bool operator==(const DataType *other) const
Comparison operator with a pointer to DataType.
Definition: dataexchange.h:520
The exception thrown when using invalid combinations of NewDatumAvailableBehavior and objects for not...
Definition: utilitiesexceptions.h:508
FullQueueBehavior getFullQueueBehavior() const
Returns the FullQueueBehavior.
Definition: dataexchange.h:299
DataUploader< DataType > * uploader
The uploader associated with this queue.
Definition: dataexchange.h:1396
unsigned int availableSpace
The number of data the queue can hold before becoming full.
Definition: dataexchange.h:1340
The parent of the class containing the queue and all related elements.
Definition: dataexchange.h:1210
DataDownloader< DataType > * downloader
The downloader associated with this queue.
Definition: dataexchange.h:1404
QMutex mutex
The mutex protecting from concurrent accesses to data in this object.
Definition: dataexchange.h:1228
bool datumCreatedNotUploaded() const
Returns true if a new datum has been created but not uploaded (i.e. createDatum() has been called but...
Definition: dataexchange.h:1599
unsigned int getNumAvailableData() const
Returns the number of available data.
Definition: dataexchange.h:1675
A class for bi-directional communication.
Definition: dataexchange.h:839
The exception thrown when the association between uploader and downloader is not 1:1.
Definition: utilitiesexceptions.h:272
bool downloaderPresent() const
Returns true if we are associated with a downloader.
Definition: dataexchange.h:1429
QLinkedList< DataType * >::iterator nextUploadIt
The iterator to the element of the queue where the \ next datum uploaded by the uploader will be put...
Definition: dataexchange.h:1382
const DataDownloader< DataType > * getDownloader() const
Returns the downloader object which triggered this event (const version)
Definition: dataexchange.h:611
DataType * createDatum()
Returns a pointer to an object that will be the next datum to upload.
Definition: dataexchange.h:1457
QueueHolder(unsigned int queueSize, DataUploader< DataType > *u)
Constructor.
Definition: dataexchange.h:1266
unsigned int getNumDataInQueue() const
Returns the number of data currently in the queue.
Definition: dataexchange.h:1449
void checkAssociationBeforeUpload(bool v)
Sets whether an exception has to be thrown if the user tries to upload a datum but no association is ...
Definition: dataexchange.h:368
DataUploader(unsigned int queueSize, FullQueueBehavior b)
Constructor.
Definition: dataexchange.h:1409
DataUploader< UploadedData >::FullQueueBehavior FullQueueBehavior
A typedef to easily access the FullQueueBehavior type.
Definition: dataexchange.h:855
DataUploaderDownloader(unsigned int uploadQueueSize, FullQueueBehavior fullQueueBehavior, NewDatumNotifiable< DownloadedData > *o)
Constructor.
Definition: dataexchange.h:925
The interface for classes that want to be notified when a new datum is available. ...
Definition: dataexchange.h:638
Definition: utilitiesexceptions.h:400
DataDownloader< DownloadedData >::NewDatumAvailableBehavior NewDatumAvailableBehavior
A typedef to easily access the NewDatumAvailableBehavior type.
Definition: dataexchange.h:860
DataType * operator->()
Overloading of the -> operator to access the datum.
Definition: dataexchange.h:509
DataType * currentDownloaderDatum
The datum the downloader is currently using.
Definition: dataexchange.h:1376
Definition: dataexchange.h:688
The exception thrown when trying to create a datum or download without an uploader/downloader associa...
Definition: utilitiesexceptions.h:389
QWaitCondition waitCondition
The wait condition used to wake the blocked downloader when a new datum arrives or the uploader when ...
Definition: dataexchange.h:1235
const DataType * downloadDatum()
Returns a pointer to the next datum.
Definition: dataexchange.h:1689
UploadedData_t UploadedData
The type of data being uploaded by this class.
Definition: dataexchange.h:845
QLinkedList< DataType * >::iterator nextDownloadIt
The position in the queue that will be read next by the downloader.
Definition: dataexchange.h:1388
bool queueFullLastDatumCreation
Whether the queue was full the last time a datum was created.
Definition: dataexchange.h:1351
DownloadedData_t DownloadedData
The type of data being downloaded by this class.
Definition: dataexchange.h:850
DataUploaderDownloader(unsigned int uploadQueueSize, FullQueueBehavior fullQueueBehavior, NewDatumAvailableBehavior newDatumAvailableBehavior)
Constructor.
Definition: dataexchange.h:881
The class used to implement RAII for data uploading.
Definition: dataexchange.h:228
NewDatumAvailableBehavior getNewDatumAvailableBehavior() const
Returns the NewDatumAvailableBehavior.
Definition: dataexchange.h:731
DataDownloader< DataType > * getDownloader()
Returns the downloader object which triggered this event.
Definition: dataexchange.h:621
bool associationBeforeUploadChecked() const
Returns true if an exception is thrown if the user tries to upload a datum but no association is pres...
Definition: dataexchange.h:381
bool datumCreatedNotUploaded
True if a new datum has been created but not uploaded (i.e. createDatum() in the uploader has been ca...
Definition: dataexchange.h:1358
unsigned int numDataInQueue
The number of data currently in the queue.
Definition: dataexchange.h:1345
farsa::DatumToUpload< DataType > DatumToUpload
A typedef to use the correct DatumToUpload.
Definition: dataexchange.h:252
Definition: utilitiesexceptions.h:396
static void associate(DataUploader< DataType > *uploader, DataDownloader< DataType > *downloader)
The function to associate an uploader and a downloader.
Definition: dataexchange.h:1773
The class containing the queue and all related elements.
Definition: dataexchange.h:225
unsigned int getAvailableSpace() const
Returns the number of data the queue can hold before becoming full.
Definition: dataexchange.h:1437
Definition: dataexchange.h:232
The class to create or remove associations and to wake all sleeping uploaders and downloaders...
Definition: dataexchange.h:950