1 /* 2 * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "LocaleBackend.h" 8 9 #include <dlfcn.h> 10 #include <pthread.h> 11 #include <string.h> 12 13 14 namespace BPrivate { 15 16 17 LocaleBackend* gLocaleBackend = NULL; 18 19 20 static LocaleDataBridge sLocaleDataBridge; 21 static pthread_once_t sBackendInitOnce = PTHREAD_ONCE_INIT; 22 23 24 static void 25 LoadBackend() 26 { 27 void* imageHandle = dlopen("libroot-addon-icu.so", RTLD_LAZY); 28 if (imageHandle == NULL) 29 return; 30 31 typedef LocaleBackend* (*symbolType)(); 32 symbolType createInstanceFunc 33 = (symbolType)dlsym(imageHandle, "CreateInstance"); 34 if (createInstanceFunc == NULL) 35 return; 36 37 gLocaleBackend = createInstanceFunc(); 38 } 39 40 41 LocaleBackend::LocaleBackend() 42 { 43 } 44 45 46 LocaleBackend::~LocaleBackend() 47 { 48 } 49 50 51 status_t 52 LocaleBackend::LoadBackend() 53 { 54 if (gLocaleBackend == NULL) { 55 pthread_once(&sBackendInitOnce, &BPrivate::LoadBackend); 56 if (gLocaleBackend != NULL) 57 gLocaleBackend->Initialize(&sLocaleDataBridge); 58 } 59 60 return gLocaleBackend != NULL ? B_OK : B_ERROR; 61 } 62 63 64 } // namespace BPrivate 65