blob: af88be04184427ee7cb8da2908380b1fa3db85d1 [file] [log] [blame]
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05001// Copyright (c) 2012 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_ASYNC_CALL_HANDLER_
6#define SHILL_ASYNC_CALL_HANDLER_
7
8#include <base/basictypes.h>
9
10namespace shill {
11
12class Error;
13class ReturnerInterface;
14
15// TODO(ers): An AsyncCallHandler object for an in-flight operation can leak if
16// an ObjectProxy disappears before the object is deleted. This can probably
17// be handled by changing dbus-c++ to allow registering a user-supplied
18// 'free' function for the 'data' argument passed to proxy methods. In that
19// case, the objects will be freed when pending dbus calls are canceled.
20//
21// The same issue appears to be relevant to Returner objects as well.
22
23
24// This class implements reply handling for code that makes asynchronous
25// client calls. The default behavior, embodied in this class, is to
26// return a result or error to the pending adaptor method invocation,
27// if any. This behavior may be overridden or extended by specializations
28// of this class.
29//
30// <external-client> --- [method call] ---> shill adaptor
31class AsyncCallHandler {
32 public:
33 AsyncCallHandler();
34 explicit AsyncCallHandler(ReturnerInterface *returner);
35 virtual ~AsyncCallHandler() { }
36
37 // Signal successful completion of the handling of a reply to a
38 // single asynchronous client operation. Returns true if a terminal
39 // state has been reached, i.e., the AsyncCallHandler is no longer
40 // needed. The base class always returns true.
41 bool Complete();
42 // Signal completion of the handling of a reply to a single
43 // asynchronous client operation which resulted in an error.
44 // Returns true if a terminal state has been reached, i.e.,
45 // the AsyncCallHandler is no longer needed. The base class always
46 // returns true.
47 bool Complete(const Error &error);
48
49 protected:
50 ReturnerInterface *returner() const { return returner_; }
51
52 virtual bool CompleteOperation();
53 virtual bool CompleteOperationWithError(const Error &error);
54
55 void DoReturn();
56
57 private:
58 // scoped_ptr not used here because Returners delete themselves
59 ReturnerInterface *returner_;
60
61 DISALLOW_COPY_AND_ASSIGN(AsyncCallHandler);
62};
63
64} // namespace shill
65
66#endif // SHILL_ASYNC_CALL_HANDLER_