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));
}
}
-} // namespace tvchannel
-} // namespace extension
+void TVChannelInstance::findChannel(const picojson::value& args,
+ picojson::object& out) {
+ LOGD("Enter");
+ std::function<void(std::shared_ptr<TVChannelManager::FindChannelData>)>
+ asyncWork = std::bind(
+ &TVChannelManager::findChannel,
+ TVChannelManager::getInstance(),
+ std::placeholders::_1);
+ std::function<void(std::shared_ptr<TVChannelManager::FindChannelData>)>
+ afterWork = std::bind(
+ &TVChannelInstance::findChannelResult,
+ this,
+ std::placeholders::_1);
+ std::shared_ptr<TVChannelManager::FindChannelData> data(
+ new TVChannelManager::FindChannelData());
+ data->major = static_cast<int32_t>(args.get("major").get<double>());
+ data->minor = static_cast<int32_t>(args.get("minor").get<double>());
+ data->callbackId = args.get("callbackId").get<double>();
+ common::TaskQueue::GetInstance().Queue<TVChannelManager::FindChannelData>(
+ asyncWork,
+ afterWork,
+ data);
+ picojson::value result;
+ ReportSuccess(result, out);
+}
+
+void TVChannelInstance::findChannelResult(
+ const std::shared_ptr<TVChannelManager::FindChannelData>& 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<ChannelInfo>(*it)));
+ }
+ data->channels.clear();
+ dict["channelInfos"] = picojson::value(channels);
+ }
+ picojson::value result(dict);
+ PostMessage(result.serialize().c_str());
+}
+
+} // namespace tvchannel
+} // namespace extension
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<TVChannelManager::FindChannelData>& data);
picojson::value channelInfoToJson(
const std::unique_ptr<ChannelInfo> &pChannel);
picojson::value programInfoToJson(
#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 <NavigationModeHelper.h>
namespace extension {
namespace tvchannel {
iconv_close(cd);
}
+void TVChannelManager::findChannel(
+ const std::shared_ptr<FindChannelData>& data) {
+ LOGD("Enter");
+ try {
+ IServiceNavigation* navigation =
+ getNavigation(getProfile(WindowType::MAIN), 0);
+
+ std::unique_ptr<TCCriteriaHelper> 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<int>(data->major));
+ criteria->Where(MINOR, static_cast<int>(data->minor));
+
+ std::list<TCServiceData*> 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
#include <memory>
#include <mutex>
#include <map>
+#include <list>
#include <TVServiceAPI.h>
#include <ServiceNavigationDataType.h>
#include <NavigationModeHelper.h>
#include "tvchannel/types.h"
#include "tvchannel/tune_option.h"
+#include "common/platform_exception.h"
namespace common {
class PlatformException;
IService* getService();
+ struct FindChannelData {
+ std::shared_ptr<common::PlatformException> error;
+ int32_t major;
+ int32_t minor;
+ double callbackId;
+ std::list<ChannelInfo*> channels;
+ };
+
+ void findChannel(const std::shared_ptr<FindChannelData>& data);
+
private:
EventListener* m_listener;
// Not copyable, assignable, movable
TVChannelManager();
+ ~TVChannelManager();
TVChannelManager(TVChannelManager const&) = delete;
void operator=(TVChannelManager const&) = delete;
TVChannelManager(TVChannelManager &&) = delete;