Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 1 | // 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 Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 5 | #ifndef SHILL_RPC_TASK_H_ |
| 6 | #define SHILL_RPC_TASK_H_ |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 7 | |
| 8 | #include <map> |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 9 | #include <memory> |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 10 | #include <string> |
mukesh agrawal | ae30e9e | 2013-05-28 14:09:16 -0700 | [diff] [blame] | 11 | #include <vector> |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 12 | |
Ben Chan | cc67c52 | 2014-09-03 07:19:18 -0700 | [diff] [blame] | 13 | #include <base/macros.h> |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 14 | |
| 15 | namespace shill { |
| 16 | |
Darin Petkov | 728faa9 | 2012-10-12 11:25:47 +0200 | [diff] [blame] | 17 | // Declared in the header to avoid linking unused code into shims. |
| 18 | static const char kRPCTaskServiceVariable[] = "SHILL_TASK_SERVICE"; |
| 19 | static const char kRPCTaskPathVariable[] = "SHILL_TASK_PATH"; |
| 20 | |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 21 | class ControlInterface; |
| 22 | class RPCTaskAdaptorInterface; |
| 23 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 24 | // TODO(petkov): Switch from delegate interface to registered callbacks |
Paul Stewart | ee6b3d7 | 2013-07-12 16:07:51 -0700 | [diff] [blame] | 25 | // (crbug.com/212273). |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 26 | class RPCTaskDelegate { |
| 27 | public: |
| 28 | virtual ~RPCTaskDelegate() {} |
| 29 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 30 | 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 Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 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. |
| 38 | class RPCTask { |
| 39 | public: |
| 40 | // A constructor for the RPCTask object. |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 41 | RPCTask(ControlInterface* control_interface, RPCTaskDelegate* delegate); |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 42 | virtual ~RPCTask(); |
| 43 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 44 | 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 Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 47 | |
| 48 | // Returns a string that is guaranteed to uniquely identify this RPCTask |
| 49 | // instance. |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 50 | const std::string& UniqueName() const { return unique_name_; } |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 51 | |
mukesh agrawal | ae30e9e | 2013-05-28 14:09:16 -0700 | [diff] [blame] | 52 | // 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 Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 55 | std::string GetRpcIdentifier() const; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 56 | std::string GetRpcConnectionIdentifier() const; |
| 57 | |
| 58 | private: |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 59 | RPCTaskDelegate* delegate_; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 60 | static unsigned int serial_number_; |
| 61 | std::string unique_name_; // MUST be unique amongst RPC task instances |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 62 | std::unique_ptr<RPCTaskAdaptorInterface> adaptor_; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 63 | |
| 64 | DISALLOW_COPY_AND_ASSIGN(RPCTask); |
| 65 | }; |
| 66 | |
| 67 | } // namespace shill |
| 68 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 69 | #endif // SHILL_RPC_TASK_H_ |