SuperTuxKart
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Online::OnlineProfile Class Reference

Class that represents an online profile. More...

#include <online_profile.hpp>

Classes

class  RelationInfo
 

Public Types

enum  ConstructorType { C_DEFAULT = 1, C_RELATION_INFO }
 
typedef std::vector< uint32_t > IDList
 

Public Member Functions

 OnlineProfile (const uint32_t &userid, const irr::core::stringw &username, bool is_current_user=false)
 Constructor for a new profile. More...
 
 OnlineProfile (const XMLNode *xml, ConstructorType type=C_DEFAULT)
 Creates a new profile from an XML Node. More...
 
void fetchFriends ()
 Triggers an asynchronous request to download the friends for this user. More...
 
const IDList & getFriends ()
 Returns the list of all friend ids.
 
void fetchAchievements ()
 Triggers an asynchronous request to get the achievements for this user from the server. More...
 
void removeFriend (const uint32_t id)
 Removed a friend with a given id. More...
 
void addFriend (const uint32_t id)
 Adds a friend to the friend list. More...
 
void deleteRelationalInfo ()
 Deletes the relational info for this profile.
 
const IDList & getAchievements ()
 Returns the list of all achievement ids.
 
void merge (OnlineProfile *profile)
 Merges the information from a given profile with this profile. More...
 
std::map< uint32_t, irr::core::stringw > & getFriendServerMap ()
 
bool hasFetchedAchievements () const
 Returns true if the achievements for this profile have been fetched. More...
 
void unsetHasFetchedFriends ()
 Unsets the flag that all friends of this profile are in cache. More...
 
bool hasFetchedFriends () const
 Returns true if the friend list for this profile has been fetched. More...
 
bool finishedFetchingFriends () const
 True if the profile has fetched friends. More...
 
bool finishedFetchingAchievements () const
 True if the profile has fetched friends. More...
 
bool isCurrentUser () const
 Returns true if this item is the current user. More...
 
bool isFriend () const
 
void setFriend ()
 
RelationInfogetRelationInfo ()
 
void setRelationInfo (RelationInfo *r)
 
void setCacheBit (bool cache_bit)
 Sets the cache bit of this profile. More...
 
bool getCacheBit () const
 Returns the cache bit for this profile. More...
 
uint32_t getID () const
 Returns the online id of this profile. More...
 
const irr::core::stringw & getUserName () const
 Returns the user name of this profile. More...
 

Private Types

enum  State { S_FETCHING_ACHIEVEMENTS = 0x01, S_FETCHING_FRIENDS = 0x02 }
 The profile can either be fetching data, or be ready. More...
 

Private Member Functions

void storeFriends (const XMLNode *input)
 Stores the friends from an XML node into this profile. More...
 
void storeAchievements (const XMLNode *input)
 Stores the achievement ids from an XML node into this profile. More...
 

Private Attributes

State m_state
 
bool m_is_current_user
 
uint32_t m_id
 
irr::core::stringw m_username
 
RelationInfom_relation_info
 information about the relation with the current user
 
bool m_is_friend
 Whether or not the user of this profile, is a friend of the current user.
 
std::atomic_bool m_has_fetched_friends
 
std::vector< uint32_t > m_friends
 List of user id's that are friends with the user of this profile. More...
 
bool m_has_fetched_achievements
 
std::vector< uint32_t > m_achievements
 
std::map< uint32_t, irr::core::stringw > m_friend_server_map
 
bool m_cache_bit
 

Detailed Description

Class that represents an online profile.

It manages the online profile for any user on this system, but also for users for which information is requested (e.g. to see the achievements of friends). All those profiles are managed by the ProfileManager.

Member Enumeration Documentation

◆ State

The profile can either be fetching data, or be ready.

Constructor & Destructor Documentation

◆ OnlineProfile() [1/2]

Online::OnlineProfile::OnlineProfile ( const uint32_t &  userid,
const irr::core::stringw &  username,
bool  is_current_user = false 
)

Constructor for a new profile.

It does only store the ID, a name, and if it is the current user.

◆ OnlineProfile() [2/2]

Online::OnlineProfile::OnlineProfile ( const XMLNode xml,
ConstructorType  type = C_DEFAULT 
)

Creates a new profile from an XML Node.

Two different profiles can be created: either a simple one with no relation, or a profile with relation information, i.e. it contains how this profile is related to the current profile.

Parameters
xmlThe XML node with the data to use.
typeEither C_DEFAULT (no relation), or C_RELATION_INFO if the XML node contains relation information.

Member Function Documentation

◆ addFriend()

void Online::OnlineProfile::addFriend ( const uint32_t  id)

Adds a friend to the friend list.

Parameters
idThe id of the profile to add.

◆ fetchAchievements()

void Online::OnlineProfile::fetchAchievements ( )

Triggers an asynchronous request to get the achievements for this user from the server.

The state of this profile is changed to be fetching, and will be reset to ready when the server request returns.

A simple class that receives the achievements, and calls the right Profile instance to store them.

◆ fetchFriends()

void Online::OnlineProfile::fetchFriends ( )

Triggers an asynchronous request to download the friends for this user.

The state of this profile is changed to be fetching, and will be reset to ready when the server request returns.

◆ finishedFetchingAchievements()

bool Online::OnlineProfile::finishedFetchingAchievements ( ) const
inline

True if the profile has fetched friends.

◆ finishedFetchingFriends()

bool Online::OnlineProfile::finishedFetchingFriends ( ) const
inline

True if the profile has fetched friends.

◆ getCacheBit()

bool Online::OnlineProfile::getCacheBit ( ) const
inline

Returns the cache bit for this profile.

Used by the cache eviction algorithm.

◆ getID()

uint32_t Online::OnlineProfile::getID ( ) const
inline

Returns the online id of this profile.

◆ getUserName()

const irr::core::stringw& Online::OnlineProfile::getUserName ( ) const
inline

Returns the user name of this profile.

◆ hasFetchedAchievements()

bool Online::OnlineProfile::hasFetchedAchievements ( ) const
inline

Returns true if the achievements for this profile have been fetched.

◆ hasFetchedFriends()

bool Online::OnlineProfile::hasFetchedFriends ( ) const
inline

Returns true if the friend list for this profile has been fetched.

◆ isCurrentUser()

bool Online::OnlineProfile::isCurrentUser ( ) const
inline

Returns true if this item is the current user.

◆ merge()

void Online::OnlineProfile::merge ( OnlineProfile profile)

Merges the information from a given profile with this profile.

Any data that is in the given profile that's not available in this profile will be copied over, then the given profile will be deleted.

◆ removeFriend()

void Online::OnlineProfile::removeFriend ( const uint32_t  id)

Removed a friend with a given id.

Parameters
idFriend id to remove.

◆ setCacheBit()

void Online::OnlineProfile::setCacheBit ( bool  cache_bit)
inline

Sets the cache bit of this profile.

Used by the cache eviction algorithm.

◆ storeAchievements()

void Online::OnlineProfile::storeAchievements ( const XMLNode input)
private

Stores the achievement ids from an XML node into this profile.

It also sets that achievements have been fetched, and changes the state to be READY again.

Parameters
inputXML node with the achievements data.

◆ storeFriends()

void Online::OnlineProfile::storeFriends ( const XMLNode input)
private

Stores the friends from an XML node into this profile.

It also sets that friends have been fetched, and changes the state of the profile to be READY again.

Parameters
inputXML node with the friends data.

◆ unsetHasFetchedFriends()

void Online::OnlineProfile::unsetHasFetchedFriends ( )
inline

Unsets the flag that all friends of this profile are in cache.

Used when a profile is pushed out of cache.

Member Data Documentation

◆ m_friends

std::vector<uint32_t> Online::OnlineProfile::m_friends
private

List of user id's that are friends with the user of this profile.

In case this profile is of the current user, this list also contains any id's of users that still have a friend request pending.


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