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);
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) {
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;
};
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;
}
}
+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");
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;
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);