示例#1
0
        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);
                throw StcErrorFactory.GetStcException(ret);
            }
            return(handle);
        }
示例#2
0
        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);
        }