1 /* $NetBSD: app_api.c,v 1.7 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2009, 2013, 2014 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 */
26 #include <isc/magic.h>
27 #include <isc/mutex.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)
39 RUNTIME_CHECK(isc_mutex_init(&createlock
) == ISC_R_SUCCESS
);
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
);
49 if (appctx_createfunc
== NULL
)
50 appctx_createfunc
= createfunc
;
52 result
= ISC_R_EXISTS
;
59 isc_appctx_create(isc_mem_t
*mctx
, isc_appctx_t
**ctxp
) {
63 return (isc__appctx_create(mctx
, ctxp
));
67 REQUIRE(appctx_createfunc
!= NULL
);
68 result
= (*appctx_createfunc
)(mctx
, ctxp
);
76 isc_appctx_destroy(isc_appctx_t
**ctxp
) {
77 REQUIRE(ctxp
!= NULL
&& ISCAPI_APPCTX_VALID(*ctxp
));
80 isc__appctx_destroy(ctxp
);
82 (*ctxp
)->methods
->ctxdestroy(ctxp
);
84 ENSURE(*ctxp
== NULL
);
88 isc_app_ctxstart(isc_appctx_t
*ctx
) {
89 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
92 return (isc__app_ctxstart(ctx
));
94 return (ctx
->methods
->ctxstart(ctx
));
98 isc_app_ctxrun(isc_appctx_t
*ctx
) {
99 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
102 return (isc__app_ctxrun(ctx
));
104 return (ctx
->methods
->ctxrun(ctx
));
108 isc_app_ctxonrun(isc_appctx_t
*ctx
, isc_mem_t
*mctx
,
109 isc_task_t
*task
, isc_taskaction_t action
,
112 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
115 return (isc__app_ctxonrun(ctx
, mctx
, task
, action
, arg
));
117 return (ctx
->methods
->ctxonrun(ctx
, mctx
, task
, action
, arg
));
121 isc_app_ctxsuspend(isc_appctx_t
*ctx
) {
122 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
125 return (isc__app_ctxsuspend(ctx
));
127 return (ctx
->methods
->ctxsuspend(ctx
));
131 isc_app_ctxshutdown(isc_appctx_t
*ctx
) {
132 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
135 return (isc__app_ctxshutdown(ctx
));
137 return (ctx
->methods
->ctxshutdown(ctx
));
141 isc_app_ctxfinish(isc_appctx_t
*ctx
) {
142 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
145 isc__app_ctxfinish(ctx
);
147 ctx
->methods
->ctxfinish(ctx
);
151 isc_appctx_settaskmgr(isc_appctx_t
*ctx
, isc_taskmgr_t
*taskmgr
) {
152 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
153 REQUIRE(taskmgr
!= NULL
);
156 isc__appctx_settaskmgr(ctx
, taskmgr
);
158 ctx
->methods
->settaskmgr(ctx
, taskmgr
);
162 isc_appctx_setsocketmgr(isc_appctx_t
*ctx
, isc_socketmgr_t
*socketmgr
) {
163 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
164 REQUIRE(socketmgr
!= NULL
);
167 isc__appctx_setsocketmgr(ctx
, socketmgr
);
169 ctx
->methods
->setsocketmgr(ctx
, socketmgr
);
173 isc_appctx_settimermgr(isc_appctx_t
*ctx
, isc_timermgr_t
*timermgr
) {
174 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
175 REQUIRE(timermgr
!= NULL
);
178 isc__appctx_settimermgr(ctx
, timermgr
);
180 ctx
->methods
->settimermgr(ctx
, timermgr
);
184 isc_app_start(void) {
186 return (isc__app_start());
188 return (ISC_R_NOTIMPLEMENTED
);
192 isc_app_onrun(isc_mem_t
*mctx
, isc_task_t
*task
,
193 isc_taskaction_t action
, void *arg
)
196 return (isc__app_onrun(mctx
, task
, action
, arg
));
198 return (ISC_R_NOTIMPLEMENTED
);
204 return (isc__app_run());
206 return (ISC_R_NOTIMPLEMENTED
);
210 isc_app_shutdown(void) {
212 return (isc__app_shutdown());
214 return (ISC_R_NOTIMPLEMENTED
);
218 isc_app_reload(void) {
220 return (isc__app_reload());
222 return (ISC_R_NOTIMPLEMENTED
);
226 isc_app_finish(void) {
234 isc_app_block(void) {
242 isc_app_unblock(void) {