Esempio n. 1
0
void Campfire::ListenWorker()
{
   void******* m_pRest = NULL;//This is a thread; so don't use m_pRest!

   std::string strAddress = GetStreamingURL(m_nRoomNum, m_bUseSSL);

   while( !m_bExit )
   {
      RestClientFactory factory;
      RestClient* pClient = factory.SetUsernamePassword(m_strAuthCode, "x").SetVerbosity(false).CreateRestClient();
      pClient->SetCallback(Campfire::listen_callback);
      pClient->SetUserData((void*)this);
      RestClient::response r = pClient->get(strAddress);
      cout << "Finished Listening!!!" << r.code << endl;
      SAFE_DELETE(pClient);//Done with this so no need to revert the callback/userdata

      if( !m_bExit )
      {
#ifdef _WIN32
         Sleep(200);
#else
         usleep(200*1000);
#endif
      }
   }
}
const char* SwitchScheduler::getAstronomyDataResponse()
{
    Uri apiUri = Uri::Parse(configuration->astronomyApiUrl);

    RestClient client = RestClient(apiUri.Host.c_str());
    String response = "";

    int statusCode = client.get(apiUri.Path.c_str(), &response);

    if (statusCode == 200)
    {
        DEBUG_PRINT("Successfully retrieved JSON response\n");
        return response.c_str();
    }
    else
    {
        DEBUG_PRINT("Failed to retrieve sunset data with status: ");
        DEBUG_PRINT(statusCode);
        DEBUG_PRINT("\n");
        return "";
    }
}