CMessengerServerDoc

Back to Classes Page

Parent Class: CDocument

This class is generated by MFC and is the main data storage and processing class for the Chatter-jee Server.

Field Summary

Access Data Type Name
public int m_nPortNum
public CMessengerServerSocket * m_pServerSocket
public CPtrList m_ClientsList
public CPtrList m_SocketsList
public CMessengerClientSocket * m_pClientSocket
public CPtrList m_OfflineMessagesList
public CPtrList m_BlockedUsersList
public HANDLE m_hSocketsListMutex
public HANDLE m_hClientsListMutex
public HANDLE m_hOfflineMessagesListMutex
public HANDLE m_hBlockedUsersListMutex

Constructor Summary

CMessengerServerDoc()

Destructor Summary

~CMessengerServerDoc()

Method Summary

void AddUserToThisUsersBlockedList(CString& ownerName, CString& userName)
CBlockedUserListElement * CreateBlockedUserElement(CString& ownerName, CString& userName)
void CreateBlockedUserMessagePacket(CString &userName, CBlockedUserListElement *element)
void CreateBlockedUsersList()
void EmptyAllLists()
void EmptyBlockedUsersList()
void EmptyBlockedUsersListElement(CBlockedUserListElement *element)
void EmptyClientsList()
void EmptyOfflineMessagesList()
void EmptySocketsList()
bool GetConfigData()
CMessengerServerView * GetViewPtr()
BOOL OnNewDocument()
int processAccept()
void RemoveTempBlockedUsers(CMessagePacket &msg)
BOOL SaveModified()
bool SendMessagePacket(CMessagePacket& msgPacket, CMessengerClientSocket *clientSocket)
void SendServerClosingNotificationToAllClients()
void SendServerClosingNotificationToListMembers(CPtrList &list)

Field Detail

m_nPortNum
Port where the Server Socket will listen to. This number is read from config.txt at the time of application startup. Each client must specify the same number in its config.txt file in order to connect to the server socket on this port number.

m_pServerSocket
Only 1 ServerSocket object is enough to cater to all the clients. This socket just listens on the port specified and accepts connections. On each connection request, it creates a CMessengerClientSocket object.

m_ClientsList
A list of pointer, each of whose member points to a client socket. Each of this client socket corresponds to one user each, who has completed his/her login process.

m_SocketsList
A list of pointer, each of whose member points to a client socket. Each of this client socket corresponds to one user each, who has not yet logged in to the Chatter-jee Server.

m_pClientSocket
This pointer is used again and again for creating CMessengerClientSocket objects at runtime.

m_OfflineMessagesList
A list of pointers, each of which points to a Message packet object. Each of these objects contains 1 offline message.

m_BlockedUsersList
A list of pointers, each of which points to a Blocked Users List Element object. Each of these objects contains a user's name (owner of the list) and user names of all the users blocked by this user. The blocked users' names are placed in the Pointer list inside the Blocked User List Element.

m_hSocketsListMutex
Used as a lock over Sockets List. Required for modifying the list since we are working in a multithreaded environment.

m_hClientsListMutex
Used as a lock over Clients List. Required for modifying the list since we are working in a multithreaded environment.

m_hOfflineMessagesListMutex
Used as a lock over Offline Messages List. Required for modifying the list since we are working in a multithreaded environment.

m_hBlockedUsersListMutex
Used as a lock over Blocked Users List. Required for modifying the list since we are working in a multithreaded environment.

Constructor Detail

CMessengerServerDoc()
Default Constructor. Also creates Mutexes and initializes Client and Server Sockets to NULL.

Destructor Detail

~CMessengerServerDoc()
Empties all the lists of their pointer members. Deletes the Server Socket object.

Method Detail

AddUserToThisUsersBlockedList(CString& ownerName, CString& userName)
Adds a user to another user's blocked users list in the memory.


CreateBlockedUserElement(CString& ownerName, CString& userName)
Creates an object of the type CBlockedUserListElement, and inserts it into the appropriate position in Blocked Users List.


CreateBlockedUserMessagePacket(CString &userName, CBlockedUserListElement *element)
Adds a user to another user's blocked users list in the memory. Here it doesn't create a blocked user element, but just adds the new


CreateBlockedUsersList()

Creates a blocked users list, by reading the Blocked Users Table. This is done at server startup, in OnNewDocument() method.


EmptyAllLists()
First obtains lock on each of the Blocked Users List, Clients List, Sockets List and Offline Messages List. Then it calls various methods to free all the memory used by all the objects in those lists.


EmptyBlockedUsersList()
Traverses thru all the elements of Blocked Users List and frees up the memory pointed to by each of these pointers. For each Blocked User List Element, it calls EmptyBlockedUsersListElement method.


EmptyBlockedUsersListElement(CBlockedUserListElement *element)
Frees up the memory occupied by a Blocked User List Element. It frees up the Blocked Users List, too, by traversing thru the list and deleting each element one by one.


EmptyClientsList()
Traverses thru all the elements of Clients List and frees up the memory pointed to by each of these pointers.


EmptyOfflineMessagesList()
Traverses thru all the elements of Offline Messages List and frees up the memory pointed to by each of these pointers.


EmptySocketsList()
Traverses thru all the elements of Sockets List and frees up the memory pointed to by each of these pointers.


GetConfigData()
Reads the configuration settings from Config.txt, on application startup.


GetViewPtr()
Gets pointer to the application's view object.


OnNewDocument()
Generated by MFC. Called on app startup. We do the following additional things in this method.



processAccept()
Called when a connection request is received by the server socket. Does the following:


RemoveTempBlockedUsers(CMessagePacket &msg)
When a user logs off, this method is called to ensure that the users he/she blocked only for current session are removed from his/her Blocked Users List.


SaveModified()
Called when Chatter-jee Server process is terminating. Does all the cleanup by calling the method EmptyAllLists(). Also sends a notification to all clients that the Chatter-jee Server is shutting down, by calling the method SendServerClosingNotificationToAllClients()


SendMessagePacket(CMessagePacket& msgPacket, CMessengerClientSocket *clientSocket)
Sends 1 message packet over the client socket.


SendServerClosingNotificationToAllClients()
Sends the notification to all online and offline clients, that the Chatter-jee server is shutting down.


SendServerClosingNotificationToListMembers(CPtrList &list)
Sends the notification to all the members of a list, that the Chatter-jee server is shutting down. Each member of the list must point to an object of type CMessengerClientSocket


Back to Classes Page