bool CHarmonyHub::UpdateCurrentActivity() { if(SubmitCommand(m_commandcsocket, m_szAuthorizationToken, GET_CURRENT_ACTIVITY_COMMAND, "", "") == 1) { //_log.Log(LOG_ERROR,"Harmony Hub: Get current activity failed"); return false; } //check if changed if(!strcmp(m_szCurActivityID.c_str(), m_szResultString.c_str())==0) { if(!m_szCurActivityID.empty()) { //need to set the old activity to off CheckSetActivity(m_szCurActivityID,false ); } CheckSetActivity(m_szResultString,true); m_szCurActivityID = m_szResultString; } return true; }
bool CHarmonyHub::UpdateCurrentActivity() { if(!SubmitCommand(GET_CURRENT_ACTIVITY_COMMAND_RAW, "", "")) { //_log.Log(LOG_ERROR,"Harmony Hub: Get current activity failed"); return false; } //check if changed if(m_szCurActivityID!=m_szResultString) { if(!m_szCurActivityID.empty()) { //need to set the old activity to off CheckSetActivity(m_szCurActivityID,false ); } CheckSetActivity(m_szResultString,true); m_szCurActivityID = m_szResultString; } return true; }
bool CHarmonyHub::CheckIfChanging(const std::string& strData) { //activityStatus // 0 = Hub is off // 1 = Activity is starting // 2 = Activity is started // 3 = Hub is turning off bool bIsChanging = m_bIsChangingActivity; std::string LastActivity = m_szCurActivityID; std::string szData = strData; int pos; while (!szData.empty()) { size_t apos = szData.find("</message>"); if (apos == std::string::npos) break; std::string szResponse = szData.substr(0, apos); szData = szData.substr(apos + 10); if (szResponse.find("getCurrentActivity") != std::string::npos) continue; //dont want you if (szResponse.find("startActivityFinished") != std::string::npos) { bIsChanging = false; pos = szResponse.find("<![CDATA["); if (pos == std::string::npos) continue; szResponse = szResponse.substr(pos + 9); pos = szResponse.find("]]>"); if (pos == std::string::npos) continue; szResponse = szResponse.substr(0, pos); pos = szResponse.find("activityId="); if (pos == std::string::npos) continue; szResponse = szResponse.substr(pos + 11); pos = szResponse.find(":"); if (pos == std::string::npos) continue; szResponse = szResponse.substr(0, pos); LastActivity = szResponse; continue; } pos = szResponse.find("<![CDATA["); if (pos == std::string::npos) continue; szResponse = szResponse.substr(pos + 9); pos = szResponse.find("]]>"); if (pos == std::string::npos) continue; szResponse = szResponse.substr(0, pos); Json::Reader jReader; Json::Value root; bool ret = jReader.parse(szResponse, root); if (!ret) continue; if (root["activityStatus"].empty()) continue; int activityStatus = root["activityStatus"].asInt(); if (!root["hubSwVersion"].empty()) { std::string hubSwVersion = root["hubSwVersion"].asString(); if (hubSwVersion != m_hubSwVersion) { m_hubSwVersion = hubSwVersion; _log.Log(LOG_STATUS, "Harmony Hub: Software version: %s", m_hubSwVersion.c_str()); } } bIsChanging = (activityStatus == 1); if (activityStatus == 2) { if (!root["activityId"].empty()) { LastActivity = root["activityId"].asString(); } } else if (activityStatus == 3) { //Power Off LastActivity = "-1"; } } if (bIsChanging != m_bIsChangingActivity) { m_bIsChangingActivity = bIsChanging; if (m_bIsChangingActivity) _log.Log(LOG_STATUS, "Harmony Hub: Changing activity"); else _log.Log(LOG_STATUS, "Harmony Hub: Finished changing activity"); } if (m_szCurActivityID != LastActivity) { if (!m_szCurActivityID.empty()) { //need to set the old activity to off CheckSetActivity(m_szCurActivityID, false); } CheckSetActivity(LastActivity, true); m_szCurActivityID = LastActivity; } return true; }