#include <dlog/dlog.h>
#include <fstream>
+#include <iostream>
#include <regex>
#include <sstream>
LogRecorder::LogRecorder()
{
- mMessages.assign(MAX_LOG_MESSAGES, std::string());
+ mMainMessages.assign(MAX_LOG_MESSAGES, std::string());
+ mAllMessages.assign(MAX_LOG_MESSAGES, std::string());
}
LogRecorder::~LogRecorder()
{
mCounter.store(0);
mIsRunning.store(true);
+ mIsPrinting.store(false);
+ mMainThreadId = std::this_thread::get_id();
+
mPrintThread = std::thread([this]() {
pthread_t thread = pthread_self();
pthread_setname_np(thread, "log-recorder-thread");
std::this_thread::sleep_for(std::chrono::seconds(1));
mCounter.fetch_add(1);
if (mCounter.load() > MAX_TIMER_COUNTER) {
+ mIsPrinting.store(true);
dlog_print(DLOG_ERROR, LOG_TAG, "Counter : %d, printing recorded logs ===", mCounter.load());
+ std::cerr << "Counter : " << mCounter.load() << "printing recorded logs ===" << std::endl;
std::lock_guard<std::mutex> lock(mMutex);
- for (auto message : mMessages) {
+ int index = 0;
+ for (auto message : mMainMessages) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
+ dlog_print(DLOG_ERROR, LOG_TAG, "M[%d], %s", ++index, message.c_str());
std::this_thread::sleep_for(std::chrono::milliseconds(10));
- dlog_print(DLOG_ERROR, LOG_TAG, "%s", message.c_str());
+ std::cerr << message << std::endl;
+ if (mCounter.load() <= 0) {
+ break;
+ }
+ }
+ index = 0;
+ for (auto message : mAllMessages) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
+ dlog_print(DLOG_ERROR, LOG_TAG, "A[%d], %s", ++index, message.c_str());
if (mCounter <= 0) {
break;
}
}
- mCounter.store(0);
dlog_print(DLOG_ERROR, LOG_TAG, "Counter is now 0, printed recorded logs ===");
+ std::cerr << "Counter is now 0, printed recorded logs ===" << std::endl;
print_esp_eip();
+
+ mCounter.store(0);
+ mIsPrinting.store(false);
}
if (localCounter++ > 10) {
dlog_print(DLOG_ERROR, LOG_TAG, "Log recorder is running");
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
+ std::cerr << "Log recorder is running" << std::endl;
localCounter = 0;
}
}
});
+ mInitialized.store(true);
}
void LogRecorder::deinitialize()
{
mCounter.store(0);
mIsRunning.store(false);
- mPrintThread.join();
+ if (mPrintThread.joinable()) {
+ mPrintThread.join();
+ }
+ mInitialized.store(false);
}
void LogRecorder::resetCounter()
void LogRecorder::addMessage(const char *format, ...)
{
+ if (!mInitialized.load()) return;
+
const int BUFFER_SIZE = 256;
char buffer[BUFFER_SIZE];
va_list args;
vsnprintf(buffer, BUFFER_SIZE, format, args);
va_end(args);
- std::lock_guard<std::mutex> lock(mMutex);
- mMessages.pop_front();
- mMessages.push_back(std::string(buffer));
+ if (!mIsPrinting.load()) {
+ std::lock_guard<std::mutex> lock(mMutex);
+
+ std::thread::id this_id = std::this_thread::get_id();
+ if (this_id == mMainThreadId) {
+ if (!mMainMessages.empty()) mMainMessages.pop_back();
+ mMainMessages.push_front(std::string(buffer));
+ }
+ if (!mAllMessages.empty()) mAllMessages.pop_back();
+ mAllMessages.push_front(std::string(buffer));
+ }
}
#endif // LOG_RECORDER_ENABLED
#include <sys/resource.h>
#include <algorithm>
+#include <iostream>
#include <map>
#include <Ecore.h>
int CAudioManager::initialize(void)
{
- sound_manager_add_focus_state_watch_cb(SOUND_STREAM_FOCUS_FOR_RECORDING,
- recording_focus_state_watch_cb, this, &mSoundFocusWatchId);
return 0;
}
}
}
- sound_manager_remove_focus_state_watch_cb(mSoundFocusWatchId);
+ return 0;
+}
+
+int CAudioManager::activate(void)
+{
+ MWR_LOGE("[ENTER]");
+ std::cerr << "CAudioManager activation started" << std::endl;
+ sound_manager_add_focus_state_watch_cb(SOUND_STREAM_FOCUS_FOR_RECORDING,
+ recording_focus_state_watch_cb, this, &mSoundFocusWatchId);
+ std::cerr << "CAudioManager activation finished" << std::endl;
+ MWR_LOGE("[END]");
return 0;
}
+int CAudioManager::deactivate(void)
+{
+ sound_manager_remove_focus_state_watch_cb(mSoundFocusWatchId);
+ return 0;
+}
+
void CAudioManager::sound_focus_changed()
{
sound_stream_focus_change_reason_e acquired_by;
MWR_LOGE("[ENTER]");
std::cerr << "WakeupManager Initialize" << std::endl;
+#ifdef LOG_RECORDER_ENABLED
+ LogRecorder::getInstance().initialize();
+ mPeriodicLogRecorderResetTimer = ecore_timer_add(1.0f, periodic_log_recorder_reset, nullptr);
+#endif // LOG_RECORDER_ENABLED
+
mPolicyEventObserver.set_wakeup_manager(this);
mEngineEventObserver.set_wakeup_manager(this);
mAudioEventObserver.set_wakeup_manager(this);
initialize_wakeup_policy();
start_periodic_monitor_timer();
-#ifdef LOG_RECORDER_ENABLED
- LogRecorder::getInstance().initialize();
- mPeriodicLogRecorderResetTimer = ecore_timer_add(1.0f, periodic_log_recorder_reset, nullptr);
-#endif // LOG_RECORDER_ENABLED
-
MWR_LOGD("[END]");
return true;
}
{
MWR_LOGI("[ENTER]");
+ mAudioManager.activate();
+
if (WAKEUP_MANAGER_STATE_INACTIVE != mWakeupManagerState)
return false;
stop_streaming_previous_utterance_data();
stop_streaming_follow_up_data();
+ mAudioManager.deactivate();
+
MWR_LOGD("[END]");
return true;
}