Ejemplo n.º 1
0
bool Agent::updateAsset (Device *aDevice, const std::string & aId, AssetChangeList & aList,
                         const string & aTime)
{
    AssetPtr asset;
    string   time;

    if ( aTime.empty( ) )
    {
        time = getCurrentTime(GMT_UV_SEC);
    }
    else
    {
        time = aTime;
    }

    {
        dlib::auto_mutex lock(*mAssetLock);

        asset = mAssetMap[aId];

        if ( asset.getObject( ) == NULL )
        {
            return false;
        }

        if ( asset->getType( ) != "CuttingTool" )
        {
            return false;
        }

        CuttingToolPtr tool((CuttingTool *) asset.getObject( ));

        AssetChangeList::iterator iter;

        for ( iter = aList.begin( ); iter != aList.end( ); ++iter )
        {
            if ( iter->first == "xml" )
            {
                mXmlParser->updateAsset(asset, asset->getType( ), iter->second);
            }
            else
            {
                tool->updateValue(iter->first, iter->second);
            }
        }
        tool->setTimestamp(aTime);
        tool->setDeviceUuid(aDevice->getUuid( ));
        tool->changed( );
    }

    addToBuffer(aDevice->getAssetChanged( ), asset->getType( ) + "|" + aId, time);

    return true;
}