Exemplo n.º 1
0
        public override bool QueryActiveEntry(UIntPtr sourceHandle,
                                              int index,
                                              ref QueryBuffer entryBuffer)
        {
            unsafe {
                UInt32  offset;
                UIntPtr type;

                fixed(byte *ptr = &(entryBuffer.GetBuffer()[0]))
                {
                    bool success = DiagnosisService.ReadActiveSourceItem(sourceHandle,
                                                                         index,
                                                                         &type,
                                                                         ptr,
                                                                         entryBuffer.GetBufferSize());


                    entryBuffer.Type = type;

                    // the active entries do not have any header

                    entryBuffer.UserOffset = 0;

                    return(success);
                }
            }
        }
Exemplo n.º 2
0
 static internal bool ActiveEntryDelegate(UIntPtr sourceHandle,
                                          int index,
                                          EventDescriptor descriptor,
                                          QueryBuffer entryBuffer,
                                          ref EnumerationContext context)
 {
     Console.Write("{0:d5}", index);
     descriptor.EnumerateFields(new QueryFieldDelegate(ActiveFieldDelegate), entryBuffer, ref context);
     Console.WriteLine("");
     return(true);
 }
Exemplo n.º 3
0
        public object GetProperty(QueryBuffer buffer, string propertyName)
        {
            FieldDescriptor fieldDescriptor = LookupTable[propertyName] as FieldDescriptor;

            if (fieldDescriptor == null)
            {
                return(null);
            }

            return(fieldDescriptor.GetObject(buffer));
        }
Exemplo n.º 4
0
        static internal bool EntryDelegate(EventDescriptor currentEntry,
                                           QueryBuffer buffer,
                                           ref EnumerationContext context)
        {
            if ((currentEntry != null) && (buffer != null))
            {
                currentEntry.EnumerateFields(new QueryFieldDelegate(fieldDelegate), buffer, ref context);
            }

            return(true);
        }
Exemplo n.º 5
0
        public object GetObject(QueryBuffer buffer)
        {
            unsafe {
                switch (Type)
                {
                case DataType.__int8:
                case DataType.__uint8:
                    fixed(byte *ptrInt = &(buffer.GetBuffer()[buffer.UserOffset + Offset]))
                    {
                        return(*(byte *)ptrInt);
                    }

                case DataType.__int16:
                case DataType.__uint16:
                    fixed(byte *ptrInt = &(buffer.GetBuffer()[buffer.UserOffset + Offset]))
                    {
                        return(*(ushort *)ptrInt);
                    }

                case DataType.__int32:
                case DataType.__uint32:
                    fixed(byte *ptrInt = &(buffer.GetBuffer()[buffer.UserOffset + Offset]))
                    {
                        return(*(Int32 *)ptrInt);
                    }

                case DataType.__UIntPtr:
                    fixed(byte *ptrInt = &(buffer.GetBuffer()[buffer.UserOffset + Offset]))
                    {
                        return(*(UIntPtr *)ptrInt);
                    }

                case DataType.__IntPtr:
                    fixed(byte *ptrInt = &(buffer.GetBuffer()[buffer.UserOffset + Offset]))
                    {
                        return(*(IntPtr *)ptrInt);
                    }

                default:
                    DebugStub.WriteLine("Unknown field type");
                    break;
                }
            }

            return(null);
        }
Exemplo n.º 6
0
        public bool Initialize(EventingStorage storage,
                               bool forward)
        {
            if (EntryBuffer == null)
            {
                EntryBuffer = new QueryBuffer(256);
                if ((EntryBuffer == null) || (EntryBuffer.GetBuffer() == null))
                {
                    return(false);
                }
            }

            //  Cleanup for the previous states.

            if (QueryHandle != 0)
            {
                QueryStorage.DeleteQueryView(QueryHandle);
                QueryHandle  = 0;
                QueryStorage = null;
            }

            //  Initialize the new query states

            QueryStorage = storage;

            if (QueryStorage == null)
            {
                return(false);
            }

            QueryHandle = QueryStorage.CreateQueryView(forward);

            if (QueryHandle == 0)
            {
                QueryStorage = null;

                return(false);
            }

            return(true);
        }
Exemplo n.º 7
0
        public override UIntPtr GetNextEntry(UIntPtr queryHandle,
                                             ref QueryBuffer entryBuffer)
        {
            unsafe {
                UInt32  offset;
                UIntPtr type;

                fixed(byte *ptr = &(entryBuffer.GetBuffer()[0]))
                {
                    entryBuffer.EntryHandle = DiagnosisService.GetNextEntry(queryHandle,
                                                                            &type,
                                                                            &offset,
                                                                            ptr,
                                                                            entryBuffer.GetBufferSize());

                    entryBuffer.Type       = type;
                    entryBuffer.UserOffset = offset;

                    return(entryBuffer.EntryHandle);
                }
            }
        }
Exemplo n.º 8
0
        public void EnumerateFields(QueryFieldDelegate fieldDelegate,
                                    QueryBuffer buffer,
                                    ref EnumerationContext context)
        {
            for (int i = 0; i < Fields.Count; i++)
            {
                FieldDescriptor fieldDescriptor = Fields[i] as FieldDescriptor;

                if (buffer != null)
                {
                    if (!fieldDelegate(fieldDescriptor, fieldDescriptor.GetObject(buffer), ref context))
                    {
                        break;
                    }
                }
                else
                {
                    if (!fieldDelegate(fieldDescriptor, null, ref context))
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 9
0
 public abstract UIntPtr GetNextEntry(UIntPtr queryHandle,
                                      ref QueryBuffer entryBuffer);
Exemplo n.º 10
0
        public virtual void EnumerateActiveSources(QuerySourceDelegate sourceDelegate,
                                                   ActiveSourceEntryDelegate activeEntryDelegate,
                                                   QueryEntryDelegate entryDelegate,
                                                   ushort maxEntrySize,
                                                   ref EnumerationContext context)
        {
            if (maxEntrySize == 0)
            {
                maxEntrySize = DefaultEntrySize;
            }

            //  Create a temporary buffer to store the temporary query information

            QueryBuffer entryBuffer = new QueryBuffer(maxEntrySize);

            if ((entryBuffer == null) || (sourceDelegate == null))
            {
                return;
            }

            //  Prepare to query the controller for the source list. We just pick up an number
            //  that would represent the limit for most common cases as the initial guess.

            int currentSize = 100;

            UIntPtr [] sourceArray = new UIntPtr[currentSize];

            if (sourceArray != null)
            {
                //  Query the controller for the actual source list

                int sourceCount = QuerySourcesList(sourceArray, currentSize);

                //
                //  The array was not large enough, attempt again with the new size

                while (sourceCount > currentSize)
                {
                    sourceArray = new UIntPtr[sourceCount];
                    sourceCount = QuerySourcesList(sourceArray, currentSize);
                }

                //
                //  We sucessfully received an array of entries. We walk them and build the
                //  required information
                //

                for (int i = 0; i < sourceCount; i++)
                {
                    UIntPtr sourceHandle  = sourceArray[i];
                    UIntPtr storageHandle = 0;
                    UIntPtr eventType     = 0;
                    UInt16  count         = 0;
                    string  bufferName    = "";

                    if (GetSourceInformation(sourceHandle,
                                             ref storageHandle,
                                             ref eventType,
                                             ref count,
                                             ref bufferName))
                    {
                        if (storageHandle == 0)
                        {
                            //
                            //  This is an active source. The eventing has no information
                            //  about the storage, it has instead information about the
                            //  types of events handled by this source
                            //

                            EventDescriptor descriptor = QuerySession.GetEventDescriptor(this,
                                                                                         eventType);

                            if (descriptor != null)
                            {
                                //  The source is valid, call the delegate with the appropriate
                                //  arguments filled in
                                // TODO: Also retrieve the control flags status


                                if (!sourceDelegate(sourceHandle,
                                                    storageHandle,
                                                    eventType,
                                                    count,
                                                    bufferName,
                                                    descriptor,
                                                    ref context))
                                {
                                    break;
                                }

                                if (entryDelegate != null)
                                {
                                    //  The caller also provided an entry delegate. We need in that
                                    //  case to also enumerate all entries from the active source

                                    for (int index = 0; index < count; index++)
                                    {
                                        if (!QueryActiveEntry(sourceHandle,
                                                              index,
                                                              ref entryBuffer))
                                        {
                                            break;
                                        }

                                        activeEntryDelegate(sourceHandle,
                                                            index,
                                                            descriptor,
                                                            entryBuffer,
                                                            ref context);
                                    }
                                }
                            }
                        }
                        else
                        {
                            //  This source has an associated storage. Enumerate the entries from
                            //  the storage
                            // TODO: we might also want to filter the sources inside the storage
                            // since multiple sources can share the same storage

                            if (!sourceDelegate(sourceHandle,
                                                storageHandle,
                                                eventType,
                                                count,
                                                bufferName,
                                                null,
                                                ref context))
                            {
                                break;
                            }

                            EventingStorage storage = OpenStorage(storageHandle);

                            if (storage != null)
                            {
                                // Instantiate a query session for the storage and
                                // enumerate the entries passing the provided delegate

                                QuerySession query = new QuerySession();

                                if ((query != null) && (context != null) &&
                                    query.Initialize(storage, false))
                                {
                                    query.EnumerateEntries(entryDelegate, ref context);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
 public virtual bool QueryActiveEntry(UIntPtr sourceHandle,
                                      int index,
                                      ref QueryBuffer entryBuffer)
 {
     return(false);
 }