blob: 3c0b81cf6a98ff0266e305a1edab57c297451d19 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_BASE_TASKPARENT_H__
12#define WEBRTC_BASE_TASKPARENT_H__
13
jbauch555604a2016-04-26 03:13:22 -070014#include <memory>
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000015#include <set>
16
17#include "webrtc/base/basictypes.h"
jbauch555604a2016-04-26 03:13:22 -070018#include "webrtc/base/constructormagic.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000019
20namespace rtc {
21
22class Task;
23class TaskRunner;
24
25class TaskParent {
26 public:
27 TaskParent(Task *derived_instance, TaskParent *parent);
28 explicit TaskParent(TaskRunner *derived_instance);
kwiberg@webrtc.org67186fe2015-03-09 22:21:53 +000029 virtual ~TaskParent();
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000030
31 TaskParent *GetParent() { return parent_; }
32 TaskRunner *GetRunner() { return runner_; }
33
34 bool AllChildrenDone();
35 bool AnyChildError();
tfarinaa41ab932015-10-30 16:08:48 -070036#if !defined(NDEBUG)
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000037 bool IsChildTask(Task *task);
38#endif
39
40 protected:
41 void OnStopped(Task *task);
42 void AbortAllChildren();
43 TaskParent *parent() {
44 return parent_;
45 }
46
47 private:
48 void Initialize();
49 void OnChildStopped(Task *child);
50 void AddChild(Task *child);
51
52 TaskParent *parent_;
53 TaskRunner *runner_;
54 bool child_error_;
55 typedef std::set<Task *> ChildSet;
jbauch555604a2016-04-26 03:13:22 -070056 std::unique_ptr<ChildSet> children_;
henrikg3c089d72015-09-16 05:37:44 -070057 RTC_DISALLOW_COPY_AND_ASSIGN(TaskParent);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000058};
59
60
61} // namespace rtc
62
63#endif // WEBRTC_BASE_TASKPARENT_H__