VirtualBox

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

Last change on this file since 25988 was 24607, checked in by vboxsync, 15 years ago

VBoxClient: Make update notifications work under OpenSolaris.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1/** @file
2 * X11 guest client - host version check.
3 */
4
5/*
6 * Copyright (C) 2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
17 * Clara, CA 95054 USA or visit http://www.sun.com if you need
18 * additional information or have any questions.
19 */
20#include <stdio.h>
21#include <iprt/assert.h>
22#include <iprt/err.h>
23#include <iprt/ldr.h>
24#include <iprt/string.h>
25#include <iprt/thread.h>
26
27#ifdef VBOX_WITH_DBUS
28 #include <VBox/dbus.h>
29#endif
30#include <VBox/log.h>
31#include <VBox/VBoxGuestLib.h>
32
33#include "VBoxClient.h"
34
35class HostVersionService : public VBoxClient::Service
36{
37
38public:
39
40 virtual const char *getPidFilePath()
41 {
42 return ".vboxclient-hostversion.pid";
43 }
44
45 virtual int showNotify(const char *pcHeader, const char *pcBody)
46 {
47 int rc;
48# ifdef VBOX_WITH_DBUS
49 DBusConnection *conn;
50 DBusMessage* msg;
51 conn = dbus_bus_get (DBUS_BUS_SESSON, NULL);
52 if (conn == NULL)
53 {
54 LogFlow(("Could not retrieve D-BUS session bus!\n"));
55 rc = VERR_INVALID_HANDLE;
56 }
57 else
58 {
59 msg = dbus_message_new_method_call("org.freedesktop.Notifications",
60 "/org/freedesktop/Notifications",
61 "org.freedesktop.Notifications",
62 "Notify");
63 if (msg == NULL)
64 {
65 Log(("Could not create D-BUS message!\n"));
66 rc = VERR_INVALID_HANDLE;
67 }
68 else
69 rc = VINF_SUCCESS;
70 }
71 if (RT_SUCCESS(rc))
72 {
73 uint32_t msg_replace_id = 0;
74 const char *msg_app = "VBoxClient";
75 const char *msg_icon = "";
76 const char *msg_summary = pcHeader;
77 const char *msg_body = pcBody;
78 int32_t msg_timeout = -1; /* Let the notification server decide */
79
80 DBusMessageIter iter;
81 DBusMessageIter array;
82 DBusMessageIter dict;
83 DBusMessageIter value;
84 DBusMessageIter variant;
85 DBusMessageIter data;
86
87 /* Format: UINT32 org.freedesktop.Notifications.Notify
88 * (STRING app_name, UINT32 replaces_id, STRING app_icon, STRING summary, STRING body,
89 * ARRAY actions, DICT hints, INT32 expire_timeout)
90 */
91 dbus_message_iter_init_append(msg,&iter);
92 dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_app);
93 dbus_message_iter_append_basic(&iter,DBUS_TYPE_UINT32,&msg_replace_id);
94 dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_icon);
95 dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_summary);
96 dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_body);
97 dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,DBUS_TYPE_STRING_AS_STRING,&array);
98 dbus_message_iter_close_container(&iter,&array);
99 dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,"{sv}",&array);
100 dbus_message_iter_close_container(&iter,&array);
101 dbus_message_iter_append_basic(&iter,DBUS_TYPE_INT32,&msg_timeout);
102
103 DBusError err;
104 dbus_error_init(&err);
105
106 DBusMessage *reply;
107 reply = dbus_connection_send_with_reply_and_block(conn, msg,
108 30 * 1000 /* 30 seconds timeout */, &err);
109 if (dbus_error_is_set(&err))
110 {
111 Log(("D-BUS returned an error while sending the notification: %s", err.message));
112 }
113 else if (reply)
114 {
115 dbus_connection_flush(conn);
116 dbus_message_unref(reply);
117 }
118 if (dbus_error_is_set(&err))
119 dbus_error_free(&err);
120 }
121 if (msg != NULL)
122 dbus_message_unref(msg);
123# else
124 /* TODO: Implement me */
125 rc = VINF_SUCCESS;
126# endif /* VBOX_WITH_DBUS */
127 return rc;
128 }
129
130 /** @todo Move this part in VbglR3 and just provide a callback for the platform-specific
131 notification stuff, since this is very similar to the VBoxTray code. */
132 virtual int run(bool fDaemonised /* = false */)
133 {
134 int rc;
135 LogFlowFunc(("\n"));
136
137 /* Because we need desktop notifications to be displayed, wait
138 * some time to make the desktop environment load (as a work around). */
139 if (fDaemonised)
140 RTThreadSleep(30 * 1000 /* Wait 30 seconds */);
141
142# ifdef VBOX_WITH_DBUS
143 rc = RTDBusLoadLib();
144 if (RT_FAILURE(rc))
145 LogRel(("VBoxClient: D-Bus seems not to be installed; no host version check/notification done.\n"));
146# else
147 rc = VERR_NOT_IMPLEMENTED;
148# endif /* VBOX_WITH_DBUS */
149
150# ifdef VBOX_WITH_GUEST_PROPS
151 uint32_t uGuestPropSvcClientID;
152 if (RT_SUCCESS(rc))
153 {
154 rc = VbglR3GuestPropConnect(&uGuestPropSvcClientID);
155 if (RT_FAILURE(rc))
156 Log(("Cannot connect to guest property service! rc = %Rrc\n", rc));
157 }
158
159 if (RT_SUCCESS(rc))
160 {
161 char *pszHostVersion;
162 char *pszGuestVersion;
163 bool bUpdate;
164
165 rc = VbglR3HostVersionCheckForUpdate(uGuestPropSvcClientID, &bUpdate, &pszHostVersion, &pszGuestVersion);
166 if (RT_SUCCESS(rc))
167 {
168 if (bUpdate)
169 {
170 char szMsg[256];
171 char szTitle[64];
172
173 /** @todo add some translation macros here */
174 RTStrPrintf(szTitle, sizeof(szTitle), "VirtualBox Guest Additions update available!");
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 rc = showNotify(szTitle, szMsg);
179 LogRel(("VBoxClient: VirtualBox Guest Additions update available!"));
180 if (RT_FAILURE(rc))
181 Log(("VBoxClient: Could not show version notifier tooltip! rc = %d\n", rc));
182 }
183
184 /* Store host version to not notify again */
185 rc = VbglR3HostVersionLastCheckedStore(uGuestPropSvcClientID, pszHostVersion);
186
187 VbglR3GuestPropReadValueFree(pszHostVersion);
188 VbglR3GuestPropReadValueFree(pszGuestVersion);
189 }
190 VbglR3GuestPropDisconnect(uGuestPropSvcClientID);
191 }
192# endif /* VBOX_WITH_GUEST_PROPS */
193 LogFlowFunc(("returning %Rrc\n", rc));
194 return rc;
195 }
196
197 virtual void cleanup()
198 {
199
200 }
201};
202
203/* Static factory */
204VBoxClient::Service *VBoxClient::GetHostVersionService()
205{
206 return new HostVersionService;
207}
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