ClientTokenHolder.cpp revision 5637660ed0c2a4a3a114e6d2d4c8294f2fd5f18f
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * VirtualBox API client token holder (in the client process)
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Copyright (C) 2006-2013 Oracle Corporation
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * available from http://www.virtualbox.org. This file is free software;
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * you can redistribute it and/or modify it under the terms of the GNU
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * General Public License (GPL) as published by the Free Software
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync/** client token holder thread */
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsyncstatic DECLCALLBACK(int) ClientTokenHolderThread(RTTHREAD Thread, void *pvUser);
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync /* release the client token */
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * tell the thread holding the token to release it;
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * it will close mSem handle
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync /* wait for the thread to finish */
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync /* tell the thread holding the token to release it */
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync /* wait for the thread to finish */
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync vrc = RTThreadUserWait(mThread, RT_INDEFINITE_WAIT);
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync Assert(RT_SUCCESS(vrc) || vrc == VERR_INTERRUPTED);
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsyncSession::ClientTokenHolder::ClientTokenHolder(const Utf8Str &strTokenId) :
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Since there is no guarantee that the constructor and destructor will be
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * called in the same thread, we need a separate thread to hold the token.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync mThreadSem = ::CreateEvent(NULL, FALSE, FALSE, NULL);
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync ("Cannot create an event sem, err=%d", ::GetLastError()));
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync data[2] = 0; /* will get an output from the thread */
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync /* create a thread to hold the token until signalled to release it */
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync int vrc = RTThreadCreate(&mThread, ClientTokenHolderThread, (void*)data, 0, RTTHREADTYPE_MAIN_WORKER, 0, "IPCHolder");
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync /* wait until thread init is completed */
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync DWORD wrc = ::WaitForSingleObject(mThreadSem, INFINITE);
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync AssertMsg(wrc == WAIT_OBJECT_0, ("Wait failed, err=%d\n", ::GetLastError()));
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync /* memorize the event sem we should signal in close() */
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Since there is no guarantee that the constructor and destructor will be
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * called in the same thread, we need a separate thread to hold the token.
# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
AssertMsgReturnVoid(s >= 0,
mSem = s;
# if defined(RT_OS_WINDOWS)
if (mutex)
if (finishSem)