Home | History | Annotate | Download | only in shill
      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 
     25 using std::map;
     26 using std::string;
     27 using std::vector;
     28 
     29 namespace shill {
     30 
     31 // static
     32 unsigned int RPCTask::serial_number_ = 0;
     33 
     34 RPCTask::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 
     42 RPCTask::~RPCTask() {
     43   LOG(INFO) << "RPCTask " + unique_name_ + " destroyed.";
     44 }
     45 
     46 void RPCTask::GetLogin(string* user, string* password) const {
     47   delegate_->GetLogin(user, password);
     48 }
     49 
     50 void RPCTask::Notify(const string& reason, const map<string, string>& dict) {
     51   delegate_->Notify(reason, dict);
     52 }
     53 
     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;
     59 }
     60 
     61 // TODO(quiche): remove after moving OpenVPNDriver over to ExternalTask.
     62 string RPCTask::GetRpcIdentifier() const {
     63   return adaptor_->GetRpcIdentifier();
     64 }
     65 
     66 // TODO(quiche): remove after moving OpenVPNDriver over to ExternalTask.
     67 string RPCTask::GetRpcConnectionIdentifier() const {
     68   return adaptor_->GetRpcConnectionIdentifier();
     69 }
     70 
     71 }  // namespace shill
     72