Peter Qiu | c0beca5 | 2015-09-03 11:25:46 -0700 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (C) 2012 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 16 | |
| 17 | #include "shill/rpc_task.h" |
| 18 | |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 19 | #include <base/strings/string_number_conversions.h> |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 20 | |
| 21 | #include "shill/adaptor_interfaces.h" |
| 22 | #include "shill/control_interface.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 23 | #include "shill/logging.h" |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 24 | |
| 25 | using std::map; |
| 26 | using std::string; |
mukesh agrawal | ae30e9e | 2013-05-28 14:09:16 -0700 | [diff] [blame] | 27 | using std::vector; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 28 | |
| 29 | namespace shill { |
| 30 | |
| 31 | // static |
| 32 | unsigned int RPCTask::serial_number_ = 0; |
| 33 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 34 | RPCTask::RPCTask(ControlInterface* control_interface, RPCTaskDelegate* delegate) |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 35 | : delegate_(delegate), |
| 36 | unique_name_(base::UintToString(serial_number_++)), |
| 37 | adaptor_(control_interface->CreateRPCTaskAdaptor(this)) { |
| 38 | CHECK(delegate); |
Darin Petkov | 6999022 | 2012-11-14 09:25:25 +0100 | [diff] [blame] | 39 | LOG(INFO) << "RPCTask " + unique_name_ + " created."; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | RPCTask::~RPCTask() { |
Darin Petkov | 6999022 | 2012-11-14 09:25:25 +0100 | [diff] [blame] | 43 | LOG(INFO) << "RPCTask " + unique_name_ + " destroyed."; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 44 | } |
| 45 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 46 | void RPCTask::GetLogin(string* user, string* password) const { |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 47 | delegate_->GetLogin(user, password); |
| 48 | } |
| 49 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 50 | void RPCTask::Notify(const string& reason, const map<string, string>& dict) { |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 51 | delegate_->Notify(reason, dict); |
| 52 | } |
| 53 | |
Peter Qiu | a24480a | 2015-08-11 23:09:54 -0700 | [diff] [blame] | 54 | map<string, string> RPCTask::GetEnvironment() const { |
| 55 | map<string, string> env; |
| 56 | env.emplace(kRPCTaskServiceVariable, adaptor_->GetRpcConnectionIdentifier()); |
| 57 | env.emplace(kRPCTaskPathVariable, adaptor_->GetRpcIdentifier()); |
| 58 | return env; |
mukesh agrawal | ae30e9e | 2013-05-28 14:09:16 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | // TODO(quiche): remove after moving OpenVPNDriver over to ExternalTask. |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 62 | string RPCTask::GetRpcIdentifier() const { |
| 63 | return adaptor_->GetRpcIdentifier(); |
| 64 | } |
| 65 | |
mukesh agrawal | ae30e9e | 2013-05-28 14:09:16 -0700 | [diff] [blame] | 66 | // TODO(quiche): remove after moving OpenVPNDriver over to ExternalTask. |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 67 | string RPCTask::GetRpcConnectionIdentifier() const { |
| 68 | return adaptor_->GetRpcConnectionIdentifier(); |
| 69 | } |
| 70 | |
| 71 | } // namespace shill |