#include "../../Global/Initialisierung.h" #include #include "../../Global/Variablen.h" // Inhalt der UpdateGUI klasse aus UpdateGUI.h // Konstruktor Update::Update( 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( 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, dynamic_cast( fb->getThis() ), 0, &err ) ) { updateAbbrechen = 1; if( nachLogin && nachLogin->zNachrichtenListe() ) nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), dynamic_cast( 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() : ReferenceCounter() { patcher = new Patcher(); updates = new RCArray< Update >(); } // 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( dynamic_cast( 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; }