#include "../../Global/Initialisierung.h" #include #include "../../Global/Variablen.h" // Inhalt der UpdateGUI klasse aus UpdateGUI.h // Konstruktor Update::Update( Schrift *zSchrift, FBalken *fb, int dg, std::function< void(bool) > after ) : Thread() { p = 0; this->fb = fb; updateAbbrechen = 0; this->dg = dg; this->after = after; } // Destruktor Update::~Update() { if( isRunning() ) { updateAbbrechen = 1; warteAufThread( 5000 ); if( isRunning() ) { ende(); after( 0 ); } } if( fb ) fb->release(); if( p ) p->release(); } // nicht constant void Update::setPatcher( Patcher *p ) { this->p = p; } void Update::abbrechen() { updateAbbrechen = 1; } void Update::herunterladen() { if( isRunning() || !p ) return; start(); getThis(); } void Update::thread() { int dgId = dg; Text err; if( !p->update( dgId, &updateAbbrechen, (FBalken*)fb->getThis(), 0, &err ) ) { updateAbbrechen = 1; if( nachLogin && nachLogin->zNachrichtenListe() ) nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), err.getThis(), new Text( "Ok" ) ); } run = 0; } void Update::threadEnd() { __super::threadEnd(); after( !updateAbbrechen ); release(); } // constant int Update::getDateiGruppe() const { return dg; } // inhalt der UpdateHandler Klasse aus UpdateGUI.h // Konstruktor UpdateHandler::UpdateHandler() { patcher = new Patcher(); updates = new RCArray< Update >(); ref = 1; } // Destruktor UpdateHandler::~UpdateHandler() { updates->release(); patcher->release(); } // privat void UpdateHandler::lock() { cs.lock(); } void UpdateHandler::unlock() { cs.unlock(); } // nicht constant bool UpdateHandler::add( Update *update ) { lock(); if( hat( update->getDateiGruppe() ) ) { update->release(); unlock(); return 0; } int anz = updates->getEintragAnzahl(); update->setPatcher( patcher->getThis() ); updates->add( update ); unlock(); return 1; } void UpdateHandler::remove( int dg ) { lock(); int anz = updates->getEintragAnzahl(); for( int i = 0; i < anz; i++ ) { if( updates->z( i )->getDateiGruppe() == dg ) { updates->remove( i ); break; } } unlock(); } bool UpdateHandler::hat( int dg ) { lock(); bool ret = 0; int anz = updates->getEintragAnzahl(); for( int i = 0; i < anz; i++ ) { if( updates->z( i )->getDateiGruppe() == dg ) { ret = 1; break; } } unlock(); return ret; } // Reference Counting UpdateHandler *UpdateHandler::getThis() { ref++; return this; } UpdateHandler *UpdateHandler::release() { ref--; if( !ref ) delete this; return 0; }