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

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

#include "Mediator_UserList.h"
#include "Mediator_Users.h"
Include dependency graph for Mediator_Users.c:

Go to the source code of this file.

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.
 

Variables

static UserList _users = { 0 }
 The list of users.
 

Detailed Description

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

Definition in file Mediator_Users.c.

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().

Variable Documentation

◆ _users

UserList _users = { 0 }
static

The list of users.

Definition at line 12 of file Mediator_Users.c.

Referenced by Users_AddUser(), Users_Clear(), Users_FindUser(), Users_GetAllUsers(), and Users_RemoveUser().