123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- #include "../../Global/Initialisierung.h"
- #include <MausEreignis.h>
- #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;
- }
|