mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
factorize access to resource code
This commit is contained in:
parent
d0b5c85d13
commit
835d54adde
2 changed files with 33 additions and 18 deletions
|
|
@ -29,10 +29,6 @@
|
|||
#include "object/object-p.h"
|
||||
|
||||
#include "cpim-parser.h"
|
||||
#ifdef __APPLE__
|
||||
#include <TargetConditionals.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
#define CPIM_GRAMMAR "cpim_grammar"
|
||||
|
||||
|
|
@ -583,18 +579,7 @@ public:
|
|||
|
||||
Cpim::Parser::Parser () : Singleton(*new ParserPrivate) {
|
||||
L_D();
|
||||
#if TARGET_OS_IPHONE
|
||||
CFBundleRef bundle = CFBundleGetBundleWithIdentifier(CFSTR("org.linphone.linphone"));
|
||||
CFURLRef grammarUrl = CFBundleCopyResourceURL(bundle, CFSTR(CPIM_GRAMMAR), nullptr, nullptr);
|
||||
CFStringRef grammarPath = CFURLCopyFileSystemPath(grammarUrl, kCFURLPOSIXPathStyle);
|
||||
CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
|
||||
const char *path = CFStringGetCStringPtr(grammarPath, encodingMethod);
|
||||
CFRelease(grammarUrl);
|
||||
CFRelease(grammarPath);
|
||||
#else
|
||||
const char *path = CPIM_GRAMMAR;
|
||||
#endif
|
||||
d->grammar = belr::GrammarLoader::get().load(path);
|
||||
d->grammar = belr::GrammarLoader::get().load(CPIM_GRAMMAR);
|
||||
if (!d->grammar)
|
||||
lFatal() << "Unable to load CPIM grammar.";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#ifdef __APPLE__
|
||||
#include "TargetConditionals.h"
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
#include <belr/grammarbuilder.h>
|
||||
|
||||
#include "linphone/utils/general.h"
|
||||
#include "linphone/utils/utils.h"
|
||||
|
||||
|
|
@ -56,6 +59,7 @@ public:
|
|||
private:
|
||||
void bgTaskTimeout ();
|
||||
static void sBgTaskTimeout (void *data);
|
||||
static const char *directoryForResource (CFStringRef framework, CFStringRef resource);
|
||||
|
||||
long int mCpuLockTaskId;
|
||||
int mCpuLockCount;
|
||||
|
|
@ -66,7 +70,20 @@ private:
|
|||
IosPlatformHelpers::IosPlatformHelpers (LinphoneCore *lc, void *system_context) : PlatformHelpers(lc) {
|
||||
mCpuLockCount = 0;
|
||||
mCpuLockTaskId = 0;
|
||||
lInfo() << "IosPlatformHelpers is fully initialised";
|
||||
|
||||
const char *cpimPath = directoryForResource(CFSTR("org.linphone.linphone"), CFSTR("cpim_grammar"));
|
||||
const char *vcardPath = directoryForResource(CFSTR("org.linphone.belcard"), CFSTR("vcard_grammar"));
|
||||
if (cpimPath)
|
||||
belr::GrammarLoader::get().addPath(cpimPath);
|
||||
else
|
||||
lError() << "IosPlatformHelpers did not find cpim grammar resource directory...";
|
||||
|
||||
if (vcardPath)
|
||||
belr::GrammarLoader::get().addPath(vcardPath);
|
||||
else
|
||||
lError() << "IosPlatformHelpers did not find vcard grammar resource directory...";
|
||||
|
||||
lInfo() << "IosPlatformHelpers is fully initialised.";
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -108,6 +125,19 @@ void IosPlatformHelpers::releaseCpuLock () {
|
|||
mCpuLockTaskId = 0;
|
||||
}
|
||||
|
||||
const char *IosPlatformHelpers::directoryForResource (CFStringRef framework, CFStringRef resource) {
|
||||
CFBundleRef bundle = CFBundleGetBundleWithIdentifier(framework);
|
||||
CFURLRef grammarUrl = CFBundleCopyResourceURL(bundle, resource, nullptr, nullptr);
|
||||
CFURLRef grammarUrlDirectory = CFURLCreateCopyDeletingLastPathComponent(nullptr, grammarUrl);
|
||||
CFStringRef grammarPath = CFURLCopyFileSystemPath(grammarUrlDirectory, kCFURLPOSIXPathStyle);
|
||||
CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
|
||||
const char *path = CFStringGetCStringPtr(grammarPath, encodingMethod);
|
||||
CFRelease(grammarUrl);
|
||||
CFRelease(grammarPath);
|
||||
CFRelease(grammarUrlDirectory);
|
||||
return path;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
PlatformHelpers *createIosPlatformHelpers (LinphoneCore *lc, void *system_context) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue