No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / bind / dist / lib / isc / app_api.c
blob25b62a4eff74206eb32125a5bc276dcff6707b8b
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 /* Id: app_api.c,v 1.5 2009/09/02 23:48:02 tbox Exp */
21 #include <config.h>
23 #include <unistd.h>
25 #include <isc/app.h>
26 #include <isc/magic.h>
27 #include <isc/mutex.h>
28 #include <isc/once.h>
29 #include <isc/util.h>
31 static isc_mutex_t createlock;
32 static isc_once_t once = ISC_ONCE_INIT;
33 static isc_appctxcreatefunc_t appctx_createfunc = NULL;
35 #define ISCAPI_APPMETHODS_VALID(m) ISC_MAGIC_VALID(m, ISCAPI_APPMETHODS_MAGIC)
37 static void
38 initialize(void) {
39 RUNTIME_CHECK(isc_mutex_init(&createlock) == ISC_R_SUCCESS);
42 isc_result_t
43 isc_app_register(isc_appctxcreatefunc_t createfunc) {
44 isc_result_t result = ISC_R_SUCCESS;
46 RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
48 LOCK(&createlock);
49 if (appctx_createfunc == NULL)
50 appctx_createfunc = createfunc;
51 else
52 result = ISC_R_EXISTS;
53 UNLOCK(&createlock);
55 return (result);
58 isc_result_t
59 isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
60 isc_result_t result;
62 LOCK(&createlock);
64 REQUIRE(appctx_createfunc != NULL);
65 result = (*appctx_createfunc)(mctx, ctxp);
67 UNLOCK(&createlock);
69 return (result);
72 void
73 isc_appctx_destroy(isc_appctx_t **ctxp) {
74 REQUIRE(ctxp != NULL && ISCAPI_APPCTX_VALID(*ctxp));
76 (*ctxp)->methods->ctxdestroy(ctxp);
78 ENSURE(*ctxp == NULL);
81 isc_result_t
82 isc_app_ctxstart(isc_appctx_t *ctx) {
83 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
85 return (ctx->methods->ctxstart(ctx));
88 isc_result_t
89 isc_app_ctxrun(isc_appctx_t *ctx) {
90 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
92 return (ctx->methods->ctxrun(ctx));
95 isc_result_t
96 isc_app_ctxsuspend(isc_appctx_t *ctx) {
97 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
99 return (ctx->methods->ctxsuspend(ctx));
102 isc_result_t
103 isc_app_ctxshutdown(isc_appctx_t *ctx) {
104 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
106 return (ctx->methods->ctxshutdown(ctx));
109 void
110 isc_app_ctxfinish(isc_appctx_t *ctx) {
111 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
113 ctx->methods->ctxfinish(ctx);
116 void
117 isc_appctx_settaskmgr(isc_appctx_t *ctx, isc_taskmgr_t *taskmgr) {
118 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
119 REQUIRE(taskmgr != NULL);
121 ctx->methods->settaskmgr(ctx, taskmgr);
124 void
125 isc_appctx_setsocketmgr(isc_appctx_t *ctx, isc_socketmgr_t *socketmgr) {
126 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
127 REQUIRE(socketmgr != NULL);
129 ctx->methods->setsocketmgr(ctx, socketmgr);
132 void
133 isc_appctx_settimermgr(isc_appctx_t *ctx, isc_timermgr_t *timermgr) {
134 REQUIRE(ISCAPI_APPCTX_VALID(ctx));
135 REQUIRE(timermgr != NULL);
137 ctx->methods->settimermgr(ctx, timermgr);