Samchon Framework for CPP
1.0.0
|
User containing Client(s) with session-id. More...
#include <User.hpp>
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... | |
![]() | |
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... | |
![]() | |
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 | |
Server * | server |
Server containing the user. More... | |
std::string | sessionID |
Session ID of the user. More... | |
library::RWMutex | mtx |
Mutex for container. More... | |
library::Semaphore * | semaphore |
Semaphore to limit number of thread. More... | |
std::string | id |
Account id. More... | |
int | authority |
Authority allocated to user. More... | |
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)
Override those methods
User::User | ( | Server * | server | ) |
auto User::getServer | ( | ) | const -> Server* |
auto User::getSemaphore | ( | ) | const -> library::Semaphore* |
Get semaphore.
Definition at line 55 of file User.cpp.
References semaphore.
Referenced by samchon::protocol::service::Client::sendData().
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().
auto User::getAuthority | ( | ) | const -> int |
Get authority of user.
Definition at line 50 of file User.cpp.
References authority.
Referenced by samchon::protocol::service::Client::constructService().
|
protectedpure virtual |
Factory method of a Client.
Implemented in samchon::example::chat_service::ChatUser.
Referenced by addClient().
|
private |
Add a client in user.
socket | Socket for interacting with (physical) client |
Definition at line 76 of file User.cpp.
References createClient(), eraseClient(), mtx, and samchon::library::UniqueWriteLock::unlock().
|
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
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
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.
no | Sequence 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().
|
private |
Log-in.
client | |
invoke |
Definition at line 111 of file User.cpp.
References authority, doLogin(), and sendData().
Referenced by replyData().
|
private |
Join as a member.
client | An application; who requested the join command |
invoke | AN invoke message containing parameters of joinning |
Definition at line 121 of file User.cpp.
References doJoin(), and sendData().
Referenced by replyData().
|
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.
client | A 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().
|
protectedpure virtual |
|
protectedpure virtual |
|
overridevirtual |
Send a message.
Sends Invoke message to a network system or shifts the responsibility to related chain.
invoke | An 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().
|
overridevirtual |
Reply a message.
Handles a replied Invoke message or shifts the responsibility to related chain.
invoke | An 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().
|
private |
Server containing the user.
Definition at line 73 of file User.hpp.
Referenced by eraseClient(), getServer(), and User().
|
private |
Session ID of the user.
$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().
|
private |
Mutex for container.
Definition at line 104 of file User.hpp.
Referenced by addClient(), eraseClient(), and sendData().
|
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.
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().
|
private |
|
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.
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
|
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().