Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a single CHIPDeviceController for all the views in the iOS app. #1004

Merged
merged 1 commit into from
Jun 4, 2020
Merged

Use a single CHIPDeviceController for all the views in the iOS app. #1004

merged 1 commit into from
Jun 4, 2020

Conversation

bzbarsky-apple
Copy link
Contributor

We don't want to be reinitializing the CHIP stack as the user
navigates through the app.

This also fixes issues where we'd have multiple CHIPDeviceController
instances live at the same time, which would bind to the same
low-level socket and confuse the networking layer into delivering
response notifications to the wrong CHIPDeviceController.

The dealloc block for CHIPDeviceController was removed because now we
always keep it alive in a static, so it would never run anyway.

Problem

We create a new CHIPDeviceController every time we switch views in the iOS app.

Summary of Changes

Have a single, static, CHIPDeviceController that all the views share.

fixes #984

@bzbarsky-apple bzbarsky-apple self-assigned this Jun 4, 2020
@property (readonly) ControllerOnMessageBlock onMessageHandler;
@property (readonly) ControllerOnErrorBlock onErrorHandler;
@property dispatch_queue_t appCallbackQueue;
@property ControllerOnMessageBlock onMessageHandler;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest being explicit about the property attributes.
Helps people who are new to objc from having to remember the default attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, will do.

*
* @param[in] onError the block to call when there is a network error.
*/
- (void)registerCallbacks:(dispatch_queue_t)appCallbackQueue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering this is a sharedController the expectation is that there will be multiple clients for this class.
However, the registerCallbacks seems to allow only one client at a time as a new client registering with CHIPDeviceController will overwrite any existing callbacks.

I would change this API to take in an error block and a completion block as part of the sendMessage API.
Internally this class will maintain a map of message ID to these blocks. And then call the appropriate block when the message sends or errors out.
Essentially move this API to a model where we take send and error callbacks in the message send API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the update to address @sagar-apple's comments plus #1007 more or less addresses this.

We don't want to be reinitializing the CHIP stack as the user
navigates through the app.

This also fixes issues where we'd have multiple CHIPDeviceController
instances live at the same time, which would bind to the same
low-level socket and confuse the networking layer into delivering
response notifications to the wrong CHIPDeviceController.

The dealloc block for CHIPDeviceController was removed because now we
always keep it alive in a static, so it would never run anyway.
@sagar-apple
Copy link
Contributor

LGTM

@woody-apple woody-apple merged commit e0c9ff6 into project-chip:master Jun 4, 2020
@bzbarsky-apple bzbarsky-apple deleted the make-device-controller-singleton branch June 5, 2020 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iOS echo app screen does not work the second time
6 participants