Fix $1569 (allow adjusting of polling interval from server via news.xml

or polling response data).
This commit is contained in:
hiker
2014-09-25 17:04:36 +10:00
parent df8c2cb2c3
commit 48d99086f1
4 changed files with 72 additions and 28 deletions

View File

@@ -235,6 +235,16 @@ void NewsManager::checkRedirect(const XMLNode *xml)
UserConfigParams::m_server_hw_report = hw_report_server;
}
float polling;
if(xml->get("menu-polling-interval", &polling))
{
RequestManager::get()->setMenuPollingInterval(polling);
}
if(xml->get("game-polling-interval", &polling))
{
RequestManager::get()->setGamePollingInterval(polling);
}
} // checkRedirect
// ----------------------------------------------------------------------------

View File

@@ -324,6 +324,11 @@ namespace Online
if (!PlayerManager::getCurrentPlayer()->isLoggedIn())
return;
float f;
if(getXMLData()->get("menu-polling-interval", &f))
RequestManager::get()->setMenuPollingInterval(f);
if(getXMLData()->get("game-polling-interval", &f))
RequestManager::get()->setGamePollingInterval(f);
if (PlayerManager::getCurrentPlayer()->getProfile()->hasFetchedFriends())
{

View File

@@ -40,30 +40,17 @@ using namespace Online;
namespace Online
{
#define MENU_POLLING_INTERVAL 10.0f
#define GAME_POLLING_INTERVAL 15.0f
static RequestManager * http_singleton = NULL;
// ------------------------------------------------------------------------
RequestManager* RequestManager::get()
{
if (http_singleton == NULL)
{
http_singleton = new RequestManager();
}
return http_singleton;
} // get
RequestManager * RequestManager::m_request_manager = NULL;
// ------------------------------------------------------------------------
/** Deletes the http manager.
*/
void RequestManager::deallocate()
{
if (http_singleton != NULL)
if (m_request_manager!= NULL)
{
delete http_singleton;
http_singleton = NULL;
delete m_request_manager;
m_request_manager = NULL;
}
} // deallocate
@@ -72,17 +59,20 @@ namespace Online
*/
bool RequestManager::isRunning()
{
return http_singleton != NULL;
return m_request_manager != NULL;
} // isRunning
// ------------------------------------------------------------------------
/** Constructor. It only initialised values, it does not start the actual
* thread.
*/
RequestManager::RequestManager()
{
m_menu_polling_interval = 60; // Default polling: every 60 seconds.
m_game_polling_interval = 60; // same for game polling
m_time_since_poll = m_menu_polling_interval;
curl_global_init(CURL_GLOBAL_DEFAULT);
pthread_cond_init(&m_cond_request, NULL);
m_abort.setAtomic(false);
m_time_since_poll = MENU_POLLING_INTERVAL * 0.9;
} // RequestManager
// ------------------------------------------------------------------------
@@ -305,9 +295,9 @@ namespace Online
return;
m_time_since_poll += dt;
float interval = GAME_POLLING_INTERVAL;
float interval = m_game_polling_interval;
if (StateManager::get()->getGameState() == GUIEngine::MENU)
interval = MENU_POLLING_INTERVAL;
interval = m_menu_polling_interval;
if (m_time_since_poll > interval)
{

View File

@@ -90,7 +90,7 @@ namespace Online
IPERM_ALLOWED = 1,
IPERM_NOT_ALLOWED = 2
};
protected:
private:
/** Time passed since the last poll request. */
float m_time_since_poll;
@@ -103,10 +103,17 @@ namespace Online
/** Signal an abort in case that a download is still happening. */
Synchronised<bool> m_abort;
/** The polling interval while a game is running. */
float m_game_polling_interval;
/** The polling interval while the menu is shown. */
float m_menu_polling_interval;
/** Thread id of the thread running in this object. */
Synchronised<pthread_t *> m_thread_id;
/** The list of pointers to all requests that still need to be handled. */
/** The list of pointers to all requests that still need to be
* handled. */
Synchronised< std::priority_queue <
Online::Request*,
std::vector<Online::Request*>,
@@ -114,7 +121,9 @@ namespace Online
>
> m_request_queue;
/** The list of pointers to all requests that are already executed by the networking thread, but still need to be processed by the main thread. */
/** The list of pointers to all requests that are already executed
* by the networking thread, but still need to be processed by the
* main thread. */
Synchronised< std::queue<Online::Request*> > m_result_queue;
void addResult(Online::Request *request);
@@ -124,12 +133,25 @@ namespace Online
RequestManager(); //const std::string &url
~RequestManager();
static RequestManager * m_request_manager;
public:
static const int HTTP_MAX_PRIORITY = 9999;
// singleton
static RequestManager* get();
// ----------------------------------------------------------------
/** Singleton access function. Creates the RequestManager if
* necessary. */
static RequestManager* get()
{
if (m_request_manager == NULL)
{
m_request_manager = new RequestManager();
}
return m_request_manager;
} // get
// ----------------------------------------------------------------
static void deallocate();
static bool isRunning();
@@ -140,6 +162,23 @@ namespace Online
bool getAbort(){ return m_abort.getAtomic(); }
void update(float dt);
// ----------------------------------------------------------------
/** Sets the interval with which poll requests are send to the
* server. This can happen from the news manager (i.e. info
* contained in the news.xml file), or a poll request. */
void setMenuPollingInterval(float polling_interval)
{
m_menu_polling_interval = polling_interval;
} // setPollingInterval
// ----------------------------------------------------------------
/** Sets the interval with which poll requests are send to the
* server. This can happen from the news manager (i.e. info
* contained in the news.xml file), or a poll request. */
void setGamePollingInterval(float polling_interval)
{
m_game_polling_interval = polling_interval;
} // setPollingInterval
}; //class RequestManager
} // namespace Online
#endif // request_manager_HPP