[TV][Channel] tuneUp, tuneDown implementation
authorLukasz Foniok <l.foniok@samsung.com>
Tue, 23 Dec 2014 09:03:42 +0000 (10:03 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Mon, 2 Feb 2015 13:09:14 +0000 (22:09 +0900)
[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 <l.foniok@samsung.com>
src/tvchannel/tvchannel_instance.cc
src/tvchannel/tvchannel_instance.h
src/tvchannel/tvchannel_manager.cc
src/tvchannel/tvchannel_manager.h

index 84492b8..797ee21 100644 (file)
@@ -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<std::string>());
+    } else {
+        navMode = NavigatorMode::ALL;
+    }
+
+    double callbackId = args.get("callbackId").get<double>();
+    std::string windowType;
+    if (args.contains("windowType")) {
+        windowType = args.get("windowType").get<std::string>();
+    } else {
+        windowType = "MAIN";
+    }
+
+    LOGD("CallbackID %f", callbackId);
+    std::shared_ptr<TVChannelManager::TuneData> pTuneData(
+        new TVChannelManager::TuneData(navMode,
+            stringToWindowType(windowType), callbackId));
+
+    std::function<void(std::shared_ptr<
+        TVChannelManager::TuneData> const&)> task = std::bind(
+            &TVChannelInstance::tuneUpTask, this, std::placeholders::_1);
+    std::function<void(std::shared_ptr<
+            TVChannelManager::TuneData> const&)> taskAfter = std::bind(
+                &TVChannelInstance::tuneTaskAfter, this, std::placeholders::_1);
+
+    common::TaskQueue::GetInstance().Queue<TVChannelManager::TuneData>(task,
+        taskAfter, pTuneData);
+
+    picojson::value v;
+    ReportSuccess(v, out);
+}
+
+void TVChannelInstance::tuneUpTask(
+    std::shared_ptr<TVChannelManager::TuneData> 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<std::string>());
+    } else {
+        navMode = NavigatorMode::ALL;
+    }
+
+    double callbackId = args.get("callbackId").get<double>();
+    std::string windowType;
+    if (args.contains("windowType")) {
+        windowType = args.get("windowType").get<std::string>();
+    } else {
+        windowType = "MAIN";
+    }
+
+    LOGD("CallbackID %f", callbackId);
+    std::shared_ptr<TVChannelManager::TuneData> pTuneData(
+        new TVChannelManager::TuneData(navMode,
+            stringToWindowType(windowType), callbackId));
+
+    std::function<void(std::shared_ptr<
+        TVChannelManager::TuneData> const&)> task = std::bind(
+            &TVChannelInstance::tuneUpTask, this, std::placeholders::_1);
+    std::function<void(std::shared_ptr<
+            TVChannelManager::TuneData> const&)> taskAfter = std::bind(
+                &TVChannelInstance::tuneTaskAfter, this, std::placeholders::_1);
+
+    common::TaskQueue::GetInstance().Queue<TVChannelManager::TuneData>(task,
+        taskAfter, pTuneData);
+
+    picojson::value v;
+    ReportSuccess(v, out);
+}
+
+void TVChannelInstance::tuneDownTask(
+    std::shared_ptr<TVChannelManager::TuneData> const& _tuneData) {
+    TVChannelManager::getInstance()->tuneDown(_tuneData);
+}
+
 void TVChannelInstance::getCurrentChannel(picojson::value const& args,
     picojson::object& out) {
 
index e8b1688..b601a67 100644 (file)
@@ -44,9 +44,18 @@ class TVChannelInstance:
         const std::shared_ptr<TVChannelManager::GetProgramListData>& data);
     void tune(picojson::value const& args,
         picojson::object& out);
-    void tuneTask(std::shared_ptr<TVChannelManager::TuneData> 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<TVChannelManager::TuneData> const& _pTuneData);
+    void tuneUpTask(std::shared_ptr<
+        TVChannelManager::TuneData> const& _tuneData);
+    void tuneDownTask(
+        std::shared_ptr<TVChannelManager::TuneData> const& _tuneData);
 
     ISignalSubscriber* m_pSubscriber;
 };
index f9ab756..5ac90bb 100644 (file)
@@ -106,7 +106,7 @@ void TVChannelManager::tune(std::shared_ptr<TuneData> 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<TuneData> const& _pTuneData) {
     }
 }
 
+void TVChannelManager::tuneUp(std::shared_ptr<TuneData> const& _pTuneData) {
+    LOGD("Enter");
+    try {
+        std::unique_lock<std::mutex> 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<TCServiceId>(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<TuneData> const& _pTuneData) {
+    LOGD("Enter");
+    try {
+        std::unique_lock<std::mutex> 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<TCServiceId>(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");
index a363917..2281d5d 100644 (file)
@@ -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<TuneData> const& _pTuneData);
+    void tuneUp(std::shared_ptr<TuneData> const& _pTuneData);
+    void tuneDown(std::shared_ptr<TuneData> const& _pTuneData);
 
     EProfile getProfile(WindowType windowType);
     IServiceNavigation* getNavigation(EProfile profileId, u_int16_t screenId);