1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
diff -ux '*.txt' -r SampleApp_org/include/SampleApp/SampleApplication.h SampleApp_patched/include/SampleApp/SampleApplication.h
--- SampleApp_org/include/SampleApp/SampleApplication.h 2018-12-19 20:13:36.000000000 +0100
+++ SampleApp_patched/include/SampleApp/SampleApplication.h 2019-02-09 13:43:59.973245132 +0100
@@ -67,7 +67,8 @@
std::shared_ptr<alexaClientSDK::sampleApp::ConsoleReader> consoleReader,
const std::vector<std::string>& configFiles,
const std::string& pathToInputFolder,
- const std::string& logLevel = "");
+ const std::string& logLevel = "",
+ bool headless = false);
/**
* Runs the application, blocking until the user asks the application to quit or a device reset is triggered.
@@ -158,7 +159,8 @@
std::shared_ptr<alexaClientSDK::sampleApp::ConsoleReader> consoleReader,
const std::vector<std::string>& configFiles,
const std::string& pathToInputFolder,
- const std::string& logLevel);
+ const std::string& logLevel,
+ bool headless);
/**
* Create an application media player.
diff -ux '*.txt' -r SampleApp_org/include/SampleApp/UserInputManager.h SampleApp_patched/include/SampleApp/UserInputManager.h
--- SampleApp_org/include/SampleApp/UserInputManager.h 2018-12-19 20:13:36.000000000 +0100
+++ SampleApp_patched/include/SampleApp/UserInputManager.h 2019-02-09 13:43:59.973245132 +0100
@@ -43,7 +43,8 @@
*/
static std::unique_ptr<UserInputManager> create(
std::shared_ptr<InteractionManager> interactionManager,
- std::shared_ptr<ConsoleReader> consoleReader);
+ std::shared_ptr<ConsoleReader> consoleReader,
+ bool headless);
/**
* Processes user input until a quit command or a device reset is triggered.
@@ -63,7 +64,8 @@
*/
UserInputManager(
std::shared_ptr<InteractionManager> interactionManager,
- std::shared_ptr<ConsoleReader> consoleReader);
+ std::shared_ptr<ConsoleReader> consoleReader,
+ bool headless);
/**
* Reads an input from the console. This is a blocking call until an input is read from the console or if m_restart
@@ -127,6 +129,8 @@
/// the app.
std::atomic_bool m_limitedInteraction;
+ bool headless;
+
/// Flag to indicate that the @c run() should stop and return @c SampleAppReturnCode::RESTART.
std::atomic_bool m_restart;
};
diff -ux '*.txt' -r SampleApp_org/src/main.cpp SampleApp_patched/src/main.cpp
--- SampleApp_org/src/main.cpp 2018-12-19 20:13:36.000000000 +0100
+++ SampleApp_patched/src/main.cpp 2019-02-09 13:43:59.976578511 +0100
@@ -51,6 +51,7 @@
std::vector<std::string> configFiles;
std::string pathToKWDInputFolder;
std::string logLevel;
+ bool headless = false;
if (usesOptStyleArgs(argc, argv)) {
for (int i = 1; i < argc; i++) {
@@ -73,6 +74,8 @@
return SampleAppReturnCode::ERROR;
}
logLevel = std::string(argv[++i]);
+ } else if (strcmp(argv[i], "--headless") == 0) {
+ headless = true;
} else {
ConsolePrinter::simplePrint(
"USAGE: " + std::string(argv[0]) + " -C <config1.json> -C <config2.json> ... -C <configN.json> " +
@@ -114,7 +117,7 @@
SampleAppReturnCode returnCode = SampleAppReturnCode::OK;
do {
- sampleApplication = SampleApplication::create(consoleReader, configFiles, pathToKWDInputFolder, logLevel);
+ sampleApplication = SampleApplication::create(consoleReader, configFiles, pathToKWDInputFolder, logLevel, headless);
if (!sampleApplication) {
ConsolePrinter::simplePrint("Failed to create to SampleApplication!");
return SampleAppReturnCode::ERROR;
diff -ux '*.txt' -r SampleApp_org/src/SampleApplication.cpp SampleApp_patched/src/SampleApplication.cpp
--- SampleApp_org/src/SampleApplication.cpp 2018-12-19 20:13:36.000000000 +0100
+++ SampleApp_patched/src/SampleApplication.cpp 2019-02-09 13:43:59.976578511 +0100
@@ -202,9 +202,10 @@
std::shared_ptr<alexaClientSDK::sampleApp::ConsoleReader> consoleReader,
const std::vector<std::string>& configFiles,
const std::string& pathToInputFolder,
- const std::string& logLevel) {
+ const std::string& logLevel,
+ const bool headless) {
auto clientApplication = std::unique_ptr<SampleApplication>(new SampleApplication);
- if (!clientApplication->initialize(consoleReader, configFiles, pathToInputFolder, logLevel)) {
+ if (!clientApplication->initialize(consoleReader, configFiles, pathToInputFolder, logLevel, headless)) {
ACSDK_CRITICAL(LX("Failed to initialize SampleApplication"));
return nullptr;
}
@@ -321,7 +322,8 @@
std::shared_ptr<alexaClientSDK::sampleApp::ConsoleReader> consoleReader,
const std::vector<std::string>& configFiles,
const std::string& pathToInputFolder,
- const std::string& logLevel) {
+ const std::string& logLevel,
+ bool headless) {
/*
* Set up the SDK logging system to write to the SampleApp's ConsolePrinter. Also adjust the logging level
* if requested.
@@ -854,7 +856,7 @@
#endif
// Creating the input observer.
- m_userInputManager = alexaClientSDK::sampleApp::UserInputManager::create(m_interactionManager, consoleReader);
+ m_userInputManager = alexaClientSDK::sampleApp::UserInputManager::create(m_interactionManager, consoleReader, headless);
if (!m_userInputManager) {
ACSDK_CRITICAL(LX("Failed to create UserInputManager!"));
return false;
diff -ux '*.txt' -r SampleApp_org/src/UserInputManager.cpp SampleApp_patched/src/UserInputManager.cpp
--- SampleApp_org/src/UserInputManager.cpp 2018-12-19 20:13:36.000000000 +0100
+++ SampleApp_patched/src/UserInputManager.cpp 2019-02-09 13:43:59.976578511 +0100
@@ -96,7 +96,8 @@
std::unique_ptr<UserInputManager> UserInputManager::create(
std::shared_ptr<InteractionManager> interactionManager,
- std::shared_ptr<ConsoleReader> consoleReader) {
+ std::shared_ptr<ConsoleReader> consoleReader,
+ bool headless) {
if (!interactionManager) {
ACSDK_CRITICAL(LX("Invalid InteractionManager passed to UserInputManager"));
return nullptr;
@@ -107,15 +108,17 @@
return nullptr;
}
- return std::unique_ptr<UserInputManager>(new UserInputManager(interactionManager, consoleReader));
+ return std::unique_ptr<UserInputManager>(new UserInputManager(interactionManager, consoleReader, headless));
}
UserInputManager::UserInputManager(
std::shared_ptr<InteractionManager> interactionManager,
- std::shared_ptr<ConsoleReader> consoleReader) :
+ std::shared_ptr<ConsoleReader> consoleReader,
+ bool headless) :
m_interactionManager{interactionManager},
m_consoleReader{consoleReader},
m_limitedInteraction{false},
+ headless{headless},
m_restart{false} {
}
@@ -132,6 +135,10 @@
bool userTriggeredLogout = false;
m_interactionManager->begin();
while (true) {
+ if (headless) {
+ std::this_thread::sleep_for(std::chrono::hours(100));
+ continue;
+ }
char x;
if (!readConsoleInput(&x)) {
break;
|