blob: 55fe16f1d61ca8eef3cd5c759061e0075ebda9a8 [file] [log] [blame]
Ben Chan99c8a4d2012-05-01 08:11:53 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "shill/wimax.h"
6
Darin Petkov912f0de2012-05-16 14:12:14 +02007#include <base/bind.h>
8
9#include "shill/manager.h"
Darin Petkovb72b62e2012-05-15 16:55:36 +020010#include "shill/proxy_factory.h"
11#include "shill/scope_logger.h"
12#include "shill/wimax_device_proxy_interface.h"
Darin Petkov912f0de2012-05-16 14:12:14 +020013#include "shill/wimax_service.h"
Darin Petkovb72b62e2012-05-15 16:55:36 +020014
Darin Petkov912f0de2012-05-16 14:12:14 +020015using base::Bind;
Ben Chan99c8a4d2012-05-01 08:11:53 -070016using std::string;
17
18namespace shill {
19
Darin Petkov912f0de2012-05-16 14:12:14 +020020const int WiMax::kTimeoutDefault = 30000;
21
Ben Chan99c8a4d2012-05-01 08:11:53 -070022WiMax::WiMax(ControlInterface *control,
23 EventDispatcher *dispatcher,
24 Metrics *metrics,
25 Manager *manager,
26 const string &link_name,
Ben Chan4e64d2d2012-05-16 00:02:25 -070027 const string &address,
Darin Petkovb72b62e2012-05-15 16:55:36 +020028 int interface_index,
29 const RpcIdentifier &path)
Ben Chan4e64d2d2012-05-16 00:02:25 -070030 : Device(control, dispatcher, metrics, manager, link_name, address,
Darin Petkovb72b62e2012-05-15 16:55:36 +020031 interface_index, Technology::kWiMax),
32 path_(path),
33 proxy_factory_(ProxyFactory::GetInstance()) {
34 SLOG(WiMax, 2) << __func__ << "(" << link_name << ", " << path << ")";
35}
Ben Chan99c8a4d2012-05-01 08:11:53 -070036
Darin Petkovb72b62e2012-05-15 16:55:36 +020037WiMax::~WiMax() {
38 SLOG(WiMax, 2) << __func__ << "(" << link_name() << ", " << path_ << ")";
39}
Ben Chan99c8a4d2012-05-01 08:11:53 -070040
41void WiMax::Start(Error *error, const EnabledStateChangedCallback &callback) {
Darin Petkovb72b62e2012-05-15 16:55:36 +020042 SLOG(WiMax, 2) << __func__;
43 proxy_.reset(proxy_factory_->CreateWiMaxDeviceProxy(path_));
Darin Petkov912f0de2012-05-16 14:12:14 +020044 proxy_->Enable(
45 error, Bind(&WiMax::OnEnableComplete, this, callback), kTimeoutDefault);
Ben Chan99c8a4d2012-05-01 08:11:53 -070046}
47
48void WiMax::Stop(Error *error, const EnabledStateChangedCallback &callback) {
Darin Petkovb72b62e2012-05-15 16:55:36 +020049 SLOG(WiMax, 2) << __func__;
Darin Petkov912f0de2012-05-16 14:12:14 +020050 if (service_) {
51 manager()->DeregisterService(service_);
52 service_ = NULL;
Darin Petkovb72b62e2012-05-15 16:55:36 +020053 }
Darin Petkov912f0de2012-05-16 14:12:14 +020054 proxy_->Disable(
55 error, Bind(&WiMax::OnDisableComplete, this, callback), kTimeoutDefault);
Ben Chan99c8a4d2012-05-01 08:11:53 -070056}
57
58bool WiMax::TechnologyIs(const Technology::Identifier type) const {
59 return type == Technology::kWiMax;
60}
61
62void WiMax::Connect(Error *error) {
Darin Petkov912f0de2012-05-16 14:12:14 +020063 SLOG(WiMax, 2) << __func__;
64 proxy_->Connect(
65 error, Bind(&WiMax::OnConnectComplete, this), kTimeoutDefault);
Ben Chan99c8a4d2012-05-01 08:11:53 -070066}
67
68void WiMax::Disconnect(Error *error) {
Darin Petkov912f0de2012-05-16 14:12:14 +020069 SLOG(WiMax, 2) << __func__;
70 proxy_->Disconnect(
71 error, Bind(&WiMax::OnDisconnectComplete, this), kTimeoutDefault);
72}
73
74void WiMax::OnConnectComplete(const Error &error) {
75 SLOG(WiMax, 2) << __func__;
76 if (error.IsSuccess()) {
77 SelectService(service_);
78 // TODO(petkov): AcquireIPConfig through DHCP?
79 }
80}
81
82void WiMax::OnDisconnectComplete(const Error &error) {
83 SLOG(WiMax, 2) << __func__;
84 SelectService(NULL);
85}
86
87void WiMax::OnEnableComplete(const EnabledStateChangedCallback &callback,
88 const Error &error) {
89 SLOG(WiMax, 2) << __func__;
90 if (error.IsFailure()) {
91 proxy_.reset();
92 } else {
93 service_ = new WiMaxService(control_interface(),
94 dispatcher(),
95 metrics(),
96 manager(),
97 this);
98 manager()->RegisterService(service_);
99 }
100 callback.Run(error);
101
102}
103
104void WiMax::OnDisableComplete(const EnabledStateChangedCallback &callback,
105 const Error &error) {
106 SLOG(WiMax, 2) << __func__;
107 callback.Run(error);
Ben Chan99c8a4d2012-05-01 08:11:53 -0700108}
109
110} // namespace shill