2 * Copyright (C) 2009, 2013 Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
17 /* $Id: app_api.c,v 1.5 2009/09/02 23:48:02 tbox Exp $ */
24 #include <isc/magic.h>
25 #include <isc/mutex.h>
29 static isc_mutex_t createlock;
30 static isc_once_t once = ISC_ONCE_INIT;
31 static isc_appctxcreatefunc_t appctx_createfunc = NULL;
33 #define ISCAPI_APPMETHODS_VALID(m) ISC_MAGIC_VALID(m, ISCAPI_APPMETHODS_MAGIC)
37 RUNTIME_CHECK(isc_mutex_init(&createlock) == ISC_R_SUCCESS);
41 isc_app_register(isc_appctxcreatefunc_t createfunc) {
42 isc_result_t result = ISC_R_SUCCESS;
44 RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
47 if (appctx_createfunc == NULL)
48 appctx_createfunc = createfunc;
50 result = ISC_R_EXISTS;
57 isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
62 REQUIRE(appctx_createfunc != NULL);
63 result = (*appctx_createfunc)(mctx, ctxp);
71 isc_appctx_destroy(isc_appctx_t **ctxp) {
72 REQUIRE(ctxp != NULL && ISCAPI_APPCTX_VALID(*ctxp));
74 (*ctxp)->methods->ctxdestroy(ctxp);
76 ENSURE(*ctxp == NULL);
80 isc_app_ctxstart(isc_appctx_t *ctx) {
81 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
83 return (ctx->methods->ctxstart(ctx));
87 isc_app_ctxrun(isc_appctx_t *ctx) {
88 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
90 return (ctx->methods->ctxrun(ctx));
94 isc_app_ctxonrun(isc_appctx_t *ctx, isc_mem_t *mctx,
95 isc_task_t *task, isc_taskaction_t action,
98 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
100 return (ctx->methods->ctxonrun(ctx, mctx, task, action, arg));
104 isc_app_ctxsuspend(isc_appctx_t *ctx) {
105 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
107 return (ctx->methods->ctxsuspend(ctx));
111 isc_app_ctxshutdown(isc_appctx_t *ctx) {
112 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
114 return (ctx->methods->ctxshutdown(ctx));
118 isc_app_ctxfinish(isc_appctx_t *ctx) {
119 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
121 ctx->methods->ctxfinish(ctx);
125 isc_appctx_settaskmgr(isc_appctx_t *ctx, isc_taskmgr_t *taskmgr) {
126 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
127 REQUIRE(taskmgr != NULL);
129 ctx->methods->settaskmgr(ctx, taskmgr);
133 isc_appctx_setsocketmgr(isc_appctx_t *ctx, isc_socketmgr_t *socketmgr) {
134 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
135 REQUIRE(socketmgr != NULL);
137 ctx->methods->setsocketmgr(ctx, socketmgr);
141 isc_appctx_settimermgr(isc_appctx_t *ctx, isc_timermgr_t *timermgr) {
142 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
143 REQUIRE(timermgr != NULL);
145 ctx->methods->settimermgr(ctx, timermgr);