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

Q: purpose of "server processing emits" code in example #271

Open
lure23 opened this issue Jan 25, 2025 · 1 comment
Open

Q: purpose of "server processing emits" code in example #271

lure23 opened this issue Jan 25, 2025 · 1 comment

Comments

@lure23
Copy link
Contributor

lure23 commented Jan 25, 2025

I've never quite understood the purpose of this code section in the examples.

                match data.process(server).await {
                    // Server processing emits
                    Ok(Some(GattEvent::Read(event))) => {
                        if event.handle() == level.handle {
                            let value = server.get(&level);
                            info!("[gatt] Read Event to Level Characteristic: {:?}", value);
                        }
                    }
                    Ok(Some(GattEvent::Write(event))) => {
                        if event.handle() == level.handle {
                            info!("[gatt] Write Event to Level Characteristic: {:?}", event.data());
                        }
                    }
                    Ok(_) => {}
                    Err(e) => {
                        warn!("[gatt] error processing event: {:?}", e);
                    }
                }

It only logs stuff. When would I enable such in my application, if reads, writes etc. happen anyways within the data.process(server) call?

The problem I have with this is that it ties the level.handle (a particular service's detail) to the implementation of the server's event loop. I don't think that's necessary, and removing this code in my own app allows encapsulation of service characteristics to be private.

@lulf
Copy link
Member

lulf commented Jan 25, 2025

The write doesnt happen in the process call, but when the event is accept()ed, at which point it will return a reply that can be sent explicitly. The example code hides this since it relies on the drop implementation. It should probably show the full accept() and send() dance

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

No branches or pull requests

2 participants