Skip to content

Commit

Permalink
Next attempt on issue #404
Browse files Browse the repository at this point in the history
  • Loading branch information
eelcocramer committed May 27, 2022
1 parent 1ae137a commit e738fcb
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
56 changes: 55 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/macos/BluetoothWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ BluetoothDeviceResources *res;
NSLock *writeLock;
IOReturn writeResult;
NSTimer *keepAliveTimer;
BOOL runLoopIsStopped;
}

+ (id)getInstance: (NSString *) address;
Expand Down
16 changes: 14 additions & 2 deletions src/macos/BluetoothWorker.mm
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ - (void)rfcommChannelWriteComplete:(IOBluetoothRFCOMMChannel*)rfcommChannel refc
- (void) inquireWithPipe: (pipe_t *)pipe
{
@synchronized(self) {
runLoopIsStopped = YES;
inquiryProducer = pipe_producer_new(pipe);
dispatch_async(worker_queue, ^{
[self inquiryTask];
Expand All @@ -270,11 +271,20 @@ - (void) inquireWithPipe: (pipe_t *)pipe
/** Worker task to the the inquiry */
- (void) inquiryTask
{
@autoreleasepool {
IOBluetoothDeviceInquiry *bdi = [IOBluetoothDeviceInquiry inquiryWithDelegate:self];
// bdi.inquiryLength = 30;
bdi.inquiryLength = 10;
[bdi start];
fprintf(stderr,"before: %d\n", runLoopIsStopped);
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
while ( runLoopIsStopped) {
NSDate *date = [NSDate distantFuture];
[runLoop runMode:NSDefaultRunLoopMode beforeDate:date];
}
fprintf(stderr,"after\n");
// [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 31]];
// [bdi stop];
[bdi stop];
}
}

/** Get the RFCOMM channel for a given device */
Expand Down Expand Up @@ -361,12 +371,14 @@ - (void)rfcommChannelClosed:(IOBluetoothRFCOMMChannel*)rfcommChannel
/** Called when the device inquiry completes */
- (void) deviceInquiryComplete: (IOBluetoothDeviceInquiry *) sender error: (IOReturn) error aborted: (BOOL) aborted
{
fprintf(stderr, "complete with aborted = %d\n", aborted);
@synchronized(self) {
if (inquiryProducer != NULL) {
// free the producer so the main thread is signaled that the inquiry has been completed.
pipe_producer_free(inquiryProducer);
inquiryProducer = NULL;
}
runLoopIsStopped = NO;
}
}

Expand Down

0 comments on commit e738fcb

Please sign in to comment.