Index: installer/src/installer-lib/process.h |
=================================================================== |
--- a/installer/src/installer-lib/process.h |
+++ b/installer/src/installer-lib/process.h |
@@ -26,17 +26,17 @@ |
/** |
* Traits class for case-insensitive strings. |
*/ |
-template< class T > |
-struct CaseInsensitiveTraits: std::char_traits< T > |
+template<class T> |
+struct CaseInsensitiveTraits: std::char_traits<T> |
{ |
- static bool eq( T c1, T c2 ) |
+ static bool eq(T c1, T c2) |
{ |
- return std::tolower( c1 ) == std::tolower( c2 ) ; |
+ return std::tolower(c1) == std::tolower(c2); |
} |
- static bool lt( T c1, T c2 ) |
+ static bool lt(T c1, T c2) |
{ |
- return std::tolower( c1 ) < std::tolower( c2 ) ; |
+ return std::tolower(c1) < std::tolower(c2); |
} |
/** |
@@ -47,29 +47,29 @@ |
* The argument 'n' is the minimum length of the two strings being compared. |
* We may assume that the intervals p1[0..n) and p2[0..n) are both valid substrings. |
*/ |
- static int compare( const T * p1, const T * p2, size_t n ) |
+ static int compare(const T* p1, const T* p2, size_t n) |
{ |
- while ( n-- > 0 ) |
+ while (n-- > 0) |
{ |
- T l1 = std::tolower( * p1 ++ ) ; |
- T l2 = std::tolower( * p2 ++ ) ; |
- if ( l1 == l2 ) |
+ T l1 = std::tolower(* p1 ++); |
+ T l2 = std::tolower(* p2 ++); |
+ if (l1 == l2) |
{ |
- continue ; |
+ continue; |
} |
- return ( l1 < l2 ) ? -1 : +1 ; |
+ return (l1 < l2) ? -1 : +1; |
} |
- return 0 ; |
+ return 0; |
} |
-} ; |
+}; |
-typedef std::basic_string< wchar_t, CaseInsensitiveTraits< wchar_t > > WstringCaseInsensitive ; |
+typedef std::basic_string<wchar_t, CaseInsensitiveTraits<wchar_t>> WstringCaseInsensitive; |
//------------------------------------------------------- |
// FileNameSet: case-insensitive wide-string set |
//------------------------------------------------------- |
struct FileNameSet |
- : public std::set< WstringCaseInsensitive > |
+ : public std::set<WstringCaseInsensitive> |
{ |
/** |
* Empty set constructor. |
@@ -80,15 +80,15 @@ |
/** |
* Constructor initialization from an array. |
*/ |
- template< size_t nFileNames > |
- FileNameSet( const wchar_t * ( & fileNameList )[ nFileNames ] ) |
+ template<size_t nFileNames> |
+ FileNameSet(const wchar_t* (& fileNameList)[nFileNames]) |
{ |
- for ( unsigned int j = 0 ; j < nFileNames ; ++ j ) |
+ for (unsigned int j = 0 ; j < nFileNames ; ++ j) |
{ |
- insert( WstringCaseInsensitive( fileNameList[ j ] ) ) ; |
+ insert(WstringCaseInsensitive(fileNameList[j])); |
} |
} |
-} ; |
+}; |
//------------------------------------------------------- |
//------------------------------------------------------- |
@@ -107,11 +107,11 @@ |
* and so also is this class. |
* Hence the lifetimes are coterminous, and the reference is not problematic. |
*/ |
- const FileNameSet & processNames; |
+ const FileNameSet& processNames; |
public: |
- bool operator()( const PROCESSENTRY32W & ); |
- ProcessByAnyExeNotImmersive(const FileNameSet & names) : processNames( names ) {} |
-} ; |
+ bool operator()(const PROCESSENTRY32W&); |
+ ProcessByAnyExeNotImmersive(const FileNameSet& names) : processNames(names) {} |
+}; |
//------------------------------------------------------- |
@@ -121,33 +121,42 @@ |
* A promiscuous filter admits everything. |
*/ |
struct EveryProcess |
- : public std::unary_function< PROCESSENTRY32W, bool > |
+ : public std::unary_function<PROCESSENTRY32W, bool> |
{ |
- bool operator()( const PROCESSENTRY32W & ) { return true ; } ; |
-} ; |
+ bool operator()(const PROCESSENTRY32W&) |
+ { |
+ return true ; |
+ }; |
+}; |
/** |
* Extractor that copies the entire process structure. |
*/ |
struct CopyAll |
- : public std::unary_function< PROCESSENTRY32W, PROCESSENTRY32W > |
+ : public std::unary_function<PROCESSENTRY32W, PROCESSENTRY32W> |
{ |
- PROCESSENTRY32W operator()( const PROCESSENTRY32W & process ) { return process ; } |
-} ; |
+ PROCESSENTRY32W operator()(const PROCESSENTRY32W& process) |
+ { |
+ return process ; |
+ } |
+}; |
/** |
* Extractor that copies only the PID. |
*/ |
struct CopyPID |
- : public std::unary_function< PROCESSENTRY32W, DWORD > |
+ : public std::unary_function<PROCESSENTRY32W, DWORD> |
{ |
- inline DWORD operator()( const PROCESSENTRY32W & process ) { return process.th32ProcessID ; } |
-} ; |
+ inline DWORD operator()(const PROCESSENTRY32W& process) |
+ { |
+ return process.th32ProcessID ; |
+ } |
+}; |
/** |
* Retrieve the process ID that created a window. |
* |
- * Wrapper around GetWindowThreadProcessId. |
+ * Wrapper around GetWindowThreadProcessId. |
* Converts an error return from the system call into an exception. |
* The system call can also retrieve the creating thread; we ignore it. |
* |
@@ -159,7 +168,7 @@ |
* \sa |
* MSDN [GetWindowThreadProcessId function](http://msdn.microsoft.com/en-us/library/windows/desktop/ms633522%28v=vs.85%29.aspx) |
*/ |
-DWORD CreatorProcess( HWND window ) ; |
+DWORD CreatorProcess(HWND window); |
//------------------------------------------------------- |
// Snapshot |
@@ -172,29 +181,29 @@ |
/** |
* The type of the data resulting from CreateToolhelp32Snapshot. |
*/ |
- typedef PROCESSENTRY32W ResultType ; |
+ typedef PROCESSENTRY32W ResultType; |
/** |
* Flags used to call CreateToolhelp32Snapshot. |
*/ |
- const static DWORD SnapshotFlags = TH32CS_SNAPPROCESS ; |
+ const static DWORD SnapshotFlags = TH32CS_SNAPPROCESS; |
/** |
* Wrapper for 'first' function for processes |
*/ |
- static BOOL First( HANDLE arg1, LPPROCESSENTRY32 arg2 ) |
+ static BOOL First(HANDLE arg1, LPPROCESSENTRY32 arg2) |
{ |
- return ::Process32First( arg1, arg2 ) ; |
+ return ::Process32First(arg1, arg2); |
} |
/** |
* Wrapper for 'next' function for processes |
*/ |
- static BOOL Next( HANDLE arg1, LPPROCESSENTRY32 arg2 ) |
+ static BOOL Next(HANDLE arg1, LPPROCESSENTRY32 arg2) |
{ |
- return ::Process32Next( arg1, arg2 ) ; |
+ return ::Process32Next(arg1, arg2); |
} |
-} ; |
+}; |
/** |
* Traits class for snapshots of all modules loaded by a process. |
@@ -204,29 +213,29 @@ |
/** |
* The type of the data resulting from CreateToolhelp32Snapshot. |
*/ |
- typedef MODULEENTRY32W ResultType ; |
+ typedef MODULEENTRY32W ResultType; |
/** |
* Flags used to call CreateToolhelp32Snapshot. |
*/ |
- const static DWORD SnapshotFlags = TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32 ; |
+ const static DWORD SnapshotFlags = TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32; |
/** |
* Wrapper for 'first' function for modules |
*/ |
- static BOOL First( HANDLE arg1, LPMODULEENTRY32 arg2 ) |
+ static BOOL First(HANDLE arg1, LPMODULEENTRY32 arg2) |
{ |
- return ::Module32First( arg1, arg2 ) ; |
+ return ::Module32First(arg1, arg2); |
} |
/** |
* Wrapper for 'next' function for modules |
*/ |
- static BOOL Next( HANDLE arg1, LPMODULEENTRY32 arg2 ) |
+ static BOOL Next(HANDLE arg1, LPMODULEENTRY32 arg2) |
{ |
- return ::Module32Next( arg1, arg2 ) ; |
+ return ::Module32Next(arg1, arg2); |
} |
-} ; |
+}; |
/** |
* A snapshot wrapping the results of CreateToolhelp32Snapshot system call. |
@@ -253,25 +262,25 @@ |
* That extension, however, does not go far enough to be able to declare a pointer with the same modifier. |
* Hence the system calls must be called directly; they are wrapped in the trait functions. |
*/ |
-template< class Traits > |
+template<class Traits> |
class Snapshot |
{ |
public: |
/** |
* Expose the result type from the traits class as our own. |
*/ |
- typedef typename Traits::ResultType ResultType ; |
+ typedef typename Traits::ResultType ResultType; |
private: |
/** |
* Process ID argument for CreateToolhelp32Snapshot. |
*/ |
- DWORD id ; |
+ DWORD id; |
/** |
* Handle to the underlying snapshot. |
*/ |
- WindowsHandle handle ; |
+ WindowsHandle handle; |
/** |
* Buffer for reading a single process entry out of the snapshot. |
@@ -287,7 +296,7 @@ |
* \par Implementation |
* Add "= delete" for C++11. |
*/ |
- Snapshot( const Snapshot & ) ; |
+ Snapshot(const Snapshot&); |
/** |
* Copy assignment declared private and not defined. |
@@ -295,30 +304,30 @@ |
* \par Implementation |
* Add "= delete" for C++11. |
*/ |
- Snapshot operator=( const Snapshot & ) ; |
+ Snapshot operator=(const Snapshot&); |
/** |
* Create a new snapshot and return its handle. |
*/ |
WindowsHandle::HandleType MakeHandle() |
{ |
- WindowsHandle::HandleType h = ::CreateToolhelp32Snapshot( Traits::SnapshotFlags, id ) ; |
- if ( h == INVALID_HANDLE_VALUE ) |
+ WindowsHandle::HandleType h = ::CreateToolhelp32Snapshot(Traits::SnapshotFlags, id); |
+ if (h == INVALID_HANDLE_VALUE) |
{ |
- throw WindowsApiError( "CreateToolhelp32Snapshot", "INVALID_HANDLE_VALUE" ) ; |
+ throw WindowsApiError("CreateToolhelp32Snapshot", "INVALID_HANDLE_VALUE"); |
} |
- return h ; |
+ return h; |
} |
protected: |
/** |
* Constructor takes a snapshot. |
*/ |
- Snapshot( DWORD id ) |
- : id( id ), handle( MakeHandle() ) |
+ Snapshot(DWORD id) |
+ : id(id), handle(MakeHandle()) |
{ |
// The various result types all define 'dwSize' with the same semantics. |
- buffer.dwSize = sizeof( ResultType ) ; |
+ buffer.dwSize = sizeof(ResultType); |
} |
public: |
@@ -349,7 +358,7 @@ |
* The upshot is that we rely that our implementation calls the right functions on the snapshot, |
* and so we ignore the case where we've passed bad arguments to the system call. |
*/ |
- const ResultType * First() |
+ const ResultType* First() |
{ |
return Traits::First(handle, &buffer) ? &buffer : 0; |
} |
@@ -365,33 +374,33 @@ |
* \par Design Note |
* See the Design Note for First(); the same considerations apply here. |
*/ |
- const ResultType * Next() |
+ const ResultType* Next() |
{ |
return Traits::Next(handle, &buffer) ? &buffer : 0; |
} |
-} ; |
+}; |
/** |
* A snapshot of all processes running on the system. |
*/ |
struct ProcessSnapshot |
- : public Snapshot< ProcessSnapshotTraits > |
+ : public Snapshot<ProcessSnapshotTraits> |
{ |
ProcessSnapshot() |
- : Snapshot( 0 ) |
+ : Snapshot(0) |
{} |
-} ; |
+}; |
/** |
* A snapshot of all modules loaded for a given process. |
*/ |
struct ModuleSnapshot |
- : public Snapshot< ModuleSnapshotTraits > |
+ : public Snapshot<ModuleSnapshotTraits> |
{ |
- ModuleSnapshot( DWORD processId ) |
- : Snapshot( processId ) |
+ ModuleSnapshot(DWORD processId) |
+ : Snapshot(processId) |
{} |
-} ; |
+}; |
//------------------------------------------------------- |
// InitializeProcessList |
@@ -401,17 +410,17 @@ |
* \tparam Admittance Function type for argument 'admit' |
* \tparam Extractor Function type for argument 'extract' |
* \param admit A unary predicate function class that determines what's included |
- * A process appears in the list only if the predicate returns true. |
- * The use of this predicate is analogous to that in std::copy_if. |
+ * A process appears in the list only if the predicate returns true. |
+ * The use of this predicate is analogous to that in std::copy_if. |
* \param convert A conversion function that takes a PROCESSENTRY32W as input argument and returns an element of type T. |
*/ |
template<class T, class Admittance, class Extractor> |
-void InitializeProcessList(std::vector<T>& v, ProcessSnapshot &snap, Admittance admit = Admittance(), Extractor extract = Extractor()) |
+void InitializeProcessList(std::vector<T>& v, ProcessSnapshot& snap, Admittance admit = Admittance(), Extractor extract = Extractor()) |
{ |
const PROCESSENTRY32W* p = snap.First(); |
while (p != 0) |
{ |
- if (admit(*p )) |
+ if (admit(*p)) |
{ |
/* |
* We don't have C++11 emplace_back, which can construct the element in place. |
@@ -431,12 +440,12 @@ |
* \tparam Admittance Function type for argument 'admit' |
* \tparam Extractor Function type for argument 'extract' |
* \param admit A unary predicate function class that determines what's included |
- * A process appears in the list only if the predicate returns true. |
- * The use of this predicate is analogous to that in std::copy_if. |
+ * A process appears in the list only if the predicate returns true. |
+ * The use of this predicate is analogous to that in std::copy_if. |
* \param convert A conversion function that takes a PROCESSENTRY32W as input argument and returns an element of type T. |
*/ |
template<class T, class Admittance, class Extractor> |
-void InitializeProcessSet(std::set< T > & set, ProcessSnapshot &snap, Admittance admit = Admittance(), Extractor extract = Extractor()) |
+void InitializeProcessSet(std::set<T>& set, ProcessSnapshot& snap, Admittance admit = Admittance(), Extractor extract = Extractor()) |
{ |
const PROCESSENTRY32W* p = snap.First(); |
while (p != 0) |
@@ -458,28 +467,28 @@ |
*/ |
typedef enum |
{ |
- started, ///< The iteration is currently running |
- normal, ///< Iteration terminated without error. |
- early, ///< Callback returned false and terminated iteration early. |
- exception, ///< Callback threw an exception and thereby terminated iteration. |
- error ///< Callback always return true but EnumWindows failed. |
-} EnumerateWindowsState ; |
+ started, ///< The iteration is currently running |
+ normal, ///< Iteration terminated without error. |
+ early, ///< Callback returned false and terminated iteration early. |
+ exception, ///< Callback threw an exception and thereby terminated iteration. |
+ error ///< Callback always return true but EnumWindows failed. |
+} EnumerateWindowsState; |
/** |
* Data to perform a window enumeration, shared between the main function and the callback function. |
*/ |
-template< class F > |
+template<class F> |
struct EWData |
{ |
/** |
* Function to be applied to each enumerated window. |
*/ |
- F & f ; |
+ F& f; |
/** |
* Completion status of the enumeration. |
*/ |
- EnumerateWindowsState status ; |
+ EnumerateWindowsState status; |
/** |
* An exception to be transported across the callback. |
@@ -487,22 +496,22 @@ |
* The enumerator and the callback are not guaranteed to share a call stack, |
* nor need they even share compatible exception conventions, |
* and might not even be in the same thread. |
- * Thus, if the applied function throws an exception, |
+ * Thus, if the applied function throws an exception, |
* we catch it in the callback and re-throw it in the enumerator. |
* This member holds such an exception. |
* |
* This member holds an exception only if 'status' has the value 'exception'. |
* Otherwise it's a null pointer. |
*/ |
- std::unique_ptr< std::exception > ee ; |
+ std::unique_ptr<std::exception> ee; |
/** |
* Ordinary constructor. |
*/ |
- EWData( F & f ) |
- : f( f ), status( started ) |
+ EWData(F& f) |
+ : f(f), status(started) |
{} |
-} ; |
+}; |
/** |
* Callback function for EnumWindows. |
@@ -511,81 +520,81 @@ |
* It records early termination of the enumeration, should that happen by the applied function returning false. |
* It captures any exception thrown for transport back to the enumerator. |
*/ |
-template< class F > |
-BOOL CALLBACK EnumerationCallback( HWND window, LPARAM x ) |
+template<class F> |
+BOOL CALLBACK EnumerationCallback(HWND window, LPARAM x) |
{ |
// LPARAM is always the same size as a pointer |
- EWData< F > * data = reinterpret_cast< EWData< F > * >( x ) ; |
+ EWData<F>* data = reinterpret_cast<EWData<F> *>(x); |
/* |
* Top-level try statement prevents exception from propagating back to system. |
*/ |
- try |
+ try |
{ |
- bool r = data -> f( window ) ; |
- if ( ! r ) |
+ bool r = data -> f(window); |
+ if (! r) |
{ |
- data -> status = early ; |
+ data -> status = early; |
} |
- return r ; |
+ return r; |
} |
- catch ( std::exception e ) |
+ catch (std::exception e) |
{ |
- data -> ee = std::unique_ptr< std::exception >( new( std::nothrow ) std::exception( e ) ) ; |
- data -> status = exception ; |
- return FALSE ; |
+ data -> ee = std::unique_ptr<std::exception>(new(std::nothrow) std::exception(e)); |
+ data -> status = exception; |
+ return FALSE; |
} |
- catch ( ... ) |
+ catch (...) |
{ |
- data -> ee = std::unique_ptr< std::exception >() ; |
- data -> status = exception ; |
- return FALSE ; |
+ data -> ee = std::unique_ptr<std::exception>(); |
+ data -> status = exception; |
+ return FALSE; |
} |
} |
/** |
* Enumerate windows, applying a function to each one. |
*/ |
-template< class F > |
-bool EnumerateWindows( F f ) |
+template<class F> |
+bool EnumerateWindows(F f) |
{ |
- EWData< F > data( f ) ; |
- BOOL x( ::EnumWindows( EnumerationCallback< F >, reinterpret_cast< LPARAM >( & data ) ) ) ; |
- bool r ; |
- if ( data.status != started ) |
+ EWData<F> data(f); |
+ BOOL x(::EnumWindows(EnumerationCallback<F>, reinterpret_cast<LPARAM>(& data))); |
+ bool r; |
+ if (data.status != started) |
{ |
// Assert status was changed within the callback |
- if ( data.status == exception ) |
+ if (data.status == exception) |
{ |
/* |
* The callback threw an exception of some sort. |
* We forward it to the extent we are able. |
*/ |
- if ( data.ee ) |
+ if (data.ee) |
{ |
- throw * data.ee ; |
+ throw* data.ee; |
} |
else |
{ |
- throw std::runtime_error( "Unknown exception thrown in callback function." ) ; |
+ throw std::runtime_error("Unknown exception thrown in callback function."); |
} |
} |
- r = false ; |
+ r = false; |
} |
else |
{ |
- if ( x ) |
+ if (x) |
{ |
- data.status = normal ; |
- r = true ; |
+ data.status = normal; |
+ r = true; |
} |
else |
{ |
// Assert EnumWindows failed |
- data.status = error ; |
- r = false ; |
+ data.status = error; |
+ r = false; |
} |
} |
- return r ; |
+ return r; |
} |
//------------------------------------------------------- |
@@ -596,7 +605,7 @@ |
/** |
* Set of process identifiers matching one of the executable names. |
*/ |
- std::set< DWORD > pidSet ; |
+ std::set<DWORD> pidSet; |
/** |
* Set of executable names by which to filter. |
@@ -604,64 +613,64 @@ |
* The argument of the filter constructor is a set by reference. |
* Since it does not make a copy for itself, we define it as a class member to provide its allocation. |
*/ |
- FileNameSet processNames ; |
+ FileNameSet processNames; |
- ProcessByAnyExeNotImmersive filter ; |
+ ProcessByAnyExeNotImmersive filter; |
/** |
* Copy function object copies just the process ID. |
*/ |
- CopyPID copy ; |
+ CopyPID copy; |
- /** |
+ /** |
* Snapshot of running processes. |
*/ |
- ProcessSnapshot & snapshot ; |
+ ProcessSnapshot& snapshot; |
void update() |
{ |
- InitializeProcessSet( pidSet, snapshot, filter, copy ) ; |
- } ; |
+ InitializeProcessSet(pidSet, snapshot, filter, copy); |
+ }; |
- template< class F > |
+ template<class F> |
class OnlyOurProcesses |
{ |
- ProcessCloser & self ; |
+ ProcessCloser& self; |
- F f ; |
+ F f; |
public: |
- OnlyOurProcesses( ProcessCloser & self, F f ) |
- : f( f ), self( self ) |
+ OnlyOurProcesses(ProcessCloser& self, F f) |
+ : f(f), self(self) |
{} |
- bool operator()( HWND window ) |
+ bool operator()(HWND window) |
{ |
- bool b ; |
+ bool b; |
try |
{ |
- b = self.Contains( CreatorProcess( window ) ) ; |
+ b = self.Contains(CreatorProcess(window)); |
} |
- catch ( ... ) |
+ catch (...) |
{ |
// ignore window handles that are no longer valid |
- return true ; |
+ return true; |
} |
- if ( ! b ) |
+ if (! b) |
{ |
// Assert the process that created the window is not in our pidSet |
- return true ; |
+ return true; |
} |
- return f( window ) ; |
+ return f(window); |
} |
- } ; |
+ }; |
public: |
template <size_t nFileNames> |
- ProcessCloser(ProcessSnapshot & snapshot, const wchar_t * (&fileNameList)[nFileNames]) |
+ ProcessCloser(ProcessSnapshot& snapshot, const wchar_t* (&fileNameList)[nFileNames]) |
: snapshot(snapshot), processNames(fileNameList), filter(processNames) |
{ |
- update() ; |
+ update(); |
} |
/** |
@@ -669,19 +678,25 @@ |
*/ |
void Refresh() |
{ |
- pidSet.clear() ; |
- update() ; |
+ pidSet.clear(); |
+ update(); |
} |
- bool IsRunning() { return ! pidSet.empty() ; } ; |
+ bool IsRunning() |
+ { |
+ return ! pidSet.empty() ; |
+ }; |
- bool Contains( DWORD pid ) const { return pidSet.find( pid ) != pidSet.end() ; } ; |
+ bool Contains(DWORD pid) const |
+ { |
+ return pidSet.find(pid) != pidSet.end() ; |
+ }; |
- template< class F > |
- bool IterateOurWindows( F f ) |
+ template<class F> |
+ bool IterateOurWindows(F f) |
{ |
- OnlyOurProcesses< F > g( * this, f ) ; |
- return EnumerateWindows( g ) ; |
+ OnlyOurProcesses<F> g(* this, f); |
+ return EnumerateWindows(g); |
} |
/* |
@@ -689,6 +704,6 @@ |
*/ |
bool ShutDown(ImmediateSession& session); |
-} ; |
+}; |
#endif |