Base class for generating the updated content of a hotlink cache.

    class API_HotlinkCacheGenerator {
             virtual             ~API_HotlinkCacheGenerator () {};
             virtual GSErrCode   GenerateCacheContentForHotlinkNode (const API_Guid &hotlinkNodeGuid) = 0;       



When a hotlink node is created by the add-on, the content of the hotlink cache must be generated also. In order to create the appropriate elements and attributes into the cache database, you need to pass an API_HotlinkCacheGenerator object to the APIDb_UpdateHotlinkCacheID function. When the GenerateCacheContentForHotlinkNode method of the object is called back from the hotlink update function, the standard element and attribute creator functions (like ACAPI_Element_Create and ACAPI_Attribute_Create) are redirected to create elements and attributes into the hotlink cache database, rather than the project database.

If the GenerateCacheContentForHotlinkNode function return an error, the update process is canceled.



class HotlinkCacheGenerator: public API_HotlinkCacheGenerator {
    virtual GSErrCode    GenerateCacheContentForHotlinkNode (const API_Guid& hotlinkNodeGuid)
        API_HotlinkNode hotlinkNode;
        BNZeroMemory (&hotlinkNode, sizeof (API_HotlinkNode));
        hotlinkNode.guid = hotlinkNodeGuid;
        GSErrCode err = ACAPI_Database (APIDb_GetHotlinkNodeID, &hotlinkNode);
        if (err == NoError && hotlinkNode.sourceLocation != nullptr) {
            IO::File sourceFile (*hotlinkNode.sourceLocation);
            err = sourceFile.GetStatus ();
            if (err == NoError) {
                // read the file, create elements and attributes into the cache database

        if (hotlinkNode.sourceLocation != nullptr)
            delete hotlinkNode.sourceLocation;
        if (hotlinkNode.userData.data != nullptr)
            BMKillPtr (&hotlinkNode.userData.data);

        return err;
} hotlinkCacheGenerator;

GS::HashSet<API_Guid> alreadyUpdatedNodes;
GS::Array<API_Guid> elemList;
ACAPI_Element_GetElemList (API_HotlinkID, &elemList);
for (GS::Array<API_Guid>::ConstIterator it = elemList.Enumerate (); it != nullptr; ++it) {
    API_Element hotlinkElem;
    BNZeroMemory (&hotlinkElem, sizeof (API_Element));
    hotlinkElem.header.guid = *it;
    if (ACAPI_Element_Get (&hotlinkElem) == NoError) {
        if (!alreadyUpdatedNodes.Contains (hotlinkElem.hotlink.hotlinkNodeGuid)) {
            ACAPI_Database (APIDb_UpdateHotlinkCacheID, &hotlinkElem.hotlink.hotlinkNodeGuid, &hotlinkCacheGenerator);
            alreadyUpdatedNodes.Add (hotlinkElem.hotlink.hotlinkNodeGuid);



Version: API 12 or later
Header: APIdefs_Database.h


See Also