- Timestamp:
- Jan 17, 2024 3:30:48 PM (11 months ago)
- Location:
- trunk/src/VBox/GuestHost/SharedClipboard
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp
r102826 r102929 334 334 335 335 Widget pWidget = pCtx->pWidget; 336 AssertPtrReturnVoid(pWidget); 336 if (!pWidget) 337 return; 337 338 338 339 bool fFound = false; … … 1155 1156 1156 1157 /** 1158 * Helper function for public X11 Shared Clipboard APIs to know whether we're running in headless mode or not. 1159 * 1160 * Headless mode either could mean that we don't want to touch the X11 clipboard, or that X simply isn't installed and/or 1161 * isn't available (e.g. running on a pure server installation w/o any desktop environment). 1162 * 1163 * Goal here is to make the X11 API transparent for the caller whether X is available or not. 1164 * 1165 * @returns \c true if running in headless mode, or \c false if not. 1166 * @param pCtx The X11 clipboard context to use. 1167 */ 1168 DECLINLINE(bool) shClX11HeadlessIsEnabled(PSHCLX11CTX pCtx) 1169 { 1170 return pCtx->fHeadless; 1171 } 1172 1173 /** 1157 1174 * Sets the callback table, internal version. 1158 1175 * … … 1196 1213 LogFlowFunc(("pCtx=%p\n", pCtx)); 1197 1214 1198 int rc = VINF_SUCCESS;1199 1200 1215 RT_BZERO(pCtx, sizeof(SHCLX11CTX)); 1201 1202 if (fHeadless)1203 {1204 /*1205 * If we don't find the DISPLAY environment variable we assume that1206 * we are not connected to an X11 server. Don't actually try to do1207 * this then, just fail silently and report success on every call.1208 * This is important for VBoxHeadless.1209 */1210 LogRel(("Shared Clipboard: X11 DISPLAY variable not set -- disabling clipboard sharing\n"));1211 }1212 1216 1213 1217 /* Init clipboard cache. */ … … 1217 1221 shClX11SetCallbacksInternal(pCtx, pCallbacks); 1218 1222 1219 pCtx->fH aveX11 = !fHeadless;1223 pCtx->fHeadless = fHeadless; 1220 1224 pCtx->pFrontend = pParent; 1221 1225 … … 1225 1229 #endif 1226 1230 1231 int rc = VINF_SUCCESS; 1232 1233 LogRel(("Shared Clipboard: Initializing X11 clipboard (%s mode)\n", fHeadless ? "headless" : "regular")); 1234 1235 if (!pCtx->fHeadless) 1236 { 1227 1237 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP 1228 ShClTransferHttpServerInit(&pCtx->HttpCtx.HttpServer);1238 rc = ShClTransferHttpServerInit(&pCtx->HttpCtx.HttpServer); 1229 1239 #endif 1230 1240 1231 1241 #ifdef TESTCASE 1232 if (RT_SUCCESS(rc))1233 {1234 /** @todo The testcases currently do not utilize the threading code. So init stuff here. */1235 rc = clipInitInternal(pCtx);1236 1242 if (RT_SUCCESS(rc)) 1237 rc = clipRegisterContext(pCtx); 1238 } 1239 #endif 1243 { 1244 /** @todo The testcases currently do not utilize the threading code. So init stuff here. */ 1245 rc = clipInitInternal(pCtx); 1246 if (RT_SUCCESS(rc)) 1247 rc = clipRegisterContext(pCtx); 1248 } 1249 #endif 1250 } 1251 1252 if (RT_FAILURE(rc)) 1253 LogRel(("Shared Clipboard: Initializing X11 clipboard failed with %Rrc\n", rc)); 1240 1254 1241 1255 LogFlowFuncLeaveRC(rc); … … 1246 1260 * Destroys a Shared Clipboard X11 context. 1247 1261 * 1262 * @returns VBox status code. 1248 1263 * @param pCtx The X11 clipboard context to destroy. 1249 1264 */ 1250 voidShClX11Destroy(PSHCLX11CTX pCtx)1265 int ShClX11Destroy(PSHCLX11CTX pCtx) 1251 1266 { 1252 1267 if (!pCtx) 1253 return ;1268 return VINF_SUCCESS; 1254 1269 1255 1270 LogFlowFunc(("pCtx=%p\n", pCtx)); … … 1258 1273 ShClCacheDestroy(&pCtx->Cache); 1259 1274 1275 int rc = VINF_SUCCESS; 1260 1276 #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP 1261 ShClTransferHttpServerDestroy(&pCtx->HttpCtx.HttpServer);1277 rc = ShClTransferHttpServerDestroy(&pCtx->HttpCtx.HttpServer); 1262 1278 #endif 1263 1279 … … 1268 1284 #endif 1269 1285 1270 if ( pCtx->fHaveX11)1286 if (!shClX11HeadlessIsEnabled(pCtx)) 1271 1287 { 1272 1288 /* We set this to NULL when the event thread exits. It really should 1273 1289 * have exited at this point, when we are about to unload the code from 1274 1290 * memory. */ 1275 Assert(pCtx->pWidget == NULL); 1276 } 1291 AssertStmt(pCtx->pWidget == NULL, rc = VERR_WRONG_ORDER); 1292 } 1293 1294 return rc; 1277 1295 } 1278 1296 … … 1290 1308 AssertPtrReturn(pCtx, VERR_INVALID_POINTER); 1291 1309 1292 /* 1293 * Immediately return if we are not connected to the X server. 1294 */ 1295 if (!pCtx->fHaveX11) 1310 if (shClX11HeadlessIsEnabled(pCtx)) 1296 1311 return VINF_SUCCESS; 1297 1312 … … 1376 1391 int ShClX11ThreadStop(PSHCLX11CTX pCtx) 1377 1392 { 1378 int rc; 1379 /* 1380 * Immediately return if we are not connected to the X server. 1381 */ 1382 if (!pCtx->fHaveX11) 1393 if (shClX11HeadlessIsEnabled(pCtx)) 1383 1394 return VINF_SUCCESS; 1384 1395 … … 1386 1397 1387 1398 /* Write to the "stop" pipe. */ 1388 rc = clipThreadScheduleCall(pCtx, clipThreadSignalStop, (XtPointer)pCtx);1399 int rc = clipThreadScheduleCall(pCtx, clipThreadSignalStop, (XtPointer)pCtx); 1389 1400 if (RT_FAILURE(rc)) 1390 1401 { … … 1985 1996 int ShClX11ReportFormatsToX11Async(PSHCLX11CTX pCtx, SHCLFORMATS uFormats) 1986 1997 { 1987 /* 1988 * Immediately return if we are not connected to the X server. 1989 */ 1990 if (!pCtx->fHaveX11) 1998 if (shClX11HeadlessIsEnabled(pCtx)) 1991 1999 return VINF_SUCCESS; 1992 2000 … … 2632 2640 { 2633 2641 AssertPtrReturn(pEvent, VERR_INVALID_POINTER); 2634 /* 2635 * Immediately return if we are not connected to the X server. 2636 */ 2637 if (!pCtx->fHaveX11) 2642 2643 if (shClX11HeadlessIsEnabled(pCtx)) 2638 2644 return VINF_SUCCESS; 2639 2645 … … 2683 2689 AssertReturn(cbBuf, VERR_INVALID_PARAMETER); 2684 2690 /* pcbRead is optional. */ 2691 2692 if (shClX11HeadlessIsEnabled(pCtx)) 2693 { 2694 if (pcbRead) 2695 *pcbRead = 0; 2696 return VINF_SUCCESS; 2697 } 2685 2698 2686 2699 PSHCLEVENT pEvent; … … 2750 2763 /* pEvent not used yet. */ RT_NOREF(pEvent); 2751 2764 2752 /* 2753 * Immediately return if we are not connected to the X server. 2754 */ 2755 if (!pCtx->fHaveX11) 2765 if (shClX11HeadlessIsEnabled(pCtx)) 2756 2766 return VINF_SUCCESS; 2757 2767 -
trunk/src/VBox/GuestHost/SharedClipboard/testcase/tstClipboardGH-X11.cpp
r102466 r102929 589 589 RTTestFailureDetails(hTest, "Conversion to %s, expected \"%s\"\n", 590 590 pcszTarget, valueExp); 591 }592 593 static void tstNoX11(PSHCLX11CTX pCtx, const char *pcszTestCtx)594 {595 uint32_t cbActual = 0;596 uint8_t abBuf[TESTCASE_MAX_BUF_SIZE];597 int rc = ShClX11ReadDataFromX11(pCtx, &g_EventSource, g_msTimeout, VBOX_SHCL_FMT_UNICODETEXT, abBuf, sizeof(abBuf), &cbActual);598 RTTESTI_CHECK_MSG(rc == VERR_NO_DATA, ("context: %s\n", pcszTestCtx));599 591 } 600 592 … … 878 870 * Headless clipboard tests 879 871 */ 880 rc = ShClX11Init(&X11Ctx, &Callbacks, NULL /* pParent */, true /* fHeadless */); 881 AssertRCReturn(rc, RTEXITCODE_FAILURE); 872 RTTEST_CHECK_RC_OK(hTest, ShClX11Init(&X11Ctx, &Callbacks, NULL /* pParent */, true /* fHeadless */)); 882 873 883 874 /* Read from X11 */ 884 875 RTTestSub(hTest, "reading from X11, headless clipboard"); 876 885 877 /* Simple test */ 886 tstClipSetVBoxUtf16(&X11Ctx, VINF_SUCCESS, "", 887 sizeof("") * 2);888 tstClipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world",889 sizeof("hello world"), 8);890 tstNoX11(&X11Ctx, "reading from X11, headless clipboard");878 tstClipSetVBoxUtf16(&X11Ctx, VINF_SUCCESS, "", sizeof("") * 2); 879 tstClipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world", sizeof("hello world"), 8); 880 rc = ShClX11ReadDataFromX11(&X11Ctx, &g_EventSource, g_msTimeout, VBOX_SHCL_FMT_UNICODETEXT, abBuf, sizeof(abBuf), &cbActual); 881 RTTESTI_CHECK_MSG(cbActual == 0, ("expected 0 but got %RU32\n", cbActual)); 882 RTTESTI_CHECK_MSG(rc == VINF_SUCCESS, ("expected VINF_SUCCESS but got %Rrc, context: %s\n", rc)); 891 883 892 884 /* Read from VBox */ 893 885 RTTestSub(hTest, "reading from VBox, headless clipboard"); 886 894 887 /* Simple test */ 895 888 tstClipEmptyVBox(&X11Ctx, VERR_WRONG_ORDER); … … 899 892 tstNoSelectionOwnership(&X11Ctx, "reading from VBox, headless clipboard"); 900 893 901 ShClX11Destroy(&X11Ctx);894 RTTEST_CHECK_RC_OK(hTest, ShClX11Destroy(&X11Ctx)); 902 895 ShClEventSourceDestroy(&g_EventSource); 903 896 -
trunk/src/VBox/GuestHost/SharedClipboard/testcase/tstClipboardGH-X11Smoke.cpp
r98103 r102929 90 90 91 91 SHCLX11CTX X11Ctx; 92 rc = ShClX11Init(&X11Ctx, &Callbacks, NULL /* pParent */, false); 93 AssertRCReturn(rc, 1); 94 rc = ShClX11ThreadStart(&X11Ctx, false /* fGrab */); 95 AssertRCReturn(rc, 1); 92 RTTEST_CHECK_RC_OK(hTest, ShClX11Init(&X11Ctx, &Callbacks, NULL /* pParent */, false /* fHeadless */)); 93 RTTEST_CHECK_RC_OK(hTest, ShClX11ThreadStart(&X11Ctx, false /* fGrab */)); 94 96 95 /* Give the clipboard time to synchronise. */ 97 96 RTThreadSleep(500); 98 rc = ShClX11ThreadStop(&X11Ctx); 99 AssertRCReturn(rc, 1); 100 ShClX11Destroy(&X11Ctx); 97 98 RTTEST_CHECK_RC_OK(hTest, ShClX11ThreadStop(&X11Ctx)); 99 RTTEST_CHECK_RC_OK(hTest, ShClX11Destroy(&X11Ctx)); 100 101 101 return RTTestSummaryAndDestroy(hTest); 102 102 }
Note:
See TracChangeset
for help on using the changeset viewer.