summaryrefslogtreecommitdiff
path: root/src/components/media_manager/src/pipe_streamer_adapter.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/media_manager/src/pipe_streamer_adapter.cc')
-rw-r--r--src/components/media_manager/src/pipe_streamer_adapter.cc70
1 files changed, 37 insertions, 33 deletions
diff --git a/src/components/media_manager/src/pipe_streamer_adapter.cc b/src/components/media_manager/src/pipe_streamer_adapter.cc
index 43f0d7153..5990428c6 100644
--- a/src/components/media_manager/src/pipe_streamer_adapter.cc
+++ b/src/components/media_manager/src/pipe_streamer_adapter.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Ford Motor Company
+ * Copyright (c) 2014, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,32 +41,34 @@
namespace media_manager {
-CREATE_LOGGERPTR_GLOBAL(logger, "PipeStreamerAdapter")
+CREATE_LOGGERPTR_GLOBAL(logger_, "PipeStreamerAdapter")
PipeStreamerAdapter::PipeStreamerAdapter()
: is_ready_(false),
- thread_(NULL),
+ thread_(threads::CreateThread("PipeStreamer", new Streamer(this))),
messages_() {
- LOG4CXX_INFO(logger, "PipeStreamerAdapter::PipeStreamerAdapter");
+ LOG4CXX_AUTO_TRACE(logger_);
}
PipeStreamerAdapter::~PipeStreamerAdapter() {
- LOG4CXX_INFO(logger, "PipeStreamerAdapter::~PipeStreamerAdapter");
+ LOG4CXX_AUTO_TRACE(logger_);
if ((0 != current_application_ ) && (is_ready_)) {
StopActivity(current_application_);
}
- thread_->stop();
+ thread_->join();
+ delete thread_->delegate();
+ threads::DeleteThread(thread_);
}
void PipeStreamerAdapter::SendData(
int32_t application_key,
const ::protocol_handler::RawMessagePtr message) {
- LOG4CXX_INFO(logger, "PipeStreamerAdapter::SendData");
+ LOG4CXX_AUTO_TRACE(logger_);
if (application_key != current_application_) {
- LOG4CXX_WARN(logger, "Wrong application " << application_key);
+ LOG4CXX_WARN(logger_, "Wrong application " << application_key);
return;
}
@@ -76,10 +78,10 @@ void PipeStreamerAdapter::SendData(
}
void PipeStreamerAdapter::StartActivity(int32_t application_key) {
- LOG4CXX_INFO(logger, "PipeStreamerAdapter::StartActivity");
+ LOG4CXX_AUTO_TRACE(logger_);
if (application_key == current_application_) {
- LOG4CXX_WARN(logger, "Already started activity for " << application_key);
+ LOG4CXX_WARN(logger_, "Already started activity for " << application_key);
return;
}
@@ -92,20 +94,22 @@ void PipeStreamerAdapter::StartActivity(int32_t application_key) {
(*it)->OnActivityStarted(application_key);
}
- LOG4CXX_TRACE(logger, "Pipe was opened for writing " << named_pipe_path_);
+ LOG4CXX_DEBUG(logger_, "Pipe was opened for writing " << named_pipe_path_);
}
void PipeStreamerAdapter::StopActivity(int32_t application_key) {
- LOG4CXX_INFO(logger, "PipeStreamerAdapter::StopActivity");
+ LOG4CXX_AUTO_TRACE(logger_);
if (application_key != current_application_) {
- LOG4CXX_WARN(logger, "Not performing activity for " << application_key);
+ LOG4CXX_WARN(logger_, "Not performing activity for " << application_key);
return;
}
is_ready_ = false;
current_application_ = 0;
+ messages_.Reset();
+
for (std::set<MediaListenerPtr>::iterator it = media_listeners_.begin();
media_listeners_.end() != it;
++it) {
@@ -113,18 +117,19 @@ void PipeStreamerAdapter::StopActivity(int32_t application_key) {
}
}
-bool PipeStreamerAdapter::is_app_performing_activity(
- int32_t application_key) {
+bool PipeStreamerAdapter::is_app_performing_activity( int32_t application_key) {
return (application_key == current_application_);
}
void PipeStreamerAdapter::Init() {
- if (!thread_) {
- LOG4CXX_INFO(logger, "Create and start sending thread");
- thread_ = threads::CreateThread("PipeStreamer", new Streamer(this));
- const size_t kStackSize = 16384;
- thread_->startWithOptions(threads::ThreadOptions(kStackSize));
+ LOG4CXX_AUTO_TRACE(logger_);
+ if (thread_->is_running()) {
+ thread_->stop();
+ thread_->join();
}
+ LOG4CXX_DEBUG(logger_, "Start sending thread");
+ const size_t kStackSize = 16384;
+ thread_->start(threads::ThreadOptions(kStackSize));
}
PipeStreamerAdapter::Streamer::Streamer(
@@ -139,7 +144,7 @@ PipeStreamerAdapter::Streamer::~Streamer() {
}
void PipeStreamerAdapter::Streamer::threadMain() {
- LOG4CXX_INFO(logger, "Streamer::threadMain");
+ LOG4CXX_AUTO_TRACE(logger_);
open();
@@ -147,7 +152,7 @@ void PipeStreamerAdapter::Streamer::threadMain() {
while (!server_->messages_.empty()) {
::protocol_handler::RawMessagePtr msg = server_->messages_.pop();
if (!msg) {
- LOG4CXX_ERROR(logger, "Null pointer message");
+ LOG4CXX_ERROR(logger_, "Null pointer message");
continue;
}
@@ -155,7 +160,7 @@ void PipeStreamerAdapter::Streamer::threadMain() {
msg.get()->data_size());
if (ret == -1) {
- LOG4CXX_ERROR(logger, "Failed writing data to pipe "
+ LOG4CXX_ERROR(logger_, "Failed writing data to pipe "
<< server_->named_pipe_path_);
std::set<MediaListenerPtr>::iterator it =
@@ -164,14 +169,14 @@ void PipeStreamerAdapter::Streamer::threadMain() {
(*it)->OnErrorReceived(server_->current_application_, -1);
}
} else if (static_cast<uint32_t>(ret) != msg.get()->data_size()) {
- LOG4CXX_WARN(logger, "Couldn't write all the data to pipe "
+ LOG4CXX_WARN(logger_, "Couldn't write all the data to pipe "
<< server_->named_pipe_path_);
}
static int32_t messsages_for_session = 0;
++messsages_for_session;
- LOG4CXX_INFO(logger, "Handling map streaming message. This is "
+ LOG4CXX_DEBUG(logger_, "Handling map streaming message. This is "
<< messsages_for_session << " the message for "
<< server_->current_application_);
std::set<MediaListenerPtr>::iterator it =
@@ -186,16 +191,14 @@ void PipeStreamerAdapter::Streamer::threadMain() {
close();
}
-bool PipeStreamerAdapter::Streamer::exitThreadMain() {
- LOG4CXX_INFO(logger, "Streamer::exitThreadMain");
+void PipeStreamerAdapter::Streamer::exitThreadMain() {
+ LOG4CXX_AUTO_TRACE(logger_);
stop_flag_ = true;
server_->messages_.Shutdown();
- return false;
}
void PipeStreamerAdapter::Streamer::open() {
-
- LOG4CXX_INFO(logger, "Streamer::open() " << server_->named_pipe_path_.c_str());
+ LOG4CXX_AUTO_TRACE(logger_);
DCHECK(file_system::CreateDirectoryRecursively(
profile::Profile::instance()->app_storage_folder()));
@@ -203,22 +206,23 @@ void PipeStreamerAdapter::Streamer::open() {
if ((mkfifo(server_->named_pipe_path_.c_str(),
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0)
&& (errno != EEXIST)) {
- LOG4CXX_ERROR(logger, "Cannot create pipe " << server_->named_pipe_path_);
+ LOG4CXX_ERROR(logger_, "Cannot create pipe " << server_->named_pipe_path_);
return;
}
pipe_fd_ = ::open(server_->named_pipe_path_.c_str(), O_RDWR, 0);
if (-1 == pipe_fd_) {
- LOG4CXX_ERROR(logger, "Cannot open pipe for writing "
+ LOG4CXX_ERROR(logger_, "Cannot open pipe for writing "
<< server_->named_pipe_path_);
return;
}
- LOG4CXX_TRACE(logger, "Pipe " << server_->named_pipe_path_
+ LOG4CXX_DEBUG(logger_, "Pipe " << server_->named_pipe_path_
<< " was successfully created");
}
void PipeStreamerAdapter::Streamer::close() {
+ LOG4CXX_AUTO_TRACE(logger_);
::close(pipe_fd_);
unlink(server_->named_pipe_path_.c_str());
}