diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-09-24 12:54:31 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-09-24 12:59:42 +0200 |
commit | c820c3d4830b2c5db1c026ee332f2d773c366247 (patch) | |
tree | 993f5622d79236cdec2b86aa05f115ea2875c057 /src/util.h | |
parent | 99961ccd710e5300de5fb749aa10619632ac96e9 (diff) | |
download | cmumble-c820c3d4830b2c5db1c026ee332f2d773c366247.tar.gz cmumble-c820c3d4830b2c5db1c026ee332f2d773c366247.tar.bz2 cmumble-c820c3d4830b2c5db1c026ee332f2d773c366247.zip |
Add a general element finding routine to util.c
And use this to implement find_user and find_channel
as inline functions.
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..dab7b54 --- /dev/null +++ b/src/util.h @@ -0,0 +1,26 @@ +#ifndef _UTIL_H_ +#define _UTIL_H_ + +#include <glib.h> +#include "cmumble.h" + +gpointer +cmumble_find_by_id(GList *list, gsize member_offset, guint id); + +static inline struct cmumble_user * +find_user(struct cmumble_context *ctx, uint32_t session) +{ + return cmumble_find_by_id(ctx->users, + G_STRUCT_OFFSET(struct cmumble_user, id), + session); +} + +static inline struct cmumble_channel * +find_channel(struct cmumble_context *ctx, guint channel_id) +{ + return cmumble_find_by_id(ctx->channels, + G_STRUCT_OFFSET(struct cmumble_channel, id), + channel_id); +} + +#endif /* _UTIL_H_ */ |