Commit fe535663 authored by Romain Bertozzi's avatar Romain Bertozzi

dringadapter: use main thread for calls

This patchs ensures that the dringadapter uses the application's main
thread to make the calls to the daemon.

This is necessary because of the conception of the daemon.

It captures and registers the thread that initializes and starts it
and considers it as its main thread.
pjsip then also uses it. It does not tolerate any other threads than
the ones that it had already registered.

Using the app main thread guarantees that is remains the same during
the whole lifecyle.

Tuleap: #1423
Change-Id: Id03933f3f1a4c0428899af3593b35fc92a873e35
parent a933e793
......@@ -2,6 +2,7 @@
* Copyright (C) 2016 Savoir-faire Linux Inc.
*
* Author: Edric Ladent-Milaret <edric.ladent-milaret@savoirfairelinux.com>
* Author: Romain Bertozzi <romain.bertozzi@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -26,24 +27,73 @@
@implementation DRingAdapter
- (BOOL)initDaemon {
int flag = DRing::DRING_FLAG_CONSOLE_LOG | DRing::DRING_FLAG_DEBUG;
return DRing::init(static_cast<DRing::InitFlag>(flag));
if (![[NSThread currentThread] isMainThread]) {
__block bool success;
dispatch_sync(dispatch_get_main_queue(), ^{
success = [self initDaemonInternal];
});
return success;
}
else {
return [self initDaemonInternal];
}
}
- (BOOL) initDaemonInternal {
int flag = DRing::DRING_FLAG_CONSOLE_LOG | DRing::DRING_FLAG_DEBUG;
return DRing::init(static_cast<DRing::InitFlag>(flag));
}
- (BOOL)startDaemon {
return DRing::start();
if (![[NSThread currentThread] isMainThread]) {
__block bool success;
dispatch_sync(dispatch_get_main_queue(), ^{
success = [self startDaemonInternal];
});
return success;
}
else {
return [self startDaemonInternal];
}
}
- (BOOL)startDaemonInternal {
return DRing::start();
}
- (void)fini {
DRing::fini();
if (![[NSThread currentThread] isMainThread]) {
dispatch_sync(dispatch_get_main_queue(), ^{
DRing::fini();
});
}
else {
DRing::fini();
}
}
- (void)pollEvents {
DRing::pollEvents();
if (![[NSThread currentThread] isMainThread]) {
dispatch_sync(dispatch_get_main_queue(), ^{
DRing::pollEvents();
});
}
else {
DRing::pollEvents();
}
}
- (NSString*)getVersion {
return [NSString stringWithUTF8String:DRing::version()];
if (![[NSThread currentThread] isMainThread]) {
__block NSString *version;
dispatch_sync(dispatch_get_main_queue(), ^{
version = [NSString stringWithUTF8String:DRing::version()];
});
return version;
}
else {
return [NSString stringWithUTF8String:DRing::version()];
}
}
@end
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