michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * @section intro_sec Introduction michael@0: * CPR is an OS-abstraction layer which provides the functionality set of an OS michael@0: * while hiding all the operational details from the applications. CPR also michael@0: * provides additional functionality when certain operating-systems prove michael@0: * deficient providing a consistent set of functionality for the applications michael@0: * to use. The pSipCC library uses the CPR routines to achieve portablity. It michael@0: * is the responsibility of any vendor requiring to port pSipCC into their michael@0: * platforms to have the correct implementation of the CPR layer. michael@0: * michael@0: * The CPR delivery includes two "archives/binary" for memory and string michael@0: * related operations. These binaries contain functions that the pSIPCC uses michael@0: * for it's functionality. The header files that contain the external functions michael@0: * (APIs) from these binaries are also distributed. michael@0: * michael@0: * @section sub_sec Functionality michael@0: * CPR consists of a number of functional subsystems to achieve OS abstraction. The main michael@0: * functionality provided by CPR to the pSIPCC library are michael@0: * @li Memory Management - Provided as a binary that needs to be linked into CPR michael@0: * @li Timers michael@0: * @li Inter Process Communication - Sockets, Message Queues, Mutex, Semaphores michael@0: * @li String Handling - Provided as a binary that needs to be linked into CPR michael@0: * @li Thread Abstraction michael@0: * @li Other Platform/OS Abstractions michael@0: * @li Debug/Logging Abstraction michael@0: * michael@0: * @section file_list EXTERNAL APIS michael@0: * The External APIs that need to be exposed by CPR to the pSIPCC application are michael@0: * defined in the following header files. The documentation within michael@0: * each header file lists the functions/macros that @b NEED to be defined for michael@0: * pSIPCC to work correctly. Example functions (and an implementation for michael@0: * Linux) is available for most functions defined in these headers. Look under michael@0: * the "Modules" tab to find the various subsystems and associated APIs and michael@0: * helper functions. michael@0: * @li cpr_debug.h michael@0: * @li cpr_errno.h michael@0: * @li cpr_in.h michael@0: * @li cpr_locks.h michael@0: * @li cpr_rand.h michael@0: * @li cpr_socket.h michael@0: * @li cpr_stdio.h michael@0: * @li cpr_threads.h michael@0: * @li cpr_timers.h michael@0: * @li cpr.h michael@0: * @li cpr_ipc.h michael@0: * @li cpr_stddef.h michael@0: * @li cpr_time.h michael@0: * @li cpr_types.h michael@0: * michael@0: * The function prototypes in these header files are implemented in the michael@0: * binaries related to memory and string functionality. The prototypes are michael@0: * given so that vendors can use these functions for implementation of other michael@0: * CPR parts. michael@0: * @li cpr_memory.h michael@0: * @li cpr_stdlib.h michael@0: * @li cpr_string.h michael@0: * @li cpr_strings.h michael@0: * michael@0: * @section standard_headers Standard Header Files michael@0: * The pSIPCC component expects some standard header files and associated michael@0: * functionality to be present in the native operating system of the vendors michael@0: * porting it. These header files contain some basic functionality that pSIPCC michael@0: * uses for proper operation. A list of the standard headers (from a standard michael@0: * Linux distribution) are - michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * @li michael@0: * michael@0: * michael@0: * @section Comp Compiling CPR michael@0: * A sample makefile is also provided with the Linux distribution. Running michael@0: * "make" generates a CPR executable called "cprtest". This sample makefile can michael@0: * be modified to generate a shared library if required. Modify the CC, STDINC, michael@0: * STDLIB paths to point to the correct compiler and header files in the michael@0: * environment where this is being built. michael@0: * @note The README file shows the exact commands required to build/test the CPR michael@0: * functionality. michael@0: * michael@0: * @file cpr_linux_init.c michael@0: * @brief This file contains CPR initialization routines michael@0: * michael@0: * DESCRIPTION michael@0: * Initialization routine for the Cisco Portable Runtime layer michael@0: * running in the Linux operating System. michael@0: */ michael@0: michael@0: /** michael@0: * @addtogroup Initialization The initialization module michael@0: * @ingroup CPR michael@0: * @brief The intialization module consists of APIs used to initialize or destroy the CPR layer by pSipCC michael@0: * michael@0: * @{ michael@0: */ michael@0: #include "cpr.h" michael@0: #include "cpr_stdlib.h" michael@0: #include "cpr_stdio.h" michael@0: #include "cpr_timers.h" michael@0: #include "cpr_android_timers.h" michael@0: #include "plat_api.h" michael@0: #include michael@0: #ifndef ANDROID michael@0: #include michael@0: #include michael@0: #endif michael@0: #include "plat_debug.h" michael@0: michael@0: /** michael@0: * Mutex to manage message queue list. michael@0: */ michael@0: extern pthread_mutex_t msgQueueListMutex; michael@0: michael@0: /** michael@0: * Boolean to check that cprPreInit been called michael@0: */ michael@0: static boolean pre_init_called = FALSE; michael@0: michael@0: /** michael@0: * cprInfo prints out informational messages that are michael@0: * not necessarily errors, but maybe of interest to michael@0: * someone debugging a problem. Examples of this are michael@0: * requesting a msg from a msg queue that is empty, michael@0: * stopping a timer that is not running, etc... michael@0: */ michael@0: int32_t cprInfo = TRUE; michael@0: michael@0: michael@0: /** michael@0: * cprPreInit michael@0: * michael@0: * @brief The cprPreInit function IS called from pSIPCC @b before any components are initialized. michael@0: * michael@0: * This function @b SHOULD initialize those portions of the CPR that michael@0: * are needed before applications can start using it. The memory subsystem michael@0: * (sandbox) is initialized from this routine. michael@0: * michael@0: * michael@0: * @return CPR_SUCCESS or CPR_FAILURE michael@0: * @note pSIPCC will NOT continue and stop initialization if the return value is CPR_FAILURE. michael@0: */ michael@0: cprRC_t michael@0: cprPreInit (void) michael@0: { michael@0: static const char fname[] = "cprPreInit"; michael@0: int32_t returnCode; michael@0: michael@0: /* michael@0: * Make function reentreant michael@0: */ michael@0: if (pre_init_called == TRUE) { michael@0: return CPR_SUCCESS; michael@0: } michael@0: pre_init_called = TRUE; michael@0: /* michael@0: * Create message queue list mutex michael@0: */ michael@0: returnCode = pthread_mutex_init(&msgQueueListMutex, NULL); michael@0: if (returnCode != 0) { michael@0: CPR_ERROR("%s: MsgQueue Mutex init failure %d\n", fname, returnCode); michael@0: return CPR_FAILURE; michael@0: } michael@0: #ifdef CPR_TIMERS_ENABLED michael@0: returnCode = cpr_timer_pre_init(); michael@0: if (returnCode != 0) { michael@0: CPR_ERROR("%s: timer pre init failed %d\n", fname, returnCode); michael@0: return CPR_FAILURE; michael@0: } michael@0: #endif michael@0: return CPR_SUCCESS; michael@0: } michael@0: michael@0: michael@0: /** michael@0: * cprPostInit michael@0: * michael@0: * @brief The cprPostInit function IS called from pSIPCC @b after all the components are initialized. michael@0: * michael@0: * This function @b SHOULD complete any CPR activities before the phone is michael@0: * operational. In other words a call to this function will be the last line of michael@0: * the phone initializtion routine from pSIPCC. This function implementation michael@0: * ties in a couple of debug commands to get more information on the CPR from michael@0: * the shell. michael@0: * michael@0: * michael@0: * @return CPR_SUCCESS or CPR_FAILURE michael@0: * @note pSIPCC will NOT continue and stop initialization if the return value is CPR_FAILURE. michael@0: */ michael@0: cprRC_t michael@0: cprPostInit (void) michael@0: { michael@0: /* if (cpr_memory_mgmt_post_init() not_eq TRUE) { michael@0: return CPR_FAILURE; michael@0: } michael@0: */ michael@0: return CPR_SUCCESS; michael@0: } michael@0: