status_t VBoxClipboardService::Connect() { status_t err; LogFlowFunc(("Connect\n")); int rc = VbglR3ClipboardConnect(&fClientId); if (RT_SUCCESS(rc)) { err = fServiceThreadID = spawn_thread(_ServiceThreadNub, "VBoxClipboardService", B_NORMAL_PRIORITY, this); if (err >= B_OK) { resume_thread(fServiceThreadID); err = be_clipboard->StartWatching(BMessenger(this)); LogFlow(("be_clipboard->StartWatching: %ld\n", err)); if (err == B_OK) return B_OK; else LogRel(("VBoxClipboardService: Error watching the system clipboard: %ld\n", err)); } else LogRel(("VBoxClipboardService: Error starting service thread: %ld\n", err)); //rc = RTErrConvertFromErrno(err); VbglR3ClipboardDisconnect(fClientId); } else LogRel(("VBoxClipboardService: Error starting service thread: %d\n", rc)); return B_ERROR; }
/** * Connect the guest clipboard to the host. * * @returns VBox status code */ int vboxClipboardConnect(void) { int rc = VINF_SUCCESS; LogRelFlowFunc(("\n")); /* Sanity */ AssertReturn(g_ctx.client == 0, VERR_WRONG_ORDER); g_ctx.pBackend = ClipConstructX11(&g_ctx, false); if (!g_ctx.pBackend) rc = VERR_NO_MEMORY; if (RT_SUCCESS(rc)) rc = ClipStartX11(g_ctx.pBackend); if (RT_SUCCESS(rc)) { rc = VbglR3ClipboardConnect(&g_ctx.client); if (RT_FAILURE(rc)) LogRel(("Error connecting to host. rc=%Rrc\n", rc)); else if (!g_ctx.client) { LogRel(("Invalid client ID of 0\n")); rc = VERR_NOT_SUPPORTED; } } if (rc != VINF_SUCCESS && g_ctx.pBackend) ClipDestructX11(g_ctx.pBackend); LogRelFlowFunc(("g_ctx.client=%u rc=%Rrc\n", g_ctx.client, rc)); return rc; }
int VBoxClipboardInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread) { Log(("VBoxTray: VboxClipboardInit\n")); if (gCtx.pEnv) { /* Clipboard was already initialized. 2 or more instances are not supported. */ return VERR_NOT_SUPPORTED; } RT_ZERO (gCtx); gCtx.pEnv = pEnv; int rc = VbglR3ClipboardConnect(&gCtx.u32ClientID); if (RT_SUCCESS (rc)) { rc = vboxClipboardInit(&gCtx); if (RT_SUCCESS (rc)) { /* Always start the thread for host messages. */ *pfStartThread = true; } else { VbglR3ClipboardDisconnect(gCtx.u32ClientID); } } if (RT_SUCCESS(rc)) *ppInstance = &gCtx; return rc; }
DECLCALLBACK(int) VBoxClipboardInit(const PVBOXSERVICEENV pEnv, void **ppInstance) { LogFlowFuncEnter(); PVBOXCLIPBOARDCONTEXT pCtx = &g_Ctx; /* Only one instance for now. */ AssertPtr(pCtx); if (pCtx->pEnv) { /* Clipboard was already initialized. 2 or more instances are not supported. */ return VERR_NOT_SUPPORTED; } if (VbglR3AutoLogonIsRemoteSession()) { /* Do not use clipboard for remote sessions. */ LogRel(("Clipboard: Clipboard has been disabled for a remote session\n")); return VERR_NOT_SUPPORTED; } RT_BZERO(pCtx, sizeof(VBOXCLIPBOARDCONTEXT)); pCtx->pEnv = pEnv; /* Check that new Clipboard API is available */ VBoxClipboardWinCheckAndInitNewAPI(&pCtx->Win.newAPI); int rc = VbglR3ClipboardConnect(&pCtx->u32ClientID); if (RT_SUCCESS(rc)) { rc = vboxClipboardCreateWindow(pCtx); if (RT_SUCCESS(rc)) { *ppInstance = pCtx; } else { VbglR3ClipboardDisconnect(pCtx->u32ClientID); } } LogFlowFuncLeaveRC(rc); return rc; }