示例#1
0
int Downloader::download(bool wait)
{
	if (!isStarted)
	{
		isStarted = true;
		downloadError = 0;
		
		if (!dlFile->open(QIODevice::WriteOnly))
		{
			errorStr += "can not open file " + dest + "\n";
			return 1;
		}

		if (reply == NULL)
			reply = network->get(request);
		
		QObject::connect(reply, SIGNAL(readyRead()), this, SLOT(downloadedFileWrite()));
		QObject::connect(reply, SIGNAL(finished ()), this, SLOT(handleDownload()));
		QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError)));
		//QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(slotSslErrors(QList<QSslError>)));

		if (wait)
		{
			QEventLoop loop;
			QObject::connect(this, SIGNAL(finished(int)), &loop, SLOT(quit()));
			loop.exec();
		}
		return downloadError;
	}
示例#2
0
UpdateDialog::UpdateDialog(QWidget *parent, const QString& releaseNotes, const QString& latestVersion, const QUrl& downloadURL) :
    QDialog(parent),
    _latestVersion(latestVersion),
    _downloadUrl(downloadURL)
{
    Ui::Dialog dialogUI;
    dialogUI.setupUi(this);
    
    QString updateRequired = QString("You are currently running build %1, the latest build released is %2."
                                     "\n\nPlease download and install the most recent release to access the latest features and bug fixes.")
                                      .arg(Application::getInstance()->applicationVersion(), latestVersion);
    
    setAttribute(Qt::WA_DeleteOnClose);
    
    QPushButton* downloadButton = findChild<QPushButton*>("downloadButton");
    QPushButton* skipButton = findChild<QPushButton*>("skipButton");
    QPushButton* closeButton = findChild<QPushButton*>("closeButton");
    QLabel* updateContent = findChild<QLabel*>("updateContent");
    
    updateContent->setText(updateRequired);
    
    connect(downloadButton, SIGNAL(released()), this, SLOT(handleDownload()));
    connect(skipButton, SIGNAL(released()), this, SLOT(handleSkip()));
    connect(closeButton, SIGNAL(released()), this, SLOT(close()));
    
    QMetaObject::invokeMethod(this, "show", Qt::QueuedConnection);
}
/*
 * main(): This function is the entry point for the server program of Share Your Playlist application.
 * This function creates the upload and download sockets and waits for client connections.
 * We have implemented all the 3 methods used in concurrency in servers namely:
 * 1. Multi-process approach using fork() for handling upload and download functionalities
 * 2. Non-blocking I/O using select() for monitoring two ports on server
 * 3. Multi-threaded approach for data redundancy between servers
 */
int main(int argc, char **argv) {
	struct sockaddr_in sockserv;
	unsigned int alen;
	int upload_sock, download_sock, i, slave_sock, fds[2], *fd = NULL;
	struct sockaddr *addr;
	socklen_t *addrlen;

	//binds sockets for upload and download functionality
	upload_sock = passiveTCP(UPLOAD_PORT);
	download_sock = passiveTCP(DOWNLOAD_PORT);

	printf("Upload sock : %d\n", upload_sock);
	printf("Download sock : %d\n", download_sock);

	fds[0] = upload_sock;
	fds[1] = download_sock;

	while (1) {
		//calls function to identify which port client connected to
		slave_sock = network_accept_any(fds, 2, &fd);

		//Initializing thread attributes for prstats thread
		(void) pthread_attr_init(&ta);
		(void) pthread_attr_setdetachstate(&ta, PTHREAD_CREATE_DETACHED);
		(void) pthread_mutex_init(&stats.st_mutex, 0);

		/*if(pthread_create(&th, &ta, (void * (*)(void *))prstats, 0) < 0)
		 fatal("prstats thread failed");*/

		//Based on socket that obtained the connection, we use multi-process approach using fork() to provide concurrency
		//Based on upload/download, the respective functions are called in the child processes.
		if (*fd == upload_sock) {
			switch (fork()) {
			case 0:
				close(*fd);
				exit(handleUpload(slave_sock));
			default:
				close(slave_sock);
				break;
			}
		}
		if (*fd == download_sock) {
			switch (fork()) {
			case 0:
				close(*fd);
				exit(handleDownload(slave_sock));
			default:
				close(slave_sock);
				break;
			}
		}
	}
}
示例#4
0
void DlgFmncPrjImpelb::handleRequest(
			DbsFmnc* dbsfmnc
			, ReqFmnc* req
		) {
	if (req->ixVBasetype == ReqFmnc::VecVBasetype::CMD) {
		reqCmd = req;

		if (req->cmd.compare("cmdset") == 0) {

		} else {
			cout << "\tinvalid command!" << endl;
		};

		if (!req->retain) reqCmd = NULL;

	} else if (req->ixVBasetype == ReqFmnc::VecVBasetype::REGULAR) {
		if (req->dpchapp->ixFmncVDpch == VecFmncVDpch::DPCHAPPFMNCINIT) {
			handleDpchAppFmncInit(dbsfmnc, (DpchAppFmncInit*) (req->dpchapp), &(req->dpcheng));

		} else if (req->dpchapp->ixFmncVDpch == VecFmncVDpch::DPCHAPPDLGFMNCPRJIMPELBDATA) {
			DpchAppData* dpchappdata = (DpchAppData*) (req->dpchapp);

			if (dpchappdata->has(DpchAppData::CONTIAC)) {
				handleDpchAppDataContiac(dbsfmnc, &(dpchappdata->contiac), &(req->dpcheng));
			};

		} else if (req->dpchapp->ixFmncVDpch == VecFmncVDpch::DPCHAPPDLGFMNCPRJIMPELBDO) {
			DpchAppDo* dpchappdo = (DpchAppDo*) (req->dpchapp);

			if (dpchappdo->ixVDo != 0) {
				if (dpchappdo->ixVDo == VecVDo::BUTDNECLICK) {
					handleDpchAppDoButDneClick(dbsfmnc, &(req->dpcheng));
				};

			} else if (dpchappdo->ixVDoImp != 0) {
				if (dpchappdo->ixVDoImp == VecVDoImp::BUTRUNCLICK) {
					handleDpchAppDoImpButRunClick(dbsfmnc, &(req->dpcheng));
				} else if (dpchappdo->ixVDoImp == VecVDoImp::BUTSTOCLICK) {
					handleDpchAppDoImpButStoClick(dbsfmnc, &(req->dpcheng));
				};

			};

		} else if (req->dpchapp->ixFmncVDpch == VecFmncVDpch::DPCHAPPFMNCALERT) {
			handleDpchAppFmncAlert(dbsfmnc, (DpchAppFmncAlert*) (req->dpchapp), &(req->dpcheng));

		};
// IP handleRequest.upload --- BEGIN

	} else if (req->ixVBasetype == ReqFmnc::VecVBasetype::UPLOAD) {
		handleUpload(dbsfmnc, req->filename);
// IP handleRequest.upload --- END
// IP handleRequest.download --- BEGIN

	} else if (req->ixVBasetype == ReqFmnc::VecVBasetype::DOWNLOAD) {
		req->filename = handleDownload(dbsfmnc);
// IP handleRequest.download --- END
// IP handleRequest.timer --- BEGIN

	} else if (req->ixVBasetype == ReqFmnc::VecVBasetype::TIMER) {
		handleTimer(dbsfmnc, req->sref);
// IP handleRequest.timer --- END
	};
};