Commit 835d54ad authored by Benjamin REIS's avatar Benjamin REIS
Browse files

factorize access to resource code

parent d0b5c85d
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment