Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 5 | #include "shill/dbus_control.h" |
| 6 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 7 | #include <string> |
| 8 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 9 | #include <dbus-c++/glib-integration.h> |
| 10 | #include <dbus-c++/util.h> |
| 11 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 12 | #include "shill/device_dbus_adaptor.h" |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 13 | #include "shill/ipconfig_dbus_adaptor.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 14 | #include "shill/logging.h" |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 15 | #include "shill/manager_dbus_adaptor.h" |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 16 | #include "shill/profile_dbus_adaptor.h" |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 17 | #include "shill/rpc_task_dbus_adaptor.h" |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 18 | #include "shill/service_dbus_adaptor.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 19 | |
| 20 | namespace shill { |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 21 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 22 | DBusControl::DBusControl() {} |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 23 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 24 | DBusControl::~DBusControl() {} |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 25 | |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 26 | DeviceAdaptorInterface *DBusControl::CreateDeviceAdaptor(Device *device) { |
Wade Guthrie | e2e2924 | 2012-05-08 08:58:56 -0700 | [diff] [blame] | 27 | DeviceAdaptorInterface *result = NULL; |
| 28 | try { |
| 29 | result = new DeviceDBusAdaptor(connection_.get(), device); |
| 30 | } catch(const DBus::Error &error) { |
| 31 | LOG(ERROR) << error.message(); |
| 32 | } |
| 33 | return result; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 36 | IPConfigAdaptorInterface *DBusControl::CreateIPConfigAdaptor(IPConfig *config) { |
Wade Guthrie | e2e2924 | 2012-05-08 08:58:56 -0700 | [diff] [blame] | 37 | IPConfigAdaptorInterface *result = NULL; |
| 38 | try { |
| 39 | result = new IPConfigDBusAdaptor(connection_.get(), config); |
| 40 | } catch(const DBus::Error &error) { |
| 41 | LOG(ERROR) << error.message(); |
| 42 | } |
| 43 | return result; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | ManagerAdaptorInterface *DBusControl::CreateManagerAdaptor(Manager *manager) { |
Wade Guthrie | e2e2924 | 2012-05-08 08:58:56 -0700 | [diff] [blame] | 47 | ManagerAdaptorInterface *result = NULL; |
| 48 | try { |
| 49 | result = new ManagerDBusAdaptor(connection_.get(), manager); |
| 50 | } catch(const DBus::Error &error) { |
| 51 | LOG(ERROR) << error.message(); |
| 52 | } |
| 53 | return result; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 56 | ProfileAdaptorInterface *DBusControl::CreateProfileAdaptor(Profile *profile) { |
Wade Guthrie | e2e2924 | 2012-05-08 08:58:56 -0700 | [diff] [blame] | 57 | ProfileAdaptorInterface *result = NULL; |
| 58 | try { |
| 59 | result = new ProfileDBusAdaptor(connection_.get(), profile); |
| 60 | } catch(const DBus::Error &error) { |
| 61 | LOG(ERROR) << error.message(); |
| 62 | } |
| 63 | return result; |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 66 | RPCTaskAdaptorInterface *DBusControl::CreateRPCTaskAdaptor(RPCTask *task) { |
Wade Guthrie | e2e2924 | 2012-05-08 08:58:56 -0700 | [diff] [blame] | 67 | RPCTaskAdaptorInterface *result = NULL; |
| 68 | try { |
| 69 | result = new RPCTaskDBusAdaptor(connection_.get(), task); |
| 70 | } catch(const DBus::Error &error) { |
| 71 | LOG(ERROR) << error.message(); |
| 72 | } |
| 73 | return result; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 76 | ServiceAdaptorInterface *DBusControl::CreateServiceAdaptor(Service *service) { |
Wade Guthrie | e2e2924 | 2012-05-08 08:58:56 -0700 | [diff] [blame] | 77 | ServiceAdaptorInterface *result = NULL; |
| 78 | try { |
| 79 | result = new ServiceDBusAdaptor(connection_.get(), service); |
| 80 | } catch(const DBus::Error &error) { |
| 81 | LOG(ERROR) << error.message(); |
| 82 | } |
| 83 | return result; |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 86 | void DBusControl::Init() { |
| 87 | CHECK(!connection_.get()); |
| 88 | dispatcher_.reset(new(std::nothrow) DBus::Glib::BusDispatcher()); |
| 89 | CHECK(dispatcher_.get()) << "Failed to create a dbus-dispatcher"; |
| 90 | DBus::default_dispatcher = dispatcher_.get(); |
| 91 | dispatcher_->attach(NULL); |
| 92 | connection_.reset(new DBus::Connection(DBus::Connection::SystemBus())); |
mukesh agrawal | d1511fe | 2012-03-14 17:12:27 -0700 | [diff] [blame] | 93 | connection_->request_name(SHILL_INTERFACE); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 94 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 95 | |
| 96 | } // namespace shill |