ATLAS Offline Software
Classes | Signals | Public Member Functions | Private Slots | Private Attributes | List of all members
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;
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 }

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 }

◆ 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 {
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 {
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 }

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:
VP1HttpGetFile::m_d
Imp * m_d
Definition: VP1HttpGetFile.h:60
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
VP1HttpGetFile::downloadThreadTerminated
void downloadThreadTerminated()
Definition: VP1HttpGetFile.cxx:116
VP1HttpGetFile::Imp::activeDownloadThreads
QList< VP1HttpGetFile_DownloadThread * > activeDownloadThreads
Definition: VP1HttpGetFile.cxx:28
VP1HttpGetFile_DownloadThread::data
QString data() const
Definition: VP1HttpGetFile_Private.h:49
VP1HttpGetFile::downloadThreadFinished
void downloadThreadFinished()
Definition: VP1HttpGetFile.cxx:94
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
VP1HttpGetFile::downloadSuccessful
void downloadSuccessful(const QString &urltofile, const QString &localtargetfile, const QString &data)
VP1HttpGetFile_DownloadThread::errors
bool errors() const
Definition: VP1HttpGetFile_Private.h:43
VP1HttpGetFile_DownloadThread::errorString
QString errorString() const
Definition: VP1HttpGetFile_Private.h:44
beamspotman.n
n
Definition: beamspotman.py:731
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VP1HttpGetFile_DownloadThread::localtargetfile
QString localtargetfile() const
Definition: VP1HttpGetFile_Private.h:47
mergePhysValFiles.errors
list errors
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:43
VP1HttpGetFile_DownloadThread::urltofile
QString urltofile() const
Definition: VP1HttpGetFile_Private.h:46
VP1HttpGetFile::downloadFailed
void downloadFailed(const QString &error, const QString &urltofile, const QString &localtargetfile, const QString &data)
VP1HttpGetFile::Imp::dead
bool dead
Definition: VP1HttpGetFile.cxx:27
VP1HttpGetFile_DownloadThread
Definition: VP1HttpGetFile_Private.h:29
VP1HttpGetFile::isDownloadingTo
bool isDownloadingTo(const QString &localtargetfile) const
Definition: VP1HttpGetFile.cxx:148
VP1HttpGetFile::Imp::maxDownloads
unsigned maxDownloads
Definition: VP1HttpGetFile.cxx:26