/*
        Copyright (c) 2025, MOEX. All rights reserved.
        
        Plaza-2 Client Gate API Usage Sample.
        
        All the software and documentation included in this and any
        other MOEX CGate Release is copyrighted by MOEX.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted only by the terms of a valid
        software license agreement with MOEX.
        
        THIS SOFTWARE IS PROVIDED "AS IS" AND MOEX DISCLAIMS ALL WARRANTIES
        EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF
        NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
        PURPOSE.  MOEX DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE
        UNINTERRUPTED OR ERROR-FREE.  MOEX SHALL NOT, UNDER ANY CIRCUMSTANCES, BE
        LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR
        INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE
        TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF MOEX HAS BEEN APPRISED OF
        THE LIKELIHOOD OF SUCH DAMAGES.
*/

#pragma once

#ifndef _WIN32
#include "conio.h"
#else
#include <conio.h>
#include <memory>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>
#include <memory>
#include <iostream>
#include <unordered_map>
#include <string>
#include <list>

#ifdef _WIN32
#include <windows.h>
#elif __unix__
#include <signal.h>
#endif

#define CG_SHORT_NAMES
#include <cgate.h>

// вспомогательный макрос для вызова функций CGate
// и выхода в случае ошибки
//
// helper macro to call CGate function
// and exit if there was error
#define CHECK_FAIL(f) \
    { \
        uint32_t res = f; \
        if (res != CG_ERR_OK) \
        { \
            log_info("Client gate error: %x", res); \
            exit(1); \
        } \
    } 

#define EXIT_WITH_ERROR(msg) \
    { \
        log_info("Client gate error: %s", msg); \
        throw std::runtime_error(msg); \
    } \

// вспомогательный макрос для вызова функций CGate
// и вывода предупреждения в случае ошибки
//
// helper macro to call CGate function
// and print warning if there was error
#define WARN_FAIL(f) \
    { \
        uint32_t res = f; \
        if (res != CG_ERR_OK) \
            log_info("Error: %x", res); \
    } 

