blob: 48951e9f62aa2c9d44d29e95cc6ea622d7a2089c [file] [log] [blame]
Darin Petkova9b1fed2012-02-29 11:49:05 +01001// 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_RPC_TASK_
6#define SHILL_RPC_TASK_
7
8#include <map>
9#include <string>
10
11#include <base/basictypes.h>
12#include <base/memory/scoped_ptr.h>
13
14namespace shill {
15
16class ControlInterface;
17class RPCTaskAdaptorInterface;
18
Darin Petkov209e6292012-04-20 11:33:32 +020019// TODO(petkov): Switch from delegate interface to registered callbacks
20// (crosbug.com/29766).
Darin Petkova9b1fed2012-02-29 11:49:05 +010021class RPCTaskDelegate {
22 public:
23 virtual ~RPCTaskDelegate() {}
24
Darin Petkov209e6292012-04-20 11:33:32 +020025 virtual void GetLogin(std::string *user, std::string *password) = 0;
Darin Petkova9b1fed2012-02-29 11:49:05 +010026 virtual void Notify(const std::string &reason,
27 const std::map<std::string, std::string> &dict) = 0;
28};
29
30// RPC tasks are currently used by VPN drivers for communication with external
31// VPN processes. The RPC task should be owned by a single owner -- its
32// RPCTaskDelegate -- so no need to be reference counted.
33class RPCTask {
34 public:
35 // A constructor for the RPCTask object.
36 RPCTask(ControlInterface *control_interface, RPCTaskDelegate *delegate);
37 virtual ~RPCTask();
38
Darin Petkov209e6292012-04-20 11:33:32 +020039 virtual void GetLogin(std::string *user, std::string *password);
Darin Petkova9b1fed2012-02-29 11:49:05 +010040 virtual void Notify(const std::string &reason,
41 const std::map<std::string, std::string> &dict);
42
43 // Returns a string that is guaranteed to uniquely identify this RPCTask
44 // instance.
45 const std::string &UniqueName() const { return unique_name_; }
46
47 std::string GetRpcIdentifier() const;
48 std::string GetRpcInterfaceIdentifier() const;
49 std::string GetRpcConnectionIdentifier() const;
50
51 private:
52 RPCTaskDelegate *delegate_;
53 static unsigned int serial_number_;
54 std::string unique_name_; // MUST be unique amongst RPC task instances
55 scoped_ptr<RPCTaskAdaptorInterface> adaptor_;
56
57 DISALLOW_COPY_AND_ASSIGN(RPCTask);
58};
59
60} // namespace shill
61
62#endif // SHILL_RPC_TASK_