~marcobiscaro2112/unity/custom-bg

« back to all changes in this revision

Viewing changes to UnityCore/GLibSource.h

  • Committer: Marco Biscaro
  • Date: 2012-07-12 12:05:07 UTC
  • mfrom: (2353.2.144 unity)
  • Revision ID: marcobiscaro2112@gmail.com-20120712120507-7u9sb43bqon88ifl
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
public:
56
56
  typedef std::shared_ptr<Source> Ptr;
57
57
  typedef std::unique_ptr<Source> UniquePtr;
58
 
  typedef sigc::slot<bool> SourceCallback;
 
58
  typedef sigc::slot<bool> Callback;
59
59
 
60
60
  /**
61
61
   * This is an enum used for convenience, you can actually cast to this
77
77
   * This Run a source using the @callback function as Source's callback.
78
78
   * The method will return false if the source is already running, true otherwise.
79
79
   */
80
 
  bool Run(SourceCallback callback);
 
80
  bool Run(Callback callback);
81
81
  bool IsRunning() const;
82
82
 
83
83
  /**
111
111
    Source* self;
112
112
  };
113
113
 
114
 
  static gboolean Callback(gpointer data);
 
114
  static gboolean SourceCallback(gpointer data);
115
115
  static void DestroyCallback(gpointer data);
116
116
 
117
117
  unsigned int source_id_;
118
118
  CallBackData* callback_data_;
119
 
  SourceCallback callback_;
 
119
  Callback callback_;
120
120
};
121
121
 
122
122
 
125
125
 * timeout that will be executed every @milliseconds milliseconds, whenever
126
126
 * there are no higher priority events pending to the default main loop.
127
127
 *
128
 
 * If the SourceCallback is defined on construction, then the Timeout is ran
129
 
 * as soon as it is created, otherwise you must manually call the Run() method
130
 
 * with the appropriate parameters.
 
128
 * If the Callback is defined on construction, then the Timeout is ran as soon
 
129
 * as it is created, otherwise you must manually call the Run() method with the
 
130
 * appropriate parameters.
131
131
 */
132
132
class Timeout : public Source
133
133
{
134
134
public:
135
135
  Timeout(unsigned int milliseconds, Priority prio = Priority::DEFAULT);
136
 
  Timeout(unsigned int milliseconds, SourceCallback cb, Priority prio = Priority::DEFAULT);
 
136
  Timeout(unsigned int milliseconds, Callback cb, Priority prio = Priority::DEFAULT);
137
137
 
138
138
private:
139
139
  void Init(unsigned int milliseconds, Priority prio);
145
145
 * a timeout that will be executed every @seconds seconds, whenever
146
146
 * there are no higher priority events pending to the default main loop.
147
147
 *
148
 
 * If the SourceCallback is defined on construction, then the Timeout is ran
149
 
 * as soon as it is created, otherwise you must manually call the Run() method
150
 
 * with the appropriate parameters.
 
148
 * If the Callback is defined on construction, then the Timeout is ran as soon
 
149
 * as it is created, otherwise you must manually call the Run() method with the
 
150
 * appropriate parameters.
151
151
 */
152
152
class TimeoutSeconds : public Source
153
153
{
154
154
public:
155
155
  TimeoutSeconds(unsigned int seconds, Priority prio = Priority::DEFAULT);
156
 
  TimeoutSeconds(unsigned int seconds, SourceCallback cb, Priority prio = Priority::DEFAULT);
 
156
  TimeoutSeconds(unsigned int seconds, Callback cb, Priority prio = Priority::DEFAULT);
157
157
 
158
158
private:
159
159
  void Init(unsigned int seconds, Priority prio);
165
165
 * that will be executed whenever there are no higher priority events pending to
166
166
 * the default main loop.
167
167
 *
168
 
 * If the SourceCallback is defined on construction, then the Idle is ran as
169
 
 * soon as it is created, otherwise you must manually call the Run() method with
170
 
 * the appropriate parameters.
 
168
 * If the Callback is defined on construction, then the Idle is ran as soon as
 
169
 * it is created, otherwise you must manually call the Run() method with the
 
170
 * appropriate parameters.
171
171
 */
172
172
class Idle : public Source
173
173
{
174
174
public:
175
175
  Idle(Priority prio = Priority::DEFAULT_IDLE);
176
 
  Idle(SourceCallback cb, Priority prio = Priority::DEFAULT_IDLE);
 
176
  Idle(Callback cb, Priority prio = Priority::DEFAULT_IDLE);
177
177
 
178
178
private:
179
179
  void Init(Priority prio);
205
205
  bool Add(Source* source, std::string const& nick = "");
206
206
  bool Add(Source::Ptr const& source, std::string const& nick = "");
207
207
 
 
208
  Source::Ptr AddTimeout(unsigned int milliseconds, std::string const& nick = "");
 
209
  Source::Ptr AddTimeout(unsigned int milliseconds, Source::Callback cb, std::string const& nick = "");
 
210
 
 
211
  Source::Ptr AddTimeoutSeconds(unsigned int seconds, std::string const& nick = "");
 
212
  Source::Ptr AddTimeoutSeconds(unsigned int seconds, Source::Callback cb, std::string const& nick = "");
 
213
 
 
214
  Source::Ptr AddIdle(std::string const& nick = "");
 
215
  Source::Ptr AddIdle(Source::Callback cb, std::string const& nick = "");
 
216
 
208
217
  bool Remove(std::string const& nick);
209
218
  bool Remove(unsigned int id);
210
219
 
225
234
 
226
235
 
227
236
/* This code is needed to make the lambda functions with a return value to work
228
 
 * with the sigc::slot. We need that here to use lambdas as SourceCallback.
 
237
 * with the sigc::slot. We need that here to use lambdas as Source::Callback.
229
238
 * This can safely removed once libsigc++ will include it.
230
239
 *
231
240
 * Thanks to Chow Loong Jin <hyperair@gmail.com> for this code, see: