|
SOMHunter Core
|
Class responsible for listening for HTTP requests and for handlling them using the core. More...
#include <network-api.h>

Public Member Functions | |
| NetworkApi ()=delete | |
| Only single ctor overload is acceptable. More... | |
| NetworkApi (const ApiConfig &API, Somhunter *p_core) | |
| Constructs the HTTP API instance for the given core and with the given API config. More... | |
| void | initialize () |
| Initializes the HTTP listeners on the required endpoints. More... | |
| void | run () |
The "main" function of the HTTP API - calls both initialize & terminate. More... | |
| void | terminate () |
| Safely terminates all the endpoint listeners. More... | |
Private Member Functions | |
| void | handle__api__GET (http_request req) |
| void | handle__api__config__GET (http_request req) |
| void | handle__config__GET (http_request req) |
| void | handle__user__context__GET (http_request req) |
| void | handle__dataset__video_detail__GET (http_request req) |
| void | handle__search__get_top_display__POST (http_request req) |
| void | handle__search__get_som_display__POST (http_request req) |
| void | handle__search__get_som_relocation_display__POST (http_request req) |
| void | handle__search__keyword_autocomplete__GET (http_request req) |
| void | handle__search__reset__POST (http_request req) |
| void | handle__search__rescore__POST (http_request req) |
| void | handle__search__like_frame__POST (http_request req) |
| void | handle__search__bookmark_frame__POST (http_request req) |
| void | handle__search__context__POST (http_request req) |
| void | handle__search__context__GET (http_request req) |
| void | handle__log__scroll__GET (http_request req) |
| void | handle__log__text_query_change__GET (http_request req) |
| void | handle__log__canvas_query_change__GET (http_request req) |
| void | handle__eval_server__submit__POST (http_request req) |
| void | handle__eval_server__login__POST (http_request req) |
| void | handle__eval_server__logout__POST (http_request req) |
| void | push_endpoint (const std::string &path, std::function< void(NetworkApi *, http_request)> GET_handler=std::function< void(NetworkApi *, http_request)>{}, std::function< void(NetworkApi *, http_request)> POST_handler=std::function< void(NetworkApi *, http_request)>{}, std::function< void(NetworkApi *, http_request)> PUT_handler=std::function< void(NetworkApi *, http_request)>{}, std::function< void(NetworkApi *, http_request)> DEL_handler=std::function< void(NetworkApi *, http_request)>{}) |
Registers the provided handlers for the given path in the HTTP listener. More... | |
| RescoreMetadata | extract_rescore_metadata (web::json::value &body) |
Extracts RescoreMetadata from the body variable. More... | |
| std::vector< TextualQuery > | extract_textual_query (web::json::value &body) |
Extracts a vector of TextualQuery from the body variable. More... | |
| std::vector< RelocationQuery > | extract_relocation_query (web::json::value &body) |
Extracts a vector of RelocationQuery from the body variable. More... | |
| std::vector< CanvasQuery > | extract_canvas_query (web::json::value &body) |
Extracts a vector of CanvasQuery from the body variable. More... | |
| Filters | extract_filters (web::json::value &body) |
Extracts Filters from the body variable. More... | |
| std::lock_guard< std::mutex > | exclusive_lock () const |
Static Private Member Functions | |
| static void | add_CORS_headers (http_response &res) |
| Adds the CORS headers to the given HTTP response instance. More... | |
Private Attributes | |
| ApiConfig | _API_config |
| A private copy of config. More... | |
| Somhunter * | _p_core |
| A pointer to the core that this API exposes. More... | |
| std::string | _base_addr |
| Base HTTP API address. More... | |
| std::vector< http_listener > | _endpoints |
| Vector of used endpoints. More... | |
| std::mutex | _req_mtx |
| Lock used to synchronize some requests. More... | |
Class responsible for listening for HTTP requests and for handlling them using the core.
This is the universal API to the SOMHunter Core if you're not able to call the native C++ API of class Somhunter directly.
|
delete |
Only single ctor overload is acceptable.
Constructs the HTTP API instance for the given core and with the given API config.
|
staticprivate |
Adds the CORS headers to the given HTTP response instance.
|
inlineprivate |
|
private |
Extracts a vector of CanvasQuery from the body variable.
| body | JSON structure to be parsed. |
|
private |
|
private |
Extracts a vector of RelocationQuery from the body variable.
| body | JSON structure to be parsed. |
|
private |
Extracts RescoreMetadata from the body variable.
| body | JSON structure to be parsed. |

|
private |
Extracts a vector of TextualQuery from the body variable.
| body | JSON structure to be parsed. |
|
private |

|
private |

|
private |

|
private |

|
private |

|
private |

|
private |
|
private |

|
private |

|
private |

|
private |

|
private |

|
private |

|
private |

|
private |

|
private |

|
private |

|
private |

|
private |

|
private |

|
private |

| void NetworkApi::initialize | ( | ) |
Initializes the HTTP listeners on the required endpoints.

|
private |
Registers the provided handlers for the given path in the HTTP listener.
| path | String denoting the path of this endpoint (e.g. /api/do-something). |
| GET_handler | Handler to call in case of GET request. |
| POST_handler | Handler to call in case of POST request. |
| PUT_handler | Handler to call in case of PUT request. |
| DEL_handler | Handler to call in case of DEL request. |

| void NetworkApi::run | ( | ) |
The "main" function of the HTTP API - calls both initialize & terminate.

| void NetworkApi::terminate | ( | ) |
Safely terminates all the endpoint listeners.
|
private |
A private copy of config.
|
private |
Base HTTP API address.
|
private |
Vector of used endpoints.
|
private |
A pointer to the core that this API exposes.
|
mutableprivate |
Lock used to synchronize some requests.