Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/uso_trigger/MiniUsoClient.cpp
Views: 11766
1#include "MiniUsoClient.h"23#pragma comment(lib, "rpcrt4.lib")45MiniUsoClient::MiniUsoClient()6{7HRESULT hResult;89hResult = CoInitializeEx(0, COINIT_MULTITHREADED);10if (FAILED(hResult))11{12//wprintf_s(L" |__ CoInitializeEx() failed. Error code = 0x%08X\n", hResult);13_ready = false;14}15else16{17_ready = true;18}19}2021MiniUsoClient::~MiniUsoClient()22{23CoUninitialize();24}2526void MiniUsoClient::ThrowOnError(HRESULT hResult)27{28if (hResult != 0)29{30throw _com_error(hResult);31}32}333435bool MiniUsoClient::Run(UsoAction action)36{37HRESULT hResult;3839if (this->_ready)40{41//wprintf_s(L" |__ Creating instance of 'UpdateSessionOrchestrator'... ");4243GUID CLSID_UpdateSessionOrchestrator = { 0xb91d5831, 0xb1bd, 0x4608, { 0x81, 0x98, 0xd7, 0x2e, 0x15, 0x50, 0x20, 0xf7 } };44IUpdateSessionOrchestratorPtr updateSessionOrchestrator;45hResult = CoCreateInstance(CLSID_UpdateSessionOrchestrator, nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&updateSessionOrchestrator));46if (FAILED(hResult))47{48//wprintf_s(L"\n |__ CoCreateInstance() failed. Error code = 0x%08X\n", hResult);49CoUninitialize();50return false;51}5253//wprintf_s(L"Done.\n");5455/*56try57{58ThrowOnError(updateSessionOrchestrator->LogTaskRunning(L"StartScan"));59}60catch (const _com_error& error)61{62//wprintf(L" |__ LogTaskRunning() - Return code: 0x%08X (\"%s\")\n", error.Error(), error.ErrorMessage());63}64*/6566IUsoSessionCommonPtr usoSessionCommon;67GUID IID_IUsoSessionCommon = { 0xfccc288d, 0xb47e, 0x41fa, { 0x97, 0x0c, 0x93, 0x5e, 0xc9, 0x52, 0xf4, 0xa4 } };68try69{70//wprintf_s(L" |__ Creating a new Update Session... ");71updateSessionOrchestrator->CreateUpdateSession(1, &IID_IUsoSessionCommon, &usoSessionCommon);72//wprintf_s(L"Done.\n");7374//wprintf_s(L" |__ Calling 'CoSetProxyBlanket()'... ");75ThrowOnError(CoSetProxyBlanket(usoSessionCommon, RPC_C_AUTHN_DEFAULT, RPC_C_AUTHZ_DEFAULT, COLE_DEFAULT_PRINCIPAL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, NULL));76//wprintf_s(L"Done.\n");7778switch (action)79{80case USO_STARTSCAN:81//wprintf(L" |__ Calling 'StartScan'... ");82ThrowOnError(usoSessionCommon->Proc21(0, 0, L"ScanTriggerUsoClient"));83//wprintf(L"Done.\n");84break;85case USO_STARTDOWNLOAD:86//wprintf(L" |__ Calling 'StartDownload'... ");87ThrowOnError(usoSessionCommon->Proc22(0));88//wprintf(L"Done.\n");89break;90case USO_STARTINTERACTIVESCAN:91//wprintf(L" |__ Calling 'StartInteractiveScan'... ");92ThrowOnError(usoSessionCommon->Proc21(-1, 0, L"ScanTriggerUsoClientInteractive"));93//wprintf(L"Done.\n");94break;95}9697}98catch (const _com_error&)99{100return false;101}102}103else104{105return false;106}107108return true;109}110111112