| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010, 2011 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SRC_DEVICE_H_ | 5 #ifndef SRC_DEVICE_H_ |
| 6 #define SRC_DEVICE_H_ | 6 #define SRC_DEVICE_H_ |
| 7 | 7 |
| 8 #include <glib.h> | |
| 9 | |
| 10 #include <string> | 8 #include <string> |
| 11 | 9 |
| 12 #include <base/basictypes.h> // NOLINT | 10 #include <base/basictypes.h> // NOLINT |
| 13 #include <dbus-c++/dbus.h> // NOLINT | 11 #include <dbus-c++/dbus.h> // NOLINT |
| 14 | 12 |
| 15 #include "src/byte_counter.h" | |
| 16 #include "src/flimflam_device_client_glue.h" | |
| 17 #include "src/property_changed_handler.h" | |
| 18 | |
| 19 namespace cashew { | 13 namespace cashew { |
| 20 | 14 |
| 21 class ByteCounter; | 15 class ByteCounter; |
| 22 class Service; | 16 class Service; |
| 23 | 17 |
| 18 // Device interface |
| 24 // represents a cellular device and monitors Flimflam state for that device | 19 // represents a cellular device and monitors Flimflam state for that device |
| 25 class Device : public org::chromium::flimflam::Device_proxy, | 20 class Device { |
| 26 public DBus::IntrospectableProxy, | |
| 27 public DBus::ObjectProxy, | |
| 28 public ByteCounterDelegate, | |
| 29 public PropertyChangedDelegate { | |
| 30 public: | 21 public: |
| 31 Device(Service * const parent, DBus::Connection& connection, // NOLINT | 22 Device() {} |
| 32 const DBus::Path& path); | 23 virtual ~Device() {} |
| 33 virtual ~Device(); | |
| 34 | 24 |
| 35 // get D-Bus path for this device | 25 // get D-Bus path for this device |
| 36 virtual const DBus::Path& GetPath() const; | 26 virtual const DBus::Path& GetPath() const = 0; |
| 37 | 27 |
| 38 // valid type values for this device | 28 // valid type values for this device |
| 39 typedef enum { | 29 typedef enum { |
| 40 kTypeUnknown = 0, | 30 kTypeUnknown = 0, |
| 41 kTypeEthernet, | 31 kTypeEthernet, |
| 42 kTypeWifi, | 32 kTypeWifi, |
| 43 kTypeWimax, | 33 kTypeWimax, |
| 44 kTypeBluetooth, | 34 kTypeBluetooth, |
| 45 kTypeGPS, | 35 kTypeGPS, |
| 46 kTypeCellular, | 36 kTypeCellular, |
| 47 kTypeVendor, | 37 kTypeVendor, |
| 48 } Type; | 38 } Type; |
| 49 | 39 |
| 50 // get type for this device | 40 // get type for this device |
| 51 // NOTE: for now, should always be kTypeCellular | 41 // NOTE: for now, should always be kTypeCellular |
| 52 virtual Type GetType() const; | 42 virtual Type GetType() const = 0; |
| 53 | 43 |
| 54 // get cellular carrier for this device | 44 // get cellular carrier for this device |
| 55 // returns empty string if we don't know | 45 // returns empty string if we don't know |
| 56 virtual const std::string& GetCarrier() const; | 46 virtual const std::string& GetCarrier() const = 0; |
| 57 | 47 |
| 58 // get interface name for this device (e.g., "usb0") | 48 // get interface name for this device (e.g., "usb0") |
| 59 // returns empty string if we don't know | 49 // returns empty string if we don't know |
| 60 virtual const std::string& GetInterface() const; | 50 virtual const std::string& GetInterface() const = 0; |
| 61 | |
| 62 // Flimflam Device D-Bus Proxy methods | |
| 63 | |
| 64 // receive incoming PropertyChanged D-Bus signal from Flimflam device and | |
| 65 // schedule deferred processing | |
| 66 virtual void PropertyChanged(const std::string& property_name, | |
| 67 const DBus::Variant& new_value); | |
| 68 | |
| 69 // PropertyChangedDelegate methods | |
| 70 | |
| 71 virtual void OnPropertyChanged(const PropertyChangedHandler *handler, | |
| 72 const std::string& property_name, | |
| 73 const DBus::Variant& new_value); | |
| 74 | 51 |
| 75 // Service methods | 52 // Service methods |
| 76 | 53 |
| 77 // start a new byte counter from 0 | 54 // start a new byte counter from 0 |
| 78 // there must not be an existing byte counter | 55 // there must not be an existing byte counter |
| 79 // |parent_| will receive periodic updates via Service::OnByteCounterUpdate | 56 // |parent_| will receive periodic updates via Service::OnByteCounterUpdate |
| 80 // returns true on success and false on failure | 57 // returns true on success and false on failure |
| 81 virtual bool StartByteCounter(); | 58 virtual bool StartByteCounter() = 0; |
| 82 | 59 |
| 83 // destroy any existing byte counter | 60 // destroy any existing byte counter |
| 84 // |parent_| will no longer receive updates after this call | 61 // |parent_| will no longer receive updates after this call |
| 85 virtual void StopByteCounter(); | 62 virtual void StopByteCounter() = 0; |
| 86 | 63 |
| 87 // is the byte counter running? | 64 // is the byte counter running? |
| 88 virtual bool ByteCounterRunning() const; | 65 virtual bool ByteCounterRunning() const = 0; |
| 89 | 66 |
| 90 // glib integration interface | 67 // factory |
| 91 | 68 static Device* NewDevice(Service * const parent, |
| 92 // get idle/timer source id | 69 DBus::Connection& connection, // NOLINT |
| 93 virtual guint GetGetPropertiesSourceId() const; | 70 const DBus::Path& path); |
| 94 | |
| 95 // set idle/timer source id | |
| 96 virtual void SetGetPropertiesSourceId(guint source_id); | |
| 97 | |
| 98 // are we in the process of retrying our GetProperties call? | |
| 99 virtual bool RetryingGetProperties() const; | |
| 100 | |
| 101 // set the retrying flag | |
| 102 virtual void OnRetryingGetProperties(bool retrying); | |
| 103 | |
| 104 // ByteCounterDelegate methods | |
| 105 | |
| 106 // called when bye counter is updated | |
| 107 virtual void OnByteCounterUpdate(const ByteCounter *counter, | |
| 108 uint64 rx_bytes, uint64 tx_bytes); | |
| 109 | 71 |
| 110 private: | 72 private: |
| 111 // back pointer to our parent Service | |
| 112 Service * const parent_; | |
| 113 | |
| 114 // D-Bus path for Flimflam device that we represent | |
| 115 // this is our unique identifier | |
| 116 const DBus::Path path_; | |
| 117 | |
| 118 // device type | |
| 119 Type type_; | |
| 120 | |
| 121 // cellular carrier | |
| 122 std::string carrier_; | |
| 123 | |
| 124 // interface name | |
| 125 std::string interface_; | |
| 126 | |
| 127 // GetProperties timer glib source id | |
| 128 // 0 means no source | |
| 129 guint get_properties_source_id_; | |
| 130 | |
| 131 // are we in the process of retrying our GetProperties call? | |
| 132 // this flag exists to distinguish between our initial g_idle_add call | |
| 133 // and our subsequent timer calls | |
| 134 bool retrying_get_properties_; | |
| 135 | |
| 136 // byte counter for this device | |
| 137 // can be NULL | |
| 138 ByteCounter *byte_counter_; | |
| 139 | |
| 140 // is the byte counter running? | |
| 141 // this is distinct from whether or not byte_counter_ == NULL, since the | |
| 142 // counter may be logically running but we may not yet know our interface | |
| 143 // name and therefore may not yet have created a byte counter object. | |
| 144 bool byte_counter_running_; | |
| 145 | |
| 146 // Handler for deferred processing of D-Bus PropertyChanged signals. | |
| 147 // See comments in service_manager.h | |
| 148 PropertyChangedHandler property_changed_handler_; | |
| 149 | |
| 150 // convert type string to Type enum value | |
| 151 Type TypeFromString(const std::string& type) const; | |
| 152 | |
| 153 // we've received updated Cellular.Carrier info from Flimflam | |
| 154 void OnCarrierUpdate(const std::string& carrier); | |
| 155 | |
| 156 // we've received updated Interface info from Flimflam | |
| 157 void OnInterfaceUpdate(const std::string& interface); | |
| 158 | |
| 159 // we've received updated Type info from Flimflam | |
| 160 void OnTypeUpdate(const std::string& type); | |
| 161 | |
| 162 // glib integration: static wrapper for GetDeviceProperties | |
| 163 // takes object ptr as data and invokes object->GetDeviceProperties | |
| 164 static gboolean StaticGetDevicePropertiesCallback(gpointer data); | |
| 165 | |
| 166 // get device properties from Flimflam | |
| 167 // returns true on success and false on failure | |
| 168 bool GetDeviceProperties(); | |
| 169 | |
| 170 // create a byte counter object and assign it to |byte_counter_| | |
| 171 bool CreateByteCounter(); | |
| 172 | |
| 173 // delete byte counter object pointed to by |byte_counter_| if any | |
| 174 void DeleteByteCounter(); | |
| 175 | |
| 176 DISALLOW_COPY_AND_ASSIGN(Device); | 73 DISALLOW_COPY_AND_ASSIGN(Device); |
| 177 }; | 74 }; |
| 178 | 75 |
| 179 } // namespace cashew | 76 } // namespace cashew |
| 180 | 77 |
| 181 #endif // SRC_DEVICE_H_ | 78 #endif // SRC_DEVICE_H_ |
| OLD | NEW |