VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/VBoxClient/hostversion.cpp@ 50667

Last change on this file since 50667 was 44529, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/** @file
2 * X11 guest client - host version check.
3 */
4
5/*
6 * Copyright (C) 2011-2012 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16#include <stdio.h>
17#include <iprt/assert.h>
18#include <iprt/err.h>
19#include <iprt/ldr.h>
20#include <iprt/string.h>
21#include <iprt/thread.h>
22
23#ifdef VBOX_WITH_DBUS
24# include <VBox/dbus.h>
25#endif
26#include <VBox/log.h>
27#include <VBox/VBoxGuestLib.h>
28#ifdef VBOX_OSE
29# include <VBox/version.h>
30#endif
31
32#include "VBoxClient.h"
33
34class HostVersionService : public VBoxClient::Service
35{
36
37public:
38
39 virtual const char *getPidFilePath()
40 {
41 return ".vboxclient-hostversion.pid";
42 }
43
44 virtual int showNotify(const char *pcHeader, const char *pcBody)
45 {
46 int rc;
47# ifdef VBOX_WITH_DBUS
48 DBusConnection *conn;
49 DBusMessage* msg = NULL;
50 conn = dbus_bus_get (DBUS_BUS_SESSON, NULL);
51 if (conn == NULL)
52 {
53 LogRelFlowFunc(("Could not retrieve D-BUS session bus!\n"));
54 rc = VERR_INVALID_HANDLE;
55 }
56 else
57 {
58 msg = dbus_message_new_method_call("org.freedesktop.Notifications",
59 "/org/freedesktop/Notifications",
60 "org.freedesktop.Notifications",
61 "Notify");
62 if (msg == NULL)
63 {
64 LogRel(("Could not create D-BUS message!\n"));
65 rc = VERR_INVALID_HANDLE;
66 }
67 else
68 rc = VINF_SUCCESS;
69 }
70 if (RT_SUCCESS(rc))
71 {
72 uint32_t msg_replace_id = 0;
73 const char *msg_app = "VBoxClient";
74 const char *msg_icon = "";
75 const char *msg_summary = pcHeader;
76 const char *msg_body = pcBody;
77 int32_t msg_timeout = -1; /* Let the notification server decide */
78
79 DBusMessageIter iter;
80 DBusMessageIter array;
81 DBusMessageIter dict;
82 DBusMessageIter value;
83 DBusMessageIter variant;
84 DBusMessageIter data;
85
86 /* Format: UINT32 org.freedesktop.Notifications.Notify
87 * (STRING app_name, UINT32 replaces_id, STRING app_icon, STRING summary, STRING body,
88 * ARRAY actions, DICT hints, INT32 expire_timeout)
89 */
90 dbus_message_iter_init_append(msg,&iter);
91 dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_app);
92 dbus_message_iter_append_basic(&iter,DBUS_TYPE_UINT32,&msg_replace_id);
93 dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_icon);
94 dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_summary);
95 dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_body);
96 dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,DBUS_TYPE_STRING_AS_STRING,&array);
97 dbus_message_iter_close_container(&iter,&array);
98 dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,"{sv}",&array);
99 dbus_message_iter_close_container(&iter,&array);
100 dbus_message_iter_append_basic(&iter,DBUS_TYPE_INT32,&msg_timeout);
101
102 DBusError err;
103 dbus_error_init(&err);
104
105 DBusMessage *reply;
106 reply = dbus_connection_send_with_reply_and_block(conn, msg,
107 30 * 1000 /* 30 seconds timeout */, &err);
108 if (dbus_error_is_set(&err))
109 {
110 LogRel(("D-BUS returned an error while sending the notification: %s", err.message));
111 }
112 else if (reply)
113 {
114 dbus_connection_flush(conn);
115 dbus_message_unref(reply);
116 }
117 if (dbus_error_is_set(&err))
118 dbus_error_free(&err);
119 }
120 if (msg != NULL)
121 dbus_message_unref(msg);
122# else
123 /* TODO: Implement me */
124 rc = VINF_SUCCESS;
125# endif /* VBOX_WITH_DBUS */
126 return rc;
127 }
128
129 /** @todo Move this part in VbglR3 and just provide a callback for the platform-specific
130 notification stuff, since this is very similar to the VBoxTray code. */
131 virtual int run(bool fDaemonised /* = false */)
132 {
133 int rc;
134 LogFlowFunc(("\n"));
135
136 /* Because we need desktop notifications to be displayed, wait
137 * some time to make the desktop environment load (as a work around). */
138 if (fDaemonised)
139 RTThreadSleep(30 * 1000 /* Wait 30 seconds */);
140
141# ifdef VBOX_WITH_DBUS
142 rc = RTDBusLoadLib();
143 if (RT_FAILURE(rc))
144 LogRel(("VBoxClient: D-Bus seems not to be installed; no host version check/notification done.\n"));
145# else
146 rc = VERR_NOT_IMPLEMENTED;
147# endif /* VBOX_WITH_DBUS */
148
149# ifdef VBOX_WITH_GUEST_PROPS
150 uint32_t uGuestPropSvcClientID;
151 if (RT_SUCCESS(rc))
152 {
153 rc = VbglR3GuestPropConnect(&uGuestPropSvcClientID);
154 if (RT_FAILURE(rc))
155 LogRel(("VBoxClient: Cannot connect to guest property service while chcking for host version! rc = %Rrc\n", rc));
156 }
157
158 if (RT_SUCCESS(rc))
159 {
160 char *pszHostVersion;
161 char *pszGuestVersion;
162 bool bUpdate;
163
164 rc = VbglR3HostVersionCheckForUpdate(uGuestPropSvcClientID, &bUpdate, &pszHostVersion, &pszGuestVersion);
165 if (RT_SUCCESS(rc))
166 {
167 if (bUpdate)
168 {
169 char szMsg[1024];
170 char szTitle[64];
171
172 /** @todo add some translation macros here */
173 RTStrPrintf(szTitle, sizeof(szTitle), "VirtualBox Guest Additions update available!");
174#ifndef VBOX_OSE
175 RTStrPrintf(szMsg, sizeof(szMsg), "Your guest is currently running the Guest Additions version %s. "
176 "We recommend updating to the latest version (%s) by choosing the "
177 "install option from the Devices menu.", pszGuestVersion, pszHostVersion);
178#else
179/* This is the message which appears for non-Oracle builds of the
180 * Guest Additions. Distributors are encouraged to customise this. */
181 RTStrPrintf(szMsg, sizeof(szMsg), "Your virtual machine is currently running the Guest Additions version %s. Since you are running a version of the Guest Additions provided by the operating system you installed in the virtual machine we recommend that you update it to at least version %s using that system's update features, or alternatively that you remove this version and then install the " VBOX_VENDOR_SHORT " Guest Additions package using the install option from the Devices menu. Please consult the documentation for the operating system you are running to find out how to update or remove the current Guest Additions package.", pszGuestVersion, pszHostVersion);
182#endif
183 rc = showNotify(szTitle, szMsg);
184 LogRel(("VBoxClient: VirtualBox Guest Additions update available!"));
185 if (RT_FAILURE(rc))
186 LogRel(("VBoxClient: Could not show version notifier tooltip! rc = %d\n", rc));
187 }
188
189 /* Store host version to not notify again */
190 rc = VbglR3HostVersionLastCheckedStore(uGuestPropSvcClientID, pszHostVersion);
191
192 VbglR3GuestPropReadValueFree(pszHostVersion);
193 VbglR3GuestPropReadValueFree(pszGuestVersion);
194 }
195 VbglR3GuestPropDisconnect(uGuestPropSvcClientID);
196 }
197# endif /* VBOX_WITH_GUEST_PROPS */
198 LogFlowFunc(("returning %Rrc\n", rc));
199 return rc;
200 }
201
202 virtual void cleanup()
203 {
204
205 }
206};
207
208/* Static factory */
209VBoxClient::Service *VBoxClient::GetHostVersionService()
210{
211 return new HostVersionService;
212}
213
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette