| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <?php
- /* $Id: FluxdServiceMod.Qmgr.php 2943 2007-04-23 18:43:05Z b4rt $ */
- /*******************************************************************************
- LICENSE
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License (GPL)
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- To read the license please visit http://www.gnu.org/copyleft/gpl.html
- *******************************************************************************/
- // class for the Fluxd-Service-module Qmgr
- class FluxdQmgr extends FluxdServiceMod
- {
- // =========================================================================
- // public static methods
- // =========================================================================
- /**
- * accessor for singleton
- *
- * @return FluxdQmgr
- */
- function getInstance() {
- global $instanceFluxdQmgr;
- // initialize if needed
- if (!isset($instanceFluxdQmgr))
- FluxdQmgr::initialize();
- return $instanceFluxdQmgr;
- }
- /**
- * initialize FluxdQmgr.
- */
- function initialize() {
- global $instanceFluxdQmgr;
- // create instance
- if (!isset($instanceFluxdQmgr))
- $instanceFluxdQmgr = new FluxdQmgr();
- }
- /**
- * getState
- *
- * @return state
- */
- function getState() {
- global $instanceFluxdQmgr;
- return (isset($instanceFluxdQmgr))
- ? $instanceFluxdQmgr->state
- : FLUXDMOD_STATE_NULL;
- }
- /**
- * getMessages
- *
- * @return array
- */
- function getMessages() {
- global $instanceFluxdQmgr;
- return (isset($instanceFluxdQmgr))
- ? $instanceFluxdQmgr->messages
- : array();
- }
- /**
- * getModState
- *
- * @return state
- */
- function getModState() {
- global $instanceFluxdQmgr;
- return (isset($instanceFluxdQmgr))
- ? $instanceFluxdQmgr->modstate
- : FLUXDMOD_STATE_NULL;
- }
- /**
- * isRunning
- *
- * @return boolean
- */
- function isRunning() {
- global $instanceFluxdQmgr;
- return (isset($instanceFluxdQmgr))
- ? ($instanceFluxdQmgr->modstate == FLUXDMOD_STATE_RUNNING)
- : false;
- }
- /**
- * getQueuedTransfers
- *
- * @param $user
- * @return string
- */
- function getQueuedTransfers($user = "") {
- global $instanceFluxdQmgr;
- return (isset($instanceFluxdQmgr))
- ? $instanceFluxdQmgr->instance_getQueuedTransfers($user)
- : "";
- }
- /**
- * countQueuedTransfers
- *
- * @param $user
- * @return int
- */
- function countQueuedTransfers($user = "") {
- global $instanceFluxdQmgr;
- return (isset($instanceFluxdQmgr))
- ? $instanceFluxdQmgr->instance_countQueuedTransfers($user)
- : 0;
- }
- /**
- * enqueue
- *
- * @param $transfer
- * @param $user
- */
- function enqueueTransfer($transfer, $user) {
- global $instanceFluxdQmgr;
- if (isset($instanceFluxdQmgr))
- $instanceFluxdQmgr->instance_enqueueTransfer($transfer, $user);
- }
- /**
- * dequeue
- *
- * @param $transfer
- * @param $user
- */
- function dequeueTransfer($transfer, $user) {
- global $instanceFluxdQmgr;
- if (isset($instanceFluxdQmgr))
- $instanceFluxdQmgr->instance_dequeueTransfer($transfer, $user);
- }
- // =========================================================================
- // ctor
- // =========================================================================
- /**
- * ctor
- */
- function FluxdQmgr() {
- // name
- $this->moduleName = "Qmgr";
- // initialize
- $this->instance_initialize();
- }
- // =========================================================================
- // public methods
- // =========================================================================
- /**
- * instance_getQueuedTransfers
- *
- * @param $user
- * @return string
- */
- function instance_getQueuedTransfers($user = "") {
- return ($this->modstate == FLUXDMOD_STATE_RUNNING)
- ? Fluxd::sendServiceCommand($this->moduleName, 'list-queue', 1)
- : "";
- }
- /**
- * instance_countQueuedTransfers
- *
- * @param $user
- * @return int
- */
- function instance_countQueuedTransfers($user = "") {
- return ($this->modstate == FLUXDMOD_STATE_RUNNING)
- ? Fluxd::sendServiceCommand($this->moduleName, 'count-queue', 1)
- : 0;
- }
- /**
- * instance_enqueue
- *
- * @param $transfer
- * @param $user
- */
- function instance_enqueueTransfer($transfer, $user) {
- if ($this->modstate == FLUXDMOD_STATE_RUNNING) {
- // send command
- Fluxd::sendServiceCommand($this->moduleName, 'enqueue;'.$transfer.';'.$user, 0);
- // just 2 sec... dont stress fluxd
- sleep(2);
- }
- }
- /**
- * instance_dequeue
- *
- * @param $transfer
- * @param $user
- */
- function instance_dequeueTransfer($transfer, $user) {
- global $cfg;
- if ($this->modstate == FLUXDMOD_STATE_RUNNING) {
- if (isTransferRunning($transfer)) {
- // transfer has been started...log
- AuditAction($cfg["constants"]["unqueued_transfer"], $transfer . "has been already started.");
- } else {
- // send command
- Fluxd::sendServiceCommand($this->moduleName, 'dequeue;'.$transfer.';'.$user, 0);
- // flag the transfer as stopped (in db)
- stopTransferSettings($transfer);
- // update the stat file.
- $this->_updateStatFile($transfer);
- // log
- AuditAction($cfg["constants"]["unqueued_transfer"], $transfer);
- // just 2 sec... dont stress fluxd
- sleep(2);
- }
- }
- }
- // =========================================================================
- // private methods
- // =========================================================================
- /**
- * _updateStatFile
- *
- * @param $transfer
- */
- function _updateStatFile($transfer) {
- global $transfers;
- $modded = 0;
- // create sf object
- $sf = new StatFile($transfer, getOwner($transfer));
- if ($sf->percent_done > 0 && $sf->percent_done < 100) {
- // has downloaded something at some point, mark it is incomplete
- $sf->running = "0";
- $sf->time_left = "Transfer Stopped";
- $modded++;
- }
- if ($modded == 0) {
- if ($sf->percent_done == 0 || $sf->percent_done == "") {
- // We are going to write a '2' on the front of the stat file so that it will be set back to New Status
- $sf->running = "2";
- $sf->time_left = "";
- $modded++;
- }
- }
- if ($modded == 0) {
- if ($sf->percent_done == 100) {
- // transfer was done and is now being stopped
- $sf->running = "0";
- $sf->time_left = "Download Succeeded!";
- $modded++;
- }
- }
- if ($modded == 0) {
- // hmmm this stat-file is quite strange... just rewrite it stopped.
- $sf->running = "0";
- $sf->time_left = "Transfer Stopped";
- }
- // Write out the new Stat File
- $sf->write();
- // set transfers-cache
- cacheTransfersSet();
- }
- }
- ?>
|