Samchon Framework for CPP  1.0.0
samchon::templates::service::User Class Referenceabstract

#include <User.hpp>

Collaboration diagram for samchon::templates::service::User:

Public Member Functions

 User (Server *server)
 
virtual ~User ()=default
 
auto getServer () const -> Server *
 
auto getAccount () const -> std::string
 
auto getAuthority () const -> int
 
void setAccount (const std::string &account, int authority)
 
void logout ()
 
virtual void sendData (std::shared_ptr< protocol::Invoke > invoke) override
 
virtual void replyData (std::shared_ptr< protocol::Invoke >)=0
 
- Public Member Functions inherited from samchon::TreeMap< size_t, std::shared_ptr< Client > >
auto has (const size_t &key) const -> bool
 Whether have the item or not. More...
 
auto get (const size_t &key) -> std::shared_ptr< Client > &
 Get element. More...
 
void set (const size_t &key, const std::shared_ptr< Client > &val)
 Set element. More...
 
auto pop (const size_t &key) -> std::shared_ptr< Client >
 Pop item. More...
 
- Public Member Functions inherited from samchon::protocol::IProtocol
virtual void replyData (std::shared_ptr< Invoke >)=0
 
virtual void sendData (std::shared_ptr< Invoke >)=0
 

Protected Member Functions

virtual auto createClient () -> Client *=0
 

Detailed Description

An user.

The User is an abstract class groupping Client objects, who communicates with remote client, with same session id. This {link User} represents a remote user literally. Within framework of remote system, an User corresponds to a web-browser and a Client represents a window in the web-browser.

Extends this User class and override the createClient method, a factory method creating a child Client object. I repeat, the User class represents a remote user, groupping Client objects with same session id. If your cloud server has some processes to be handled in the user level, then defines method in this User class. Methods managing account under below are some of them:

The children Client objects, they're contained with their key, the sequence number. If you erase the children Client object by yourself, then their connection with the remote clients will be closed and their destruction method will be called. If you remove all children, then this User object will be also destructed and erased from the parent Server object.

Class Diagram

Templates - Cloud Service

Author
Jeongho Nam http://samchon.org

Definition at line 48 of file User.hpp.

Constructor & Destructor Documentation

samchon::templates::service::User::User ( Server server)
inline

Construct from its parent Server.

Parameters
serverThe parent Server object.

Definition at line 78 of file User.hpp.

References createClient(), and ~User().

Here is the call graph for this function:

virtual samchon::templates::service::User::~User ( )
virtualdefault

Default Destructor.

The User object is destructed when connections with the remote clients are all closed, that is all the children Client objects are all removed, and 30 seconds has left. If some remote client connects within the 30 seconds, then the User object doesn't be destructed.

Referenced by User().

Here is the caller graph for this function:

Member Function Documentation

virtual auto samchon::templates::service::User::createClient ( ) -> Client *
protectedpure virtual

Factory method creating a Client object.

Parameters
driverA web communicator for remote client.
Returns
A newly created Client object.

Referenced by User().

Here is the caller graph for this function:

auto samchon::templates::service::User::getServer ( ) const -> Server*
inline

Get parent { Server} object.

Returns
Parent Server object.

Definition at line 121 of file User.hpp.

auto samchon::templates::service::User::getAccount ( ) const -> std::string
inline

Get account id.

Returns
Account ID.

Definition at line 131 of file User.hpp.

auto samchon::templates::service::User::getAuthority ( ) const -> int
inline

Get authority.

Returns
Authority

Definition at line 141 of file User.hpp.

void samchon::templates::service::User::setAccount ( const std::string &  account,
int  authority 
)
inline

Set account id and authority.

The setAccount() is a method configuring account id and authority of this User.

After the configuring, the account id is enrolled into the parent Server as a key for this User object. You can test existence and access this User object from Server.has() and Server.get() with the account id. Of course, if ordinary account id had existed, then the ordinary key will be replaced.

As you suggest, this setAccount() is something like a log-in function. If what you want is not logging-in, but logging-out, then configure the account id to empty string ""`` or call the logout() method.

Parameters
idTo be account id.
authorityTo be authority.

Definition at line 167 of file User.hpp.

void samchon::templates::service::User::logout ( )
inline

Log-out.

This logout() method configures account id to empty string and authority to zero.

The ordinary account id will be also erased from the parent Server object. You can't access this User object from Server.has() and Server.get() with the ordinary account id more.

Definition at line 197 of file User.hpp.

virtual void samchon::templates::service::User::sendData ( std::shared_ptr< protocol::Invoke invoke)
inlineoverridevirtual

Send an Invoke message.

Sends an Invoke message to all remote clients through the belonged Client objects. Sending the Invoke message to all remote clients, it's came true by passing through the Client.sendData() methods.

1 class protocol.service.User
2 {
3  public sendData(invoke: Invoke): void
4  {
5  for (let it = this.begin(); !it.equal_to(this.end()); it = it.next())
6  it.second.sendData(invoke);
7  }
8 }
Parameters
invokeInvoke message to send to all remote clients.

Definition at line 229 of file User.hpp.

References replyData(), samchon::templates::service::Client::sendData(), and samchon::library::UniqueReadLock::unlock().

Referenced by samchon::templates::service::Server::sendData().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void samchon::templates::service::User::replyData ( std::shared_ptr< protocol::Invoke )
pure virtual

Handle a replied Invoke message.

The default User.replyData() shifts chain to its parent Server object, by calling the Server.replyData() method. If there're some Invoke message to be handled in this User level, then override this method and defines what to do with the Invoke message in this User level.

1 class protocol.service.User
2 {
3  public replyData(invoke: protocol.Invoke): void
4  {
5  this.getServer().replyData(invoke);
6  }
7 }
8 
9 class MyUser extends protocol.service.User
10 {
11  public replyData(invoke: protocol.Invoke): void
12  {
13  if (invoke.apply(this) == false) // IS TARGET TO BE HANDLED IN THIS USER LEVEL
14  super.replyData(invoke); // SHIFT TO SERVER
15  }
16 }
Parameters
invokeAn invoke message to be handled in User level.

Referenced by sendData().

Here is the caller graph for this function:


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