| 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 | #include "shill/rpc_task.h" | 
|  | 6 |  | 
|  | 7 | #include <base/string_number_conversions.h> | 
|  | 8 |  | 
|  | 9 | #include "shill/adaptor_interfaces.h" | 
|  | 10 | #include "shill/control_interface.h" | 
| Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 11 | #include "shill/logging.h" | 
| Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 12 |  | 
|  | 13 | using std::map; | 
|  | 14 | using std::string; | 
| mukesh agrawal | ae30e9e | 2013-05-28 14:09:16 -0700 | [diff] [blame] | 15 | using std::vector; | 
| Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 16 |  | 
|  | 17 | namespace shill { | 
|  | 18 |  | 
|  | 19 | // static | 
|  | 20 | unsigned int RPCTask::serial_number_ = 0; | 
|  | 21 |  | 
|  | 22 | RPCTask::RPCTask(ControlInterface *control_interface, RPCTaskDelegate *delegate) | 
|  | 23 | : delegate_(delegate), | 
|  | 24 | unique_name_(base::UintToString(serial_number_++)), | 
|  | 25 | adaptor_(control_interface->CreateRPCTaskAdaptor(this)) { | 
|  | 26 | CHECK(delegate); | 
| Darin Petkov | 6999022 | 2012-11-14 09:25:25 +0100 | [diff] [blame] | 27 | LOG(INFO) << "RPCTask " + unique_name_ + " created."; | 
| Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 28 | } | 
|  | 29 |  | 
|  | 30 | RPCTask::~RPCTask() { | 
| Darin Petkov | 6999022 | 2012-11-14 09:25:25 +0100 | [diff] [blame] | 31 | LOG(INFO) << "RPCTask " + unique_name_ + " destroyed."; | 
| Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 32 | } | 
|  | 33 |  | 
| mukesh agrawal | ae30e9e | 2013-05-28 14:09:16 -0700 | [diff] [blame] | 34 | void RPCTask::GetLogin(string *user, string *password) const { | 
| Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 35 | delegate_->GetLogin(user, password); | 
|  | 36 | } | 
|  | 37 |  | 
| Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 38 | void RPCTask::Notify(const string &reason, const map<string, string> &dict) { | 
|  | 39 | delegate_->Notify(reason, dict); | 
|  | 40 | } | 
|  | 41 |  | 
| mukesh agrawal | ae30e9e | 2013-05-28 14:09:16 -0700 | [diff] [blame] | 42 | vector<string> RPCTask::GetEnvironment() const { | 
|  | 43 | return vector<string>{ | 
|  | 44 | string(kRPCTaskServiceVariable) + "=" + | 
|  | 45 | adaptor_->GetRpcConnectionIdentifier(), | 
|  | 46 | string(kRPCTaskPathVariable) + "=" + | 
|  | 47 | adaptor_->GetRpcIdentifier()}; | 
|  | 48 | } | 
|  | 49 |  | 
|  | 50 | // TODO(quiche): remove after moving OpenVPNDriver over to ExternalTask. | 
| Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 51 | string RPCTask::GetRpcIdentifier() const { | 
|  | 52 | return adaptor_->GetRpcIdentifier(); | 
|  | 53 | } | 
|  | 54 |  | 
| mukesh agrawal | ae30e9e | 2013-05-28 14:09:16 -0700 | [diff] [blame] | 55 | // TODO(quiche): remove after moving OpenVPNDriver over to ExternalTask. | 
| Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 56 | string RPCTask::GetRpcConnectionIdentifier() const { | 
|  | 57 | return adaptor_->GetRpcConnectionIdentifier(); | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | }  // namespace shill |