• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2015 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/dbus/chromeos_rpc_task_dbus_adaptor.h"
18 
19 #include <base/strings/stringprintf.h>
20 
21 #include "shill/error.h"
22 #include "shill/logging.h"
23 #include "shill/rpc_task.h"
24 
25 using brillo::dbus_utils::AsyncEventSequencer;
26 using brillo::dbus_utils::ExportedObjectManager;
27 using std::map;
28 using std::string;
29 
30 namespace shill {
31 
32 namespace Logging {
33 static auto kModuleLogScope = ScopeLogger::kDBus;
ObjectID(ChromeosRPCTaskDBusAdaptor * r)34 static string ObjectID(ChromeosRPCTaskDBusAdaptor* r) {
35   return r->GetRpcIdentifier();
36 }
37 }
38 
39 // static
40 const char ChromeosRPCTaskDBusAdaptor::kPath[] = "/task/";
41 
ChromeosRPCTaskDBusAdaptor(const scoped_refptr<dbus::Bus> & bus,RPCTask * task)42 ChromeosRPCTaskDBusAdaptor::ChromeosRPCTaskDBusAdaptor(
43     const scoped_refptr<dbus::Bus>& bus,
44     RPCTask* task)
45     : org::chromium::flimflam::TaskAdaptor(this),
46       ChromeosDBusAdaptor(bus, kPath + task->UniqueName()),
47       task_(task),
48       connection_name_(bus->GetConnectionName()) {
49   // Register DBus object.
50   RegisterWithDBusObject(dbus_object());
51   dbus_object()->RegisterAndBlock();
52 }
53 
~ChromeosRPCTaskDBusAdaptor()54 ChromeosRPCTaskDBusAdaptor::~ChromeosRPCTaskDBusAdaptor() {
55   dbus_object()->UnregisterAsync();
56   task_ = nullptr;
57 }
58 
GetRpcIdentifier()59 const string& ChromeosRPCTaskDBusAdaptor::GetRpcIdentifier() {
60   return dbus_path().value();
61 }
62 
GetRpcConnectionIdentifier()63 const string& ChromeosRPCTaskDBusAdaptor::GetRpcConnectionIdentifier() {
64   return connection_name_;
65 }
66 
getsec(brillo::ErrorPtr *,string * user,string * password)67 bool ChromeosRPCTaskDBusAdaptor::getsec(
68     brillo::ErrorPtr* /*error*/, string* user, string* password) {
69   SLOG(this, 2) << __func__ << ": " << user;
70   task_->GetLogin(user, password);
71   return true;
72 }
73 
notify(brillo::ErrorPtr *,const string & reason,const map<string,string> & dict)74 bool ChromeosRPCTaskDBusAdaptor::notify(brillo::ErrorPtr* /*error*/,
75                                         const string& reason,
76                                         const map<string, string>& dict) {
77   SLOG(this, 2) << __func__ << ": " << reason;
78   task_->Notify(reason, dict);
79   return true;
80 }
81 
82 }  // namespace shill
83