Huggle  build:^490^dce1e5c
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
query.hpp
1 //This program is free software: you can redistribute it and/or modify
2 //it under the terms of the GNU General Public License as published by
3 //the Free Software Foundation, either version 3 of the License, or
4 //(at your option) any later version.
5 
6 //This program is distributed in the hope that it will be useful,
7 //but WITHOUT ANY WARRANTY; without even the implied warranty of
8 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 //GNU General Public License for more details.
10 
11 #ifndef QUERY_H
12 #define QUERY_H
13 
14 #include <QDateTime>
15 #include <QThread>
16 #include <QObject>
17 #include <QString>
18 #include <QMutex>
19 #include <QStringList>
20 #include <QNetworkAccessManager>
21 #include "queryresult.hpp"
22 #include "collectable.hpp"
23 #include "exception.hpp"
24 #include "gc.hpp"
25 
26 namespace Huggle
27 {
28  class Query;
29  typedef void* (*Callback) (Query*);
30 
31  //! Status of a query
32  enum _Status
33  {
34  StatusNull,
35  StatusDone,
36  StatusProcessing,
37  StatusInError
38  };
39 
40  /*!
41  * \brief The QueryType enum
42  */
43  enum QueryType
44  {
45  //! Edit
47  //! Default
49  //! Whitelist
51  //! Api
53  //! Revert
55  };
56 
57  //! Query base class for all http queries executed by huggle
58 
59  //! Every request to website is processed as a query, this is a base object that all
60  //! other queries are derived from. The query system is using own GC see a QueryGC
61  //! That means every query is either unmanaged or managed. In case it is managed,
62  //! the GC will care about it being removed from operating memory and you must not
63  //! call a delete on it, otherwise program will crash.
64  class Query : public QObject, public Collectable
65  {
66  public:
67  //! Result of query, see documentation of QueryResult for more
69  //! Current status of a query
71  //! Custom status
72 
73  //! This can be used to override the current string representation of status with
74  //! some custom string, the system will still process the primary status but
75  //! user will see this custom string in a process list
76  QString CustomStatus;
77  //! Type of a query
78 
79  //! This is very useful when you are casting a query to different type
81  //! Callback
82 
83  //! If this is not a NULL this function will be called by query
84  //! once it's finished, a consumer called "delegate" will be created and you
85  //! will have to either replace it or remove in your function
86  //! otherwise you create a leak in huggle
87  Callback callback;
88  //! This is a pointer to object returned by your callback function
90  static QNetworkAccessManager NetworkManager;
91  bool RetryOnTimeoutFailure;
92  QDateTime StartTime;
93  int Timeout;
94  //! Query doesn't have internal data displayed in debug log, this is usefull
95  //! when you are working with passwords in parameters
97  //! Dependency for query
98 
99  //! If you put anything in here, it either must be NULL or query
100  //! that is processed. The query will not be flagged as processed
101  //! until the dependency is processed as well, for most types
102  //! of queries they will not even start before that
104  //! Creates empty query
105  Query();
106  //! Destructor for query
107  virtual ~Query();
108  //! Returns true in case that query is processed
109  virtual bool Processed();
110  //! Execute query
111 
112  //! This is a main() of every query, your implementation goes here
113  virtual void Process() {}
114  //! Terminates a query
115 
116  //! In case it's not running nothing happens, in case query is currently running
117  //! it should be immediately stopped and error result should be generated
118 
119  //! This is only a virtual interface implemented in Query which does nothing by default
120  //! it is necessary for every query to implement this for it to work properly
121  virtual void Kill() {}
122  //! Convert a type of this query to a string
123  virtual QString QueryTypeToString();
124  //! Return a target of a query
125 
126  //! Target is either explicitly defined abstract identifier that is used for statistical
127  //! purposes, or it is provided by query itself, based on a type of that query
128  //! typical example would be a page that is affected by ApiQuery
129  virtual QString QueryTargetToString();
130  virtual QString QueryStatusToString();
131  //! If you inherit query you should allways call this from a signal that
132  //! you receive when the query finish
133  void ProcessCallback();
134  //! Every query has own unique ID which can be used to work with them
135  //! this function returns that
136  unsigned int QueryID();
137 
138  private:
139  //! Every query has own unique ID which can be used to work with them
140  unsigned int ID;
141  //! This is a last ID used by a constructor of a query
142  static unsigned int LastID;
143  //! When a query fail and retry this is changed to true so that it doesn't endlessly restart
144  bool Repeated;
145  };
146 }
147 
148 #endif // QUERY_H
Base for all items that are supposed to be collected by garbage collector.
Definition: collectable.hpp:34
bool HiddenQuery
Definition: query.hpp:96
bool Repeated
When a query fail and retry this is changed to true so that it doesn&#39;t endlessly restart.
Definition: query.hpp:144
virtual void Process()
Execute query.
Definition: query.hpp:113
virtual QString QueryTargetToString()
Return a target of a query.
Definition: query.cpp:93
virtual bool Processed()
Returns true in case that query is processed.
Definition: query.cpp:45
Result of query.
Definition: queryresult.hpp:19
_Status
Status of a query.
Definition: query.hpp:32
void ProcessCallback()
Definition: query.cpp:126
Default.
Definition: query.hpp:48
static unsigned int LastID
This is a last ID used by a constructor of a query.
Definition: query.hpp:142
virtual QString QueryTypeToString()
Convert a type of this query to a string.
Definition: query.cpp:75
Callback callback
Callback.
Definition: query.hpp:87
virtual void Kill()
Terminates a query.
Definition: query.hpp:121
QueryType Type
Type of a query.
Definition: query.hpp:80
QueryType
The QueryType enum.
Definition: query.hpp:43
virtual ~Query()
Destructor for query.
Definition: query.cpp:35
Query()
Creates empty query.
Definition: query.cpp:18
Whitelist.
Definition: query.hpp:50
Query * Dependency
Dependency for query.
Definition: query.hpp:103
enum _Status Status
Current status of a query.
Definition: query.hpp:70
unsigned int QueryID()
Definition: query.cpp:135
QString CustomStatus
Custom status.
Definition: query.hpp:76
unsigned int ID
Every query has own unique ID which can be used to work with them.
Definition: query.hpp:140
void * CallbackResult
This is a pointer to object returned by your callback function.
Definition: query.hpp:89
Query base class for all http queries executed by huggle.
Definition: query.hpp:64
QueryResult * Result
Result of query, see documentation of QueryResult for more.
Definition: query.hpp:68