1 : // Copyright 2012 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 : // Defines the template member function of the application::Application template
16 : // class.
17 : //
18 : // This is not meant to be included directly.
19 :
20 : #ifndef SYZYGY_APPLICATION_APPLICATION_IMPL_H_
21 : #define SYZYGY_APPLICATION_APPLICATION_IMPL_H_
22 :
23 : #include "base/win/scoped_com_initializer.h"
24 : #include "syzygy/version/syzygy_version.h"
25 :
26 : namespace application {
27 :
28 : template <typename Impl, AppLoggingFlag kInitLogging>
29 : Application<Impl, kInitLogging>::Application()
30 E : : command_line_(base::CommandLine::ForCurrentProcess()) {
31 E : }
32 :
33 : template <typename Impl, AppLoggingFlag kInitLogging>
34 E : int Application<Impl, kInitLogging>::Run() {
35 : // If we've been asked for our version, spit it out and quit.
36 E : if (command_line_->HasSwitch("version")) {
37 : ::fprintf(out(), "%s\n",
38 i : version::kSyzygyVersion.GetVersionString().c_str());
39 i : return 0;
40 : }
41 :
42 E : if (!InitializeLogging())
43 i : return 1;
44 :
45 E : if (!command_line_->HasSwitch("no-logo")) {
46 E : LOG(INFO) << "Syzygy " << implementation_.name() << " Version "
47 : << version::kSyzygyVersion.GetVersionString() << ".";
48 E : LOG(INFO) << "Copyright (c) Google Inc. All rights reserved.";
49 : }
50 :
51 E : base::win::ScopedCOMInitializer com_initializer;
52 E : if (!com_initializer.succeeded())
53 i : return 1;
54 :
55 E : if (!implementation_.ParseCommandLine(command_line_))
56 E : return 1;
57 :
58 E : if (!implementation_.SetUp())
59 E : return 1;
60 :
61 E : int result = implementation_.Run();
62 :
63 E : implementation_.TearDown();
64 :
65 E : return result;
66 E : }
67 :
68 : template <typename Impl, AppLoggingFlag kInitLogging>
69 E : bool Application<Impl, kInitLogging>::InitializeLogging() {
70 E : logging::LoggingSettings settings;
71 E : settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
72 E : settings.lock_log = logging::DONT_LOCK_LOG_FILE;
73 E : settings.delete_old = logging::APPEND_TO_OLD_LOG_FILE;
74 : if ((kInitLogging == INIT_LOGGING_YES) &&
75 E : !logging::InitLogging(settings)) {
76 i : return false;
77 : }
78 :
79 E : if (command_line_->HasSwitch("verbose")) {
80 E : std::string value_str(command_line_->GetSwitchValueASCII("verbose"));
81 E : base::TrimWhitespaceASCII(value_str, base::TRIM_ALL, &value_str);
82 E : int value = 1;
83 E : if (!base::StringToInt(value_str, &value))
84 i : value = 1;
85 E : logging::SetMinLogLevel(-::abs(value));
86 E : }
87 :
88 E : if (command_line_->HasSwitch("quiet"))
89 i : logging::SetMinLogLevel(logging::LOG_ERROR);
90 :
91 E : return true;
92 E : }
93 :
94 : } // namespace application
95 :
96 : #endif // SYZYGY_APPLICATION_APPLICATION_IMPL_H_
|