From 325e738202468ebf184400aa27370eca824d050c Mon Sep 17 00:00:00 2001 From: Lukasz Foniok Date: Tue, 23 Dec 2014 10:03:42 +0100 Subject: [PATCH] [TV][Channel] tuneUp, tuneDown implementation [Verification] Following code should witch one channel up/down at a time tizen.tvchannel.tuneUp( function(){console.log("success")} ) tizen.tvchannel.tuneDown( function(){console.log("success")} ) Change-Id: Ic5ba6d40f17004da7cec038bccf358b9e7cb6c6c Signed-off-by: Lukasz Foniok --- src/tvchannel/tvchannel_instance.cc | 94 ++++++++++++++++++++++++++++++++ src/tvchannel/tvchannel_instance.h | 11 +++- src/tvchannel/tvchannel_manager.cc | 104 +++++++++++++++++++++++++++++++++++- src/tvchannel/tvchannel_manager.h | 8 +++ 4 files changed, 215 insertions(+), 2 deletions(-) diff --git a/src/tvchannel/tvchannel_instance.cc b/src/tvchannel/tvchannel_instance.cc index 84492b8..797ee21 100644 --- a/src/tvchannel/tvchannel_instance.cc +++ b/src/tvchannel/tvchannel_instance.cc @@ -40,6 +40,12 @@ TVChannelInstance::TVChannelInstance() { RegisterHandler("TVChannelManager_tune", std::bind(&TVChannelInstance::tune, this, std::placeholders::_1, std::placeholders::_2)); + RegisterHandler("TVChannelManager_tuneUp", + std::bind(&TVChannelInstance::tuneUp, this, std::placeholders::_1, + std::placeholders::_2)); + RegisterHandler("TVChannelManager_tuneDown", + std::bind(&TVChannelInstance::tuneDown, this, std::placeholders::_1, + std::placeholders::_2)); m_pSubscriber = TVChannelManager::getInstance()->createSubscriber(this); TVChannelManager::getInstance()->registerListener(m_pSubscriber); @@ -100,6 +106,94 @@ void TVChannelInstance::tuneTask( TVChannelManager::getInstance()->tune(_tuneData); } +void TVChannelInstance::tuneUp(picojson::value const& args, + picojson::object& out) { + LOGD("Enter"); + + NavigatorMode navMode; + if (args.contains("tuneMode")) { + navMode = stringToNavigatorMode( + args.get("tuneMode").get()); + } else { + navMode = NavigatorMode::ALL; + } + + double callbackId = args.get("callbackId").get(); + std::string windowType; + if (args.contains("windowType")) { + windowType = args.get("windowType").get(); + } else { + windowType = "MAIN"; + } + + LOGD("CallbackID %f", callbackId); + std::shared_ptr pTuneData( + new TVChannelManager::TuneData(navMode, + stringToWindowType(windowType), callbackId)); + + std::function const&)> task = std::bind( + &TVChannelInstance::tuneUpTask, this, std::placeholders::_1); + std::function const&)> taskAfter = std::bind( + &TVChannelInstance::tuneTaskAfter, this, std::placeholders::_1); + + common::TaskQueue::GetInstance().Queue(task, + taskAfter, pTuneData); + + picojson::value v; + ReportSuccess(v, out); +} + +void TVChannelInstance::tuneUpTask( + std::shared_ptr const& _tuneData) { + TVChannelManager::getInstance()->tuneUp(_tuneData); +} + +void TVChannelInstance::tuneDown(picojson::value const& args, + picojson::object& out) { + LOGD("Enter"); + + NavigatorMode navMode; + if (args.contains("tuneMode")) { + navMode = stringToNavigatorMode( + args.get("tuneMode").get()); + } else { + navMode = NavigatorMode::ALL; + } + + double callbackId = args.get("callbackId").get(); + std::string windowType; + if (args.contains("windowType")) { + windowType = args.get("windowType").get(); + } else { + windowType = "MAIN"; + } + + LOGD("CallbackID %f", callbackId); + std::shared_ptr pTuneData( + new TVChannelManager::TuneData(navMode, + stringToWindowType(windowType), callbackId)); + + std::function const&)> task = std::bind( + &TVChannelInstance::tuneUpTask, this, std::placeholders::_1); + std::function const&)> taskAfter = std::bind( + &TVChannelInstance::tuneTaskAfter, this, std::placeholders::_1); + + common::TaskQueue::GetInstance().Queue(task, + taskAfter, pTuneData); + + picojson::value v; + ReportSuccess(v, out); +} + +void TVChannelInstance::tuneDownTask( + std::shared_ptr const& _tuneData) { + TVChannelManager::getInstance()->tuneDown(_tuneData); +} + void TVChannelInstance::getCurrentChannel(picojson::value const& args, picojson::object& out) { diff --git a/src/tvchannel/tvchannel_instance.h b/src/tvchannel/tvchannel_instance.h index e8b1688..b601a67 100644 --- a/src/tvchannel/tvchannel_instance.h +++ b/src/tvchannel/tvchannel_instance.h @@ -44,9 +44,18 @@ class TVChannelInstance: const std::shared_ptr& data); void tune(picojson::value const& args, picojson::object& out); - void tuneTask(std::shared_ptr const& _tuneData); + void tuneUp(picojson::value const& args, + picojson::object& out); + void tuneDown(picojson::value const& args, + picojson::object& out); + void tuneTask(std::shared_ptr< + TVChannelManager::TuneData> const& _tuneData); void tuneTaskAfter( std::shared_ptr const& _pTuneData); + void tuneUpTask(std::shared_ptr< + TVChannelManager::TuneData> const& _tuneData); + void tuneDownTask( + std::shared_ptr const& _tuneData); ISignalSubscriber* m_pSubscriber; }; diff --git a/src/tvchannel/tvchannel_manager.cc b/src/tvchannel/tvchannel_manager.cc index f9ab756..5ac90bb 100644 --- a/src/tvchannel/tvchannel_manager.cc +++ b/src/tvchannel/tvchannel_manager.cc @@ -106,7 +106,7 @@ void TVChannelManager::tune(std::shared_ptr const& _pTuneData) { ret = getNavigation(getProfile(windowType), 0)->SetService(serviceId); if (TV_SERVICE_API_METHOD_SUCCESS != ret) { LOGE("Failed to set selected channel: %d", ret); - throw new common::UnknownException( + throw common::UnknownException( "Failed to set selected channel"); } _pTuneData->serviceId = serviceId; @@ -118,6 +118,108 @@ void TVChannelManager::tune(std::shared_ptr const& _pTuneData) { } } +void TVChannelManager::tuneUp(std::shared_ptr const& _pTuneData) { + LOGD("Enter"); + try { + std::unique_lock lock(tuneMutex); + + WindowType windowType = _pTuneData->windowType; + + TCServiceId currentServiceId = + getCurrentChannel(windowType)->getServiceID(); + + TSTvMode tvMode = getTvMode( + getNavigation(getProfile(windowType), SCREENID)); + + ENavigationMode naviMode = NAVIGATION_MODE_ALL; + std::unique_ptr < TCCriteriaHelper > pCriteria = getBasicCriteria( + tvMode, naviMode); + pCriteria->Fetch(SERVICE_ID); + pCriteria->Fetch(SERVICE_NAME); + pCriteria->Fetch(CHANNEL_TYPE); + pCriteria->Fetch(CHANNEL_NUMBER); + TCServiceData previousService; + int ret = getNavigation( + getProfile(windowType), SCREENID)->GetPreviousService(*pCriteria, + currentServiceId, + previousService); + if (TV_SERVICE_API_METHOD_SUCCESS != ret) { + LOGE("Failed to find previous channel: %d", ret); + throw common::NotFoundException("Failed to find previous channel"); + } + TCServiceId serviceId = previousService.Get(SERVICE_ID); + + // if GetNextService's result is same with current service id, + // it means failure to find previous channel. + if (currentServiceId == serviceId) { + LOGE("Failed to find previous channel: %d", ret); + throw common::NotFoundException("Failed to find next channel"); + } + ret = getNavigation(getProfile(windowType), 0)->SetService(serviceId); + if (TV_SERVICE_API_METHOD_SUCCESS != ret) { + LOGE("Failed to set selected channel: %d", ret); + throw common::UnknownException( + "Failed to set selected channel"); + } + m_callbackTuneMap[serviceId] = _pTuneData->callbackId; + } catch (common::PlatformException const& _error) { + _pTuneData->pError.reset( + new common::PlatformException(_error.name(), _error.message())); + LOGE("Some exception caught"); + } +} + +void TVChannelManager::tuneDown(std::shared_ptr const& _pTuneData) { + LOGD("Enter"); + try { + std::unique_lock lock(tuneMutex); + + WindowType windowType = _pTuneData->windowType; + + TCServiceId currentServiceId = + getCurrentChannel(windowType)->getServiceID(); + + TSTvMode tvMode = getTvMode( + getNavigation(getProfile(windowType), SCREENID)); + + ENavigationMode naviMode = NAVIGATION_MODE_ALL; + std::unique_ptr < TCCriteriaHelper > pCriteria = getBasicCriteria( + tvMode, naviMode); + pCriteria->Fetch(SERVICE_ID); + pCriteria->Fetch(SERVICE_NAME); + pCriteria->Fetch(CHANNEL_TYPE); + pCriteria->Fetch(CHANNEL_NUMBER); + TCServiceData nextService; + int ret = getNavigation( + getProfile(windowType), SCREENID)->GetNextService(*pCriteria, + currentServiceId, + nextService); + if (TV_SERVICE_API_METHOD_SUCCESS != ret) { + LOGE("Failed to find previous channel: %d", ret); + throw common::NotFoundException("Failed to find previous channel"); + } + TCServiceId serviceId = nextService.Get(SERVICE_ID); + + // if GetNextService's result is same with current service id, + // it means failure to find previous channel. + if (currentServiceId == serviceId) { + LOGE("Failed to find previous channel: %d", ret); + throw common::NotFoundException("Failed to find previous channel"); + } + ret = getNavigation(getProfile(windowType), 0)->SetService(serviceId); + if (TV_SERVICE_API_METHOD_SUCCESS != ret) { + LOGE("Failed to set selected channel: %d", ret); + throw common::UnknownException( + "Failed to set selected channel"); + } + m_callbackTuneMap[serviceId] = _pTuneData->callbackId; + } catch (common::PlatformException const& _error) { + _pTuneData->pError.reset( + new common::PlatformException(_error.name(), _error.message())); + LOGE("Some exception caught"); + } +} + IServiceNavigation* TVChannelManager::getNavigation(EProfile profileId, u_int16_t screenId) { LOGD("Enter"); diff --git a/src/tvchannel/tvchannel_manager.h b/src/tvchannel/tvchannel_manager.h index a363917..2281d5d 100644 --- a/src/tvchannel/tvchannel_manager.h +++ b/src/tvchannel/tvchannel_manager.h @@ -53,6 +53,12 @@ class TVChannelManager { tuneOption(_tuneOption), windowType(_windowType), callbackId(_callbackId) { } + TuneData(NavigatorMode _navMode, WindowType _windowType, + double _callbackId) : + navMode(_navMode), windowType(_windowType), + callbackId(_callbackId) { + } + NavigatorMode navMode; TuneOption tuneOption; WindowType windowType; double callbackId; @@ -68,6 +74,8 @@ class TVChannelManager { ProgramInfo* getCurrentProgram(WindowType _windowType); void tune(std::shared_ptr const& _pTuneData); + void tuneUp(std::shared_ptr const& _pTuneData); + void tuneDown(std::shared_ptr const& _pTuneData); EProfile getProfile(WindowType windowType); IServiceNavigation* getNavigation(EProfile profileId, u_int16_t screenId); -- 2.7.4