Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
status_t VBoxClipboardService::Disconnect()
{
    status_t status;

    be_clipboard->StopWatching(BMessenger(this));

    fExiting = true;

    VbglR3ClipboardDisconnect(fClientId);

    wait_for_thread(fServiceThreadID, &status);
    return B_OK;
}
Ejemplo n.º 4
0
void VBoxClipboardDestroy(const VBOXSERVICEENV *pEnv, void *pInstance)
{
    VBOXCLIPBOARDCONTEXT *pCtx = (VBOXCLIPBOARDCONTEXT *)pInstance;
    if (pCtx != &gCtx)
    {
        Log(("VBoxTray: VBoxClipboardDestroy: invalid instance %p (our = %p)!\n", pCtx, &gCtx));
        pCtx = &gCtx;
    }

    vboxClipboardDestroy (pCtx);
    VbglR3ClipboardDisconnect(pCtx->u32ClientID);
    memset (pCtx, 0, sizeof (*pCtx));
    return;
}
Ejemplo n.º 5
0
DECLCALLBACK(int) VBoxClipboardStop(void *pInstance)
{
    AssertPtrReturn(pInstance, VERR_INVALID_POINTER);

    LogFunc(("Stopping pInstance=%p\n", pInstance));

    PVBOXCLIPBOARDCONTEXT pCtx = (PVBOXCLIPBOARDCONTEXT)pInstance;
    AssertPtr(pCtx);

    VbglR3ClipboardDisconnect(pCtx->u32ClientID);
    pCtx->u32ClientID = 0;

    LogFlowFuncLeaveRC(VINF_SUCCESS);
    return VINF_SUCCESS;
}
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;
}