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

The front end of the Groups sub-system. Contains the implementation of the Group support functions as used in the Mediator Pattern. More...

#include <stdlib.h>
#include "Mediator_GroupList.h"
#include "Mediator_Groups.h"
Include dependency graph for Mediator_Groups.c:

Go to the source code of this file.

Functions

void Groups_Clear (void)
 Release all memory associated with list of groups.
 
GroupErrorCode Groups_AddGroup (const char *groupName)
 Add a group to the list of groups.
 
GroupErrorCode Groups_RemoveGroup (const char *groupName)
 Remove a group from the list of groups.
 
GroupGroups_FindGroup (const char *groupName)
 Find a group from the list of groups given the group's name.
 
bool Groups_UserInGroup (const char *userName, const char *groupName)
 Determine if the specified user is in this group. This is a case- sensitive search.
 
GroupErrorCode Groups_AddUserGroup (const char *userName, const char *groupName)
 Add the specified user to the specified group. If the user is already in the group, the operation is ignored.
 
GroupErrorCode Groups_RemoveUserFromGroup (const char *userName, const char *groupName)
 Remove the specified user from the specified group. If the user is not in the group, the operation is ignored.
 
GroupErrorCode Groups_RemoveUserFromAllGroups (const char *userName)
 Remove the specified user from all groups.
 
GroupErrorCode Groups_GetAllGroups (StringList *groups)
 Retrieve a list of all group names.
 
GroupErrorCode Groups_GetAllUsersInGroup (const char *groupName, StringList *users)
 Retrieve a list of all users in the specified group.
 
GroupErrorCode Groups_GetGroupsWithUser (const char *userName, StringList *groups)
 Retrieve a list of all groups that contains the given user.
 

Variables

static GroupList _groups = { 0 }
 The list of all groups.
 

Detailed Description

The front end of the Groups sub-system. Contains the implementation of the Group support functions as used in the Mediator Pattern.

Definition in file Mediator_Groups.c.

Function Documentation

◆ Groups_AddGroup()

GroupErrorCode Groups_AddGroup ( const char *  groupName)

Add a group to the list of groups.

Parameters
groupNameName of the group to add.
Returns
A value from the GroupErrorCode enumeration indicating success or failure.
Return values
GroupErrorCode_No_Errorindicates success.
GroupErrorCode_Null_Argumentindicates the groupName parameter is NULL.
GroupErrorCode_Group_Does_Not_Existindicates the group does not exist.
GroupErrorCode_No_Memoryindicates an out of memory condition.

Definition at line 30 of file Mediator_Groups.c.

References _groups, Group_Create(), Group_Destroy(), GroupErrorCode_No_Error, GroupErrorCode_No_Memory, GroupErrorCode_Null_Argument, GroupList_AddGroup(), and GroupList_FindGroup().

Referenced by Mediator_AddGroup().

◆ Groups_AddUserGroup()

GroupErrorCode Groups_AddUserGroup ( const char *  userName,
const char *  groupName 
)

Add the specified user to the specified group. If the user is already in the group, the operation is ignored.

Parameters
userNameName of the user to add. Cannot be null or empty.
groupNameName of the group to add to. Cannot be null or empty.
Returns
A value from the GroupErrorCode enumeration indicating success or failure.
Return values
GroupErrorCode_No_Errorindicates success.
GroupErrorCode_Null_Argumentindicates the userName or groupName parameter is NULL.
GroupErrorCode_No_Memoryindicates an out of memory condition.

Definition at line 124 of file Mediator_Groups.c.

References _groups, Group_AddUser(), GroupErrorCode_Group_Does_Not_Exist, GroupErrorCode_No_Error, GroupErrorCode_No_Memory, GroupErrorCode_Null_Argument, GroupList_FindGroup(), and GroupList::groups.

Referenced by Mediator_AddUserToGroup().

◆ Groups_Clear()

void Groups_Clear ( void  )

Release all memory associated with list of groups.

Definition at line 22 of file Mediator_Groups.c.

References _groups, and GroupList_Clear().

Referenced by Mediator_ClearAll().

◆ Groups_FindGroup()

Group * Groups_FindGroup ( const char *  groupName)

Find a group from the list of groups given the group's name.

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

Definition at line 84 of file Mediator_Groups.c.

References _groups, GroupList_FindGroup(), and GroupList::groups.

◆ Groups_GetAllGroups()

GroupErrorCode Groups_GetAllGroups ( StringList groups)

Retrieve a list of all group names.

Parameters
groupsA StringList object to be populated with the names of all groups.
Returns
A value from the GroupErrorCode enumeration indicating success or failure.
Return values
GroupErrorCode_No_Errorindicates success.
GroupErrorCode_Null_Argumentindicates the groups parameter is NULL.

Definition at line 200 of file Mediator_Groups.c.

References _groups, GroupErrorCode_No_Error, GroupErrorCode_No_Memory, GroupErrorCode_Null_Argument, GroupList::groups, GroupList::groups_count, Group::Name, and StringList_AddString().

Referenced by Mediator_GetAllGroups().

◆ Groups_GetAllUsersInGroup()

GroupErrorCode Groups_GetAllUsersInGroup ( const char *  groupName,
StringList users 
)

Retrieve a list of all users in the specified group.

Parameters
groupNameName of the group to examine.
usersA StringList object to be populated with the names of all users in the group.
Returns
A value from the GroupErrorCode enumeration indicating success or failure.
Return values
GroupErrorCode_No_Errorindicates success.
GroupErrorCode_Null_Argumentindicates the groupName or groups parameter is NULL.

Definition at line 224 of file Mediator_Groups.c.

References _groups, Group_GetAllUsers(), GroupErrorCode_Group_Does_Not_Exist, GroupErrorCode_No_Error, GroupErrorCode_No_Memory, GroupErrorCode_Null_Argument, GroupList_FindGroup(), and GroupList::groups.

Referenced by Mediator_GetUsersInGroup().

◆ Groups_GetGroupsWithUser()

GroupErrorCode Groups_GetGroupsWithUser ( const char *  userName,
StringList groups 
)

Retrieve a list of all groups that contains the given user.

Parameters
userNameName of the user to search for.
groupsA StringList object to be filled with the names of groups containing the given user.
Returns
A value from the GroupErrorCode enumeration indicating success or failure.
Return values
GroupErrorCode_No_Errorindicates success.
GroupErrorCode_Null_Argumentindicates the userName or groups parameter is NULL.
GroupErrorCode_No_Memoryindicates an out of memory condition.

Definition at line 250 of file Mediator_Groups.c.

References _groups, Group_FindUser(), GroupErrorCode_No_Error, GroupErrorCode_No_Memory, GroupErrorCode_Null_Argument, GroupList::groups, GroupList::groups_count, Group::Name, and StringList_AddString().

Referenced by Mediator_GetGroupsWithUser().

◆ Groups_RemoveGroup()

GroupErrorCode Groups_RemoveGroup ( const char *  groupName)

Remove a group from the list of groups.

Parameters
groupNameName of the group to remove.
Returns
A value from the GroupErrorCode enumeration indicating success or failure.
Return values
GroupErrorCode_No_Errorindicates success.
GroupErrorCode_Null_Argumentindicates the groupName parameter is NULL.
GroupErrorCode_Group_Does_Not_Existindicates the group does not exist.

Definition at line 62 of file Mediator_Groups.c.

References _groups, GroupErrorCode_Group_Does_Not_Exist, GroupErrorCode_No_Error, GroupErrorCode_Null_Argument, GroupList_FindGroup(), and GroupList_RemoveGroup().

Referenced by Mediator_RemoveGroup().

◆ Groups_RemoveUserFromAllGroups()

GroupErrorCode Groups_RemoveUserFromAllGroups ( const char *  userName)

Remove the specified user from all groups.

Parameters
userNameName of the user to remove. Cannot be null.
Returns
A value from the GroupErrorCode enumeration indicating success or failure.
Return values
GroupErrorCode_No_Errorindicates success.
GroupErrorCode_Null_Argumentindicates the userName parameter is NULL.

Definition at line 175 of file Mediator_Groups.c.

References _groups, Group_FindUser(), Group_RemoveUser(), GroupErrorCode_No_Error, GroupErrorCode_Null_Argument, GroupList::groups, and GroupList::groups_count.

Referenced by Mediator_RemoveUserFromAllGroups().

◆ Groups_RemoveUserFromGroup()

GroupErrorCode Groups_RemoveUserFromGroup ( const char *  userName,
const char *  groupName 
)

Remove the specified user from the specified group. If the user is not in the group, the operation is ignored.

Parameters
userNameName of the user to remove. Cannot be null or empty.
groupNameName of the group to remove from. Cannot be null or empty.
Returns
A value from the GroupErrorCode enumeration indicating success or failure.
Return values
GroupErrorCode_No_Errorindicates success.
GroupErrorCode_Null_Argumentindicates the userName or groupName parameter is NULL.

Definition at line 149 of file Mediator_Groups.c.

References _groups, Group_FindUser(), Group_RemoveUser(), GroupErrorCode_Group_Does_Not_Exist, GroupErrorCode_No_Error, GroupErrorCode_Null_Argument, GroupList_FindGroup(), and GroupList::groups.

Referenced by Mediator_RemoveUserFromGroup().

◆ Groups_UserInGroup()

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

Determine if the specified user is in this group. This is a case- sensitive search.

Parameters
userNameName of the user to look for. Should not be NULL.
groupNameName of the group to look in. Should not be NULL.
Returns
Return true if the user is in this group; otherwise false.

Definition at line 104 of file Mediator_Groups.c.

References _groups, Group_FindUser(), GroupList_FindGroup(), and GroupList::groups.

Referenced by Mediator_AddUserToGroup(), Mediator_IsUserInGroup(), and Mediator_RemoveUserFromGroup().

Variable Documentation

◆ _groups