internal SafeStcHandle Initialize() { SafeStcHandle handle; int ret = Interop.Stc.Initialize(out handle); if (ret != (int)StcError.None) { Log.Error(Globals.LogTag, "Failed to initialize Stc, Error - " + (StcError)ret); StcErrorFactory.ThrowStcException(ret); } return(handle); }
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(new InvalidOperationException("Error occurs during GetAllStats(), " + (StcError)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(new InvalidOperationException("Error occurs during ForeachAllStats(), " + (StcError)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(new InvalidOperationException("Error occurs during StatsClone(), " + (StcError)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(new InvalidOperationException("Error occurs during foreachAllStatus(), " + (StcError)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); StcErrorFactory.ThrowStcException(ret); } } return(task.Task); }