- Timestamp:
- Jun 4, 2019 7:26:56 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/GuestHost/SharedClipboard-uri.h
r78942 r78950 48 48 #define NIL_SHAREDCLIPBOARDAREAID UINT32_MAX 49 49 50 /** SharedClipboardArea flags. */ 51 typedef uint32_t SHAREDCLIPBOARDAREAFLAGS; 52 53 /** No flags specified. */ 54 #define SHAREDCLIPBOARDAREA_FLAGS_NONE 0 50 /** SharedClipboardArea open flags. */ 51 typedef uint32_t SHAREDCLIPBOARDAREAOPENFLAGS; 52 53 /** No open flags specified. */ 54 #define SHAREDCLIPBOARDAREA_OPEN_FLAGS_NONE 0 55 /** The clipboard area must not exist yet. */ 56 #define SHAREDCLIPBOARDAREA_OPEN_FLAGS_MUST_NOT_EXIST RT_BIT(0) 55 57 56 58 /** … … 68 70 SharedClipboardArea(void); 69 71 SharedClipboardArea(const char *pszPath, SHAREDCLIPBOARDAREAID uID = NIL_SHAREDCLIPBOARDAREAID, 70 SHAREDCLIPBOARDAREA FLAGS fFlags = SHAREDCLIPBOARDAREA_FLAGS_NONE);72 SHAREDCLIPBOARDAREAOPENFLAGS fFlags = SHAREDCLIPBOARDAREA_OPEN_FLAGS_NONE); 71 73 virtual ~SharedClipboardArea(void); 72 74 … … 84 86 bool IsOpen(void) const; 85 87 int OpenEx(const char *pszPath, SHAREDCLIPBOARDAREAID uID = NIL_SHAREDCLIPBOARDAREAID, 86 SHAREDCLIPBOARDAREA FLAGS fFlags = SHAREDCLIPBOARDAREA_FLAGS_NONE);88 SHAREDCLIPBOARDAREAOPENFLAGS fFlags = SHAREDCLIPBOARDAREA_OPEN_FLAGS_NONE); 87 89 int OpenTemp(SHAREDCLIPBOARDAREAID uID = NIL_SHAREDCLIPBOARDAREAID, 88 SHAREDCLIPBOARDAREA FLAGS fFlags = SHAREDCLIPBOARDAREA_FLAGS_NONE);90 SHAREDCLIPBOARDAREAOPENFLAGS fFlags = SHAREDCLIPBOARDAREA_OPEN_FLAGS_NONE); 89 91 SHAREDCLIPBOARDAREAID GetID(void) const; 90 92 const char *GetDirAbs(void) const; -
trunk/src/VBox/GuestHost/SharedClipboard/ClipboardArea.cpp
r78942 r78950 47 47 SharedClipboardArea::SharedClipboardArea(const char *pszPath, 48 48 SHAREDCLIPBOARDAREAID uID /* = NIL_SHAREDCLIPBOARDAREAID */, 49 SHAREDCLIPBOARDAREA FLAGS fFlags /* = SHAREDCLIPBOARDAREA_FLAGS_NONE */)49 SHAREDCLIPBOARDAREAOPENFLAGS fFlags /* = SHAREDCLIPBOARDAREA_OPEN_FLAGS_NONE */) 50 50 : m_tsCreatedMs(0) 51 51 , m_cRefs(0) … … 158 158 if (RT_SUCCESS(rc)) 159 159 { 160 this->m_fOpen = SHAREDCLIPBOARDAREA_ FLAGS_NONE;160 this->m_fOpen = SHAREDCLIPBOARDAREA_OPEN_FLAGS_NONE; 161 161 this->m_uID = NIL_SHAREDCLIPBOARDAREAID; 162 162 } … … 238 238 int SharedClipboardArea::OpenEx(const char *pszPath, 239 239 SHAREDCLIPBOARDAREAID uID /* = NIL_SHAREDCLIPBOARDAREAID */, 240 SHAREDCLIPBOARDAREA FLAGS fFlags /* = SHAREDCLIPBOARDAREA_FLAGS_NONE */)240 SHAREDCLIPBOARDAREAOPENFLAGS fFlags /* = SHAREDCLIPBOARDAREA_OPEN_FLAGS_NONE */) 241 241 { 242 242 AssertPtrReturn(pszPath, VERR_INVALID_POINTER); … … 247 247 if (RT_SUCCESS(rc)) 248 248 { 249 if (!RTDirExists(szAreaDir)) 250 rc = RTDirCreateFullPath(szAreaDir, RTFS_UNIX_IRWXU); 249 if ( RTDirExists(szAreaDir) 250 && (fFlags & SHAREDCLIPBOARDAREA_OPEN_FLAGS_MUST_NOT_EXIST)) 251 { 252 rc = VERR_ALREADY_EXISTS; 253 } 254 else 255 rc = RTDirCreateFullPath(szAreaDir, RTFS_UNIX_IRWXU); /** @todo Tweak path mode? */ 251 256 252 257 if (RT_SUCCESS(rc)) … … 270 275 271 276 int SharedClipboardArea::OpenTemp(SHAREDCLIPBOARDAREAID uID, 272 SHAREDCLIPBOARDAREA FLAGS fFlags /* = SHAREDCLIPBOARDAREA_FLAGS_NONE */)277 SHAREDCLIPBOARDAREAOPENFLAGS fFlags /* = SHAREDCLIPBOARDAREA_OPEN_FLAGS_NONE */) 273 278 { 274 279 AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER); /* Flags not supported yet. */ -
trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-uri.cpp
r78942 r78950 114 114 AssertPtrReturn(pState, VERR_INVALID_POINTER); 115 115 116 int rc = pTransfer->Area.OpenTemp(SHAREDCLIPBOARDAREA_FLAGS_NONE);116 int rc = SharedClipboardMetaDataInit(&pTransfer->Meta); 117 117 if (RT_SUCCESS(rc)) 118 118 { 119 rc = SharedClipboardMetaDataInit(&pTransfer->Meta);119 vboxClipboardSvcURIObjCtxInit(&pTransfer->ObjCtx); 120 120 if (RT_SUCCESS(rc)) 121 121 { 122 vboxClipboardSvcURIObjCtxInit(&pTransfer->ObjCtx); 123 if (RT_SUCCESS(rc)) 124 { 125 pTransfer->pState = pState; 126 } 122 pTransfer->pState = pState; 127 123 } 128 124 } … … 472 468 RT_ZERO(parms); 473 469 470 parms.uID = NIL_SHAREDCLIPBOARDAREAID; 474 471 parms.u.fn_register.pvData = pvMeta; 475 472 parms.u.fn_register.cbData = (uint32_t)cbMeta; … … 477 474 /* As the meta data is now complete, register a new clipboard on the host side. */ 478 475 rc = g_pfnExtension(g_pvExtension, VBOX_CLIPBOARD_EXT_FN_AREA_REGISTER, &parms, sizeof(parms)); 476 if (RT_SUCCESS(rc)) 477 rc = pTransfer->Area.OpenTemp(parms.uID /* Area ID */); 479 478 #ifdef LOG_ENABLED 480 479 AssertPtr(pTransfer->pState); 481 LogFlowFunc(("Registered new clipboard area by client %RU32 with rc=%Rrc\n",482 p Transfer->pState->u32ClientID, rc));480 LogFlowFunc(("Registered new clipboard area (%RU32) by client %RU32 with rc=%Rrc\n", 481 parms.uID, pTransfer->pState->u32ClientID, rc)); 483 482 #endif 484 483 } -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r78916 r78950 8461 8461 8462 8462 VBOXCLIPBOARDEXTPARMS *pParms = (VBOXCLIPBOARDEXTPARMS *)pvParms; 8463 AssertPtr(pParms); 8463 8464 8464 8465 /* The guest announces clipboard formats. This must be delivered to all clients. */ … … 8476 8477 8477 8478 VBOXCLIPBOARDEXTPARMS *pParms = (VBOXCLIPBOARDEXTPARMS *)pvParms; 8479 AssertPtr(pParms); 8478 8480 8479 8481 /* The clipboard service expects that the pvData buffer will be filled … … 8494 8496 8495 8497 VBOXCLIPBOARDEXTPARMS *pParms = (VBOXCLIPBOARDEXTPARMS *)pvParms; 8498 AssertPtr(pParms); 8496 8499 8497 8500 if (pThis->mConsoleVRDPServer) … … 8509 8512 ULONG uID; 8510 8513 hrc = pControl->ClipboardAreaRegister(ComSafeArrayAsInParam(abstrParms), &uID); H(); 8514 if (SUCCEEDED(hrc)) 8515 { 8516 PVBOXCLIPBOARDEXTAREAPARMS pParms = (PVBOXCLIPBOARDEXTAREAPARMS)pvParms; 8517 AssertPtr(pParms); 8518 8519 /* Return the registered area ID back to the caller. */ 8520 pParms->uID = uID; 8521 } 8511 8522 } break; 8512 8523 -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r78942 r78950 230 230 { 231 231 SharedClipboardAreaData() 232 : uID(0) { } 233 234 /** The area's (unique) ID. */ 232 : uID(NIL_SHAREDCLIPBOARDAREAID) { } 233 234 /** The area's (unique) ID. 235 * Set to NIL_SHAREDCLIPBOARDAREAID if not initialized yet. */ 235 236 ULONG uID; 236 237 /** The actual Shared Clipboard area assigned to this ID. */ … … 247 248 { 248 249 SharedClipboardData() 249 : u NextClipboardAreaID(0)250 , uMaxClipboardAreas(32) 250 : uMostRecentClipboardAreaID(NIL_SHAREDCLIPBOARDAREAID) 251 , uMaxClipboardAreas(32) /** @todo Make this configurable. */ 251 252 { 252 253 int rc2 = RTCritSectInit(&CritSect); … … 259 260 } 260 261 262 /** 263 * Generates a new clipboard area ID. 264 * Currently does *not* check for collisions and stuff. 265 * 266 * @returns New clipboard area ID. 267 */ 268 ULONG GenerateAreaID(void) 269 { 270 ULONG uID = NIL_SHAREDCLIPBOARDAREAID; 271 272 int rc = RTCritSectEnter(&CritSect); 273 if (RT_SUCCESS(rc)) 274 { 275 uID = RTRandU32Ex(1, UINT32_MAX - 1); /** @todo Make this a bit more sophisticated. Later. */ 276 277 int rc2 = RTCritSectLeave(&CritSect); 278 AssertRC(rc2); 279 } 280 281 LogFlowFunc(("uID=%RU32\n", uID)); 282 return uID; 283 } 284 261 285 /** Critical section to serialize access. */ 262 286 RTCRITSECT CritSect; 263 /** The next (free) clipboard area ID. */ 264 ULONG uNextClipboardAreaID; 287 /** The most recent (last created) clipboard area ID. 288 * NIL_SHAREDCLIPBOARDAREAID if not initialized yet. */ 289 ULONG uMostRecentClipboardAreaID; 265 290 /** Maximum of concurrent clipboard areas. 266 291 * @todo Make this configurable. */ … … 3353 3378 3354 3379 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST 3380 /** 3381 * Generates a new clipboard area on the host by opening (and locking) a new, temporary directory. 3382 * 3383 * @returns HRESULT 3384 * @param AreaData Area data to use for clipboard area creation. 3385 * @param fFlags Additional creation flags; currently unused and ignored. 3386 */ 3355 3387 int VirtualBox::i_clipboardAreaCreate(SharedClipboardAreaData &AreaData, uint32_t fFlags) 3356 3388 { 3357 3389 RT_NOREF(fFlags); 3358 int vrc = AreaData.Area.OpenTemp(AreaData.uID); 3359 if (RT_SUCCESS(vrc)) 3360 { 3361 } 3390 int vrc = AreaData.Area.OpenTemp(AreaData.uID, SHAREDCLIPBOARDAREA_OPEN_FLAGS_MUST_NOT_EXIST); 3362 3391 LogFlowFunc(("uID=%RU32, rc=%Rrc\n", AreaData.uID, vrc)); 3363 3392 return vrc; 3364 3393 } 3365 3394 3395 /** 3396 * Destroys a formerly created clipboard area. 3397 * 3398 * @returns HRESULT 3399 * @param AreaData Area data to use for clipboard area destruction. 3400 */ 3366 3401 int VirtualBox::i_clipboardAreaDestroy(SharedClipboardAreaData &AreaData) 3367 3402 { … … 3373 3408 } 3374 3409 3410 /** 3411 * Registers and creates a new clipboard area on the host (for all VMs), returned the clipboard area ID for it. 3412 * 3413 * @returns HRESULT 3414 * @param aParms Creation parameters. Currently unused. 3415 * @param aID Where to return the clipboard area ID on success. 3416 */ 3375 3417 HRESULT VirtualBox::i_onClipboardAreaRegister(const std::vector<com::Utf8Str> &aParms, ULONG *aID) 3376 3418 { … … 3386 3428 if (m->SharedClipboard.mapClipboardAreas.size() >= m->SharedClipboard.uMaxClipboardAreas) 3387 3429 { 3388 const ULONG uAreaID = m->SharedClipboard.uNextClipboardAreaID; 3389 3390 SharedClipboardAreaData AreaData; 3391 AreaData.uID = uAreaID; 3392 3393 vrc = i_clipboardAreaCreate(AreaData, 0 /* fFlags */); 3394 if (RT_SUCCESS(vrc)) 3430 for (unsigned uTries = 0; uTries < 32; uTries++) /* Don't try too hard. */ 3395 3431 { 3396 m->SharedClipboard.mapClipboardAreas[uAreaID] = AreaData; 3397 m->SharedClipboard.uNextClipboardAreaID++; 3398 3399 /** @todo Implement collision detection / wrap-around. */ 3400 3401 if (aID) 3402 *aID = uAreaID; 3403 3404 LogThisFunc(("Registered new clipboard area %RU32: '%s'\n", 3405 uAreaID, AreaData.Area.GetDirAbs())); 3432 const ULONG uAreaID = m->SharedClipboard.GenerateAreaID(); 3433 3434 /* Area ID already taken? */ 3435 if (m->SharedClipboard.mapClipboardAreas.find(uAreaID) != m->SharedClipboard.mapClipboardAreas.end()) 3436 continue; 3437 3438 SharedClipboardAreaData AreaData; 3439 AreaData.uID = uAreaID; 3440 3441 vrc = i_clipboardAreaCreate(AreaData, 0 /* fFlags */); 3442 if (RT_SUCCESS(vrc)) 3443 { 3444 m->SharedClipboard.mapClipboardAreas[uAreaID] = AreaData; 3445 m->SharedClipboard.uMostRecentClipboardAreaID = uAreaID; 3446 3447 /** @todo Implement collision detection / wrap-around. */ 3448 3449 if (aID) 3450 *aID = uAreaID; 3451 3452 LogThisFunc(("Registered new clipboard area %RU32: '%s'\n", 3453 uAreaID, AreaData.Area.GetDirAbs())); 3454 break; 3455 } 3406 3456 } 3407 else 3457 3458 if (RT_FAILURE(vrc)) 3408 3459 rc = setError(E_FAIL, /** @todo Find a better rc. */ 3409 tr("Failed to create new clipboard area %RU32 (%Rrc)"), aID, vrc);3460 tr("Failed to create new clipboard area (%Rrc)"), vrc); 3410 3461 } 3411 3462 else 3412 3463 { 3413 3464 rc = setError(E_FAIL, /** @todo Find a better rc. */ 3414 tr("Maximum number of con ucurrent clipboard areas reached (%RU32)"),3465 tr("Maximum number of concurrent clipboard areas reached (%RU32)"), 3415 3466 m->SharedClipboard.uMaxClipboardAreas); 3416 3467 } … … 3428 3479 } 3429 3480 3481 /** 3482 * Unregisters (destroys) a formerly created clipboard area. 3483 * 3484 * @returns HRESULT 3485 * @param aID ID of clipboard area to destroy. 3486 */ 3430 3487 HRESULT VirtualBox::i_onClipboardAreaUnregister(ULONG aID) 3431 3488 { … … 3461 3518 } 3462 3519 3520 /** 3521 * Attaches to an existing clipboard area. 3522 * 3523 * @returns HRESULT 3524 * @param aID ID of clipboard area to attach. 3525 */ 3463 3526 HRESULT VirtualBox::i_onClipboardAreaAttach(ULONG aID) 3464 3527 { … … 3486 3549 } 3487 3550 3551 /** 3552 * Detaches from an existing clipboard area. 3553 * 3554 * @returns HRESULT 3555 * @param aID ID of clipboard area to detach from. 3556 */ 3488 3557 HRESULT VirtualBox::i_onClipboardAreaDetach(ULONG aID) 3489 3558 { … … 3511 3580 } 3512 3581 3582 /** 3583 * Returns the ID of the most recent (last created) clipboard area, 3584 * or NIL_SHAREDCLIPBOARDAREAID if no clipboard area has been created yet. 3585 * 3586 * @returns Most recent clipboard area ID. 3587 */ 3513 3588 ULONG VirtualBox::i_onClipboardAreaGetMostRecent(void) 3514 3589 { … … 3517 3592 if (RT_SUCCESS(vrc2)) 3518 3593 { 3519 aID = m->SharedClipboard.uNextClipboardAreaID 3520 ? m->SharedClipboard.uNextClipboardAreaID - 1 : 0; 3594 aID = m->SharedClipboard.uMostRecentClipboardAreaID; 3521 3595 3522 3596 vrc2 = RTCritSectLeave(&m->SharedClipboard.CritSect); … … 3527 3601 } 3528 3602 3603 /** 3604 * Returns the current reference count of a clipboard area. 3605 * 3606 * @returns Reference count of given clipboard area ID. 3607 */ 3529 3608 ULONG VirtualBox::i_onClipboardAreaGetRefCount(ULONG aID) 3530 3609 {
Note:
See TracChangeset
for help on using the changeset viewer.