Blame modules/core/mod_watchdog.h

Packit 90a5c9
/* Licensed to the Apache Software Foundation (ASF) under one or more
Packit 90a5c9
 * contributor license agreements.  See the NOTICE file distributed with
Packit 90a5c9
 * this work for additional information regarding copyright ownership.
Packit 90a5c9
 * The ASF licenses this file to You under the Apache License, Version 2.0
Packit 90a5c9
 * (the "License"); you may not use this file except in compliance with
Packit 90a5c9
 * the License.  You may obtain a copy of the License at
Packit 90a5c9
 *
Packit 90a5c9
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 90a5c9
 *
Packit 90a5c9
 * Unless required by applicable law or agreed to in writing, software
Packit 90a5c9
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 90a5c9
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 90a5c9
 * See the License for the specific language governing permissions and
Packit 90a5c9
 * limitations under the License.
Packit 90a5c9
 */
Packit 90a5c9
Packit 90a5c9
#ifndef MOD_WATCHDOG_H
Packit 90a5c9
#define MOD_WATCHDOG_H
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * @file  mod_watchdog.h
Packit 90a5c9
 * @brief Watchdog module for Apache
Packit 90a5c9
 *
Packit 90a5c9
 * @defgroup MOD_WATCHDOG mod_watchdog
Packit 90a5c9
 * @ingroup  APACHE_MODS
Packit 90a5c9
 * @{
Packit 90a5c9
 */
Packit 90a5c9
Packit 90a5c9
#include "httpd.h"
Packit 90a5c9
#include "http_config.h"
Packit 90a5c9
#include "http_log.h"
Packit 90a5c9
#include "ap_provider.h"
Packit 90a5c9
Packit 90a5c9
#include "apr.h"
Packit 90a5c9
#include "apr_strings.h"
Packit 90a5c9
#include "apr_pools.h"
Packit 90a5c9
#include "apr_shm.h"
Packit 90a5c9
#include "apr_hash.h"
Packit 90a5c9
#include "apr_hooks.h"
Packit 90a5c9
#include "apr_optional.h"
Packit 90a5c9
#include "apr_file_io.h"
Packit 90a5c9
#include "apr_time.h"
Packit 90a5c9
#include "apr_thread_proc.h"
Packit 90a5c9
#include "apr_global_mutex.h"
Packit 90a5c9
#include "apr_thread_mutex.h"
Packit 90a5c9
Packit 90a5c9
#ifdef __cplusplus
Packit 90a5c9
extern "C" {
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Default singleton watchdog instance name.
Packit 90a5c9
 * Singleton watchdog is protected by mutex and
Packit 90a5c9
 * guaranteed to be run inside a single child process
Packit 90a5c9
 * at any time.
Packit 90a5c9
 */
Packit 90a5c9
#define AP_WATCHDOG_SINGLETON       "_singleton_"
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Default watchdog instance name
Packit 90a5c9
 */
Packit 90a5c9
#define AP_WATCHDOG_DEFAULT         "_default_"
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Default Watchdog interval
Packit 90a5c9
 */
Packit 90a5c9
#define AP_WD_TM_INTERVAL           APR_TIME_C(1000000)  /* 1 second     */
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Watchdog thread timer resolution
Packit 90a5c9
 */
Packit 90a5c9
#define AP_WD_TM_SLICE              APR_TIME_C(100000)   /* 100 ms       */
Packit 90a5c9
Packit 90a5c9
/* State values for callback */
Packit 90a5c9
#define AP_WATCHDOG_STATE_STARTING  1
Packit 90a5c9
#define AP_WATCHDOG_STATE_RUNNING   2
Packit 90a5c9
#define AP_WATCHDOG_STATE_STOPPING  3
Packit 90a5c9
Packit 90a5c9
typedef struct ap_watchdog_t ap_watchdog_t;
Packit 90a5c9
Packit 90a5c9
/* Create a set of AP_WD_DECLARE(type), AP_WD_DECLARE_NONSTD(type) and
Packit 90a5c9
 * AP_WD_DECLARE_DATA with appropriate export and import tags for the platform
Packit 90a5c9
 */
Packit 90a5c9
#if !defined(AP_WD_DECLARE)
Packit 90a5c9
#if !defined(WIN32)
Packit 90a5c9
#define AP_WD_DECLARE(type)            type
Packit 90a5c9
#define AP_WD_DECLARE_NONSTD(type)     type
Packit 90a5c9
#define AP_WD_DECLARE_DATA
Packit 90a5c9
#elif defined(AP_WD_DECLARE_STATIC)
Packit 90a5c9
#define AP_WD_DECLARE(type)            type __stdcall
Packit 90a5c9
#define AP_WD_DECLARE_NONSTD(type)     type
Packit 90a5c9
#define AP_WD_DECLARE_DATA
Packit 90a5c9
#elif defined(AP_WD_DECLARE_EXPORT)
Packit 90a5c9
#define AP_WD_DECLARE(type)            __declspec(dllexport) type __stdcall
Packit 90a5c9
#define AP_WD_DECLARE_NONSTD(type)     __declspec(dllexport) type
Packit 90a5c9
#define AP_WD_DECLARE_DATA             __declspec(dllexport)
Packit 90a5c9
#else
Packit 90a5c9
#define AP_WD_DECLARE(type)            __declspec(dllimport) type __stdcall
Packit 90a5c9
#define AP_WD_DECLARE_NONSTD(type)     __declspec(dllimport) type
Packit 90a5c9
#define AP_WD_DECLARE_DATA             __declspec(dllimport)
Packit 90a5c9
#endif
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Callback function used for watchdog.
Packit 90a5c9
 * @param state Watchdog state function. See @p AP_WATCHDOG_STATE_ .
Packit 90a5c9
 * @param data is what was passed to @p ap_watchdog_register_callback function.
Packit 90a5c9
 * @param pool Temporary callback pool destroyed after the call.
Packit 90a5c9
 * @return APR_SUCCESS to continue calling this callback.
Packit 90a5c9
 */
Packit 90a5c9
typedef apr_status_t ap_watchdog_callback_fn_t(int state, void *data,
Packit 90a5c9
                                               apr_pool_t *pool);
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Get watchdog instance.
Packit 90a5c9
 * @param watchdog Storage for watchdog instance.
Packit 90a5c9
 * @param name Watchdog name.
Packit 90a5c9
 * @param parent Non-zero to get the parent process watchdog instance.
Packit 90a5c9
 * @param singleton Non-zero to get the singleton watchdog instance.
Packit 90a5c9
 * @param p The pool to use.
Packit 90a5c9
 * @return APR_SUCCESS if all went well
Packit 90a5c9
 * @remark Use @p AP_WATCHDOG_DEFAULT to get default watchdog instance.
Packit 90a5c9
 *         If separate watchdog thread is needed provide unique name
Packit 90a5c9
 *         and function will create a new watchdog instance.
Packit 90a5c9
 *         Note that default client process watchdog works in singleton mode.
Packit 90a5c9
 */
Packit 90a5c9
APR_DECLARE_OPTIONAL_FN(apr_status_t, ap_watchdog_get_instance,
Packit 90a5c9
                        (ap_watchdog_t **watchdog, const char *name, int parent,
Packit 90a5c9
                         int singleton, apr_pool_t *p));
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Register watchdog callback.
Packit 90a5c9
 * @param watchdog Watchdog to use
Packit 90a5c9
 * @param interval Interval on which the callback function will execute.
Packit 90a5c9
 * @param callback  The function to call on watchdog event.
Packit 90a5c9
 * @param data The data to pass to the callback function.
Packit 90a5c9
 * @return APR_SUCCESS if all went well. APR_EEXIST if already registered.
Packit 90a5c9
 */
Packit 90a5c9
APR_DECLARE_OPTIONAL_FN(apr_status_t, ap_watchdog_register_callback,
Packit 90a5c9
                        (ap_watchdog_t *watchdog, apr_interval_time_t interval,
Packit 90a5c9
                         const void *data, ap_watchdog_callback_fn_t *callback));
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Update registered watchdog callback interval.
Packit 90a5c9
 * @param w Watchdog to use
Packit 90a5c9
 * @param interval New interval on which the callback function will execute.
Packit 90a5c9
 * @param callback  The function to call on watchdog event.
Packit 90a5c9
 * @param data The data to pass to the callback function.
Packit 90a5c9
 * @return APR_SUCCESS if all went well. APR_EOF if callback was not found.
Packit 90a5c9
 */
Packit 90a5c9
APR_DECLARE_OPTIONAL_FN(apr_status_t, ap_watchdog_set_callback_interval,
Packit 90a5c9
                        (ap_watchdog_t *w, apr_interval_time_t interval,
Packit 90a5c9
                         const void *data, ap_watchdog_callback_fn_t *callback));
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Watchdog require hook.
Packit 90a5c9
 * @param s The server record
Packit 90a5c9
 * @param name Watchdog name.
Packit 90a5c9
 * @param parent Non-zero to indicate the parent process watchdog mode.
Packit 90a5c9
 * @param singleton Non-zero to indicate the singleton watchdog mode.
Packit 90a5c9
 * @return OK to enable notifications from this watchdog, DECLINED otherwise.
Packit 90a5c9
 * @remark This is called in post config phase for all watchdog instances
Packit 90a5c9
 *         that have no callbacks registered. Modules using this hook
Packit 90a5c9
 *         should ensure that their post_config hook is called after watchdog
Packit 90a5c9
 *         post_config.
Packit 90a5c9
 */
Packit 90a5c9
APR_DECLARE_EXTERNAL_HOOK(ap, AP_WD, int, watchdog_need, (server_rec *s,
Packit 90a5c9
                          const char *name,
Packit 90a5c9
                          int parent, int singleton))
Packit 90a5c9
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Watchdog initialize hook.
Packit 90a5c9
 * It is called after the watchdog thread is initialized.
Packit 90a5c9
 * @param s The server record
Packit 90a5c9
 * @param name Watchdog name.
Packit 90a5c9
 * @param pool The pool used to create the watchdog.
Packit 90a5c9
 */
Packit 90a5c9
APR_DECLARE_EXTERNAL_HOOK(ap, AP_WD, int, watchdog_init, (
Packit 90a5c9
                          server_rec *s,
Packit 90a5c9
                          const char *name,
Packit 90a5c9
                          apr_pool_t *pool))
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Watchdog terminate hook.
Packit 90a5c9
 * It is called when the watchdog thread is terminated.
Packit 90a5c9
 * @param s The server record
Packit 90a5c9
 * @param name Watchdog name.
Packit 90a5c9
 * @param pool The pool used to create the watchdog.
Packit 90a5c9
 */
Packit 90a5c9
APR_DECLARE_EXTERNAL_HOOK(ap, AP_WD, int, watchdog_exit, (
Packit 90a5c9
                          server_rec *s,
Packit 90a5c9
                          const char *name,
Packit 90a5c9
                          apr_pool_t *pool))
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Fixed interval watchdog hook.
Packit 90a5c9
 * It is called regularly on @p AP_WD_TM_INTERVAL interval.
Packit 90a5c9
 * @param s The server record
Packit 90a5c9
 * @param name Watchdog name.
Packit 90a5c9
 * @param pool Temporary pool destroyed after the call.
Packit 90a5c9
 */
Packit 90a5c9
APR_DECLARE_EXTERNAL_HOOK(ap, AP_WD, int, watchdog_step, (
Packit 90a5c9
                          server_rec *s,
Packit 90a5c9
                          const char *name,
Packit 90a5c9
                          apr_pool_t *pool))
Packit 90a5c9
Packit 90a5c9
#ifdef __cplusplus
Packit 90a5c9
}
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
#endif /* MOD_WATCHDOG_H */
Packit 90a5c9
/** @} */