SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Online::ProfileManager Class Reference

Class that manages all online profiles. More...

#include <profile_manager.hpp>

Public Member Functions

void addToCache (OnlineProfile *profile)
 Adds profile to the cache.
 
OnlineProfileaddPersistent (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.
 
OnlineProfilegetProfileByID (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.
 
OnlineProfilegetVisitingProfile ()
 

Static Public Member Functions

static void create ()
 Create the singleton instance.
 
static ProfileManagerget ()
 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.
 
OnlineProfilem_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 ProfileManagerm_profile_manager = NULL
 Singleton pointer.
 

Detailed Description

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

Member Function Documentation

◆ addDirectToCache()

void Online::ProfileManager::addDirectToCache ( OnlineProfile profile)
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.

◆ addPersistent()

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.)

Parameters
profileThe profile to make persistent.

◆ addToCache()

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.

◆ deleteFromPersistent()

void Online::ProfileManager::deleteFromPersistent ( const uint32_t  id)

Removes and deletes an entry from the persistent map.

Parameters
idthe id of the profile to be removed.

◆ get()

static ProfileManager * Online::ProfileManager::get ( )
inlinestatic

Returns the singleton.

Precondition
create has been called to create the singleton.

◆ getProfileByID()

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.

Parameters
idThe id of the profile to find.

◆ getVisitingProfile()

OnlineProfile * Online::ProfileManager::getVisitingProfile ( )
inline
Returns
the instance of the profile that's currently being visited

◆ guaranteeCacheSize()

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.

Parameters
min_numMinimum number of entries the chache should be able to store.

◆ inPersistent()

bool Online::ProfileManager::inPersistent ( const uint32_t  id)

True if the profile with the given id is persistent.

Parameters
idThe id of the profile to test.

◆ isInCache()

bool Online::ProfileManager::isInCache ( const uint32_t  id)

Checks if a profile is in cache.

If so, it updates its usage bit.

Parameters
idIdentifier for the profile to check.

◆ moveToCache()

void Online::ProfileManager::moveToCache ( const uint32_t  id)

Removes a currently persistent profile to the cache (where it can be deleted later).

Parameters
idThe the id of the profile to be moved.

◆ setVisiting()

void Online::ProfileManager::setVisiting ( const uint32_t  id)
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).

◆ updateAllFriendFlags()

void Online::ProfileManager::updateAllFriendFlags ( const OnlineProfile profile)
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.

◆ updateCacheBits()

void Online::ProfileManager::updateCacheBits ( OnlineProfile profile)
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.

◆ updateFriendFlagsInCache()

void Online::ProfileManager::updateFriendFlagsInCache ( const ProfilesMap cache,
uint32_t  profile_id 
)
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.

Member Data Documentation

◆ m_currently_visiting

OnlineProfile* Online::ProfileManager::m_currently_visiting
private

A temporary profile that is currently being 'visited', e.g.

its data is shown in a gui.

◆ m_max_cache_size

unsigned int Online::ProfileManager::m_max_cache_size
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).

◆ m_profiles_cache

ProfilesMap Online::ProfileManager::m_profiles_cache
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.

◆ m_profiles_persistent

ProfilesMap Online::ProfileManager::m_profiles_persistent
private

A map of profiles that is persistent.

(i.e. no automatic removing happens) Normally used for the current user's profile and friends.


The documentation for this class was generated from the following files: