00001 #include "ac_app_context_private.h" 00002 00003 #include "kr_controller_private.h" 00004 #include "utils_cl2.h" 00005 00006 #include <stdlib.h> // free 00007 00008 // -------------------------------------------------- 00009 // Symbian private implementation 00010 // -------------------------------------------------- 00011 00012 // We include here so that we can directly refer to anything and 00013 // everything in here. 00014 #ifdef __cplusplus 00015 #if defined(__SYMBIAN32__) 00016 #include "ac_app_context_epoc.cpp" 00017 #endif /* __SYMBIAN32__ */ 00018 #endif 00019 00020 // -------------------------------------------------- 00021 // common private implementation 00022 // -------------------------------------------------- 00023 00024 struct _ac_AppContext 00025 { 00026 kr_Controller* kr; // not owned 00027 DEFINE_FOR_SYMBIAN_CXX(CAppContext* plat); // owned 00028 const char* logdb_dir; // not owned 00029 char* logdb_file; // owned 00030 char* log_uploads_dir; // owned 00031 ac_Registry registry; // initially zeroed 00032 bb_Blackboard* blackboard; // owned 00033 }; 00034 00035 EXTERN_C ac_AppContext* ac_AppContext_new(GError** error) 00036 { 00037 ac_AppContext* self = g_try_new0(ac_AppContext, 1); 00038 if (G_UNLIKELY(!self)) { 00039 if (error) *error = gx_error_no_memory; 00040 return NULL; 00041 } 00042 00043 self->blackboard = bb_Blackboard_new(error); 00044 if (G_UNLIKELY(!self->blackboard)) { 00045 ac_AppContext_destroy(self); 00046 return NULL; 00047 } 00048 00049 return self; 00050 } 00051 00052 // The result is "static", and not to be freed. 00053 static const gchar* get_config_database_dir(ac_AppContext* self) 00054 { 00055 const gchar* database_dir = cf_RcFile_get_database_dir(ac_RcFile(self)); 00056 return database_dir; 00057 } 00058 00059 EXTERN_C void ac_AppContext_set_controller(ac_AppContext* self, 00060 kr_Controller* kr) 00061 { 00062 self->kr = kr; 00063 } 00064 00065 //// Clear previous cached configuration. 00066 static void free_config_cache(ac_AppContext* self) 00067 { 00068 self->logdb_dir = NULL; 00069 FREE_Z(self->logdb_file, free); 00070 FREE_Z(self->log_uploads_dir, free); 00071 } 00072 00073 EXTERN_C gboolean ac_AppContext_configure(ac_AppContext* self, 00074 GError** error) 00075 { 00076 free_config_cache(self); 00077 00078 const gchar* database_dir = get_config_database_dir(self); 00079 00080 self->logdb_dir = database_dir; 00081 logg("log db stored in directory '%s'", self->logdb_dir); 00082 00083 { 00084 TRAP_OOM(goto fail, 00085 self->logdb_file = g_strdup_printf("%s%s%s", 00086 self->logdb_dir, 00087 DIR_SEP, 00088 LOGDB_BASENAME) 00089 ); 00090 } 00091 00092 { 00093 TRAP_OOM(goto fail, 00094 self->log_uploads_dir = g_strdup_printf("%s%suploads", 00095 database_dir, 00096 DIR_SEP) 00097 ); 00098 } 00099 00100 logg("uploads stored in directory '%s'", self->log_uploads_dir); 00101 return TRUE; 00102 00103 #if HAVE_TRAP_OOM 00104 fail: 00105 if (error) *error = gx_error_no_memory; 00106 return FALSE; 00107 #else 00108 (void)error; 00109 #endif 00110 } 00111 00112 EXTERN_C void ac_AppContext_destroy(ac_AppContext* self) 00113 { 00114 if (self) { 00115 WHEN_SYMBIAN(delete self->plat); 00116 free_config_cache(self); 00117 bb_Blackboard_destroy(self->blackboard); 00118 g_free(self); 00119 } 00120 } 00121 00122 // -------------------------------------------------- 00123 // global instance 00124 // -------------------------------------------------- 00125 00126 static ac_AppContext* iGlobal = NULL; // not owned 00127 00128 EXTERN_C void ac_set_global_AppContext(ac_AppContext* ac) 00129 { 00130 iGlobal = ac; 00131 } 00132 00133 // -------------------------------------------------- 00134 // common public API implementation 00135 // -------------------------------------------------- 00136 00137 EXTERN_C ac_AppContext* ac_get_global_AppContext() 00138 { 00139 return iGlobal; 00140 } 00141 00142 EXTERN_C kr_Controller* ac_Controller(ac_AppContext* self) 00143 { 00144 if (!self) return NULL; 00145 return self->kr; 00146 } 00147 00148 EXTERN_C LogDb* ac_LogDb(ac_AppContext* self) 00149 { 00150 if (!self || !(self->kr)) return NULL; 00151 return self->kr->log; 00152 } 00153 00154 EXTERN_C cf_RcFile* ac_RcFile(ac_AppContext* self) 00155 { 00156 if (!self || !(self->kr)) return NULL; 00157 return self->kr->rcFile; 00158 } 00159 00160 EXTERN_C ConfigDb* ac_ConfigDb(ac_AppContext* self) 00161 { 00162 if (!self || !(self->kr)) return NULL; 00163 return self->kr->configDb; 00164 } 00165 00166 EXTERN_C ac_Registry* ac_get_Registry(ac_AppContext* self) 00167 { 00168 return &self->registry; 00169 } 00170 00171 EXTERN_C bb_Blackboard* ac_get_Blackboard(ac_AppContext* self) 00172 { 00173 if (!self) return NULL; 00174 return self->blackboard; 00175 } 00176 00177 EXTERN_C up_Uploader* ac_get_Uploader(ac_AppContext* self) 00178 { 00179 #if __FEATURE_UPLOADER__ 00180 if (!self || !(self->kr)) return NULL; 00181 return self->kr->uploader; 00182 #else 00183 return NULL; 00184 #endif 00185 } 00186 00187 EXTERN_C rk_Remokon* ac_get_Remokon(ac_AppContext* self) 00188 { 00189 #if __FEATURE_REMOKON__ 00190 if (!self || !(self->kr)) return NULL; 00191 return self->kr->remokon; 00192 #else 00193 return NULL; 00194 #endif 00195 } 00196 00197 EXTERN_C const char* ac_get_logdb_file(ac_AppContext* self) 00198 { 00199 return self->logdb_file; 00200 } 00201 00202 EXTERN_C const char* ac_get_logdb_dir(ac_AppContext* self) 00203 { 00204 return self->logdb_dir; 00205 } 00206 00207 EXTERN_C const char* ac_get_log_uploads_dir(ac_AppContext* self) 00208 { 00209 return self->log_uploads_dir; 00210 } 00211 00212 // -------------------------------------------------- 00213 // Symbian public API implementation 00214 // -------------------------------------------------- 00215 00216 #if defined(__SYMBIAN32__) 00217 #if defined(__cplusplus) 00218 00219 void ac_AppContext_PlatInitAsyncL(ac_AppContext* self, 00220 MAppContextInitObserver& obs) 00221 { 00222 self->plat = CAppContext::NewL(self, obs); 00223 } 00224 00225 CAppContext& ac_AppContext_plat(ac_AppContext* self) 00226 { 00227 assert(self && self->plat); 00228 return *(self->plat); 00229 } 00230 00231 RFs& ac_Fs(ac_AppContext* self) 00232 { 00233 assert(self && self->plat); 00234 return self->plat->iImpl->iFs; 00235 } 00236 00237 CTelephony& ac_Telephony(ac_AppContext* self) 00238 { 00239 assert(self && self->plat); 00240 return *(self->plat->iImpl->iTelephony); 00241 } 00242 00243 #if __NEED_CONTACT_DATABASE__ 00244 CContactDatabase& ac_ContactDatabase(ac_AppContext* self) 00245 { 00246 assert(self && self->plat); 00247 return *(self->plat->iImpl->iContactDatabase); 00248 } 00249 #endif 00250 00251 const TPlatformVersion& ac_get_PlatformVersion(ac_AppContext* self) 00252 { 00253 assert(self && self->plat); 00254 return self->plat->iImpl->iPlatformVersion; 00255 } 00256 00257 #endif /* defined(__cplusplus) */ 00258 #endif /* __SYMBIAN32__ */ 00259 00260 /** 00261 00262 ac_app_context.cpp 00263 00264 Copyright 2009 Helsinki Institute for Information Technology (HIIT) 00265 and the authors. All rights reserved. 00266 00267 Authors: Tero Hasu <tero.hasu@hut.fi> 00268 00269 Permission is hereby granted, free of charge, to any person 00270 obtaining a copy of this software and associated documentation files 00271 (the "Software"), to deal in the Software without restriction, 00272 including without limitation the rights to use, copy, modify, merge, 00273 publish, distribute, sublicense, and/or sell copies of the Software, 00274 and to permit persons to whom the Software is furnished to do so, 00275 subject to the following conditions: 00276 00277 The above copyright notice and this permission notice shall be 00278 included in all copies or substantial portions of the Software. 00279 00280 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00281 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00282 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00283 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00284 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00285 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00286 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00287 SOFTWARE. 00288 00289 **/
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:51 2011 by Doxygen 1.6.1