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

User containing Client(s) with session-id. More...

#include <User.hpp>

Collaboration diagram for samchon::protocol::service::User:

Public Member Functions

 User (Server *)
 Construct from server. More...
 
auto getServer () const -> Server *
 Get server. More...
 
auto getSemaphore () const -> library::Semaphore *
 Get semaphore. More...
 
auto getID () const -> std::string
 Get user's account id. More...
 
auto getAuthority () const -> int
 Get authority of user. More...
 
virtual void sendData (std::shared_ptr< Invoke >) override
 Send a message. More...
 
virtual void replyData (std::shared_ptr< Invoke >) override
 Reply a message. More...
 
- Public Member Functions inherited from samchon::protocol::IProtocol
 IProtocol ()
 Default Constructor. More...
 

Protected Member Functions

virtual auto createClient () -> Client *=0
 Factory method of a Client. More...
 
virtual auto doLogin (std::shared_ptr< Invoke >) -> bool=0
 Login and return whether success. More...
 
virtual auto doJoin (std::shared_ptr< Invoke >) -> bool=0
 Join and returns whether success. More...
 

Private Member Functions

void addClient (Socket *)
 Add a client in user. More...
 
void eraseClient (size_t)
 Erase a Client. More...
 
void goLogin (std::shared_ptr< Invoke >)
 Log-in. More...
 
void goJoin (std::shared_ptr< Invoke >)
 Join as a member. More...
 
virtual void goLogout ()
 Log-out. More...
 
- Private Member Functions inherited from samchon::Map< size_t, SmartPointer< Client > >
auto has (const size_t &key) const -> bool
 Whether have the item or not. More...
 
auto get (const size_t &key) -> SmartPointer< Client > &
 Get element. More...
 
void set (const size_t &key, const SmartPointer< Client > &val)
 Set element. More...
 
auto pop (const size_t &key) -> SmartPointer< Client >
 Pop item. More...
 

Private Attributes

Serverserver
 Server containing the user. More...
 
std::string sessionID
 Session ID of the user. More...
 
library::RWMutex mtx
 Mutex for container. More...
 
library::Semaphoresemaphore
 Semaphore to limit number of thread. More...
 
std::string id
 Account id. More...
 
int authority
 Authority allocated to user. More...
 

Detailed Description

User containing Client(s) with session-id.

The User does not have any network I/O and its own special work something to do. It's a container for groupping clients by their session id. Thus, the User corresponds with an user (Computer) and Client corresponds with a client (A browser window)

protocol_service.png

Override those methods

Author
Jeongho Nam http://samchon.org

Definition at line 56 of file User.hpp.

Constructor & Destructor Documentation

User::User ( Server server)

Construct from server.

Parameters
serverA server who containing users and clients
sessionIDA session ID for discriminating User; A logical identifier

Definition at line 24 of file User.cpp.

References authority, semaphore, and server.

Member Function Documentation

auto User::getServer ( ) const -> Server*

Get server.

Definition at line 42 of file User.cpp.

References server.

auto User::getSemaphore ( ) const -> library::Semaphore*

Get semaphore.

See also
User::semaphore

Definition at line 55 of file User.cpp.

References semaphore.

Referenced by samchon::protocol::service::Client::sendData().

Here is the caller graph for this function:

auto User::getID ( ) const -> std::string

Get user's account id.

Definition at line 46 of file User.cpp.

References id.

Referenced by samchon::example::chat_service::ChatRoom::toXML().

Here is the caller graph for this function:

auto User::getAuthority ( ) const -> int

Get authority of user.

See also
User::authority

Definition at line 50 of file User.cpp.

References authority.

Referenced by samchon::protocol::service::Client::constructService().

Here is the caller graph for this function:

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

Factory method of a Client.

Implemented in samchon::example::chat_service::ChatUser.

Referenced by addClient().

Here is the caller graph for this function:

void User::addClient ( Socket *  socket)
private

Add a client in user.

Parameters
socketSocket for interacting with (physical) client

Definition at line 76 of file User.cpp.

References createClient(), eraseClient(), mtx, and samchon::library::UniqueWriteLock::unlock().

Here is the call graph for this function:

void User::eraseClient ( size_t  no)
private

Erase a Client.

Erase a Client from User by its key(no:int).

When a network connection between server and user(person) was disconnected, matched Client is erased from User and the Client object will be destructed.

Some reasons of disconnection

  • An user(not object but person using UI) closed the Window
  • A "closeWindow" command has sent to the Window
  • A network failure has occured

If the Client was the last object remained in the User, the User will be destructed too. However, the User is not destructed directly but waits for 15 seconds. In the 15 seconds, another Client object was created in User, the User doesn't be destructed.

Some reasons of postponing destruction for 15 seconds

  • Page direction(href) or redirection in a browser.
  • Temporary network failure.
Note

There're some tasks that have to completed irrespectively of network connection.

In that case, although user closed the window or logged-out, matched User, Client and Service objects haven't be destructed. They must stay alive until the tasks have completed.

To stay those objects User, Client and Service, use follwing macros. Those macros assure the objects to stay alive until the termination matched each stack.

  • KEEP_USER_ALIVE(Client*)
  • KEEP_CLIENT_ALIVE
  • KEEP_SERVICE_ALIVE
Parameters
noSequence number of the client in user

Definition at line 94 of file User.cpp.

References mtx, server, sessionID, and samchon::library::UniqueWriteLock::unlock().

Referenced by addClient().

Here is the call graph for this function:

Here is the caller graph for this function:

void User::goLogin ( std::shared_ptr< Invoke )
private

Log-in.

Parameters
client
invoke
See also
User::doLogin()

Definition at line 111 of file User.cpp.

References authority, doLogin(), and sendData().

Referenced by replyData().

Here is the call graph for this function:

Here is the caller graph for this function:

void User::goJoin ( std::shared_ptr< Invoke )
private

Join as a member.

Parameters
clientAn application; who requested the join command
invokeAN invoke message containing parameters of joinning
See also
User::doJoin()

Definition at line 121 of file User.cpp.

References doJoin(), and sendData().

Referenced by replyData().

Here is the call graph for this function:

Here is the caller graph for this function:

void User::goLogout ( )
privatevirtual

Log-out.

Log-out account; change id and authority to "guest" and 0.

Default is to send "closeWindow" message to all clients except the applicant.

  • Perspective on UI:

    All windows of the user will be closed by getting an invoke message "closeWindow" except who requested the command log-out.

    The applicant window will moved to default log-in page.

Parameters
clientA window of browser; client who requested the log-out command

Definition at line 130 of file User.cpp.

References authority, and sendData().

Referenced by replyData().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual auto samchon::protocol::service::User::doLogin ( std::shared_ptr< Invoke ) -> bool
protectedpure virtual

Login and return whether success.

Parameters
invokeInvoke message containing parameters for logging-in
Returns
Whether the log-in is succeded or not

Referenced by goLogin().

Here is the caller graph for this function:

virtual auto samchon::protocol::service::User::doJoin ( std::shared_ptr< Invoke ) -> bool
protectedpure virtual

Join and returns whether success.

Parameters
invokeInvoke message containing paramters for joinning
Returns
Whether the join is succeded or not

Referenced by goJoin().

Here is the caller graph for this function:

void User::sendData ( std::shared_ptr< Invoke )
overridevirtual

Send a message.

Sends Invoke message to a network system or shifts the responsibility to related chain.

Parameters
invokeAn Invoke message to send to a network system

Reimplemented from samchon::protocol::IProtocol.

Definition at line 142 of file User.cpp.

References mtx, and samchon::protocol::service::Client::sendData().

Referenced by goJoin(), goLogin(), and goLogout().

Here is the call graph for this function:

Here is the caller graph for this function:

void User::replyData ( std::shared_ptr< Invoke )
overridevirtual

Reply a message.

Handles a replied Invoke message or shifts the responsibility to related chain.

Parameters
invokeAn Invoke message gotten from a network system

Reimplemented from samchon::protocol::IProtocol.

Definition at line 150 of file User.cpp.

References goJoin(), goLogin(), and goLogout().

Referenced by samchon::protocol::service::Client::sendData().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Server* samchon::protocol::service::User::server
private

Server containing the user.

Definition at line 73 of file User.hpp.

Referenced by eraseClient(), getServer(), and User().

std::string samchon::protocol::service::User::sessionID
private

Session ID of the user.

Organization of the Session ID
  • {$name}::{$port}::{$sequence}::{$linux_time}
    1. $name: Name of the Server; Server::NAME()
    2. $port: Port number of the Server; Server::PORT()
    3. $sequence: Sequence number of creation of User in Server
    4. $linux_time: Linux time of current time.

      If the object Server is re-constructed, $sequence can be duplicated. $linux_time is to avoid the duplication so that ensures exclusiveness on session id

Definition at line 94 of file User.hpp.

Referenced by eraseClient().

library::RWMutex samchon::protocol::service::User::mtx
private

Mutex for container.

Definition at line 104 of file User.hpp.

Referenced by addClient(), eraseClient(), and sendData().

library::Semaphore* samchon::protocol::service::User::semaphore
private

Semaphore to limit number of thread.

Semaphore in User is designed to constraint number of thread.

It's recommended to acquire the semaphore when a task from Client or Service occurs a new thread and you want to avoid exhausted allocation of new threads.

Note

If a task influences to all clients in a user globally, use lock instead of acquire

Definition at line 118 of file User.hpp.

Referenced by getSemaphore(), and User().

std::string samchon::protocol::service::User::id
private

Account id.

Default is "guest"

Definition at line 133 of file User.hpp.

Referenced by getID().

int samchon::protocol::service::User::authority
private

Authority allocated to user.

The authority means authority(right, power) level allocated to the user.

The default value is zero, which means not logged-in user.

Note

Each number of level is not defined clearly. Follwing table is just an example.

Level Definition
-1

Banned member

The -1 level member is banished by manager or policy

0

Guest, Not logged in

1

Unconfired member

The member have applied to the join, but the join was not confirmed by manager or policy yet.

2

Confirmed member

The member have joined and have already confirmed by manager or policy

3

Manager

A manager of the application(cloud service). The manager can

  • Access to the monitoring service. (MonitorService)
  • Access historical log of members whose level are below Manager.
  • Banish or modify level of members whose level are below Manager. </u>
4

Administrator or super Manager

Administrator is a Manager of Managers. An administrator can do same thing with Managers, but adminstrator even possible to target Managers as below.

Definition at line 200 of file User.hpp.

Referenced by getAuthority(), goLogin(), goLogout(), and User().


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