coan 4.2.4
|
00001 /*************************************************************************** 00002 * Copyright (C) 2004, 2006 Symbian Software Ltd. * 00003 * All rights reserved. * 00004 * * 00005 * Contributed originally by Mike Kinghan, imk@strudl.org * 00006 * * 00007 * Redistribution and use in source and binary forms, with or without * 00008 * modification, are permitted provided that the following conditions * 00009 * are met: * 00010 * * 00011 * Redistributions of source code must retain the above copyright * 00012 * notice, this list of conditions and the following disclaimer. * 00013 * * 00014 * Redistributions in binary form must reproduce the above copyright * 00015 * notice, this list of conditions and the following disclaimer in the * 00016 * documentation and/or other materials provided with the distribution. * 00017 * * 00018 * Neither the name of Symbian Software Ltd. nor the names of its * 00019 * contributors may be used to endorse or promote products derived from * 00020 * this software without specific prior written permission. * 00021 * * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * 00029 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * 00030 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,* 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * 00032 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 00033 * DAMAGE. * 00034 * * 00035 **************************************************************************/ 00036 00037 #include "memory.h" 00038 00040 #ifdef STATE_ALLOCATOR 00041 #undef STATE_ALLOCATOR 00042 00045 #define STATE_ALLOCATOR (zallocate) 00046 #endif 00047 #include "state_utils.h" 00048 00056 00057 void 00058 component_initor( 00059 bool is_static, 00060 bool is_zero_initable, 00061 void **state, 00062 void **public_state, 00063 void const *initialiser, 00064 size_t size, 00065 void (*user_init)()) 00066 { 00067 if (!is_static) { 00068 assert(*state == NULL); 00069 *state = zallocate(size); 00070 *public_state = *state; 00071 } 00072 if (is_zero_initable) { 00073 memset(*state,0,size); 00074 } else if (initialiser) { 00075 memcpy(*state,initialiser,size); 00076 } else { 00077 assert(user_init); 00078 user_init(*state); 00079 } 00080 } 00081 00082 void 00083 component_finitor( 00084 bool is_static, 00085 void **state, 00086 void **public_state, 00087 void (*user_finis)()) 00088 { 00089 if (user_finis) { 00090 assert(*state); 00091 user_finis(*state); 00092 } 00093 if (!is_static) { 00094 assert(*state); 00095 release(state); 00096 *public_state = NULL; 00097 } 00098 } 00101 /* EOF*/