blob: 3e68b0085edb47492779f45fe8aad345e8f2f912 [file] [log] [blame]
Willy Tarreau8a8d83b2015-04-13 13:24:54 +02001/*
2 * include/proto/applet.h
3 * This file contains applet function prototypes
4 *
5 * Copyright (C) 2000-2015 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_APPLET_H
23#define _PROTO_APPLET_H
24
25#include <stdlib.h>
26
27#include <common/config.h>
Willy Tarreau81f38d62015-04-13 17:11:11 +020028#include <common/mini-clist.h>
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020029#include <types/applet.h>
30#include <proto/connection.h>
31
Willy Tarreau81f38d62015-04-13 17:11:11 +020032extern struct list applet_runq;
33
Willy Tarreau3c595ac2015-04-19 09:59:31 +020034void applet_run_active();
35
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020036/* Initializes all required fields for a new appctx. Note that it does the
37 * minimum acceptable initialization for an appctx. This means only the
38 * 3 integer states st0, st1, st2 are zeroed.
39 */
40static inline void appctx_init(struct appctx *appctx)
41{
42 appctx->st0 = appctx->st1 = appctx->st2 = 0;
43}
44
45/* Tries to allocate a new appctx and initialize its main fields. The appctx
46 * is returned on success, NULL on failure. The appctx must be released using
47 * pool_free2(connection) or appctx_free(), since it's allocated from the
48 * connection pool. <applet> is assigned as the applet, but it can be NULL.
49 */
Willy Tarreau30576452015-04-13 13:50:30 +020050static inline struct appctx *appctx_new(struct applet *applet)
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020051{
52 struct appctx *appctx;
53
54 appctx = pool_alloc2(pool2_connection);
55 if (likely(appctx != NULL)) {
56 appctx->obj_type = OBJ_TYPE_APPCTX;
57 appctx->applet = applet;
58 appctx_init(appctx);
Willy Tarreau81f38d62015-04-13 17:11:11 +020059 LIST_INIT(&appctx->runq);
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020060 }
61 return appctx;
62}
63
64/* Releases an appctx previously allocated by appctx_new(). Note that
65 * we share the connection pool.
66 */
67static inline void appctx_free(struct appctx *appctx)
68{
Willy Tarreau81f38d62015-04-13 17:11:11 +020069 if (!LIST_ISEMPTY(&appctx->runq))
70 LIST_DEL(&appctx->runq);
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020071 pool_free2(pool2_connection, appctx);
72}
73
Willy Tarreau81f38d62015-04-13 17:11:11 +020074/* wakes up an applet when conditions have changed */
75static inline void appctx_wakeup(struct appctx *appctx)
76{
77 if (LIST_ISEMPTY(&appctx->runq))
78 LIST_ADDQ(&applet_runq, &appctx->runq);
79}
80
Willy Tarreau3c595ac2015-04-19 09:59:31 +020081/* removes an applet from the list of active applets */
82static inline void appctx_pause(struct appctx *appctx)
83{
84 if (!LIST_ISEMPTY(&appctx->runq)) {
85 LIST_DEL(&appctx->runq);
86 LIST_INIT(&appctx->runq);
87 }
88}
89
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020090#endif /* _PROTO_APPLET_H */
91
92/*
93 * Local variables:
94 * c-indent-level: 8
95 * c-basic-offset: 8
96 * End:
97 */