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
4#include <sys/types.h>
5#include <cstddef>
6#include <cstdint>
7#include <memory>
8#include <mutex>
9#include <regex>
10#include <shared_mutex>
11#include <string>
12#include <utility>
13#include <vector>
14#include "AyonLogger.h"
15#include "appDataFoulder.h"
16#include "httplib.h"
17#include "nlohmann/json_fwd.hpp"
18
25class AyonApi {
26 public:
30 AyonApi();
34 ~AyonApi();
35
40 std::string getKey();
45 std::string getUrl();
46
54 nlohmann::json GET(const std::shared_ptr<std::string> endPoint,
55 const std::shared_ptr<httplib::Headers> headers,
56 uint8_t sucsessStatus);
57
66 nlohmann::json SPOST(const std::shared_ptr<std::string> endPoint,
67 const std::shared_ptr<httplib::Headers> headers,
68 nlohmann::json jsonPayload,
69 const std::shared_ptr<uint8_t> sucsessStatus);
78 nlohmann::json CPOST(const std::shared_ptr<std::string> endPoint,
79 const std::shared_ptr<httplib::Headers> headers,
80 nlohmann::json jsonPayload,
81 const std::shared_ptr<uint8_t> sucsessStatus);
82
89 std::pair<std::string, std::string> resolvePath(const std::string &uriPath);
95 std::unordered_map<std::string, std::string> batchResolvePath(std::vector<std::string> &uriPaths);
96
103 std::pair<std::string, std::string> getAssetIdent(const nlohmann::json &uriResolverRespone);
104
111 bool loadEnvVars();
112
116 std::shared_ptr<AyonLogger> logPointer();
117
122 std::unordered_map<std::string, std::string>*
123 getSiteRoots(); // TODO think about if this should only support current project or multiple projects
124
131 std::string rootReplace(const std::string &rootLessPath);
132
133 private:
142 std::string serialCorePost(const std::string &endPoint,
143 httplib::Headers headers,
144 std::string &Payload,
145 const int &sucsessStatus);
154 std::string GenerativeCorePost(const std::string &endPoint,
155 httplib::Headers headers,
156 std::string &Payload,
157 const int &sucsessStatus);
158
164 std::string convertUriVecToString(const std::vector<std::string> &uriVec);
165
166 // ----- Env Varibles
167
168 std::unique_ptr<httplib::Client> AyonServer;
169
170 std::unordered_map<std::string, std::string> siteRoots;
171
172 const char* authKey;
173 const char* serverUrl;
174 std::string ayonProjectName;
175
176 std::string ayonAppData = getAppDataDir() + "/AYON";
177
178 // ---- Server Vars
179 std::string siteId;
180 std::string userName;
181
182 // --- Runtime Dep Vars
183
184 // Async Grp Generation Varibles
189 u_int8_t maxCallRetrys = 8;
190 u_int16_t retryWaight = 800;
191
195 const int num_threads; // set by constructor
196 std::shared_ptr<AyonLogger> Log;
197 std::string uriResolverEndpoint = "/api/resolve";
198 std::string uriResolverEndpointPathOnlyVar = "?pathOnly=true";
200
203
205
206 u_int16_t connectionTimeOutMax = 200;
207 u_int8_t readTimeOutMax = 160;
208 // bool enableThreadWaithing = false;
209 // bool enableBigBlockThreadWaithing = true;
214
215 uint16_t ServerBusyCode = 503;
217 // std::mutex allowRequest;
218
222 bool serverBusy = false;
223
227 std::mutex AyonServerMutex;
228};
229
230#endif // !AYONCPPAPI_H
std::string getAppDataDir()
Definition: appDataFoulder.h:25
Central Ayon api class Class for exposing Ayon server functions to C++ users.
Definition: AyonCppApi.h:25
bool batchResolveOptimizeVector
decides if the cpp api removes duplicates from batch request vector default is true
Definition: AyonCppApi.h:213
std::string getUrl()
returns the stored AYON server url.
Definition: AyonCppApi.cpp:462
std::string 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:470
std::string rootReplace(const std::string &rootLessPath)
replaces {root[var]} for ayon:// paths
Definition: AyonCppApi.cpp:138
bool loadEnvVars()
this function loads all needed varible into the class this will allso be called by the constructor
Definition: AyonCppApi.cpp:64
std::string uriResolverEndpointPathOnlyVar
Definition: AyonCppApi.h:198
std::string siteId
Definition: AyonCppApi.h:179
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:252
u_int16_t maxGroupSizeForAsyncRequests
Definition: AyonCppApi.h:187
u_int8_t maxCallRetrys
Definition: AyonCppApi.h:189
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:514
std::mutex ConcurentRequestAfterffoMutex
Definition: AyonCppApi.h:201
AyonApi()
constructor
Definition: AyonCppApi.cpp:39
const char * authKey
Definition: AyonCppApi.h:172
std::unordered_map< std::string, std::string > * getSiteRoots()
gets the site root overwrites for the current project.
Definition: AyonCppApi.cpp:119
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:284
bool serverBusy
this bool will be set to true if a 503 is encountered
Definition: AyonCppApi.h:222
bool pathOnlyReselution
Definition: AyonCppApi.h:199
u_int16_t retryWaight
Definition: AyonCppApi.h:190
uint16_t ServerBusyCode
Definition: AyonCppApi.h:215
std::unique_ptr< httplib::Client > AyonServer
Definition: AyonCppApi.h:168
const char * serverUrl
Definition: AyonCppApi.h:173
std::unordered_map< std::string, std::string > siteRoots
Definition: AyonCppApi.h:170
u_int16_t connectionTimeOutMax
Definition: AyonCppApi.h:206
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:172
u_int8_t minGrpSizeForAsyncRequests
Definition: AyonCppApi.h:185
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:606
std::string ayonAppData
Definition: AyonCppApi.h:176
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:306
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:214
std::string userName
Definition: AyonCppApi.h:180
const int num_threads
maximum number off threads that the cpu can handle at the same time.
Definition: AyonCppApi.h:195
u_int16_t regroupSizeForAsyncRequests
Definition: AyonCppApi.h:186
std::mutex AyonServerMutex
needed for serial resolve operations.
Definition: AyonCppApi.h:227
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:432
std::string getKey()
returns the stored apikey.
Definition: AyonCppApi.cpp:455
std::shared_ptr< AyonLogger > Log
Definition: AyonCppApi.h:196
~AyonApi()
destructor
Definition: AyonCppApi.cpp:59
u_int16_t minVecSizeForGroupSplitAsyncRequests
Definition: AyonCppApi.h:188
uint16_t RequestDelayWhenServerBusy
Definition: AyonCppApi.h:216
uint16_t GenerativeCorePostMaxLoopIterations
Definition: AyonCppApi.h:204
std::string ayonProjectName
Definition: AyonCppApi.h:174
uint8_t maxConcurentRequestAfterffo
Definition: AyonCppApi.h:202
u_int8_t readTimeOutMax
Definition: AyonCppApi.h:207
std::shared_ptr< AyonLogger > logPointer()
get function for shared AyonLogger pointer used by this class instance
Definition: AyonCppApi.cpp:623