|
KiCad PCB EDA Suite
|
#include <http_lib_connection.h>
Public Types | |
| using | RETRIEVER |
| Allows replacing CURL fetches with a mock for testing. | |
Public Member Functions | |
| HTTP_LIB_CONNECTION (const HTTP_LIB_SOURCE &aSource, bool aTestConnectionNow) | |
| HTTP_LIB_CONNECTION (const HTTP_LIB_SOURCE &aSource, bool aTestConnectionNow, RETRIEVER aRetriever) | |
| virtual | ~HTTP_LIB_CONNECTION ()=default |
| bool | IsValidEndpoint () const |
| bool | SelectOne (const std::string &aPartID, HTTP_LIB_PART &aFetchedPart) |
| Retrieve a single part with full details from the HTTP library. | |
| bool | SelectAll (const HTTP_LIB_CATEGORY &aCategory, std::vector< HTTP_LIB_PART > &aParts) |
| Retrieve all parts from a specific category from the HTTP library. | |
| std::string | GetLastError () const |
| std::vector< HTTP_LIB_CATEGORY > | getCategories () const |
| std::string | getCategoryDescription (const std::string &aCategoryName) const |
| bool | HasCachedParts () const |
| bool | GetCachedPartRelation (const std::string &aPartName, std::string &aPartId, std::string &aCategoryId) const |
| Resolve a cached part name to its part ID and category ID. | |
| void | ClearPartCache () |
Private Member Functions | |
| bool | validateHttpLibraryEndpoints () |
| bool | syncCategories () |
| bool | retrieve (const std::string &aUrl, int &aStatusCode, std::string &aBody) |
Fetch aUrl through the transport. | |
| bool | checkServerResponse (int aStatusCode) |
| wxString | httpErrorCodeDescription (uint16_t aHttpCode) |
| HTTP response status codes indicate whether a specific HTTP request has been successfully completed. | |
Private Attributes | |
| std::mutex | m_queryMutex |
| HTTP_LIB_SOURCE | m_source |
| RETRIEVER | m_retriever |
| bool | m_endpointValid = false |
| std::string | m_lastError |
| std::vector< HTTP_LIB_CATEGORY > | m_categories |
| std::map< std::string, std::string > | m_categoryDescriptions |
| std::map< std::string, std::string > | m_parts |
| std::map< std::string, HTTP_LIB_PART > | m_cachedParts |
| std::map< std::string, std::tuple< std::string, std::string > > | m_cache |
Definition at line 47 of file http_lib_connection.h.
Allows replacing CURL fetches with a mock for testing.
| aUrl | the URL to retrieve |
| aStatusCode | receives the HTTP status (0 when no response was received) |
| aBody | receives the response body |
| aError | receives a failure reason when the request could not be completed |
Definition at line 60 of file http_lib_connection.h.
| HTTP_LIB_CONNECTION::HTTP_LIB_CONNECTION | ( | const HTTP_LIB_SOURCE & | aSource, |
| bool | aTestConnectionNow ) |
Definition at line 67 of file http_lib_connection.cpp.
References HTTP_LIB_CONNECTION(), and makeDefaultRetriever().
Referenced by HTTP_LIB_CONNECTION().
| HTTP_LIB_CONNECTION::HTTP_LIB_CONNECTION | ( | const HTTP_LIB_SOURCE & | aSource, |
| bool | aTestConnectionNow, | ||
| RETRIEVER | aRetriever ) |
Definition at line 73 of file http_lib_connection.cpp.
References m_retriever, m_source, move, and validateHttpLibraryEndpoints().
|
virtualdefault |
|
private |
Definition at line 455 of file http_lib_connection.cpp.
References _, httpErrorCodeDescription(), and m_lastError.
Referenced by SelectOne(), syncCategories(), and validateHttpLibraryEndpoints().
|
inline |
Definition at line 139 of file http_lib_connection.h.
References m_cache, m_cachedParts, and m_queryMutex.
|
inline |
Resolve a cached part name to its part ID and category ID.
| aPartName | the name to look up |
| aPartId | receives the part ID on a hit |
| aCategoryId | receives the category ID on a hit |
Definition at line 125 of file http_lib_connection.h.
References m_cache, and m_queryMutex.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Definition at line 95 of file http_lib_connection.h.
References m_categories, and m_queryMutex.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Definition at line 101 of file http_lib_connection.h.
References m_categoryDescriptions, and m_queryMutex.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Definition at line 89 of file http_lib_connection.h.
References m_lastError, and m_queryMutex.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
inline |
Definition at line 111 of file http_lib_connection.h.
References m_cache, and m_queryMutex.
|
private |
HTTP response status codes indicate whether a specific HTTP request has been successfully completed.
Responses are grouped in five classes:
Server error responses (500 ? 599)
see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
Definition at line 468 of file http_lib_connection.cpp.
Referenced by checkServerResponse().
|
inline |
Definition at line 69 of file http_lib_connection.h.
References m_endpointValid.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), SelectAll(), SelectOne(), and syncCategories().
|
private |
Fetch aUrl through the transport.
aStatusCode is not 200. Definition at line 441 of file http_lib_connection.cpp.
References m_lastError, and m_retriever.
Referenced by SelectAll(), SelectOne(), syncCategories(), and validateHttpLibraryEndpoints().
| bool HTTP_LIB_CONNECTION::SelectAll | ( | const HTTP_LIB_CATEGORY & | aCategory, |
| std::vector< HTTP_LIB_PART > & | aParts ) |
Retrieve all parts from a specific category from the HTTP library.
| aCategory | is the category to fetch parts from |
| aParts | will be filled with all parts in that category |
Definition at line 384 of file http_lib_connection.cpp.
References _, HTTP_LIB_PART::detailsLoaded, HTTP_LIB_CATEGORY::id, HTTP_LIB_PART::id, IsValidEndpoint(), HTTP_LIB_PART::lastCached, m_cache, m_cachedParts, m_lastError, m_queryMutex, m_source, HTTP_LIB_PART::name, res, retrieve(), setPartExtendedData(), setPartIdNameAndMetadata(), and traceHTTPLib.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and fetchCategoryParts().
| bool HTTP_LIB_CONNECTION::SelectOne | ( | const std::string & | aPartID, |
| HTTP_LIB_PART & | aFetchedPart ) |
Retrieve a single part with full details from the HTTP library.
| aPartID | is the unique ID of the part |
| aFetchedPart | will contain the part if one was found |
Definition at line 312 of file http_lib_connection.cpp.
References _, HTTP_LIB_PART::associated_footprints, checkServerResponse(), HTTP_LIB_PART::detailsLoaded, HTTP_LIB_PART::id, IsValidEndpoint(), HTTP_LIB_PART::lastCached, m_cachedParts, m_lastError, m_queryMutex, m_source, HTTP_LIB_PART::named_pin_maps, ParseAssociatedFootprints(), ParseLegacyPinAssignments(), ParsePinMapSet(), HTTP_LIB_PART::pin_map, res, retrieve(), setPartExtendedData(), setPartIdNameAndMetadata(), and traceHTTPLib.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and fetchCategoryParts().
|
private |
Definition at line 131 of file http_lib_connection.cpp.
References _, checkServerResponse(), HTTP_LIB_CATEGORY::description, HTTP_LIB_CATEGORY::id, IsValidEndpoint(), m_categories, m_categoryDescriptions, m_lastError, m_source, HTTP_LIB_CATEGORY::name, res, retrieve(), and traceHTTPLib.
Referenced by validateHttpLibraryEndpoints().
|
private |
Definition at line 83 of file http_lib_connection.cpp.
References _, checkServerResponse(), m_endpointValid, m_lastError, m_queryMutex, m_source, res, retrieve(), syncCategories(), and traceHTTPLib.
Referenced by HTTP_LIB_CONNECTION().
|
private |
Definition at line 192 of file http_lib_connection.h.
Referenced by ClearPartCache(), GetCachedPartRelation(), HasCachedParts(), and SelectAll().
|
private |
Definition at line 189 of file http_lib_connection.h.
Referenced by ClearPartCache(), SelectAll(), and SelectOne().
|
private |
Definition at line 184 of file http_lib_connection.h.
Referenced by getCategories(), and syncCategories().
|
private |
Definition at line 185 of file http_lib_connection.h.
Referenced by getCategoryDescription(), and syncCategories().
|
private |
Definition at line 181 of file http_lib_connection.h.
Referenced by IsValidEndpoint(), and validateHttpLibraryEndpoints().
|
private |
Definition at line 182 of file http_lib_connection.h.
Referenced by checkServerResponse(), GetLastError(), retrieve(), SelectAll(), SelectOne(), syncCategories(), and validateHttpLibraryEndpoints().
|
private |
Definition at line 186 of file http_lib_connection.h.
|
mutableprivate |
Definition at line 177 of file http_lib_connection.h.
Referenced by ClearPartCache(), GetCachedPartRelation(), getCategories(), getCategoryDescription(), GetLastError(), HasCachedParts(), SelectAll(), SelectOne(), and validateHttpLibraryEndpoints().
|
private |
Definition at line 180 of file http_lib_connection.h.
Referenced by HTTP_LIB_CONNECTION(), and retrieve().
|
private |
Definition at line 179 of file http_lib_connection.h.
Referenced by HTTP_LIB_CONNECTION(), SelectAll(), SelectOne(), syncCategories(), and validateHttpLibraryEndpoints().