ATLAS Offline Software
Loading...
Searching...
No Matches
VP1HttpGetFile Class Reference

#include <VP1HttpGetFile.h>

Inheritance diagram for VP1HttpGetFile:
Collaboration diagram for VP1HttpGetFile:

Classes

class  Imp

Signals

void downloadSuccessful (const QString &urltofile, const QString &localtargetfile, const QString &data)
void downloadFailed (const QString &error, const QString &urltofile, const QString &localtargetfile, const QString &data)

Public Member Functions

 VP1HttpGetFile (QObject *parent=0)
virtual ~VP1HttpGetFile ()
void setMaxNumberOfPendingDownloads (unsigned)
unsigned maxNumberOfPendingDownloads () const
unsigned numberOfPendingDownloads () const
bool isDownloading (const QString &urltofile) const
bool isDownloadingTo (const QString &localtargetfile) const
QString startDownload (const QString &urltofile, const QString &localtargetfile, const QString &md5sum="", const QString &data="")

Private Slots

void downloadThreadFinished ()
void downloadThreadTerminated ()

Private Attributes

Impm_d

Detailed Description

Definition at line 25 of file VP1HttpGetFile.h.

Constructor & Destructor Documentation

◆ VP1HttpGetFile()

VP1HttpGetFile::VP1HttpGetFile ( QObject * parent = 0)

Definition at line 32 of file VP1HttpGetFile.cxx.

33 : QObject(parent), m_d(new Imp)
34{
35}

◆ ~VP1HttpGetFile()

VP1HttpGetFile::~VP1HttpGetFile ( )
virtual

Definition at line 38 of file VP1HttpGetFile.cxx.

39{
40 m_d->dead = true;
41 for( VP1HttpGetFile_DownloadThread * thread : m_d->activeDownloadThreads) {
42 thread->blockSignals(true);
43 QString urltofile = thread->urltofile();
44 QString localtargetfile = thread->localtargetfile();
45 QString data = thread->data();
46 emit downloadFailed( "VP1HttpGetFile object deleted before download finished", urltofile, localtargetfile, data );
47 thread->terminate();
48 thread->wait();
49 thread->deleteLater();
50 }
51 delete m_d;
52}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
const QString & localtargetfile() const
void downloadFailed(const QString &error, const QString &urltofile, const QString &localtargetfile, const QString &data)

Member Function Documentation

◆ downloadFailed

void VP1HttpGetFile::downloadFailed ( const QString & error,
const QString & urltofile,
const QString & localtargetfile,
const QString & data )
signal

◆ downloadSuccessful

void VP1HttpGetFile::downloadSuccessful ( const QString & urltofile,
const QString & localtargetfile,
const QString & data )
signal

◆ downloadThreadFinished

void VP1HttpGetFile::downloadThreadFinished ( )
privateslot

Definition at line 94 of file VP1HttpGetFile.cxx.

95{
96 if (m_d->dead)
97 return;
98 VP1HttpGetFile_DownloadThread * thread = dynamic_cast<VP1HttpGetFile_DownloadThread *>(sender());
99 if (!thread)
100 return;
101 m_d->activeDownloadThreads.removeAll(thread);
102 const QString urltofile = thread->urltofile();
103 const QString localtargetfile = thread->localtargetfile();
104 const QString data = thread->data();
105 const bool errors = thread->errors();
106 const QString errorString = thread->errorString();
107 thread->wait();
108 thread->deleteLater();
109 if (errors)
110 emit downloadFailed( errorString, urltofile, localtargetfile, data );
111 else
112 emit downloadSuccessful( urltofile, localtargetfile, data );
113}
void downloadSuccessful(const QString &urltofile, const QString &localtargetfile, const QString &data)

◆ downloadThreadTerminated

void VP1HttpGetFile::downloadThreadTerminated ( )
privateslot

Definition at line 116 of file VP1HttpGetFile.cxx.

117{
118 if (m_d->dead)
119 return;
120 VP1HttpGetFile_DownloadThread * thread = dynamic_cast<VP1HttpGetFile_DownloadThread *>(sender());
121 if (!thread)
122 return;
123 m_d->activeDownloadThreads.removeAll(thread);
124 const QString urltofile = thread->urltofile();
125 const QString localtargetfile = thread->localtargetfile();
126 const QString data = thread->data();
127 thread->wait();
128 thread->deleteLater();
129 emit downloadFailed( "Download thread terminated", urltofile, localtargetfile, data );
130
131 //NB: As always when threads are terminated, we might get memory
132 //leaks, but it usually only happens if the VP1HttpGetFile instance
133 //is deleted prematurely (e.g. at program shutdown).
134}

◆ isDownloading()

bool VP1HttpGetFile::isDownloading ( const QString & urltofile) const

Definition at line 137 of file VP1HttpGetFile.cxx.

138{
139 for( VP1HttpGetFile_DownloadThread * thread : m_d->activeDownloadThreads)
140 if (urltofile==thread->urltofile()) {
141 QTimer::singleShot(0, thread, SLOT(checkForStall()));
142 return true;
143 }
144 return false;
145}

◆ isDownloadingTo()

bool VP1HttpGetFile::isDownloadingTo ( const QString & localtargetfile) const

Definition at line 148 of file VP1HttpGetFile.cxx.

149{
150 for( VP1HttpGetFile_DownloadThread * thread : m_d->activeDownloadThreads)
151 if (localtargetfile==thread->localtargetfile()) {
152 QTimer::singleShot(0, thread, SLOT(checkForStall()));
153 return true;
154 }
155 return false;
156}

◆ maxNumberOfPendingDownloads()

unsigned VP1HttpGetFile::maxNumberOfPendingDownloads ( ) const

Definition at line 61 of file VP1HttpGetFile.cxx.

62{
63 return m_d->maxDownloads;
64}

◆ numberOfPendingDownloads()

unsigned VP1HttpGetFile::numberOfPendingDownloads ( ) const

Definition at line 67 of file VP1HttpGetFile.cxx.

68{
69 return m_d->activeDownloadThreads.size();
70}

◆ setMaxNumberOfPendingDownloads()

void VP1HttpGetFile::setMaxNumberOfPendingDownloads ( unsigned n)

Definition at line 55 of file VP1HttpGetFile.cxx.

56{
57 m_d->maxDownloads = n;
58}

◆ startDownload()

QString VP1HttpGetFile::startDownload ( const QString & urltofile,
const QString & localtargetfile,
const QString & md5sum = "",
const QString & data = "" )

Definition at line 73 of file VP1HttpGetFile.cxx.

77{
78 if (m_d->maxDownloads>0 && unsigned(m_d->activeDownloadThreads.count()) >= m_d->maxDownloads)
79 return "Too many simultaneous downloads requested";
80
81 if (isDownloadingTo(localtargetfile))
82 return "Already downloading file to location: "+localtargetfile;
83
84 VP1HttpGetFile_DownloadThread * thread = new VP1HttpGetFile_DownloadThread( urltofile, localtargetfile, md5sum, data);
85 connect(thread,SIGNAL(finished()),this,SLOT(downloadThreadFinished()));
86 connect(thread,SIGNAL(terminated()),this,SLOT(downloadThreadTerminated()));
87 m_d->activeDownloadThreads << thread;
88 thread->start();
89
90 return "";//Download started succesfully.
91}
void downloadThreadTerminated()
void downloadThreadFinished()
bool isDownloadingTo(const QString &localtargetfile) const

Member Data Documentation

◆ m_d

Imp* VP1HttpGetFile::m_d
private

Definition at line 61 of file VP1HttpGetFile.h.


The documentation for this class was generated from the following files: