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

The front end of the Mediator system that mediates between the Users and the Groups sub-systems. Contains the declarations of the Mediator functions as used in the Mediator Pattern. More...

Include dependency graph for Mediator_Functions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __MEDIATOR_FUNCTIONS_H__
 

Enumerations

enum  MediatorErrorCode {
  MediatorErrorCode_No_Error = 0 , MediatorErrorCode_Null_Argument = 1 , MediatorErrorCode_User_Does_Not_Exist = 2 , MediatorErrorCode_Group_Does_Not_Exist = 3 ,
  MediatorErrorCode_No_Memory = 4
}
 Represents error codes that can be returned from the Mediator functions used in the Mediator Pattern. More...
 

Functions

void Mediator_ClearAll (void)
 Clear all memory associated with groups and users.
 
MediatorErrorCode Mediator_AddUser (const char *userName)
 Add a user to the list of known users. If the name is already in the list of users, the request to add is ignored.
 
MediatorErrorCode Mediator_RemoveUser (const char *userName)
 Removes the specified user from the list of known users, if the user exists. Also removes the user from all groups.
 
MediatorErrorCode Mediator_AddGroup (const char *groupName)
 Add a group to the list of known groups. If the group is already in the list, the request to add is ignored.
 
MediatorErrorCode Mediator_RemoveGroup (const char *groupName)
 Remove the specified group from the list of known groups if the group exists.
 
MediatorErrorCode Mediator_AddUserToGroup (const char *userName, const char *groupName)
 Add the specified user to the specified group. If the user is already in the group, do nothing. The user must exist.
 
MediatorErrorCode Mediator_RemoveUserFromGroup (const char *userName, const char *groupName)
 Remove the specified user from the specified group.
 
MediatorErrorCode Mediator_RemoveUserFromAllGroups (const char *userName)
 Remove the specified user from all existing groups. The user still exists.
 
MediatorErrorCode Mediator_GetAllGroups (StringList *groups)
 Retrieve a list of all known groups.
 
MediatorErrorCode Mediator_GetAllUsers (StringList *users)
 Retrieve a list of all known users.
 
bool Mediator_IsUserInGroup (const char *userName, const char *groupName)
 Determine if the specified user is in the specified group.
 
MediatorErrorCode Mediator_GetUsersInGroup (const char *groupName, StringList *users)
 Retrieve a list of users in the specified group.
 
MediatorErrorCode Mediator_GetGroupsWithUser (const char *userName, StringList *groups)
 Retrieve a list of all groups that contain the specified user.
 

Detailed Description

The front end of the Mediator system that mediates between the Users and the Groups sub-systems. Contains the declarations of the Mediator functions as used in the Mediator Pattern.

Definition in file Mediator_Functions.h.

Macro Definition Documentation

◆ __MEDIATOR_FUNCTIONS_H__

#define __MEDIATOR_FUNCTIONS_H__

Definition at line 9 of file Mediator_Functions.h.

Enumeration Type Documentation

◆ MediatorErrorCode

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

Enumerator
MediatorErrorCode_No_Error 

No error occurred.

MediatorErrorCode_Null_Argument 

One of the arguments was null or empty.

MediatorErrorCode_User_Does_Not_Exist 

The specified user does not exist.

MediatorErrorCode_Group_Does_Not_Exist 

The specified group does not exist.

MediatorErrorCode_No_Memory 

Indicates an out of memory condition.

Definition at line 17 of file Mediator_Functions.h.

Function Documentation

◆ Mediator_AddGroup()

MediatorErrorCode Mediator_AddGroup ( const char *  groupName)

Add a group to the list of known groups. If the group is already in the list, the request to add is ignored.

Parameters
groupNameName of the group to add. Do nothing if null or empty.
Returns
Returns a value from the MediatorErrorCode enumeration indicating success or failure.
Return values
MediatorErrorCode_No_Errorindicates success.
MediatorErrorCode_Null_Argumentindicates the group parameter is null.
MediatorErrorCode_No_Memoryindicates an out of memory condition.

Definition at line 77 of file Mediator_Functions.c.

References GroupErrorCode_No_Memory, Groups_AddGroup(), MediatorErrorCode_No_Error, MediatorErrorCode_No_Memory, and MediatorErrorCode_Null_Argument.

Referenced by Mediator_SetupGroups().

◆ Mediator_AddUser()

MediatorErrorCode Mediator_AddUser ( const char *  userName)

Add a user to the list of known users. If the name is already in the list of users, the request to add is ignored.

Parameters
userNameName of the user to add. Do nothing if null or empty.
Returns
Returns a value from the MediatorErrorCode enumeration indicating success or failure.
Return values
MediatorErrorCode_No_Errorindicates success.
MediatorErrorCode_Null_Argumentindicates the user parameter is null.
MediatorErrorCode_No_Memoryindicates an out of memory condition.

Definition at line 27 of file Mediator_Functions.c.

References MediatorErrorCode_No_Error, MediatorErrorCode_No_Memory, MediatorErrorCode_Null_Argument, UserErrorCode_No_Memory, and Users_AddUser().

Referenced by Mediator_SetupUsers().

◆ Mediator_AddUserToGroup()

MediatorErrorCode Mediator_AddUserToGroup ( const char *  userName,
const char *  groupName 
)

Add the specified user to the specified group. If the user is already in the group, do nothing. The user must exist.

Parameters
userNameName of user to add. Must be an existing user.
groupNameName of group to add user to. Must be an existing group.
Returns
Returns a value from the MediatorErrorCode enumeration indicating success or failure.
Return values
MediatorErrorCode_No_Errorindicates success.
MediatorErrorCode_Null_Argumentindicates the user or group parameter is null.
MediatorErrorCode_User_Does_Not_Existindicates the user does not exist.
MediatorErrorCode_Group_Does_Not_Existindicates the group does not exist.
MediatorErrorCode_No_Memoryindicates an out of memory condition.

Definition at line 123 of file Mediator_Functions.c.

References GroupErrorCode_Group_Does_Not_Exist, GroupErrorCode_No_Memory, Groups_AddUserGroup(), Groups_UserInGroup(), MediatorErrorCode_Group_Does_Not_Exist, MediatorErrorCode_No_Error, MediatorErrorCode_No_Memory, MediatorErrorCode_Null_Argument, and MediatorErrorCode_User_Does_Not_Exist.

Referenced by _Mediator_Example_AddUserToGroup(), and Mediator_SetupGroups().

◆ Mediator_ClearAll()

void Mediator_ClearAll ( void  )

Clear all memory associated with groups and users.

Definition at line 18 of file Mediator_Functions.c.

References Groups_Clear(), and Users_Clear().

Referenced by Mediator_Exercise().

◆ Mediator_GetAllGroups()

MediatorErrorCode Mediator_GetAllGroups ( StringList groups)

Retrieve a list of all known groups.

Parameters
groupsA StringList object to be filled with the names of all known groups.
Returns
Returns a value from the MediatorErrorCode enumeration indicating success or failure.
Return values
MediatorErrorCode_No_Errorindicates success.
MediatorErrorCode_No_Memoryindicates an out of memory condition.

Definition at line 205 of file Mediator_Functions.c.

References GroupErrorCode_No_Memory, Groups_GetAllGroups(), MediatorErrorCode_No_Error, MediatorErrorCode_No_Memory, and MediatorErrorCode_Null_Argument.

Referenced by _Mediator_Example_RemoveUser(), and _Mediator_Example_ShowAllGroups().

◆ Mediator_GetAllUsers()

MediatorErrorCode Mediator_GetAllUsers ( StringList users)

Retrieve a list of all known users.

Parameters
usersA StringList object to be filled with the names of all known users.
Returns
Returns a value from the MediatorErrorCode enumeration indicating success or failure.
Return values
MediatorErrorCode_No_Errorindicates success.
MediatorErrorCode_No_Memoryindicates an out of memory condition.

Definition at line 227 of file Mediator_Functions.c.

References MediatorErrorCode_No_Error, MediatorErrorCode_No_Memory, MediatorErrorCode_Null_Argument, UserErrorCode_No_Memory, and Users_GetAllUsers().

Referenced by _Mediator_Example_RemoveUser(), and _Mediator_Example_ShowAllUsers().

◆ Mediator_GetGroupsWithUser()

MediatorErrorCode Mediator_GetGroupsWithUser ( const char *  userName,
StringList groups 
)

Retrieve a list of all groups that contain the specified user.

Parameters
userNameName of the user to look for. Must be an existing user.
groupsA StringList object to be filled with the names of the groups containing the user. Object is empty if the name is not in any group.
Returns
Returns a value from the MediatorErrorCode enumeration indicating success or failure.
Return values
MediatorErrorCode_No_Errorindicates success.
MediatorErrorCode_Null_Argumentindicates the user or groups parameter is null.
MediatorErrorCode_User_Does_Not_Existindicates the user does not exist.

Definition at line 287 of file Mediator_Functions.c.

References GroupErrorCode_No_Memory, Groups_GetGroupsWithUser(), MediatorErrorCode_No_Error, MediatorErrorCode_No_Memory, and MediatorErrorCode_Null_Argument.

Referenced by _Mediator_Example_AddUserToGroup(), _Mediator_Example_RemoveUserFromAllGroups(), _Mediator_Example_RemoveUserFromGroup(), and _Mediator_Example_ShowAllGroupsContainingUser().

◆ Mediator_GetUsersInGroup()

MediatorErrorCode Mediator_GetUsersInGroup ( const char *  groupName,
StringList users 
)

Retrieve a list of users in the specified group.

Parameters
groupNameName of the group to examine. Must be an existing group.
usersA StringList object to be filled in with the names of users in the group. Object is empty if the group does not contain any users.
Returns
Returns a value from the MediatorErrorCode enumeration indicating success or failure.
Return values
MediatorErrorCode_No_Errorindicates success.
MediatorErrorCode_Null_Argumentindicates the group or users parameter is null.
MediatorErrorCode_Group_Does_Not_Existindicates the group does not exist.

Definition at line 264 of file Mediator_Functions.c.

References GroupErrorCode_No_Memory, Groups_GetAllUsersInGroup(), MediatorErrorCode_No_Error, MediatorErrorCode_No_Memory, and MediatorErrorCode_Null_Argument.

Referenced by _Mediator_Example_RemoveUser(), and _Mediator_Example_ShowUsersInGroup().

◆ Mediator_IsUserInGroup()

bool Mediator_IsUserInGroup ( const char *  userName,
const char *  groupName 
)

Determine if the specified user is in the specified group.

Parameters
userNameName of user to find. Should be an existing user.
groupNameName of group to look in. Should be an existing group.
Returns
Returns true if the user is in the group; otherwise, returns false.

Definition at line 249 of file Mediator_Functions.c.

References Groups_UserInGroup().

Referenced by _Mediator_Example_SeeIfUserInGroup().

◆ Mediator_RemoveGroup()

MediatorErrorCode Mediator_RemoveGroup ( const char *  groupName)

Remove the specified group from the list of known groups if the group exists.

Parameters
groupNameName of group to remove.
Returns
Returns a value from the MediatorErrorCode enumeration indicating success or failure.
Return values
MediatorErrorCode_No_Errorindicates success.
MediatorErrorCode_Null_Argumentindicates the group parameter is null.
MediatorErrorCode_Group_Does_Not_Existindicates the group does not exist.

Definition at line 100 of file Mediator_Functions.c.

References GroupErrorCode_Group_Does_Not_Exist, Groups_RemoveGroup(), MediatorErrorCode_Group_Does_Not_Exist, MediatorErrorCode_No_Error, and MediatorErrorCode_Null_Argument.

◆ Mediator_RemoveUser()

MediatorErrorCode Mediator_RemoveUser ( const char *  userName)

Removes the specified user from the list of known users, if the user exists. Also removes the user from all groups.

Parameters
userNameName of user to remove.
Returns
Returns a value from the MediatorErrorCode enumeration indicating success or failure.
Return values
MediatorErrorCode_No_Errorindicates success.
MediatorErrorCode_Null_Argumentindicates the user parameter is null.
MediatorErrorCode_User_Does_Not_Existindicates the user does not exist.

Definition at line 50 of file Mediator_Functions.c.

References Mediator_RemoveUserFromAllGroups(), MediatorErrorCode_No_Error, MediatorErrorCode_Null_Argument, MediatorErrorCode_User_Does_Not_Exist, UserErrorCode_User_Does_Not_Exist, and Users_RemoveUser().

Referenced by _Mediator_Example_RemoveUser().

◆ Mediator_RemoveUserFromAllGroups()

MediatorErrorCode Mediator_RemoveUserFromAllGroups ( const char *  userName)

Remove the specified user from all existing groups. The user still exists.

Parameters
userNameName of user to remove. Must be an existing user.
Returns
Returns a value from the MediatorErrorCode enumeration indicating success or failure.
Return values
MediatorErrorCode_No_Errorindicates success.
MediatorErrorCode_Null_Argumentindicates the user parameter is null.
MediatorErrorCode_User_Does_Not_Existindicates the user does not exist.

Definition at line 181 of file Mediator_Functions.c.

References GroupErrorCode_No_Error, Groups_RemoveUserFromAllGroups(), MediatorErrorCode_No_Error, MediatorErrorCode_Null_Argument, MediatorErrorCode_User_Does_Not_Exist, and Users_FindUser().

Referenced by _Mediator_Example_RemoveUserFromAllGroups(), and Mediator_RemoveUser().

◆ Mediator_RemoveUserFromGroup()

MediatorErrorCode Mediator_RemoveUserFromGroup ( const char *  userName,
const char *  groupName 
)

Remove the specified user from the specified group.

Parameters
userNameName of user to remove. Must be an existing user.
groupNameName of group to remove user from. Must be an existing group.
Returns
Returns a value from the MediatorErrorCode enumeration indicating success or failure.
Return values
MediatorErrorCode_No_Errorindicates success.
MediatorErrorCode_Null_Argumentindicates the user or group parameter is null.
MediatorErrorCode_User_Does_Not_Existindicates the user does not exist.
MediatorErrorCode_Group_Does_Not_Existindicates the group does not exist.

Definition at line 154 of file Mediator_Functions.c.

References GroupErrorCode_Group_Does_Not_Exist, Groups_RemoveUserFromGroup(), Groups_UserInGroup(), MediatorErrorCode_Group_Does_Not_Exist, MediatorErrorCode_No_Error, MediatorErrorCode_Null_Argument, and MediatorErrorCode_User_Does_Not_Exist.

Referenced by _Mediator_Example_RemoveUserFromGroup().