Commit c2a27a38 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wbemprox: Add a partial Win32_Process class implementation.

parent 92e99866
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "wbemcli.h" #include "wbemcli.h"
#include "tlhelp32.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "wbemprox_private.h" #include "wbemprox_private.h"
...@@ -32,6 +33,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(wbemprox); ...@@ -32,6 +33,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
static const WCHAR class_biosW[] = static const WCHAR class_biosW[] =
{'W','i','n','3','2','_','B','I','O','S',0}; {'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[] = static const WCHAR prop_captionW[] =
{'C','a','p','t','i','o','n',0}; {'C','a','p','t','i','o','n',0};
...@@ -39,10 +42,16 @@ static const WCHAR prop_descriptionW[] = ...@@ -39,10 +42,16 @@ static const WCHAR prop_descriptionW[] =
{'D','e','s','c','r','i','p','t','i','o','n',0}; {'D','e','s','c','r','i','p','t','i','o','n',0};
static const WCHAR prop_manufacturerW[] = static const WCHAR prop_manufacturerW[] =
{'M','a','n','u','f','a','c','t','u','r','e','r',0}; {'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[] = static const WCHAR prop_releasedateW[] =
{'R','e','l','e','a','s','e','D','a','t','e',0}; {'R','e','l','e','a','s','e','D','a','t','e',0};
static const WCHAR prop_serialnumberW[] = static const WCHAR prop_serialnumberW[] =
{'S','e','r','i','a','l','N','u','m','b','e','r',0}; {'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[] = static const struct column col_bios[] =
{ {
...@@ -51,6 +60,14 @@ static const struct column col_bios[] = ...@@ -51,6 +60,14 @@ static const struct column col_bios[] =
{ prop_releasedateW, CIM_DATETIME }, { prop_releasedateW, CIM_DATETIME },
{ prop_serialnumberW, CIM_STRING } { 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[] = static const WCHAR bios_descriptionW[] =
{'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0}; {'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 ...@@ -69,6 +86,14 @@ struct record_bios
const WCHAR *releasedate; const WCHAR *releasedate;
const WCHAR *serialnumber; const WCHAR *serialnumber;
}; };
struct record_process
{
const WCHAR *caption;
const WCHAR *description;
UINT32 pprocess_id;
UINT32 process_id;
UINT32 thread_count;
};
#include "poppack.h" #include "poppack.h"
static const struct record_bios data_bios[] = static const struct record_bios data_bios[] =
...@@ -76,9 +101,50 @@ 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 } { 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[] = 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 ) struct table *get_table( const WCHAR *name )
...@@ -91,6 +157,7 @@ struct table *get_table( const WCHAR *name ) ...@@ -91,6 +157,7 @@ struct table *get_table( const WCHAR *name )
if (!strcmpiW( classtable[i].name, name )) if (!strcmpiW( classtable[i].name, name ))
{ {
table = &classtable[i]; table = &classtable[i];
if (table->fill && !table->data) table->fill( table );
break; break;
} }
} }
......
...@@ -30,28 +30,6 @@ ...@@ -30,28 +30,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(wbemprox); 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 ) static HRESULT get_column_index( const struct table *table, const WCHAR *name, UINT *column )
{ {
UINT i; UINT i;
...@@ -140,6 +118,52 @@ static HRESULT get_value( const struct table *table, UINT row, UINT column, INT_ ...@@ -140,6 +118,52 @@ static HRESULT get_value( const struct table *table, UINT row, UINT column, INT_
return S_OK; 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 ) static BOOL eval_like( INT_PTR lval, INT_PTR rval )
{ {
const WCHAR *p = (const WCHAR *)lval, *q = (const WCHAR *)rval; const WCHAR *p = (const WCHAR *)lval, *q = (const WCHAR *)rval;
......
...@@ -34,6 +34,7 @@ struct table ...@@ -34,6 +34,7 @@ struct table
const struct column *columns; const struct column *columns;
UINT num_rows; UINT num_rows;
BYTE *data; BYTE *data;
void (*fill)(struct table *);
}; };
struct property struct property
...@@ -135,3 +136,11 @@ static inline BOOL heap_free( void *mem ) ...@@ -135,3 +136,11 @@ static inline BOOL heap_free( void *mem )
{ {
return HeapFree( GetProcessHeap(), 0, 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment