Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few blocking/callback issues in the vault API #1486

Merged
merged 7 commits into from
Sep 19, 2023
6 changes: 4 additions & 2 deletions Scripts/Python/nb01DRCImager.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def doneAddingDevice(node,nodeRef,resultCode):
"initializes new imager device with default inbox folder."
PtDebugPrint("nb01DRCImager: doneAddingDevice, result code = %d" % resultCode)

if resultCode == 0:
PtDebugPrint("nb01DRCImager: doneAddingDevice, setting device inbox - %s" % ("DRCImagerState%d" % nb01DRCImager.Instance.current_state))
ptAgeVault().setDeviceInbox("DRCImager", "DRCImagerState%d" % nb01DRCImager.Instance.current_state, doneSettingDeviceInbox)

#====================================
class nb01DRCImager(ptModifier):
Instance = None
Expand Down Expand Up @@ -156,8 +160,6 @@ def OnServerInitComplete(self):

PtDebugPrint("nb01DRCImager.OnServerInitComplete: Adding device")
ptAgeVault().addDevice("DRCImager",doneAddingDevice)
PtDebugPrint("nb01DRCImager.OnServerInitComplete: Setting device inbox - %s" % ("DRCImagerState%d" % self.current_state))
ptAgeVault().setDeviceInbox("DRCImager", "DRCImagerState%d" % self.current_state, doneSettingDeviceInbox)

def OnTimer(self,id):
PtDebugPrint("nb01DRCImager.OnTimer executing")
Expand Down
4 changes: 2 additions & 2 deletions Scripts/Python/nxusBookMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,14 +581,14 @@ def IMakeHoodPublic(self):
hoodInfo = self.IGetHoodInfoNode()
if hoodInfo is not None:
infoStruct = hoodInfo.asAgeInfoStruct()
PtCreatePublicAge(infoStruct, self)
PtCreatePublicAge(infoStruct)


def IMakeHoodPrivate(self):
hoodInfo = self.IGetHoodInfoNode()
if hoodInfo is not None:
guid = hoodInfo.getAgeInstanceGuid()
PtRemovePublicAge(guid, self)
PtRemovePublicAge(guid)

def IPublicAgeCreated(self, ageName):
PtDebugPrint("IPublicAgeCreated: " + ageName)
Expand Down
14 changes: 4 additions & 10 deletions Scripts/Python/plasma/Plasma.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ def PtCreatePlayer(playerName, avatarShape, invitation):
"""Creates a new player"""
pass

def PtCreatePublicAge(ageInfo, cbObject=None):
"""Create a public instance of the given age.
cbObject, if supplied should have a member called publicAgeCreated(self,ageInfo)"""
def PtCreatePublicAge(ageInfo):
"""Create a public instance of the given age."""
pass

def PtDebugAssert(cond, msg):
Expand Down Expand Up @@ -686,9 +685,8 @@ def PtRecenterCamera():
"""re-centers the camera"""
pass

def PtRemovePublicAge(ageInstanceGuid, cbObject=None):
"""Remove a public instance of the given age.
cbObject, if supplied should have a member called publicAgeRemoved(self,ageInstanceGuid)"""
def PtRemovePublicAge(ageInstanceGuid):
"""Remove a public instance of the given age."""
pass

def PtRequestLOSScreen(selfKey,ID,xPos,yPos,distance,what,reportType):
Expand Down Expand Up @@ -6531,10 +6529,6 @@ def registerVisitAge(self,link):
"""Register this age as visitable by this player"""
pass

def sendToDevice(self,node,deviceName):
"""Sends a ptVaultNode object to an Age's device by deviceName."""
pass

def setAgePublic(self,ageInfo,makePublic):
"""Makes the specified age public or private"""
pass
Expand Down
6 changes: 3 additions & 3 deletions Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ PF_CONSOLE_CMD( Net_Vault,
"string stationName, string mtSpawnPt",
"Register an MT Station with your Nexus" )
{
VaultRegisterMTStationAndWait(params[0], params[1]);
VaultRegisterMTStation(params[0], params[1]);
PrintString("Registered MT Station.");
}

Expand Down Expand Up @@ -779,7 +779,7 @@ PF_CONSOLE_CMD( Net_Vault,
{
plAgeInfoStruct info;
info.SetAgeFilename(params[0]);
bool success = VaultUnregisterOwnedAgeAndWait(&info);
bool success = VaultUnregisterOwnedAge(&info);
PrintString(ST::format("Operation {}.", success ? "Successful" : "Failed"));
}

Expand Down Expand Up @@ -809,7 +809,7 @@ PF_CONSOLE_CMD( Net_Vault,
info.SetAgeFilename(params[0]);

unsigned count = 0;
while (VaultUnregisterVisitAgeAndWait(&info))
while (VaultUnregisterVisitAge(&info))
++count;

PrintString(ST::format("Operation {}.", count > 0 ? "Successful" : "Failed"));
Expand Down
14 changes: 6 additions & 8 deletions Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2189,30 +2189,28 @@ void cyMisc::GetPublicAgeList(const ST::string& ageName, PyObject * cbObject)
//////////////////////////////////////////////////////////////////////////////
//
// Function : CreatePublicAge
// PARAMETERS : ageInfo, callback object
// PARAMETERS : ageInfo
//
// PURPOSE : Add a public age to the list of available ones.
//
void cyMisc::CreatePublicAge( pyAgeInfoStruct * ageInfo, PyObject * cbObject )
void cyMisc::CreatePublicAge(pyAgeInfoStruct* ageInfo)
{
VaultSetOwnedAgePublicAndWait(ageInfo->GetAgeInfo(), true);
// TODO: make the callback here
VaultSetOwnedAgePublic(ageInfo->GetAgeInfo(), true);
}

//////////////////////////////////////////////////////////////////////////////
//
// Function : RemovePublicAge
// PARAMETERS : ageInstanceGuid, callback object
// PARAMETERS : ageInstanceGuid
//
// PURPOSE : Remove a public age from the list of available ones.
//
void cyMisc::RemovePublicAge(const ST::string& ageInstanceGuid, PyObject * cbObject/*=nullptr */)
void cyMisc::RemovePublicAge(const ST::string& ageInstanceGuid)
{
plAgeInfoStruct info;
plUUID uuid(ageInstanceGuid);
info.SetAgeInstanceGuid(&uuid);
VaultSetOwnedAgePublicAndWait(&info, false);
// TODO: make the callback here
VaultSetOwnedAgePublic(&info, false);
}

int cyMisc::GetKILevel()
Expand Down
8 changes: 4 additions & 4 deletions Sources/Plasma/FeatureLib/pfPython/cyMisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,20 +753,20 @@ class cyMisc
//////////////////////////////////////////////////////////////////////////////
//
// Function : CreatePublicAge
// PARAMETERS : ageInfo, callback object
// PARAMETERS : ageInfo
//
// PURPOSE : Add a public age to the list of available ones.
//
static void CreatePublicAge(pyAgeInfoStruct * ageInfo, PyObject * cbObject = nullptr);
static void CreatePublicAge(pyAgeInfoStruct* ageInfo);

//////////////////////////////////////////////////////////////////////////////
//
// Function : RemovePublicAge
// PARAMETERS : ageInstanceGuid, callback object
// PARAMETERS : ageInstanceGuid
//
// PURPOSE : Remove a public age from the list of available ones.
//
static void RemovePublicAge(const ST::string& ageInstanceGuid, PyObject * cbObject = nullptr);
static void RemovePublicAge(const ST::string& ageInstanceGuid);

//////////////////////////////////////////////////////////////////////////////
//
Expand Down
22 changes: 9 additions & 13 deletions Sources/Plasma/FeatureLib/pfPython/cyMiscGlue4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,37 +243,33 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtGetPublicAgeList, args, "Params: ageName, cbOb
PYTHON_RETURN_NONE;
}

PYTHON_GLOBAL_METHOD_DEFINITION(PtCreatePublicAge, args, "Params: ageInfo, cbObject=None\nCreate a public instance of the given age.\n"
"cbObject, if supplied should have a member called publicAgeCreated(self,ageInfo)")
PYTHON_GLOBAL_METHOD_DEFINITION(PtCreatePublicAge, args, "Params: ageInfo\nCreate a public instance of the given age.")
{
PyObject* ageInfoObj = nullptr;
PyObject* cbObject = nullptr;
if (!PyArg_ParseTuple(args, "O|O", &ageInfoObj, &cbObject))
if (!PyArg_ParseTuple(args, "O", &ageInfoObj))
{
PyErr_SetString(PyExc_TypeError, "PtCreatePublicAge expects a ptAgeInfoStruct object and an optional object with a publicAgeCreated() method");
PyErr_SetString(PyExc_TypeError, "PtCreatePublicAge expects a ptAgeInfoStruct object");
PYTHON_RETURN_ERROR;
}
if (!pyAgeInfoStruct::Check(ageInfoObj))
{
PyErr_SetString(PyExc_TypeError, "PtCreatePublicAge expects a ptAgeInfoStruct object and an optional object with a publicAgeCreated() method");
PyErr_SetString(PyExc_TypeError, "PtCreatePublicAge expects a ptAgeInfoStruct object");
PYTHON_RETURN_ERROR;
}
pyAgeInfoStruct* ageInfo = pyAgeInfoStruct::ConvertFrom(ageInfoObj);
cyMisc::CreatePublicAge(ageInfo, cbObject);
cyMisc::CreatePublicAge(ageInfo);
PYTHON_RETURN_NONE;
}

PYTHON_GLOBAL_METHOD_DEFINITION(PtRemovePublicAge, args, "Params: ageInstanceGuid, cbObject=None\nRemove a public instance of the given age.\n"
"cbObject, if supplied should have a member called publicAgeRemoved(self,ageInstanceGuid)")
PYTHON_GLOBAL_METHOD_DEFINITION(PtRemovePublicAge, args, "Params: ageInstanceGuid\nRemove a public instance of the given age.")
{
ST::string ageInstanceGUID;
PyObject* cbObject = nullptr;
if (!PyArg_ParseTuple(args, "O&|O", PyUnicode_STStringConverter, &ageInstanceGUID, &cbObject))
if (!PyArg_ParseTuple(args, "O&", PyUnicode_STStringConverter, &ageInstanceGUID))
{
PyErr_SetString(PyExc_TypeError, "PtRemovePublicAge expects a string and an optional object with a publicAgeRemoved() method");
PyErr_SetString(PyExc_TypeError, "PtRemovePublicAge expects a string");
PYTHON_RETURN_ERROR;
}
cyMisc::RemovePublicAge(ageInstanceGUID, cbObject);
cyMisc::RemovePublicAge(ageInstanceGUID);
PYTHON_RETURN_NONE;
}

Expand Down
26 changes: 16 additions & 10 deletions Sources/Plasma/FeatureLib/pfPython/pyAgeVault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,21 @@ void pyAgeVault::AddChronicleEntry( const ST::string& name, uint32_t type, const
VaultAddAgeChronicleEntry(name, type, value);
}

static void _AddDeviceCallback(ENetError result, hsRef<RelVaultNode> device, void* param)
{
auto cb = static_cast<pyVaultNode::pyVaultNodeOperationCallback*>(param);
cb->SetNode(std::move(device));
cb->VaultOperationComplete(result);
}

// AGE DEVICES. AKA IMAGERS, WHATEVER.
// Add a new device.
void pyAgeVault::AddDevice(const ST::string& deviceName, PyObject * cbObject, uint32_t cbContext)
{
pyVaultNode::pyVaultNodeOperationCallback * cb = new pyVaultNode::pyVaultNodeOperationCallback( cbObject );
cb->VaultOperationStarted( cbContext );

if (hsRef<RelVaultNode> rvn = VaultAgeAddDeviceAndWait(deviceName))
cb->SetNode(rvn);

// cb deletes itself here.
cb->VaultOperationComplete(cbContext, cb->GetNode() ? kNetSuccess : kNetErrInternalError);
VaultAgeAddDevice(deviceName, _AddDeviceCallback, cb);
}

// Remove a device.
Expand All @@ -210,17 +213,20 @@ PyObject * pyAgeVault::GetDevice(const ST::string& deviceName)
PYTHON_RETURN_NONE;
}

static void _SetDeviceInboxCallback(ENetError result, hsRef<RelVaultNode> inbox, void* param)
{
auto cb = static_cast<pyVaultNode::pyVaultNodeOperationCallback*>(param);
cb->SetNode(std::move(inbox));
cb->VaultOperationComplete(result);
}

// Sets the inbox associated with a device.
void pyAgeVault::SetDeviceInbox(const ST::string& deviceName, const ST::string& inboxName, PyObject * cbObject, uint32_t cbContext)
{
pyVaultNode::pyVaultNodeOperationCallback * cb = new pyVaultNode::pyVaultNodeOperationCallback( cbObject );
cb->VaultOperationStarted( cbContext );

if (hsRef<RelVaultNode> rvn = VaultAgeSetDeviceInboxAndWait(deviceName, inboxName))
cb->SetNode(rvn);

// cb deletes itself here.
cb->VaultOperationComplete(cbContext, cb->GetNode() ? kNetSuccess : kNetErrInternalError);
VaultAgeSetDeviceInbox(deviceName, inboxName, _SetDeviceInboxCallback, cb);
}

PyObject * pyAgeVault::GetDeviceInbox(const ST::string& deviceName)
Expand Down
25 changes: 6 additions & 19 deletions Sources/Plasma/FeatureLib/pfPython/pyVault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,6 @@ void pyVault::AddChronicleEntry(const ST::string& name, uint32_t type, const ST:
}


void pyVault::SendToDevice(pyVaultNode& node, const ST::string& deviceName)
{
if (!node.GetNode())
return;

// Note: This actually blocks (~Hoikas)
VaultPublishNode(node.GetNode()->GetNodeId(), deviceName);
}


PyObject* pyVault::GetAgesICanVisitFolder()
{
PyObject * result = GetAgeInfoList(plVault::kAgesICanVisitFolder);
Expand Down Expand Up @@ -468,8 +458,7 @@ bool pyVault::AmAgeCzar( const pyAgeInfoStruct * ageInfo )

void pyVault::RegisterMTStation( const ST::string& stationName, const ST::string& backLinkSpawnPtObjName )
{
// Note: This doesn't actually block (~Hoikas)
VaultRegisterMTStationAndWait(stationName, backLinkSpawnPtObjName);
VaultRegisterMTStation(stationName, backLinkSpawnPtObjName);
}

void pyVault::RegisterOwnedAge( const pyAgeLinkStruct & link )
Expand All @@ -481,7 +470,7 @@ void pyVault::UnRegisterOwnedAge(const ST::string& ageFilename)
{
plAgeInfoStruct info;
info.SetAgeFilename(ageFilename);
VaultUnregisterOwnedAgeAndWait(&info);
VaultUnregisterOwnedAge(&info);
}

void pyVault::RegisterVisitAge( const pyAgeLinkStruct & link )
Expand All @@ -494,7 +483,7 @@ void pyVault::UnRegisterVisitAge(const ST::string& guidstr)
plAgeInfoStruct info;
plUUID guid(guidstr);
info.SetAgeInstanceGuid(&guid);
VaultUnregisterVisitAgeAndWait(&info);
VaultUnregisterVisitAge(&info);
}

//============================================================================
Expand Down Expand Up @@ -554,10 +543,9 @@ void pyVault::CreateNeighborhood()
plNetClientMgr * nc = plNetClientMgr::GetInstance();

// Unregister old hood
// Note: This doesn't actually block (~Hoikas)
plAgeInfoStruct info;
info.SetAgeFilename(kNeighborhoodAgeFilename);
VaultUnregisterOwnedAgeAndWait(&info);
VaultUnregisterOwnedAge(&info);

// Register new hood
plAgeLinkStruct link;
Expand Down Expand Up @@ -588,13 +576,12 @@ void pyVault::CreateNeighborhood()

bool pyVault::SetAgePublic( const pyAgeInfoStruct * ageInfo, bool makePublic )
{
// Note: This doesn't actually block (~Hoikas)
return VaultSetOwnedAgePublicAndWait(ageInfo->GetAgeInfo(), makePublic);
return VaultSetOwnedAgePublic(ageInfo->GetAgeInfo(), makePublic);
}

bool pyVault::SetAgePublic( const pyVaultAgeInfoNode * ageInfoNode, bool makePublic )
{
return VaultSetAgePublicAndWait(ageInfoNode->GetNode(), makePublic);
return VaultSetAgePublic(ageInfoNode->GetNode(), makePublic);
}


Expand Down
3 changes: 0 additions & 3 deletions Sources/Plasma/FeatureLib/pfPython/pyVault.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ class pyVault
PyObject* FindChronicleEntry(const ST::string& entryName); // returns pyVaultChronicleNode
void AddChronicleEntry(const ST::string& name, uint32_t type, const ST::string& value);
///////////////
// publishing
void SendToDevice(pyVaultNode& node, const ST::string& deviceName);
///////////////
// yeesha pages, etc.
PyObject* GetPsnlAgeSDL() const; // returns pySDLStateDataRecord
void UpdatePsnlAgeSDL( pySDLStateDataRecord & rec );
Expand Down
20 changes: 0 additions & 20 deletions Sources/Plasma/FeatureLib/pfPython/pyVaultGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,25 +228,6 @@ PYTHON_METHOD_DEFINITION(ptVault, findNode, args)
return self->fThis->FindNode(templateNode);
}

PYTHON_METHOD_DEFINITION(ptVault, sendToDevice, args)
{
PyObject* nodeObj = nullptr;
ST::string deviceName;
if (!PyArg_ParseTuple(args, "OO&", &nodeObj, PyUnicode_STStringConverter, &deviceName))
{
PyErr_SetString(PyExc_TypeError, "sendToDevice expects a ptVaultNode and a string");
PYTHON_RETURN_ERROR;
}
if (!pyVaultNode::Check(nodeObj))
{
PyErr_SetString(PyExc_TypeError, "sendToDevice expects a ptVaultNode and a string");
PYTHON_RETURN_ERROR;
}
pyVaultNode* node = pyVaultNode::ConvertFrom(nodeObj);
self->fThis->SendToDevice(*node, deviceName);
PYTHON_RETURN_NONE;
}

PYTHON_METHOD_DEFINITION_NOARGS(ptVault, getPsnlAgeSDL)
{
return self->fThis->GetPsnlAgeSDL();
Expand Down Expand Up @@ -501,7 +482,6 @@ PYTHON_START_METHODS_TABLE(ptVault)
PYTHON_BASIC_METHOD(ptVault, createGlobalInbox, "Creates the global inbox folder."),
#endif
PYTHON_METHOD(ptVault, findNode, "Params: templateNode\nFind the node matching the template"),
PYTHON_METHOD(ptVault, sendToDevice, "Params: node,deviceName\nSends a ptVaultNode object to an Age's device by deviceName."),
PYTHON_METHOD_NOARGS(ptVault, getPsnlAgeSDL, "Returns the personal age SDL"),
PYTHON_METHOD(ptVault, updatePsnlAgeSDL, "Params: pyrec\nUpdates the personal age SDL to the specified data"),
PYTHON_METHOD_NOARGS(ptVault, inMyPersonalAge, "Are we in the player's personal age?"),
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void pyVaultPlayerNode::RemoveOwnedAgeLink(const ST::string& ageFilename)
{
plAgeInfoStruct info;
info.SetAgeFilename(ageFilename);
VaultUnregisterOwnedAgeAndWait(&info);
VaultUnregisterOwnedAge(&info);
}

PyObject *pyVaultPlayerNode::GetVisitAgeLink(const pyAgeInfoStruct *info)
Expand All @@ -214,7 +214,7 @@ void pyVaultPlayerNode::RemoveVisitAgeLink(const ST::string& guidstr)
plAgeInfoStruct info;
plUUID guid(guidstr);
info.SetAgeInstanceGuid(&guid);
VaultUnregisterOwnedAgeAndWait(&info);
VaultUnregisterOwnedAge(&info);
}

PyObject *pyVaultPlayerNode::FindChronicleEntry(const ST::string& entryName)
Expand Down
Loading