Browse Source

Make adding pyVaultNodeRefs async

Adam Johnson 14 years ago
parent
commit
f4021846a4
  1. 29
      Sources/Plasma/FeatureLib/pfPython/pyVaultNode.cpp
  2. 2
      Sources/Plasma/FeatureLib/pfPython/pyVaultNode.h

29
Sources/Plasma/FeatureLib/pfPython/pyVaultNode.cpp

@ -92,6 +92,7 @@ pyVaultNode::pyVaultNodeOperationCallback::~pyVaultNodeOperationCallback()
void pyVaultNode::pyVaultNodeOperationCallback::VaultOperationStarted( UInt32 context ) void pyVaultNode::pyVaultNodeOperationCallback::VaultOperationStarted( UInt32 context )
{ {
fContext = context;
if ( fCbObject ) if ( fCbObject )
{ {
// Call the callback. // Call the callback.
@ -391,6 +392,14 @@ void pyVaultNode::SetCreateAgeGuid( const char * v )
// Vault Node API // Vault Node API
// Add child node // Add child node
void _AddNodeCallback(ENetError result, void* param) {
pyVaultNode::pyVaultNodeOperationCallback* cb = (pyVaultNode::pyVaultNodeOperationCallback*)param;
if (IS_NET_SUCCESS(result))
cb->VaultOperationComplete(hsOK);
else
cb->VaultOperationComplete(hsFail);
}
PyObject* pyVaultNode::AddNode(pyVaultNode* pynode, PyObject* cbObject, UInt32 cbContext) PyObject* pyVaultNode::AddNode(pyVaultNode* pynode, PyObject* cbObject, UInt32 cbContext)
{ {
pyVaultNodeOperationCallback * cb = NEWZERO(pyVaultNodeOperationCallback)(cbObject); pyVaultNodeOperationCallback * cb = NEWZERO(pyVaultNodeOperationCallback)(cbObject);
@ -421,21 +430,23 @@ PyObject* pyVaultNode::AddNode(pyVaultNode* pynode, PyObject* cbObject, UInt32 c
} }
} }
// Block here until we have the child node =( VaultAddChildNode(fNode->nodeId,
VaultAddChildNodeAndWait(fNode->nodeId, pynode->fNode->nodeId, NetCommGetPlayer()->playerInt); pynode->fNode->nodeId,
NetCommGetPlayer()->playerInt,
(FVaultAddChildNodeCallback)_AddNodeCallback,
cb
);
PyObject * nodeRef = cb->fPyNodeRef = pyVaultNodeRef::New(fNode, pynode->fNode); PyObject * nodeRef = cb->fPyNodeRef = pyVaultNodeRef::New(fNode, pynode->fNode);
Py_INCREF(nodeRef); // incref it, because we MUST return a new PyObject, and the callback "steals" the ref from us Py_INCREF(nodeRef); // incref it, because we MUST return a new PyObject, and the callback "steals" the ref from us
cb->SetNode(pynode->fNode); cb->SetNode(pynode->fNode);
cb->VaultOperationComplete(cbContext, hsResult);
return nodeRef; return nodeRef;
} }
else else
{ {
// manually make the callback // manually make the callback
cb->VaultOperationStarted( cbContext ); cb->VaultOperationStarted( cbContext );
cb->VaultOperationComplete( cbContext, hsFail ); cb->VaultOperationComplete(hsFail);
} }
// just return a None object // just return a None object
@ -452,14 +463,18 @@ void pyVaultNode::LinkToNode(int nodeID, PyObject* cbObject, UInt32 cbContext)
// Hack the callbacks until vault notification is in place // Hack the callbacks until vault notification is in place
cb->VaultOperationStarted( cbContext ); cb->VaultOperationStarted( cbContext );
VaultAddChildNodeAndWait(fNode->nodeId, nodeID, NetCommGetPlayer()->playerInt);
if (RelVaultNode * rvn = VaultGetNodeIncRef(nodeID)) { if (RelVaultNode * rvn = VaultGetNodeIncRef(nodeID)) {
cb->SetNode(rvn); cb->SetNode(rvn);
cb->fPyNodeRef = pyVaultNodeRef::New(fNode, rvn); cb->fPyNodeRef = pyVaultNodeRef::New(fNode, rvn);
rvn->DecRef(); rvn->DecRef();
} }
cb->VaultOperationComplete( cbContext, hsOK ); VaultAddChildNode(fNode->nodeId,
nodeID,
NetCommGetPlayer()->playerInt,
(FVaultAddChildNodeCallback)_AddNodeCallback,
cb
);
} }
else else
{ {

2
Sources/Plasma/FeatureLib/pfPython/pyVaultNode.h

@ -69,12 +69,14 @@ public:
PyObject * fCbObject; PyObject * fCbObject;
RelVaultNode * fNode; RelVaultNode * fNode;
PyObject * fPyNodeRef; PyObject * fPyNodeRef;
UInt32 fContext;
pyVaultNodeOperationCallback(PyObject * cbObject); pyVaultNodeOperationCallback(PyObject * cbObject);
~pyVaultNodeOperationCallback(); ~pyVaultNodeOperationCallback();
void VaultOperationStarted(UInt32 context); void VaultOperationStarted(UInt32 context);
void VaultOperationComplete(UInt32 context, int resultCode); void VaultOperationComplete(UInt32 context, int resultCode);
void VaultOperationComplete(int resultCode) { VaultOperationComplete(fContext, resultCode); }
void SetNode (RelVaultNode * rvn); void SetNode (RelVaultNode * rvn);
RelVaultNode * GetNode (); RelVaultNode * GetNode ();

Loading…
Cancel
Save