blob: 5d8a264ac3623e26f3e13ae596aaadf46c716ea5 [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
Darin Petkov728faa92012-10-12 11:25:47 +020016// Declared in the header to avoid linking unused code into shims.
17static const char kRPCTaskServiceVariable[] = "SHILL_TASK_SERVICE";
18static const char kRPCTaskPathVariable[] = "SHILL_TASK_PATH";
19
Darin Petkova9b1fed2012-02-29 11:49:05 +010020class ControlInterface;
21class RPCTaskAdaptorInterface;
22
Darin Petkov209e6292012-04-20 11:33:32 +020023// TODO(petkov): Switch from delegate interface to registered callbacks
24// (crosbug.com/29766).
Darin Petkova9b1fed2012-02-29 11:49:05 +010025class RPCTaskDelegate {
26 public:
27 virtual ~RPCTaskDelegate() {}
28
Darin Petkov209e6292012-04-20 11:33:32 +020029 virtual void GetLogin(std::string *user, std::string *password) = 0;
Darin Petkova9b1fed2012-02-29 11:49:05 +010030 virtual void Notify(const std::string &reason,
31 const std::map<std::string, std::string> &dict) = 0;
32};
33
34// RPC tasks are currently used by VPN drivers for communication with external
35// VPN processes. The RPC task should be owned by a single owner -- its
36// RPCTaskDelegate -- so no need to be reference counted.
37class RPCTask {
38 public:
39 // A constructor for the RPCTask object.
40 RPCTask(ControlInterface *control_interface, RPCTaskDelegate *delegate);
41 virtual ~RPCTask();
42
Darin Petkov209e6292012-04-20 11:33:32 +020043 virtual void GetLogin(std::string *user, std::string *password);
Darin Petkova9b1fed2012-02-29 11:49:05 +010044 virtual void Notify(const std::string &reason,
45 const std::map<std::string, std::string> &dict);
46
47 // Returns a string that is guaranteed to uniquely identify this RPCTask
48 // instance.
49 const std::string &UniqueName() const { return unique_name_; }
50
51 std::string GetRpcIdentifier() const;
52 std::string GetRpcInterfaceIdentifier() const;
53 std::string GetRpcConnectionIdentifier() const;
54
55 private:
56 RPCTaskDelegate *delegate_;
57 static unsigned int serial_number_;
58 std::string unique_name_; // MUST be unique amongst RPC task instances
59 scoped_ptr<RPCTaskAdaptorInterface> adaptor_;
60
61 DISALLOW_COPY_AND_ASSIGN(RPCTask);
62};
63
64} // namespace shill
65
66#endif // SHILL_RPC_TASK_