Apply patch that is a bit similar to what xapantu did, but in a IMHO more modular way
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10263 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
c65762cd77
commit
c50e1a6c8b
@ -187,6 +187,8 @@ set( SRCS ${SRCS} src/main.cpp
|
||||
src/addons/addon.hpp
|
||||
src/addons/addons_manager.cpp
|
||||
src/addons/addons_manager.hpp
|
||||
src/addons/dummy_network_http.hpp
|
||||
src/addons/inetwork_http.hpp
|
||||
src/addons/network_http.cpp
|
||||
src/addons/network_http.hpp
|
||||
src/addons/news_manager.cpp
|
||||
|
@ -16,6 +16,8 @@ supertuxkart_SOURCES = \
|
||||
addons/addon.hpp \
|
||||
addons/addons_manager.cpp \
|
||||
addons/addons_manager.hpp \
|
||||
addons/dummy_network_http.hpp \
|
||||
addons/inetwork_http.hpp \
|
||||
addons/network_http.cpp \
|
||||
addons/network_http.hpp \
|
||||
addons/news_manager.cpp \
|
||||
|
@ -294,7 +294,8 @@ void AddonsManager::downloadIcons()
|
||||
Request *r = network_http->downloadFileAsynchron(url, save,
|
||||
/*priority*/1,
|
||||
/*manage_mem*/true);
|
||||
r->setAddonIconNotification(&addon);
|
||||
if (r != NULL)
|
||||
r->setAddonIconNotification(&addon);
|
||||
}
|
||||
else
|
||||
m_addons_list.getData()[i].setIconReady();
|
||||
|
48
src/addons/dummy_network_http.hpp
Normal file
48
src/addons/dummy_network_http.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2010 Lucas Baudin
|
||||
// 2011 Lucas Baudin, Joerg Henrichs
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_DUMMY_NETWORK_HTTP_HPP
|
||||
#define HEADER_DUMMY_NETWORK_HTTP_HPP
|
||||
|
||||
|
||||
#include "addons/request.hpp"
|
||||
|
||||
class XMLNode;
|
||||
|
||||
/**
|
||||
* \ingroup addonsgroup
|
||||
* Dummy implementation used when curl is not available
|
||||
*/
|
||||
class DummyNetworkHttp
|
||||
{
|
||||
|
||||
public:
|
||||
virtual ~DummyNetworkHttp() {}
|
||||
virtual void startNetworkThread() {}
|
||||
virtual void stopNetworkThread() {}
|
||||
virtual void insertReInit() {}
|
||||
virtual Request *downloadFileAsynchron(const std::string &url,
|
||||
const std::string &save = "",
|
||||
int priority = 1,
|
||||
bool manage_memory=true) { return NULL; }
|
||||
virtual void cancelAllDownloads() {}
|
||||
}; // NetworkHttp
|
||||
|
||||
|
||||
#endif
|
||||
|
59
src/addons/inetwork_http.hpp
Normal file
59
src/addons/inetwork_http.hpp
Normal file
@ -0,0 +1,59 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2010 Lucas Baudin
|
||||
// 2011 Lucas Baudin, Joerg Henrichs
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_INETWORK_HTTP_HPP
|
||||
#define HEADER_INETWORK_HTTP_HPP
|
||||
|
||||
|
||||
#include "addons/request.hpp"
|
||||
|
||||
class XMLNode;
|
||||
|
||||
/**
|
||||
* \ingroup addonsgroup
|
||||
* Abstract base interface for the network manager
|
||||
*/
|
||||
class INetworkHttp
|
||||
{
|
||||
public:
|
||||
/** If stk has permission to access the internet (for news
|
||||
* server etc).
|
||||
* IPERM_NOT_ASKED: The user needs to be asked if he wants to
|
||||
* grant permission
|
||||
* IPERM_ALLOWED: STK is allowed to access server.
|
||||
* IPERM_NOT_ALLOWED: STK must not access external servers. */
|
||||
enum InternetPermission {IPERM_NOT_ASKED =0,
|
||||
IPERM_ALLOWED =1,
|
||||
IPERM_NOT_ALLOWED=2 };
|
||||
|
||||
public:
|
||||
virtual ~INetworkHttp() {}
|
||||
virtual void startNetworkThread() = 0;
|
||||
virtual void stopNetworkThread() = 0;
|
||||
virtual void insertReInit() = 0;
|
||||
virtual Request *downloadFileAsynchron(const std::string &url,
|
||||
const std::string &save = "",
|
||||
int priority = 1,
|
||||
bool manage_memory=true) = 0;
|
||||
virtual void cancelAllDownloads() = 0;
|
||||
}; // NetworkHttp
|
||||
|
||||
extern INetworkHttp *network_http;
|
||||
|
||||
#endif
|
||||
|
@ -16,6 +16,8 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef NO_CURL
|
||||
|
||||
#include "addons/network_http.hpp"
|
||||
|
||||
#include <curl/curl.h>
|
||||
@ -48,7 +50,7 @@
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
NetworkHttp *network_http=NULL;
|
||||
INetworkHttp *network_http = NULL;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Create a thread that handles all network functions independent of the
|
||||
@ -631,17 +633,20 @@ int NetworkHttp::progressDownload(void *clientp,
|
||||
double upload_total, double upload_now)
|
||||
{
|
||||
Request *request = (Request *)clientp;
|
||||
|
||||
NetworkHttp* self = (NetworkHttp*)network_http;
|
||||
|
||||
// Check if we are asked to abort the download. If so, signal this
|
||||
// back to libcurl by returning a non-zero status.
|
||||
if(network_http->m_abort.getAtomic() || request->isCancelled() )
|
||||
if(self->m_abort.getAtomic() || request->isCancelled() )
|
||||
{
|
||||
if(UserConfigParams::logAddons())
|
||||
{
|
||||
if(network_http->m_abort.getAtomic())
|
||||
if(self->m_abort.getAtomic())
|
||||
{
|
||||
// Reset abort flag so that the next download will work
|
||||
// as expected.
|
||||
network_http->m_abort.setAtomic(false);
|
||||
self->m_abort.setAtomic(false);
|
||||
printf("[addons] Global abort of downloads.\n");
|
||||
}
|
||||
else
|
||||
@ -670,4 +675,5 @@ int NetworkHttp::progressDownload(void *clientp,
|
||||
return 0;
|
||||
} // progressDownload
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -19,6 +19,8 @@
|
||||
#ifndef HEADER_NETWORK_HTTP_HPP
|
||||
#define HEADER_NETWORK_HTTP_HPP
|
||||
|
||||
#ifndef NO_CURL
|
||||
|
||||
#include <queue>
|
||||
#include <pthread.h>
|
||||
#include <string>
|
||||
@ -29,6 +31,7 @@
|
||||
#endif
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "addons/inetwork_http.hpp"
|
||||
#include "addons/request.hpp"
|
||||
#include "utils/synchronised.hpp"
|
||||
|
||||
@ -37,7 +40,7 @@ class XMLNode;
|
||||
/**
|
||||
* \ingroup addonsgroup
|
||||
*/
|
||||
class NetworkHttp
|
||||
class NetworkHttp : public INetworkHttp
|
||||
{
|
||||
public:
|
||||
/** If stk has permission to access the internet (for news
|
||||
@ -82,7 +85,7 @@ private:
|
||||
CURLcode reInit();
|
||||
public:
|
||||
NetworkHttp();
|
||||
~NetworkHttp();
|
||||
virtual ~NetworkHttp();
|
||||
void startNetworkThread();
|
||||
void stopNetworkThread();
|
||||
void insertReInit();
|
||||
@ -93,7 +96,6 @@ public:
|
||||
void cancelAllDownloads();
|
||||
}; // NetworkHttp
|
||||
|
||||
extern NetworkHttp *network_http;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -1145,6 +1145,8 @@
|
||||
95A1184C0F77FC8800B18B3D /* input_device.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = input_device.hpp; path = ../../input/input_device.hpp; sourceTree = SOURCE_ROOT; };
|
||||
95A1187A0F78024E00B18B3D /* device_manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = device_manager.cpp; path = ../../input/device_manager.cpp; sourceTree = SOURCE_ROOT; };
|
||||
95A1187C0F78026D00B18B3D /* device_manager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = device_manager.hpp; path = ../../input/device_manager.hpp; sourceTree = SOURCE_ROOT; };
|
||||
95A5402D1481BD950086FE38 /* inetwork_http.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = inetwork_http.hpp; path = ../../addons/inetwork_http.hpp; sourceTree = SOURCE_ROOT; };
|
||||
95A540411481BEB60086FE38 /* dummy_network_http.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = dummy_network_http.hpp; path = ../../addons/dummy_network_http.hpp; sourceTree = SOURCE_ROOT; };
|
||||
95AAD97E12BAD36300B7B8A3 /* tutorial_screen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tutorial_screen.cpp; path = ../../states_screens/tutorial_screen.cpp; sourceTree = SOURCE_ROOT; };
|
||||
95AAD97F12BAD36300B7B8A3 /* tutorial_screen.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = tutorial_screen.hpp; path = ../../states_screens/tutorial_screen.hpp; sourceTree = SOURCE_ROOT; };
|
||||
95B5CD12102DE08F00EF2001 /* device_config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = device_config.hpp; path = ../../config/device_config.hpp; sourceTree = SOURCE_ROOT; };
|
||||
@ -1510,6 +1512,8 @@
|
||||
9538A55F12CD094200CE3220 /* addon.hpp */,
|
||||
9538E2B512C25D6800172896 /* addons_manager.cpp */,
|
||||
9538E2B612C25D6800172896 /* addons_manager.hpp */,
|
||||
95A540411481BEB60086FE38 /* dummy_network_http.hpp */,
|
||||
95A5402D1481BD950086FE38 /* inetwork_http.hpp */,
|
||||
9538E2B712C25D6800172896 /* network_http.cpp */,
|
||||
9538E2B812C25D6800172896 /* network_http.hpp */,
|
||||
9584B309137CAC12008565D7 /* news_manager.cpp */,
|
||||
|
@ -142,6 +142,7 @@
|
||||
|
||||
#include "main_loop.hpp"
|
||||
#include "addons/addons_manager.hpp"
|
||||
#include "addons/dummy_network_http.hpp"
|
||||
#include "addons/network_http.hpp"
|
||||
#include "addons/news_manager.hpp"
|
||||
#include "audio/music_manager.hpp"
|
||||
@ -1006,7 +1007,12 @@ void initRest()
|
||||
// separate thread running in network http.
|
||||
news_manager = new NewsManager();
|
||||
addons_manager = new AddonsManager();
|
||||
|
||||
#ifdef NO_CURL
|
||||
network_http = new DummyNetworkHttp();
|
||||
#else
|
||||
network_http = new NetworkHttp();
|
||||
#endif
|
||||
// Note that the network thread must be started after the assignment
|
||||
// to network_http (since the thread might use network_http, otherwise
|
||||
// a race condition can be introduced resulting in a crash).
|
||||
|
Loading…
Reference in New Issue
Block a user