msvcp90: Added num_put<char>::put(double) implementation.
[wine] / dlls / wbemprox / builtin.c
1 /*
2  * Copyright 2012 Hans Leidekker for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #define COBJMACROS
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
22
23 #include "config.h"
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wbemcli.h"
29 #include "tlhelp32.h"
30 #include "initguid.h"
31 #include "d3d10.h"
32
33 #include "wine/debug.h"
34 #include "wbemprox_private.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
37
38 static const WCHAR class_biosW[] =
39     {'W','i','n','3','2','_','B','I','O','S',0};
40 static const WCHAR class_compsysW[] =
41     {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
42 static const WCHAR class_osW[] =
43     {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
44 static const WCHAR class_processW[] =
45     {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
46 static const WCHAR class_processorW[] =
47     {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
48 static const WCHAR class_videocontrollerW[] =
49     {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
50
51 static const WCHAR prop_adapterramW[] =
52     {'A','d','a','p','t','e','r','R','A','M',0};
53 static const WCHAR prop_captionW[] =
54     {'C','a','p','t','i','o','n',0};
55 static const WCHAR prop_commandlineW[] =
56     {'C','o','m','m','a','n','d','L','i','n','e',0};
57 static const WCHAR prop_descriptionW[] =
58     {'D','e','s','c','r','i','p','t','i','o','n',0};
59 static const WCHAR prop_deviceidW[] =
60     {'D','e','v','i','c','e','I','d',0};
61 static const WCHAR prop_handleW[] =
62     {'H','a','n','d','l','e',0};
63 static const WCHAR prop_manufacturerW[] =
64     {'M','a','n','u','f','a','c','t','u','r','e','r',0};
65 static const WCHAR prop_modelW[] =
66     {'M','o','d','e','l',0};
67 static const WCHAR prop_osarchitectureW[] =
68     {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
69 static const WCHAR prop_pprocessidW[] =
70     {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
71 static const WCHAR prop_processidW[] =
72     {'P','r','o','c','e','s','s','I','D',0};
73 static const WCHAR prop_releasedateW[] =
74     {'R','e','l','e','a','s','e','D','a','t','e',0};
75 static const WCHAR prop_serialnumberW[] =
76     {'S','e','r','i','a','l','N','u','m','b','e','r',0};
77 static const WCHAR prop_threadcountW[] =
78     {'T','h','r','e','a','d','C','o','u','n','t',0};
79
80 static const struct column col_bios[] =
81 {
82     { prop_descriptionW,  CIM_STRING },
83     { prop_manufacturerW, CIM_STRING },
84     { prop_releasedateW,  CIM_DATETIME },
85     { prop_serialnumberW, CIM_STRING }
86 };
87 static const struct column col_compsys[] =
88 {
89     { prop_descriptionW,  CIM_STRING },
90     { prop_manufacturerW, CIM_STRING },
91     { prop_modelW,        CIM_STRING }
92 };
93 static const struct column col_os[] =
94 {
95     { prop_captionW,        CIM_STRING },
96     { prop_osarchitectureW, CIM_STRING }
97 };
98 static const struct column col_process[] =
99 {
100     { prop_captionW,     CIM_STRING|COL_FLAG_DYNAMIC },
101     { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
102     { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
103     { prop_handleW,      CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
104     { prop_pprocessidW,  CIM_UINT32 },
105     { prop_processidW,   CIM_UINT32 },
106     { prop_threadcountW, CIM_UINT32 }
107 };
108 static const struct column col_processor[] =
109 {
110     { prop_manufacturerW, CIM_STRING }
111 };
112 static const struct column col_videocontroller[] =
113 {
114     { prop_adapterramW,  CIM_UINT32 },
115     { prop_deviceidW,    CIM_STRING|COL_FLAG_KEY }
116 };
117
118 static const WCHAR bios_descriptionW[] =
119     {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
120 static const WCHAR bios_manufacturerW[] =
121     {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
122 static const WCHAR bios_releasedateW[] =
123     {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
124 static const WCHAR bios_serialnumberW[] =
125     {'0',0};
126 static const WCHAR compsys_descriptionW[] =
127     {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
128 static const WCHAR compsys_manufacturerW[] =
129     {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
130 static const WCHAR compsys_modelW[] =
131     {'W','i','n','e',0};
132 static const WCHAR os_captionW[] =
133     {'W','i','n','e',0};
134 static const WCHAR os_32bitW[] =
135     {'3','2','-','b','i','t',0};
136 static const WCHAR os_64bitW[] =
137     {'6','4','-','b','i','t',0};
138 static const WCHAR processor_manufacturerW[] =
139     {'G','e','n','u','i','n','e','I','n','t','e','l',0};
140 static const WCHAR videocontroller_deviceidW[] =
141     {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
142
143 #include "pshpack1.h"
144 struct record_bios
145 {
146     const WCHAR *description;
147     const WCHAR *manufacturer;
148     const WCHAR *releasedate;
149     const WCHAR *serialnumber;
150 };
151 struct record_computersystem
152 {
153     const WCHAR *description;
154     const WCHAR *manufacturer;
155     const WCHAR *model;
156 };
157 struct record_operatingsystem
158 {
159     const WCHAR *caption;
160     const WCHAR *osarchitecture;
161 };
162 struct record_process
163 {
164     const WCHAR *caption;
165     const WCHAR *commandline;
166     const WCHAR *description;
167     const WCHAR *handle;
168     UINT32       pprocess_id;
169     UINT32       process_id;
170     UINT32       thread_count;
171 };
172 struct record_processor
173 {
174     const WCHAR *manufacturer;
175 };
176 struct record_videocontroller
177 {
178     UINT32       adapter_ram;
179     const WCHAR *device_id;
180 };
181 #include "poppack.h"
182
183 static const struct record_bios data_bios[] =
184 {
185     { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW }
186 };
187 static const struct record_computersystem data_compsys[] =
188 {
189     { compsys_descriptionW, compsys_manufacturerW, compsys_modelW }
190 };
191 static const struct record_processor data_processor[] =
192 {
193     { processor_manufacturerW }
194 };
195
196 static WCHAR *get_cmdline( DWORD process_id )
197 {
198     if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
199     return NULL; /* FIXME handle different process case */
200 }
201
202 static void fill_process( struct table *table )
203 {
204     static const WCHAR fmtW[] = {'%','u',0};
205     WCHAR handle[11];
206     struct record_process *rec;
207     PROCESSENTRY32W entry;
208     HANDLE snap;
209     UINT num_rows = 0, offset = 0, count = 8;
210
211     snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
212     if (snap == INVALID_HANDLE_VALUE) return;
213
214     entry.dwSize = sizeof(entry);
215     if (!Process32FirstW( snap, &entry )) goto done;
216     if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
217
218     do
219     {
220         if (num_rows > count)
221         {
222             BYTE *data;
223             count *= 2;
224             if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
225             table->data = data;
226         }
227         rec = (struct record_process *)(table->data + offset);
228         rec->caption      = heap_strdupW( entry.szExeFile );
229         rec->commandline  = get_cmdline( entry.th32ProcessID );
230         rec->description  = heap_strdupW( entry.szExeFile );
231         sprintfW( handle, fmtW, entry.th32ProcessID );
232         rec->handle       = heap_strdupW( handle );
233         rec->process_id   = entry.th32ProcessID;
234         rec->pprocess_id  = entry.th32ParentProcessID;
235         rec->thread_count = entry.cntThreads;
236         offset += sizeof(*rec);
237         num_rows++;
238     } while (Process32NextW( snap, &entry ));
239
240     TRACE("created %u rows\n", num_rows);
241     table->num_rows = num_rows;
242
243 done:
244     CloseHandle( snap );
245 }
246
247 static void fill_os( struct table *table )
248 {
249     struct record_operatingsystem *rec;
250     SYSTEM_INFO info;
251
252     if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
253
254     rec = (struct record_operatingsystem *)table->data;
255     rec->caption = os_captionW;
256
257     GetNativeSystemInfo( &info );
258     if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
259         rec->osarchitecture = os_64bitW;
260     else
261         rec->osarchitecture = os_32bitW;
262
263     TRACE("created 1 row\n");
264     table->num_rows = 1;
265 }
266
267 static void fill_videocontroller( struct table *table )
268 {
269
270     struct record_videocontroller *rec;
271     HRESULT hr;
272     IDXGIFactory *factory = NULL;
273     IDXGIAdapter *adapter = NULL;
274     DXGI_ADAPTER_DESC desc;
275     UINT vidmem = 512 * 1024 * 1024;
276
277     if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
278
279     hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
280     if (FAILED(hr)) goto done;
281
282     hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
283     if (FAILED(hr)) goto done;
284
285     hr = IDXGIAdapter_GetDesc( adapter, &desc );
286     if (SUCCEEDED(hr)) vidmem = desc.DedicatedVideoMemory;
287
288 done:
289     rec = (struct record_videocontroller *)table->data;
290     rec->device_id   = videocontroller_deviceidW;
291     rec->adapter_ram = vidmem;
292
293     TRACE("created 1 row\n");
294     table->num_rows = 1;
295
296     if (adapter) IDXGIAdapter_Release( adapter );
297     if (factory) IDXGIFactory_Release( factory );
298 }
299
300 static struct table classtable[] =
301 {
302     { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios, NULL },
303     { class_compsysW, SIZEOF(col_compsys), col_compsys, SIZEOF(data_compsys), (BYTE *)data_compsys, NULL },
304     { class_osW, SIZEOF(col_os), col_os, 0, NULL, fill_os },
305     { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process },
306     { class_processorW, SIZEOF(col_processor), col_processor, SIZEOF(data_processor), (BYTE *)data_processor, NULL },
307     { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, NULL, fill_videocontroller }
308 };
309
310 struct table *get_table( const WCHAR *name )
311 {
312     UINT i;
313     struct table *table = NULL;
314
315     for (i = 0; i < SIZEOF(classtable); i++)
316     {
317         if (!strcmpiW( classtable[i].name, name ))
318         {
319             table = &classtable[i];
320             if (table->fill && !table->data) table->fill( table );
321             break;
322         }
323     }
324     return table;
325 }