]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
dbus: Replace StateChanged with PropertiesChanged signal
authorMarcel Holtmann <marcel@holtmann.org>
Mon, 4 Jan 2010 14:33:44 +0000 (16:33 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 4 Jan 2010 14:33:44 +0000 (16:33 +0200)
The actual supplicant state is exposed via a property on the interface
object. So having a separate signal StateChanged for notifying about
changes is a bad idea. The standard PropertiesChanged signal should be
used for this.

The advantage of StateChanged signal was that it includes the previous
state, but not even NetworkManager is making use of this. And tracking
the old state via the property and this signal is easily possible anyway.

doc/dbus.doxygen
wpa_supplicant/dbus/dbus_new.c
wpa_supplicant/dbus/dbus_new.h
wpa_supplicant/notify.c
wpa_supplicant/wpa_supplicant.c

index 9deb28df90c5667e05428f1a39aba3325c6a33a5..9b7dff2180a6e5e2990b05d9d9ada1ea265dd33e 100644 (file)
@@ -405,18 +405,6 @@ fi.w1.wpa_supplicant1.CreateInterface.
        </dl>
       </li>
 
-      <li>
-       <h3>StateChanged ( s : newState, s : oldState )</h3>
-       <p>Interface state has changed.</p>
-       <h4>Arguments</h4>
-       <dl>
-         <dt>s : newState</dt>
-         <dd>A state which the interface goes to</dd>
-         <dt>s : oldState</dt>
-         <dd>A state which the interface goes from</dd>
-       </dl>
-      </li>
-
       <li>
        <h3>BSSAdded ( o : BSS, a{sv} : properties )</h3>
        <p>Interface became aware of a new BSS.</p>
@@ -501,7 +489,7 @@ fi.w1.wpa_supplicant1.CreateInterface.
        <h4>Arguments</h4>
        <dl>
          <dt>a{sv} : properties</dt>
-         <dd>A dictionary with pairs of properties names which have changed and theirs new values. Possible dictionary keys are: "ApScan", "Scanning", "CurrentBSS", "CurrentNetwork"</dd>
+         <dd>A dictionary with pairs of properties names which have changed and theirs new values. Possible dictionary keys are: "ApScan", "Scanning", "State", "CurrentBSS", "CurrentNetwork"</dd>
        </dl>
       </li>
     </ul>
index 1633b96494c9415fd5e79ada61e23e548179763f..ce63325601817ab6408927f85b6e0bf9bb180e57 100644 (file)
@@ -393,75 +393,6 @@ void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
 }
 
 
-static void str_to_lower(char *s)
-{
-       while (*s) {
-               *s = tolower(*s);
-               s++;
-       }
-}
-
-
-/**
- * wpas_dbus_signal_state_changed - Send a state changed signal
- * @wpa_s: %wpa_supplicant network interface data
- * @new_state: new state wpa_supplicant is entering
- * @old_state: old state wpa_supplicant is leaving
- *
- * Notify listeners that wpa_supplicant has changed state
- */
-void wpas_dbus_signal_state_changed(struct wpa_supplicant *wpa_s,
-                                   enum wpa_states new_state,
-                                   enum wpa_states old_state)
-{
-       struct wpas_dbus_priv *iface;
-       DBusMessage *msg;
-       char *new_state_str, *old_state_str;
-
-       /* Do nothing if the control interface is not turned on */
-       if (wpa_s->global == NULL)
-               return;
-       iface = wpa_s->global->dbus;
-       if (iface == NULL)
-               return;
-
-       /* Only send signal if state really changed */
-       if (new_state == old_state)
-               return;
-
-       msg = dbus_message_new_signal(wpa_s->dbus_new_path,
-                                     WPAS_DBUS_NEW_IFACE_INTERFACE,
-                                     "StateChanged");
-       if (msg == NULL)
-               return;
-
-       new_state_str = os_strdup(wpa_supplicant_state_txt(new_state));
-       old_state_str = os_strdup(wpa_supplicant_state_txt(old_state));
-       if (new_state_str == NULL || old_state_str == NULL)
-               goto out;
-
-       /* make state string lowercase to fit new DBus API convention */
-       str_to_lower(new_state_str);
-       str_to_lower(old_state_str);
-
-       if (!dbus_message_append_args(msg,
-                                     DBUS_TYPE_STRING, &new_state_str,
-                                     DBUS_TYPE_STRING, &old_state_str,
-                                     DBUS_TYPE_INVALID)) {
-               wpa_printf(MSG_ERROR, "dbus: Failed to construct state change "
-                          "signal");
-               goto out;
-       }
-
-       dbus_connection_send(iface->con, msg, NULL);
-
-out:
-       dbus_message_unref(msg);
-       os_free(new_state_str);
-       os_free(old_state_str);
-}
-
-
 /**
  * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
  * @wpa_s: %wpa_supplicant network interface data
@@ -747,6 +678,10 @@ void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
                getter = (WPADBusPropertyAccessor) wpas_dbus_getter_scanning;
                prop = "Scanning";
                break;
+       case WPAS_DBUS_PROP_STATE:
+               getter = (WPADBusPropertyAccessor) wpas_dbus_getter_state;
+               prop = "State";
+               break;
        case WPAS_DBUS_PROP_CURRENT_BSS:
                getter = (WPADBusPropertyAccessor)
                        wpas_dbus_getter_current_bss;
@@ -1419,13 +1354,6 @@ static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
                  END_ARGS
          }
        },
-       { "StateChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
-         {
-                 { "newState", "s", ARG_OUT },
-                 { "oldState", "s", ARG_OUT },
-                 END_ARGS
-         }
-       },
        { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
          {
                  { "path", "o", ARG_OUT },
index 896e8f05d7e0382b67111bf5cad447762478b198..e20ab7654e7337d41d9936218b1900cbcf92db75 100644 (file)
@@ -27,6 +27,7 @@ enum wpa_states;
 enum wpas_dbus_prop {
        WPAS_DBUS_PROP_AP_SCAN,
        WPAS_DBUS_PROP_SCANNING,
+       WPAS_DBUS_PROP_STATE,
        WPAS_DBUS_PROP_CURRENT_BSS,
        WPAS_DBUS_PROP_CURRENT_NETWORK,
 };
@@ -77,9 +78,6 @@ void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface);
 
 int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s);
 int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s);
-void wpas_dbus_signal_state_changed(struct wpa_supplicant *wpa_s,
-                                   enum wpa_states new_state,
-                                   enum wpa_states old_state);
 void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
                                   enum wpas_dbus_prop property);
 void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
index 5e6aa19b3106c786f1d560a1e855db311042bce2..970ba9b4f455b254a7b017191460a20c6b3cfb8c 100644 (file)
@@ -78,7 +78,7 @@ void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
                                                old_state);
 
        /* notify the new DBus API */
-       wpas_dbus_signal_state_changed(wpa_s, new_state, old_state);
+       wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_STATE);
 }
 
 
@@ -118,6 +118,7 @@ void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
 {
        /* notify the old DBus API */
        wpa_supplicant_dbus_notify_scanning(wpa_s);
+
        /* notify the new DBus API */
        wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING);
 }
index dff8a10b012efce6d45790e1fdf7a563dea1b1fa..ee7acdd4bcbabe93ed71c80e9c26dcb5f7f932b8 100644 (file)
@@ -520,6 +520,8 @@ const char * wpa_supplicant_state_txt(enum wpa_states state)
 void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s,
                              enum wpa_states state)
 {
+       enum wpa_states old_state = wpa_s->wpa_state;
+
        wpa_printf(MSG_DEBUG, "State: %s -> %s",
                   wpa_supplicant_state_txt(wpa_s->wpa_state),
                   wpa_supplicant_state_txt(state));
@@ -527,8 +529,6 @@ void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s,
        if (state != WPA_SCANNING)
                wpa_supplicant_notify_scanning(wpa_s, 0);
 
-       wpas_notify_state_changed(wpa_s, state, wpa_s->wpa_state);
-
        if (state == WPA_COMPLETED && wpa_s->new_connection) {
 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
                struct wpa_ssid *ssid = wpa_s->current_ssid;
@@ -548,6 +548,9 @@ void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s,
                wpa_drv_set_operstate(wpa_s, 0);
        }
        wpa_s->wpa_state = state;
+
+       if (wpa_s->wpa_state != old_state)
+               wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
 }
 
 
@@ -583,12 +586,15 @@ static void wpa_supplicant_terminate(int sig, void *signal_ctx)
 static void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s)
 {
        enum wpa_states old_state = wpa_s->wpa_state;
+
        wpa_s->pairwise_cipher = 0;
        wpa_s->group_cipher = 0;
        wpa_s->mgmt_group_cipher = 0;
        wpa_s->key_mgmt = 0;
        wpa_s->wpa_state = WPA_DISCONNECTED;
-       wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
+
+       if (wpa_s->wpa_state != old_state)
+               wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
 }