11 #include "collectable.hpp"
13 using namespace Huggle;
15 unsigned long Collectable::LastCID = 0;
16 QMutex Collectable::WideLock(QMutex::Recursive);
18 Collectable::Collectable()
21 this->CID = Collectable::LastCID;
22 Collectable::LastCID++;
26 this->QL =
new QMutex(QMutex::Recursive);
29 Collectable::~Collectable()
33 throw new Exception(
"Request to delete managed entity");
40 if (this->Consumers.count() == 0 && this->iConsumers.count() == 0)
60 if (!this->iConsumers.contains(consumer))
62 this->iConsumers.append(consumer);
71 this->iConsumers.removeAll(consumer);
79 this->Consumers.append(consumer);
80 this->Consumers.removeDuplicates();
88 this->Consumers.removeAll(consumer);
98 QString Collectable::ConsumerIdToString(
const int id)
102 case HUGGLECONSUMER_WIKIEDIT:
104 case HUGGLECONSUMER_PROVIDERIRC:
105 return "ProviderIRC";
106 case HUGGLECONSUMER_QUEUE:
108 case HUGGLECONSUMER_CORE_POSTPROCESS:
109 return "Core::Postprocess";
110 case HUGGLECONSUMER_DELETEFORM:
111 return "Delete Form";
112 case HUGGLECONSUMER_PROCESSLIST:
113 return "ProcessList";
114 case HUGGLECONSUMER_HUGGLETOOL:
116 case HUGGLECONSUMER_EDITQUERY:
118 case HUGGLECONSUMER_REVERTQUERY:
119 return "RevertQuery";
120 case HUGGLECONSUMER_MAINFORM:
122 case HUGGLECONSUMER_LOGINFORM:
125 return "Unknown consumer: " + QString::number(
id);
128 void Collectable::SetManaged()
140 if (this->iConsumers.count() > 0 || this->Consumers.count() > 0)
142 result += (
"GC: Listing all dependencies for " + QString::number(this->
CollectableID())) +
"\n";
144 while (Item < this->Consumers.count())
146 result +=(
"GC: " + QString::number(this->
CollectableID()) +
" " + this->Consumers.at(Item)) +
"\n";
150 while (Item < this->iConsumers.count())
152 result +=(
"GC: " + QString::number(this->
CollectableID()) +
" " + ConsumerIdToString( this->iConsumers.at(Item)) ) +
"\n";
157 result +=
"No consumers found: " + QString::number(this->
CollectableID());
185 return ((this->Consumers.count() > 0) || (this->iConsumers.count() > 0));
bool IsManaged()
IsManaged Managed class is deleted by GC and must not be deleted by hand.
virtual bool SafeDelete()
Use this if you are not sure if you can delete this object in this moment.
void UnregisterConsumer(const int consumer)
This function will remove a string which prevent the object from being removed.
void RegisterConsumer(const int consumer)
Registers a consumer.
QString DebugHgc()
DebugHgc.
void Unlock()
Unlock this object for deletion by other threads.
unsigned long CollectableID()
CollectableID.
Every exception raised by huggle is defined by this class.
static QMutex Lock
QMutex that is used to lock the GC::list object.
bool Managed
Internal variable that contains a cache whether object is managed.
void Lock()
Lock this object so that other threads can't change consumers or modify its properties.
static QList< Collectable * > list
List of all managed queries that qgc keeps track of.