Babel
Epitech's C++ VoIP project
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Babel::BabelServer Class Reference

Main server class contains almost all the logic for the server. More...

#include <BabelServer.hpp>

Inheritance diagram for Babel::BabelServer:
Collaboration diagram for Babel::BabelServer:

Classes

struct  RequestHandler
 Utils struct to store requests information. More...
 

Public Member Functions

void onMessage (std::shared_ptr< ITCPConnection< RFCCodes >> client, Message< RFCCodes > &msg) override
 Called when we received a message from a client. More...
 
bool onClientConnect (std::shared_ptr< ITCPConnection< RFCCodes >> client) override
 Called when a client connect. More...
 
void onClientDisconnect (std::shared_ptr< ITCPConnection< RFCCodes >> client) override
 Called when a client disconnect. More...
 
Message< RFCCodeslogin (std::shared_ptr< ITCPConnection< RFCCodes >> connection, Message< RFCCodes > message)
 The function to call to manage a login request. More...
 
Message< RFCCodeslistUsers (std::shared_ptr< ITCPConnection< RFCCodes >> connection, Message< RFCCodes > message)
 The function to call to manage a listUser request. More...
 
Message< RFCCodescallUser (std::shared_ptr< ITCPConnection< RFCCodes >> connection, Message< RFCCodes > message)
 The function to call to manage a callUser request. More...
 
Message< RFCCodesjoinCall (std::shared_ptr< ITCPConnection< RFCCodes >> connection, Message< RFCCodes > message)
 The function to call to manage a joinCall request. More...
 
Message< RFCCodesdenyCall (std::shared_ptr< ITCPConnection< RFCCodes >> connection, Message< RFCCodes > message)
 The function to call to manage a denyCall request. More...
 
Message< RFCCodeshangUpCall (std::shared_ptr< ITCPConnection< RFCCodes >> connection, Message< RFCCodes > message)
 The function to call to manage a hangUp request. More...
 
- Public Member Functions inherited from Babel::AsioTCPServer< RFCCodes >
bool start (uint16_t port) override
 Starts the server on indicated port. More...
 
void stop () override
 Stop the server. More...
 
void messageClient (std::shared_ptr< ITCPConnection< RFCCodes >> client, const Message< RFCCodes > &msg) override
 Send a message to the specified client. More...
 
void messageAllClients (const Message< RFCCodes > &msg) override
 Send a message to all connected clients. More...
 
void update (uint64_t nbMessagesToProcess, bool wait) override
 Forces the server to call callbacks. More...
 
bool onClientConnect (std::shared_ptr< ITCPConnection< RFCCodes >> client) override
 Called when a client connect. More...
 
void onClientDisconnect (std::shared_ptr< ITCPConnection< RFCCodes >> client) override
 Called when a client disconnect. More...
 
void onMessage (std::shared_ptr< ITCPConnection< RFCCodes >> client, Message< RFCCodes > &msg) override
 Called when we received a message from a client. More...
 
 ~AsioTCPServer () override
 default dtor More...
 
 AsioTCPServer ()
 ctor More...
 
- Public Member Functions inherited from Babel::ITCPServer< RFCCodes >
virtual ~ITCPServer ()=default
 default dtor More...
 

Private Member Functions

bool getUserByUsername (const std::string &username, User &user)
 Utility function to get the User from it's username. More...
 
bool isValidCallId (int callId) const
 Tells if a given callId is currently pointing to an active call. More...
 
Message< RFCCodes > & getCallAllIPs (Message< RFCCodes > &m, const Call &call)
 
std::shared_ptr< ITCPConnection< RFCCodes > > getConnectionById (uint64_t id) const
 Get the connection from it's Id. More...
 
void messageAllParticipants (Call &call, const Message< RFCCodes > &m)
 Send a message to all current call participants. More...
 
void announceUserLeftCall (Call &call, const ITCPConnection< RFCCodes > &connectionLeaving)
 

Private Attributes

std::map< uint64_t, User_users
 All the connected user. More...
 
FreeList< CallongoingCalls
 The list of all ongoing calls. More...
 
std::map< RFCCodes, RequestHandlerrequestsHandlers
 map that map a RFCCode to an requestHandler More...
 

Additional Inherited Members

- Protected Member Functions inherited from Babel::AsioTCPServer< RFCCodes >
void waitForClientConnections ()
 Listens for client messages. More...
 
- Protected Attributes inherited from Babel::AsioTCPServer< RFCCodes >
TSQueue< OwnedMessage< RFCCodes > > _messagesIn
 Received messages from clients. More...
 
std::deque< std::shared_ptr< ITCPConnection< RFCCodes > > > _connections
 All the active connections. More...
 
asio::io_context _ioContext
 Server's asio context. More...
 
std::thread _contextThread
 Thread running the asio context. More...
 
asio::ip::tcp::acceptor _acceptor
 The acceptor. More...
 
uint64_t _idCounter
 The counter to set connections ids. More...
 

Detailed Description

Main server class contains almost all the logic for the server.

Member Function Documentation

◆ announceUserLeftCall()

void Babel::BabelServer::announceUserLeftCall ( Call call,
const ITCPConnection< RFCCodes > &  connectionLeaving 
)
private

◆ callUser()

Message< RFCCodes > Babel::BabelServer::callUser ( std::shared_ptr< ITCPConnection< RFCCodes >>  connection,
Message< RFCCodes message 
)

The function to call to manage a callUser request.

Parameters
connectionThe connection who made the request
messageThe request message
Returns
The response for the connection

◆ denyCall()

Message< RFCCodes > Babel::BabelServer::denyCall ( std::shared_ptr< ITCPConnection< RFCCodes >>  connection,
Message< RFCCodes message 
)

The function to call to manage a denyCall request.

Parameters
connectionThe connection who made the request
messageThe request message
Returns
The response for the connection

◆ getCallAllIPs()

Message< RFCCodes > & Babel::BabelServer::getCallAllIPs ( Message< RFCCodes > &  m,
const Call call 
)
private

◆ getConnectionById()

std::shared_ptr< ITCPConnection< RFCCodes > > Babel::BabelServer::getConnectionById ( uint64_t  id) const
private

Get the connection from it's Id.

Warning
the connection id isn't it's index you should use this function to get the connection
Parameters
idThe connection id
Returns
A shared_ptr of the connection

◆ getUserByUsername()

bool Babel::BabelServer::getUserByUsername ( const std::string &  username,
User user 
)
private

Utility function to get the User from it's username.

Parameters
usernameThe username of the wanted User
userParam out the reference is assigned to the correct user if the function return true
Returns
true if the user was found and the user is set to the corresponding user otherwise false

◆ hangUpCall()

Message< RFCCodes > Babel::BabelServer::hangUpCall ( std::shared_ptr< ITCPConnection< RFCCodes >>  connection,
Message< RFCCodes message 
)

The function to call to manage a hangUp request.

Parameters
connectionThe connection who made the request
messageThe request message
Returns
The response for the connection

◆ isValidCallId()

bool Babel::BabelServer::isValidCallId ( int  callId) const
private

Tells if a given callId is currently pointing to an active call.

Parameters
callIdThe wanted call Id
Returns
true if it's valid otherwise false

◆ joinCall()

Message< RFCCodes > Babel::BabelServer::joinCall ( std::shared_ptr< ITCPConnection< RFCCodes >>  connection,
Message< RFCCodes message 
)

The function to call to manage a joinCall request.

Parameters
connectionThe connection who made the request
messageThe request message
Returns
The response for the connection

◆ listUsers()

Message< RFCCodes > Babel::BabelServer::listUsers ( std::shared_ptr< ITCPConnection< RFCCodes >>  connection,
Message< RFCCodes message 
)

The function to call to manage a listUser request.

Parameters
connectionThe connection who made the request
messageThe request message
Returns
The response for the connection

◆ login()

Message< RFCCodes > Babel::BabelServer::login ( std::shared_ptr< ITCPConnection< RFCCodes >>  connection,
Message< RFCCodes message 
)

The function to call to manage a login request.

Parameters
connectionThe connection who made the request
messageThe request message
Returns
The response for the connection

◆ messageAllParticipants()

void Babel::BabelServer::messageAllParticipants ( Call call,
const Message< RFCCodes > &  m 
)
private

Send a message to all current call participants.

Note
useful to send userJoinedCall or UserLeftCall

◆ onClientConnect()

bool Babel::BabelServer::onClientConnect ( std::shared_ptr< ITCPConnection< RFCCodes >>  client)
overridevirtual

Called when a client connect.

Note
You can refuse the connection by returning false

Implements Babel::ITCPServer< RFCCodes >.

◆ onClientDisconnect()

void Babel::BabelServer::onClientDisconnect ( std::shared_ptr< ITCPConnection< RFCCodes >>  client)
overridevirtual

Called when a client disconnect.

Implements Babel::ITCPServer< RFCCodes >.

◆ onMessage()

void Babel::BabelServer::onMessage ( std::shared_ptr< ITCPConnection< RFCCodes >>  client,
Message< RFCCodes > &  msg 
)
overridevirtual

Called when we received a message from a client.

Implements Babel::ITCPServer< RFCCodes >.

Member Data Documentation

◆ _users

std::map<uint64_t, User> Babel::BabelServer::_users
private

All the connected user.

◆ ongoingCalls

FreeList<Call> Babel::BabelServer::ongoingCalls
private

The list of all ongoing calls.

◆ requestsHandlers

std::map<RFCCodes, RequestHandler> Babel::BabelServer::requestsHandlers
private

map that map a RFCCode to an requestHandler


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