Docs: Big entity cleanup
[platform/upstream/glib.git] / gio / gdbusproxy.c
index 5bab9bf..5df0388 100644 (file)
@@ -13,9 +13,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  * Author: David Zeuthen <davidz@redhat.com>
  */
@@ -187,10 +185,10 @@ static void initable_iface_init       (GInitableIface *initable_iface);
 static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface);
 
 G_DEFINE_TYPE_WITH_CODE (GDBusProxy, g_dbus_proxy, G_TYPE_OBJECT,
+                         G_ADD_PRIVATE (GDBusProxy)
                          G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_INTERFACE, dbus_interface_iface_init)
                          G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)
-                         G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init)
-                         );
+                         G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init))
 
 static void
 g_dbus_proxy_dispose (GObject *object)
@@ -363,27 +361,22 @@ g_dbus_proxy_class_init (GDBusProxyClass *klass)
    * Ensure that interactions with this proxy conform to the given
    * interface. This is mainly to ensure that malformed data received
    * from the other peer is ignored. The given #GDBusInterfaceInfo is
-   * said to be the <emphasis>expected interface</emphasis>.
+   * said to be the "expected interface".
    *
    * The checks performed are:
-   * <itemizedlist>
-   *   <listitem><para>
-   *     When completing a method call, if the type signature of
-   *     the reply message isn't what's expected, the reply is
-   *     discarded and the #GError is set to %G_IO_ERROR_INVALID_ARGUMENT.
-   *   </para></listitem>
-   *   <listitem><para>
-   *     Received signals that have a type signature mismatch are dropped and
-   *     a warning is logged via g_warning().
-   *   </para></listitem>
-   *   <listitem><para>
-   *     Properties received via the initial <literal>GetAll()</literal> call
-   *     or via the <literal>::PropertiesChanged</literal> signal (on the
-   *     <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties">org.freedesktop.DBus.Properties</ulink> interface) or
-   *     set using g_dbus_proxy_set_cached_property() with a type signature
-   *     mismatch are ignored and a warning is logged via g_warning().
-   *   </para></listitem>
-   * </itemizedlist>
+   * - When completing a method call, if the type signature of
+   *   the reply message isn't what's expected, the reply is
+   *   discarded and the #GError is set to %G_IO_ERROR_INVALID_ARGUMENT.
+   *
+   * - Received signals that have a type signature mismatch are dropped and
+   *   a warning is logged via g_warning().
+   *
+   * - Properties received via the initial <literal>GetAll()</literal> call
+   *   or via the <literal>::PropertiesChanged</literal> signal (on the
+   *   <ulink url="http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties">org.freedesktop.DBus.Properties</ulink> interface) or
+   *   set using g_dbus_proxy_set_cached_property() with a type signature
+   *   mismatch are ignored and a warning is logged via g_warning().
+   *
    * Note that these checks are never done on methods, signals and
    * properties that are not referenced in the given
    * #GDBusInterfaceInfo, since extending a D-Bus interface on the
@@ -633,14 +626,12 @@ g_dbus_proxy_class_init (GDBusProxyClass *klass)
                                          G_TYPE_STRING,
                                          G_TYPE_VARIANT);
 
-
-  g_type_class_add_private (klass, sizeof (GDBusProxyPrivate));
 }
 
 static void
 g_dbus_proxy_init (GDBusProxy *proxy)
 {
-  proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, G_TYPE_DBUS_PROXY, GDBusProxyPrivate);
+  proxy->priv = g_dbus_proxy_get_instance_private (proxy);
   proxy->priv->signal_subscription_data = g_slice_new0 (SignalSubscriptionData);
   proxy->priv->signal_subscription_data->ref_count = 1;
   proxy->priv->signal_subscription_data->proxy = proxy;
@@ -1001,7 +992,7 @@ invalidated_property_get_cb (GDBusConnection *connection,
 
   if (!g_variant_is_of_type (value, G_VARIANT_TYPE ("(v)")))
     {
-      g_warning ("Expected type `(v)' for Get() reply, got `%s'", g_variant_get_type_string (value));
+      g_warning ("Expected type '(v)' for Get() reply, got '%s'", g_variant_get_type_string (value));
       goto out;
     }
 
@@ -1081,7 +1072,7 @@ on_properties_changed (GDBusConnection *connection,
 
   if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa{sv}as)")))
     {
-      g_warning ("Value for PropertiesChanged signal with type `%s' does not match `(sa{sv}as)'",
+      g_warning ("Value for PropertiesChanged signal with type '%s' does not match '(sa{sv}as)'",
                  g_variant_get_type_string (parameters));
       G_UNLOCK (properties_lock);
       goto out;
@@ -1173,7 +1164,7 @@ process_get_all_reply (GDBusProxy *proxy,
 
   if (!g_variant_is_of_type (result, G_VARIANT_TYPE ("(a{sv})")))
     {
-      g_warning ("Value for GetAll reply with type `%s' does not match `(a{sv})'",
+      g_warning ("Value for GetAll reply with type '%s' does not match '(a{sv})'",
                  g_variant_get_type_string (result));
       goto out;
     }
@@ -1609,21 +1600,39 @@ async_init_start_service_by_name_cb (GDBusConnection *connection,
        *   org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Epiphany2
        *   was not provided by any .service files
        *
+       * or (see #677718)
+       *
+       *   org.freedesktop.systemd1.Masked: Unit polkit.service is masked.
+       *
        * This doesn't mean that the name doesn't have an owner, just
-       * that it's not provided by a .service file. So just proceed to
-       * invoke GetNameOwner() if dealing with that error.
+       * that it's not provided by a .service file or can't currently
+       * be started.
+       *
+       * In particular, in both cases, it could be that a service
+       * owner will actually appear later. So instead of erroring out,
+       * we just proceed to invoke GetNameOwner() if dealing with the
+       * kind of errors above.
        */
-      if (error->domain == G_DBUS_ERROR &&
-          error->code == G_DBUS_ERROR_SERVICE_UNKNOWN)
+      if (error->domain == G_DBUS_ERROR && error->code == G_DBUS_ERROR_SERVICE_UNKNOWN)
         {
           g_error_free (error);
         }
       else
         {
-          g_prefix_error (&error,
-                          _("Error calling StartServiceByName for %s: "),
-                          data->proxy->priv->name);
-          goto failed;
+          gchar *remote_error = g_dbus_error_get_remote_error (error);
+          if (g_strcmp0 (remote_error, "org.freedesktop.systemd1.Masked") == 0)
+            {
+              g_error_free (error);
+              g_free (remote_error);
+            }
+          else
+            {
+              g_prefix_error (&error,
+                              _("Error calling StartServiceByName for %s: "),
+                              data->proxy->priv->name);
+              g_free (remote_error);
+              goto failed;
+            }
         }
     }
   else
@@ -1709,7 +1718,8 @@ async_initable_init_second_async (GAsyncInitable      *initable,
     }
   else
     {
-      if (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
+      if ((proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START) ||
+          (proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION))
         {
           async_init_call_get_name_owner (data);
         }
@@ -2023,9 +2033,9 @@ initable_iface_init (GInitableIface *initable_iface)
  * to handle signals from the remote object.
  *
  * If @name is a well-known name and the
- * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag isn't set and no name
- * owner currently exists, the message bus will be requested to launch
- * a name owner for the name.
+ * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START and %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION
+ * flags aren't set and no name owner currently exists, the message bus
+ * will be requested to launch a name owner for the name.
  *
  * This is a failable asynchronous constructor - when the proxy is
  * ready, @callback will be invoked and you can use
@@ -2120,9 +2130,9 @@ g_dbus_proxy_new_finish (GAsyncResult  *res,
  * to handle signals from the remote object.
  *
  * If @name is a well-known name and the
- * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag isn't set and no name
- * owner currently exists, the message bus will be requested to launch
- * a name owner for the name.
+ * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START and %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION
+ * flags aren't set and no name owner currently exists, the message bus
+ * will be requested to launch a name owner for the name.
  *
  * This is a synchronous failable constructor. See g_dbus_proxy_new()
  * and g_dbus_proxy_new_finish() for the asynchronous version.
@@ -2966,7 +2976,7 @@ g_dbus_proxy_call_sync_internal (GDBusProxy      *proxy,
  *                     -1,
  *                     NULL,
  *                     (GAsyncReadyCallback) two_strings_done,
- *                     &amp;data);
+ *                     &data);
  * ]|
  *
  * If @proxy has an expected interface (see
@@ -3056,7 +3066,7 @@ g_dbus_proxy_call_finish (GDBusProxy    *proxy,
  *                          G_DBUS_CALL_FLAGS_NONE,
  *                          -1,
  *                          NULL,
- *                          &amp;error);
+ *                          &error);
  * ]|
  *
  * The calling thread is blocked until a reply is received. See