[4/6] wbemprox: Add a partial Win32_Process class implementation.

Hans Leidekker hans at codeweavers.com
Mon Jun 18 02:32:02 CDT 2012


---
 dlls/wbemprox/builtin.c          |   69 +++++++++++++++++++++++++++++++++++++-
 dlls/wbemprox/query.c            |   68 +++++++++++++++++++++++++------------
 dlls/wbemprox/wbemprox_private.h |    9 +++++
 3 files changed, 123 insertions(+), 23 deletions(-)

diff --git a/dlls/wbemprox/builtin.c b/dlls/wbemprox/builtin.c
index c6879e7..2cf55d5 100644
--- a/dlls/wbemprox/builtin.c
+++ b/dlls/wbemprox/builtin.c
@@ -24,6 +24,7 @@
 #include "windef.h"
 #include "winbase.h"
 #include "wbemcli.h"
+#include "tlhelp32.h"
 
 #include "wine/debug.h"
 #include "wbemprox_private.h"
@@ -32,6 +33,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
 
 static const WCHAR class_biosW[] =
     {'W','i','n','3','2','_','B','I','O','S',0};
+static const WCHAR class_processW[] =
+    {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
 
 static const WCHAR prop_captionW[] =
     {'C','a','p','t','i','o','n',0};
@@ -39,10 +42,16 @@ static const WCHAR prop_descriptionW[] =
     {'D','e','s','c','r','i','p','t','i','o','n',0};
 static const WCHAR prop_manufacturerW[] =
     {'M','a','n','u','f','a','c','t','u','r','e','r',0};
+static const WCHAR prop_pprocessidW[] =
+    {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
+static const WCHAR prop_processidW[] =
+    {'P','r','o','c','e','s','s','I','D',0};
 static const WCHAR prop_releasedateW[] =
     {'R','e','l','e','a','s','e','D','a','t','e',0};
 static const WCHAR prop_serialnumberW[] =
     {'S','e','r','i','a','l','N','u','m','b','e','r',0};
+static const WCHAR prop_threadcountW[] =
+    {'T','h','r','e','a','d','C','o','u','n','t',0};
 
 static const struct column col_bios[] =
 {
@@ -51,6 +60,14 @@ static const struct column col_bios[] =
     { prop_releasedateW,  CIM_DATETIME },
     { prop_serialnumberW, CIM_STRING }
 };
+static const struct column col_process[] =
+{
+    { prop_captionW,     CIM_STRING },
+    { prop_descriptionW, CIM_STRING },
+    { prop_pprocessidW,  CIM_UINT32 },
+    { prop_processidW,   CIM_UINT32 },
+    { prop_threadcountW, CIM_UINT32 }
+};
 
 static const WCHAR bios_descriptionW[] =
     {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
@@ -69,6 +86,14 @@ struct record_bios
     const WCHAR *releasedate;
     const WCHAR *serialnumber;
 };
+struct record_process
+{
+    const WCHAR *caption;
+    const WCHAR *description;
+    UINT32       pprocess_id;
+    UINT32       process_id;
+    UINT32       thread_count;
+};
 #include "poppack.h"
 
 static const struct record_bios data_bios[] =
@@ -76,9 +101,50 @@ static const struct record_bios data_bios[] =
     { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW }
 };
 
+static void fill_process( struct table *table )
+{
+    struct record_process *rec;
+    PROCESSENTRY32W entry;
+    HANDLE snap;
+    UINT num_rows = 0, offset = 0, count = 8;
+
+    snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
+    if (snap == INVALID_HANDLE_VALUE) return;
+
+    entry.dwSize = sizeof(entry);
+    if (!Process32FirstW( snap, &entry )) goto done;
+    if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
+
+    do
+    {
+        if (num_rows > count)
+        {
+            BYTE *data;
+            count *= 2;
+            if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
+            table->data = data;
+        }
+        rec = (struct record_process *)(table->data + offset);
+        rec->caption      = heap_strdupW( entry.szExeFile );
+        rec->description  = heap_strdupW( entry.szExeFile );
+        rec->process_id   = entry.th32ProcessID;
+        rec->pprocess_id  = entry.th32ParentProcessID;
+        rec->thread_count = entry.cntThreads;
+        offset += sizeof(*rec);
+        num_rows++;
+    } while (Process32NextW( snap, &entry ));
+
+    TRACE("created %u rows\n", num_rows);
+    table->num_rows = num_rows;
+
+done:
+    CloseHandle( snap );
+}
+
 static struct table classtable[] =
 {
-    { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios }
+    { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios, NULL },
+    { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process }
 };
 
 struct table *get_table( const WCHAR *name )
@@ -91,6 +157,7 @@ struct table *get_table( const WCHAR *name )
         if (!strcmpiW( classtable[i].name, name ))
         {
             table = &classtable[i];
+            if (table->fill && !table->data) table->fill( table );
             break;
         }
     }
diff --git a/dlls/wbemprox/query.c b/dlls/wbemprox/query.c
index 7b228ae..1d17a28 100644
--- a/dlls/wbemprox/query.c
+++ b/dlls/wbemprox/query.c
@@ -30,28 +30,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
 
-HRESULT create_view( const struct property *proplist, const WCHAR *class,
-                     const struct expr *cond, struct view **ret )
-{
-    struct view *view = heap_alloc( sizeof(struct view) );
-
-    if (!view) return E_OUTOFMEMORY;
-    view->proplist = proplist;
-    view->table    = get_table( class );
-    view->cond     = cond;
-    view->result   = NULL;
-    view->count    = 0;
-    view->index    = 0;
-    *ret = view;
-    return S_OK;
-}
-
-void destroy_view( struct view *view )
-{
-    heap_free( view->result );
-    heap_free( view );
-}
-
 static HRESULT get_column_index( const struct table *table, const WCHAR *name, UINT *column )
 {
     UINT i;
@@ -140,6 +118,52 @@ static HRESULT get_value( const struct table *table, UINT row, UINT column, INT_
     return S_OK;
 }
 
+HRESULT create_view( const struct property *proplist, const WCHAR *class,
+                     const struct expr *cond, struct view **ret )
+{
+    struct view *view = heap_alloc( sizeof(struct view) );
+
+    if (!view) return E_OUTOFMEMORY;
+    view->proplist = proplist;
+    view->table    = get_table( class );
+    view->cond     = cond;
+    view->result   = NULL;
+    view->count    = 0;
+    view->index    = 0;
+    *ret = view;
+    return S_OK;
+}
+
+static void clear_table( struct table *table )
+{
+    UINT i, j;
+
+    if (!table->fill || !table->data) return;
+
+    for (i = 0; i < table->num_rows; i++)
+    {
+        for (j = 0; j < table->num_cols; j++)
+        {
+            if (table->columns[j].type == CIM_STRING   ||
+                table->columns[j].type == CIM_DATETIME ||
+                (table->columns[j].type & CIM_FLAG_ARRAY))
+            {
+                void *ptr;
+                if (get_value( table, i, j, (INT_PTR *)&ptr ) == S_OK) heap_free( ptr );
+            }
+        }
+    }
+    heap_free( table->data );
+    table->data = NULL;
+}
+
+void destroy_view( struct view *view )
+{
+    if (view->table) clear_table( view->table );
+    heap_free( view->result );
+    heap_free( view );
+}
+
 static BOOL eval_like( INT_PTR lval, INT_PTR rval )
 {
     const WCHAR *p = (const WCHAR *)lval, *q = (const WCHAR *)rval;
diff --git a/dlls/wbemprox/wbemprox_private.h b/dlls/wbemprox/wbemprox_private.h
index 1e3ca0c..15a7146 100644
--- a/dlls/wbemprox/wbemprox_private.h
+++ b/dlls/wbemprox/wbemprox_private.h
@@ -34,6 +34,7 @@ struct table
     const struct column *columns;
     UINT num_rows;
     BYTE *data;
+    void (*fill)(struct table *);
 };
 
 struct property
@@ -135,3 +136,11 @@ static inline BOOL heap_free( void *mem )
 {
     return HeapFree( GetProcessHeap(), 0, mem );
 }
+
+static inline WCHAR *heap_strdupW( const WCHAR *src )
+{
+    WCHAR *dst;
+    if (!src) return NULL;
+    if ((dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ))) strcpyW( dst, src );
+    return dst;
+}
-- 
1.7.10







More information about the wine-patches mailing list