diff options
Diffstat (limited to 'src/components/media_manager/src/pipe_streamer_adapter.cc')
-rw-r--r-- | src/components/media_manager/src/pipe_streamer_adapter.cc | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/src/components/media_manager/src/pipe_streamer_adapter.cc b/src/components/media_manager/src/pipe_streamer_adapter.cc index c1a0e1fa20..43f0d71530 100644 --- a/src/components/media_manager/src/pipe_streamer_adapter.cc +++ b/src/components/media_manager/src/pipe_streamer_adapter.cc @@ -41,34 +41,32 @@ namespace media_manager { -CREATE_LOGGERPTR_GLOBAL(logger_, "PipeStreamerAdapter") +CREATE_LOGGERPTR_GLOBAL(logger, "PipeStreamerAdapter") PipeStreamerAdapter::PipeStreamerAdapter() : is_ready_(false), - thread_(threads::CreateThread("PipeStreamer", new Streamer(this))), + thread_(NULL), messages_() { - LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_INFO(logger, "PipeStreamerAdapter::PipeStreamerAdapter"); } PipeStreamerAdapter::~PipeStreamerAdapter() { - LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_INFO(logger, "PipeStreamerAdapter::~PipeStreamerAdapter"); if ((0 != current_application_ ) && (is_ready_)) { StopActivity(current_application_); } - thread_->join(); - delete thread_->delegate(); - threads::DeleteThread(thread_); + thread_->stop(); } void PipeStreamerAdapter::SendData( int32_t application_key, const ::protocol_handler::RawMessagePtr message) { - LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_INFO(logger, "PipeStreamerAdapter::SendData"); if (application_key != current_application_) { - LOG4CXX_WARN(logger_, "Wrong application " << application_key); + LOG4CXX_WARN(logger, "Wrong application " << application_key); return; } @@ -78,10 +76,10 @@ void PipeStreamerAdapter::SendData( } void PipeStreamerAdapter::StartActivity(int32_t application_key) { - LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_INFO(logger, "PipeStreamerAdapter::StartActivity"); if (application_key == current_application_) { - LOG4CXX_WARN(logger_, "Already started activity for " << application_key); + LOG4CXX_WARN(logger, "Already started activity for " << application_key); return; } @@ -94,14 +92,14 @@ void PipeStreamerAdapter::StartActivity(int32_t application_key) { (*it)->OnActivityStarted(application_key); } - LOG4CXX_DEBUG(logger_, "Pipe was opened for writing " << named_pipe_path_); + LOG4CXX_TRACE(logger, "Pipe was opened for writing " << named_pipe_path_); } void PipeStreamerAdapter::StopActivity(int32_t application_key) { - LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_INFO(logger, "PipeStreamerAdapter::StopActivity"); if (application_key != current_application_) { - LOG4CXX_WARN(logger_, "Not performing activity for " << application_key); + LOG4CXX_WARN(logger, "Not performing activity for " << application_key); return; } @@ -115,19 +113,18 @@ 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() { - LOG4CXX_AUTO_TRACE(logger_); - if (thread_->is_running()) { - thread_->stop(); - thread_->join(); + 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_DEBUG(logger_, "Start sending thread"); - const size_t kStackSize = 16384; - thread_->start(threads::ThreadOptions(kStackSize)); } PipeStreamerAdapter::Streamer::Streamer( @@ -142,7 +139,7 @@ PipeStreamerAdapter::Streamer::~Streamer() { } void PipeStreamerAdapter::Streamer::threadMain() { - LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_INFO(logger, "Streamer::threadMain"); open(); @@ -150,7 +147,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; } @@ -158,7 +155,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 = @@ -167,14 +164,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_DEBUG(logger_, "Handling map streaming message. This is " + LOG4CXX_INFO(logger, "Handling map streaming message. This is " << messsages_for_session << " the message for " << server_->current_application_); std::set<MediaListenerPtr>::iterator it = @@ -189,14 +186,16 @@ void PipeStreamerAdapter::Streamer::threadMain() { close(); } -void PipeStreamerAdapter::Streamer::exitThreadMain() { - LOG4CXX_AUTO_TRACE(logger_); +bool PipeStreamerAdapter::Streamer::exitThreadMain() { + LOG4CXX_INFO(logger, "Streamer::exitThreadMain"); stop_flag_ = true; server_->messages_.Shutdown(); + return false; } void PipeStreamerAdapter::Streamer::open() { - LOG4CXX_AUTO_TRACE(logger_); + + LOG4CXX_INFO(logger, "Streamer::open() " << server_->named_pipe_path_.c_str()); DCHECK(file_system::CreateDirectoryRecursively( profile::Profile::instance()->app_storage_folder())); @@ -204,23 +203,22 @@ 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_DEBUG(logger_, "Pipe " << server_->named_pipe_path_ + LOG4CXX_TRACE(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()); } |