public override bool RegisterEnumValue(UIntPtr eventHandle,
                                               string valueName,
                                               UInt64 value,
                                               byte flagChar)
        {
            UIntPtr field = RegisterValueDescriptorInternal(eventHandle,
                                                            valueName,
                                                            value,
                                                            flagChar);

            while (field == 0)
            {
                Lock.AcquireMutex();
                if (!TypesRepository.AddBuffer(BUFFER_EXPANSION_SIZE))
                {
                    Lock.ReleaseMutex();
                    return(false);
                }

                Lock.ReleaseMutex();
                field = RegisterValueDescriptorInternal(eventHandle,
                                                        valueName,
                                                        value,
                                                        flagChar);
            }

            return(true);
        }
        public unsafe bool ReadActiveSourceItem(UIntPtr sourceHandle,
                                                int item,
                                                UIntPtr *type,
                                                byte *buffer,
                                                UInt16 bufferSize)
        {
            Lock.AcquireMutex();

            object source = SourcesHandleTable[sourceHandle];

            if (source != null)
            {
                ActiveSource activeSource = source as ActiveSource;

                if (activeSource != null)
                {
                    bool success = activeSource.GetActiveEntry(item, type, buffer, bufferSize);
                    Lock.ReleaseMutex();

                    return(success);
                }
            }

            Lock.ReleaseMutex();
            return(false);
        }
        //
        //  Enumeration registration support
        //

        public override bool RegisterEnum(string enumName,
                                          UInt16 type,
                                          ref UIntPtr eventHandle)
        {
            Lock.AcquireMutex();
            object o = EventTable[enumName];

            if (o != null)
            {
                // Type already registered. Return the existing value
                eventHandle = (UIntPtr)o;
                Lock.ReleaseMutex();
                return(false);
            }

            eventHandle = RegisterEnumDescriptorInternal(enumName, type);

            while (eventHandle == 0)
            {
                if (!TypesRepository.AddBuffer(BUFFER_EXPANSION_SIZE))
                {
                    Lock.ReleaseMutex();
                    return(false);
                }

                eventHandle = RegisterEnumDescriptorInternal(enumName, type);
            }

            EventTable[enumName] = eventHandle;

            Lock.ReleaseMutex();

            return(true);
        }
        public override bool RegisterEventGenericField(UIntPtr eventHandle,
                                                       string fieldName,
                                                       UInt16 offset,
                                                       UInt16 size,
                                                       UIntPtr fieldTypeHandle)
        {
            UIntPtr field = RegisterEventGenericFieldInternal(eventHandle,
                                                              fieldName,
                                                              offset,
                                                              size,
                                                              fieldTypeHandle);

            while (field == 0)
            {
                Lock.AcquireMutex();
                if (!TypesRepository.AddBuffer(BUFFER_EXPANSION_SIZE))
                {
                    Lock.ReleaseMutex();
                    return(false);
                }

                Lock.ReleaseMutex();

                field = RegisterEventGenericFieldInternal(eventHandle,
                                                          fieldName,
                                                          offset,
                                                          size,
                                                          fieldTypeHandle);
            }

            return(true);
        }
        //  Storage registration routines

        public bool RegisterStorage(EventingStorage Storage)
        {
            Lock.AcquireMutex();
            bool success = RegisterStorageImpl(Storage.GetHandle());

            Lock.ReleaseMutex();
            return(success);
        }
 public void UnRegisterStorage(EventingStorage Storage)
 {
     if (!Controller.Finalized)
     {
         Lock.AcquireMutex();
         UnRegisterStorageImpl(Storage.GetHandle());
         Lock.ReleaseMutex();
     }
 }
        public override void UnRegisterController(int processId)
        {
            Lock.AcquireMutex();
            ProcessContext ctx = ProcessContext.GetProcessContext(processId);

            if (ctx != null)
            {
                ctx.Delete();
            }

            Lock.ReleaseMutex();
        }
        public bool RegisterControllerImpl(UIntPtr controllerHandle, UIntPtr context)
        {
            ProcessContext ctx = new ProcessContext();

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

            Lock.AcquireMutex();
            bool success = ctx.Initialize(controllerHandle, context);

            Lock.ReleaseMutex();

            return(success);
        }
        public override void UnRegisterSource(EventSource source)
        {
            if (!Controller.Finalized)
            {
                Lock.AcquireMutex();

                if (source.SourceHandle != 0)
                {
                    SourcesHandleTable.Remove(source.SourceHandle);
                    UnRegisterSourceImpl(source.SourceHandle);

                    source.SourceHandle = 0;
                }
                Lock.ReleaseMutex();
            }
        }
        public override int QueryEventTypeList(UIntPtr [] buffer, int size)
        {
            int i = 0;

            Lock.AcquireMutex();

            IDictionaryEnumerator enumerator = EventTable.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (i < size)
                {
                    UIntPtr eventHandle = (UIntPtr)enumerator.Value;
                    buffer[i++] = eventHandle;
                }
            }

            Lock.ReleaseMutex();
            return(i);
        }
        public override int QuerySourcesList(UIntPtr [] buffer, int size)
        {
            int i = 0;

            Lock.AcquireMutex();

            IDictionaryEnumerator enumerator = SourcesHandleTable.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (i < size)
                {
                    EventSource source = enumerator.Value as EventSource;
                    buffer[i++] = source.SourceHandle;
                }
            }

            Lock.ReleaseMutex();
            return(i);
        }
        public override bool GetSourceInformation(UIntPtr sourceHandle,
                                                  ref UIntPtr storageHandle,
                                                  ref UIntPtr eventType,
                                                  ref UInt16 count,
                                                  ref string bufferName)
        {
            Lock.AcquireMutex();

            EventSource source = SourcesHandleTable[sourceHandle] as EventSource;

            if (source != null)
            {
                bufferName = source.SourceName;
                ActiveSource activeSource = source as ActiveSource;

                if (activeSource != null)
                {
                    storageHandle = 0;
                    eventType     = activeSource.EventTypeHandle;
                    count         = activeSource.Count;
                }
                else
                {
                    storageHandle = source.Storage.GetHandle();
                    eventType     = 0;
                    count         = 0;
                }

                Lock.ReleaseMutex();

                return(true);
            }

            Lock.ReleaseMutex();
            return(false);
        }
        // Eventing source support routines

        public override bool RegisterSource(EventSource source)
        {
            // Sanity check against double registration
            if (source.SourceHandle != 0)
            {
                return(false);
            }

            UIntPtr sourceHandle = 0;

            Lock.AcquireMutex();

            object obj = SourcesLookupTable[source.SourceName];

            if (obj != null)
            {
                sourceHandle = (UIntPtr)obj;
            }

            if (sourceHandle != 0)
            {
                object existingSource = SourcesHandleTable[sourceHandle];

                if (existingSource != null)
                {
                    // Type already registered. Return the existing value
                    Lock.ReleaseMutex();
                    return(false);
                }
            }
            else
            {
                // The handle for this source has not been allocated
                // Register a new one

                sourceHandle = AllocateSourceHandleImpl(source.SourceName);

                while (sourceHandle == 0)
                {
                    if (!TypesRepository.AddBuffer(BUFFER_EXPANSION_SIZE))
                    {
                        Lock.ReleaseMutex();
                        return(false);
                    }

                    sourceHandle = AllocateSourceHandleImpl(source.SourceName);
                }

                SourcesLookupTable[source.SourceName] = sourceHandle;
            }

            // We must have here a valid source handle

            source.SourceHandle = sourceHandle;
            SourcesHandleTable[sourceHandle] = source;

            ActiveSource activeSource = source as ActiveSource;

            if (activeSource == null)
            {
                //  regular sources with associated memory storage

                RegisterSourceStorageImpl(sourceHandle,
                                          source.Storage.GetHandle(),
                                          source.ControlFlags);
            }
            else
            {
                RegisterActiveSourceImpl(sourceHandle,
                                         activeSource.EventTypeHandle,
                                         activeSource.DebugBufferAddress,
                                         activeSource.Count,
                                         activeSource.EntrySize);

                //  Active sources, the object does the event buffer management
            }

            Lock.ReleaseMutex();
            return(true);
        }