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 namespace Libroot { 16 17 18 LocaleBackend* gLocaleBackend = NULL; 19 20 21 static LocaleDataBridge sLocaleDataBridge; 22 static pthread_once_t sBackendInitOnce = PTHREAD_ONCE_INIT; 23 24 25 static void 26 LoadBackend() 27 { 28 void* imageHandle = dlopen("libroot-addon-icu.so", RTLD_LAZY); 29 if (imageHandle == NULL) 30 return; 31 32 typedef LocaleBackend* (*symbolType)(); 33 symbolType createInstanceFunc 34 = (symbolType)dlsym(imageHandle, "CreateInstance"); 35 if (createInstanceFunc == NULL) { 36 dlclose(imageHandle); 37 return; 38 } 39 40 gLocaleBackend = createInstanceFunc(); 41 } 42 43 44 LocaleBackend::LocaleBackend() 45 { 46 } 47 48 49 LocaleBackend::~LocaleBackend() 50 { 51 } 52 53 54 status_t 55 LocaleBackend::LoadBackend() 56 { 57 if (gLocaleBackend == NULL) { 58 pthread_once(&sBackendInitOnce, &BPrivate::Libroot::LoadBackend); 59 if (gLocaleBackend != NULL) 60 gLocaleBackend->Initialize(&sLocaleDataBridge); 61 } 62 63 return gLocaleBackend != NULL ? B_OK : B_ERROR; 64 } 65 66 67 } // namespace Libroot 68 } // namespace BPrivate 69