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 | |
| 5 | #ifndef SHILL_RPC_TASK_ |
| 6 | #define SHILL_RPC_TASK_ |
| 7 | |
| 8 | #include <map> |
| 9 | #include <string> |
mukesh agrawal | ae30e9e | 2013-05-28 14:09:16 -0700 | [diff] [blame] | 10 | #include <vector> |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 11 | |
| 12 | #include <base/basictypes.h> |
| 13 | #include <base/memory/scoped_ptr.h> |
| 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 |
| 25 | // (crosbug.com/29766). |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 26 | class RPCTaskDelegate { |
| 27 | public: |
| 28 | virtual ~RPCTaskDelegate() {} |
| 29 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 30 | virtual void GetLogin(std::string *user, std::string *password) = 0; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 31 | 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. |
| 38 | class RPCTask { |
| 39 | public: |
| 40 | // A constructor for the RPCTask object. |
| 41 | RPCTask(ControlInterface *control_interface, RPCTaskDelegate *delegate); |
| 42 | virtual ~RPCTask(); |
| 43 | |
mukesh agrawal | ae30e9e | 2013-05-28 14:09:16 -0700 | [diff] [blame] | 44 | virtual void GetLogin(std::string *user, std::string *password) const; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 45 | 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 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: |
| 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_ |