glib/libglib/src/glib_wsd.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include <e32std.h>
       
    23 #include <_ansi.h>
       
    24 #include <glib.h>
       
    25 #include "glib_wsd.h"
       
    26 #include <stdlib.h>
       
    27 #include <string.h>
       
    28 
       
    29 
       
    30 #if EMULATOR
       
    31 #include <pls.h> // For emulator WSD API 
       
    32 const TUid KLibglibUid3 = {0x10281F2C};     // This is the UID of the library
       
    33 
       
    34 G_BEGIN_DECLS
       
    35 extern const GSourceFuncs temp_g_io_watch_funcs;
       
    36 extern const GIOFuncs temp_unix_channel_funcs;
       
    37 extern const GSourceFuncs temp_g_timeout_funcs;
       
    38 extern const GSourceFuncs temp_g_child_watch_funcs;
       
    39 extern const GSourceFuncs temp_g_idle_funcs;
       
    40 extern const GSourceCallbackFuncs temp_g_source_callback_funcs;
       
    41 extern const GMemVTable temp_glib_mem_vtable;
       
    42 extern const GMemVTable temp_profiler_table;
       
    43 extern const GThreadFunctions temp_g_thread_functions_for_glib_use;
       
    44 
       
    45 void InitializeGlobalStaticMutexes(struct global_struct* g)
       
    46 {
       
    47 	GStaticMutex temp_init_mutex = { NULL, PTHREAD_MUTEX_INITIALIZER };
       
    48 
       
    49 	GStaticRWLock temp_init_lock = {G_STATIC_MUTEX_INIT, NULL, NULL, 0, FALSE, 0, 0};
       
    50 	
       
    51 	//variable initialization for gdataset.c
       
    52 	memcpy(&(g->VARIABLE_NAME_MACRO(g_dataset_global, gdataset)), &temp_init_mutex, sizeof(GStaticMutex));
       
    53 	memcpy(&(g->VARIABLE_NAME_MACRO(g_quark_global, gdataset)), &temp_init_mutex, sizeof(GStaticMutex));
       
    54 	
       
    55 	//variable initialization for gdate.c
       
    56 	memcpy(&(g->VARIABLE_NAME_MACRO(g_date_global, gdate)), &temp_init_mutex, sizeof(GStaticMutex));
       
    57 	
       
    58 	//variable initialization for gmain.c global data
       
    59 	memcpy(&(g->VARIABLE_NAME_MACRO(main_loop, gmain)), &temp_init_mutex, sizeof(GStaticMutex));
       
    60 	memcpy(&(g->VARIABLE_NAME_MACRO(main_context_list, gmain)), &temp_init_mutex, sizeof(GStaticMutex));
       
    61 	
       
    62 	//variable initialization for grand.c
       
    63 	memcpy(&(g->VARIABLE_NAME_MACRO(global_random, grand)), &temp_init_mutex, sizeof(GStaticMutex));
       
    64 	
       
    65 	//variable initialization for gthread.c
       
    66 	memcpy(&(g->VARIABLE_NAME_MACRO(g_thread, gthread)), &temp_init_mutex, sizeof(GStaticMutex));
       
    67 	
       
    68 	//variable initialization for gthreadpool.c
       
    69 	memcpy(&(g->VARIABLE_NAME_MACRO(init, g_thread_pool_new)), &temp_init_mutex, sizeof(GStaticMutex));
       
    70 	
       
    71 	//variable initialization for gutf8.c
       
    72 	memcpy(&(g->VARIABLE_NAME_MACRO(aliases, gutf8)), &temp_init_mutex, sizeof(GStaticMutex));
       
    73 	
       
    74 	//variable initialization for gutils.c
       
    75 	memcpy(&(g->VARIABLE_NAME_MACRO(g_utils_global, gutils)), &temp_init_mutex, sizeof(GStaticMutex));
       
    76 	memcpy(&(g->VARIABLE_NAME_MACRO(g_prgname, gutils)), &temp_init_mutex, sizeof(GStaticMutex));
       
    77 	memcpy(&(g->VARIABLE_NAME_MACRO(g_application_name, gutils)), &temp_init_mutex, sizeof(GStaticMutex));
       
    78 	
       
    79 }
       
    80 
       
    81 
       
    82 int InitializeWsd(struct global_struct* g)
       
    83 {
       
    84 	memset(g,0,sizeof(struct global_struct));
       
    85 
       
    86 	//variable initialization for gbacktrace.c global data
       
    87 	g->VARIABLE_NAME(glib_on_error_halt,gbacktrace) = TRUE ;
       
    88 	
       
    89 	//variable initialization for gdate.c global data
       
    90 	g->VARIABLE_NAME(long_month_names,gdate)[0] = "Error";
       
    91 	g->VARIABLE_NAME(short_month_names,gdate)[0] = "Error";
       
    92 	g->VARIABLE_NAME(dmy_order,gdate)[0] = G_DATE_DAY;
       
    93 	g->VARIABLE_NAME(dmy_order,gdate)[1] = G_DATE_MONTH;
       
    94 	g->VARIABLE_NAME(dmy_order,gdate)[2] = G_DATE_YEAR;
       
    95 	
       
    96 	//variable initialization for giounix.c global data
       
    97 	memcpy(&(g->VARIABLE_NAME(unix_channel_funcs,giounix)),&temp_unix_channel_funcs,sizeof(GIOFuncs));
       
    98 	memcpy(&(g->VARIABLE_NAME(g_io_watch_funcs,giounix)),&temp_g_io_watch_funcs,sizeof(GSourceFuncs));
       
    99 	
       
   100 	//variable initialization for gmain.c global data
       
   101 	memcpy(&(g->VARIABLE_NAME(g_source_callback_funcs,gmain)),&temp_g_source_callback_funcs,sizeof(GSourceCallbackFuncs));
       
   102 	memcpy(&(g->VARIABLE_NAME(g_timeout_funcs,gmain)),&temp_g_timeout_funcs,sizeof(GSourceFuncs));
       
   103 	memcpy(&(g->VARIABLE_NAME(g_child_watch_funcs,gmain)),&temp_g_child_watch_funcs,sizeof(GSourceFuncs));
       
   104 	memcpy(&(g->VARIABLE_NAME(g_idle_funcs,gmain)),&temp_g_idle_funcs,sizeof(GSourceFuncs));
       
   105 	
       
   106 	//variable initialization for gmem.c global data
       
   107 	memcpy(&(g->VARIABLE_NAME(glib_mem_vtable,gmem)),&temp_glib_mem_vtable,sizeof(GMemVTable));
       
   108 	memcpy(&(g->VARIABLE_NAME(profiler_table,gmem)),&temp_profiler_table,sizeof(GMemVTable));
       
   109 
       
   110 	#ifdef G_DISABLE_CHECKS
       
   111 	g->VARIABLE_NAME(glib_mem_profiler_table,gmem)= &(g->VARIABLE_NAME(glib_mem_vtable,gmem));
       
   112 	#else
       
   113 	g->VARIABLE_NAME(glib_mem_profiler_table,gmem) = &(g->VARIABLE_NAME(profiler_table,gmem));
       
   114 	#endif /* G_DISABLE_CHECKS */
       
   115 	
       
   116 	#ifdef ENABLE_GC_FRIENDLY_DEFAULT
       
   117 	g->VARIABLE_NAME(g_mem_gc_friendly,gmem)= TRUE;
       
   118 	#else
       
   119 	g->VARIABLE_NAME(g_mem_gc_friendly,gmem)= FALSE;
       
   120 	#endif /* ENABLE_GC_FRIENDLY_DEFAULT */
       
   121 	
       
   122 	(g->VARIABLE_NAME(dummy,g_allocator_new)).name = "GAllocator is deprecated";
       
   123 	(g->VARIABLE_NAME(dummy,g_allocator_new)).n_preallocs = 1;
       
   124 	(g->VARIABLE_NAME(dummy,g_allocator_new)).is_unused = TRUE;
       
   125 	
       
   126 	//variable initialization for gmessages.c global data
       
   127 	g->VARIABLE_NAME(g_log_always_fatal,gmessages) = (GLogLevelFlags)G_LOG_FATAL_MASK;
       
   128 	g->VARIABLE_NAME(g_log_msg_prefix,gmessages) = (GLogLevelFlags)(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_DEBUG);
       
   129 	g->VARIABLE_NAME(default_log_func,gmessages) = g_log_default_handler;
       
   130 	
       
   131 	//variable initialization for gscanner.c global data
       
   132 	GScannerConfig temp_g_scanner_config_template =
       
   133 	{
       
   134 	  (
       
   135 	   " \t\r\n"
       
   136 	   )			/* cset_skip_characters */,
       
   137 	  (
       
   138 	   G_CSET_a_2_z
       
   139 	   "_"
       
   140 	   G_CSET_A_2_Z
       
   141 	   )			/* cset_identifier_first */,
       
   142 	  (
       
   143 	   G_CSET_a_2_z
       
   144 	   "_"
       
   145 	   G_CSET_A_2_Z
       
   146 	   G_CSET_DIGITS
       
   147 	   G_CSET_LATINS
       
   148 	   G_CSET_LATINC
       
   149 	   )			/* cset_identifier_nth */,
       
   150 	  ( "#\n" )		/* cpair_comment_single */,
       
   151 	  
       
   152 	  FALSE			/* case_sensitive */,
       
   153 	  
       
   154 	  TRUE			/* skip_comment_multi */,
       
   155 	  TRUE			/* skip_comment_single */,
       
   156 	  TRUE			/* scan_comment_multi */,
       
   157 	  TRUE			/* scan_identifier */,
       
   158 	  FALSE			/* scan_identifier_1char */,
       
   159 	  FALSE			/* scan_identifier_NULL */,
       
   160 	  TRUE			/* scan_symbols */,
       
   161 	  FALSE			/* scan_binary */,
       
   162 	  TRUE			/* scan_octal */,
       
   163 	  TRUE			/* scan_float */,
       
   164 	  TRUE			/* scan_hex */,
       
   165 	  FALSE			/* scan_hex_dollar */,
       
   166 	  TRUE			/* scan_string_sq */,
       
   167 	  TRUE			/* scan_string_dq */,
       
   168 	  TRUE			/* numbers_2_int */,
       
   169 	  FALSE			/* int_2_float */,
       
   170 	  FALSE			/* identifier_2_string */,
       
   171 	  TRUE			/* char_2_token */,
       
   172 	  FALSE			/* symbol_2_token */,
       
   173 	  FALSE			/* scope_0_fallback */,
       
   174 	  FALSE			/* store_int64 */,
       
   175 	};
       
   176 
       
   177 	memcpy(&(g->VARIABLE_NAME(g_scanner_config_template,gscanner)),&temp_g_scanner_config_template,sizeof(GScannerConfig));
       
   178 	
       
   179 	//variable initialization for gspawn-symbian.c global data
       
   180 	#ifdef G_SPAWN_SYMBIAN_DEBUG
       
   181 	g->VARIABLE_NAME(debug,gspawn_symbian) = 1;
       
   182 	#else
       
   183 	g->VARIABLE_NAME(debug,gspawn_symbian) = -1;
       
   184 	#endif // G_SPAWN_SYMBIAN_DEBUG 
       
   185 	
       
   186 	//variable initialization for gthread.c global data
       
   187 	g->VARIABLE_NAME(g_thread_use_default_impl,gthread) = TRUE ;
       
   188 	memcpy(&(g->VARIABLE_NAME(g_thread_functions_for_glib_use,gthread)),&temp_g_thread_functions_for_glib_use,sizeof(GThreadFunctions));
       
   189 	
       
   190 	//variable initialization for gslice.c global data
       
   191 	(g->VARIABLE_NAME(slice_config,gslice)).working_set_msecs = 15 * 1000 ;
       
   192 	(g->VARIABLE_NAME(slice_config,gslice)).color_increment	 = 1 ;
       
   193 	
       
   194 	InitializeGlobalStaticMutexes(g);
       
   195 	
       
   196 	return KErrNone;
       
   197 }
       
   198 
       
   199 struct global_struct *Glib_ImpurePtr()
       
   200 {
       
   201 #if defined(__WINSCW__) || defined(__WINS__)
       
   202 
       
   203 	// Access the PLS of this process
       
   204 	struct global_struct* p  = Pls<struct global_struct>(KLibglibUid3, &InitializeWsd);
       
   205     return p;
       
   206 
       
   207 #else
       
   208 
       
   209 	return NULL;	
       
   210 
       
   211 #endif
       
   212 
       
   213 }
       
   214 
       
   215 G_END_DECLS
       
   216 #endif /* EMULATOR */ 
       
   217