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