Hi Daniel,

> Instead of collecting statistics on interface
> name base and storing it local in counter.c, update
> the Service object.
> 
> counter.c maps interface names to Service objects.
> The assumption is made that there is a 1:1 mapping
> between Service objects and interface name.
> 
> A Counter object will only show Service object
> statistics for services in the ready state. There
> is no interface (yet) for retrieving information on
> Service objects in idle/failure/configuration/.. state.
> ---
>  src/connman.h     |    9 ++++-
>  src/counter.c     |   87 
> +++++++++++++++++++++++++++--------------------------
>  src/ipconfig.c    |    2 +-
>  src/service.c     |    4 ++
>  test/test-counter |    2 +-
>  5 files changed, 57 insertions(+), 47 deletions(-)
> 
> diff --git a/src/connman.h b/src/connman.h
> index c30dccd..f2775f3 100644
> --- a/src/connman.h
> +++ b/src/connman.h
> @@ -66,17 +66,22 @@ void __connman_agent_cleanup(void);
>  int __connman_agent_register(const char *sender, const char *path);
>  int __connman_agent_unregister(const char *sender, const char *path);
>  
> +struct connman_service;
> +struct connman_ipconfig;
> +
>  int __connman_counter_register(const char *owner, const char *path,
>                                               unsigned int interval);
>  int __connman_counter_unregister(const char *owner, const char *path);
>  
> -void __connman_counter_notify(const char *interface,
> +void __connman_counter_notify(struct connman_ipconfig *config,
>                               unsigned int rx_bytes, unsigned int tx_bytes);
>  
> +int __connman_counter_add_service(struct connman_service *service);
> +void __connman_counter_remove_service(struct connman_service *service);
> +
>  int __connman_counter_init(void);
>  void __connman_counter_cleanup(void);
>  
> -struct connman_service;
>  
>  typedef void (* passphrase_cb_t) (struct connman_service *service,
>                               const char *passphrase, void *user_data);
> diff --git a/src/counter.c b/src/counter.c
> index bf9da90..df98ca1 100644
> --- a/src/counter.c
> +++ b/src/counter.c
> @@ -33,12 +33,6 @@ static GHashTable *stats_table;
>  static GHashTable *counter_table;
>  static GHashTable *owner_mapping;
>  
> -struct connman_stats {
> -     char *interface;
> -     unsigned int rx_bytes;
> -     unsigned int tx_bytes;
> -};
> -
>  struct connman_counter {
>       char *owner;
>       char *path;
> @@ -46,14 +40,6 @@ struct connman_counter {
>       guint watch;
>  };
>  
> -static void remove_stats(gpointer user_data)
> -{
> -     struct connman_stats *stats = user_data;
> -
> -     g_free(stats->interface);
> -     g_free(stats);
> -}
> -
>  static void remove_counter(gpointer user_data)
>  {
>       struct connman_counter *counter = user_data;
> @@ -130,10 +116,14 @@ int __connman_counter_unregister(const char *owner, 
> const char *path)
>  }
>  
>  static void send_usage(struct connman_counter *counter,
> -                                     struct connman_stats *stats)
> +                             struct connman_service *service)
>  {
>       DBusMessage *message;
>       DBusMessageIter array, dict;
> +     const char *service_path;
> +     unsigned long rx_bytes;
> +     unsigned long tx_bytes;
> +     unsigned long time;
>  
>       message = dbus_message_new_method_call(counter->owner, counter->path,
>                                       CONNMAN_COUNTER_INTERFACE, "Usage");
> @@ -146,50 +136,43 @@ static void send_usage(struct connman_counter *counter,
>  
>       connman_dbus_dict_open(&array, &dict);
>  
> -     connman_dbus_dict_append_basic(&dict, "Interface",
> -                                     DBUS_TYPE_STRING, &stats->interface);
> -     connman_dbus_dict_append_basic(&dict, "RX.Bytes",
> -                                     DBUS_TYPE_UINT32, &stats->rx_bytes);
> -     connman_dbus_dict_append_basic(&dict, "TX.Bytes",
> -                                     DBUS_TYPE_UINT32, &stats->tx_bytes);
> +     service_path = __connman_service_get_path(service);
> +     rx_bytes = __connman_service_stats_get_rx_bytes(service);
> +     tx_bytes = __connman_service_stats_get_tx_bytes(service);
> +     time = __connman_service_stats_get_time(service);
> +
> +     connman_dbus_dict_append_basic(&dict, "Path", DBUS_TYPE_OBJECT_PATH,
> +                             &service_path);
> +     connman_dbus_dict_append_basic(&dict, "RX.Bytes", DBUS_TYPE_UINT32,
> +                             &rx_bytes);
> +     connman_dbus_dict_append_basic(&dict, "TX.Bytes", DBUS_TYPE_UINT32,
> +                             &tx_bytes);
> +     connman_dbus_dict_append_basic(&dict, "Time", DBUS_TYPE_UINT32,
> +                             &time);
>  
>       connman_dbus_dict_close(&array, &dict);
>  
>       g_dbus_send_message(connection, message);
>  }

For this we need some extra documentation on how the API is suppose to
behave. For example having someting Usage(object service, dict stats)
sounds also reasonable. We do wanna give the service object to the user
as well.

> diff --git a/test/test-counter b/test/test-counter
> index 70a3027..45c8a39 100755
> --- a/test/test-counter
> +++ b/test/test-counter
> @@ -18,7 +18,7 @@ class Counter(dbus.service.Object):
>                                       in_signature='a{sv}', out_signature='')
>       def Usage(self, stats):
>               for key in stats.keys():
> -                     if key in ["Interface"]:
> +                     if key in ["Path"]:
>                               val = str(stats[key])
>                       else:
>                               val = int(stats[key])

You could do key in ["Interface", "Path"]: actually. However I am more
thinking that the object path should be a separate parameter and not
part of the dict itself. You might wanna filter on that one.

Regards

Marcel


_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to