From cd81e2f559b946d1e5730a92d08b7675c8242773 Mon Sep 17 00:00:00 2001
From: Przemyslaw Ciezkowski
Date: Wed, 17 Dec 2014 18:12:10 +0100
Subject: [PATCH] [TVChannel] findChannel body
[Verification]
tizen.tvchannel.findChannel(5, 65535, function(){console.log(arguments);});
Change-Id: Idb3989e7ae3af515fab6098620ffec6aaa6a6d3c
Signed-off-by: Przemyslaw Ciezkowski
---
src/tvchannel/tvchannel_instance.cc | 55 +++++++++++++++++++++++++++++++++++--
src/tvchannel/tvchannel_instance.h | 3 ++
src/tvchannel/tvchannel_manager.cc | 54 +++++++++++++++++++++++++++++++++++-
src/tvchannel/tvchannel_manager.h | 13 +++++++++
4 files changed, 122 insertions(+), 3 deletions(-)
diff --git a/src/tvchannel/tvchannel_instance.cc b/src/tvchannel/tvchannel_instance.cc
index bff3953..5e2d11a 100644
--- a/src/tvchannel/tvchannel_instance.cc
+++ b/src/tvchannel/tvchannel_instance.cc
@@ -23,6 +23,10 @@ TVChannelInstance::TVChannelInstance() {
RegisterSyncHandler("TVChannelManager_getCurrentProgram",
std::bind(&TVChannelInstance::getCurrentProgram, this,
std::placeholders::_1, std::placeholders::_2));
+ RegisterHandler("TVChannelManager_findChannel",
+ std::bind(&TVChannelInstance::findChannel, this,
+ std::placeholders::_1,
+ std::placeholders::_2));
RegisterHandler("TVChannelManager_tune",
std::bind(&TVChannelInstance::tune, this, std::placeholders::_1,
std::placeholders::_2));
@@ -225,5 +229,52 @@ void TVChannelInstance::onNoSignal(double callbackId) {
}
}
-} // namespace tvchannel
-} // namespace extension
+void TVChannelInstance::findChannel(const picojson::value& args,
+ picojson::object& out) {
+ LOGD("Enter");
+ std::function)>
+ asyncWork = std::bind(
+ &TVChannelManager::findChannel,
+ TVChannelManager::getInstance(),
+ std::placeholders::_1);
+ std::function)>
+ afterWork = std::bind(
+ &TVChannelInstance::findChannelResult,
+ this,
+ std::placeholders::_1);
+ std::shared_ptr data(
+ new TVChannelManager::FindChannelData());
+ data->major = static_cast(args.get("major").get());
+ data->minor = static_cast(args.get("minor").get());
+ data->callbackId = args.get("callbackId").get();
+ common::TaskQueue::GetInstance().Queue(
+ asyncWork,
+ afterWork,
+ data);
+ picojson::value result;
+ ReportSuccess(result, out);
+}
+
+void TVChannelInstance::findChannelResult(
+ const std::shared_ptr& data) {
+ LOGD("Enter");
+ picojson::value::object dict;
+ dict["callbackId"] = picojson::value(data->callbackId);
+ if (data->error) {
+ dict["error"] = data->error->ToJSON();
+ } else {
+ picojson::value::array channels;
+ auto it = data->channels.begin();
+ for (; it != data->channels.end(); ++it) {
+ channels.push_back(channelInfoToJson(
+ std::unique_ptr(*it)));
+ }
+ data->channels.clear();
+ dict["channelInfos"] = picojson::value(channels);
+ }
+ picojson::value result(dict);
+ PostMessage(result.serialize().c_str());
+}
+
+} // namespace tvchannel
+} // namespace extension
diff --git a/src/tvchannel/tvchannel_instance.h b/src/tvchannel/tvchannel_instance.h
index 24fcecb..743bf79 100644
--- a/src/tvchannel/tvchannel_instance.h
+++ b/src/tvchannel/tvchannel_instance.h
@@ -29,6 +29,9 @@ class TVChannelInstance:
virtual void onChannelChange(double callbackId);
virtual void onEPGReceived(double callbackId);
virtual void onNoSignal(double callbackId);
+ void findChannel(const picojson::value& args, picojson::object& out);
+ void findChannelResult(
+ const std::shared_ptr& data);
picojson::value channelInfoToJson(
const std::unique_ptr &pChannel);
picojson::value programInfoToJson(
diff --git a/src/tvchannel/tvchannel_manager.cc b/src/tvchannel/tvchannel_manager.cc
index 14a2f2b..49b5ddc 100644
--- a/src/tvchannel/tvchannel_manager.cc
+++ b/src/tvchannel/tvchannel_manager.cc
@@ -9,7 +9,8 @@
#include "tvchannel/channel_info.h"
#include "tvchannel/program_info.h"
#include "common/logger.h"
-#include "common/platform_exception.h"
+#include "common/task-queue.h"
+#include
namespace extension {
namespace tvchannel {
@@ -331,5 +332,56 @@ void TVChannelManager::ucs2utf8(char *out, size_t out_len, char *in,
iconv_close(cd);
}
+void TVChannelManager::findChannel(
+ const std::shared_ptr& data) {
+ LOGD("Enter");
+ try {
+ IServiceNavigation* navigation =
+ getNavigation(getProfile(WindowType::MAIN), 0);
+
+ std::unique_ptr criteria = getBasicCriteria(
+ getTvMode(navigation), NAVIGATION_MODE_ALL);
+ criteria->Fetch(SERVICE_ID);
+ criteria->Fetch(MAJOR);
+ criteria->Fetch(MINOR);
+ criteria->Fetch(PROGRAM_NUMBER);
+ criteria->Fetch(CHANNEL_NUMBER);
+ criteria->Fetch(CHANNEL_TYPE);
+ criteria->Fetch(SERVICE_NAME);
+ criteria->Fetch(SOURCE_ID);
+ criteria->Fetch(TRANSPORT_STREAM_ID);
+ criteria->Fetch(ORIGINAL_NETWORK_ID);
+ criteria->Fetch(LCN);
+ criteria->Where(MAJOR, static_cast(data->major));
+ criteria->Where(MINOR, static_cast(data->minor));
+
+ std::list resultServices;
+ int ret = m_pService->FindServiceList(*criteria, resultServices);
+ if (TV_SERVICE_API_METHOD_FAILURE == ret) {
+ LOGE("Failed to find channel: %d", ret);
+ throw common::NotFoundException("Failed to find channel");
+ }
+ LOGD("Found channels: %d", resultServices.size());
+ auto it = resultServices.begin();
+ for (; it != resultServices.end(); ++it) {
+ ChannelInfo *channelInfo = new ChannelInfo();
+ channelInfo->fromApiData(*(*it));
+ data->channels.push_back(channelInfo);
+ delete (*it);
+ }
+ resultServices.clear();
+ } catch (common::PlatformException& e) {
+ data->error.reset(new common::PlatformException(e.name(), e.message()));
+ } catch (...) {
+ data->error.reset(
+ new common::UnknownException("Couldn't find channels"));
+ }
+}
+
+TVChannelManager::~TVChannelManager() {
+ TVServiceAPI::Destroy();
+}
+
+
} // namespace tvchannel
} // namespace extension
diff --git a/src/tvchannel/tvchannel_manager.h b/src/tvchannel/tvchannel_manager.h
index e7b2f40..365dd28 100644
--- a/src/tvchannel/tvchannel_manager.h
+++ b/src/tvchannel/tvchannel_manager.h
@@ -9,11 +9,13 @@
#include
#include
#include