blob: 1e81d6f19040b2043180c6af862b27b38b8e8b61 [file] [log] [blame]
mukesh agrawal46c27cc2013-07-10 16:39:10 -07001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SHILL_RESULT_AGGREGATOR_H_
6#define SHILL_RESULT_AGGREGATOR_H_
7
8#include <base/basictypes.h>
9#include <base/memory/ref_counted.h>
10
11#include "shill/callbacks.h"
12#include "shill/error.h"
13
14namespace shill {
15
16// The ResultAggregator is used to aggregate the result of multiple
17// asynchronous operations. To use: construct a ResultAggregator, and
18// Bind its ReportResult methods to some Callbacks.
19//
20// When the Callbacks are destroyed, they will drop their references
21// to the ResultAggregator. When all references to the
22// ResultAggregator are destroyed, the ResultAggregator will invoke
23// the |callback| with which ResultAggregator was constructed. However,
24// if no Callbacks invoked ReportResult, then the original |callback|
25// will not be invoked.
26//
27// |callback| will see Error type of Success if all Callbacks reported
28// Success to ResultAggregator. Otherwise, |callback| will see the first
29// of the Errors reported to ResultAggregator.
30class ResultAggregator : public base::RefCounted<ResultAggregator> {
31 public:
32 explicit ResultAggregator(const ResultCallback &callback);
33 virtual ~ResultAggregator();
34
35 void ReportResult(const Error &error);
36
37 private:
38 const ResultCallback callback_;
39 bool got_result_;
40 Error error_;
41
42 DISALLOW_COPY_AND_ASSIGN(ResultAggregator);
43};
44
45} // namespace shill
46
47#endif // SHILL_RESULT_AGGREGATOR_H_