shill: Cellular device obtains Modem status through its Simple interface.
BUG=chromium-os:18315
TEST=unit tests, tested on device
Change-Id: I0eae20e65724387c1acad05acdf85bc6cd20d71f
Reviewed-on: http://gerrit.chromium.org/gerrit/4968
Reviewed-by: Darin Petkov <petkov@chromium.org>
Tested-by: Darin Petkov <petkov@chromium.org>
diff --git a/Makefile b/Makefile
index e03f580..dbb91cd 100644
--- a/Makefile
+++ b/Makefile
@@ -30,6 +30,10 @@
DBUS_BINDINGS_DIR = dbus_bindings
DBUS_BINDINGS_MODEM_MANAGER = $(DBUS_BINDINGS_DIR)/modem_manager.xml
+DBUS_BINDINGS_MODEM_SIMPLE = $(DBUS_BINDINGS_DIR)/modem-simple.xml
+DBUS_BINDINGS_XML = \
+ $(DBUS_BINDINGS_MODEM_MANAGER) \
+ $(DBUS_BINDINGS_MODEM_SIMPLE)
DBUS_ADAPTOR_HEADERS = \
flimflam-device.h \
@@ -39,9 +43,9 @@
flimflam-service.h
DBUS_PROXY_HEADERS = \
+ $(patsubst $(DBUS_BINDINGS_DIR)/%.xml,%.h,$(DBUS_BINDINGS_XML)) \
dhcpcd.h \
modem.h \
- modem_manager.h \
supplicant-bss.h \
supplicant-interface.h \
supplicant-network.h \
@@ -88,6 +92,7 @@
modem_manager.o \
modem_manager_proxy.o \
modem_proxy.o \
+ modem_simple_proxy.o \
profile.o \
profile_dbus_adaptor.o \
property_store.o \
@@ -156,6 +161,10 @@
$(DBUS_INTERFACES_DIR)/org.freedesktop.ModemManager.xml
cat $< > $@
+$(DBUS_BINDINGS_MODEM_SIMPLE): \
+ $(DBUS_INTERFACES_DIR)/org.freedesktop.ModemManager.Modem.Simple.xml
+ cat $< > $@
+
$(DBUS_PROXY_BINDINGS): %.h: %.xml
$(DBUSXX_XML2CPP) $< --proxy=$@
@@ -176,5 +185,9 @@
$(CXX) $(CXXFLAGS) $(TEST_LIB_DIRS) $(LDFLAGS) $^ $(TEST_LIBS) -o $@
clean:
- rm -rf *.o $(DBUS_BINDINGS_MODEM_MANAGER) $(DBUS_BINDINGS) \
- $(SHILL_BIN) $(TEST_BIN)
+ rm -rf \
+ *.o \
+ $(DBUS_BINDINGS_XML) \
+ $(DBUS_BINDINGS) \
+ $(SHILL_BIN) \
+ $(TEST_BIN)
diff --git a/cellular.cc b/cellular.cc
index eba4956..07276aa 100644
--- a/cellular.cc
+++ b/cellular.cc
@@ -18,6 +18,7 @@
#include "shill/device_info.h"
#include "shill/manager.h"
#include "shill/modem_proxy_interface.h"
+#include "shill/modem_simple_proxy_interface.h"
#include "shill/profile.h"
#include "shill/property_accessor.h"
#include "shill/proxy_factory.h"
@@ -169,11 +170,21 @@
// TODO(petkov): Switch to asynchronous calls (crosbug.com/17583).
proxy_->Enable(true);
state_ = kStateEnabled;
+
+ simple_proxy_.reset(
+ ProxyFactory::factory()->CreateModemSimpleProxy(dbus_path_, dbus_owner_));
+ // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583).
+ DBusPropertiesMap properties = simple_proxy_->GetStatus();
+ for (DBusPropertiesMap::const_iterator it = properties.begin();
+ it != properties.end(); ++it) {
+ VLOG(2) << "ModemManager.Modem.Simple: " << it->first;
+ }
// TODO(petkov): Device::Start();
}
void Cellular::Stop() {
proxy_.reset();
+ simple_proxy_.reset();
manager_->DeregisterService(service_);
service_ = NULL; // Breaks a reference cycle.
// TODO(petkov): Device::Stop();
diff --git a/cellular.h b/cellular.h
index e684361..22236fb 100644
--- a/cellular.h
+++ b/cellular.h
@@ -17,6 +17,7 @@
namespace shill {
class ModemProxyInterface;
+class ModemSimpleProxyInterface;
class Cellular : public Device {
public:
@@ -109,6 +110,7 @@
const std::string dbus_owner_; // ModemManager.Modem
const std::string dbus_path_; // ModemManager.Modem
scoped_ptr<ModemProxyInterface> proxy_;
+ scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
ServiceRefPtr service_;
bool service_registered_;
diff --git a/cellular_unittest.cc b/cellular_unittest.cc
index 73aa66b..acba7b0 100644
--- a/cellular_unittest.cc
+++ b/cellular_unittest.cc
@@ -7,10 +7,12 @@
#include <chromeos/dbus/service_constants.h>
#include "shill/mock_modem_proxy.h"
+#include "shill/mock_modem_simple_proxy.h"
#include "shill/property_store_unittest.h"
#include "shill/proxy_factory.h"
using std::string;
+using testing::Return;
namespace shill {
@@ -18,6 +20,7 @@
public:
CellularTest()
: proxy_(new MockModemProxy()),
+ simple_proxy_(new MockModemSimpleProxy()),
proxy_factory_(this),
device_(new Cellular(&control_interface_,
NULL,
@@ -48,6 +51,12 @@
return test_->proxy_.release();
}
+ virtual ModemSimpleProxyInterface *CreateModemSimpleProxy(
+ const string &path,
+ const string &service) {
+ return test_->simple_proxy_.release();
+ }
+
private:
CellularTest *test_;
};
@@ -56,6 +65,7 @@
static const char kDBusPath[];
scoped_ptr<MockModemProxy> proxy_;
+ scoped_ptr<MockModemSimpleProxy> simple_proxy_;
TestProxyFactory proxy_factory_;
CellularRefPtr device_;
@@ -134,6 +144,8 @@
TEST_F(CellularTest, Start) {
EXPECT_CALL(*proxy_, Enable(true)).Times(1);
+ EXPECT_CALL(*simple_proxy_, GetStatus())
+ .WillOnce(Return(DBusPropertiesMap()));
device_->Start();
EXPECT_EQ(Cellular::kStateEnabled, device_->state_);
}
diff --git a/mock_modem_simple_proxy.h b/mock_modem_simple_proxy.h
new file mode 100644
index 0000000..f0ba0a2
--- /dev/null
+++ b/mock_modem_simple_proxy.h
@@ -0,0 +1,21 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_MOCK_MODEM_SIMPLE_PROXY_H_
+#define SHILL_MOCK_MODEM_SIMPLE_PROXY_H_
+
+#include <gmock/gmock.h>
+
+#include "shill/modem_simple_proxy_interface.h"
+
+namespace shill {
+
+class MockModemSimpleProxy : public ModemSimpleProxyInterface {
+ public:
+ MOCK_METHOD0(GetStatus, DBusPropertiesMap());
+};
+
+} // namespace shill
+
+#endif // SHILL_MOCK_MODEM_SIMPLE_PROXY_H_
diff --git a/modem_simple_proxy.cc b/modem_simple_proxy.cc
new file mode 100644
index 0000000..a8b48b1
--- /dev/null
+++ b/modem_simple_proxy.cc
@@ -0,0 +1,29 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "shill/modem_simple_proxy.h"
+
+using std::string;
+
+namespace shill {
+
+ModemSimpleProxy::ModemSimpleProxy(DBus::Connection *connection,
+ const string &path,
+ const string &service)
+ : proxy_(connection, path, service) {}
+
+ModemSimpleProxy::~ModemSimpleProxy() {}
+
+DBusPropertiesMap ModemSimpleProxy::GetStatus() {
+ return proxy_.GetStatus();
+}
+
+ModemSimpleProxy::Proxy::Proxy(DBus::Connection *connection,
+ const string &path,
+ const string &service)
+ : DBus::ObjectProxy(*connection, path, service.c_str()) {}
+
+ModemSimpleProxy::Proxy::~Proxy() {}
+
+} // namespace shill
diff --git a/modem_simple_proxy.h b/modem_simple_proxy.h
new file mode 100644
index 0000000..91fccd2
--- /dev/null
+++ b/modem_simple_proxy.h
@@ -0,0 +1,46 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_MODEM_SIMPLE_PROXY_
+#define SHILL_MODEM_SIMPLE_PROXY_
+
+#include <base/basictypes.h>
+
+#include "shill/dbus_bindings/modem-simple.h"
+#include "shill/modem_simple_proxy_interface.h"
+
+namespace shill {
+
+// A proxy to ModemManager.Modem.Simple.
+class ModemSimpleProxy : public ModemSimpleProxyInterface {
+ public:
+ ModemSimpleProxy(DBus::Connection *connection,
+ const std::string &path,
+ const std::string &service);
+ virtual ~ModemSimpleProxy();
+
+ // Inherited from ModemSimpleProxyInterface.
+ virtual DBusPropertiesMap GetStatus();
+
+ private:
+ class Proxy : public org::freedesktop::ModemManager::Modem::Simple_proxy,
+ public DBus::ObjectProxy {
+ public:
+ Proxy(DBus::Connection *connection,
+ const std::string &path,
+ const std::string &service);
+ virtual ~Proxy();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Proxy);
+ };
+
+ Proxy proxy_;
+
+ DISALLOW_COPY_AND_ASSIGN(ModemSimpleProxy);
+};
+
+} // namespace shill
+
+#endif // SHILL_MODEM_SIMPLE_PROXY_
diff --git a/modem_simple_proxy_interface.h b/modem_simple_proxy_interface.h
new file mode 100644
index 0000000..9d0c248
--- /dev/null
+++ b/modem_simple_proxy_interface.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_MODEM_SIMPLE_PROXY_INTERFACE_
+#define SHILL_MODEM_SIMPLE_PROXY_INTERFACE_
+
+#include "shill/dbus_properties.h"
+
+namespace shill {
+
+// These are the methods that a ModemManager.Modem.Simple proxy must
+// support. The interface is provided so that it can be mocked in tests.
+class ModemSimpleProxyInterface {
+ public:
+ virtual ~ModemSimpleProxyInterface() {}
+
+ virtual DBusPropertiesMap GetStatus() = 0;
+};
+
+} // namespace shill
+
+#endif // SHILL_MODEM_SIMPLE_PROXY_INTERFACE_
diff --git a/proxy_factory.cc b/proxy_factory.cc
index f6637b1..389dde6 100644
--- a/proxy_factory.cc
+++ b/proxy_factory.cc
@@ -10,6 +10,7 @@
#include "shill/dhcpcd_proxy.h"
#include "shill/modem_manager_proxy.h"
#include "shill/modem_proxy.h"
+#include "shill/modem_simple_proxy.h"
#include "shill/supplicant_interface_proxy.h"
#include "shill/supplicant_process_proxy.h"
@@ -48,6 +49,12 @@
return new ModemProxy(connection(), path, service);
}
+ModemSimpleProxyInterface *ProxyFactory::CreateModemSimpleProxy(
+ const string &path,
+ const string &service) {
+ return new ModemSimpleProxy(connection(), path, service);
+}
+
SupplicantProcessProxyInterface *ProxyFactory::CreateSupplicantProcessProxy(
const char *dbus_path,
const char *dbus_addr) {
diff --git a/proxy_factory.h b/proxy_factory.h
index 804dc77..908b699 100644
--- a/proxy_factory.h
+++ b/proxy_factory.h
@@ -21,6 +21,7 @@
class ModemManager;
class ModemManagerProxyInterface;
class ModemProxyInterface;
+class ModemSimpleProxyInterface;
class SupplicantInterfaceProxyInterface;
class SupplicantProcessProxyInterface;
@@ -45,6 +46,10 @@
virtual ModemProxyInterface *CreateModemProxy(const std::string &path,
const std::string &service);
+ virtual ModemSimpleProxyInterface *CreateModemSimpleProxy(
+ const std::string &path,
+ const std::string &service);
+
virtual SupplicantProcessProxyInterface *CreateSupplicantProcessProxy(
const char *dbus_path,
const char *dbus_addr);