lib.c revision 499b34cea04a46823d003d4c0520c8b03e8513cb
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/*
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Copyright (C) 1999-2001 Internet Software Consortium.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai *
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Permission to use, copy, modify, and distribute this software for any
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * purpose with or without fee is hereby granted, provided that the above
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * copyright notice and this permission notice appear in all copies.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai *
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/* $Id: lib.c,v 1.14 2001/01/09 21:59:59 bwelling Exp $ */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#include <config.h>
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#include <isc/msgcat.h>
cd3e933325e68e23516a196a8fea7f49b1e497c3Ali Bahrami#include <isc/once.h>
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#include <isc/task.h>
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#include <isc/util.h>
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#include <omapi/lib.h>
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#include <omapi/private.h>
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/***
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai *** Library Globals.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai ***/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaiisc_msgcat_t *omapi_msgcat = NULL;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaiomapi_objecttype_t *omapi_type_connection;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaiomapi_objecttype_t *omapi_type_listener;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaiomapi_objecttype_t *omapi_type_generic;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaiomapi_objecttype_t *omapi_type_protocol;
cd3e933325e68e23516a196a8fea7f49b1e497c3Ali Bahramiomapi_objecttype_t *omapi_type_message;
cd3e933325e68e23516a196a8fea7f49b1e497c3Ali Bahramiomapi_objecttype_t *omapi_object_types;
cd3e933325e68e23516a196a8fea7f49b1e497c3Ali Bahrami
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaiisc_mem_t *omapi_mctx;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaiisc_task_t *omapi_task;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaiisc_taskmgr_t *omapi_taskmgr;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaiisc_socketmgr_t *omapi_socketmgr;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/***
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai *** Private to lib.c.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai ***/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaistatic isc_once_t msgcat_once = ISC_ONCE_INIT;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/***
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai *** Functions.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai ***/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaistatic void
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaiopen_msgcat(void) {
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai isc_msgcat_open("libomapi.cat", &omapi_msgcat);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai}
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaivoid
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaiomapi_lib_initmsgcat(void) {
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai /*
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Initialize the OMAPI library's message catalog, omapi_msgcat, if it
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * has not already been initialized.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai RUNTIME_CHECK(isc_once_do(&msgcat_once, open_msgcat) == ISC_R_SUCCESS);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai}
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
isc_result_t
omapi_lib_init(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
isc_socketmgr_t *socketmgr)
{
isc_result_t result;
/*
* Can only be called once without an intervening omapi_lib_destroy.
*/
REQUIRE(omapi_mctx == NULL &&
omapi_socketmgr == NULL &&
omapi_taskmgr == NULL &&
omapi_task == NULL &&
omapi_object_types == NULL);
REQUIRE(mctx != NULL && taskmgr != NULL && socketmgr != NULL);
omapi_mctx = mctx;
omapi_taskmgr = taskmgr;
omapi_socketmgr = socketmgr;
result = isc_task_create(omapi_taskmgr, 0, &omapi_task);
if (result == ISC_R_SUCCESS)
isc_task_setname(omapi_task, "omapi", NULL);
/*
* Initialize the standard object types.
*/
if (result == ISC_R_SUCCESS)
result = generic_init();
if (result == ISC_R_SUCCESS)
result = listener_init();
if (result == ISC_R_SUCCESS)
result = connection_init();
if (result == ISC_R_SUCCESS)
result = protocol_init();
if (result == ISC_R_SUCCESS)
result = message_init();
return (result);
}
/*
* This does not free connections and other in-use objects, only the
* things created by omapi_lib_init(). It is the callers responsibility to
* free the other things (as via omapi_connection_disconnect or
* omapi_object_dereference).
*/
void
omapi_lib_destroy(void) {
object_destroytypes();
handle_destroy();
auth_destroy();
isc_task_destroy(&omapi_task);
omapi_mctx = NULL;
omapi_socketmgr = NULL;
omapi_taskmgr = NULL;
}