SuperTuxKart
|
Class that manages all online profiles. More...
#include <profile_manager.hpp>
Public Member Functions | |
void | addToCache (OnlineProfile *profile) |
Adds profile to the cache. | |
OnlineProfile * | addPersistent (OnlineProfile *profile) |
Adds a profile to the persistent map. | |
void | deleteFromPersistent (const uint32_t id) |
Removes and deletes an entry from the persistent map. | |
void | clearPersistent () |
Deletes all persistent profiles. | |
void | moveToCache (const uint32_t id) |
Removes a currently persistent profile to the cache (where it can be deleted later). | |
int | guaranteeCacheSize (unsigned int max_num) |
Makes sure that the cache can store at least max_num entries. | |
bool | isInCache (const uint32_t id) |
Checks if a profile is in cache. | |
bool | inPersistent (const uint32_t id) |
True if the profile with the given id is persistent. | |
OnlineProfile * | getProfileByID (const uint32_t id) |
Search for a given profile in the set of persistent and cached entries. | |
void | setVisiting (const uint32_t id) |
Marks a given profile to be the currently visited one. | |
OnlineProfile * | getVisitingProfile () |
Static Public Member Functions | |
static void | create () |
Create the singleton instance. | |
static ProfileManager * | get () |
Returns the singleton. | |
static void | destroy () |
Destroys the singleton. | |
Private Types | |
typedef std::map< uint32_t, OnlineProfile * > | ProfilesMap |
The mapping of ids to profile. | |
Private Member Functions | |
ProfileManager () | |
Private constructor, used by static create() function. | |
~ProfileManager () | |
Destructor, which frees the persistent and cached data. | |
void | updateCacheBits (OnlineProfile *profile) |
This function updates the cache bits of all cached entries. | |
void | addDirectToCache (OnlineProfile *profile) |
Initialisation before the object is displayed. | |
void | updateFriendFlagsInCache (const ProfilesMap &cache, uint32_t profile_id) |
This function is called when the specified profile id is removed from cache. | |
void | updateAllFriendFlags (const OnlineProfile *profile) |
This function is called when the specified profile is removed from cache. | |
Private Attributes | |
ProfilesMap | m_profiles_persistent |
A map of profiles that is persistent. | |
ProfilesMap | m_profiles_cache |
Any profiles that don't go into the persistent map, go here. | |
OnlineProfile * | m_currently_visiting |
A temporary profile that is currently being 'visited', e.g. | |
unsigned int | m_max_cache_size |
The max size of the m_profiles cache. | |
Static Private Attributes | |
static ProfileManager * | m_profile_manager = NULL |
Singleton pointer. | |
Class that manages all online profiles.
Profiles are used for storing online information from local users, but also to store information about remote users (e.g. if you want to see the achievements of another user a Profile for this user is created, the server is then queried for the information and the result is stored in that profile). The profile manager has two
|
private |
Initialisation before the object is displayed.
If necessary this function will pause the race if it is running (i.e. world exists). While only some of the screen can be shown during the race (via the in-game menu you can get the options screen and the help screens only). This is used by the RaceResultGUI to leave the race running (for the end animation) while the results are being shown.
OnlineProfile * Online::ProfileManager::addPersistent | ( | OnlineProfile * | profile | ) |
Adds a profile to the persistent map.
If a profile with the same id is already in there, the profiles are "merged" with the goal to save as much information (i.e. one profile instance could have already fetched the friends, while the other could have fetched the achievements.)
profile | The profile to make persistent. |
void Online::ProfileManager::addToCache | ( | OnlineProfile * | profile | ) |
Adds profile to the cache.
If the profile is already persistent, then it merges any new information from this profile to the persistent one. If the entry is already in the cache, the cached entry will be updated with any new information from the given profile. Otherwise, the profile is just added to the cache.
void Online::ProfileManager::deleteFromPersistent | ( | const uint32_t | id | ) |
Removes and deletes an entry from the persistent map.
id | the id of the profile to be removed. |
|
inlinestatic |
Returns the singleton.
OnlineProfile * Online::ProfileManager::getProfileByID | ( | const uint32_t | id | ) |
Search for a given profile in the set of persistent and cached entries.
If the profile does not exist, a NULL is returned. FIXME: This should be improved to download the profile is necessary.
id | The id of the profile to find. |
|
inline |
int Online::ProfileManager::guaranteeCacheSize | ( | unsigned int | min_num | ) |
Makes sure that the cache can store at least max_num entries.
This is used by the online search screen to make sure all results found can be cached at the same time.
min_num | Minimum number of entries the chache should be able to store. |
bool Online::ProfileManager::inPersistent | ( | const uint32_t | id | ) |
True if the profile with the given id is persistent.
id | The id of the profile to test. |
bool Online::ProfileManager::isInCache | ( | const uint32_t | id | ) |
Checks if a profile is in cache.
If so, it updates its usage bit.
id | Identifier for the profile to check. |
void Online::ProfileManager::moveToCache | ( | const uint32_t | id | ) |
Removes a currently persistent profile to the cache (where it can be deleted later).
id | The the id of the profile to be moved. |
|
inline |
Marks a given profile to be the currently visited one.
This is used to mark the profiles that ave its data display (e.g. to see achievements either of a local or a remote player).
|
private |
This function is called when the specified profile is removed from cache.
It searches through all caches for profiles X, that have the given profile as friend, and then reset the 'friends fetched' flag in profile X. Otherwise if a profile is pushed out of the cache, all friends of this profile in cache will have an incomplete list of friends.
|
private |
This function updates the cache bits of all cached entries.
It will set the cache bit of the given profile. Then, if the cachen is full it will check if there are any entries that don't have the cache bit set (i.e. entries that can be discarded because they were not used). If no such entry is found, all usage flags will be reset, and only the one for the given entry will remain set. This results with high probability that most often used entries will remain in the cache, without adding much overhead.
|
private |
This function is called when the specified profile id is removed from cache.
It will search all currently cached profiles that have the 'friends fetched' flag set, and reset that flag if the profile id is one of their friends. This fixes the problem that friend lists can get shortened if some of their friends are being pushed out of cache.
|
private |
A temporary profile that is currently being 'visited', e.g.
its data is shown in a gui.
|
private |
The max size of the m_profiles cache.
Its default size can be inrceased when necessary (e.g. when too many search results are loaded, to make sure they can be all stored).
|
private |
Any profiles that don't go into the persistent map, go here.
This uses a pseudo-LRU algorithm with age bits to remove entries when the max size is reached.
|
private |
A map of profiles that is persistent.
(i.e. no automatic removing happens) Normally used for the current user's profile and friends.