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//
16
17#include "shill/rpc_task.h"
18
19#include <base/strings/string_number_conversions.h>
20
21#include "shill/adaptor_interfaces.h"
22#include "shill/control_interface.h"
23#include "shill/logging.h"
24
25using std::map;
26using std::string;
27using std::vector;
28
29namespace shill {
30
31// static
32unsigned int RPCTask::serial_number_ = 0;
33
34RPCTask::RPCTask(ControlInterface* control_interface, RPCTaskDelegate* delegate)
35    : delegate_(delegate),
36      unique_name_(base::UintToString(serial_number_++)),
37      adaptor_(control_interface->CreateRPCTaskAdaptor(this)) {
38  CHECK(delegate);
39  LOG(INFO) << "RPCTask " + unique_name_ + " created.";
40}
41
42RPCTask::~RPCTask() {
43  LOG(INFO) << "RPCTask " + unique_name_ + " destroyed.";
44}
45
46void RPCTask::GetLogin(string* user, string* password) const {
47  delegate_->GetLogin(user, password);
48}
49
50void RPCTask::Notify(const string& reason, const map<string, string>& dict) {
51  delegate_->Notify(reason, dict);
52}
53
54map<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;
59}
60
61// TODO(quiche): remove after moving OpenVPNDriver over to ExternalTask.
62string RPCTask::GetRpcIdentifier() const {
63  return adaptor_->GetRpcIdentifier();
64}
65
66// TODO(quiche): remove after moving OpenVPNDriver over to ExternalTask.
67string RPCTask::GetRpcConnectionIdentifier() const {
68  return adaptor_->GetRpcConnectionIdentifier();
69}
70
71}  // namespace shill
72