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> |
| 10 | |
| 11 | #include <base/basictypes.h> |
| 12 | #include <base/memory/scoped_ptr.h> |
| 13 | |
| 14 | namespace shill { |
| 15 | |
Darin Petkov | 728faa9 | 2012-10-12 11:25:47 +0200 | [diff] [blame] | 16 | // Declared in the header to avoid linking unused code into shims. |
| 17 | static const char kRPCTaskServiceVariable[] = "SHILL_TASK_SERVICE"; |
| 18 | static const char kRPCTaskPathVariable[] = "SHILL_TASK_PATH"; |
| 19 | |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 20 | class ControlInterface; |
| 21 | class RPCTaskAdaptorInterface; |
| 22 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 23 | // TODO(petkov): Switch from delegate interface to registered callbacks |
| 24 | // (crosbug.com/29766). |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 25 | class RPCTaskDelegate { |
| 26 | public: |
| 27 | virtual ~RPCTaskDelegate() {} |
| 28 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 29 | virtual void GetLogin(std::string *user, std::string *password) = 0; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 30 | 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. |
| 37 | class RPCTask { |
| 38 | public: |
| 39 | // A constructor for the RPCTask object. |
| 40 | RPCTask(ControlInterface *control_interface, RPCTaskDelegate *delegate); |
| 41 | virtual ~RPCTask(); |
| 42 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 43 | virtual void GetLogin(std::string *user, std::string *password); |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 44 | 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_ |