QtWebApp
stefanfrings::HttpSession Class Reference

This class stores data for a single HTTP session. More...

#include <httpsession.h>

Public Member Functions

 HttpSession (const bool canStore=false)
 Constructor. More...
 
 HttpSession (const HttpSession &other)
 Copy constructor. More...
 
HttpSessionoperator= (const HttpSession &other)
 Copy operator. More...
 
virtual ~HttpSession ()
 Destructor. More...
 
QByteArray getId () const
 Get the unique ID of this session. More...
 
bool isNull () const
 Null sessions cannot store data. More...
 
void set (const QByteArray &key, const QVariant &value)
 Set a value. More...
 
void remove (const QByteArray &key)
 Remove a value. More...
 
QVariant get (const QByteArray &key) const
 Get a value. More...
 
bool contains (const QByteArray &key) const
 Check if a key exists. More...
 
QMap< QByteArray, QVariant > getAll () const
 Get a copy of all data stored in this session. More...
 
qint64 getLastAccess () const
 Get the timestamp of last access. More...
 
void setLastAccess ()
 Set the timestamp of last access, to renew the timeout period. More...
 

Detailed Description

This class stores data for a single HTTP session.

A session can store any number of key/value pairs. This class uses implicit sharing for read and write access. This class is thread safe.

See also
HttpSessionStore should be used to create and get instances of this class.

Definition at line 23 of file httpsession.h.

Constructor & Destructor Documentation

◆ HttpSession() [1/2]

HttpSession::HttpSession ( const bool  canStore = false)

Constructor.

Parameters
canStoreThe session can store data, if this parameter is true. Otherwise all calls to set() and remove() do not have any effect.

Definition at line 12 of file httpsession.cpp.

◆ HttpSession() [2/2]

HttpSession::HttpSession ( const HttpSession other)

Copy constructor.

Creates another HttpSession object that shares the data of the other object.

Definition at line 30 of file httpsession.cpp.

◆ ~HttpSession()

HttpSession::~HttpSession ( )
virtual

Destructor.

Detaches from the shared data.

Definition at line 76 of file httpsession.cpp.

Member Function Documentation

◆ contains()

bool HttpSession::contains ( const QByteArray &  key) const

Check if a key exists.

This method is thread safe.

Definition at line 143 of file httpsession.cpp.

◆ get()

QVariant HttpSession::get ( const QByteArray &  key) const

Get a value.

This method is thread safe.

Definition at line 131 of file httpsession.cpp.

◆ getAll()

QMap< QByteArray, QVariant > HttpSession::getAll ( ) const

Get a copy of all data stored in this session.

Changes to the session do not affect the copy and vice versa. This method is thread safe.

Definition at line 155 of file httpsession.cpp.

◆ getId()

QByteArray HttpSession::getId ( ) const

Get the unique ID of this session.

This method is thread safe.

Definition at line 95 of file httpsession.cpp.

◆ getLastAccess()

qint64 HttpSession::getLastAccess ( ) const

Get the timestamp of last access.

That is the time when the last HttpSessionStore::getSession() has been called. This method is thread safe.

Definition at line 167 of file httpsession.cpp.

◆ isNull()

bool HttpSession::isNull ( ) const

Null sessions cannot store data.

All calls to set() and remove() do not have any effect. This method is thread safe.

Definition at line 107 of file httpsession.cpp.

◆ operator=()

HttpSession & HttpSession::operator= ( const HttpSession other)

Copy operator.

Detaches from the current shared data and attaches to the data of the other object.

Definition at line 44 of file httpsession.cpp.

◆ remove()

void HttpSession::remove ( const QByteArray &  key)

Remove a value.

This method is thread safe.

Definition at line 121 of file httpsession.cpp.

◆ set()

void HttpSession::set ( const QByteArray &  key,
const QVariant &  value 
)

Set a value.

This method is thread safe.

Definition at line 111 of file httpsession.cpp.

◆ setLastAccess()

void HttpSession::setLastAccess ( )

Set the timestamp of last access, to renew the timeout period.

Called by HttpSessionStore::getSession(). This method is thread safe.

Definition at line 180 of file httpsession.cpp.


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