VBoxClipboard.cpp revision 8e9d8c088aac57bedb558d3164bb681a582e4474
/* $Id$ */
/** @file
* VBoxClipboard; Haiku Guest Additions, implementation.
*/
/*
* Copyright (C) 2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*
* This code is based on:
*
* VirtualBox Guest Additions for Haiku.
* Copyright (c) 2011 Mike Smith <mike@scgtrp.net>
* Fran�ois Revol <revol@free.fr>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <new>
#include <Bitmap.h>
#include <BitmapStream.h>
#include <Clipboard.h>
#include <DataIO.h>
#include <Message.h>
#include <TranslationUtils.h>
#include <TranslatorFormats.h>
#include <TranslatorRoster.h>
#include <String.h>
#include "VBoxGuestApplication.h"
#include "VBoxClipboard.h"
#include <VBoxGuestInternal.h>
#define LogRelFlowFunc(x) printf x
: BHandler("VBoxClipboardService"),
fClientId(-1),
fServiceThreadID(-1),
fExiting(false)
{
}
{
}
{
if (RT_SUCCESS(rc))
{
"VBoxClipboardService", B_NORMAL_PRIORITY, this);
{
return B_OK;
else
}
else
//rc = RTErrConvertFromErrno(err);
}
else
return B_ERROR;
}
{
fExiting = true;
return B_OK;
}
{
message->PrintToStream();
{
{
int rc;
void *pv;
bool commit = false;
break;
if (!formats)
break;
if (!be_clipboard->Lock())
break;
be_clipboard->Clear();
if (!clip)
{
be_clipboard->Unlock();
break;
}
{
if (pv)
{
char *text;
if (RT_SUCCESS(rc))
{
// @todo use vboxClipboardUtf16WinToLin()
// convert Windows CRLF to LF
// don't include the \0
commit = true;
}
}
}
{
if (pv)
{
void *pBmp;
if (RT_SUCCESS(rc))
{
if (bitmap)
{
{
commit = true;
}
delete bitmap;
}
}
}
}
/* make sure we don't bounce this data back to the host,
* it's impolite.
* It can also be used as a hint to applications probably. */
if (commit)
be_clipboard->Commit();
be_clipboard->Unlock();
break;
}
{
int rc;
break;
if (!formats)
break;
if (!be_clipboard->Lock())
break;
if (!clip)
{
be_clipboard->Unlock();
break;
}
clip->PrintToStream();
{
const char *text;
{
// usually doesn't include the \0 so be safe
// convert from LF to Windows CRLF
if (RT_SUCCESS(rc))
{
//printf("VbglR3ClipboardWriteData: %d\n", rc);
}
}
}
else if (formats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP)
{
{
if (bitmap)
{
// Don't delete bitmap, BBitmapStream will.
{
{
const void *pDib;
/* Strip out the BM header */
if (RT_SUCCESS(rc))
{
}
}
}
}
}
}
be_clipboard->Unlock();
break;
}
case B_CLIPBOARD_CHANGED:
{
printf("B_CLIPBOARD_CHANGED\n");
const void *data;
if (!be_clipboard->Lock())
break;
if (!clip)
{
be_clipboard->Unlock();
break;
}
bool fromVBox;
{
// It already comes from the host, discard.
be_clipboard->Unlock();
break;
}
be_clipboard->Unlock();
break;
}
case B_QUIT_REQUESTED:
fExiting = true;
break;
default:
}
}
{
return service->_ServiceThread();
}
{
/* The thread waits for incoming messages from the host. */
for (;;)
{
if (RT_SUCCESS(rc))
{
switch (u32Msg)
{
{
/* The host has announced available clipboard formats.
* Forward the information to the handler. */
break;
}
{
/* The host needs data in the specified format. */
break;
}
{
/* The host is terminating. */
LogRelFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_QUIT\n"));
fExiting = true;
return VERR_INTERRUPTED;
}
default:
Log(("VBoxClipboardService::%s: Unsupported message from host! Message = %u\n", __FUNCTION__, u32Msg));
}
}
else
fExiting = true;
if (fExiting)
break;
}
return 0;
}
{
void *pv;
int rc;
return NULL;
return pv;
if (rc == VINF_BUFFER_OVERFLOW)
{
return NULL;
return pv;
}
return NULL;
}