Your app can subscribe to network quality QoS evaluation data. The device will periodically send updates or notify you when QoS changes. The returned QoS information includes the link type, uplink and downlink real-time air-interface bandwidth and rates, and RTT.
For details about the APIs, please refer to API Reference.
| API | Description |
|---|---|
| int32_t HMS_NetworkBoost_RegisterNetQosCallback(HMS_NetworkBoost_NetQosChange callback, uint32_t* callbackId) | Registers the QoS information change callback. |
| int32_t HMS_NetworkBoost_UnregisterNetQosCallback(uint32_t callbackId) | Deregisters the QoS information change callback. |
Import the Network Boost Kit module.
#include "NetworkBoostKit/network_boost_quality.h" #include <cstdio>
Add the following library to the CMakeLists.txt file. For details, please refer to Preparations for C API Development.
libnetwork_boost.so
Register the network quality assessment information callback.
uint32_t callbackId = 0;
void onNetworkQoSChanged(NetworkBoost_NetworkQosArray *msg)
{
for (int32_t i = 0; i < msg->pathNum; i++) {
// Callback information processing.
printf("Data link type: %d\n", msg->networkQos[i].pathType);
printf("Uplink bandwidth of this data link type: %ld\n", msg->networkQos[i].linkUpBandwidth);
printf("Downlink bandwidth of this data link type: %ld\n", msg->networkQos[i].linkDownBandwidth);
// The unit is bit/s. You can divide the value by 8 to convert it to byte/s.
printf("Uplink rate of this data link type: %ld\n", msg->networkQos[i].linkUpRate);
// The unit is bit/s. You can divide the value by 8 to convert it to byte/s.
printf("Downlink rate of this data link type: %ld\n", msg->networkQos[i].linkDownRate);
// The real-time rate is the sum of the uplink and downlink rates.
printf("Real-time rate of this data link type (in byte/s): %ld\n", (msg->networkQos[i].linkUpRate + msg->networkQos[i].linkDownRate) / 8);
printf("RTT of this data link type: %d\n", msg->networkQos[i].rttMs);
printf("Uplink transmission air-interface buffer delay of this data link type: %d\n", msg->networkQos[i].linkUpBufferDelayMs);
}
}
int32_t RegisterNetQualityCallback()
{
HMS_NetworkBoost_NetQosChange callback;
callback = onNetworkQoSChanged;
// Register a callback and obtain the callback ID. The ID is returned by the system and will be used for subsequent deregistration.
int32_t ret = HMS_NetworkBoost_RegisterNetQosCallback(callback, &callbackId);
printf("Result of registering the network quality assessment information callback: %d, Id:%d\n", ret, callbackId);
return ret;
} Deregister the network quality assessment information callback after your app process ends.
int32_t UnregisterNetQualityCallback()
{
// Deregister the callback using the callback ID obtained during registration.
int32_t ret = HMS_NetworkBoost_UnregisterNetQosCallback(callbackId);
printf("Result of deregistering the network quality assessment information callback: %d\n", ret);
return ret;
}