1 : // Copyright 2013 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Helper functions for Service implementations.
16 :
17 : #ifndef SYZYGY_TRACE_COMMON_SERVICE_UTIL_H_
18 : #define SYZYGY_TRACE_COMMON_SERVICE_UTIL_H_
19 :
20 : #include "base/command_line.h"
21 : #include "base/memory/scoped_ptr.h"
22 : #include "base/strings/string_piece.h"
23 : #include "base/win/scoped_handle.h"
24 :
25 m : namespace trace {
26 m : namespace common {
27 :
28 : // Helper function to acquire a named mutex. Once acquired this mutex must be
29 : // freed using ::ReleaseMutex.
30 : // @param mutex_name The name of the mutex to acquire.
31 : // @param mutex will receive a handle to the named mutex.
32 : // @returns true on success, false otherwise. Logs verbosely on failure.
33 m : bool AcquireMutex(const base::StringPiece16& mutex_name,
34 m : base::win::ScopedHandle* mutex);
35 :
36 : // Helper function to initialize a named event. The event will automatically be
37 : // destroyed when the last handle to it disappears.
38 : // @param event_name The name of event to create.
39 : // @param handle Will receive a handle to the named event.
40 : // @returns true on success, false otherwise. Logs verbosely on failure.
41 m : bool InitEvent(const base::StringPiece16& event_name,
42 m : base::win::ScopedHandle* handle);
43 :
44 : // A helper to split a command line into two command lines. The split will
45 : // occur after the first non-switch parameter. The logger command line will
46 : // be populated by the switches and arguments up to and including the first
47 : // non-switch parameter. All remaining arguments and switches will be added
48 : // to the app command line. This function understands the "--" marker
49 : // which is used to allow switches to appear after the first non-switch
50 : // argument (otherwise CommandLine will sort the entire command line before
51 : // we get a chance to inspect it.).
52 m : bool SplitCommandLine(const CommandLine* orig_command_line,
53 m : CommandLine* logger_command_line,
54 m : scoped_ptr<CommandLine>* app_command_line);
55 :
56 : // A helper class to manage a console handler for Control-C.
57 m : class ScopedConsoleCtrlHandler {
58 m : public:
59 m : ScopedConsoleCtrlHandler();
60 m : ~ScopedConsoleCtrlHandler();
61 m : bool Init(PHANDLER_ROUTINE handler);
62 :
63 m : protected:
64 m : PHANDLER_ROUTINE handler_;
65 m : };
66 :
67 m : } // namespace common
68 m : } // namespace trace
69 :
70 : #endif // SYZYGY_TRACE_COMMON_SERVICE_UTIL_H_
|