internal Task <IEnumerable <NetworkStatistics> > GetStatisticsAsync(StatisticsFilter filter) { TaskCompletionSource <IEnumerable <NetworkStatistics> > task = new TaskCompletionSource <IEnumerable <NetworkStatistics> >(); IntPtr id; lock (_getAllStatsCb_map) { id = (IntPtr)_requestAllId++; _getAllStatsCb_map[id] = (int result, IntPtr infoList, IntPtr key) => { if (result != (int)StcError.None) { Log.Error(Globals.LogTag, "GetAllStats failed, Error - " + (StcError)result); task.SetException(StcErrorFactory.GetStcException(result)); } List <NetworkStatistics> statsList = new List <NetworkStatistics>(); Interop.Stc.StatsInfoCallback foreachAllStatsCb = (int resultTemp, IntPtr info, IntPtr userDataTemp) => { if (resultTemp != (int)StcError.None) { Log.Error(Globals.LogTag, "ForeachAllStats failed, Error - " + (StcError)resultTemp); task.SetException(StcErrorFactory.GetStcException(resultTemp)); } Interop.Stc.SafeStatsHandle cloned; int retValue = Interop.Stc.Info.StatsClone(info, out cloned); if (retValue != (int)StcError.None) { Log.Error(Globals.LogTag, "StatsClone() failed , Error - " + (StcError)retValue); task.SetException(StcErrorFactory.GetStcException(retValue)); } statsList.Add(new NetworkStatistics(cloned)); return(CallbackRet.Continue); }; int retTemp = Interop.Stc.ForeachAllStats(infoList, foreachAllStatsCb, IntPtr.Zero); if (retTemp != (int)StcError.None) { Log.Error(Globals.LogTag, "foreachAllStatus() failed , Error - " + (StcError)retTemp); task.SetException(StcErrorFactory.GetStcException(retTemp)); } else { task.SetResult(statsList); } lock (_getAllStatsCb_map) { _getAllStatsCb_map.Remove(key); } }; } using (var filterHandle = filter.ConvertToNativeFilter()) { int ret = Interop.Stc.GetAllStats(GetSafeHandle(), filterHandle, _getAllStatsCb_map[id], id); if (ret != (int)StcError.None) { Log.Error(Globals.LogTag, "GetAllStatus() failed , Error - " + (StcError)ret); throw StcErrorFactory.GetStcException(ret); } } return(task.Task); }
/// <summary> /// Gets statistics information of applications that used network in between specified timestamps and matches the given StatisticsFilter, asynchronously. /// </summary> /// <since_tizen> 6 </since_tizen> /// <param name="filter"> The StatisticsFilter object.</param> /// <returns>A list of the NetworkStatistics objects.</returns> /// <feature>http://tizen.org/feature/network.traffic_control</feature> /// <privilege>http://tizen.org/privilege/network.get</privilege> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> /// <exception cref="ArgumentException">Thrown when the method is provided with invalid argument.</exception> /// <exception cref="NotSupportedException">Thrown when the Stc is not supported.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception> public static Task <IEnumerable <NetworkStatistics> > GetStatisticsAsync(StatisticsFilter filter) { return(StcManagerImpl.Instance.GetStatisticsAsync(filter)); }