wbemprox: Support mixed dynamic and static table data.
[wine/multimedia.git] / dlls / wbemprox / builtin.c
blob8a6a74f56840905a031e4c1c97f1e67d12a22d6e
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_compsysW[] =
37 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
38 static const WCHAR class_processW[] =
39 {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
40 static const WCHAR class_processorW[] =
41 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
43 static const WCHAR prop_captionW[] =
44 {'C','a','p','t','i','o','n',0};
45 static const WCHAR prop_descriptionW[] =
46 {'D','e','s','c','r','i','p','t','i','o','n',0};
47 static const WCHAR prop_manufacturerW[] =
48 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
49 static const WCHAR prop_modelW[] =
50 {'M','o','d','e','l',0};
51 static const WCHAR prop_pprocessidW[] =
52 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
53 static const WCHAR prop_processidW[] =
54 {'P','r','o','c','e','s','s','I','D',0};
55 static const WCHAR prop_releasedateW[] =
56 {'R','e','l','e','a','s','e','D','a','t','e',0};
57 static const WCHAR prop_serialnumberW[] =
58 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
59 static const WCHAR prop_threadcountW[] =
60 {'T','h','r','e','a','d','C','o','u','n','t',0};
62 static const struct column col_bios[] =
64 { prop_descriptionW, CIM_STRING },
65 { prop_manufacturerW, CIM_STRING },
66 { prop_releasedateW, CIM_DATETIME },
67 { prop_serialnumberW, CIM_STRING }
69 static const struct column col_compsys[] =
71 { prop_descriptionW, CIM_STRING },
72 { prop_manufacturerW, CIM_STRING },
73 { prop_modelW, CIM_STRING }
75 static const struct column col_process[] =
77 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
78 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
79 { prop_pprocessidW, CIM_UINT32 },
80 { prop_processidW, CIM_UINT32 },
81 { prop_threadcountW, CIM_UINT32 }
83 static const struct column col_processor[] =
85 { prop_manufacturerW, CIM_STRING }
88 static const WCHAR bios_descriptionW[] =
89 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
90 static const WCHAR bios_manufacturerW[] =
91 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
92 static const WCHAR bios_releasedateW[] =
93 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
94 static const WCHAR bios_serialnumberW[] =
95 {'0',0};
96 static const WCHAR compsys_descriptionW[] =
97 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
98 static const WCHAR compsys_manufacturerW[] =
99 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
100 static const WCHAR compsys_modelW[] =
101 {'W','i','n','e',0};
102 static const WCHAR processor_manufacturerW[] =
103 {'G','e','n','u','i','n','e','I','n','t','e','l',0};
105 #include "pshpack1.h"
106 struct record_bios
108 const WCHAR *description;
109 const WCHAR *manufacturer;
110 const WCHAR *releasedate;
111 const WCHAR *serialnumber;
113 struct record_computersystem
115 const WCHAR *description;
116 const WCHAR *manufacturer;
117 const WCHAR *model;
119 struct record_process
121 const WCHAR *caption;
122 const WCHAR *description;
123 UINT32 pprocess_id;
124 UINT32 process_id;
125 UINT32 thread_count;
127 struct record_processor
129 const WCHAR *manufacturer;
131 #include "poppack.h"
133 static const struct record_bios data_bios[] =
135 { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW }
137 static const struct record_computersystem data_compsys[] =
139 { compsys_descriptionW, compsys_manufacturerW, compsys_modelW }
141 static const struct record_processor data_processor[] =
143 { processor_manufacturerW }
146 static void fill_process( struct table *table )
148 struct record_process *rec;
149 PROCESSENTRY32W entry;
150 HANDLE snap;
151 UINT num_rows = 0, offset = 0, count = 8;
153 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
154 if (snap == INVALID_HANDLE_VALUE) return;
156 entry.dwSize = sizeof(entry);
157 if (!Process32FirstW( snap, &entry )) goto done;
158 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
162 if (num_rows > count)
164 BYTE *data;
165 count *= 2;
166 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
167 table->data = data;
169 rec = (struct record_process *)(table->data + offset);
170 rec->caption = heap_strdupW( entry.szExeFile );
171 rec->description = heap_strdupW( entry.szExeFile );
172 rec->process_id = entry.th32ProcessID;
173 rec->pprocess_id = entry.th32ParentProcessID;
174 rec->thread_count = entry.cntThreads;
175 offset += sizeof(*rec);
176 num_rows++;
177 } while (Process32NextW( snap, &entry ));
179 TRACE("created %u rows\n", num_rows);
180 table->num_rows = num_rows;
182 done:
183 CloseHandle( snap );
186 static struct table classtable[] =
188 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios, NULL },
189 { class_compsysW, SIZEOF(col_compsys), col_compsys, SIZEOF(data_compsys), (BYTE *)data_compsys, NULL },
190 { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process },
191 { class_processorW, SIZEOF(col_processor), col_processor, SIZEOF(data_processor), (BYTE *)data_processor, NULL }
194 struct table *get_table( const WCHAR *name )
196 UINT i;
197 struct table *table = NULL;
199 for (i = 0; i < SIZEOF(classtable); i++)
201 if (!strcmpiW( classtable[i].name, name ))
203 table = &classtable[i];
204 if (table->fill && !table->data) table->fill( table );
205 break;
208 return table;