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 */
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
) {
64 REQUIRE(appctx_createfunc
!= NULL
);
65 result
= (*appctx_createfunc
)(mctx
, ctxp
);
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
);
82 isc_app_ctxstart(isc_appctx_t
*ctx
) {
83 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
85 return (ctx
->methods
->ctxstart(ctx
));
89 isc_app_ctxrun(isc_appctx_t
*ctx
) {
90 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
92 return (ctx
->methods
->ctxrun(ctx
));
96 isc_app_ctxsuspend(isc_appctx_t
*ctx
) {
97 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
99 return (ctx
->methods
->ctxsuspend(ctx
));
103 isc_app_ctxshutdown(isc_appctx_t
*ctx
) {
104 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
106 return (ctx
->methods
->ctxshutdown(ctx
));
110 isc_app_ctxfinish(isc_appctx_t
*ctx
) {
111 REQUIRE(ISCAPI_APPCTX_VALID(ctx
));
113 ctx
->methods
->ctxfinish(ctx
);
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
);
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
);
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
);