libtasks Documentation  1.6
cleanup_task.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #ifndef _TASKS_CLEANUP_TASK_H_
9 #define _TASKS_CLEANUP_TASK_H_
10 
11 #include <tasks/timer_task.h>
12 #include <tasks/disposable.h>
13 #include <tasks/dispatcher.h>
14 #include <tasks/logging.h>
15 
16 namespace tasks {
17 
18 class cleanup_task : public timer_task {
19  public:
21 
22  bool handle_event(worker* worker, int) {
23  if (m_disposable->can_dispose()) {
24  tdbg("cleanup_task(" << this << "): disposing " << m_disposable << std::endl);
25  m_disposable->dispose(worker);
26  return false; // done
27  } else {
28  return true; // retry
29  }
30  }
31 
32  private:
34 };
35 
36 } // tasks
37 
38 #endif // _TASKS_CLEANUP_TASK_H_
#define tdbg(m)
Definition: logging.h:54
Base class for objects/tasks that can be deleted.
Definition: disposable.h:23
disposable * m_disposable
Definition: cleanup_task.h:33
bool handle_event(worker *worker, int)
Definition: cleanup_task.h:22
cleanup_task(disposable *d)
Definition: cleanup_task.h:20
bool can_dispose() const
Check if a task can be disposed or not.
Definition: disposable.h:33
virtual void dispose(worker *)=0
Dispose an object.