/* * Send a message and wait for response */ htsmsg_t *CHTSPConnection::SendAndWait0 ( const char *method, htsmsg_t *msg, int iResponseTimeout ) { if (iResponseTimeout == -1) iResponseTimeout = g_iResponseTimeout; uint32_t seq; /* Add Sequence number */ CHTSPResponse resp; seq = ++m_seq; htsmsg_add_u32(msg, "seq", seq); m_messages[seq] = &resp; /* Send Message (bypass TX check) */ if (!SendMessage0(method, msg)) { m_messages.erase(seq); tvherror("failed to transmit"); return NULL; } /* Wait for response */ msg = resp.Get(m_mutex, iResponseTimeout * 1000); m_messages.erase(seq); if (!msg) { tvherror("response not received"); Disconnect(); return NULL; } return msg; }
/* * Send a message and wait for response */ htsmsg_t *CHTSPConnection::SendAndWait0 ( const char *method, htsmsg_t *msg, int iResponseTimeout ) { if (iResponseTimeout == -1) iResponseTimeout = Settings::GetInstance().GetResponseTimeout(); uint32_t seq; /* Add Sequence number */ CHTSPResponse resp; seq = ++m_seq; htsmsg_add_u32(msg, "seq", seq); m_messages[seq] = &resp; /* Send Message (bypass TX check) */ if (!SendMessage0(method, msg)) { m_messages.erase(seq); Logger::Log(LogLevel::ERROR, "failed to transmit"); return NULL; } /* Wait for response */ msg = resp.Get(m_mutex, iResponseTimeout); m_messages.erase(seq); if (!msg) { //XBMC->QueueNotification(QUEUE_ERROR, "Command %s failed: No response received", method); Logger::Log(LogLevel::ERROR, "Command %s failed: No response received", method); if (!m_suspended) Disconnect(); return NULL; } /* Check result for errors and announce. */ uint32_t noaccess; if (!htsmsg_get_u32(msg, "noaccess", &noaccess) && noaccess) { // access denied //XBMC->QueueNotification(QUEUE_ERROR, "Command %s failed: Access denied", method); Logger::Log(LogLevel::ERROR, "Command %s failed: Access denied", method); htsmsg_destroy(msg); return NULL; } else { const char* strError; if((strError = htsmsg_get_str(msg, "error")) != NULL) { //XBMC->QueueNotification(QUEUE_ERROR, "Command %s failed: %s", method, strError); Logger::Log(LogLevel::ERROR, "Command %s failed: %s", method, strError); htsmsg_destroy(msg); return NULL; } } return msg; }