media/webrtc/signaling/src/sipcc/cpr/android/cpr_android_init.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /**
michael@0 6 * @section intro_sec Introduction
michael@0 7 * CPR is an OS-abstraction layer which provides the functionality set of an OS
michael@0 8 * while hiding all the operational details from the applications. CPR also
michael@0 9 * provides additional functionality when certain operating-systems prove
michael@0 10 * deficient providing a consistent set of functionality for the applications
michael@0 11 * to use. The pSipCC library uses the CPR routines to achieve portablity. It
michael@0 12 * is the responsibility of any vendor requiring to port pSipCC into their
michael@0 13 * platforms to have the correct implementation of the CPR layer.
michael@0 14 *
michael@0 15 * The CPR delivery includes two "archives/binary" for memory and string
michael@0 16 * related operations. These binaries contain functions that the pSIPCC uses
michael@0 17 * for it's functionality. The header files that contain the external functions
michael@0 18 * (APIs) from these binaries are also distributed.
michael@0 19 *
michael@0 20 * @section sub_sec Functionality
michael@0 21 * CPR consists of a number of functional subsystems to achieve OS abstraction. The main
michael@0 22 * functionality provided by CPR to the pSIPCC library are
michael@0 23 * @li Memory Management - Provided as a binary that needs to be linked into CPR
michael@0 24 * @li Timers
michael@0 25 * @li Inter Process Communication - Sockets, Message Queues, Mutex, Semaphores
michael@0 26 * @li String Handling - Provided as a binary that needs to be linked into CPR
michael@0 27 * @li Thread Abstraction
michael@0 28 * @li Other Platform/OS Abstractions
michael@0 29 * @li Debug/Logging Abstraction
michael@0 30 *
michael@0 31 * @section file_list EXTERNAL APIS
michael@0 32 * The External APIs that need to be exposed by CPR to the pSIPCC application are
michael@0 33 * defined in the following header files. The documentation within
michael@0 34 * each header file lists the functions/macros that @b NEED to be defined for
michael@0 35 * pSIPCC to work correctly. Example functions (and an implementation for
michael@0 36 * Linux) is available for most functions defined in these headers. Look under
michael@0 37 * the "Modules" tab to find the various subsystems and associated APIs and
michael@0 38 * helper functions.
michael@0 39 * @li cpr_debug.h
michael@0 40 * @li cpr_errno.h
michael@0 41 * @li cpr_in.h
michael@0 42 * @li cpr_locks.h
michael@0 43 * @li cpr_rand.h
michael@0 44 * @li cpr_socket.h
michael@0 45 * @li cpr_stdio.h
michael@0 46 * @li cpr_threads.h
michael@0 47 * @li cpr_timers.h
michael@0 48 * @li cpr.h
michael@0 49 * @li cpr_ipc.h
michael@0 50 * @li cpr_stddef.h
michael@0 51 * @li cpr_time.h
michael@0 52 * @li cpr_types.h
michael@0 53 *
michael@0 54 * The function prototypes in these header files are implemented in the
michael@0 55 * binaries related to memory and string functionality. The prototypes are
michael@0 56 * given so that vendors can use these functions for implementation of other
michael@0 57 * CPR parts.
michael@0 58 * @li cpr_memory.h
michael@0 59 * @li cpr_stdlib.h
michael@0 60 * @li cpr_string.h
michael@0 61 * @li cpr_strings.h
michael@0 62 *
michael@0 63 * @section standard_headers Standard Header Files
michael@0 64 * The pSIPCC component expects some standard header files and associated
michael@0 65 * functionality to be present in the native operating system of the vendors
michael@0 66 * porting it. These header files contain some basic functionality that pSIPCC
michael@0 67 * uses for proper operation. A list of the standard headers (from a standard
michael@0 68 * Linux distribution) are -
michael@0 69 * @li <assert.h>
michael@0 70 * @li <errno.h>
michael@0 71 * @li <arpa/inet.h>
michael@0 72 * @li <netinet/in.h>
michael@0 73 * @li <netinet/tcp.h>
michael@0 74 * @li <pthread.h>
michael@0 75 * @li <sys/socket.h>
michael@0 76 * @li <sys/select.h>
michael@0 77 * @li <sys/un.h>
michael@0 78 * @li <unistd.h>
michael@0 79 * @li <stdarg.h>
michael@0 80 * @li <stdio.h>
michael@0 81 * @li <stdlib.h>
michael@0 82 * @li <string.h>
michael@0 83 * @li <ctype.h>
michael@0 84 * @li <strings.h>
michael@0 85 * @li <time.h>
michael@0 86 *
michael@0 87 *
michael@0 88 * @section Comp Compiling CPR
michael@0 89 * A sample makefile is also provided with the Linux distribution. Running
michael@0 90 * "make" generates a CPR executable called "cprtest". This sample makefile can
michael@0 91 * be modified to generate a shared library if required. Modify the CC, STDINC,
michael@0 92 * STDLIB paths to point to the correct compiler and header files in the
michael@0 93 * environment where this is being built.
michael@0 94 * @note The README file shows the exact commands required to build/test the CPR
michael@0 95 * functionality.
michael@0 96 *
michael@0 97 * @file cpr_linux_init.c
michael@0 98 * @brief This file contains CPR initialization routines
michael@0 99 *
michael@0 100 * DESCRIPTION
michael@0 101 * Initialization routine for the Cisco Portable Runtime layer
michael@0 102 * running in the Linux operating System.
michael@0 103 */
michael@0 104
michael@0 105 /**
michael@0 106 * @addtogroup Initialization The initialization module
michael@0 107 * @ingroup CPR
michael@0 108 * @brief The intialization module consists of APIs used to initialize or destroy the CPR layer by pSipCC
michael@0 109 *
michael@0 110 * @{
michael@0 111 */
michael@0 112 #include "cpr.h"
michael@0 113 #include "cpr_stdlib.h"
michael@0 114 #include "cpr_stdio.h"
michael@0 115 #include "cpr_timers.h"
michael@0 116 #include "cpr_android_timers.h"
michael@0 117 #include "plat_api.h"
michael@0 118 #include <errno.h>
michael@0 119 #ifndef ANDROID
michael@0 120 #include <sys/msg.h>
michael@0 121 #include <sys/ipc.h>
michael@0 122 #endif
michael@0 123 #include "plat_debug.h"
michael@0 124
michael@0 125 /**
michael@0 126 * Mutex to manage message queue list.
michael@0 127 */
michael@0 128 extern pthread_mutex_t msgQueueListMutex;
michael@0 129
michael@0 130 /**
michael@0 131 * Boolean to check that cprPreInit been called
michael@0 132 */
michael@0 133 static boolean pre_init_called = FALSE;
michael@0 134
michael@0 135 /**
michael@0 136 * cprInfo prints out informational messages that are
michael@0 137 * not necessarily errors, but maybe of interest to
michael@0 138 * someone debugging a problem. Examples of this are
michael@0 139 * requesting a msg from a msg queue that is empty,
michael@0 140 * stopping a timer that is not running, etc...
michael@0 141 */
michael@0 142 int32_t cprInfo = TRUE;
michael@0 143
michael@0 144
michael@0 145 /**
michael@0 146 * cprPreInit
michael@0 147 *
michael@0 148 * @brief The cprPreInit function IS called from pSIPCC @b before any components are initialized.
michael@0 149 *
michael@0 150 * This function @b SHOULD initialize those portions of the CPR that
michael@0 151 * are needed before applications can start using it. The memory subsystem
michael@0 152 * (sandbox) is initialized from this routine.
michael@0 153 *
michael@0 154 *
michael@0 155 * @return CPR_SUCCESS or CPR_FAILURE
michael@0 156 * @note pSIPCC will NOT continue and stop initialization if the return value is CPR_FAILURE.
michael@0 157 */
michael@0 158 cprRC_t
michael@0 159 cprPreInit (void)
michael@0 160 {
michael@0 161 static const char fname[] = "cprPreInit";
michael@0 162 int32_t returnCode;
michael@0 163
michael@0 164 /*
michael@0 165 * Make function reentreant
michael@0 166 */
michael@0 167 if (pre_init_called == TRUE) {
michael@0 168 return CPR_SUCCESS;
michael@0 169 }
michael@0 170 pre_init_called = TRUE;
michael@0 171 /*
michael@0 172 * Create message queue list mutex
michael@0 173 */
michael@0 174 returnCode = pthread_mutex_init(&msgQueueListMutex, NULL);
michael@0 175 if (returnCode != 0) {
michael@0 176 CPR_ERROR("%s: MsgQueue Mutex init failure %d\n", fname, returnCode);
michael@0 177 return CPR_FAILURE;
michael@0 178 }
michael@0 179 #ifdef CPR_TIMERS_ENABLED
michael@0 180 returnCode = cpr_timer_pre_init();
michael@0 181 if (returnCode != 0) {
michael@0 182 CPR_ERROR("%s: timer pre init failed %d\n", fname, returnCode);
michael@0 183 return CPR_FAILURE;
michael@0 184 }
michael@0 185 #endif
michael@0 186 return CPR_SUCCESS;
michael@0 187 }
michael@0 188
michael@0 189
michael@0 190 /**
michael@0 191 * cprPostInit
michael@0 192 *
michael@0 193 * @brief The cprPostInit function IS called from pSIPCC @b after all the components are initialized.
michael@0 194 *
michael@0 195 * This function @b SHOULD complete any CPR activities before the phone is
michael@0 196 * operational. In other words a call to this function will be the last line of
michael@0 197 * the phone initializtion routine from pSIPCC. This function implementation
michael@0 198 * ties in a couple of debug commands to get more information on the CPR from
michael@0 199 * the shell.
michael@0 200 *
michael@0 201 *
michael@0 202 * @return CPR_SUCCESS or CPR_FAILURE
michael@0 203 * @note pSIPCC will NOT continue and stop initialization if the return value is CPR_FAILURE.
michael@0 204 */
michael@0 205 cprRC_t
michael@0 206 cprPostInit (void)
michael@0 207 {
michael@0 208 /* if (cpr_memory_mgmt_post_init() not_eq TRUE) {
michael@0 209 return CPR_FAILURE;
michael@0 210 }
michael@0 211 */
michael@0 212 return CPR_SUCCESS;
michael@0 213 }
michael@0 214

mercurial