• 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_wimax_network_proxy.h"
18 
19 #if defined(__ANDROID__)
20 #include <dbus/service_constants.h>
21 #else
22 #include <chromeos/dbus/service_constants.h>
23 #endif  // __ANDROID__
24 
25 #include "shill/error.h"
26 #include "shill/logging.h"
27 
28 using std::string;
29 
30 namespace shill {
31 
32 namespace Logging {
33 static auto kModuleLogScope = ScopeLogger::kDBus;
ObjectID(const dbus::ObjectPath * p)34 static string ObjectID(const dbus::ObjectPath* p) {
35   return "wimax_network_proxy (" + p->value() + ")";
36 }
37 }
38 
39 // static.
40 const char ChromeosWiMaxNetworkProxy::kPropertyIdentifier[] = "Identifier";
41 const char ChromeosWiMaxNetworkProxy::kPropertyName[] = "Name";
42 const char ChromeosWiMaxNetworkProxy::kPropertyType[] = "Type";
43 const char ChromeosWiMaxNetworkProxy::kPropertyCINR[] = "CINR";
44 const char ChromeosWiMaxNetworkProxy::kPropertyRSSI[] = "RSSI";
45 const char ChromeosWiMaxNetworkProxy::kPropertySignalStrength[] =
46     "SignalStrength";
47 
PropertySet(dbus::ObjectProxy * object_proxy,const std::string & interface_name,const PropertyChangedCallback & callback)48 ChromeosWiMaxNetworkProxy::PropertySet::PropertySet(
49     dbus::ObjectProxy* object_proxy,
50     const std::string& interface_name,
51     const PropertyChangedCallback& callback)
52     : dbus::PropertySet(object_proxy, interface_name, callback) {
53   RegisterProperty(kPropertyIdentifier, &identifier);
54   RegisterProperty(kPropertyName, &name);
55   RegisterProperty(kPropertyType, &type);
56   RegisterProperty(kPropertyCINR, &cinr);
57   RegisterProperty(kPropertyRSSI, &rssi);
58   RegisterProperty(kPropertySignalStrength, &signal_strength);
59 }
60 
ChromeosWiMaxNetworkProxy(const scoped_refptr<dbus::Bus> & bus,const std::string & rpc_identifier)61 ChromeosWiMaxNetworkProxy::ChromeosWiMaxNetworkProxy(
62     const scoped_refptr<dbus::Bus>& bus,
63     const std::string& rpc_identifier)
64     : proxy_(
65         new org::chromium::WiMaxManager::NetworkProxy(
66             bus,
67             wimax_manager::kWiMaxManagerServiceName,
68             dbus::ObjectPath(rpc_identifier))) {
69   // Register signal handlers.
70   proxy_->RegisterSignalStrengthChangedSignalHandler(
71       base::Bind(&ChromeosWiMaxNetworkProxy::SignalStrengthChanged,
72                  weak_factory_.GetWeakPtr()),
73       base::Bind(&ChromeosWiMaxNetworkProxy::OnSignalConnected,
74                  weak_factory_.GetWeakPtr()));
75 
76   // Register properties.
77   properties_.reset(
78       new PropertySet(
79           proxy_->GetObjectProxy(),
80           wimax_manager::kWiMaxManagerNetworkInterface,
81           base::Bind(&ChromeosWiMaxNetworkProxy::OnPropertyChanged,
82                      weak_factory_.GetWeakPtr())));
83   properties_->ConnectSignals();
84   properties_->GetAll();
85 }
86 
87 
~ChromeosWiMaxNetworkProxy()88 ChromeosWiMaxNetworkProxy::~ChromeosWiMaxNetworkProxy() {
89   proxy_->ReleaseObjectProxy(base::Bind(&base::DoNothing));
90 }
91 
path() const92 RpcIdentifier ChromeosWiMaxNetworkProxy::path() const {
93   return proxy_->GetObjectPath().value();
94 }
95 
set_signal_strength_changed_callback(const SignalStrengthChangedCallback & callback)96 void ChromeosWiMaxNetworkProxy::set_signal_strength_changed_callback(
97     const SignalStrengthChangedCallback& callback) {
98   signal_strength_changed_callback_ = callback;
99 }
100 
Identifier(Error *)101 uint32_t ChromeosWiMaxNetworkProxy::Identifier(Error* /*error*/) {
102   SLOG(&proxy_->GetObjectPath(), 2) << __func__;
103   if (!properties_->identifier.GetAndBlock()) {
104     LOG(ERROR) << "Failed to get Identifier";
105     return 0;
106   }
107   return properties_->identifier.value();
108 }
109 
Name(Error *)110 string ChromeosWiMaxNetworkProxy::Name(Error* /*error*/) {
111   SLOG(&proxy_->GetObjectPath(), 2) << __func__;
112   if (!properties_->name.GetAndBlock()) {
113     LOG(ERROR) << "Failed to get Name";
114     return string();
115   }
116   return properties_->name.value();
117 }
118 
Type(Error *)119 int ChromeosWiMaxNetworkProxy::Type(Error* /*error*/) {
120   SLOG(&proxy_->GetObjectPath(), 2) << __func__;
121   if (!properties_->type.GetAndBlock()) {
122     LOG(ERROR) << "Failed to get Type";
123     return 0;
124   }
125   return properties_->type.value();
126 }
127 
CINR(Error *)128 int ChromeosWiMaxNetworkProxy::CINR(Error* /*error*/) {
129   SLOG(&proxy_->GetObjectPath(), 2) << __func__;
130   if (!properties_->cinr.GetAndBlock()) {
131     LOG(ERROR) << "Failed to get CINR";
132     return 0;
133   }
134   return properties_->cinr.value();
135 }
136 
RSSI(Error *)137 int ChromeosWiMaxNetworkProxy::RSSI(Error* /*error*/) {
138   SLOG(&proxy_->GetObjectPath(), 2) << __func__;
139   if (!properties_->rssi.GetAndBlock()) {
140     LOG(ERROR) << "Failed to get RSSI";
141     return 0;
142   }
143   return properties_->rssi.value();
144 }
145 
SignalStrength(Error *)146 int ChromeosWiMaxNetworkProxy::SignalStrength(Error* /*error*/) {
147   SLOG(&proxy_->GetObjectPath(), 2) << __func__;
148   if (!properties_->signal_strength.GetAndBlock()) {
149     LOG(ERROR) << "Faild to get SignalStrength";
150     return 0;
151   }
152   return properties_->signal_strength.value();
153 }
154 
SignalStrengthChanged(int32_t signal_strength)155 void ChromeosWiMaxNetworkProxy::SignalStrengthChanged(int32_t signal_strength) {
156   SLOG(&proxy_->GetObjectPath(), 2) << __func__
157       << "(" << signal_strength << ")";
158   if (!signal_strength_changed_callback_.is_null()) {
159     signal_strength_changed_callback_.Run(signal_strength);
160   }
161 }
162 
OnSignalConnected(const string & interface_name,const string & signal_name,bool success)163 void ChromeosWiMaxNetworkProxy::OnSignalConnected(
164     const string& interface_name, const string& signal_name, bool success) {
165   SLOG(&proxy_->GetObjectPath(), 2) << __func__
166       << "interface: " << interface_name << " signal: " << signal_name
167       << "success: " << success;
168   if (!success) {
169     LOG(ERROR) << "Failed to connect signal " << signal_name
170         << " to interface " << interface_name;
171   }
172 }
173 
OnPropertyChanged(const std::string & property_name)174 void ChromeosWiMaxNetworkProxy::OnPropertyChanged(
175     const std::string& property_name) {
176   SLOG(&proxy_->GetObjectPath(), 2) << __func__ << ": " << property_name;
177 }
178 
179 }  // namespace shill
180