blob: e26cc9db4ed3f826fd1674e5589a5aebce09b80c [file] [log] [blame]
Peter Qiuc0beca52015-09-03 11:25:46 -07001//
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 Petkova9b1fed2012-02-29 11:49:05 +010016
17#include "shill/rpc_task.h"
18
Ben Chana0ddf462014-02-06 11:32:42 -080019#include <base/strings/string_number_conversions.h>
Darin Petkova9b1fed2012-02-29 11:49:05 +010020
21#include "shill/adaptor_interfaces.h"
22#include "shill/control_interface.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070023#include "shill/logging.h"
Darin Petkova9b1fed2012-02-29 11:49:05 +010024
25using std::map;
26using std::string;
mukesh agrawalae30e9e2013-05-28 14:09:16 -070027using std::vector;
Darin Petkova9b1fed2012-02-29 11:49:05 +010028
29namespace shill {
30
31// static
32unsigned int RPCTask::serial_number_ = 0;
33
Paul Stewart1a212a62015-06-16 13:13:10 -070034RPCTask::RPCTask(ControlInterface* control_interface, RPCTaskDelegate* delegate)
Darin Petkova9b1fed2012-02-29 11:49:05 +010035 : delegate_(delegate),
36 unique_name_(base::UintToString(serial_number_++)),
37 adaptor_(control_interface->CreateRPCTaskAdaptor(this)) {
38 CHECK(delegate);
Darin Petkov69990222012-11-14 09:25:25 +010039 LOG(INFO) << "RPCTask " + unique_name_ + " created.";
Darin Petkova9b1fed2012-02-29 11:49:05 +010040}
41
42RPCTask::~RPCTask() {
Darin Petkov69990222012-11-14 09:25:25 +010043 LOG(INFO) << "RPCTask " + unique_name_ + " destroyed.";
Darin Petkova9b1fed2012-02-29 11:49:05 +010044}
45
Paul Stewart1a212a62015-06-16 13:13:10 -070046void RPCTask::GetLogin(string* user, string* password) const {
Darin Petkov209e6292012-04-20 11:33:32 +020047 delegate_->GetLogin(user, password);
48}
49
Paul Stewart1a212a62015-06-16 13:13:10 -070050void RPCTask::Notify(const string& reason, const map<string, string>& dict) {
Darin Petkova9b1fed2012-02-29 11:49:05 +010051 delegate_->Notify(reason, dict);
52}
53
Peter Qiua24480a2015-08-11 23:09:54 -070054map<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 agrawalae30e9e2013-05-28 14:09:16 -070059}
60
61// TODO(quiche): remove after moving OpenVPNDriver over to ExternalTask.
Darin Petkova9b1fed2012-02-29 11:49:05 +010062string RPCTask::GetRpcIdentifier() const {
63 return adaptor_->GetRpcIdentifier();
64}
65
mukesh agrawalae30e9e2013-05-28 14:09:16 -070066// TODO(quiche): remove after moving OpenVPNDriver over to ExternalTask.
Darin Petkova9b1fed2012-02-29 11:49:05 +010067string RPCTask::GetRpcConnectionIdentifier() const {
68 return adaptor_->GetRpcConnectionIdentifier();
69}
70
71} // namespace shill