1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
45use crate::prelude_internal::*;
6use std::mem::transmute;
78/// DnsUpstream callback from platform to OT
9pub trait DnsUpstream {
10/// Update DNS upstream query done
11fn plat_dns_upstream_query_done(
12&self,
13 query_context: &PlatDnsUpstreamQuery,
14 response: ot::Box<Message<'_>>,
15 );
16}
1718impl<T: DnsUpstream + ot::Boxable> DnsUpstream for ot::Box<T> {
19fn plat_dns_upstream_query_done(
20&self,
21 query_context: &PlatDnsUpstreamQuery,
22 response: ot::Box<Message<'_>>,
23 ) {
24self.as_ref().plat_dns_upstream_query_done(query_context, response)
25 }
26}
2728// SAFETY: this call will be called only once for each &mut PlatDnsUpstreamQuery passed to lowpan,
29// and the reference will be removed right after the call. It is ok to transmute it to
30// mutable reference.
31#[allow(clippy::useless_transmute)]
32unsafe fn dns_upstream_query_context_get_mut(
33 original: &PlatDnsUpstreamQuery,
34) -> *mut otPlatDnsUpstreamQuery {
35 transmute(original)
36}
3738impl DnsUpstream for Instance {
39fn plat_dns_upstream_query_done(
40&self,
41 query_context: &PlatDnsUpstreamQuery,
42 response: ot::Box<Message<'_>>,
43 ) {
44unsafe {
45 otPlatDnsUpstreamQueryDone(
46self.as_ot_ptr(),
47 dns_upstream_query_context_get_mut(query_context),
48 response.take_ot_ptr(),
49 );
50 }
51 }
52}