]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/DataHubDxe/DataHub.c
Fix bug in DataHub where it would skip the first record in a set when a filter is...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / DataHubDxe / DataHub.c
index 72287ffa8cdc0c219f6063c1b3a5514ce8fd95a1..e4dfa29d69f0b5a9b497b5a38ada9cf30dcbf32f 100644 (file)
@@ -2,7 +2,7 @@
   This code produces the Data Hub protocol. It preloads the data hub\r
   with status information copied in from PEI HOBs.\r
   \r
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -99,7 +99,7 @@ DataHubLogData (
   // Build Standard Log Header\r
   //\r
   Record->Version     = EFI_DATA_RECORD_HEADER_VERSION;\r
-  Record->HeaderSize  = sizeof (EFI_DATA_RECORD_HEADER);\r
+  Record->HeaderSize  = (UINT16) sizeof (EFI_DATA_RECORD_HEADER);\r
   Record->RecordSize  = RecordSize;\r
   CopyMem (&Record->DataRecordGuid, DataRecordGuid, sizeof (EFI_GUID));\r
   CopyMem (&Record->ProducerName, ProducerName, sizeof (EFI_GUID));\r
@@ -286,85 +286,96 @@ DataHubGetNextRecord (
   DATA_HUB_INSTANCE       *Private;\r
   DATA_HUB_FILTER_DRIVER  *FilterDriver;\r
   UINT64                  ClassFilter;\r
-  UINT64                  FilterMonotonicCount;\r
 \r
   Private               = DATA_HUB_INSTANCE_FROM_THIS (This);\r
 \r
   FilterDriver          = NULL;\r
-  FilterMonotonicCount  = 0;\r
   ClassFilter = EFI_DATA_RECORD_CLASS_DEBUG |\r
     EFI_DATA_RECORD_CLASS_ERROR |\r
     EFI_DATA_RECORD_CLASS_DATA |\r
     EFI_DATA_RECORD_CLASS_PROGRESS_CODE;\r
 \r
-  if (FilterDriverEvent != NULL) {\r
-    //\r
-    // For events the beginning is the last unread record. This info is\r
-    // stored in the instance structure, so we must look up the event\r
-    // to get the data.\r
-    //\r
-    FilterDriver = FindFilterDriverByEvent (\r
-                    &Private->FilterDriverListHead,\r
-                    *FilterDriverEvent\r
-                    );\r
-    if (FilterDriver == NULL) {\r
-      return EFI_INVALID_PARAMETER;\r
+  //\r
+  // If FilterDriverEvent is NULL, then return the next record\r
+  //\r
+  if (FilterDriverEvent == NULL) {\r
+    *Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, MonotonicCount);\r
+    if (*Record == NULL) {\r
+      return EFI_NOT_FOUND;\r
     }\r
-    //\r
-    // Use the Class filter the event was created with.\r
-    //\r
-    ClassFilter = FilterDriver->ClassFilter;\r
+    return EFI_SUCCESS;\r
+  }\r
+    \r
+  //\r
+  // For events the beginning is the last unread record. This info is\r
+  // stored in the instance structure, so we must look up the event\r
+  // to get the data.\r
+  //\r
+  FilterDriver = FindFilterDriverByEvent (\r
+                  &Private->FilterDriverListHead,\r
+                  *FilterDriverEvent\r
+                  );\r
+  if (FilterDriver == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Use the Class filter the event was created with.\r
+  //\r
+  ClassFilter = FilterDriver->ClassFilter;\r
 \r
-    if (*MonotonicCount == 0) {\r
+  //\r
+  // Retrieve the next record or the first record.\r
+  //   \r
+  if (*MonotonicCount != 0 || FilterDriver->GetNextMonotonicCount == 0) { \r
+    *Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, MonotonicCount);\r
+    if (*Record == NULL) {\r
+      return EFI_NOT_FOUND;\r
+    }\r
+    \r
+    if (*MonotonicCount != 0) {\r
       //\r
-      // Use the MTC from the Filter Driver.\r
+      // If this was not the last record then update the count associated with the filter \r
       //\r
-      FilterMonotonicCount = FilterDriver->GetNextMonotonicCount;\r
-       \r
+      FilterDriver->GetNextMonotonicCount = *MonotonicCount;\r
+    } else {\r
       //\r
-      // The GetNextMonotonicCount field remembers the last value from the previous time.\r
-      // But we already processed this vaule, so we need to find the next one.\r
+      // Save the MonotonicCount of the last record which has been read\r
       //\r
-      *Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, &FilterMonotonicCount);\r
-      if (FilterMonotonicCount != 0) {\r
-        *MonotonicCount = FilterMonotonicCount;\r
-      }\r
-      \r
-      if ((FilterDriver->GetNextMonotonicCount != 0) && (FilterMonotonicCount == 0)) {\r
-        //\r
-        // If there is no new record to get exit now.\r
-        //\r
-        *MonotonicCount = 0;\r
-        return EFI_NOT_FOUND;\r
-      }\r
+      FilterDriver->GetNextMonotonicCount = (*Record)->LogMonotonicCount;\r
     }\r
+    return EFI_SUCCESS;\r
   }\r
+  \r
   //\r
-  // Return the record\r
+  // This is a request to read the first record that has not been read yet.  \r
+  // Set MonotoicCount to the last record successfuly read\r
+  //\r
+  *MonotonicCount = FilterDriver->GetNextMonotonicCount;\r
+  \r
+  //\r
+  // Retrieve the last record successfuly read again, but do not return it since\r
+  // it has already been returned before.\r
   //\r
   *Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, MonotonicCount);\r
   if (*Record == NULL) {\r
     return EFI_NOT_FOUND;\r
   }\r
-\r
-  if (FilterDriver != NULL) {\r
+  \r
+  if (*MonotonicCount != 0) {\r
     //\r
-    // If we have a filter driver update the records that have been read.\r
-    // If MonotonicCount is zero No more reacords left.\r
+    // Update the count associated with the filter \r
     //\r
-    if (*MonotonicCount == 0) {\r
-      //\r
-      // Save the current Record MonotonicCount.\r
-      //\r
-      FilterDriver->GetNextMonotonicCount = (*Record)->LogMonotonicCount;\r
-    } else {\r
-      //\r
-      // Point to next undread record\r
-      //\r
-      FilterDriver->GetNextMonotonicCount = *MonotonicCount;\r
+    FilterDriver->GetNextMonotonicCount = *MonotonicCount;\r
+\r
+    //\r
+    // Retrieve the record after the last record successfuly read \r
+    //  \r
+    *Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, MonotonicCount);\r
+    if (*Record == NULL) {\r
+      return EFI_NOT_FOUND;\r
     }\r
   }\r
-\r
+  \r
   return EFI_SUCCESS;\r
 }\r
 \r