blob: d1fd251c7322adfdf8e4cec9e8f655ce91ac5363 [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>
mukesh agrawalae30e9e2013-05-28 14:09:16 -070010#include <vector>
Darin Petkova9b1fed2012-02-29 11:49:05 +010011
12#include <base/basictypes.h>
13#include <base/memory/scoped_ptr.h>
14
15namespace shill {
16
Darin Petkov728faa92012-10-12 11:25:47 +020017// Declared in the header to avoid linking unused code into shims.
18static const char kRPCTaskServiceVariable[] = "SHILL_TASK_SERVICE";
19static const char kRPCTaskPathVariable[] = "SHILL_TASK_PATH";
20
Darin Petkova9b1fed2012-02-29 11:49:05 +010021class ControlInterface;
22class RPCTaskAdaptorInterface;
23
Darin Petkov209e6292012-04-20 11:33:32 +020024// TODO(petkov): Switch from delegate interface to registered callbacks
25// (crosbug.com/29766).
Darin Petkova9b1fed2012-02-29 11:49:05 +010026class RPCTaskDelegate {
27 public:
28 virtual ~RPCTaskDelegate() {}
29
Darin Petkov209e6292012-04-20 11:33:32 +020030 virtual void GetLogin(std::string *user, std::string *password) = 0;
Darin Petkova9b1fed2012-02-29 11:49:05 +010031 virtual void Notify(const std::string &reason,
32 const std::map<std::string, std::string> &dict) = 0;
33};
34
35// RPC tasks are currently used by VPN drivers for communication with external
36// VPN processes. The RPC task should be owned by a single owner -- its
37// RPCTaskDelegate -- so no need to be reference counted.
38class RPCTask {
39 public:
40 // A constructor for the RPCTask object.
41 RPCTask(ControlInterface *control_interface, RPCTaskDelegate *delegate);
42 virtual ~RPCTask();
43
mukesh agrawalae30e9e2013-05-28 14:09:16 -070044 virtual void GetLogin(std::string *user, std::string *password) const;
Darin Petkova9b1fed2012-02-29 11:49:05 +010045 virtual void Notify(const std::string &reason,
46 const std::map<std::string, std::string> &dict);
47
48 // Returns a string that is guaranteed to uniquely identify this RPCTask
49 // instance.
50 const std::string &UniqueName() const { return unique_name_; }
51
mukesh agrawalae30e9e2013-05-28 14:09:16 -070052 // Generates environment variable strings for a child process to
53 // communicate back to us over RPC.
54 virtual std::vector<std::string> GetEnvironment() const;
Darin Petkova9b1fed2012-02-29 11:49:05 +010055 std::string GetRpcIdentifier() const;
Darin Petkova9b1fed2012-02-29 11:49:05 +010056 std::string GetRpcConnectionIdentifier() const;
57
58 private:
59 RPCTaskDelegate *delegate_;
60 static unsigned int serial_number_;
61 std::string unique_name_; // MUST be unique amongst RPC task instances
62 scoped_ptr<RPCTaskAdaptorInterface> adaptor_;
63
64 DISALLOW_COPY_AND_ASSIGN(RPCTask);
65};
66
67} // namespace shill
68
69#endif // SHILL_RPC_TASK_