blob: 1023d3c49736998dee51f1542961f09456971d33 [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
Ben Chanc45688b2014-07-02 23:50:45 -07005#ifndef SHILL_RPC_TASK_H_
6#define SHILL_RPC_TASK_H_
Darin Petkova9b1fed2012-02-29 11:49:05 +01007
8#include <map>
Ben Chancd477322014-10-17 14:19:30 -07009#include <memory>
Darin Petkova9b1fed2012-02-29 11:49:05 +010010#include <string>
mukesh agrawalae30e9e2013-05-28 14:09:16 -070011#include <vector>
Darin Petkova9b1fed2012-02-29 11:49:05 +010012
Ben Chancc67c522014-09-03 07:19:18 -070013#include <base/macros.h>
Darin Petkova9b1fed2012-02-29 11:49:05 +010014
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
Paul Stewartee6b3d72013-07-12 16:07:51 -070025// (crbug.com/212273).
Darin Petkova9b1fed2012-02-29 11:49:05 +010026class RPCTaskDelegate {
27 public:
28 virtual ~RPCTaskDelegate() {}
29
Paul Stewart1a212a62015-06-16 13:13:10 -070030 virtual void GetLogin(std::string* user, std::string* password) = 0;
31 virtual void Notify(const std::string& reason,
32 const std::map<std::string, std::string>& dict) = 0;
Darin Petkova9b1fed2012-02-29 11:49:05 +010033};
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.
Paul Stewart1a212a62015-06-16 13:13:10 -070041 RPCTask(ControlInterface* control_interface, RPCTaskDelegate* delegate);
Darin Petkova9b1fed2012-02-29 11:49:05 +010042 virtual ~RPCTask();
43
Paul Stewart1a212a62015-06-16 13:13:10 -070044 virtual void GetLogin(std::string* user, std::string* password) const;
45 virtual void Notify(const std::string& reason,
46 const std::map<std::string, std::string>& dict);
Darin Petkova9b1fed2012-02-29 11:49:05 +010047
48 // Returns a string that is guaranteed to uniquely identify this RPCTask
49 // instance.
Paul Stewart1a212a62015-06-16 13:13:10 -070050 const std::string& UniqueName() const { return unique_name_; }
Darin Petkova9b1fed2012-02-29 11:49:05 +010051
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:
Paul Stewart1a212a62015-06-16 13:13:10 -070059 RPCTaskDelegate* delegate_;
Darin Petkova9b1fed2012-02-29 11:49:05 +010060 static unsigned int serial_number_;
61 std::string unique_name_; // MUST be unique amongst RPC task instances
Ben Chancd477322014-10-17 14:19:30 -070062 std::unique_ptr<RPCTaskAdaptorInterface> adaptor_;
Darin Petkova9b1fed2012-02-29 11:49:05 +010063
64 DISALLOW_COPY_AND_ASSIGN(RPCTask);
65};
66
67} // namespace shill
68
Ben Chanc45688b2014-07-02 23:50:45 -070069#endif // SHILL_RPC_TASK_H_