wbemprox: Add a partial Win32_Process class implementation.
[wine/multimedia.git] / dlls / wbemprox / builtin.c
blob2cf55d50781e264ef72efd8c376763064fba5897
1 /*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
21 #include "config.h"
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wbemcli.h"
27 #include "tlhelp32.h"
29 #include "wine/debug.h"
30 #include "wbemprox_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
34 static const WCHAR class_biosW[] =
35 {'W','i','n','3','2','_','B','I','O','S',0};
36 static const WCHAR class_processW[] =
37 {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
39 static const WCHAR prop_captionW[] =
40 {'C','a','p','t','i','o','n',0};
41 static const WCHAR prop_descriptionW[] =
42 {'D','e','s','c','r','i','p','t','i','o','n',0};
43 static const WCHAR prop_manufacturerW[] =
44 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
45 static const WCHAR prop_pprocessidW[] =
46 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
47 static const WCHAR prop_processidW[] =
48 {'P','r','o','c','e','s','s','I','D',0};
49 static const WCHAR prop_releasedateW[] =
50 {'R','e','l','e','a','s','e','D','a','t','e',0};
51 static const WCHAR prop_serialnumberW[] =
52 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
53 static const WCHAR prop_threadcountW[] =
54 {'T','h','r','e','a','d','C','o','u','n','t',0};
56 static const struct column col_bios[] =
58 { prop_descriptionW, CIM_STRING },
59 { prop_manufacturerW, CIM_STRING },
60 { prop_releasedateW, CIM_DATETIME },
61 { prop_serialnumberW, CIM_STRING }
63 static const struct column col_process[] =
65 { prop_captionW, CIM_STRING },
66 { prop_descriptionW, CIM_STRING },
67 { prop_pprocessidW, CIM_UINT32 },
68 { prop_processidW, CIM_UINT32 },
69 { prop_threadcountW, CIM_UINT32 }
72 static const WCHAR bios_descriptionW[] =
73 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
74 static const WCHAR bios_manufacturerW[] =
75 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
76 static const WCHAR bios_releasedateW[] =
77 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
78 static const WCHAR bios_serialnumberW[] =
79 {'0',0};
81 #include "pshpack1.h"
82 struct record_bios
84 const WCHAR *description;
85 const WCHAR *manufacturer;
86 const WCHAR *releasedate;
87 const WCHAR *serialnumber;
89 struct record_process
91 const WCHAR *caption;
92 const WCHAR *description;
93 UINT32 pprocess_id;
94 UINT32 process_id;
95 UINT32 thread_count;
97 #include "poppack.h"
99 static const struct record_bios data_bios[] =
101 { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW }
104 static void fill_process( struct table *table )
106 struct record_process *rec;
107 PROCESSENTRY32W entry;
108 HANDLE snap;
109 UINT num_rows = 0, offset = 0, count = 8;
111 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
112 if (snap == INVALID_HANDLE_VALUE) return;
114 entry.dwSize = sizeof(entry);
115 if (!Process32FirstW( snap, &entry )) goto done;
116 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
120 if (num_rows > count)
122 BYTE *data;
123 count *= 2;
124 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
125 table->data = data;
127 rec = (struct record_process *)(table->data + offset);
128 rec->caption = heap_strdupW( entry.szExeFile );
129 rec->description = heap_strdupW( entry.szExeFile );
130 rec->process_id = entry.th32ProcessID;
131 rec->pprocess_id = entry.th32ParentProcessID;
132 rec->thread_count = entry.cntThreads;
133 offset += sizeof(*rec);
134 num_rows++;
135 } while (Process32NextW( snap, &entry ));
137 TRACE("created %u rows\n", num_rows);
138 table->num_rows = num_rows;
140 done:
141 CloseHandle( snap );
144 static struct table classtable[] =
146 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios, NULL },
147 { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process }
150 struct table *get_table( const WCHAR *name )
152 UINT i;
153 struct table *table = NULL;
155 for (i = 0; i < SIZEOF(classtable); i++)
157 if (!strcmpiW( classtable[i].name, name ))
159 table = &classtable[i];
160 if (table->fill && !table->data) table->fill( table );
161 break;
164 return table;