Design Pattern Examples
Overview of object-oriented design patterns
Mediator_Users.h File Reference

The front end of the Users sub-system. Contains the declarations of the support functions for working with users as used in the Mediator Pattern. More...

#include "helpers/stringlist.h"
#include "Mediator_User.h"
Include dependency graph for Mediator_Users.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __MEDIATOR_USERS_H__
 

Enumerations

enum  UserErrorCode { UserErrorCode_No_Error = 0 , UserErrorCode_Null_Argument = 1 , UserErrorCode_User_Does_Not_Exist = 2 , UserErrorCode_No_Memory = 3 }
 Represents error codes that can be returned from the User functions used in the Mediator Pattern. More...
 

Functions

void Users_Clear (void)
 Release all memory associated with the list of users.
 
UserErrorCode Users_AddUser (const char *userName)
 Add a user to the list of users.
 
UserErrorCode Users_RemoveUser (const char *userName)
 Remove a user from the list of users.
 
UserUsers_FindUser (const char *userName)
 Find a user from the list of users given the user's name.
 
UserErrorCode Users_GetAllUsers (StringList *userNames)
 Retrieve a list of all users.
 

Detailed Description

The front end of the Users sub-system. Contains the declarations of the support functions for working with users as used in the Mediator Pattern.

Definition in file Mediator_Users.h.

Macro Definition Documentation

◆ __MEDIATOR_USERS_H__

#define __MEDIATOR_USERS_H__

Definition at line 8 of file Mediator_Users.h.

Enumeration Type Documentation

◆ UserErrorCode

Represents error codes that can be returned from the User functions used in the Mediator Pattern.

Enumerator
UserErrorCode_No_Error 

Indicates success.

UserErrorCode_Null_Argument 

Indicates an argument is NULL.

UserErrorCode_User_Does_Not_Exist 

Indicates the user does not exist.

UserErrorCode_No_Memory 

Indicates an out of memory condition.

Definition at line 18 of file Mediator_Users.h.

Function Documentation

◆ Users_AddUser()

UserErrorCode Users_AddUser ( const char *  userName)

Add a user to the list of users.

Parameters
userNameName of the user to add.
Returns
A value from the UserErrorCode enumeration indicating success or failure.
Return values
UserErrorCode_No_Errorindicates success.
UserErrorCode_Null_Argumentindicates the user parameter is NULL.
UserErrorCode_User_Does_Not_Existindicates the user does not exist.
UserErrorCode_No_Memoryindicates an out of memory condition.

Definition at line 27 of file Mediator_Users.c.

References _users, User_Create(), UserErrorCode_No_Error, UserErrorCode_No_Memory, UserErrorCode_Null_Argument, and UserList_AddUser().

Referenced by Mediator_AddUser().

◆ Users_Clear()

void Users_Clear ( void  )

Release all memory associated with the list of users.

Definition at line 19 of file Mediator_Users.c.

References _users, and UserList_Clear().

Referenced by Mediator_ClearAll().

◆ Users_FindUser()

User * Users_FindUser ( const char *  userName)

Find a user from the list of users given the user's name.

Parameters
userNameName of the user to search for.
Returns
A pointer to a User object if found; otherwise, returns NULL. This is a borrowed pointer; do not deallocate it.

Definition at line 71 of file Mediator_Users.c.

References _users, UserList_FindUser(), and UserList::users.

Referenced by Mediator_RemoveUserFromAllGroups().

◆ Users_GetAllUsers()

UserErrorCode Users_GetAllUsers ( StringList userNames)

Retrieve a list of all users.

Parameters
userNamesA StringList object to be populated with all user names.
Returns
A value from the UserErrorCode enumeration indicating success or failure.
Return values
UserErrorCode_No_Errorindicates success.
UserErrorCode_Null_Argumentindicates the userName parameter is NULL.
UserErrorCode_No_Memoryindicates an out of memory condition.

Definition at line 91 of file Mediator_Users.c.

References _users, User::Name, StringList_AddString(), UserErrorCode_No_Memory, UserErrorCode_Null_Argument, UserList::users, and UserList::users_count.

Referenced by Mediator_GetAllUsers().

◆ Users_RemoveUser()

UserErrorCode Users_RemoveUser ( const char *  userName)

Remove a user from the list of users.

Parameters
userNameName of the user to remove.
Returns
A value from the UserErrorCode enumeration indicating success or failure.
Return values
UserErrorCode_No_Errorindicates success.
UserErrorCode_Null_Argumentindicates the user parameter is NULL.
UserErrorCode_User_Does_Not_Existindicates the user does not exist.

Definition at line 50 of file Mediator_Users.c.

References _users, UserErrorCode_No_Error, UserErrorCode_Null_Argument, UserErrorCode_User_Does_Not_Exist, UserList_FindUser(), and UserList_RemoveUser().

Referenced by Mediator_RemoveUser().