Hans Leidekker : pdh: Implement PdhAddCounter{A, W} and PdhRemoveCounter.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Jun 28 08:08:11 CDT 2007


Module: wine
Branch: master
Commit: 0718c11ee16d7e81e46bcfd4710b4563e554c6a8
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=0718c11ee16d7e81e46bcfd4710b4563e554c6a8

Author: Hans Leidekker <hans at it.vu.nl>
Date:   Mon Jun 25 21:10:19 2007 +0200

pdh: Implement PdhAddCounter{A, W} and PdhRemoveCounter.

---

 dlls/pdh/pdh.spec   |    6 ++--
 dlls/pdh/pdh_main.c |   95 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+), 3 deletions(-)

diff --git a/dlls/pdh/pdh.spec b/dlls/pdh/pdh.spec
index 26494cd..3bfae97 100644
--- a/dlls/pdh/pdh.spec
+++ b/dlls/pdh/pdh.spec
@@ -1,8 +1,8 @@
 1 stub PdhPlaGetLogFileNameA
 @ stub PdhAdd009CounterA
 @ stub PdhAdd009CounterW
-@ stub PdhAddCounterA
-@ stub PdhAddCounterW
+@ stdcall PdhAddCounterA(ptr str long ptr)
+@ stdcall PdhAddCounterW(ptr wstr long ptr)
 @ stub PdhBindInputDataSourceA
 @ stub PdhBindInputDataSourceW
 @ stub PdhBrowseCountersA
@@ -120,7 +120,7 @@
 @ stub PdhReadRawLogRecord
 @ stub PdhRelogA
 @ stub PdhRelogW
-@ stub PdhRemoveCounter
+@ stdcall PdhRemoveCounter(ptr)
 @ stub PdhSelectDataSourceA
 @ stub PdhSelectDataSourceW
 @ stub PdhSetCounterScaleFactor
diff --git a/dlls/pdh/pdh_main.c b/dlls/pdh/pdh_main.c
index 1531b94..2dc7b8b 100644
--- a/dlls/pdh/pdh_main.c
+++ b/dlls/pdh/pdh_main.c
@@ -111,6 +111,14 @@ struct counter
     } two;                                          /* second value */
 };
 
+static struct counter *create_counter( void )
+{
+    struct counter *counter;
+
+    if ((counter = pdh_alloc_zero( sizeof(struct counter) ))) return counter;
+    return NULL;
+}
+
 #define PDH_MAGIC_QUERY     0x50444830 /* 'PDH0' */
 
 struct query
@@ -142,6 +150,74 @@ struct source
     LONGLONG        base;                           /* samples per second */
 };
 
+/* counter source registry */
+static const struct source counter_sources[] =
+{
+    { NULL, NULL, 0, 0, 0 }
+};
+
+/***********************************************************************
+ *              PdhAddCounterA   (PDH.@)
+ */
+PDH_STATUS WINAPI PdhAddCounterA( PDH_HQUERY query, LPCSTR path,
+                                  DWORD_PTR userdata, PDH_HCOUNTER *counter )
+{
+    PDH_STATUS ret;
+    WCHAR *pathW;
+
+    TRACE("%p %s %lx %p\n", query, debugstr_a(path), userdata, counter);
+
+    if (!path) return PDH_INVALID_ARGUMENT;
+
+    if (!(pathW = pdh_strdup_aw( path )))
+        return PDH_MEMORY_ALLOCATION_FAILURE;
+
+    ret = PdhAddCounterW( query, pathW, userdata, counter );
+
+    pdh_free( pathW );
+    return ret;
+}
+
+/***********************************************************************
+ *              PdhAddCounterW   (PDH.@)
+ */
+PDH_STATUS WINAPI PdhAddCounterW( PDH_HQUERY hquery, LPCWSTR path,
+                                  DWORD_PTR userdata, PDH_HCOUNTER *hcounter )
+{
+    struct query *query = hquery;
+    struct counter *counter;
+    unsigned int i;
+
+    TRACE("%p %s %lx %p\n", hquery, debugstr_w(path), userdata, hcounter);
+
+    if (!path  || !hcounter) return PDH_INVALID_ARGUMENT;
+    if (!query || (query->magic != PDH_MAGIC_QUERY)) return PDH_INVALID_HANDLE;
+
+    *hcounter = NULL;
+    for (i = 0; i < sizeof(counter_sources) / sizeof(counter_sources[0]); i++)
+    {
+        if (strstrW( path, counter_sources[i].path ))
+        {
+            if ((counter = create_counter()))
+            {
+                counter->path         = pdh_strdup( counter_sources[i].path );
+                counter->collect      = counter_sources[i].collect;
+                counter->type         = counter_sources[i].type;
+                counter->defaultscale = counter_sources[i].scale;
+                counter->base         = counter_sources[i].base;
+                counter->queryuser    = query->user;
+                counter->user         = userdata;
+
+                list_add_tail( &query->counters, &counter->entry );
+
+                *hcounter = counter;
+                return ERROR_SUCCESS;
+            }
+            return PDH_MEMORY_ALLOCATION_FAILURE;
+        }
+    }
+    return PDH_CSTATUS_NO_COUNTER;
+}
 
 /***********************************************************************
  *              PdhCloseQuery   (PDH.@)
@@ -212,3 +288,22 @@ PDH_STATUS WINAPI PdhOpenQueryW( LPCWSTR source, DWORD_PTR userdata, PDH_HQUERY
     }
     return PDH_MEMORY_ALLOCATION_FAILURE;
 }
+
+/***********************************************************************
+ *              PdhRemoveCounter   (PDH.@)
+ */
+PDH_STATUS WINAPI PdhRemoveCounter( PDH_HCOUNTER handle )
+{
+    struct counter *counter = handle;
+
+    TRACE("%p\n", handle);
+
+    if (!counter) return PDH_INVALID_HANDLE;
+
+    list_remove( &counter->entry );
+
+    pdh_free( counter->path );
+    pdh_free( counter );
+
+    return ERROR_SUCCESS;
+}




More information about the wine-cvs mailing list