--- /dev/null
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "tvchannel/program_info.h"
+#include "tvchannel/tvchannel_manager.h"
+#include "common/logger.h"
+
+namespace extension {
+namespace tvchannel {
+
+ProgramInfo::ProgramInfo() :
+m_title(""),
+m_startTime(0),
+m_duration(0),
+m_detailedDescription(""),
+m_language(""),
+m_rating("") {
+}
+
+ProgramInfo::~ProgramInfo() {
+}
+
+void ProgramInfo::fromApiData(const TCProgramData &data) {
+ LOGD("Enter");
+ setTitle(data);
+ m_startTime = data.StartTime();
+ m_duration = data.EndTime() - m_startTime;
+ setDetailedDescription(data);
+ setLanguage(data);
+}
+
+std::string ProgramInfo::getTitle() const {
+ return m_title;
+}
+
+void ProgramInfo::setTitle(const TCProgramData &data) {
+ LOGD("Enter");
+ try {
+ unsigned int len;
+ size_t c_len;
+ t_wchar_t *title;
+
+ len = data.TitleLength();
+ if (len) {
+ LOGD("Title length %d", len);
+ title = new t_wchar_t[len + 1];
+ TCProgramData copy = data;
+ copy.Title(title, &len);
+ c_len = len * sizeof (t_wchar_t) / sizeof (char);
+ char name[128];
+ TVChannelManager::ucs2utf8(name, (size_t)sizeof (name),
+ reinterpret_cast<char*>(title), c_len);
+ delete [] title;
+ m_title = name;
+ } else {
+ m_title = "";
+ }
+ } catch (...) {
+ LOGD("There is some problem on text encoding.");
+ m_title = "";
+ }
+}
+
+void ProgramInfo::setTitle(std::string title) {
+ m_title = title;
+}
+
+int64_t ProgramInfo::getStartTime() const {
+ return m_startTime;
+}
+
+double ProgramInfo::getStartTimeMs() const {
+ return static_cast<double> (m_startTime * 1000.0);
+}
+
+void ProgramInfo::setStartTime(int64_t startTime) {
+ m_startTime = startTime;
+}
+
+int64_t ProgramInfo::getDuration() const {
+ return m_duration;
+}
+
+void ProgramInfo::setDuration(int64_t duration) {
+ m_duration = duration;
+}
+
+std::string ProgramInfo::getDetailedDescription() const {
+ return m_detailedDescription;
+}
+
+void ProgramInfo::setDetailedDescription(std::string detailedDescription) {
+ m_detailedDescription = detailedDescription;
+}
+
+void ProgramInfo::setDetailedDescription(const TCProgramData &data) {
+ LOGD("Enter");
+ try {
+ unsigned int len;
+ size_t c_len;
+ t_wchar_t *description;
+
+ len = data.ExtendedTextLength();
+ LOGD("Description length %d", len);
+ if (len) {
+ description = new t_wchar_t[len + 1];
+ TCProgramData copy = data;
+ copy.ExtendedText(description, &len);
+
+ c_len = len * sizeof (t_wchar_t) / sizeof (char);
+ char name[TCProgramData::EExtendChannelTextLength
+ ::EXTEND_CHANNEL_TEXT_LENGTH];
+ TVChannelManager::ucs2utf8(name, (size_t)sizeof (name),
+ reinterpret_cast<char*>(description), c_len);
+ delete [] description;
+ m_detailedDescription = name;
+ } else {
+ m_detailedDescription = "";
+ }
+ } catch (...) {
+ LOGD("There is some problem on text encoding.");
+ m_detailedDescription = "";
+ }
+}
+
+std::string ProgramInfo::getLanguage() const {
+ return m_language;
+}
+
+void ProgramInfo::setLanguage(std::string language) {
+ m_language = language;
+}
+
+void ProgramInfo::setLanguage(const TCProgramData &data) {
+ // todo: convert language number to code?
+ m_language = std::to_string(data.Language());
+}
+
+std::string ProgramInfo::getRating() const {
+ return m_rating;
+}
+
+void ProgramInfo::setRating(std::string rating) {
+ m_rating = rating;
+}
+
+
+} // namespace tvchannel
+} // namespace extension
--- /dev/null
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef SRC_TVCHANNEL_PROGRAM_INFO_H_
+#define SRC_TVCHANNEL_PROGRAM_INFO_H_
+
+#include <ProgramData.h>
+#include <string>
+
+#include "tvchannel/types.h"
+
+namespace extension {
+namespace tvchannel {
+
+class ProgramInfo {
+ public:
+ ProgramInfo();
+ virtual ~ProgramInfo();
+ void fromApiData(const TCProgramData &data);
+
+ std::string getTitle() const;
+ void setTitle(std::string title);
+ void setTitle(const TCProgramData &data);
+
+ int64_t getStartTime() const;
+ double getStartTimeMs() const;
+ void setStartTime(int64_t startTime);
+
+ int64_t getDuration() const;
+ void setDuration(int64_t duration);
+
+ std::string getDetailedDescription() const;
+ void setDetailedDescription(std::string detailedDescription);
+ void setDetailedDescription(const TCProgramData &data);
+
+ std::string getLanguage() const;
+ void setLanguage(std::string language);
+ void setLanguage(const TCProgramData &data);
+
+ std::string getRating() const;
+ void setRating(std::string rating);
+
+ private:
+ std::string m_title;
+ int64_t m_startTime;
+ int64_t m_duration;
+ std::string m_detailedDescription;
+ std::string m_language;
+ std::string m_rating;
+};
+
+} // namespace tvchannel
+} // namespace extension
+
+#endif // SRC_TVCHANNEL_PROGRAM_INFO_H_
'tvchannel_instance.h',
'channel_info.cc',
'channel_info.h',
+ 'program_info.cc',
+ 'program_info.h',
'tvchannel_manager.h',
'tvchannel_manager.cc',
'types.h',
#include "common/picojson.h"
#include "tvchannel/tvchannel_manager.h"
#include "tvchannel/channel_info.h"
+#include "tvchannel/program_info.h"
namespace extension {
namespace tvchannel {
std::bind(&TVChannelInstance::getCurrentChannel, this,
std::placeholders::_1,
std::placeholders::_2));
+ RegisterSyncHandler("TVChannelManager_getCurrentProgram",
+ std::bind(&TVChannelInstance::getCurrentProgram, this,
+ std::placeholders::_1,
+ std::placeholders::_2));
}
TVChannelInstance::~TVChannelInstance() {
ReportSuccess(v, out);
}
+void TVChannelInstance::getCurrentProgram(const picojson::value& args,
+ picojson::object& out) {
+ std::unique_ptr<ProgramInfo> pInfo(TVChannelManager::getInstance()
+ ->getCurrentProgram(args.get("windowType").get<std::string>()));
+ picojson::value::object program;
+ program.insert(
+ std::make_pair("title",
+ picojson::value(pInfo->getTitle())));
+ program.insert(
+ std::make_pair("startTime",
+ picojson::value(static_cast<double>(pInfo->getStartTimeMs()))));
+ program.insert(
+ std::make_pair("duration",
+ picojson::value(static_cast<double>(pInfo->getDuration()))));
+ program.insert(
+ std::make_pair("detailedDescription",
+ picojson::value(pInfo->getDetailedDescription())));
+ program.insert(
+ std::make_pair("language",
+ picojson::value(pInfo->getLanguage())));
+ program.insert(
+ std::make_pair("rating",
+ picojson::value(pInfo->getRating())));
+
+ picojson::value result(program);
+ ReportSuccess(result, out);
+}
+
+
} // namespace tvchannel
} // namespace extension
private:
void getCurrentChannel(const picojson::value& args, picojson::object& out);
+ void getCurrentProgram(const picojson::value& args, picojson::object& out);
};
} // namespace tvchannel
#include "tvchannel/tvchannel_manager.h"
#include <iconv.h>
#include "tvchannel/channel_info.h"
+#include "tvchannel/program_info.h"
#include "common/logger.h"
#include "common/platform_exception.h"
namespace extension {
namespace tvchannel {
+using common::UnknownException;
+
TVChannelManager* TVChannelManager::getInstance() {
static TVChannelManager manager;
return &manager;
}
}
+TCServiceId TVChannelManager::getCurrentChannelId(
+ const std::string& _windowType) {
+ TCServiceData serviceData;
+ TCCriteriaHelper criteria;
+ criteria.Fetch(SERVICE_ID);
+ // Navigation
+ IServiceNavigation* navigation;
+ int ret = TVServiceAPI::CreateServiceNavigation(
+ getProfile(stringToWindowType(_windowType)), 0, &navigation);
+ if (TV_SERVICE_API_SUCCESS != ret) {
+ LOGE("Failed to create service navigation: %d", ret);
+ throw UnknownException("Failed to create service navigation");
+ }
+
+ struct TSTvMode tvMode;
+ ret = navigation->GetTvMode(tvMode);
+ if (TV_SERVICE_API_METHOD_SUCCESS != ret) {
+ LOGE("Failed to get current tv mode: %d", ret);
+ throw UnknownException("Failed to get current tv mode");
+ }
+
+ ret = navigation->GetCurrentServiceInfo(tvMode, criteria, serviceData);
+ if (TV_SERVICE_API_METHOD_SUCCESS != ret) {
+ LOGE("Failed to get current service info: %d", ret);
+ throw UnknownException("Failed to get current service info");
+ }
+ return serviceData.Get<TCServiceId>(SERVICE_ID);
+}
+
+ProgramInfo* TVChannelManager::getCurrentProgram(
+ const std::string& _windowType) {
+
+ IServiceGuide* guide;
+ int ret = TVServiceAPI::CreateServiceGuide(&guide);
+ if (TV_SERVICE_API_SUCCESS != ret) {
+ LOGE("Failed to create service guide: %d", ret);
+ throw UnknownException("Failed to create service guide");
+ }
+
+ TCProgramData programData;
+ ret = guide->GetPresentProgram(getCurrentChannelId(_windowType),
+ programData);
+ if (TV_SERVICE_API_METHOD_SUCCESS != ret) {
+ LOGE("Failed to get current program: %d", ret);
+ throw UnknownException("Failed to get current program");
+ }
+ ProgramInfo* program = new ProgramInfo();
+ program->fromApiData(programData);
+ return program;
+}
+
void TVChannelManager::ucs2utf8(char *out, size_t out_len, char *in,
size_t in_len) {
iconv_t cd;
namespace tvchannel {
class ChannelInfo;
+class ProgramInfo;
// TVServiceAPI static methods returns 0 on success
static const int TV_SERVICE_API_SUCCESS = 0;
// TVServiceAPI object methods return 1 on success
public:
static TVChannelManager* getInstance();
std::unique_ptr<ChannelInfo> getCurrentChannel(std::string const& _windowType);
+ ProgramInfo* getCurrentProgram(std::string const& _windowType);
static void ucs2utf8(char *out, size_t out_len, char *in, size_t in_len);
private:
// Not copyable, assignable, movable
TVChannelManager(TVChannelManager &&) = delete;
EProfile getProfile(WindowType windowType);
+ TCServiceId getCurrentChannelId(std::string const& _windowType);
};
} // namespace tvchannel