Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: installer/src/installer-lib/process.cpp

Issue 6197445574787072: Cleaned up CA exceptions. Integrated free-standing handle class. (Closed)
Patch Set: Created March 30, 2014, 7:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include <stdexcept> 1 #include <stdexcept>
2 #include <functional> 2 #include <functional>
3 #include <wctype.h> 3 #include <wctype.h>
4 // <thread> is C++11, but implemented in VS2012 4 // <thread> is C++11, but implemented in VS2012
5 #include <thread> 5 #include <thread>
6 6
7 #include "installer-lib.h"
7 #include "process.h" 8 #include "process.h"
8 9
9 //------------------------------------------------------- 10 //-------------------------------------------------------
10 // Windows_Handle
11 //-------------------------------------------------------
12 Windows_Handle::Windows_Handle( HANDLE h )
13 : handle( h )
14 {
15 validate_handle() ;
16 }
17
18 Windows_Handle::~Windows_Handle()
19 {
20 CloseHandle( handle ) ;
21 }
22
23 void Windows_Handle::operator=( HANDLE h )
24 {
25 this -> ~Windows_Handle() ;
26 handle = h ;
27 validate_handle() ;
28 }
29
30 void Windows_Handle::validate_handle()
31 {
32 if ( handle == INVALID_HANDLE_VALUE )
33 {
34 throw std::runtime_error( "Invalid handle" ) ;
35 }
36 }
37
38 //-------------------------------------------------------
39 // process_by_name_CI 11 // process_by_name_CI
40 //------------------------------------------------------- 12 //-------------------------------------------------------
41 process_by_name_CI::process_by_name_CI( const wchar_t * name ) 13 process_by_name_CI::process_by_name_CI( const wchar_t * name )
42 : name( name ), length( wcslen( name ) ) 14 : name( name ), length( wcslen( name ) )
43 {} 15 {}
44 16
45 bool process_by_name_CI::operator()( const PROCESSENTRY32W & process ) 17 bool process_by_name_CI::operator()( const PROCESSENTRY32W & process )
46 { 18 {
47 return 0 == wcsncmpi( process.szExeFile, name, length ) ; 19 return 0 == wcsncmpi( process.szExeFile, name, length ) ;
48 } 20 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // creator_process 96 // creator_process
125 //------------------------------------------------------- 97 //-------------------------------------------------------
126 DWORD creator_process( HWND window ) 98 DWORD creator_process( HWND window )
127 { 99 {
128 DWORD pid ; 100 DWORD pid ;
129 DWORD r = GetWindowThreadProcessId( window, & pid ) ; 101 DWORD r = GetWindowThreadProcessId( window, & pid ) ;
130 if ( r == 0 ) 102 if ( r == 0 )
131 { 103 {
132 // Assert GetWindowThreadProcessId returned an error 104 // Assert GetWindowThreadProcessId returned an error
133 // If the window handle is invalid, we end up here. 105 // If the window handle is invalid, we end up here.
134 throw std::runtime_error( "" ) ; 106 throw windows_api_error( "GetWindowThreadProcessId", r ) ;
135 } 107 }
136 return pid ; 108 return pid ;
137 } 109 }
138 110
139 //------------------------------------------------------- 111 //-------------------------------------------------------
140 // Snapshot 112 // Snapshot
141 //------------------------------------------------------- 113 //-------------------------------------------------------
142 Snapshot::Snapshot() 114 Snapshot::Snapshot()
143 : handle( ::CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ) ) 115 : handle( ::CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ) )
144 { 116 {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 if ( ! is_running() ) 379 if ( ! is_running() )
408 { 380 {
409 return true ; 381 return true ;
410 } 382 }
411 } 383 }
412 // Assert is_running() 384 // Assert is_running()
413 } 385 }
414 // No control path leaves the for-loop. 386 // No control path leaves the for-loop.
415 } ; 387 } ;
416 388
OLDNEW

Powered by Google App Engine
This is Rietveld