Blame lib/isc/app_api.c

Packit Service ae04f2
/*
Packit Service ae04f2
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Packit Service ae04f2
 *
Packit Service ae04f2
 * This Source Code Form is subject to the terms of the Mozilla Public
Packit Service ae04f2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit Service ae04f2
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
Packit Service ae04f2
 *
Packit Service ae04f2
 * See the COPYRIGHT file distributed with this work for additional
Packit Service ae04f2
 * information regarding copyright ownership.
Packit Service ae04f2
 */
Packit Service ae04f2
Packit Service ae04f2
Packit Service ae04f2
#include <config.h>
Packit Service ae04f2
Packit Service ae04f2
#include <stdbool.h>
Packit Service ae04f2
#include <unistd.h>
Packit Service ae04f2
Packit Service ae04f2
#include <isc/app.h>
Packit Service ae04f2
#include <isc/magic.h>
Packit Service ae04f2
#include <isc/mutex.h>
Packit Service ae04f2
#include <isc/once.h>
Packit Service ae04f2
#include <isc/util.h>
Packit Service ae04f2
Packit Service ae04f2
static isc_mutex_t createlock;
Packit Service ae04f2
static isc_once_t once = ISC_ONCE_INIT;
Packit Service ae04f2
static isc_appctxcreatefunc_t appctx_createfunc = NULL;
Packit Service ae04f2
static isc_mutex_t runninglock;
Packit Service ae04f2
static bool is_running = false;
Packit Service ae04f2
Packit Service ae04f2
#define ISCAPI_APPMETHODS_VALID(m) ISC_MAGIC_VALID(m, ISCAPI_APPMETHODS_MAGIC)
Packit Service ae04f2
Packit Service ae04f2
static void
Packit Service ae04f2
initialize(void) {
Packit Service ae04f2
	RUNTIME_CHECK(isc_mutex_init(&createlock) == ISC_R_SUCCESS);
Packit Service ae04f2
	RUNTIME_CHECK(isc_mutex_init(&runninglock) == ISC_R_SUCCESS);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc_app_register(isc_appctxcreatefunc_t createfunc) {
Packit Service ae04f2
	isc_result_t result = ISC_R_SUCCESS;
Packit Service ae04f2
Packit Service ae04f2
	RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
Packit Service ae04f2
Packit Service ae04f2
	LOCK(&createlock);
Packit Service ae04f2
	if (appctx_createfunc == NULL)
Packit Service ae04f2
		appctx_createfunc = createfunc;
Packit Service ae04f2
	else
Packit Service ae04f2
		result = ISC_R_EXISTS;
Packit Service ae04f2
	UNLOCK(&createlock);
Packit Service ae04f2
Packit Service ae04f2
	return (result);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
Packit Service ae04f2
	isc_result_t result;
Packit Service ae04f2
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		return (isc__appctx_create(mctx, ctxp));
Packit Service ae04f2
Packit Service ae04f2
	LOCK(&createlock);
Packit Service ae04f2
Packit Service ae04f2
	REQUIRE(appctx_createfunc != NULL);
Packit Service ae04f2
	result = (*appctx_createfunc)(mctx, ctxp);
Packit Service ae04f2
Packit Service ae04f2
	UNLOCK(&createlock);
Packit Service ae04f2
Packit Service ae04f2
	return (result);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
isc_appctx_destroy(isc_appctx_t **ctxp) {
Packit Service ae04f2
	REQUIRE(ctxp != NULL && ISCAPI_APPCTX_VALID(*ctxp));
Packit Service ae04f2
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		isc__appctx_destroy(ctxp);
Packit Service ae04f2
	else
Packit Service ae04f2
		(*ctxp)->methods->ctxdestroy(ctxp);
Packit Service ae04f2
Packit Service ae04f2
	ENSURE(*ctxp == NULL);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc_app_ctxstart(isc_appctx_t *ctx) {
Packit Service ae04f2
	REQUIRE(ISCAPI_APPCTX_VALID(ctx));
Packit Service ae04f2
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		return (isc__app_ctxstart(ctx));
Packit Service ae04f2
Packit Service ae04f2
	return (ctx->methods->ctxstart(ctx));
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc_app_ctxrun(isc_appctx_t *ctx) {
Packit Service ae04f2
	REQUIRE(ISCAPI_APPCTX_VALID(ctx));
Packit Service ae04f2
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		return (isc__app_ctxrun(ctx));
Packit Service ae04f2
Packit Service ae04f2
	return (ctx->methods->ctxrun(ctx));
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc_app_ctxonrun(isc_appctx_t *ctx, isc_mem_t *mctx,
Packit Service ae04f2
		 isc_task_t *task, isc_taskaction_t action,
Packit Service ae04f2
		 void *arg)
Packit Service ae04f2
{
Packit Service ae04f2
	REQUIRE(ISCAPI_APPCTX_VALID(ctx));
Packit Service ae04f2
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		return (isc__app_ctxonrun(ctx, mctx, task, action, arg));
Packit Service ae04f2
Packit Service ae04f2
	return (ctx->methods->ctxonrun(ctx, mctx, task, action, arg));
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc_app_ctxsuspend(isc_appctx_t *ctx) {
Packit Service ae04f2
	REQUIRE(ISCAPI_APPCTX_VALID(ctx));
Packit Service ae04f2
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		return (isc__app_ctxsuspend(ctx));
Packit Service ae04f2
Packit Service ae04f2
	return (ctx->methods->ctxsuspend(ctx));
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc_app_ctxshutdown(isc_appctx_t *ctx) {
Packit Service ae04f2
	REQUIRE(ISCAPI_APPCTX_VALID(ctx));
Packit Service ae04f2
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		return (isc__app_ctxshutdown(ctx));
Packit Service ae04f2
Packit Service ae04f2
	return (ctx->methods->ctxshutdown(ctx));
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
isc_app_ctxfinish(isc_appctx_t *ctx) {
Packit Service ae04f2
	REQUIRE(ISCAPI_APPCTX_VALID(ctx));
Packit Service ae04f2
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		isc__app_ctxfinish(ctx);
Packit Service ae04f2
Packit Service ae04f2
	ctx->methods->ctxfinish(ctx);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
isc_appctx_settaskmgr(isc_appctx_t *ctx, isc_taskmgr_t *taskmgr) {
Packit Service ae04f2
	REQUIRE(ISCAPI_APPCTX_VALID(ctx));
Packit Service ae04f2
	REQUIRE(taskmgr != NULL);
Packit Service ae04f2
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		isc__appctx_settaskmgr(ctx, taskmgr);
Packit Service ae04f2
Packit Service ae04f2
	ctx->methods->settaskmgr(ctx, taskmgr);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
isc_appctx_setsocketmgr(isc_appctx_t *ctx, isc_socketmgr_t *socketmgr) {
Packit Service ae04f2
	REQUIRE(ISCAPI_APPCTX_VALID(ctx));
Packit Service ae04f2
	REQUIRE(socketmgr != NULL);
Packit Service ae04f2
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		isc__appctx_setsocketmgr(ctx, socketmgr);
Packit Service ae04f2
Packit Service ae04f2
	ctx->methods->setsocketmgr(ctx, socketmgr);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
isc_appctx_settimermgr(isc_appctx_t *ctx, isc_timermgr_t *timermgr) {
Packit Service ae04f2
	REQUIRE(ISCAPI_APPCTX_VALID(ctx));
Packit Service ae04f2
	REQUIRE(timermgr != NULL);
Packit Service ae04f2
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		isc__appctx_settimermgr(ctx, timermgr);
Packit Service ae04f2
Packit Service ae04f2
	ctx->methods->settimermgr(ctx, timermgr);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc_app_start(void) {
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		return (isc__app_start());
Packit Service ae04f2
Packit Service ae04f2
	return (ISC_R_NOTIMPLEMENTED);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc_app_onrun(isc_mem_t *mctx, isc_task_t *task,
Packit Service ae04f2
	       isc_taskaction_t action, void *arg)
Packit Service ae04f2
{
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		return (isc__app_onrun(mctx, task, action, arg));
Packit Service ae04f2
Packit Service ae04f2
	return (ISC_R_NOTIMPLEMENTED);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc_app_run() {
Packit Service ae04f2
	if (isc_bind9) {
Packit Service ae04f2
		isc_result_t result;
Packit Service ae04f2
Packit Service ae04f2
		RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
Packit Service ae04f2
Packit Service ae04f2
		LOCK(&runninglock);
Packit Service ae04f2
		is_running = true;
Packit Service ae04f2
		UNLOCK(&runninglock);
Packit Service ae04f2
		result = isc__app_run();
Packit Service ae04f2
		LOCK(&runninglock);
Packit Service ae04f2
		is_running = false;
Packit Service ae04f2
		UNLOCK(&runninglock);
Packit Service ae04f2
Packit Service ae04f2
		return (result);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	return (ISC_R_NOTIMPLEMENTED);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
bool
Packit Service ae04f2
isc_app_isrunning() {
Packit Service ae04f2
	bool running;
Packit Service ae04f2
Packit Service ae04f2
	RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
Packit Service ae04f2
Packit Service ae04f2
	LOCK(&runninglock);
Packit Service ae04f2
	running = is_running;
Packit Service ae04f2
	UNLOCK(&runninglock);
Packit Service ae04f2
Packit Service ae04f2
	return (running);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc_app_shutdown(void) {
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		return (isc__app_shutdown());
Packit Service ae04f2
Packit Service ae04f2
	return (ISC_R_NOTIMPLEMENTED);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
isc_app_reload(void) {
Packit Service ae04f2
	if (isc_bind9)
Packit Service ae04f2
		return (isc__app_reload());
Packit Service ae04f2
Packit Service ae04f2
	return (ISC_R_NOTIMPLEMENTED);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
isc_app_finish(void) {
Packit Service ae04f2
	if (!isc_bind9)
Packit Service ae04f2
		return;
Packit Service ae04f2
Packit Service ae04f2
	isc__app_finish();
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
isc_app_block(void) {
Packit Service ae04f2
	if (!isc_bind9)
Packit Service ae04f2
		return;
Packit Service ae04f2
Packit Service ae04f2
	isc__app_block();
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
void
Packit Service ae04f2
isc_app_unblock(void) {
Packit Service ae04f2
	if (!isc_bind9)
Packit Service ae04f2
		return;
Packit Service ae04f2
Packit Service ae04f2
	isc__app_unblock();
Packit Service ae04f2
}