Samchon Framework for CPP
1.0.0
|
A network boundary with the client in an User. More...
#include <Client.hpp>
Public Member Functions | |
Client (User *) | |
Construct from User, No and socket. More... | |
auto | getUser () const -> User * |
Get User. More... | |
auto | getService () const -> Service * |
Get Service. More... | |
auto | getNo () const -> size_t |
Get no. More... | |
void | sendData (std::shared_ptr< Invoke >) |
Send Invoke message to (physical) client. More... | |
void | replyData (std::shared_ptr< Invoke >) |
Reply Invoke message from (physical) client. More... | |
![]() | |
IClient () | |
Default Constructor. More... | |
virtual void | listen () |
Listens message from a related system. More... | |
![]() | |
IProtocol () | |
Default Constructor. More... | |
Protected Member Functions | |
virtual auto | createService (const std::string &) -> Service *=0 |
Factory method of Service. More... | |
![]() | |
virtual auto | BUFFER_SIZE () const -> size_t |
Buffer size of network I/O. More... | |
virtual void | _replyData (std::shared_ptr< Invoke >) |
A method for pre-processing replied Invoke message. More... | |
Protected Attributes | |
User * | user |
An User of the Client. More... | |
size_t | no |
A sequence number of the Client in an User. More... | |
Service * | service |
A Service belongs to the Client. More... | |
![]() | |
Socket * | socket |
Socket for network I/O. More... | |
std::mutex * | sendMtx |
A mutex for sending message. More... | |
Private Member Functions | |
void | constructService (const std::string &) |
Construct Service. More... | |
A network boundary with the client in an User.
Client is an object interacting with physical client by socket.
The Client is correspond with a Window in JS (UI) 1:1
Definition at line 46 of file Client.hpp.
Client::Client | ( | User * | user | ) |
|
protectedpure virtual |
Factory method of Service.
name | Requested name representing a Service from the (physical) client |
Implemented in samchon::example::chat_service::ChatClient.
Referenced by constructService().
auto Client::getUser | ( | ) | const -> User* |
auto Client::getService | ( | ) | const -> Service* |
auto Client::getNo | ( | ) | const -> size_t |
|
virtual |
Send Invoke message to (physical) client.
Method sendData of Client does not only send Invoke message to client system, but also archives the Invoke message to database system as a historical-log.
Method sendData monopolies a critical section.
How many threads have called that sendData, the Invoke messages are delivered sequentially.
invoke | Invoke message to send |
Reimplemented from samchon::protocol::IClient.
Definition at line 64 of file Client.cpp.
References constructService(), samchon::protocol::service::User::getSemaphore(), samchon::protocol::IProtocol::replyData(), replyData(), samchon::protocol::service::User::replyData(), samchon::protocol::IClient::sendMtx, service, samchon::protocol::IClient::socket, user, and samchon::ByteArray::writeReversely().
Referenced by constructService(), samchon::protocol::service::Service::sendData(), and samchon::protocol::service::User::sendData().
|
virtual |
Reply Invoke message from (physical) client.
Handles replied Invoke message from client system.
HISTORY_INVOKE and HISTORY_INVOKE_PARAMETER has a 1:N relationship
If you want to modify archiving method, override method of Server::archiveReplyData()
Service::replyData will be called by a new thread. The thread will acquire an admission from semaphore in User to avoid exhausted allocation of threads.
If an std::exception has thrown from Service::replyData, the exception will archived in Database (HISTORY_INVOKE_EXCEPTION)
The most famous thrown parameters like std::exception, std::invalid_argument and std::runtime_error, those are all derived from std::exception.
-> http://www.cplusplus.com/reference/stdexcept/
std::exception
You can't override this method, replyData.
If you want to modify replyData's rule, override related objects' replyData
invoke | Invoke message replied from client system |
Reimplemented from samchon::protocol::IProtocol.
Referenced by sendData().
|
private |
Construct Service.
Constructs Service by requested name from client and notify whether the User is satisfying authority.
name | A name representing type of Service |
Definition at line 123 of file Client.cpp.
References createService(), samchon::protocol::service::User::getAuthority(), samchon::protocol::service::Service::name, samchon::protocol::service::Service::REQUIRE_AUTHORITY(), sendData(), service, and user.
Referenced by sendData().
|
protected |
Definition at line 59 of file Client.hpp.
Referenced by Client(), constructService(), getUser(), and sendData().
|
protected |
A sequence number of the Client in an User.
Definition at line 64 of file Client.hpp.
Referenced by getNo().
|
protected |
A Service belongs to the Client.
Definition at line 69 of file Client.hpp.
Referenced by Client(), constructService(), getService(), and sendData().