diff --git a/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp b/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp index 95754c7ba3..a32f5e2eb1 100644 --- a/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp +++ b/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp @@ -3925,228 +3925,6 @@ bool VaultAgeGetSubAgeLink (const plAgeInfoStruct * info, plAgeLinkStruct * link return result; } -//============================================================================ -namespace _VaultCreateSubAgeAndWait { - -struct _InitAgeParam { - ENetError result; - bool complete; - unsigned ageInfoId; -}; -static void _InitAgeCallback ( - ENetError result, - void * , - void * vparam, - unsigned ageVaultId, - unsigned ageInfoVaultId -) { - _InitAgeParam * param = (_InitAgeParam *)vparam; - param->ageInfoId = ageInfoVaultId; - param->result = result; - param->complete = true; -} -struct _FetchVaultParam { - ENetError result; - bool complete; -}; -static void _FetchVaultCallback ( - ENetError result, - void * vparam -) { - _FetchVaultParam * param = (_FetchVaultParam *)vparam; - param->result = result; - param->complete = true; -} -struct _CreateNodeParam { - ENetError result; - bool complete; - unsigned nodeId; -}; -static void _CreateNodeCallback ( - ENetError result, - void * , - void * vparam, - hsWeakRef node -) { - _CreateNodeParam * param = (_CreateNodeParam *)vparam; - if (IS_NET_SUCCESS(result)) - param->nodeId = node->GetNodeId(); - param->result = result; - param->complete = true; -} -struct _AddChildNodeParam { - ENetError result; - bool complete; -}; -static void _AddChildNodeCallback ( - ENetError result, - void * vparam -) { - _AddChildNodeParam * param = (_AddChildNodeParam *)vparam; - param->result = result; - param->complete = true; -} - -} // namespace _VaultCreateSubAgeAndWait - -//============================================================================ -bool VaultAgeFindOrCreateSubAgeLinkAndWait ( - const plAgeInfoStruct * info, - plAgeLinkStruct * link, - const plUUID& parentAgeInstId -) { - if (hsRef rvnLink = VaultFindAgeSubAgeLink(info)) { - VaultAgeLinkNode linkAcc(rvnLink); - linkAcc.CopyTo(link); - if (hsRef rvnInfo = rvnLink->GetChildNode(plVault::kNodeType_AgeInfo, 1)) { - VaultAgeInfoNode infoAcc(rvnInfo); - infoAcc.CopyTo(link->GetAgeInfo()); - return true; - } - } - - using namespace _VaultCreateSubAgeAndWait; - - unsigned subAgesId; - unsigned ageInfoId; - unsigned ageLinkId; - - if (hsRef rvnSubAges = VaultGetAgeSubAgesFolder()) - subAgesId = rvnSubAges->GetNodeId(); - else { - LogMsg(kLogError, "CreateSubAge: Failed to get ages's SubAges folder"); - return false; - } - - { // Init age vault - _InitAgeParam param; - memset(¶m, 0, sizeof(param)); - - VaultInitAge( - info, - parentAgeInstId, - _InitAgeCallback, - nullptr, - ¶m - ); - - while (!param.complete) { - NetClientUpdate(); - plgDispatch::Dispatch()->MsgQueueProcess(); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - - if (IS_NET_ERROR(param.result)) { - LogMsg(kLogError, "CreateSubAge: Failed to init age {}", link->GetAgeInfo()->GetAgeFilename()); - return false; - } - - ageInfoId = param.ageInfoId; - } - - { // Create age link - _CreateNodeParam param; - memset(¶m, 0, sizeof(param)); - - VaultCreateNode( - plVault::kNodeType_AgeLink, - _CreateNodeCallback, - nullptr, - ¶m - ); - - while (!param.complete) { - NetClientUpdate(); - plgDispatch::Dispatch()->MsgQueueProcess(); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - - if (IS_NET_ERROR(param.result)) { - LogMsg(kLogError, "CreateSubAge: Failed create age link node"); - return false; - } - - ageLinkId = param.nodeId; - } - - { // Fetch age info node tree - _FetchVaultParam param; - memset(¶m, 0, sizeof(param)); - - VaultDownload( - "CreateSubAge", - ageInfoId, - _FetchVaultCallback, - ¶m, - nullptr, - nullptr - ); - - while (!param.complete) { - NetClientUpdate(); - plgDispatch::Dispatch()->MsgQueueProcess(); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - - if (IS_NET_ERROR(param.result)) { - LogMsg(kLogError, "CreateSubAge: Failed to download age info vault"); - return false; - } - } - - { // Link: - // ageLink to ages's subages folder - // ageInfo to ageLink - _AddChildNodeParam param1; - _AddChildNodeParam param2; - memset(¶m1, 0, sizeof(param1)); - memset(¶m2, 0, sizeof(param2)); - - VaultAddChildNode( - subAgesId, - ageLinkId, - 0, - _AddChildNodeCallback, - ¶m1 - ); - - VaultAddChildNode( - ageLinkId, - ageInfoId, - 0, - _AddChildNodeCallback, - ¶m2 - ); - - while (!param1.complete && !param2.complete) { - NetClientUpdate(); - plgDispatch::Dispatch()->MsgQueueProcess(); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - - if (IS_NET_ERROR(param1.result)) { - LogMsg(kLogError, "CreateSubAge: Failed to add link to ages's subages"); - return false; - } - if (IS_NET_ERROR(param2.result)) { - LogMsg(kLogError, "CreateSubAge: Failed to add info to link"); - return false; - } - } - - if (hsRef rvnLink = VaultGetNode(ageLinkId)) { - VaultAgeLinkNode linkAcc(rvnLink); - linkAcc.CopyTo(link); - } - - if (hsRef rvnInfo = VaultGetNode(ageInfoId)) { - VaultAgeInfoNode infoAcc(rvnInfo); - infoAcc.CopyTo(link->GetAgeInfo()); - } - - return true; -} - //============================================================================ namespace _VaultCreateSubAge { void _CreateNodeCallback(ENetError result, void* state, void* param, hsWeakRef node) { @@ -4227,263 +4005,6 @@ bool VaultAgeFindOrCreateSubAgeLink(const plAgeInfoStruct* info, plAgeLinkStruct return false; } -//============================================================================ -namespace _VaultCreateChildAgeAndWait { - -struct _InitAgeParam { - ENetError result; - bool complete; - unsigned ageInfoId; -}; -static void _InitAgeCallback ( - ENetError result, - void * , - void * vparam, - unsigned ageVaultId, - unsigned ageInfoVaultId -) { - _InitAgeParam * param = (_InitAgeParam *)vparam; - param->ageInfoId = ageInfoVaultId; - param->result = result; - param->complete = true; -} -struct _FetchVaultParam { - ENetError result; - bool complete; -}; -static void _FetchVaultCallback ( - ENetError result, - void * vparam -) { - _FetchVaultParam * param = (_FetchVaultParam *)vparam; - param->result = result; - param->complete = true; -} -struct _CreateNodeParam { - ENetError result; - bool complete; - unsigned nodeId; -}; -static void _CreateNodeCallback ( - ENetError result, - void * , - void * vparam, - hsWeakRef node -) { - _CreateNodeParam * param = (_CreateNodeParam *)vparam; - if (IS_NET_SUCCESS(result)) - param->nodeId = node->GetNodeId(); - param->result = result; - param->complete = true; -} -struct _AddChildNodeParam { - ENetError result; - bool complete; -}; -static void _AddChildNodeCallback ( - ENetError result, - void * vparam -) { - _AddChildNodeParam * param = (_AddChildNodeParam *)vparam; - param->result = result; - param->complete = true; -} - -} // namespace _VaultCreateChildAgeAndWait - -//============================================================================ -bool VaultAgeFindOrCreateChildAgeLinkAndWait ( - const ST::string& parentAgeName, - const plAgeInfoStruct * info, - plAgeLinkStruct * link -) { - using namespace _VaultCreateChildAgeAndWait; - - unsigned childAgesId; - unsigned ageInfoId; - unsigned ageLinkId; - - { // Get id of child ages folder - hsRef rvnAgeInfo; - if (!parentAgeName.empty()) { - plAgeInfoStruct pinfo; - pinfo.SetAgeFilename(parentAgeName); - if (hsRef rvnAgeLink = VaultGetOwnedAgeLink(&pinfo)) - rvnAgeInfo = rvnAgeLink->GetChildNode(plVault::kNodeType_AgeInfo, 1); - } else { - rvnAgeInfo = VaultGetAgeInfoNode(); - } - - if (!rvnAgeInfo) { - LogMsg(kLogError, "CreateChildAge: Failed to get ages's AgeInfo node"); - return false; - } - - hsRef rvnChildAges; - if (rvnChildAges = rvnAgeInfo->GetChildAgeInfoListNode(plVault::kChildAgesFolder, 1)) { - childAgesId = rvnChildAges->GetNodeId(); - } - else { - LogMsg(kLogError, "CreateChildAge: Failed to get ages's ChildAges folder"); - return false; - } - - // Check for existing child age in folder - hsRef rvnLink; - NetVaultNode templateNode; - templateNode.SetNodeType(plVault::kNodeType_AgeInfo); - - VaultAgeInfoNode ageInfo(&templateNode); - ageInfo.SetAgeFilename(info->GetAgeFilename()); - - if (hsRef rvnInfo = rvnChildAges->GetChildNode(&templateNode, 2)) { - templateNode.Clear(); - templateNode.SetNodeType(plVault::kNodeType_AgeLink); - rvnLink = rvnInfo->GetParentNode(&templateNode, 1); - } - - if (rvnLink) { - VaultAgeLinkNode access(rvnLink); - access.CopyTo(link); - return true; - } - } - - { // Init age vault - _InitAgeParam param; - memset(¶m, 0, sizeof(param)); - - plUUID parentAgeInstId; - if (hsRef rvnAge = VaultGetAgeNode()) { - VaultAgeNode access(rvnAge); - parentAgeInstId = access.GetAgeInstanceGuid(); - } - - VaultInitAge( - info, - parentAgeInstId, - _InitAgeCallback, - nullptr, - ¶m - ); - - while (!param.complete) { - NetClientUpdate(); - plgDispatch::Dispatch()->MsgQueueProcess(); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - - if (IS_NET_ERROR(param.result)) { - LogMsg(kLogError, "CreateChildAge: Failed to init age {}", link->GetAgeInfo()->GetAgeFilename()); - return false; - } - - ageInfoId = param.ageInfoId; - } - - { // Create age link - _CreateNodeParam param; - memset(¶m, 0, sizeof(param)); - - VaultCreateNode( - plVault::kNodeType_AgeLink, - _CreateNodeCallback, - nullptr, - ¶m - ); - - while (!param.complete) { - NetClientUpdate(); - plgDispatch::Dispatch()->MsgQueueProcess(); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - - if (IS_NET_ERROR(param.result)) { - LogMsg(kLogError, "CreateChildAge: Failed create age link node"); - return false; - } - - ageLinkId = param.nodeId; - } - - { // Fetch age info node tree - _FetchVaultParam param; - memset(¶m, 0, sizeof(param)); - - VaultDownload( - "CreateChildAge", - ageInfoId, - _FetchVaultCallback, - ¶m, - nullptr, - nullptr - ); - - while (!param.complete) { - NetClientUpdate(); - plgDispatch::Dispatch()->MsgQueueProcess(); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - - if (IS_NET_ERROR(param.result)) { - LogMsg(kLogError, "CreateChildAge: Failed to download age info vault"); - return false; - } - } - - { // Link: - // ageLink to ages's subages folder - // ageInfo to ageLink - _AddChildNodeParam param1; - _AddChildNodeParam param2; - memset(¶m1, 0, sizeof(param1)); - memset(¶m2, 0, sizeof(param2)); - - VaultAddChildNode( - childAgesId, - ageLinkId, - 0, - _AddChildNodeCallback, - ¶m1 - ); - - VaultAddChildNode( - ageLinkId, - ageInfoId, - 0, - _AddChildNodeCallback, - ¶m2 - ); - - while (!param1.complete && !param2.complete) { - NetClientUpdate(); - plgDispatch::Dispatch()->MsgQueueProcess(); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - - if (IS_NET_ERROR(param1.result)) { - LogMsg(kLogError, "CreateChildAge: Failed to add link to ages's subages"); - return false; - } - if (IS_NET_ERROR(param2.result)) { - LogMsg(kLogError, "CreateChildAge: Failed to add info to link"); - return false; - } - } - - if (hsRef rvnLink = VaultGetNode(ageLinkId)) { - VaultAgeLinkNode linkAcc(rvnLink); - linkAcc.CopyTo(link); - } - - if (hsRef rvnInfo = VaultGetNode(ageInfoId)) { - VaultAgeInfoNode infoAcc(rvnInfo); - infoAcc.CopyTo(link->GetAgeInfo()); - } - - return true; -} - //============================================================================ namespace _VaultCreateChildAge { struct _Params { diff --git a/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h b/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h index 19afc08977..982464126a 100644 --- a/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h +++ b/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h @@ -424,17 +424,7 @@ bool VaultAgeGetSubAgeLink ( const plAgeInfoStruct * info, plAgeLinkStruct * link ); -bool VaultAgeFindOrCreateSubAgeLinkAndWait ( - const plAgeInfoStruct * info, - plAgeLinkStruct * link, - const plUUID& parentAgeInstId -); bool VaultAgeFindOrCreateSubAgeLink(const plAgeInfoStruct* info, plAgeLinkStruct* link, const plUUID& arentUuid); -bool VaultAgeFindOrCreateChildAgeLinkAndWait ( - const ST::string& parentAgeName, // nil --> current age, non-nil --> owned age by given name - const plAgeInfoStruct * info, - plAgeLinkStruct * link -); enum class plVaultChildAgeLinkResult { kFailed,