NASFAQ/connections/parser/parser.h

68 lines
1.7 KiB
C
Raw Normal View History

#ifndef _PARSER_H_
#define _PARSER_H_
2022-02-18 09:24:24 +00:00
#include <iostream>
#include <string>
#include <stdlib.h>
#include <nlohmann/json.hpp>
2022-05-07 14:49:43 +00:00
#include "../sql/db_handle.h"
2022-02-18 09:24:24 +00:00
#include "../common/common.h"
2022-12-10 14:35:16 +00:00
#include "../common/formatting.h"
2022-05-07 14:49:43 +00:00
#include "../ws/ssl_ws.h"
2022-02-18 09:24:24 +00:00
2022-12-10 14:35:16 +00:00
#include "./parser_aux.h"
//TODO: Remove ws here and use a safequeue
2022-05-07 14:49:43 +00:00
2022-12-10 14:35:16 +00:00
namespace parser {
2022-05-07 14:49:43 +00:00
2022-12-10 14:35:16 +00:00
/*******************************************************************************
Parser object
*******************************************************************************/
2022-05-07 14:49:43 +00:00
class parser {
public:
parser(ws::connection_metadata::ptr, pqxx::connection*);
~parser(void);
void process_queue();
void process_queue_start();
void process_queue_stop();
void process_queue_thread_join();
private:
ws::connection_metadata::ptr m_metadata;
bool m_process_queue_state;
pthread_t m_process_queue_thread;
pqxx::connection* m_connection;
static void* process_queue_helper(void*);
};
2022-12-10 14:35:16 +00:00
/*******************************************************************************
Message parsing
*******************************************************************************/
template <WS_MSG E>
ws_msg_parsed<E> single(std::string);
template <WS_MSG E>
ws_msg_parsed<E> single_j(nlohmann::json);
template <>
ws_msg_parsed<WS_EVENT_COIN_PRICE> single<WS_EVENT_COIN_PRICE>(std::string);
template<>
ws_msg_parsed<WS_EVENT_TRANSACTION> single<WS_EVENT_TRANSACTION>(std::string);
template <>
ws_msg_parsed<WS_EVENT_TRANSACTION> single_j<WS_EVENT_TRANSACTION>(nlohmann::json );
template<>
ws_msg_parsed<WS_EVENT_HISTORY> single<WS_EVENT_HISTORY>(std::string);
template <>
ws_msg_parsed<WS_EVENT_MF_PORTFOLIO> single<WS_EVENT_MF_PORTFOLIO>(std::string);
2022-12-10 14:35:16 +00:00
} // parser
2022-02-18 09:24:24 +00:00
#endif