AYON Cpp Api  0.1.0
Loading...
Searching...
No Matches
AyonCppApi.h
Go to the documentation of this file.
1#ifndef AYONCPPAPI_H
2#define AYONCPPAPI_H
3#include <sys/types.h>
4#include <cstdint>
5#include <memory>
6#include <mutex>
7#include <optional>
8
9#include <string>
10#include <utility>
11#include <vector>
12#include "lib/ynput/lib/logging/AyonLogger.hpp"
13#include "appDataFoulder.h"
14#include "httplib.h"
15#include "nlohmann/json_fwd.hpp"
16
23class AyonApi {
24 public:
28 AyonApi(const std::optional<std::string> &logFilePos,
29 const std::string &authKey,
30 const std::string &serverUrl,
31 const std::string &ayonProjectName,
32 const std::string &siteId,
33 std::optional<int> concurrency = std::nullopt);
37 ~AyonApi();
38
43 std::string getKey();
48 std::string getUrl();
49
57 nlohmann::json GET(const std::shared_ptr<std::string> endPoint,
58 const std::shared_ptr<httplib::Headers> headers,
59 uint8_t sucsessStatus);
60
69 nlohmann::json SPOST(const std::shared_ptr<std::string> endPoint,
70 const std::shared_ptr<httplib::Headers> headers,
71 nlohmann::json jsonPayload,
72 const std::shared_ptr<uint8_t> sucsessStatus);
81 nlohmann::json CPOST(const std::shared_ptr<std::string> endPoint,
82 const std::shared_ptr<httplib::Headers> headers,
83 nlohmann::json jsonPayload,
84 const std::shared_ptr<uint8_t> sucsessStatus);
85
92 std::pair<std::string, std::string> resolvePath(const std::string &uriPath);
98 std::unordered_map<std::string, std::string> batchResolvePath(std::vector<std::string> &uriPaths);
99
106 std::pair<std::string, std::string> getAssetIdent(const nlohmann::json &uriResolverRespone);
107
115
119 std::shared_ptr<AyonLogger> logPointer();
120
125 std::unordered_map<std::string, std::string>*
126 getSiteRoots(); // TODO think about if this should only support current project or multiple projects
127
134 std::string rootReplace(const std::string &rootLessPath);
135
136 private:
145 std::string serialCorePost(const std::string &endPoint,
146 httplib::Headers headers,
147 std::string &Payload,
148 const int &sucsessStatus);
157 std::string GenerativeCorePost(const std::string &endPoint,
158 httplib::Headers headers,
159 std::string &Payload,
160 const int &sucsessStatus);
161
167 std::string convertUriVecToString(const std::vector<std::string> &uriVec);
168
169 // ----- Env Varibles
170 std::unique_ptr<httplib::Client> m_AyonServer;
171
172 std::unordered_map<std::string, std::string> m_siteRoots;
173
174 const std::string m_authKey;
175 const std::string m_serverUrl;
176 std::string m_ayonProjectName;
177
178 // ---- Server Vars
179 std::string m_siteId;
180 std::string m_userName;
181
182 // --- Runtime Dep Vars
183
184 // Async Grp Generation Varibles
189 uint8_t m_maxCallRetrys = 8;
190 uint16_t m_retryWaight = 800;
191
195 const int m_num_threads; // set by constructor
196 std::shared_ptr<AyonLogger> m_Log;
197 std::string m_uriResolverEndpoint = "/api/resolve";
198 std::string m_uriResolverEndpointPathOnlyVar = "?pathOnly=true";
200
203
205
207 uint8_t m_readTimeOutMax = 160;
208
213
214 uint16_t m_ServerBusyCode = 503;
216
220 bool m_serverBusy = false;
221
226};
227
228#endif // !AYONCPPAPI_H
Central Ayon api class Class for exposing Ayon server functions to C++ users.
Definition: AyonCppApi.h:23
uint16_t m_regroupSizeForAsyncRequests
Definition: AyonCppApi.h:186
std::string getUrl()
returns the stored AYON server url.
Definition: AyonCppApi.cpp:436
std::string m_uriResolverEndpoint
Definition: AyonCppApi.h:197
std::string serialCorePost(const std::string &endPoint, httplib::Headers headers, std::string &Payload, const int &sucsessStatus)
calls the server in an serial way by sharing the AyonServer pointer
Definition: AyonCppApi.cpp:444
std::string rootReplace(const std::string &rootLessPath)
replaces {root[var]} for ayon:// paths
Definition: AyonCppApi.cpp:111
bool loadEnvVars()
this function loads all needed varible into the class this will allso be called by the constructor
nlohmann::json CPOST(const std::shared_ptr< std::string > endPoint, const std::shared_ptr< httplib::Headers > headers, nlohmann::json jsonPayload, const std::shared_ptr< uint8_t > sucsessStatus)
http post request utilizing the creation of a new httplib client ( Generative Async )
Definition: AyonCppApi.cpp:225
bool m_serverBusy
this bool will be set to true if a 503 is encountered
Definition: AyonCppApi.h:220
std::unordered_map< std::string, std::string > m_siteRoots
Definition: AyonCppApi.h:172
std::string GenerativeCorePost(const std::string &endPoint, httplib::Headers headers, std::string &Payload, const int &sucsessStatus)
calls the server while creating a new client instance to stay async
Definition: AyonCppApi.cpp:488
std::shared_ptr< AyonLogger > m_Log
Definition: AyonCppApi.h:196
uint16_t m_RequestDelayWhenServerBusy
Definition: AyonCppApi.h:215
std::unordered_map< std::string, std::string > * getSiteRoots()
gets the site root overwrites for the current project.
Definition: AyonCppApi.cpp:91
std::pair< std::string, std::string > resolvePath(const std::string &uriPath)
uses the uri resolve endpoint on the AYON server in order to resolve an uri path towards the local pa...
Definition: AyonCppApi.cpp:257
std::mutex m_ConcurentRequestAfterffoMutex
Definition: AyonCppApi.h:201
uint16_t m_GenerativeCorePostMaxLoopIterations
Definition: AyonCppApi.h:204
uint16_t m_connectionTimeOutMax
Definition: AyonCppApi.h:206
std::string m_userName
Definition: AyonCppApi.h:180
std::mutex m_AyonServerMutex
needed for serial resolve operations.
Definition: AyonCppApi.h:225
const int m_num_threads
maximum number off threads that the cpu can handle at the same time.
Definition: AyonCppApi.h:195
uint16_t m_ServerBusyCode
Definition: AyonCppApi.h:214
uint8_t m_maxConcurentRequestAfterffo
Definition: AyonCppApi.h:202
nlohmann::json GET(const std::shared_ptr< std::string > endPoint, const std::shared_ptr< httplib::Headers > headers, uint8_t sucsessStatus)
runns a get command and returns the response body as std::string
Definition: AyonCppApi.cpp:145
std::string m_ayonProjectName
Definition: AyonCppApi.h:176
uint16_t m_minVecSizeForGroupSplitAsyncRequests
Definition: AyonCppApi.h:188
bool m_pathOnlyReselution
Definition: AyonCppApi.h:199
const std::string m_authKey
Definition: AyonCppApi.h:174
std::string convertUriVecToString(const std::vector< std::string > &uriVec)
converts a vector off uris into an string to serve into CorePost funcs
Definition: AyonCppApi.cpp:582
std::unordered_map< std::string, std::string > batchResolvePath(std::vector< std::string > &uriPaths)
resolves a vector off paths against the AYON server in an async way uses auto generated batch request...
Definition: AyonCppApi.cpp:279
nlohmann::json SPOST(const std::shared_ptr< std::string > endPoint, const std::shared_ptr< httplib::Headers > headers, nlohmann::json jsonPayload, const std::shared_ptr< uint8_t > sucsessStatus)
post Request via a shared httplib client ( serial )
Definition: AyonCppApi.cpp:187
std::pair< std::string, std::string > getAssetIdent(const nlohmann::json &uriResolverRespone)
this function takes a ayon path uri response(resolved ayon://path) and returns a pair of assetIdentif...
Definition: AyonCppApi.cpp:406
std::string getKey()
returns the stored apikey.
Definition: AyonCppApi.cpp:429
bool m_batchResolveOptimizeVector
decides if the cpp api removes duplicates from batch request vector default is true
Definition: AyonCppApi.h:212
~AyonApi()
destructor
Definition: AyonCppApi.cpp:86
uint8_t m_maxCallRetrys
Definition: AyonCppApi.h:189
uint8_t m_readTimeOutMax
Definition: AyonCppApi.h:207
std::string m_uriResolverEndpointPathOnlyVar
Definition: AyonCppApi.h:198
std::unique_ptr< httplib::Client > m_AyonServer
Definition: AyonCppApi.h:170
uint16_t m_maxGroupSizeForAsyncRequests
Definition: AyonCppApi.h:187
uint8_t m_minGrpSizeForAsyncRequests
Definition: AyonCppApi.h:185
uint16_t m_retryWaight
Definition: AyonCppApi.h:190
const std::string m_serverUrl
Definition: AyonCppApi.h:175
std::string m_siteId
Definition: AyonCppApi.h:179
std::shared_ptr< AyonLogger > logPointer()
get function for shared AyonLogger pointer used by this class instance
Definition: AyonCppApi.cpp:599