LEFT | RIGHT |
1 /** | 1 /** |
2 * \file process.h | 2 * \file process.h |
3 */ | 3 */ |
4 | 4 |
5 #ifndef PROCESS_H | 5 #ifndef PROCESS_H |
6 #define PROCESS_H | 6 #define PROCESS_H |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 #include <set> | 9 #include <set> |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 { | 100 { |
101 bool operator()( const file_name & a, const file_name & b ) const | 101 bool operator()( const file_name & a, const file_name & b ) const |
102 { | 102 { |
103 return wcscmpi( a.name, b.name ) < 0 ; | 103 return wcscmpi( a.name, b.name ) < 0 ; |
104 } | 104 } |
105 } ; | 105 } ; |
106 | 106 |
107 struct file_name_set | 107 struct file_name_set |
108 : public std::set< file_name > | 108 : public std::set< file_name > |
109 { | 109 { |
| 110 file_name_set(){}; |
| 111 |
110 file_name_set( const wchar_t * file_name_list[], size_t n_file_names ) | 112 file_name_set( const wchar_t * file_name_list[], size_t n_file_names ) |
111 { | 113 { |
112 for ( unsigned int j = 0 ; j < n_file_names ; ++ j ) | 114 for ( unsigned int j = 0 ; j < n_file_names ; ++ j ) |
113 { | 115 { |
114 insert( file_name( file_name_list[ j ] ) ) ; | 116 insert( file_name( file_name_list[ j ] ) ) ; |
115 } | 117 } |
116 } | 118 } |
117 } ; | 119 } ; |
118 | 120 |
119 //------------------------------------------------------- | 121 //------------------------------------------------------- |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 Snapshot() ; | 261 Snapshot() ; |
260 | 262 |
261 /** | 263 /** |
262 * Reconstruct the current instance with a new system snapshot. | 264 * Reconstruct the current instance with a new system snapshot. |
263 */ | 265 */ |
264 void refresh() ; | 266 void refresh() ; |
265 | 267 |
266 /** | 268 /** |
267 * Return a pointer to the first process in the snapshot. | 269 * Return a pointer to the first process in the snapshot. |
268 */ | 270 */ |
269 PROCESSENTRY32W * begin() ; | 271 PROCESSENTRY32W * first() ; |
270 | |
271 /** | |
272 * The end pointer is an alias for the null pointer. | |
273 */ | |
274 inline PROCESSENTRY32W * end() const { return 0 ; } | |
275 | 272 |
276 /** | 273 /** |
277 * Return a pointer to the next process in the snapshot. | 274 * Return a pointer to the next process in the snapshot. |
278 * begin() must have been called first. | 275 * begin() must have been called first. |
279 */ | 276 */ |
280 PROCESSENTRY32W * next() ; | 277 PROCESSENTRY32W * next() ; |
281 | |
282 /** | |
283 * Type definition for pointer to underlying structure. | |
284 */ | |
285 typedef PROCESSENTRY32W * Pointer ; | |
286 } ; | 278 } ; |
287 | 279 |
288 class ModulesSnapshot | 280 class ModulesSnapshot |
289 { | 281 { |
290 /** | 282 /** |
291 * Handle to the process snapshot. | 283 * Handle to the process snapshot. |
292 */ | 284 */ |
293 Windows_Handle handle; | 285 Windows_Handle handle; |
294 | 286 |
295 /** | 287 /** |
(...skipping 20 matching lines...) Expand all Loading... |
316 | 308 |
317 public: | 309 public: |
318 /** | 310 /** |
319 * Default constructor takes the snapshot. | 311 * Default constructor takes the snapshot. |
320 */ | 312 */ |
321 ModulesSnapshot(DWORD processId); | 313 ModulesSnapshot(DWORD processId); |
322 | 314 |
323 /** | 315 /** |
324 * Return a pointer to the first process in the snapshot. | 316 * Return a pointer to the first process in the snapshot. |
325 */ | 317 */ |
326 MODULEENTRY32W* begin(); | 318 MODULEENTRY32W* first(); |
327 | |
328 /** | |
329 * The end pointer is an alias for the null pointer. | |
330 */ | |
331 inline MODULEENTRY32W* end() const { return 0; } | |
332 | 319 |
333 /** | 320 /** |
334 * Return a pointer to the next process in the snapshot. | 321 * Return a pointer to the next process in the snapshot. |
335 * begin() must have been called first. | 322 * begin() must have been called first. |
336 */ | 323 */ |
337 MODULEENTRY32W* next(); | 324 MODULEENTRY32W* next(); |
338 | |
339 /** | |
340 * Type definition for pointer to underlying structure. | |
341 */ | |
342 typedef MODULEENTRY32W* Pointer; | |
343 }; | 325 }; |
344 | 326 |
345 | 327 |
346 //------------------------------------------------------- | 328 //------------------------------------------------------- |
347 // initialize_process_list | 329 // initialize_process_list |
348 //------------------------------------------------------- | 330 //------------------------------------------------------- |
349 /** | 331 /** |
350 * \tparam T The type into which a PROCESSENTRY32W struture is extracted. | 332 * \tparam T The type into which a PROCESSENTRY32W struture is extracted. |
351 * \tparam Admittance Function type for argument 'admit' | 333 * \tparam Admittance Function type for argument 'admit' |
352 * \tparam Extractor Function type for argument 'extract' | 334 * \tparam Extractor Function type for argument 'extract' |
353 * \param admit A unary predicate function class that determines what's included | 335 * \param admit A unary predicate function class that determines what's included |
354 * A process appears in the list only if the predicate returns true. | 336 * A process appears in the list only if the predicate returns true. |
355 * The use of this predicate is analogous to that in std::copy_if. | 337 * The use of this predicate is analogous to that in std::copy_if. |
356 * \param convert A conversion function that takes a PROCESSENTRY32W as input ar
gument and returns an element of type T. | 338 * \param convert A conversion function that takes a PROCESSENTRY32W as input ar
gument and returns an element of type T. |
357 */ | 339 */ |
358 template< class T, class Admittance, class Extractor > | 340 template<class T, class Admittance, class Extractor> |
359 void initialize_process_list( std::vector< T > & v, Snapshot & snap, Admittance
admit = Admittance(), Extractor extract = Extractor() ) | 341 void initialize_process_list(std::vector<T>& v, Snapshot& snap, Admittance admit
= Admittance(), Extractor extract = Extractor()) |
360 { | 342 { |
361 Snapshot::Pointer p = snap.begin() ; | 343 PROCESSENTRY32W* p = snap.first(); |
362 while ( p != snap.end() ) | 344 while (p != NULL) |
363 { | 345 { |
364 if ( admit( * p ) ) | 346 if (admit(*p )) |
365 { | 347 { |
366 /* | 348 /* |
367 * We don't have C++11 emplace_back, which can construct the element in p
lace. | 349 * We don't have C++11 emplace_back, which can construct the element in p
lace. |
368 * Instead, we copy the return value of the converter. | 350 * Instead, we copy the return value of the converter. |
369 */ | 351 */ |
370 v.push_back( extract( * p ) ); | 352 v.push_back(extract(*p)); |
371 } | 353 } |
372 p = snap.next() ; | 354 p = snap.next(); |
373 } | 355 } |
374 } ; | 356 }; |
375 | 357 |
376 //------------------------------------------------------- | 358 //------------------------------------------------------- |
377 // initialize_process_set | 359 // initialize_process_set |
378 //------------------------------------------------------- | 360 //------------------------------------------------------- |
379 /** | 361 /** |
380 * \tparam T The type into which a PROCESSENTRY32W struture is extracted. | 362 * \tparam T The type into which a PROCESSENTRY32W struture is extracted. |
381 * \tparam Admittance Function type for argument 'admit' | 363 * \tparam Admittance Function type for argument 'admit' |
382 * \tparam Extractor Function type for argument 'extract' | 364 * \tparam Extractor Function type for argument 'extract' |
383 * \param admit A unary predicate function class that determines what's included | 365 * \param admit A unary predicate function class that determines what's included |
384 * A process appears in the list only if the predicate returns true. | 366 * A process appears in the list only if the predicate returns true. |
385 * The use of this predicate is analogous to that in std::copy_if. | 367 * The use of this predicate is analogous to that in std::copy_if. |
386 * \param convert A conversion function that takes a PROCESSENTRY32W as input ar
gument and returns an element of type T. | 368 * \param convert A conversion function that takes a PROCESSENTRY32W as input ar
gument and returns an element of type T. |
387 */ | 369 */ |
388 template< class T, class Admittance, class Extractor > | 370 template<class T, class Admittance, class Extractor> |
389 void initialize_process_set( std::set< T > & set, Snapshot & snap, Admittance ad
mit = Admittance(), Extractor extract = Extractor() ) | 371 void initialize_process_set(std::set< T > & set, Snapshot& snap, Admittance admi
t = Admittance(), Extractor extract = Extractor()) |
390 { | 372 { |
391 Snapshot::Pointer p = snap.begin() ; | 373 PROCESSENTRY32W* p = snap.first(); |
392 while ( p != snap.end() ) | 374 while (p != NULL) |
393 { | 375 { |
394 if ( admit( * p ) ) | 376 if (admit(*p)) |
395 { | 377 { |
396 set.insert( extract( * p ) ); | 378 set.insert(extract(*p)); |
397 } | 379 } |
398 p = snap.next() ; | 380 p = snap.next(); |
399 } | 381 } |
400 } ; | 382 }; |
401 | 383 |
402 //------------------------------------------------------- | 384 //------------------------------------------------------- |
403 // enumerate_windows | 385 // enumerate_windows |
404 //------------------------------------------------------- | 386 //------------------------------------------------------- |
405 | 387 |
406 /** | 388 /** |
407 * States of a window enumeration. | 389 * States of a window enumeration. |
408 */ | 390 */ |
409 typedef enum | 391 typedef enum |
410 { | 392 { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 if ( ! b ) | 557 if ( ! b ) |
576 { | 558 { |
577 // Assert the process that created the window is not in our pid_set | 559 // Assert the process that created the window is not in our pid_set |
578 return true ; | 560 return true ; |
579 } | 561 } |
580 return f( window ) ; | 562 return f( window ) ; |
581 } | 563 } |
582 } ; | 564 } ; |
583 | 565 |
584 public: | 566 public: |
585 Process_Closer( Snapshot & snapshot, const wchar_t * file_name_list[], size_t
n_file_names, const wchar_t * module_name_list[], size_t n_module_names ) | 567 template <size_t n_file_names, size_t n_module_names> |
586 : snapshot( snapshot ), file_names( file_name_list, n_file_names ), module_n
ames(module_name_list, n_module_names), filter( file_names, module_names ) | 568 Process_Closer(Snapshot & snapshot, const wchar_t* (&file_name_list)[n_file_na
mes], const wchar_t* (&module_name_list)[n_module_names]) |
| 569 : snapshot(snapshot), file_names(file_name_list, n_file_names), module_names
(module_name_list, n_module_names), filter(file_names, module_names) |
| 570 { |
| 571 update() ; |
| 572 } |
| 573 template <size_t n_file_names> |
| 574 Process_Closer(Snapshot & snapshot, const wchar_t * (&file_name_list)[n_file_n
ames]) |
| 575 : snapshot(snapshot), file_names(file_name_list, n_file_names), module_names
(), filter(file_names, module_names) |
587 { | 576 { |
588 update() ; | 577 update() ; |
589 } | 578 } |
590 | 579 |
591 /** | 580 /** |
592 * Refresh our state to match the snapshot state. | 581 * Refresh our state to match the snapshot state. |
593 */ | 582 */ |
594 void refresh() | 583 void refresh() |
595 { | 584 { |
596 pid_set.clear() ; | 585 pid_set.clear() ; |
(...skipping 12 matching lines...) Expand all Loading... |
609 } | 598 } |
610 | 599 |
611 /* | 600 /* |
612 * Shut down every process in the pid_set. | 601 * Shut down every process in the pid_set. |
613 */ | 602 */ |
614 bool shut_down() ; | 603 bool shut_down() ; |
615 | 604 |
616 } ; | 605 } ; |
617 | 606 |
618 #endif | 607 #endif |
LEFT | RIGHT |