From af5b9e800b83104896f26087a20b514ab70e677d Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Fri, 7 Feb 2025 11:21:54 +0100 Subject: [PATCH 01/27] Correction of typos and comments in header file --- src/AyonCppApi/AyonCppApi.h | 147 ++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 75 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.h b/src/AyonCppApi/AyonCppApi.h index 37c2e70..d09d08b 100644 --- a/src/AyonCppApi/AyonCppApi.h +++ b/src/AyonCppApi/AyonCppApi.h @@ -16,14 +16,13 @@ /** * @class AyonApi - * @brief Central Ayon api class \n + * @brief Central Ayon api class * Class for exposing Ayon server functions to C++ users. Uses httplib internally for communication with the server - * */ class AyonApi { public: /** - * @brief constructor + * @brief Constructor */ AyonApi(const std::string &logFilePos, const std::string &authKey, @@ -32,137 +31,134 @@ class AyonApi { const std::string &siteId, std::optional concurrency = std::nullopt); /** - * @brief destructor + * @brief Destructor */ ~AyonApi(); /** - * @brief returns the stored apikey. Retrieved from the appropriate env variable. (the variable is loaded from - * loadEnvVars()) + * @brief Returns the stored API key. Passed in the constructor. */ std::string getKey(); /** - * @brief returns the stored AYON server url. Retrieved from the appropriate env variable. (the variable is - * loaded from loadEnvVars()) + * @brief Returns the stored AYON server URL. Passed in the constructor. */ std::string getUrl(); /** - * @brief runns a get command and returns the response body as std::string + * @brief Runs a GET command * - * @param endPoint reachable http / https endpoint - * @param headers http headers - * @param sucsessStatus define what http response code should be considered a success. + * @param endPoint Reachable HTTP/HTTPS endpoint + * @param headers HTTP headers + * @param successStatus Defines what HTTP response code should be considered a success. + * @return The response body as nlohmann::json */ nlohmann::json GET(const std::shared_ptr endPoint, const std::shared_ptr headers, - uint8_t sucsessStatus); + uint8_t successStatus); /** - * @brief post Request via a shared httplib client ( serial ) + * @brief POST request via a shared httplib client (serial) * - * @param endPoint the AYON enpoint to hit - * @param headers the http header that you want to send - * @param jsonPayload the payload in json format - * @param sucsessStatus defines what status code is considered a success and brakes the retry loop. + * @param endPoint The AYON endpoint to hit + * @param headers The HTTP headers to send + * @param jsonPayload The payload in JSON format + * @param successStatus Defines what status code is considered a success and breaks the retry loop + * @return The response body as nlohmann::json */ nlohmann::json SPOST(const std::shared_ptr endPoint, const std::shared_ptr headers, nlohmann::json jsonPayload, - const std::shared_ptr sucsessStatus); + const std::shared_ptr successStatus); /** - * @brief http post request utilizing the creation of a new httplib client ( Generative Async ) + * @brief HTTP POST request utilizing the creation of a new httplib client (Generative Async) * - * @param endPoint the AYON enpoint to hit - * @param headers the http header that you want to send - * @param jsonPayload the payload in json format - * @param sucsessStatus defines what status code is considered a success and brakes the retry loop. + * @param endPoint The AYON endpoint to hit + * @param headers The HTTP headers to send + * @param jsonPayload The payload in JSON format + * @param successStatus Defines what status code is considered a success and breaks the retry loop. + * @return The response body as nlohmann::json */ nlohmann::json CPOST(const std::shared_ptr endPoint, const std::shared_ptr headers, nlohmann::json jsonPayload, - const std::shared_ptr sucsessStatus); + const std::shared_ptr successStatus); /** - * @brief uses the uri resolve endpoint on the AYON server in order to resolve an uri path towards the local - * path \n gets the siteId from an variable stored in the class + * @brief Uses the URI resolve endpoint on the AYON server to resolve a URI path to the local path. + * Gets the siteId from a variable stored in the class. * - * @param uriPath + * @param uriPath The URI path to resolve. + * @return A pair containing the asset identifier (ayon:// path) and the machine local file location. */ std::pair resolvePath(const std::string &uriPath); - /** - * @brief resolves a vector off paths against the AYON server in an async way uses auto generated batch requests - * - * @param uriPaths - */ - std::unordered_map batchResolvePath(std::vector &uriPaths); /** - * @brief this function takes a ayon path uri response(resolved ayon://path) and returns a pair of - * assetIdentifier(ayon:// path) and the machine local file location + * @brief Resolves a vector of paths against the AYON server asynchronously using auto-generated batch requests. * - * @param uriResolverRespone json representation off the resolves the ayon/api/resolve endpoint returns + * @param uriPaths The vector of URI paths to resolve. + * @return An unordered map containing the resolved paths. */ - std::pair getAssetIdent(const nlohmann::json &uriResolverRespone); + std::unordered_map batchResolvePath(std::vector &uriPaths); /** - * @brief this function loads all needed varible into the class \n - * this will allso be called by the constructor + * @brief Takes an AYON path URI response (resolved ayon://path) and returns a pair of + * asset identifier (ayon:// path) and the machine local file location. * - * @return + * @param uriResolverResponse JSON representation of the response from the AYON API resolve endpoint. + * @return A pair containing the asset identifier and the machine local file location. */ - bool loadEnvVars(); + std::pair getAssetIdent(const nlohmann::json &uriResolverResponse); /** - * @brief get function for shared AyonLogger pointer used by this class instance + * @brief Get function for shared AyonLogger pointer used by this class instance */ std::shared_ptr logPointer(); /** - * @brief gets the site root overwrites for the current project. Current project is defined via an env variable + * @brief Gets the site root overwrites for the current project. Current project is defined via an env variable * for now */ std::unordered_map* getSiteRoots(); // TODO think about if this should only support current project or multiple projects /** - * @brief replaces {root[var]} for ayon:// paths + * @brief Replaces {root[var]} for ayon:// paths. * - * @param rootLessPath endpoint response for ayon://path with {root[var]} available if no root can be found the - * path will be returned as is + * @param rootLessPath Endpoint response for ayon://path with {root[var]}. + * If no root can be found, the path will be returned as is. */ std::string rootReplace(const std::string &rootLessPath); private: /** - * @brief calls the server in an serial way by sharing the AyonServer pointer + * @brief Calls the server in a serial way by sharing the AyonServer pointer. * - * @param endPoint endpoint that ayon resolve is loaded on - * @param headers http headers - * @param Payload json payload to be resolved by endpoint - * @param sucsessStatus defines what is considered a success response to break the retry loop + * @param endPoint Endpoint that AYON resolve is loaded on. + * @param headers HTTP headers. + * @param payload JSON payload to be resolved by endpoint. + * @param successStatus Defines what is considered a success response to break the retry loop. */ std::string serialCorePost(const std::string &endPoint, httplib::Headers headers, - std::string &Payload, - const int &sucsessStatus); + std::string &payload, + const int &successStatus); /** - * @brief calls the server while creating a new client instance to stay async + * @brief Calls the server while creating a new client instance to stay async. * - * @param endPoint endpoint that ayon resolve is loaded on - * @param headers http headers - * @param Payload json payload to be resolved by endpoint - * @param sucsessStatus defines what is considered a success response to break the retry loop + * @param endPoint Endpoint that AYON resolve is loaded on. + * @param headers HTTP headers. + * @param payload JSON payload to be resolved by endpoint. + * @param successStatus Defines what is considered a success response to break the retry loop. */ std::string GenerativeCorePost(const std::string &endPoint, httplib::Headers headers, - std::string &Payload, - const int &sucsessStatus); + std::string &payload, + const int &successStatus); /** - * @brief converts a vector off uris into an string to serve into CorePost funcs + * @brief Converts a vector of URIs into a string to serve into CorePost functions. * - * @param uriVec vector off str uris + * @param uriVec Vector of string URIs. */ std::string convertUriVecToString(const std::vector &uriVec); @@ -174,6 +170,7 @@ class AyonApi { const std::string m_authKey; const std::string m_serverUrl; std::string m_ayonProjectName; + httplib::Headers m_headers; // ---- Server Vars std::string m_siteId; @@ -181,33 +178,33 @@ class AyonApi { // --- Runtime Dep Vars - // Async Grp Generation Varibles + // Async Grp Generation Varaibles uint8_t m_minGrpSizeForAsyncRequests = 10; uint16_t m_regroupSizeForAsyncRequests = 200; uint16_t m_maxGroupSizeForAsyncRequests = 300; uint16_t m_minVecSizeForGroupSplitAsyncRequests = 50; - uint8_t m_maxCallRetrys = 8; - uint16_t m_retryWaight = 800; + uint8_t m_maxCallRetries = 8; + uint16_t m_retryWait = 800; /** - * @brief maximum number off threads that the cpu can handle at the same time. Will be set via constructor + * @brief maximum number of threads that the CPU can handle at the same time. Will be set via constructor */ const int m_num_threads; // set by constructor std::shared_ptr m_Log; std::string m_uriResolverEndpoint = "/api/resolve"; std::string m_uriResolverEndpointPathOnlyVar = "?pathOnly=true"; - bool m_pathOnlyReselution = true; + bool m_pathOnlyResolution = true; - std::mutex m_ConcurentRequestAfterffoMutex; - uint8_t m_maxConcurentRequestAfterffo = 8; + std::mutex m_ConcurrentRequestAfterffoMutex; + uint8_t m_maxConcurrentRequestAfterffo = 8; uint16_t m_GenerativeCorePostMaxLoopIterations = 200; - uint16_t m_connectionTimeOutMax = 200; - uint8_t m_readTimeOutMax = 160; + uint16_t m_connectionTimeoutMax = 200; + uint8_t m_readTimeoutMax = 160; /** - * @brief decides if the cpp api removes duplicates from batch request vector default is true + * @brief Decides if the cpp API removes duplicates from batch request vector. Default is true */ bool m_batchResolveOptimizeVector = true; @@ -215,12 +212,12 @@ class AyonApi { uint16_t m_RequestDelayWhenServerBusy = 10000; /** - * @brief this bool will be set to true if a 503 is encountered + * @brief This bool will be set to true if a 503 is encountered */ bool m_serverBusy = false; /** - * @brief needed for serial resolve operations. to lock acces to AyonServer shared pointer + * @brief Needed for serial resolve operations. to lock access to AyonServer shared pointer */ std::mutex m_AyonServerMutex; }; From 57b9b7ab31b1a5a89fc16ea7f3fbbff00c6ef915 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Fri, 7 Feb 2025 11:22:43 +0100 Subject: [PATCH 02/27] Correction of typos and comments in source file --- src/AyonCppApi/AyonCppApi.cpp | 244 +++++++++++++++++----------------- 1 file changed, 122 insertions(+), 122 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index 231be7f..3cd77cf 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -32,7 +32,7 @@ #include "backward.hpp" #include "perfPrinter.h" -// TODO implement the better Crash hanlder +// TODO implement the better Crash handler backward::StackTrace st; AyonApi::AyonApi(const std::string &logFilePos, @@ -99,24 +99,24 @@ AyonApi::rootReplace(const std::string &rootLessPath) { m_Log->info(m_Log->key("AyonApi"), "AyonApi::rootReplace({})", rootLessPath); std::string rootedPath; - std::smatch matchea; + std::smatch matchesA; std::regex rootFindPattern("\\{root\\[.*?\\]\\}"); - if (std::regex_search(rootLessPath, matchea, rootFindPattern)) { - std::string siteRootOverwriteName = matchea.str(0); - - std::smatch matcheb; - std::regex rootBraketPattern("\\[(.*?)\\]"); - if (std::regex_search(rootLessPath, matcheb, rootBraketPattern)) { - std::string breakedString = matcheb.str(0); - breakedString = breakedString.substr(1, breakedString.length() - 2); + if (std::regex_search(rootLessPath, matchesA, rootFindPattern)) { + std::string siteRootOverwriteName = matchesA.str(0); + + std::smatch matchesB; + std::regex rootBracketPattern("\\[(.*?)\\]"); + if (std::regex_search(rootLessPath, matchesB, rootBracketPattern)) { + std::string bracketedString = matchesB.str(0); + bracketedString = bracketedString.substr(1, bracketedString.length() - 2); try { - std::string replacement = m_siteRoots.at(breakedString); + std::string replacement = m_siteRoots.at(bracketedString); rootedPath = std::regex_replace(rootLessPath, rootFindPattern, replacement); m_Log->info(m_Log->key("AyonApi"), "AyonApi::rootReplace({}) rooted", rootedPath); return rootedPath; } catch (std::out_of_range &e) { - m_Log->warn("AyonApi::rootedPath error acured {}, list off available root replace str: "); + m_Log->warn("AyonApi::rootedPath error occurred {}, list of available root replace str: "); for (auto &g: m_siteRoots) { m_Log->warn("Key: {}, replacement: {}", g.first, g.second); } @@ -131,41 +131,41 @@ AyonApi::rootReplace(const std::string &rootLessPath) { nlohmann::json AyonApi::GET(const std::shared_ptr endPoint, const std::shared_ptr headers, - uint8_t sucsessStatus) { + uint8_t successStatus) { PerfTimer("AyonApi::GET"); m_Log->info(m_Log->key("AyonApi"), "AyonApi::GET({})", *endPoint); httplib::Result response; - int responeStatus; - uint8_t retryes = 0; - while (retryes <= m_maxCallRetrys) { + int responseStatus; + uint8_t retries = 0; + while (retries <= m_maxCallRetries) { try { response = m_AyonServer->Get(*endPoint, *headers); - responeStatus = response->status; - retryes++; + responseStatus = response->status; + retries++; - if (responeStatus == sucsessStatus) { + if (responseStatus == successStatus) { return nlohmann::json::parse(response->body); } else { - m_Log->info("AyonApi::serialCorePost wrong status code: {} expected: {}", responeStatus, sucsessStatus); - if (responeStatus == 401) { + m_Log->info("AyonApi::serialCorePost wrong status code: {} expected: {}", responseStatus, successStatus); + if (responseStatus == 401) { m_Log->warn("not logged in 401 "); return nlohmann::json(); } - if (responeStatus == 500) { + if (responseStatus == 500) { m_Log->warn("internal server error "); return nlohmann::json(); } std::this_thread::sleep_for(std::chrono::milliseconds( - responeStatus == m_ServerBusyCode ? m_RequestDelayWhenServerBusy : m_retryWaight)); + responseStatus == m_ServerBusyCode ? m_RequestDelayWhenServerBusy : m_retryWait)); } } // TODO error reason not printed catch (const httplib::Error &e) { - m_Log->warn("Request Failed because: {}"); + m_Log->warn("Request Failed because: {}"); // maybe just e - httplib::Error is just enum class break; } - m_Log->warn("The connection failed Rety now."); + m_Log->warn("The connection failed. Retry now."); } return nlohmann::json(); }; @@ -174,70 +174,70 @@ nlohmann::json AyonApi::SPOST(const std::shared_ptr endPoint, const std::shared_ptr headers, nlohmann::json jsonPayload, - const std::shared_ptr sucsessStatus) { + const std::shared_ptr successStatus) { PerfTimer("AyonApi::SPOST"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::SPOST endPoint: {}, jsonPayload: {}, sucsessStatus: {}", *endPoint, - jsonPayload.dump(), *sucsessStatus); + m_Log->info(m_Log->key("AyonApi"), "AyonApi::SPOST endPoint: {}, jsonPayload: {}, successStatus: {}", *endPoint, + jsonPayload.dump(), *successStatus); - nlohmann::json jsonRespne; + nlohmann::json jsonResponse; if (jsonPayload.empty()) { m_Log->info("JSON payload is empty. No request created"); - return jsonRespne; + return jsonResponse; } - if (endPoint == nullptr || headers == nullptr || sucsessStatus == nullptr) { - m_Log->error("One or more of the provided pointers are null: endPoint, headers, sucsessStatus."); + if (endPoint == nullptr || headers == nullptr || successStatus == nullptr) { + m_Log->error("One or more of the provided pointers are null: endPoint, headers, successStatus."); - return jsonRespne; + return jsonResponse; } m_AyonServerMutex.lock(); std::string payload = jsonPayload.dump(); - std::string rawResponse = serialCorePost(*endPoint, *headers, payload, *sucsessStatus); + std::string rawResponse = serialCorePost(*endPoint, *headers, payload, *successStatus); if (!rawResponse.empty()) { - jsonRespne = nlohmann::json::parse(rawResponse)[0]; // TODO figure out why this is isnt the same as CPOST and - // find a better way to make shure its not a array + jsonResponse = nlohmann::json::parse(rawResponse)[0]; // TODO figure out why this is isnt the same as CPOST and + // find a better way to make sure its not an array } else { - m_Log->warn("SPOST cant phrase JSON // response empty"); + m_Log->warn("SPOST can't parse JSON // response empty"); } m_AyonServerMutex.unlock(); - return jsonRespne; + return jsonResponse; }; nlohmann::json AyonApi::CPOST(const std::shared_ptr endPoint, const std::shared_ptr headers, nlohmann::json jsonPayload, - const std::shared_ptr sucsessStatus) { + const std::shared_ptr successStatus) { PerfTimer("AyonApi::CPOST"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::CPOST endPoint: {}, jsonPayload: {}, sucsessStatus: {}", *endPoint, - jsonPayload.dump(), *sucsessStatus); - nlohmann::json jsonRespne; + m_Log->info(m_Log->key("AyonApi"), "AyonApi::CPOST endPoint: {}, jsonPayload: {}, successStatus: {}", *endPoint, + jsonPayload.dump(), *successStatus); + nlohmann::json jsonResponse; if (jsonPayload.empty()) { m_Log->info("JSON payload is empty. No request created"); - return jsonRespne; + return jsonResponse; } - if (endPoint == nullptr || headers == nullptr || sucsessStatus == nullptr) { - m_Log->error("One or more of the provided pointers are null: endPoint, headers, sucsessStatus"); + if (endPoint == nullptr || headers == nullptr || successStatus == nullptr) { + m_Log->error("One or more of the provided pointers are null: endPoint, headers, successStatus"); - return jsonRespne; + return jsonResponse; } std::string payload = jsonPayload.dump(); - std::string rawResponse = GenerativeCorePost(*endPoint, *headers, payload, *sucsessStatus); + std::string rawResponse = GenerativeCorePost(*endPoint, *headers, payload, *successStatus); if (!rawResponse.empty()) { - jsonRespne = nlohmann::json::parse(rawResponse); + jsonResponse = nlohmann::json::parse(rawResponse); } else { - m_Log->warn("CPOST cant phrase JSON // response empty"); + m_Log->warn("CPOST can't parse JSON // response empty"); } - return jsonRespne; + return jsonResponse; }; // TODO change the pointer work in here because the pointers consume more data that coping would std::pair @@ -252,11 +252,11 @@ AyonApi::resolvePath(const std::string &uriPath) { std::pair resolvedAsset; nlohmann::json jsonPayload = {{"resolveRoots", false}, {"uris", nlohmann::json::array({uriPath})}}; httplib::Headers headers = {{"X-ayon-site-id", m_siteId}}; - uint8_t sucsessStatus = 200; + uint8_t successStatus = 200; nlohmann::json response = SPOST(std::make_shared(m_uriResolverEndpoint + m_uriResolverEndpointPathOnlyVar), - std::make_shared(headers), jsonPayload, std::make_shared(sucsessStatus)); + std::make_shared(headers), jsonPayload, std::make_shared(successStatus)); resolvedAsset = getAssetIdent(response); return resolvedAsset; @@ -277,7 +277,7 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { if (m_batchResolveOptimizeVector) { { - PerfTimer("AyonApi::batchResolvePath::sanatizeVector"); + PerfTimer("AyonApi::batchResolvePath::sanitizeVector"); std::set s; unsigned size = uriPaths.size(); @@ -294,7 +294,7 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { = std::make_shared(httplib::Headers{{"X-ayon-site-id", m_siteId}}); std::shared_ptr batchResolveEndpoint; - if (m_pathOnlyReselution) { + if (m_pathOnlyResolution) { batchResolveEndpoint = std::make_shared(std::string_view(m_uriResolverEndpoint + m_uriResolverEndpointPathOnlyVar)); } @@ -309,20 +309,20 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { int groupSize; int groupAmount; - // set defaults for the grouping incase the vector is to small + // set defaults for the grouping in case the vector is too small groupSize = uriPathsVecSize; groupAmount = 1; grpReason = "The vector is too small."; - // check what scaling the groups schould have + // check what scaling the groups should have if (uriPathsVecSize > m_minVecSizeForGroupSplitAsyncRequests) { - // vector size is large eonught to build groups + // vector size is large enough to build groups // double result = static_cast(uriPathsVecSize) / num_threads; groupSize = std::ceil(static_cast(uriPathsVecSize) / m_num_threads); if (groupSize > m_minGrpSizeForAsyncRequests) { - // the group size is lagre enought to build groups from them + // the group size is large enough to build groups from them if (groupSize < m_maxGroupSizeForAsyncRequests) { - // now its bigger than 5 and smaller than 500 + // now it's bigger than 5 and smaller than 500 // now we can just generate a group per thread and set the group amount groupSize = std::ceil(static_cast(uriPathsVecSize) / m_num_threads); groupAmount = std::floor(static_cast(uriPathsVecSize) / groupSize); @@ -331,7 +331,7 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { grpReason = "5> <500 build group amount by size"; } else { - // the groups are to beig + // the groups are too big // we have to generate more groups than we have threads groupSize = m_regroupSizeForAsyncRequests; groupAmount = std::floor(static_cast(uriPathsVecSize) / m_regroupSizeForAsyncRequests); @@ -339,7 +339,7 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { } } else { - // the groups are to small so we build groups by size + // the groups are too small so we build groups by size groupSize = std::min((int)m_regroupSizeForAsyncRequests, uriPathsVecSize); groupAmount = std::floor(static_cast(uriPathsVecSize) / groupSize); @@ -347,7 +347,7 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { } } m_Log->info( - "AyonApi::batchResolvePath Build groups with grpSize: {} grpAmount: {} grouingReason: {} vectorSize: {}", + "AyonApi::batchResolvePath Build groups with grpSize: {} grpAmount: {} groupingReason: {} vectorSize: {}", groupSize, groupAmount, grpReason, uriPathsVecSize); int groupStartPos = 0; @@ -357,7 +357,7 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { std::string perTimerLoopName = "AyonApi::batchResolvePath Thread Loop: " + std::to_string(thread); PerfTimer(perTimerLoopName.c_str()); - // check if we are to close to the end and extend the group to catch all the data and end the loop + // check if we are too close to the end and extend the group to catch all the data and end the loop if (uriPathsVecSize - groupEndPos < groupSize + (groupSize / 2)) { m_Log->info("the group with the threadId: {} It is too close to the end. This group will be extended. ", @@ -390,24 +390,24 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { }; // TODO make it so that hero version is chosen if available std::pair -AyonApi::getAssetIdent(const nlohmann::json &uriResolverRespone) { +AyonApi::getAssetIdent(const nlohmann::json &uriResolverResponse) { PerfTimer("AyonApi::getAssetIdent"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::getAssetIdent({})", uriResolverRespone.dump()); + m_Log->info(m_Log->key("AyonApi"), "AyonApi::getAssetIdent({})", uriResolverResponse.dump()); std::pair AssetIdent; - if (uriResolverRespone.empty()) { + if (uriResolverResponse.empty()) { return AssetIdent; } try { - AssetIdent.first = uriResolverRespone.at("uri"); - if (uriResolverRespone.at("entities").size() > 1) { - m_Log->warn("Uri reselution returned more than one path (%s)", uriResolverRespone.at("entities").dump()); + AssetIdent.first = uriResolverResponse.at("uri"); + if (uriResolverResponse.at("entities").size() > 1) { + m_Log->warn("Uri resolution returned more than one path (%s)", uriResolverResponse.at("entities").dump()); } AssetIdent.second = rootReplace( - uriResolverRespone.at("entities").at(uriResolverRespone.at("entities").size() - 1).at("filePath")); + uriResolverResponse.at("entities").at(uriResolverResponse.at("entities").size() - 1).at("filePath")); } catch (const nlohmann::json::exception &e) { - m_Log->warn("asset identification cant be generated {}", uriResolverRespone.dump()); + m_Log->warn("asset identification can't be generated {}", uriResolverResponse.dump()); } return AssetIdent; }; @@ -431,42 +431,42 @@ std::string AyonApi::serialCorePost(const std::string &endPoint, httplib::Headers headers, std::string &Payload, - const int &sucsessStatus) { + const int &successStatus) { PerfTimer("AyonApi::serialCorePost"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::serialCorePost() endPoint: {}, Payload: {}, sucsessStatus: {}", - endPoint, Payload, sucsessStatus); + m_Log->info(m_Log->key("AyonApi"), "AyonApi::serialCorePost() endPoint: {}, Payload: {}, successStatus: {}", + endPoint, Payload, successStatus); httplib::Result response; - int responeStatus; - uint8_t retryes = 0; - while (retryes <= m_maxCallRetrys) { + int responseStatus; + uint8_t retries = 0; + while (retries <= m_maxCallRetries) { try { response = m_AyonServer->Post(endPoint, headers, Payload, "application/json"); - responeStatus = response->status; - retryes++; + responseStatus = response->status; + retries++; - if (responeStatus == sucsessStatus) { + if (responseStatus == successStatus) { return response->body; } else { - m_Log->info("AyonApi::serialCorePost wrong status code: {} expected: {}", responeStatus, sucsessStatus); - if (responeStatus == 401) { + m_Log->info("AyonApi::serialCorePost wrong status code: {} expected: {}", responseStatus, successStatus); + if (responseStatus == 401) { m_Log->warn("not logged in 401 "); return ""; } - if (responeStatus == 500) { + if (responseStatus == 500) { m_Log->warn("internal server error "); return ""; } std::this_thread::sleep_for(std::chrono::milliseconds( - responeStatus == m_ServerBusyCode ? m_RequestDelayWhenServerBusy : m_retryWaight)); + responseStatus == m_ServerBusyCode ? m_RequestDelayWhenServerBusy : m_retryWait)); } } // TODO error reason not printed catch (const httplib::Error &e) { m_Log->warn("Request Failed because: {}"); break; } - m_Log->warn("The connection failed Rety now."); + m_Log->warn("The connection failed. Retry now."); } return ""; }; @@ -475,41 +475,41 @@ std::string AyonApi::GenerativeCorePost(const std::string &endPoint, httplib::Headers headers, std::string &Payload, - const int &sucsessStatus) { + const int &successStatus) { PerfTimer("AyonApi::GenerativeCorePost"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::GenerativeCorePost() endPoint: {}, Payload: {}, sucsessStatus: {}", - endPoint, Payload, sucsessStatus); + m_Log->info(m_Log->key("AyonApi"), "AyonApi::GenerativeCorePost() endPoint: {}, Payload: {}, successStatus: {}", + endPoint, Payload, successStatus); httplib::Client AyonServerClient(m_serverUrl); AyonServerClient.set_bearer_token_auth(m_authKey); - AyonServerClient.set_connection_timeout(m_connectionTimeOutMax); - AyonServerClient.set_read_timeout(m_readTimeOutMax); + AyonServerClient.set_connection_timeout(m_connectionTimeoutMax); + AyonServerClient.set_read_timeout(m_readTimeoutMax); httplib::Result response; - int responeStatus; - uint8_t retryes = 0; - bool ffoLocking = false; - uint16_t loopIertaion = 0; - while (retryes <= m_maxCallRetrys || m_GenerativeCorePostMaxLoopIterations > loopIertaion) { - loopIertaion++; + int responseStatus; + uint8_t retries = 0; + bool ffoLock = false; + uint16_t loopIteration = 0; + while (retries <= m_maxCallRetries || m_GenerativeCorePostMaxLoopIterations > loopIteration) { + loopIteration++; m_Log->info("AyonApi::GenerativeCorePost while loop thread {} iteration {}", - std::hash{}(std::this_thread::get_id()), loopIertaion); + std::hash{}(std::this_thread::get_id()), loopIteration); - if (ffoLocking) { - m_ConcurentRequestAfterffoMutex.lock(); - m_Log->info("AyonApi::GenerativeCorePost ffoLocking enabled"); - if (m_maxConcurentRequestAfterffo >= 1) { - m_maxConcurentRequestAfterffo--; + if (ffoLock) { + m_ConcurrentRequestAfterffoMutex.lock(); + m_Log->info("AyonApi::GenerativeCorePost ffoLock enabled"); + if (m_maxConcurrentRequestAfterffo >= 1) { + m_maxConcurrentRequestAfterffo--; m_Log->info("AyonApi::GenerativeCorePost thread pool open available: {}", - m_maxConcurentRequestAfterffo); + m_maxConcurrentRequestAfterffo); - m_ConcurentRequestAfterffoMutex.unlock(); + m_ConcurrentRequestAfterffoMutex.unlock(); } else { m_Log->info("AyonApi::GenerativeCorePost Thread pool closed"); - m_ConcurentRequestAfterffoMutex.unlock(); + m_ConcurrentRequestAfterffoMutex.unlock(); std::this_thread::sleep_for(std::chrono::milliseconds(800)); continue; } @@ -519,37 +519,37 @@ AyonApi::GenerativeCorePost(const std::string &endPoint, try { response = AyonServerClient.Post(endPoint, headers, Payload, "application/json"); - responeStatus = response->status; - retryes++; - if (ffoLocking) { - m_ConcurentRequestAfterffoMutex.lock(); - m_maxConcurentRequestAfterffo++; - m_ConcurentRequestAfterffoMutex.unlock(); + responseStatus = response->status; + retries++; + if (ffoLock) { + m_ConcurrentRequestAfterffoMutex.lock(); + m_maxConcurrentRequestAfterffo++; + m_ConcurrentRequestAfterffoMutex.unlock(); } - if (responeStatus == sucsessStatus) { + if (responseStatus == successStatus) { m_Log->info("AyonApi::GenerativeCorePost The request worked, unlocking and returning. "); return response->body; } else { - if (responeStatus == m_ServerBusyCode) { + if (responseStatus == m_ServerBusyCode) { m_Log->warn("AyonApi::GenerativeCorePost The server responded with 503"); - retryes = 0; - ffoLocking = true; + retries = 0; + ffoLock = true; continue; } - if (responeStatus == 401) { + if (responseStatus == 401) { m_Log->warn("not logged in 401 "); return ""; } - if (responeStatus == 500) { + if (responseStatus == 500) { m_Log->warn("internal server error "); return ""; } - m_Log->info("AyonApi::GenerativeCorePost wrong status code: {} expected: {} retrying", responeStatus, - sucsessStatus); - std::this_thread::sleep_for(std::chrono::milliseconds(m_retryWaight)); + m_Log->info("AyonApi::GenerativeCorePost wrong status code: {} expected: {} retrying", responseStatus, + successStatus); + std::this_thread::sleep_for(std::chrono::milliseconds(m_retryWait)); continue; } } // TODO error reason not printed @@ -560,7 +560,7 @@ AyonApi::GenerativeCorePost(const std::string &endPoint, } m_Log->warn( - "AyonApi::GenerativeCorePost Too many resolve retries without the correct response code for: {}, on: {}", + "AyonApi::GenerativeCorePost Too many resolve retries without the correct response code for: {}, on: {}", Payload, endPoint); return ""; }; @@ -573,7 +573,7 @@ AyonApi::convertUriVecToString(const std::vector &uriVec) { std::string payload = R"({{"resolveRoots": true,"uris": [)"; - for (int i = 0; i <= int(uriVec.size()); i++) { + for (size_t i = 0; i <= uriVec.size(); i++) { payload += uriVec[i]; } From 3769082659d705ff15e12d58a75a7e8f2f933b17 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Fri, 7 Feb 2025 11:32:15 +0100 Subject: [PATCH 03/27] Small adjustments in Instrumentor --- src/AyonCppApi/Instrumentor.h | 40 ++++++++++++++--------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/AyonCppApi/Instrumentor.h b/src/AyonCppApi/Instrumentor.h index c826d69..3b78613 100644 --- a/src/AyonCppApi/Instrumentor.h +++ b/src/AyonCppApi/Instrumentor.h @@ -10,13 +10,13 @@ #include struct ProfileResult { - std::string Name; - long long Start, End; - uint32_t ThreadID; + std::string Name; + long long Start, End; + uint32_t ThreadID; }; struct InstrumentationSession { - std::string Name; + std::string Name; }; class Instrumentor { @@ -30,16 +30,14 @@ class Instrumentor { Instrumentor(): m_CurrentSession(nullptr), m_ProfileCount(0) { } - void - BeginSession(const std::string &name, const std::string &filepath = "results.json") { + void BeginSession(const std::string &name, const std::string &filepath = "results.json") { std::lock_guard lock(m_Mutex); // Lock mutex for critical section m_OutputStream.open(filepath); WriteHeader(); m_CurrentSession = new InstrumentationSession{name}; } - void - EndSession() { + void EndSession() { WriteFooter(); m_OutputStream.close(); delete m_CurrentSession; @@ -47,14 +45,12 @@ class Instrumentor { m_ProfileCount = 0; } - void - WriteProfileAsync(const ProfileResult &result) { - std::future async = std::async(std::launch::async, [this, result]() { WriteProfile(result); }); - async.get(); + void WriteProfileAsync(const ProfileResult &result) { + std::future asyncResult = std::async(std::launch::async, [this, result]() { WriteProfile(result); }); + asyncResult.get(); } - void - WriteProfile(const ProfileResult &result) { + void WriteProfile(const ProfileResult &result) { std::lock_guard lock(m_Mutex); // Lock mutex for critical section if (m_ProfileCount++ > 0) m_OutputStream << ","; @@ -75,20 +71,17 @@ class Instrumentor { m_OutputStream.flush(); } - void - WriteHeader() { + void WriteHeader() { m_OutputStream << "{\"otherData\": {},\"traceEvents\":["; m_OutputStream.flush(); } - void - WriteFooter() { + void WriteFooter() { m_OutputStream << "]}"; m_OutputStream.flush(); } - static Instrumentor & - Get() { + static Instrumentor & Get() { static Instrumentor instance; return instance; } @@ -105,13 +98,12 @@ class InstrumentationTimer { Stop(); } - void - Stop() { + void Stop() { auto endTimepoint = std::chrono::high_resolution_clock::now(); - long long start + long long start = std::chrono::time_point_cast(m_StartTimepoint).time_since_epoch().count(); - long long end + long long end = std::chrono::time_point_cast(endTimepoint).time_since_epoch().count(); uint32_t threadID = std::hash{}(std::this_thread::get_id()); From e3029f0cd2592104dea6e4decffbcaaa7a94749f Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Fri, 7 Feb 2025 11:35:13 +0100 Subject: [PATCH 04/27] Small typos correction, the time calculation bug fixed --- src/AyonCppApi/perfPrinter.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/AyonCppApi/perfPrinter.h b/src/AyonCppApi/perfPrinter.h index 21f9cb6..73a6b8b 100644 --- a/src/AyonCppApi/perfPrinter.h +++ b/src/AyonCppApi/perfPrinter.h @@ -8,7 +8,7 @@ struct perfStats { std::chrono::time_point endTime; std::string StatName; std::string HeaderText; - std::string FoderText; + std::string FooterText; std::string Note; std::vector extraInfo; bool Stop = false; @@ -26,8 +26,7 @@ class perfPrinter { this->printStats(); }; - void - printStats() { + void printStats() { std::cout << currentRunStats.StatName << "\n" << currentRunStats.HeaderText << "\n" << currentRunStats.Note << "\n"; @@ -38,11 +37,11 @@ class perfPrinter { .time_since_epoch() .count(); - long long castEndTime + long long castedEndTime = std::chrono::time_point_cast(std::chrono::high_resolution_clock::now()) .time_since_epoch() .count(); - std::cout << "Execution Time: " << castedStartTime - castEndTime << "\n"; + std::cout << "Execution Time: " << castedEndTime - castedStartTime << "\n"; std::cout << "ThreadId: " << std::hash{}(std::this_thread::get_id()) << "\n"; @@ -50,6 +49,6 @@ class perfPrinter { for (const std::string &infoEntry: currentRunStats.extraInfo) { std::cout << infoEntry << "\n"; } - std::cout << currentRunStats.FoderText << std::endl; + std::cout << currentRunStats.FooterText << std::endl; }; }; From f7637b5c142519289e088d495401c7b18605fbe9 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Fri, 7 Feb 2025 11:38:52 +0100 Subject: [PATCH 05/27] Typo in file name correction in CMakeList --- src/AyonCppApi/CMakeLists.txt | 2 +- src/AyonCppApi/{appDataFoulder.h => appDataFolder.h} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/AyonCppApi/{appDataFoulder.h => appDataFolder.h} (100%) diff --git a/src/AyonCppApi/CMakeLists.txt b/src/AyonCppApi/CMakeLists.txt index 11a31f6..16d9129 100755 --- a/src/AyonCppApi/CMakeLists.txt +++ b/src/AyonCppApi/CMakeLists.txt @@ -43,6 +43,6 @@ install ( ) install ( - FILES AyonCppApi.h appDataFoulder.h devMacros.h Instrumentor.h + FILES AyonCppApi.h appDataFolder.h devMacros.h Instrumentor.h DESTINATION include ) diff --git a/src/AyonCppApi/appDataFoulder.h b/src/AyonCppApi/appDataFolder.h similarity index 100% rename from src/AyonCppApi/appDataFoulder.h rename to src/AyonCppApi/appDataFolder.h From f46d214f5990ed0fba67c4590562c16ae8de5bc6 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Fri, 7 Feb 2025 11:44:02 +0100 Subject: [PATCH 06/27] Typo in file name correction in header file include --- src/AyonCppApi/AyonCppApi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AyonCppApi/AyonCppApi.h b/src/AyonCppApi/AyonCppApi.h index d09d08b..82f61df 100644 --- a/src/AyonCppApi/AyonCppApi.h +++ b/src/AyonCppApi/AyonCppApi.h @@ -10,7 +10,7 @@ #include #include #include "lib/ynput/lib/logging/AyonLogger.hpp" -#include "appDataFoulder.h" +#include "appDataFolder.h" #include "httplib.h" #include "nlohmann/json_fwd.hpp" From c9b2b7353a31db1c4562f64cf3107b01f6298b00 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Fri, 7 Feb 2025 11:55:06 +0100 Subject: [PATCH 07/27] Typos and inconsistence correction --- test/GTestMain.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/GTestMain.cpp b/test/GTestMain.cpp index 5d37241..fab8135 100644 --- a/test/GTestMain.cpp +++ b/test/GTestMain.cpp @@ -9,8 +9,7 @@ nlohmann::json JsonFile; -AyonApi -getApiInstance() { +AyonApi getApiInstance() { std::string AYON_API_KEY("SuperSaveTestKey"); std::string AYON_SERVER_URL("http://localhost:8003"); std::string AYON_SITE_ID("TestId"); @@ -21,14 +20,13 @@ getApiInstance() { return AyonApi("./test_logs", AYON_API_KEY, AYON_SERVER_URL, AYON_PROJECT_NAME, AYON_SITE_ID); } -TEST(AyonCppApi, AyonCppApiCreaion) { +TEST(AyonCppApi, AyonCppApiCreation) { AyonApi Test = getApiInstance(); } TEST(AyonCppApi, AyonCppApiSerialResolveRootReplace) { Instrumentor::Get().BeginSession("Profile", "bin/profSerial.json"); AyonApi Api = getApiInstance(); - nlohmann::json JsonFileStage = JsonFile["Resolve"]; bool RunOnlyOneResolveIteration = false; bool printResult = true; @@ -40,10 +38,9 @@ TEST(AyonCppApi, AyonCppApiSerialResolveRootReplace) { std::cout << std::endl; } -TEST(AyonCppApi, AyonCppApiBathResolveRootReplace) { +TEST(AyonCppApi, AyonCppApiBatchResolveRootReplace) { Instrumentor::Get().BeginSession("Profile", "bin/profBatch.json"); AyonApi Api = getApiInstance(); - nlohmann::json JsonFileStage = JsonFile["Resolve"]; bool RunOnlyOneResolveIteration = false; bool printResult = true; @@ -55,8 +52,7 @@ TEST(AyonCppApi, AyonCppApiBathResolveRootReplace) { std::cout << std::endl; } -int -main(int argc, char** argv) { +int main(int argc, char** argv) { std::ifstream file("test/testData.json"); if (!file.is_open()) { std::cerr << "Failed to open file!" << std::endl; From b0fea84dcb7ce741a4069d8ca97bb72f7d945d9b Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Fri, 7 Feb 2025 11:55:13 +0100 Subject: [PATCH 08/27] Typos and inconsistence correction --- test/AyonCppApiTestsMain.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/AyonCppApiTestsMain.cpp b/test/AyonCppApiTestsMain.cpp index 33c0c0a..60c7f60 100644 --- a/test/AyonCppApiTestsMain.cpp +++ b/test/AyonCppApiTestsMain.cpp @@ -8,12 +8,12 @@ bool AyonCppApiTest::test_SimpleResolve(nlohmann::json &JsonFile, const bool &RunOnlyOnce, const bool &Print, AyonApi &Api) { - nlohmann::json JsonFileStage = JsonFile["Resolve"]; + nlohmann::json jsonFileStage = JsonFile["Resolve"]; - for (auto it = JsonFileStage.begin(); it != JsonFileStage.end(); it++) { - std::pair test = Api.resolvePath(it.key()); + for (const auto& item : jsonFileStage.items()) { + std::pair test = Api.resolvePath(item.key()); - if (test.second != JsonFileStage[it.key()]["RootResolved"]) { + if (test.second != item.value()["RootResolved"]) { return false; } if (Print) { @@ -28,21 +28,21 @@ AyonCppApiTest::test_SimpleResolve(nlohmann::json &JsonFile, const bool &RunOnly bool AyonCppApiTest::test_BatchResolve(nlohmann::json &JsonFile, const bool &Print, AyonApi &Api) { - nlohmann::json JsonFileStage = JsonFile["Resolve"]; + nlohmann::json jsonFileStage = JsonFile["Resolve"]; std::vector uriListSource; - for (auto it = JsonFileStage.begin(); it != JsonFileStage.end(); it++) { - uriListSource.push_back(it.key()); + for (const auto& item : jsonFileStage.items()) { + uriListSource.push_back(item.key()); } std::unordered_map test = Api.batchResolvePath(uriListSource); - for (std::pair element: test) { + for (const auto& element : test) { if (Print) { std::cout << "BatchTest Run Result: " << element.first << " / " << element.second; } - if (JsonFileStage.find(element.first) != JsonFileStage.end()) { - if (element.second != JsonFileStage[element.first]["RootResolved"]) { + if (jsonFileStage.find(element.first) != jsonFileStage.end()) { + if (element.second != jsonFileStage[element.first]["RootResolved"]) { return false; } } From 0562879215b1f9502c9afaf985dec18247822f67 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Fri, 7 Feb 2025 14:25:08 +0100 Subject: [PATCH 09/27] TODOs for adding the exception message to warning - DONE --- src/AyonCppApi/AyonCppApi.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index 3cd77cf..be0770b 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -160,9 +160,10 @@ AyonApi::GET(const std::shared_ptr endPoint, std::this_thread::sleep_for(std::chrono::milliseconds( responseStatus == m_ServerBusyCode ? m_RequestDelayWhenServerBusy : m_retryWait)); } - } // TODO error reason not printed + + } catch (const httplib::Error &e) { - m_Log->warn("Request Failed because: {}"); // maybe just e - httplib::Error is just enum class + m_Log->warn("Request Failed because: {}", httplib::to_string(e)); break; } m_Log->warn("The connection failed. Retry now."); @@ -461,9 +462,9 @@ AyonApi::serialCorePost(const std::string &endPoint, std::this_thread::sleep_for(std::chrono::milliseconds( responseStatus == m_ServerBusyCode ? m_RequestDelayWhenServerBusy : m_retryWait)); } - } // TODO error reason not printed + } catch (const httplib::Error &e) { - m_Log->warn("Request Failed because: {}"); + m_Log->warn("Request Failed because: {}", httplib::to_string(e)); break; } m_Log->warn("The connection failed. Retry now."); @@ -552,9 +553,9 @@ AyonApi::GenerativeCorePost(const std::string &endPoint, std::this_thread::sleep_for(std::chrono::milliseconds(m_retryWait)); continue; } - } // TODO error reason not printed + } catch (const httplib::Error &e) { - m_Log->warn("AyonApi::GenerativeCorePost Request Failed because: {}"); + m_Log->warn("AyonApi::GenerativeCorePost Request Failed because: {}", httplib::to_string(e));); break; } } From fca3b6045973c1273e4e417f467e5981be8ebb31 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Mon, 3 Mar 2025 16:17:35 +0100 Subject: [PATCH 10/27] Fix: default vars were not set after building with test vars --- AyonBuild.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/AyonBuild.py b/AyonBuild.py index 75f2ab4..f10325c 100644 --- a/AyonBuild.py +++ b/AyonBuild.py @@ -19,6 +19,15 @@ AyonCppApiPrj.setup_prj() +SetDefaultVars = Project.Stage("SetDefaultVars") +SetDefaultVars.add_funcs( + Project.Func("", AyonCppApiPrj.setVar, "AYON_CPP_API_ENALBE_GBENCH", "OFF"), + Project.Func("", AyonCppApiPrj.setVar, "AYON_CPP_API_ENALBE_GTEST", "OFF"), + Project.Func("", AyonCppApiPrj.setVar, "JTRACE", "0"), + Project.Func("", AyonCppApiPrj.setVar, "ReleaseType", "Release"), +) +AyonCppApiPrj.add_stage(SetDefaultVars) + SetTestVars = Project.Stage("SetTestVars") SetTestVars.add_funcs( Project.Func("", AyonCppApiPrj.setVar, "AYON_CPP_API_ENALBE_GBENCH", "ON"), @@ -195,11 +204,13 @@ def stopTestServer(): AyonCppApiPrj.creat_stage_group( "CleanBuild", CleanUpStage, + SetDefaultVars, BuildStage, ) AyonCppApiPrj.creat_stage_group( "CleanBuildAndDocs", CleanUpStage, + SetDefaultVars, BuildStage, DoxyGenStage, ) From 63305984d7c527fc4d00d816506557d142590165 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Mon, 3 Mar 2025 16:18:30 +0100 Subject: [PATCH 11/27] Fix: error while building --- src/AyonCppApi/AyonCppApi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index be0770b..e7ce344 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -555,7 +555,7 @@ AyonApi::GenerativeCorePost(const std::string &endPoint, } } catch (const httplib::Error &e) { - m_Log->warn("AyonApi::GenerativeCorePost Request Failed because: {}", httplib::to_string(e));); + m_Log->warn("AyonApi::GenerativeCorePost Request Failed because: {}", httplib::to_string(e)); break; } } From bc6f833dfb16ec34e9967dcb855e474f0e0b0b99 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Wed, 17 Dec 2025 15:04:18 +0100 Subject: [PATCH 12/27] appDataFoulder.h -> appDataFolder.h --- src/AyonCppApi/CMakeLists.txt | 37 ++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/AyonCppApi/CMakeLists.txt b/src/AyonCppApi/CMakeLists.txt index 16d9129..b9cc983 100755 --- a/src/AyonCppApi/CMakeLists.txt +++ b/src/AyonCppApi/CMakeLists.txt @@ -1,42 +1,65 @@ +# ============================================================================== +# 1. OpenSSL Version Selector +# ============================================================================== +option(USE_OPENSSL3 "Build against OpenSSL 3.x" OFF) + +if(USE_OPENSSL3) + message(STATUS " [AyonCppApi] OpenSSL Mode: v3 (Newer standards, Maya 2025+)") + set(OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../ext/openssl3L") +else() + message(STATUS " [AyonCppApi] OpenSSL Mode: v1 (VFX Platform 2023, Houdini 20/21)") + set(OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../ext/openssl1L") +endif() + +# ============================================================================== +# 2. Library Definition +# ============================================================================== add_library(AyonCppApi STATIC AyonCppApi.cpp) target_include_directories(AyonCppApi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -#include the header only libary + +# Include the header only library target_include_directories(AyonCppApi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../ext/cpp-httplib) -# precompile the header lib for better perfocmance + +# Precompile the header lib for better performance target_precompile_headers(AyonCppApi PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../ext/cpp-httplib/httplib.h) target_include_directories(AyonCppApi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../ext/json) target_include_directories(AyonCppApi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../ext/json/include) - target_link_libraries(AyonCppApi PRIVATE nlohmann_json::nlohmann_json) target_link_libraries(AyonCppApi PRIVATE Backward::Interface) target_compile_definitions(AyonCppApi PUBLIC CPPHTTPLIB_OPENSSL_SUPPORT) +# Link against the specific OpenSSL version selected above if(WIN32) target_link_libraries(AyonCppApi PRIVATE ${OPENSSL_ROOT_DIR}/lib/libcrypto_static.lib ${OPENSSL_ROOT_DIR}/lib/libssl_static.lib ) else() + # Standard Linux linking using the root dir we defined at the top target_link_libraries(AyonCppApi PRIVATE ${OPENSSL_ROOT_DIR}/lib/libssl.a ${OPENSSL_ROOT_DIR}/lib/libcrypto.a + ${OPENSSL_ROOT_DIR}/lib/libssl.a # Sometimes repeated for circular dep resolution + ${OPENSSL_ROOT_DIR}/lib/libcrypto.a + dl # OpenSSL often needs dynamic loader on Linux + pthread # OpenSSL often needs threads ) endif() + +# Include the headers from that specific version target_include_directories(AyonCppApi PUBLIC ${OPENSSL_ROOT_DIR}/include) target_include_directories(AyonCppApi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../ext/spdlog) - target_include_directories(AyonCppApi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../ext/spdlog/include) -# needed because off usd resovler +# Needed because of usd resolver set_target_properties(AyonCppApi PROPERTIES POSITION_INDEPENDENT_CODE ON) - install ( TARGETS AyonCppApi DESTINATION ${CMAKE_INSTALL_PREFIX} @@ -45,4 +68,4 @@ install ( install ( FILES AyonCppApi.h appDataFolder.h devMacros.h Instrumentor.h DESTINATION include -) +) From 1e8724bbc99828d55c16468b9eaf56ab6281e763 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Wed, 17 Dec 2025 15:22:45 +0100 Subject: [PATCH 13/27] extra handle for JTRACE --- src/AyonCppApi/devMacros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AyonCppApi/devMacros.h b/src/AyonCppApi/devMacros.h index 5492c02..f909ffc 100644 --- a/src/AyonCppApi/devMacros.h +++ b/src/AyonCppApi/devMacros.h @@ -1,7 +1,7 @@ #ifndef DEV_MACRO_H #define DEV_MACRO_H -#if JTRACE == 1 +#if defined(JTRACE) && JTRACE == 1 #include "Instrumentor.h" #define PerfTimer(x) InstrumentationTimer timer(x); #else From 1cbde64bf35e66a4594a4a0115dcfd8ff22051ba Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Wed, 17 Dec 2025 16:08:04 +0100 Subject: [PATCH 14/27] remove duplicated lines --- src/AyonCppApi/AyonCppApi.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/AyonCppApi/AyonCppApi.h b/src/AyonCppApi/AyonCppApi.h index 4f5ee5d..4537516 100644 --- a/src/AyonCppApi/AyonCppApi.h +++ b/src/AyonCppApi/AyonCppApi.h @@ -196,7 +196,6 @@ class AyonApi { const std::string m_authKey; const std::string m_serverUrl; std::string m_ayonProjectName; - httplib::Headers m_headers; // ---- Server Vars std::string m_siteId; From aecf10876d813601f6c36e1998636846b79139c4 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Wed, 17 Dec 2025 16:13:20 +0100 Subject: [PATCH 15/27] typo fix --- src/AyonCppApi/AyonCppApi.cpp | 2 +- src/AyonCppApi/AyonCppApi.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index 4ec4a4d..7ff7d52 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -548,7 +548,7 @@ AyonApi::getAssetIdent(const nlohmann::json &uriResolverResponse) { uriResolverResponse.at("entities").at(uriResolverResponse.at("entities").size() - 1).at("filePath")); } catch (const nlohmann::json::exception &e) { - m_Log->warn("asset identification cant be generated {}", uriResolverRespone.dump()); + m_Log->warn("asset identification cant be generated {}", uriResolverResponse.dump()); } return AssetIdent; }; diff --git a/src/AyonCppApi/AyonCppApi.h b/src/AyonCppApi/AyonCppApi.h index 4537516..1059ac6 100644 --- a/src/AyonCppApi/AyonCppApi.h +++ b/src/AyonCppApi/AyonCppApi.h @@ -112,7 +112,7 @@ class AyonApi { * @param uriResolverResponse JSON representation of the response from the AYON API resolve endpoint. * @return A pair containing the asset identifier and the machine local file location. */ - std::pair getAssetIdent(const nlohmann::json &uriResolverRespone); + std::pair getAssetIdent(const nlohmann::json &uriResolverResponse); /** * @brief this function loads all needed varible into the class \n From 37259c849e7656154de609b05b1d8d3bc089388d Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Wed, 17 Dec 2025 16:33:19 +0100 Subject: [PATCH 16/27] typo fix --- src/AyonCppApi/AyonCppApi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index 7ff7d52..5793889 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -281,8 +281,8 @@ AyonApi::GET(const std::shared_ptr endPoint, while (retries <= m_maxCallRetries) { try { response = m_AyonServer->Get(*endPoint, *headers); - responeStatus = response->status; - retryes++; + responseStatus = response->status; + retries++; if (responseStatus == successStatus) { return nlohmann::json::parse(response->body); From d868e6ef56fee0ec7e0044a086cdce74dec879a0 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Wed, 17 Dec 2025 16:40:02 +0100 Subject: [PATCH 17/27] typo in success --- src/AyonCppApi/AyonCppApi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index 5793889..e83b9ef 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -393,7 +393,7 @@ AyonApi::resolvePath(const std::string &uriPath) { std::pair resolvedAsset; nlohmann::json jsonPayload = {{"resolveRoots", false}, {"uris", nlohmann::json::array({uriPath})}}; httplib::Headers headers = {{"X-ayon-site-id", m_siteId}}; - uint8_t sucsessStatus = 200; + uint8_t successStatus = 200; nlohmann::json response = SPOST(std::make_shared(m_uriResolverEndpoint + m_uriResolverEndpointPathOnlyVar), From 0e3e80a0b41d2053715bbf13249e0c3546e3f409 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Wed, 17 Dec 2025 16:46:14 +0100 Subject: [PATCH 18/27] get back to prev version --- src/AyonCppApi/AyonCppApi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index e83b9ef..001b302 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -1,4 +1,4 @@ -#include "AyonCppApi.h" +include "AyonCppApi.h" #include #include "httplib.h" #include "nlohmann/json.hpp" From 06e1807da14f0bd49877c51089bef3b866ab6bf9 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Wed, 17 Dec 2025 16:59:06 +0100 Subject: [PATCH 19/27] checkout to latest impl of logger --- ext/ayon-cpp-dev-tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ayon-cpp-dev-tools b/ext/ayon-cpp-dev-tools index 9831c56..0b5bf00 160000 --- a/ext/ayon-cpp-dev-tools +++ b/ext/ayon-cpp-dev-tools @@ -1 +1 @@ -Subproject commit 9831c56a3d8e61385dcc706d003086bd6e43f4d8 +Subproject commit 0b5bf00b911a8a57560c08ab7c79089d6e846baa From 4f78984ed8f99079051fc2d1746d9b4562dcb6f4 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Wed, 17 Dec 2025 17:10:41 +0100 Subject: [PATCH 20/27] add missing hashtag --- src/AyonCppApi/AyonCppApi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index 001b302..e83b9ef 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -1,4 +1,4 @@ -include "AyonCppApi.h" +#include "AyonCppApi.h" #include #include "httplib.h" #include "nlohmann/json.hpp" From 6bc2826fc7c2a1812d5e851b1cea3f010b18886b Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Tue, 6 Jan 2026 13:45:44 +0100 Subject: [PATCH 21/27] minor changes, m_headers use in resolvePath --- src/AyonCppApi/AyonCppApi.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index e83b9ef..525c1fe 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -32,6 +32,11 @@ #include "backward.hpp" #include "perfPrinter.h" +#ifdef _WIN32 +#include +#include +#endif + // TODO implement the better Crash hanlder backward::StackTrace st; @@ -187,6 +192,7 @@ AyonApi::AyonApi(const std::optional &logFilePos, m_headers = { {"X-Api-Key", m_authKey}, + {"X-ayon-site-id", m_siteId} }; auto resMe = m_AyonServer->Get("/api/users/me", m_headers); if (resMe && resMe->status != 200) { @@ -281,13 +287,18 @@ AyonApi::GET(const std::shared_ptr endPoint, while (retries <= m_maxCallRetries) { try { response = m_AyonServer->Get(*endPoint, *headers); + + if (!response) { + m_Log->warn("AyonApi::GET response is null: {}", httplib::to_string(response.error())); + return nlohmann::json(); + } + responseStatus = response->status; retries++; if (responseStatus == successStatus) { return nlohmann::json::parse(response->body); - } - else { + } else { m_Log->info("AyonApi::serialCorePost wrong status code: {} expected: {}", responseStatus, successStatus); if (responseStatus == 401) { m_Log->warn("not logged in 401 "); @@ -392,12 +403,11 @@ AyonApi::resolvePath(const std::string &uriPath) { } std::pair resolvedAsset; nlohmann::json jsonPayload = {{"resolveRoots", false}, {"uris", nlohmann::json::array({uriPath})}}; - httplib::Headers headers = {{"X-ayon-site-id", m_siteId}}; uint8_t successStatus = 200; nlohmann::json response = SPOST(std::make_shared(m_uriResolverEndpoint + m_uriResolverEndpointPathOnlyVar), - std::make_shared(headers), jsonPayload, std::make_shared(successStatus)); + std::make_shared(m_headers), jsonPayload, std::make_shared(successStatus)); resolvedAsset = getAssetIdent(response); return resolvedAsset; From 5d2e1198891138b26dcd7a65680d3473017e283a Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Tue, 6 Jan 2026 15:59:04 +0100 Subject: [PATCH 22/27] fixing naming convention diffs --- src/AyonCppApi/AyonCppApi.cpp | 42 +++++++++++++++++------------------ src/AyonCppApi/AyonCppApi.h | 14 ++++++------ 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index 525c1fe..822147e 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -151,34 +151,34 @@ AyonApi::AyonApi(const std::optional &logFilePos, m_Log->LogLevelInfo(); m_Log->info(m_Log->key("AyonApi"), "Init AyonServer httplib::Client"); - m_AyonServer = std::make_unique(m_serverUrl); + m_ayonServer = std::make_unique(m_serverUrl); m_Log->info(m_Log->key("AyonApi"), "After creating httplib::Client - {}", m_serverUrl); if (isSSL()) { std::string ayonSSLPath = std::getenv("AYON_SSL_CERT_PATH") ? std::getenv("AYON_SSL_CERT_PATH") : ""; if (!ayonSSLPath.empty()) { m_Log->info(m_Log->key("AyonApi"), "Using AYON_SSL_CERT_PATH: {}", ayonSSLPath); - m_AyonServer->set_ca_cert_path(ayonSSLPath.c_str()); + m_ayonServer->set_ca_cert_path(ayonSSLPath.c_str()); } else { m_Log->warn(m_Log->key("AyonApi"), "No AYON_SSL_CERT_PATH set, trying to get OpenSSL dir"); try { setSSL(); } catch (const std::exception &e) { m_Log->error("Failed to get OpenSSL directory: {}", e.what()); - m_AyonServer->set_ca_cert_path(nullptr); + m_ayonServer->set_ca_cert_path(nullptr); } } - m_AyonServer->enable_server_certificate_verification(true); + m_ayonServer->enable_server_certificate_verification(true); } - if (!m_AyonServer) { - m_Log->error("m_AyonServer is null. serverUrl='{}'", m_serverUrl); + if (!m_ayonServer) { + m_Log->error("m_ayonServer is null. serverUrl='{}'", m_serverUrl); throw std::runtime_error("AyonApi: HTTP client not initialized"); } httplib::Result res; try { - res = m_AyonServer->Get("/api/info"); + res = m_ayonServer->Get("/api/info"); } catch (const std::exception& e) { m_Log->error("Exception during GET /api/info: {}", e.what()); throw; @@ -194,10 +194,10 @@ AyonApi::AyonApi(const std::optional &logFilePos, {"X-Api-Key", m_authKey}, {"X-ayon-site-id", m_siteId} }; - auto resMe = m_AyonServer->Get("/api/users/me", m_headers); + auto resMe = m_ayonServer->Get("/api/users/me", m_headers); if (resMe && resMe->status != 200) { m_headers = {}; - m_AyonServer->set_bearer_token_auth(m_authKey); + m_ayonServer->set_bearer_token_auth(m_authKey); } } @@ -286,7 +286,7 @@ AyonApi::GET(const std::shared_ptr endPoint, uint8_t retries = 0; while (retries <= m_maxCallRetries) { try { - response = m_AyonServer->Get(*endPoint, *headers); + response = m_ayonServer->Get(*endPoint, *headers); if (!response) { m_Log->warn("AyonApi::GET response is null: {}", httplib::to_string(response.error())); @@ -309,7 +309,7 @@ AyonApi::GET(const std::shared_ptr endPoint, return nlohmann::json(); } std::this_thread::sleep_for(std::chrono::milliseconds( - responseStatus == m_ServerBusyCode ? m_RequestDelayWhenServerBusy : m_retryWait)); + responseStatus == m_serverBusyCode ? m_requestDelayWhenServerBusy : m_retryWait)); } } @@ -344,7 +344,7 @@ AyonApi::SPOST(const std::shared_ptr endPoint, return jsonResponse; } - m_AyonServerMutex.lock(); + m_ayonServerMutex.lock(); std::string payload = jsonPayload.dump(); std::string rawResponse = serialCorePost(*endPoint, *headers, payload, *successStatus); @@ -356,7 +356,7 @@ AyonApi::SPOST(const std::shared_ptr endPoint, else { m_Log->warn("SPOST can't parse JSON // response empty"); } - m_AyonServerMutex.unlock(); + m_ayonServerMutex.unlock(); return jsonResponse; }; @@ -592,7 +592,7 @@ AyonApi::serialCorePost(const std::string &endPoint, uint8_t retries = 0; while (retries <= m_maxCallRetries) { try { - response = m_AyonServer->Post(endPoint, headers, Payload, "application/json"); + response = m_ayonServer->Post(endPoint, headers, Payload, "application/json"); responseStatus = response->status; retries++; @@ -610,7 +610,7 @@ AyonApi::serialCorePost(const std::string &endPoint, return ""; } std::this_thread::sleep_for(std::chrono::milliseconds( - responseStatus == m_ServerBusyCode ? m_RequestDelayWhenServerBusy : m_retryWait)); + responseStatus == m_serverBusyCode ? m_requestDelayWhenServerBusy : m_retryWait)); } } catch (const httplib::Error &e) { @@ -641,7 +641,7 @@ AyonApi::GenerativeCorePost(const std::string &endPoint, uint8_t retries = 0; bool ffoLock = false; uint16_t loopIteration = 0; - while (retries <= m_maxCallRetries || m_GenerativeCorePostMaxLoopIterations > loopIteration) { + while (retries <= m_maxCallRetries || m_generativeCorePostMaxLoopIterations > loopIteration) { loopIteration++; m_Log->info("AyonApi::GenerativeCorePost while loop thread {} iteration {}", std::hash{}(std::this_thread::get_id()), loopIteration); @@ -683,7 +683,7 @@ AyonApi::GenerativeCorePost(const std::string &endPoint, return response->body; } else { - if (responseStatus == m_ServerBusyCode) { + if (responseStatus == m_serverBusyCode) { m_Log->warn("AyonApi::GenerativeCorePost The server responded with 503"); retries = 0; @@ -751,7 +751,7 @@ AyonApi::setSSL() { if (envCertFile) { if (std::filesystem::exists(envCertFile)) { m_Log->info("Using cert based on env variable (SSL_CERT_FILE): {}", envCertFile); - m_AyonServer->set_ca_cert_path(envCertFile); + m_ayonServer->set_ca_cert_path(envCertFile); return; } } @@ -762,7 +762,7 @@ AyonApi::setSSL() { if (std::filesystem::exists(certFileCLI)) { m_Log->info("Using cert based on CLI var: {}", certFileCLI); - m_AyonServer->set_ca_cert_path(certFileCLI.c_str()); + m_ayonServer->set_ca_cert_path(certFileCLI.c_str()); return; } @@ -772,7 +772,7 @@ AyonApi::setSSL() { if (std::filesystem::exists(certFileSSLEAY)) { m_Log->info("Using cert based on SSLEAY_DIR: {}", certFileSSLEAY); - m_AyonServer->set_ca_cert_path(certFileSSLEAY.c_str()); + m_ayonServer->set_ca_cert_path(certFileSSLEAY.c_str()); return; } @@ -796,7 +796,7 @@ AyonApi::setSSL() { if (std::filesystem::exists(certPath)) { m_Log->info("Using bundled certificate (via SO path): {}", certPath); - m_AyonServer->set_ca_cert_path(certPath.c_str()); + m_ayonServer->set_ca_cert_path(certPath.c_str()); return; } diff --git a/src/AyonCppApi/AyonCppApi.h b/src/AyonCppApi/AyonCppApi.h index 1059ac6..82a8116 100644 --- a/src/AyonCppApi/AyonCppApi.h +++ b/src/AyonCppApi/AyonCppApi.h @@ -176,7 +176,7 @@ class AyonApi { std::string convertUriVecToString(const std::vector &uriVec); /** - * @brief checks if the m_AyonServer is running on ssl based on m_serverUrl + * @brief checks if the m_ayonServer is running on ssl based on m_serverUrl * dumb implementation but it should work - function from httplib is not working * * @return true if m_serverUrl starts with https:// @@ -184,11 +184,11 @@ class AyonApi { bool isSSL() const; /** - * @brief sets the ssl cert path for the m_AyonServer httplib client + * @brief sets the ssl cert path for the m_ayonServer httplib client */ void setSSL(); - std::unique_ptr m_AyonServer; + std::unique_ptr m_ayonServer; std::unordered_map m_siteRoots; @@ -226,7 +226,7 @@ class AyonApi { std::mutex m_ConcurrentRequestAfterffoMutex; uint8_t m_maxConcurrentRequestAfterffo = 8; - uint16_t m_GenerativeCorePostMaxLoopIterations = 200; + uint16_t m_generativeCorePostMaxLoopIterations = 200; uint16_t m_connectionTimeoutMax = 200; uint8_t m_readTimeoutMax = 160; @@ -236,8 +236,8 @@ class AyonApi { */ bool m_batchResolveOptimizeVector = true; - uint16_t m_ServerBusyCode = 503; - uint16_t m_RequestDelayWhenServerBusy = 10000; + uint16_t m_serverBusyCode = 503; + uint16_t m_requestDelayWhenServerBusy = 10000; /** * @brief This bool will be set to true if a 503 is encountered @@ -247,7 +247,7 @@ class AyonApi { /** * @brief Needed for serial resolve operations. to lock access to AyonServer shared pointer */ - std::mutex m_AyonServerMutex; + std::mutex m_ayonServerMutex; }; #endif // !AYONCPPAPI_H From 81ffa2ee5d6420f14e17119c0258b72b9df86efe Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Tue, 6 Jan 2026 16:23:20 +0100 Subject: [PATCH 23/27] code hygiene, variables order, naming convention, ... --- src/AyonCppApi/AyonCppApi.cpp | 48 +++++++++---------- src/AyonCppApi/AyonCppApi.h | 89 +++++++++++++---------------------- 2 files changed, 56 insertions(+), 81 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index 822147e..838ef2e 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -209,7 +209,7 @@ AyonApi::~AyonApi() { m_Log->info(m_Log->key("AyonApi"), "AyonApi::~AyonApi()"); }; -std::unordered_map* +const std::unordered_map& AyonApi::getSiteRoots() { m_Log->info(m_Log->key("AyonApi"), "AyonApi::getSiteRoots()"); if (m_siteRoots.size() < 1) { @@ -382,7 +382,7 @@ AyonApi::CPOST(const std::shared_ptr endPoint, } std::string payload = jsonPayload.dump(); - std::string rawResponse = GenerativeCorePost(*endPoint, *headers, payload, *successStatus); + std::string rawResponse = generativeCorePost(*endPoint, *headers, payload, *successStatus); if (!rawResponse.empty()) { jsonResponse = nlohmann::json::parse(rawResponse); } @@ -623,12 +623,12 @@ AyonApi::serialCorePost(const std::string &endPoint, }; std::string -AyonApi::GenerativeCorePost(const std::string &endPoint, +AyonApi::generativeCorePost(const std::string &endPoint, httplib::Headers headers, std::string &Payload, const int &successStatus) { - PerfTimer("AyonApi::GenerativeCorePost"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::GenerativeCorePost() endPoint: {}, Payload: {}, successStatus: {}", + PerfTimer("AyonApi::generativeCorePost"); + m_Log->info(m_Log->key("AyonApi"), "AyonApi::generativeCorePost() endPoint: {}, Payload: {}, successStatus: {}", endPoint, Payload, successStatus); httplib::Client AyonServerClient(m_serverUrl); @@ -643,48 +643,48 @@ AyonApi::GenerativeCorePost(const std::string &endPoint, uint16_t loopIteration = 0; while (retries <= m_maxCallRetries || m_generativeCorePostMaxLoopIterations > loopIteration) { loopIteration++; - m_Log->info("AyonApi::GenerativeCorePost while loop thread {} iteration {}", + m_Log->info("AyonApi::generativeCorePost while loop thread {} iteration {}", std::hash{}(std::this_thread::get_id()), loopIteration); if (ffoLock) { - m_ConcurrentRequestAfterffoMutex.lock(); - m_Log->info("AyonApi::GenerativeCorePost ffoLock enabled"); - if (m_maxConcurrentRequestAfterffo >= 1) { - m_maxConcurrentRequestAfterffo--; + m_concurrentRequestAfterFfoMutex.lock(); + m_Log->info("AyonApi::generativeCorePost ffoLock enabled"); + if (m_maxConcurrentRequestAfterFfo >= 1) { + m_maxConcurrentRequestAfterFfo--; - m_Log->info("AyonApi::GenerativeCorePost thread pool open available: {}", - m_maxConcurrentRequestAfterffo); + m_Log->info("AyonApi::generativeCorePost thread pool open available: {}", + m_maxConcurrentRequestAfterFfo); - m_ConcurrentRequestAfterffoMutex.unlock(); + m_concurrentRequestAfterFfoMutex.unlock(); } else { - m_Log->info("AyonApi::GenerativeCorePost Thread pool closed"); + m_Log->info("AyonApi::generativeCorePost Thread pool closed"); - m_ConcurrentRequestAfterffoMutex.unlock(); + m_concurrentRequestAfterFfoMutex.unlock(); std::this_thread::sleep_for(std::chrono::milliseconds(800)); continue; } } - m_Log->info("AyonApi::GenerativeCorePost sending request"); + m_Log->info("AyonApi::generativeCorePost sending request"); try { response = AyonServerClient.Post(endPoint, headers, Payload, "application/json"); responseStatus = response->status; retries++; if (ffoLock) { - m_ConcurrentRequestAfterffoMutex.lock(); - m_maxConcurrentRequestAfterffo++; - m_ConcurrentRequestAfterffoMutex.unlock(); + m_concurrentRequestAfterFfoMutex.lock(); + m_maxConcurrentRequestAfterFfo++; + m_concurrentRequestAfterFfoMutex.unlock(); } if (responseStatus == successStatus) { - m_Log->info("AyonApi::GenerativeCorePost The request worked, unlocking and returning. "); + m_Log->info("AyonApi::generativeCorePost The request worked, unlocking and returning. "); return response->body; } else { if (responseStatus == m_serverBusyCode) { - m_Log->warn("AyonApi::GenerativeCorePost The server responded with 503"); + m_Log->warn("AyonApi::generativeCorePost The server responded with 503"); retries = 0; ffoLock = true; @@ -698,20 +698,20 @@ AyonApi::GenerativeCorePost(const std::string &endPoint, m_Log->warn("internal server error "); return ""; } - m_Log->info("AyonApi::GenerativeCorePost wrong status code: {} expected: {} retrying", responseStatus, + m_Log->info("AyonApi::generativeCorePost wrong status code: {} expected: {} retrying", responseStatus, successStatus); std::this_thread::sleep_for(std::chrono::milliseconds(m_retryWait)); continue; } } catch (const httplib::Error &e) { - m_Log->warn("AyonApi::GenerativeCorePost Request Failed because: {}", httplib::to_string(e)); + m_Log->warn("AyonApi::generativeCorePost Request Failed because: {}", httplib::to_string(e)); break; } } m_Log->warn( - "AyonApi::GenerativeCorePost Too many resolve retries without the correct response code for: {}, on: {}", + "AyonApi::generativeCorePost Too many resolve retries without the correct response code for: {}, on: {}", Payload, endPoint); return ""; }; diff --git a/src/AyonCppApi/AyonCppApi.h b/src/AyonCppApi/AyonCppApi.h index 82a8116..f30c56b 100644 --- a/src/AyonCppApi/AyonCppApi.h +++ b/src/AyonCppApi/AyonCppApi.h @@ -114,14 +114,6 @@ class AyonApi { */ std::pair getAssetIdent(const nlohmann::json &uriResolverResponse); - /** - * @brief this function loads all needed varible into the class \n - * this will allso be called by the constructor - * - * @return - */ - bool loadEnvVars(); - /** * @brief Get function for shared AyonLogger pointer used by this class instance */ @@ -131,8 +123,7 @@ class AyonApi { * @brief Gets the site root overwrites for the current project. Current project is defined via an env variable * for now */ - std::unordered_map* - getSiteRoots(); // TODO think about if this should only support current project or multiple projects + const std::unordered_map& getSiteRoots(); // TODO think about if this should only support current project or multiple projects /** * @brief Replaces {root[var]} for ayon:// paths. @@ -163,7 +154,7 @@ class AyonApi { * @param payload JSON payload to be resolved by endpoint. * @param successStatus Defines what is considered a success response to break the retry loop. */ - std::string GenerativeCorePost(const std::string &endPoint, + std::string generativeCorePost(const std::string &endPoint, httplib::Headers headers, std::string &payload, const int &successStatus); @@ -176,78 +167,62 @@ class AyonApi { std::string convertUriVecToString(const std::vector &uriVec); /** - * @brief checks if the m_ayonServer is running on ssl based on m_serverUrl - * dumb implementation but it should work - function from httplib is not working + * @brief Checks if the m_ayonServer is running on SSL based on m_serverUrl + * Simple implementation - httplib's built-in check is not working * * @return true if m_serverUrl starts with https:// */ bool isSSL() const; /** - * @brief sets the ssl cert path for the m_ayonServer httplib client + * @brief Sets the SSL cert path for the m_ayonServer httplib client */ void setSSL(); + // Core Dependencies std::unique_ptr m_ayonServer; - - std::unordered_map m_siteRoots; + std::shared_ptr m_log; - // ----- Env Varibles + // Configuration from Constructor const std::string m_authKey; const std::string m_serverUrl; std::string m_ayonProjectName; - - // ---- Server Vars std::string m_siteId; - std::string m_userName; - - // --- HTTP Headers + const int m_numThreads; + + // Runtime State + std::unordered_map m_siteRoots; httplib::Headers m_headers; - - // --- Runtime Dep Vars - - // Async Grp Generation Varaibles - uint8_t m_minGrpSizeForAsyncRequests = 10; - uint16_t m_regroupSizeForAsyncRequests = 200; - uint16_t m_maxGroupSizeForAsyncRequests = 300; - uint16_t m_minVecSizeForGroupSplitAsyncRequests = 50; - uint8_t m_maxCallRetries = 8; - uint16_t m_retryWait = 800; - - /** - * @brief maximum number of threads that the CPU can handle at the same time. Will be set via constructor - */ - const int m_num_threads; // set by constructor - std::shared_ptr m_Log; + std::string m_userName; + bool m_serverBusy = false; + + // URI Resolution Configuration std::string m_uriResolverEndpoint = "/api/resolve"; std::string m_uriResolverEndpointPathOnlyVar = "?pathOnly=true"; bool m_pathOnlyResolution = true; - - std::mutex m_ConcurrentRequestAfterffoMutex; - uint8_t m_maxConcurrentRequestAfterffo = 8; - - uint16_t m_generativeCorePostMaxLoopIterations = 200; - - uint16_t m_connectionTimeoutMax = 200; - uint8_t m_readTimeoutMax = 160; - + /** * @brief Decides if the cpp API removes duplicates from batch request vector. Default is true */ bool m_batchResolveOptimizeVector = true; - + uint8_t m_minGroupSizeForAsyncRequests = 10; + uint16_t m_regroupSizeForAsyncRequests = 200; + uint16_t m_maxGroupSizeForAsyncRequests = 300; + uint16_t m_minVecSizeForGroupSplitAsyncRequests = 50; + + // Retry and Timeout Configuration + uint8_t m_maxCallRetries = 8; + uint16_t m_retryWait = 800; uint16_t m_serverBusyCode = 503; uint16_t m_requestDelayWhenServerBusy = 10000; - - /** - * @brief This bool will be set to true if a 503 is encountered - */ - bool m_serverBusy = false; - - /** - * @brief Needed for serial resolve operations. to lock access to AyonServer shared pointer - */ + uint16_t m_connectionTimeoutMax = 200; + uint8_t m_readTimeoutMax = 160; + uint16_t m_generativeCorePostMaxLoopIterations = 200; + + // Thread Synchronization std::mutex m_ayonServerMutex; + std::mutex m_concurrentRequestAfter503Mutex; + uint8_t m_maxConcurrentRequestsAfter503 = 8; }; #endif // !AYONCPPAPI_H From 856ded5b3836238ddd6f92563599541ee450398c Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Tue, 6 Jan 2026 16:32:19 +0100 Subject: [PATCH 24/27] m_Log -> m_log to match the naming convention --- src/AyonCppApi/AyonCppApi.cpp | 164 +++++++++++++++++----------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index 838ef2e..0e6ecad 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -135,7 +135,7 @@ AyonApi::AyonApi(const std::optional &logFilePos, } } - // ----------- Init m_Logger (Singleton Logic) + // ----------- Init m_logger (Singleton Logic) std::cout << "[AyonApi] Retrieving AyonLogger Singleton..." << std::endl; AyonLogger& loggerRef = AyonLogger::getInstance(); @@ -144,27 +144,27 @@ AyonApi::AyonApi(const std::optional &logFilePos, loggerRef.initFileLogger(logPath.string()); } - m_Log = std::shared_ptr(&loggerRef, [](AyonLogger*){}); + m_log = std::shared_ptr(&loggerRef, [](AyonLogger*){}); - m_Log->registerLoggingKey("AyonApi"); + m_log->registerLoggingKey("AyonApi"); - m_Log->LogLevelInfo(); - m_Log->info(m_Log->key("AyonApi"), "Init AyonServer httplib::Client"); + m_log->LogLevelInfo(); + m_log->info(m_log->key("AyonApi"), "Init AyonServer httplib::Client"); m_ayonServer = std::make_unique(m_serverUrl); - m_Log->info(m_Log->key("AyonApi"), "After creating httplib::Client - {}", m_serverUrl); + m_log->info(m_log->key("AyonApi"), "After creating httplib::Client - {}", m_serverUrl); if (isSSL()) { std::string ayonSSLPath = std::getenv("AYON_SSL_CERT_PATH") ? std::getenv("AYON_SSL_CERT_PATH") : ""; if (!ayonSSLPath.empty()) { - m_Log->info(m_Log->key("AyonApi"), "Using AYON_SSL_CERT_PATH: {}", ayonSSLPath); + m_log->info(m_log->key("AyonApi"), "Using AYON_SSL_CERT_PATH: {}", ayonSSLPath); m_ayonServer->set_ca_cert_path(ayonSSLPath.c_str()); } else { - m_Log->warn(m_Log->key("AyonApi"), "No AYON_SSL_CERT_PATH set, trying to get OpenSSL dir"); + m_log->warn(m_log->key("AyonApi"), "No AYON_SSL_CERT_PATH set, trying to get OpenSSL dir"); try { setSSL(); } catch (const std::exception &e) { - m_Log->error("Failed to get OpenSSL directory: {}", e.what()); + m_log->error("Failed to get OpenSSL directory: {}", e.what()); m_ayonServer->set_ca_cert_path(nullptr); } } @@ -172,7 +172,7 @@ AyonApi::AyonApi(const std::optional &logFilePos, } if (!m_ayonServer) { - m_Log->error("m_ayonServer is null. serverUrl='{}'", m_serverUrl); + m_log->error("m_ayonServer is null. serverUrl='{}'", m_serverUrl); throw std::runtime_error("AyonApi: HTTP client not initialized"); } @@ -180,15 +180,15 @@ AyonApi::AyonApi(const std::optional &logFilePos, try { res = m_ayonServer->Get("/api/info"); } catch (const std::exception& e) { - m_Log->error("Exception during GET /api/info: {}", e.what()); + m_log->error("Exception during GET /api/info: {}", e.what()); throw; } if (!res) { - m_Log->error("Failed to connect to the Ayon server."); + m_log->error("Failed to connect to the Ayon server."); } else { - m_Log->info(m_Log->key("AyonApi"), "Ayon server info: {}", res->body); - m_Log->info(m_Log->key("AyonApi"), "Status code: {}", res->status); + m_log->info(m_log->key("AyonApi"), "Ayon server info: {}", res->body); + m_log->info(m_log->key("AyonApi"), "Status code: {}", res->status); m_headers = { {"X-Api-Key", m_authKey}, @@ -201,17 +201,17 @@ AyonApi::AyonApi(const std::optional &logFilePos, } } - m_Log->info(m_Log->key("AyonApi"), "Constructor Getting Site Roots"); + m_log->info(m_log->key("AyonApi"), "Constructor Getting Site Roots"); getSiteRoots(); } AyonApi::~AyonApi() { - m_Log->info(m_Log->key("AyonApi"), "AyonApi::~AyonApi()"); + m_log->info(m_log->key("AyonApi"), "AyonApi::~AyonApi()"); }; const std::unordered_map& AyonApi::getSiteRoots() { - m_Log->info(m_Log->key("AyonApi"), "AyonApi::getSiteRoots()"); + m_log->info(m_log->key("AyonApi"), "AyonApi::getSiteRoots()"); if (m_siteRoots.size() < 1) { std::string platform; #ifdef _WIN32 @@ -223,17 +223,17 @@ AyonApi::getSiteRoots() { std::make_shared(m_headers), 200); if (response.empty()) { - m_Log->error("AyonApi::getSiteRoots response is empty"); + m_log->error("AyonApi::getSiteRoots response is empty"); return &m_siteRoots; } else { m_siteRoots = response; } } - if (m_Log->isKeyActive(m_Log->key("AyonApi"))) { - m_Log->info(m_Log->key("AyonApi"), "found site Roots: "); + if (m_log->isKeyActive(m_log->key("AyonApi"))) { + m_log->info(m_log->key("AyonApi"), "found site Roots: "); for (auto &e: m_siteRoots) { - m_Log->info("{}, {}", e.first, e.second); + m_log->info("{}, {}", e.first, e.second); } } @@ -242,7 +242,7 @@ AyonApi::getSiteRoots() { std::string AyonApi::rootReplace(const std::string &rootLessPath) { - m_Log->info(m_Log->key("AyonApi"), "AyonApi::rootReplace({})", rootLessPath); + m_log->info(m_log->key("AyonApi"), "AyonApi::rootReplace({})", rootLessPath); std::string rootedPath; std::smatch matchesA; @@ -258,13 +258,13 @@ AyonApi::rootReplace(const std::string &rootLessPath) { try { std::string replacement = m_siteRoots.at(bracketedString); rootedPath = std::regex_replace(rootLessPath, rootFindPattern, replacement); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::rootReplace({}) rooted", rootedPath); + m_log->info(m_log->key("AyonApi"), "AyonApi::rootReplace({}) rooted", rootedPath); return rootedPath; } catch (std::out_of_range &e) { - m_Log->warn("AyonApi::rootedPath error acured {}, list off available root replace str: "); + m_log->warn("AyonApi::rootedPath error acured {}, list off available root replace str: "); for (auto &g: m_siteRoots) { - m_Log->warn("Key: {}, replacement: {}", g.first, g.second); + m_log->warn("Key: {}, replacement: {}", g.first, g.second); } return rootLessPath; } @@ -279,7 +279,7 @@ AyonApi::GET(const std::shared_ptr endPoint, const std::shared_ptr headers, uint8_t successStatus) { PerfTimer("AyonApi::GET"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::GET({})", *endPoint); + m_log->info(m_log->key("AyonApi"), "AyonApi::GET({})", *endPoint); httplib::Result response; int responseStatus; @@ -289,7 +289,7 @@ AyonApi::GET(const std::shared_ptr endPoint, response = m_ayonServer->Get(*endPoint, *headers); if (!response) { - m_Log->warn("AyonApi::GET response is null: {}", httplib::to_string(response.error())); + m_log->warn("AyonApi::GET response is null: {}", httplib::to_string(response.error())); return nlohmann::json(); } @@ -299,13 +299,13 @@ AyonApi::GET(const std::shared_ptr endPoint, if (responseStatus == successStatus) { return nlohmann::json::parse(response->body); } else { - m_Log->info("AyonApi::serialCorePost wrong status code: {} expected: {}", responseStatus, successStatus); + m_log->info("AyonApi::serialCorePost wrong status code: {} expected: {}", responseStatus, successStatus); if (responseStatus == 401) { - m_Log->warn("not logged in 401 "); + m_log->warn("not logged in 401 "); return nlohmann::json(); } if (responseStatus == 500) { - m_Log->warn("internal server error "); + m_log->warn("internal server error "); return nlohmann::json(); } std::this_thread::sleep_for(std::chrono::milliseconds( @@ -314,10 +314,10 @@ AyonApi::GET(const std::shared_ptr endPoint, } catch (const httplib::Error &e) { - m_Log->warn("Request Failed because: {}", httplib::to_string(e)); + m_log->warn("Request Failed because: {}", httplib::to_string(e)); break; } - m_Log->warn("The connection failed. Retry now."); + m_log->warn("The connection failed. Retry now."); } return nlohmann::json(); }; @@ -328,18 +328,18 @@ AyonApi::SPOST(const std::shared_ptr endPoint, nlohmann::json jsonPayload, const std::shared_ptr successStatus) { PerfTimer("AyonApi::SPOST"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::SPOST endPoint: {}, jsonPayload: {}, successStatus: {}", *endPoint, + m_log->info(m_log->key("AyonApi"), "AyonApi::SPOST endPoint: {}, jsonPayload: {}, successStatus: {}", *endPoint, jsonPayload.dump(), *successStatus); nlohmann::json jsonResponse; if (jsonPayload.empty()) { - m_Log->info("JSON payload is empty. No request created"); + m_log->info("JSON payload is empty. No request created"); return jsonResponse; } if (endPoint == nullptr || headers == nullptr || successStatus == nullptr) { - m_Log->error("One or more of the provided pointers are null: endPoint, headers, successStatus."); + m_log->error("One or more of the provided pointers are null: endPoint, headers, successStatus."); return jsonResponse; } @@ -354,7 +354,7 @@ AyonApi::SPOST(const std::shared_ptr endPoint, // find a better way to make sure its not an array } else { - m_Log->warn("SPOST can't parse JSON // response empty"); + m_log->warn("SPOST can't parse JSON // response empty"); } m_ayonServerMutex.unlock(); return jsonResponse; @@ -366,17 +366,17 @@ AyonApi::CPOST(const std::shared_ptr endPoint, nlohmann::json jsonPayload, const std::shared_ptr successStatus) { PerfTimer("AyonApi::CPOST"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::CPOST endPoint: {}, jsonPayload: {}, successStatus: {}", *endPoint, + m_log->info(m_log->key("AyonApi"), "AyonApi::CPOST endPoint: {}, jsonPayload: {}, successStatus: {}", *endPoint, jsonPayload.dump(), *successStatus); nlohmann::json jsonResponse; if (jsonPayload.empty()) { - m_Log->info("JSON payload is empty. No request created"); + m_log->info("JSON payload is empty. No request created"); return jsonResponse; } if (endPoint == nullptr || headers == nullptr || successStatus == nullptr) { - m_Log->error("One or more of the provided pointers are null: endPoint, headers, successStatus"); + m_log->error("One or more of the provided pointers are null: endPoint, headers, successStatus"); return jsonResponse; } @@ -387,7 +387,7 @@ AyonApi::CPOST(const std::shared_ptr endPoint, jsonResponse = nlohmann::json::parse(rawResponse); } else { - m_Log->warn("CPOST can't parse JSON // response empty"); + m_log->warn("CPOST can't parse JSON // response empty"); } return jsonResponse; }; @@ -395,10 +395,10 @@ AyonApi::CPOST(const std::shared_ptr endPoint, std::pair AyonApi::resolvePath(const std::string &uriPath) { PerfTimer("AyonApi::resolvePath"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::resolvePath({})", uriPath); + m_log->info(m_log->key("AyonApi"), "AyonApi::resolvePath({})", uriPath); if (uriPath.empty()) { - m_Log->info("Path was empty: {}", uriPath.c_str()); + m_log->info("Path was empty: {}", uriPath.c_str()); return {}; } std::pair resolvedAsset; @@ -416,13 +416,13 @@ AyonApi::resolvePath(const std::string &uriPath) { std::unordered_map AyonApi::batchResolvePath(std::vector &uriPaths) { PerfTimer("AyonApi::batchResolvePath"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::batchResolvePath({})", + m_log->info(m_log->key("AyonApi"), "AyonApi::batchResolvePath({})", std::accumulate( uriPaths.begin(), uriPaths.end(), std::string(), [](const std::string &a, const std::string &b) { return a + (a.length() > 0 ? " " : "") + b; })); if (uriPaths.size() < 1) { - m_Log->warn("AyonApi::batchResolvePath Got empty vector stopped resolution"); + m_log->warn("AyonApi::batchResolvePath Got empty vector stopped resolution"); return {}; } @@ -434,7 +434,7 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { for (size_t i = 0; i < size; ++i) s.insert(uriPaths[i]); uriPaths.assign(s.begin(), s.end()); - m_Log->info("Make sure that the vector has no duplicates. vecSize before: {} after: {}", size, + m_log->info("Make sure that the vector has no duplicates. vecSize before: {} after: {}", size, uriPaths.size()); } } @@ -497,13 +497,13 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { grpReason = "If groups are too small, we will build them by size."; } } - m_Log->info( + m_log->info( "AyonApi::batchResolvePath Build groups with grpSize: {} grpAmount: {} groupingReason: {} vectorSize: {}", groupSize, groupAmount, grpReason, uriPathsVecSize); int groupStartPos = 0; int groupEndPos; - for (int thread = 0; thread < groupAmount; thread++) { + for (int thread = 0; thread < groupAmount; thread++) groupEndPos = groupSize * (thread + 1); std::string perTimerLoopName = "AyonApi::batchResolvePath Thread Loop: " + std::to_string(thread); PerfTimer(perTimerLoopName.c_str()); @@ -511,7 +511,7 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { // check if we are too close to the end and extend the group to catch all the data and end the loop if (uriPathsVecSize - groupEndPos < groupSize + (groupSize / 2)) { - m_Log->info("the group with the threadId: {} It is too close to the end. This group will be extended. ", + m_log->info("the group with the threadId: {} It is too close to the end. This group will be extended. ", thread); groupEndPos = uriPathsVecSize - 1; thread = groupAmount; @@ -543,7 +543,7 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { std::pair AyonApi::getAssetIdent(const nlohmann::json &uriResolverResponse) { PerfTimer("AyonApi::getAssetIdent"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::getAssetIdent({})", uriResolverResponse.dump()); + m_log->info(m_log->key("AyonApi"), "AyonApi::getAssetIdent({})", uriResolverResponse.dump()); std::pair AssetIdent; if (uriResolverResponse.empty()) { @@ -552,13 +552,13 @@ AyonApi::getAssetIdent(const nlohmann::json &uriResolverResponse) { try { AssetIdent.first = uriResolverResponse.at("uri"); if (uriResolverResponse.at("entities").size() > 1) { - m_Log->warn("Uri resolution returned more than one path (%s)", uriResolverResponse.at("entities").dump()); + m_log->warn("Uri resolution returned more than one path (%s)", uriResolverResponse.at("entities").dump()); } AssetIdent.second = rootReplace( uriResolverResponse.at("entities").at(uriResolverResponse.at("entities").size() - 1).at("filePath")); } catch (const nlohmann::json::exception &e) { - m_Log->warn("asset identification cant be generated {}", uriResolverResponse.dump()); + m_log->warn("asset identification cant be generated {}", uriResolverResponse.dump()); } return AssetIdent; }; @@ -566,14 +566,14 @@ AyonApi::getAssetIdent(const nlohmann::json &uriResolverResponse) { std::string AyonApi::getKey() { PerfTimer("AyonApi::getKey"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::getKey"); + m_log->info(m_log->key("AyonApi"), "AyonApi::getKey"); return m_authKey; }; std::string AyonApi::getUrl() { PerfTimer("AyonApi::getUrl"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::getUrl"); + m_log->info(m_log->key("AyonApi"), "AyonApi::getUrl"); return m_serverUrl; } @@ -584,7 +584,7 @@ AyonApi::serialCorePost(const std::string &endPoint, std::string &Payload, const int &successStatus) { PerfTimer("AyonApi::serialCorePost"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::serialCorePost() endPoint: {}, Payload: {}, successStatus: {}", + m_log->info(m_log->key("AyonApi"), "AyonApi::serialCorePost() endPoint: {}, Payload: {}, successStatus: {}", endPoint, Payload, successStatus); httplib::Result response; @@ -600,13 +600,13 @@ AyonApi::serialCorePost(const std::string &endPoint, return response->body; } else { - m_Log->info("AyonApi::serialCorePost wrong status code: {} expected: {}", responseStatus, successStatus); + m_log->info("AyonApi::serialCorePost wrong status code: {} expected: {}", responseStatus, successStatus); if (responseStatus == 401) { - m_Log->warn("not logged in 401 "); + m_log->warn("not logged in 401 "); return ""; } if (responseStatus == 500) { - m_Log->warn("internal server error "); + m_log->warn("internal server error "); return ""; } std::this_thread::sleep_for(std::chrono::milliseconds( @@ -614,10 +614,10 @@ AyonApi::serialCorePost(const std::string &endPoint, } } catch (const httplib::Error &e) { - m_Log->warn("Request Failed because: {}", httplib::to_string(e)); + m_log->warn("Request Failed because: {}", httplib::to_string(e)); break; } - m_Log->warn("The connection failed. Retry now."); + m_log->warn("The connection failed. Retry now."); } return ""; }; @@ -628,7 +628,7 @@ AyonApi::generativeCorePost(const std::string &endPoint, std::string &Payload, const int &successStatus) { PerfTimer("AyonApi::generativeCorePost"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::generativeCorePost() endPoint: {}, Payload: {}, successStatus: {}", + m_log->info(m_log->key("AyonApi"), "AyonApi::generativeCorePost() endPoint: {}, Payload: {}, successStatus: {}", endPoint, Payload, successStatus); httplib::Client AyonServerClient(m_serverUrl); @@ -643,22 +643,22 @@ AyonApi::generativeCorePost(const std::string &endPoint, uint16_t loopIteration = 0; while (retries <= m_maxCallRetries || m_generativeCorePostMaxLoopIterations > loopIteration) { loopIteration++; - m_Log->info("AyonApi::generativeCorePost while loop thread {} iteration {}", + m_log->info("AyonApi::generativeCorePost while loop thread {} iteration {}", std::hash{}(std::this_thread::get_id()), loopIteration); if (ffoLock) { m_concurrentRequestAfterFfoMutex.lock(); - m_Log->info("AyonApi::generativeCorePost ffoLock enabled"); + m_log->info("AyonApi::generativeCorePost ffoLock enabled"); if (m_maxConcurrentRequestAfterFfo >= 1) { m_maxConcurrentRequestAfterFfo--; - m_Log->info("AyonApi::generativeCorePost thread pool open available: {}", + m_log->info("AyonApi::generativeCorePost thread pool open available: {}", m_maxConcurrentRequestAfterFfo); m_concurrentRequestAfterFfoMutex.unlock(); } else { - m_Log->info("AyonApi::generativeCorePost Thread pool closed"); + m_log->info("AyonApi::generativeCorePost Thread pool closed"); m_concurrentRequestAfterFfoMutex.unlock(); std::this_thread::sleep_for(std::chrono::milliseconds(800)); @@ -666,7 +666,7 @@ AyonApi::generativeCorePost(const std::string &endPoint, } } - m_Log->info("AyonApi::generativeCorePost sending request"); + m_log->info("AyonApi::generativeCorePost sending request"); try { response = AyonServerClient.Post(endPoint, headers, Payload, "application/json"); @@ -678,39 +678,39 @@ AyonApi::generativeCorePost(const std::string &endPoint, m_concurrentRequestAfterFfoMutex.unlock(); } if (responseStatus == successStatus) { - m_Log->info("AyonApi::generativeCorePost The request worked, unlocking and returning. "); + m_log->info("AyonApi::generativeCorePost The request worked, unlocking and returning. "); return response->body; } else { if (responseStatus == m_serverBusyCode) { - m_Log->warn("AyonApi::generativeCorePost The server responded with 503"); + m_log->warn("AyonApi::generativeCorePost The server responded with 503"); retries = 0; ffoLock = true; continue; } if (responseStatus == 401) { - m_Log->warn("not logged in 401 "); + m_log->warn("not logged in 401 "); return ""; } if (responseStatus == 500) { - m_Log->warn("internal server error "); + m_log->warn("internal server error "); return ""; } - m_Log->info("AyonApi::generativeCorePost wrong status code: {} expected: {} retrying", responseStatus, + m_log->info("AyonApi::generativeCorePost wrong status code: {} expected: {} retrying", responseStatus, successStatus); std::this_thread::sleep_for(std::chrono::milliseconds(m_retryWait)); continue; } } catch (const httplib::Error &e) { - m_Log->warn("AyonApi::generativeCorePost Request Failed because: {}", httplib::to_string(e)); + m_log->warn("AyonApi::generativeCorePost Request Failed because: {}", httplib::to_string(e)); break; } } - m_Log->warn( + m_log->warn( "AyonApi::generativeCorePost Too many resolve retries without the correct response code for: {}, on: {}", Payload, endPoint); return ""; @@ -719,7 +719,7 @@ AyonApi::generativeCorePost(const std::string &endPoint, std::string AyonApi::convertUriVecToString(const std::vector &uriVec) { PerfTimer("AyonApi::convertUriVecToString"); - m_Log->info(m_Log->key("AyonApi"), "AyonApi::convertUriVecToString({})", + m_log->info(m_log->key("AyonApi"), "AyonApi::convertUriVecToString({})", std::accumulate(uriVec.begin(), uriVec.end(), std::string())); std::string payload = R"({{"resolveRoots": true,"uris": [)"; @@ -735,8 +735,8 @@ AyonApi::convertUriVecToString(const std::vector &uriVec) { std::shared_ptr AyonApi::logPointer() { - m_Log->info(m_Log->key("AyonApi"), "AyonApi::logPointer()"); - return m_Log; + m_log->info(m_log->key("AyonApi"), "AyonApi::logPointer()"); + return m_log; }; bool @@ -750,7 +750,7 @@ AyonApi::setSSL() { const char* envCertFile = getenv("SSL_CERT_FILE"); if (envCertFile) { if (std::filesystem::exists(envCertFile)) { - m_Log->info("Using cert based on env variable (SSL_CERT_FILE): {}", envCertFile); + m_log->info("Using cert based on env variable (SSL_CERT_FILE): {}", envCertFile); m_ayonServer->set_ca_cert_path(envCertFile); return; } @@ -761,7 +761,7 @@ AyonApi::setSSL() { std::string certFileCLI = opensslDirCLI.string(); if (std::filesystem::exists(certFileCLI)) { - m_Log->info("Using cert based on CLI var: {}", certFileCLI); + m_log->info("Using cert based on CLI var: {}", certFileCLI); m_ayonServer->set_ca_cert_path(certFileCLI.c_str()); return; } @@ -771,12 +771,12 @@ AyonApi::setSSL() { std::string certFileSSLEAY = opensslDirSSLEAY.string(); if (std::filesystem::exists(certFileSSLEAY)) { - m_Log->info("Using cert based on SSLEAY_DIR: {}", certFileSSLEAY); + m_log->info("Using cert based on SSLEAY_DIR: {}", certFileSSLEAY); m_ayonServer->set_ca_cert_path(certFileSSLEAY.c_str()); return; } - m_Log->info("Failed to determine the OpenSSL directory or load system CAs. Falling back to bundled certificate path."); + m_log->info("Failed to determine the OpenSSL directory or load system CAs. Falling back to bundled certificate path."); std::filesystem::path soPath; Dl_info dl_info; @@ -795,14 +795,14 @@ AyonApi::setSSL() { std::string certPath = bundledPath.string(); if (std::filesystem::exists(certPath)) { - m_Log->info("Using bundled certificate (via SO path): {}", certPath); + m_log->info("Using bundled certificate (via SO path): {}", certPath); m_ayonServer->set_ca_cert_path(certPath.c_str()); return; } - m_Log->error("Bundled cacert.pem file not found at expected runtime path: {}", certPath); + m_log->error("Bundled cacert.pem file not found at expected runtime path: {}", certPath); } else { - m_Log->error("Failed to determine the path of the loaded shared library (dladdr failed)."); + m_log->error("Failed to determine the path of the loaded shared library (dladdr failed)."); } throw std::runtime_error("Failed to set SSL certificate path. No valid certificate found."); From f45f4e7140b4fb93d357829783677c966c780644 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Tue, 6 Jan 2026 16:38:13 +0100 Subject: [PATCH 25/27] fix of variable name --- src/AyonCppApi/AyonCppApi.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.h b/src/AyonCppApi/AyonCppApi.h index f30c56b..a6bb115 100644 --- a/src/AyonCppApi/AyonCppApi.h +++ b/src/AyonCppApi/AyonCppApi.h @@ -221,8 +221,8 @@ class AyonApi { // Thread Synchronization std::mutex m_ayonServerMutex; - std::mutex m_concurrentRequestAfter503Mutex; - uint8_t m_maxConcurrentRequestsAfter503 = 8; + std::mutex m_concurrentRequestAfterFfoMutex; + uint8_t m_maxConcurrentRequestAfterFfo = 8; }; #endif // !AYONCPPAPI_H From 70ef824fce4b7523a994f6a7337ac116ced3d523 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Tue, 6 Jan 2026 16:48:06 +0100 Subject: [PATCH 26/27] fix of compiler errors --- src/AyonCppApi/AyonCppApi.cpp | 56 +++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index 0e6ecad..af65a1e 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -37,7 +37,7 @@ #include #endif -// TODO implement the better Crash hanlder +// TODO implement the better Crash handler backward::StackTrace st; // ------------------------------------------------ @@ -97,7 +97,7 @@ AyonApi::AyonApi(const std::optional &logFilePos, const std::string &ayonProjectName, const std::string &siteId, std::optional concurrency) - : m_num_threads(concurrency.value_or(std::max(int(std::thread::hardware_concurrency() / 2), 1))), + : m_numThreads(concurrency.value_or(std::max(int(std::thread::hardware_concurrency() / 2), 1))), m_authKey(authKey), m_serverUrl(serverUrl), m_ayonProjectName(ayonProjectName), @@ -135,7 +135,7 @@ AyonApi::AyonApi(const std::optional &logFilePos, } } - // ----------- Init m_logger (Singleton Logic) + // ----------- Init m_log (Singleton Logic) std::cout << "[AyonApi] Retrieving AyonLogger Singleton..." << std::endl; AyonLogger& loggerRef = AyonLogger::getInstance(); @@ -224,7 +224,7 @@ AyonApi::getSiteRoots() { if (response.empty()) { m_log->error("AyonApi::getSiteRoots response is empty"); - return &m_siteRoots; + return m_siteRoots; } else { m_siteRoots = response; } @@ -237,7 +237,7 @@ AyonApi::getSiteRoots() { } } - return &m_siteRoots; + return m_siteRoots; }; std::string @@ -262,7 +262,7 @@ AyonApi::rootReplace(const std::string &rootLessPath) { return rootedPath; } catch (std::out_of_range &e) { - m_log->warn("AyonApi::rootedPath error acured {}, list off available root replace str: "); + m_log->warn("AyonApi::rootedPath error occurred {}, list of available root replace str: ", e.what()); for (auto &g: m_siteRoots) { m_log->warn("Key: {}, replacement: {}", g.first, g.second); } @@ -299,7 +299,7 @@ AyonApi::GET(const std::shared_ptr endPoint, if (responseStatus == successStatus) { return nlohmann::json::parse(response->body); } else { - m_log->info("AyonApi::serialCorePost wrong status code: {} expected: {}", responseStatus, successStatus); + m_log->info("AyonApi::GET wrong status code: {} expected: {}", responseStatus, successStatus); if (responseStatus == 401) { m_log->warn("not logged in 401 "); return nlohmann::json(); @@ -391,7 +391,8 @@ AyonApi::CPOST(const std::shared_ptr endPoint, } return jsonResponse; }; -// TODO change the pointer work in here because the pointers consume more data that coping would + +// TODO change the pointer work in here because the pointers consume more data that copying would std::pair AyonApi::resolvePath(const std::string &uriPath) { PerfTimer("AyonApi::resolvePath"); @@ -468,14 +469,13 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { // check what scaling the groups should have if (uriPathsVecSize > m_minVecSizeForGroupSplitAsyncRequests) { // vector size is large enough to build groups - // double result = static_cast(uriPathsVecSize) / num_threads; - groupSize = std::ceil(static_cast(uriPathsVecSize) / m_num_threads); - if (groupSize > m_minGrpSizeForAsyncRequests) { + groupSize = std::ceil(static_cast(uriPathsVecSize) / m_numThreads); + if (groupSize > m_minGroupSizeForAsyncRequests) { // the group size is large enough to build groups from them if (groupSize < m_maxGroupSizeForAsyncRequests) { // now it's bigger than 5 and smaller than 500 // now we can just generate a group per thread and set the group amount - groupSize = std::ceil(static_cast(uriPathsVecSize) / m_num_threads); + groupSize = std::ceil(static_cast(uriPathsVecSize) / m_numThreads); groupAmount = std::floor(static_cast(uriPathsVecSize) / groupSize); // TODO explicit rounding .x group amount @@ -503,7 +503,7 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { int groupStartPos = 0; int groupEndPos; - for (int thread = 0; thread < groupAmount; thread++) + for (int thread = 0; thread < groupAmount; thread++) { groupEndPos = groupSize * (thread + 1); std::string perTimerLoopName = "AyonApi::batchResolvePath Thread Loop: " + std::to_string(thread); PerfTimer(perTimerLoopName.c_str()); @@ -539,6 +539,7 @@ AyonApi::batchResolvePath(std::vector &uriPaths) { return assetIdentGrp; }; + // TODO make it so that hero version is chosen if available std::pair AyonApi::getAssetIdent(const nlohmann::json &uriResolverResponse) { @@ -552,7 +553,7 @@ AyonApi::getAssetIdent(const nlohmann::json &uriResolverResponse) { try { AssetIdent.first = uriResolverResponse.at("uri"); if (uriResolverResponse.at("entities").size() > 1) { - m_log->warn("Uri resolution returned more than one path (%s)", uriResolverResponse.at("entities").dump()); + m_log->warn("Uri resolution returned more than one path: {}", uriResolverResponse.at("entities").dump()); } AssetIdent.second = rootReplace( uriResolverResponse.at("entities").at(uriResolverResponse.at("entities").size() - 1).at("filePath")); @@ -647,20 +648,20 @@ AyonApi::generativeCorePost(const std::string &endPoint, std::hash{}(std::this_thread::get_id()), loopIteration); if (ffoLock) { - m_concurrentRequestAfterFfoMutex.lock(); + m_concurrentRequestAfter503Mutex.lock(); m_log->info("AyonApi::generativeCorePost ffoLock enabled"); - if (m_maxConcurrentRequestAfterFfo >= 1) { - m_maxConcurrentRequestAfterFfo--; + if (m_maxConcurrentRequestsAfter503 >= 1) { + m_maxConcurrentRequestsAfter503--; m_log->info("AyonApi::generativeCorePost thread pool open available: {}", - m_maxConcurrentRequestAfterFfo); + m_maxConcurrentRequestsAfter503); - m_concurrentRequestAfterFfoMutex.unlock(); + m_concurrentRequestAfter503Mutex.unlock(); } else { m_log->info("AyonApi::generativeCorePost Thread pool closed"); - m_concurrentRequestAfterFfoMutex.unlock(); + m_concurrentRequestAfter503Mutex.unlock(); std::this_thread::sleep_for(std::chrono::milliseconds(800)); continue; } @@ -673,9 +674,9 @@ AyonApi::generativeCorePost(const std::string &endPoint, responseStatus = response->status; retries++; if (ffoLock) { - m_concurrentRequestAfterFfoMutex.lock(); - m_maxConcurrentRequestAfterFfo++; - m_concurrentRequestAfterFfoMutex.unlock(); + m_concurrentRequestAfter503Mutex.lock(); + m_maxConcurrentRequestsAfter503++; + m_concurrentRequestAfter503Mutex.unlock(); } if (responseStatus == successStatus) { m_log->info("AyonApi::generativeCorePost The request worked, unlocking and returning. "); @@ -722,10 +723,13 @@ AyonApi::convertUriVecToString(const std::vector &uriVec) { m_log->info(m_log->key("AyonApi"), "AyonApi::convertUriVecToString({})", std::accumulate(uriVec.begin(), uriVec.end(), std::string())); - std::string payload = R"({{"resolveRoots": true,"uris": [)"; + std::string payload = R"({"resolveRoots": true,"uris": [)"; - for (size_t i = 0; i <= uriVec.size(); i++) { - payload += uriVec[i]; + for (size_t i = 0; i < uriVec.size(); i++) { + payload += "\"" + uriVec[i] + "\""; + if (i < uriVec.size() - 1) { + payload += ","; + } } payload += "]}"; From 1adbf5ac284adb053ba738b896f18206ecf6b725 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Tue, 6 Jan 2026 16:54:07 +0100 Subject: [PATCH 27/27] variable names fix --- src/AyonCppApi/AyonCppApi.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.h b/src/AyonCppApi/AyonCppApi.h index a6bb115..f30c56b 100644 --- a/src/AyonCppApi/AyonCppApi.h +++ b/src/AyonCppApi/AyonCppApi.h @@ -221,8 +221,8 @@ class AyonApi { // Thread Synchronization std::mutex m_ayonServerMutex; - std::mutex m_concurrentRequestAfterFfoMutex; - uint8_t m_maxConcurrentRequestAfterFfo = 8; + std::mutex m_concurrentRequestAfter503Mutex; + uint8_t m_maxConcurrentRequestsAfter503 = 8; }; #endif // !AYONCPPAPI_H