blob: ba5d534578c7fb7f880a2aed266434f2a10b53bb [file] [log] [blame]
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001/*
2 * include/proto/obj_type.h
3 * This file contains function prototypes to manipulate object types
4 *
5 * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef _PROTO_OBJ_TYPE_H
23#define _PROTO_OBJ_TYPE_H
24
25#include <common/config.h>
26#include <common/memory.h>
27#include <types/listener.h>
28#include <types/obj_type.h>
29#include <types/proxy.h>
30#include <types/server.h>
31#include <types/stream_interface.h>
32
33static inline enum obj_type obj_type(enum obj_type *t)
34{
35 if (!t || *t > OBJ_TYPE_APPLET)
36 return OBJ_TYPE_NONE;
37 return *t;
38}
39
Willy Tarreau55e4ecd2012-12-08 17:48:47 +010040static inline const char *obj_type_name(enum obj_type *t)
41{
42 switch (obj_type(t)) {
43 case OBJ_TYPE_LISTENER: return "LISTENER";
44 case OBJ_TYPE_PROXY: return "PROXY";
45 case OBJ_TYPE_SERVER: return "SERVER";
46 case OBJ_TYPE_APPLET: return "APPLET";
47 default: return "NONE";
48 }
49}
50
Willy Tarreau3fdb3662012-11-12 00:42:33 +010051static inline struct listener *objt_listener(enum obj_type *t)
52{
53 if (!t || *t != OBJ_TYPE_LISTENER)
54 return NULL;
55 return container_of(t, struct listener, obj_type);
56}
57
58static inline struct proxy *objt_proxy(enum obj_type *t)
59{
60 if (!t || *t != OBJ_TYPE_PROXY)
61 return NULL;
62 return container_of(t, struct proxy, obj_type);
63}
64
65static inline struct server *objt_server(enum obj_type *t)
66{
67 if (!t || *t != OBJ_TYPE_SERVER)
68 return NULL;
69 return container_of(t, struct server, obj_type);
70}
71
72static inline struct si_applet *objt_applet(enum obj_type *t)
73{
74 if (!t || *t != OBJ_TYPE_APPLET)
75 return NULL;
76 return container_of(t, struct si_applet, obj_type);
77}
78
Willy Tarreau55e4ecd2012-12-08 17:48:47 +010079static inline void *obj_base_ptr(enum obj_type *t)
80{
81 switch (obj_type(t)) {
82 case OBJ_TYPE_LISTENER: return objt_listener(t);
83 case OBJ_TYPE_PROXY: return objt_proxy(t);
84 case OBJ_TYPE_SERVER: return objt_server(t);
85 case OBJ_TYPE_APPLET: return objt_applet(t);
86 default: return NULL;
87 }
88}
89
Willy Tarreau3fdb3662012-11-12 00:42:33 +010090#endif /* _PROTO_OBJ_TYPE_H */
91
92/*
93 * Local variables:
94 * c-indent-level: 8
95 * c-basic-offset: 8
96 * End:
97 */