Codebase list fwupd / f8ef850
Add --version option to fwupdmgr $ fwupdmgr --version client version: 0.9.6 daemon version: 0.9.6 Fixes https://github.com/hughsie/fwupd/issues/153 Richard Hughes 6 years ago
3 changed file(s) with 75 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
3939 typedef struct {
4040 FwupdStatus status;
4141 guint percentage;
42 gchar *daemon_version;
4243 GDBusConnection *conn;
4344 GDBusProxy *proxy;
4445 } FwupdClientPrivate;
5657 PROP_0,
5758 PROP_STATUS,
5859 PROP_PERCENTAGE,
60 PROP_DAEMON_VERSION,
5961 PROP_LAST
6062 };
6163
9597 }
9698
9799 G_DEFINE_AUTOPTR_CLEANUP_FUNC(FwupdClientHelper, fwupd_client_helper_free)
100
101 static void
102 fwupd_client_set_daemon_version (FwupdClient *client, const gchar *daemon_version)
103 {
104 FwupdClientPrivate *priv = GET_PRIVATE (client);
105 g_free (priv->daemon_version);
106 priv->daemon_version = g_strdup (daemon_version);
107 g_object_notify (G_OBJECT (client), "daemon-version");
108 }
98109
99110 static void
100111 fwupd_client_properties_changed_cb (GDBusProxy *proxy,
126137 g_object_notify (G_OBJECT (client), "percentage");
127138 }
128139 }
140 if (g_variant_dict_contains (&dict, "DaemonVersion")) {
141 g_autoptr(GVariant) val = NULL;
142 val = g_dbus_proxy_get_cached_property (proxy, "DaemonVersion");
143 if (val != NULL)
144 fwupd_client_set_daemon_version (client, g_variant_get_string (val, NULL));
145 }
129146 }
130147
131148 static void
184201 fwupd_client_connect (FwupdClient *client, GCancellable *cancellable, GError **error)
185202 {
186203 FwupdClientPrivate *priv = GET_PRIVATE (client);
204 g_autoptr(GVariant) val = NULL;
187205
188206 g_return_val_if_fail (FWUPD_IS_CLIENT (client), FALSE);
189207 g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
211229 G_CALLBACK (fwupd_client_properties_changed_cb), client);
212230 g_signal_connect (priv->proxy, "g-signal",
213231 G_CALLBACK (fwupd_client_signal_cb), client);
232 val = g_dbus_proxy_get_cached_property (priv->proxy, "DaemonVersion");
233 if (val != NULL)
234 fwupd_client_set_daemon_version (client, g_variant_get_string (val, NULL));
214235 return TRUE;
215236 }
216237
919940 }
920941
921942 /**
943 * fwupd_client_get_daemon_version:
944 * @client: A #FwupdClient
945 *
946 * Gets the daemon version number.
947 *
948 * Returns: a string, or %NULL for unknown.
949 *
950 * Since: 0.9.6
951 **/
952 const gchar *
953 fwupd_client_get_daemon_version (FwupdClient *client)
954 {
955 FwupdClientPrivate *priv = GET_PRIVATE (client);
956 g_return_val_if_fail (FWUPD_IS_CLIENT (client), NULL);
957 return priv->daemon_version;
958 }
959
960 /**
922961 * fwupd_client_get_status:
923962 * @client: A #FwupdClient
924963 *
10471086 case PROP_PERCENTAGE:
10481087 g_value_set_uint (value, priv->percentage);
10491088 break;
1089 case PROP_DAEMON_VERSION:
1090 g_value_set_string (value, priv->daemon_version);
1091 break;
10501092 default:
10511093 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
10521094 break;
11891231 0, 100, 0,
11901232 G_PARAM_READWRITE);
11911233 g_object_class_install_property (object_class, PROP_PERCENTAGE, pspec);
1234
1235 /**
1236 * FwupdClient:daemon-version:
1237 *
1238 * The daemon version number.
1239 *
1240 * Since: 0.9.6
1241 */
1242 pspec = g_param_spec_string ("daemon-version", NULL, NULL,
1243 NULL, G_PARAM_READABLE);
1244 g_object_class_install_property (object_class, PROP_DAEMON_VERSION, pspec);
11921245 }
11931246
11941247 static void
12021255 FwupdClient *client = FWUPD_CLIENT (object);
12031256 FwupdClientPrivate *priv = GET_PRIVATE (client);
12041257
1258 g_free (priv->daemon_version);
12051259 if (priv->conn != NULL)
12061260 g_object_unref (priv->conn);
12071261 if (priv->proxy != NULL)
103103 GError **error);
104104 FwupdStatus fwupd_client_get_status (FwupdClient *client);
105105 guint fwupd_client_get_percentage (FwupdClient *client);
106 const gchar *fwupd_client_get_daemon_version (FwupdClient *client);
106107
107108 G_END_DECLS
108109
10571057 gboolean offline = FALSE;
10581058 gboolean ret;
10591059 gboolean verbose = FALSE;
1060 gboolean version = FALSE;
10601061 gint rc = 1;
10611062 g_autoptr(GError) error = NULL;
10621063 g_autofree gchar *cmd_descriptions = NULL;
10641065 { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
10651066 /* TRANSLATORS: command line option */
10661067 _("Show extra debugging information"), NULL },
1068 { "version", '\0', 0, G_OPTION_ARG_NONE, &version,
1069 /* TRANSLATORS: command line option */
1070 _("Show client and daemon versions"), NULL },
10671071 { "offline", '\0', 0, G_OPTION_ARG_NONE, &offline,
10681072 /* TRANSLATORS: command line option */
10691073 _("Schedule installation for next reboot when possible"), NULL },
12241228 g_signal_connect (priv->client, "notify::status",
12251229 G_CALLBACK (fu_util_client_notify_cb), priv);
12261230
1231 /* just show versions and exit */
1232 if (version) {
1233 g_print ("client version:\t%i.%i.%i\n",
1234 FWUPD_MAJOR_VERSION,
1235 FWUPD_MINOR_VERSION,
1236 FWUPD_MICRO_VERSION);
1237 if (!fwupd_client_connect (priv->client, priv->cancellable, &error)) {
1238 g_printerr ("Failed to connect to daemon: %s\n",
1239 error->message);
1240 return EXIT_FAILURE;
1241 }
1242 g_print ("daemon version:\t%s\n",
1243 fwupd_client_get_daemon_version (priv->client));
1244 return EXIT_SUCCESS;
1245 }
1246
12271247 /* run the specified command */
12281248 ret = fu_util_run (priv, argv[1], (gchar**) &argv[2], &error);
12291249 if (!ret) {