#include "proxy.h" #include "sstream" #define CPAPI_PROXY_CALL_HELPER(callfrom, func, funcArgs, throwArgs) do { lastCpError = func funcArgs; if (lastCpError != OK) { \ std::stringstream err; err << callfrom ": CP Api error " #func "("; err << throwArgs; err << "): " << lastCpError;\ throw std::runtime_error(err.str());\ } } while (0) api_driver::proxy::CpProxy::CpProxy() = default; api_driver::proxy::CpProxy::CpProxy(TSID s): sid(s) {} void api_driver::proxy::CpProxy::connect() { unsigned int access{}; CPAPI_PROXY_CALL_HELPER("CpProxy::connect", CP_Login, ("admin", "pass", &sid, &access), R"("admin", "pass", &sid, &access)"); } void api_driver::proxy::CpProxy::disconnect() { if (sid != 0) { lastCpError = CP_Logout(sid); sid = 0; } } std::string api_driver::proxy::CpProxy::getDmaDebug(const std::string &arg) { std::string result; CPAPI_PROXY_CALL_HELPER("CpProxy::getDmaDebug", CP_GetDmaDebug, (sid, arg.c_str(), &result), arg); return result; } void api_driver::proxy::CpProxy::setDmaDebug(const std::string &arg, const std::string &value) { CPAPI_PROXY_CALL_HELPER("CpProxy::setDmaDebug", CP_SetDmaDebug, (sid, arg.c_str(), value), arg << ", \"" << value << "\""); } std::string api_driver::proxy::CpProxy::getNetwork(const std::string ¶m) { std::string result; CPAPI_PROXY_CALL_HELPER("CpProxy::getNetwork", CP_GetNetwork, (sid, param.c_str(), &result), param); return result; } void api_driver::proxy::CpProxy::setNetwork(const std::string ¶m, const std::string &value) { CPAPI_PROXY_CALL_HELPER("CpProxy::setNetwork", CP_SetNetwork, (sid, param.c_str(), value.c_str()), param << ", \"" << value << "\""); } void api_driver::proxy::CpProxy::getModState(modulator_state &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::getModState", CP_GetModulatorState, (sid, dest), ""); } void api_driver::proxy::CpProxy::getModSettings(modulator_settings &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::getModSettings", CP_GetModulatorSettings, (sid, dest), ""); } void api_driver::proxy::CpProxy::setModSettings(modulator_settings &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::setModSettings", CP_SetModulatorSettings, (sid, dest), "struct {...}"); } void api_driver::proxy::CpProxy::getDemodState(demodulator_state &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::getDemodState", CP_GetDemodulatorState, (sid, dest), ""); } void api_driver::proxy::CpProxy::getDemodSettings(demodulator_settings &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::getDemodSettings", CP_GetDemodulatorSettings, (sid, dest), ""); } void api_driver::proxy::CpProxy::setDemodSettings(demodulator_settings &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::setDemodSettings", CP_SetDemodulatorSettings, (sid, dest), "struct {...}"); } #ifdef API_STRUCT_ACM_ENABLE void api_driver::proxy::CpProxy::getAcmSettings(ACM_parameters_serv_ &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::getAcmSettings", CP_GetAcmParams, (sid, &dest), ""); } void api_driver::proxy::CpProxy::setAcmSettings(ACM_parameters_serv_ &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::setAcmSettings", CP_GetAcmParams, (sid, &dest), "struct {...}"); } #endif void api_driver::proxy::CpProxy::getDeviceState(device_state &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::getDeviceState", CP_GetDeviceState, (sid, dest), ""); } #ifdef API_OBJECT_QOS_SETTINGS_ENABLE std::tuple api_driver::proxy::CpProxy::getQosSettings() { std::string rules; bool en; CPAPI_PROXY_CALL_HELPER("CpProxy::getQosSettings", CP_GetQoSSettings, (sid, rules, en), ""); return {rules, en}; } void api_driver::proxy::CpProxy::setQosSettings(const std::string &rules, bool enable) { CPAPI_PROXY_CALL_HELPER("CpProxy::setQosSettings", CP_SetQoSSettings, (sid, rules, enable), "`" << rules << "`, " << (enable ? "true" : "false")); } #endif #ifdef API_OBJECT_DPDI_SETTINGS_ENABLE void api_driver::proxy::CpProxy::getDpdiSettings(DPDI_parmeters &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::getDpdiSettings", CP_GetDpdiParams, (sid, &dest), ""); } void api_driver::proxy::CpProxy::setDpdiSettings(DPDI_parmeters &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::setDpdiSettings", CP_SetDpdiParams, (sid, dest), "struct {...}"); } #endif #ifdef API_OBJECT_BUCLNB_SETTINGS_ENABLE void api_driver::proxy::CpProxy::getBuclnbSettings(buc_lnb_settings &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::getBuclnbSettings", CP_GetBUC_LNB_settings, (sid, dest), ""); } void api_driver::proxy::CpProxy::setBuclnbSettings(buc_lnb_settings &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::setBuclnbSettings", CP_SetBUC_LNB_settings, (sid, dest), "struct {...}"); } #endif #ifdef MODEM_IS_SCPC void api_driver::proxy::CpProxy::getCincState(CinC_state &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::getCincState", CP_GetCinCState, (sid, dest), ""); } #endif #ifdef API_OBJECT_DEBUG_METRICS_ENABLE void api_driver::proxy::CpProxy::getDebugMetrics(debug_metrics &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::getDebugMetrics", CP_GetDebugMetrics, (sid, dest), ""); } #endif #ifdef MODEM_IS_TDMA void api_driver::proxy::CpProxy::getUpdateStatus(progress_msg &dest) { CPAPI_PROXY_CALL_HELPER("CpProxy::getUpdateStatus", CP_GetUpdateStatus, (sid, dest), ""); } #endif api_driver::proxy::CpProxy::~CpProxy() { disconnect(); }