#include <assert.h>
#include "NodeMonitor.h"
{
{
return obj;
}
return obj;
}
{
{
nodeName = dagNode.fullPathName();
}
{
nodeName = node.name();
}
return nodeName;
}
NodeMonitor::NodeMonitor(NodeMonitorManager* manager )
{
fNodeName = "";
fIsDirty = false;
fRenamedCallbackId = 0;
fDirtyCallbackId = 0;
fManager = manager;
}
NodeMonitor::~NodeMonitor()
{
stopWatching();
}
bool NodeMonitor::watch(
MString nodeName)
{
stopWatching();
fNodeName = nodeName;
return attachCallbacks();
}
bool NodeMonitor::watch(
MObject nodeObj)
{
MString newNodeName = getNameFromObj(nodeObj);
stopWatching();
if (newNodeName == "")
{
return false;
}
fNodeName = newNodeName;
return attachCallbacks();
}
void NodeMonitor::stopWatching()
{
if (fNodeName != "")
{
detachCallbacks();
fNodeName = "";
fIsDirty = false;
}
}
bool NodeMonitor::dirty()
{
return fIsDirty;
}
void NodeMonitor::cleanIt()
{
if (dirty())
{
attachCallbacks();
}
fIsDirty = false;
}
bool NodeMonitor::attachCallbacks()
{
detachCallbacks();
MObject node = getObjFromName(fNodeName, stat);
if (!stat)
{
detachCallbacks();
return false;
}
fIsDirty = false;
if (stat)
{
}
if (!stat)
{
detachCallbacks();
return false;
}
return true;
}
void NodeMonitor::detachCallbacks()
{
if (fDirtyCallbackId)
{
assert(stat);
}
if (fRenamedCallbackId)
{
assert(stat);
}
fRenamedCallbackId = 0;
fDirtyCallbackId = 0;
}
void NodeMonitor::callbackOccured()
{
fIsDirty = true;
detachCallbacks();
}
void NodeMonitor::watchedObjectDirtyCallback(void* clientData)
{
NodeMonitor* pMon = (NodeMonitor*) clientData;
pMon->callbackOccured();
}
void NodeMonitor::watchedObjectRenamedCallback(
MObject & node,
void* clientData)
{
NodeMonitor* pMon = (NodeMonitor*) clientData;
pMon->fNodeName = getNameFromObj(node);
if (pMon->fManager != NULL)
pMon->fManager->onNodeRenamed(node, oldName, pMon->fNodeName);
pMon->callbackOccured();
}