From: Tomasz Marciniak Date: Sat, 13 Dec 2014 14:24:29 +0000 (+0100) Subject: [Callhistory] Initial commit. X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~832^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=372b5a067d1f8e57b91ff5d31e0d02ea265cf9dc;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Callhistory] Initial commit. [Verification] Code compiles without errors. tizen.callhistory is visible. Change-Id: I15dd2a5c48d90c77a607aa1a0453be4ac26e59a3 Signed-off-by: Tomasz Marciniak --- diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index 09d28eb1..a96ee5dc 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -168,7 +168,9 @@ BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(x11) BuildRequires: pkgconfig(xrandr) BuildRequires: python - +BuildRequires: pkgconfig(tapi) +BuildRequires: pkgconfig(libpcrecpp) +BuildRequires: pkgconfig(contacts-service2) %if 0%{?tizen_feature_badge_support} BuildRequires: pkgconfig(badge) diff --git a/src/callhistory/callhistory.cc b/src/callhistory/callhistory.cc new file mode 100644 index 00000000..25870925 --- /dev/null +++ b/src/callhistory/callhistory.cc @@ -0,0 +1,54 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "callhistory.h" + +namespace extension { +namespace callhistory { + +CallHistory::CallHistory() +{ +} + +CallHistory::~CallHistory() +{ +} + +CallHistory* CallHistory::getInstance(){ + static CallHistory instance; + return &instance; +} + +void CallHistory::find() +{ + +} + +void CallHistory::remove() +{ + +} + +void CallHistory::removeBatch() +{ + +} + +void CallHistory::removeAll() +{ + +} + +long CallHistory::addChangeListener() +{ + +} + +void CallHistory::removeChangeListener() +{ + +} + +} // namespace callhistory +} // namespace extension diff --git a/src/callhistory/callhistory.gyp b/src/callhistory/callhistory.gyp new file mode 100644 index 00000000..b4f1f09a --- /dev/null +++ b/src/callhistory/callhistory.gyp @@ -0,0 +1,37 @@ +{ + 'includes':[ + '../common/common.gypi', + ], + 'targets': [ + { + 'target_name': 'tizen_callhistory', + 'type': 'loadable_module', + 'sources': [ + 'callhistory_api.js', + 'callhistory.cc', + 'callhistory.h', + 'callhistory_extension.cc', + 'callhistory_extension.h', + 'callhistory_instance.cc', + 'callhistory_instance.h', + 'callhistory_utils.cc', + 'callhistory_utils.h', + ], + 'includes': [ + '../common/pkg-config.gypi', + ], + 'conditions': [ + ['tizen == 1', { + 'variables': { + 'packages': [ + 'glib-2.0', + 'contacts-service2', + 'libpcrecpp', + 'tapi', + ] + }, + }], + ], + }, + ], +} \ No newline at end of file diff --git a/src/callhistory/callhistory.h b/src/callhistory/callhistory.h new file mode 100644 index 00000000..45a6ed22 --- /dev/null +++ b/src/callhistory/callhistory.h @@ -0,0 +1,32 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CALLHISTORY_CALLHISTORY_H_ +#define CALLHISTORY_CALLHISTORY_H_ + +namespace extension { +namespace callhistory { + +class CallHistory +{ +public: + static CallHistory* getInstance(); + + void find(); + void remove(); + void removeBatch(); + void removeAll(); + long addChangeListener(); + void removeChangeListener(); + +private: + CallHistory(); + virtual ~CallHistory(); + +}; + +} // namespace callhistory +} // namespace extension + +#endif // CALLHISTORY_CALLHISTORY_H_ diff --git a/src/callhistory/callhistory_api.js b/src/callhistory/callhistory_api.js new file mode 100644 index 00000000..a934c4ac --- /dev/null +++ b/src/callhistory/callhistory_api.js @@ -0,0 +1,270 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var Common = function() { +function _getException(type, msg) { + return new WebAPIException(type, msg || 'Unexpected exception'); +} + +function _getTypeMismatch(msg) { + return _getException(WebAPIException.TYPE_MISMATCH_ERR, + msg || 'Provided arguments are not valid.'); +} + +function _throwTypeMismatch(msg) { + throw _getTypeMismatch(msg); +} + +var _type = xwalk.utils.type; +var _converter = xwalk.utils.converter; +var _validator = xwalk.utils.validator; + +function Common() {} + +function _prepareRequest(module, method, args) { + var request = { + module : module + }; + request.data = { + method : method, + args : args + }; + return request; +} + +Common.prototype.getCallSync = function (msg) { + var ret = extension.internal.sendSyncMessage(JSON.stringify(msg)); + var obj = JSON.parse(ret); + if (obj.error) { + throwException_(obj.error); + } + + return obj.result; +}; + +Common.prototype.getCall = function (module) { + return function _call(method, args, callback) { + return JSON.parse(native.call(_prepareRequest(module, method, args), function (result) { + if (typeof callback === 'function') { + callback(JSON.parse(result)); + } + })); + }; +}; + +Common.prototype.isSuccess = function (result) { + return (result.status !== 'error'); +}; + +Common.prototype.isFailure = function (result) { + return !this.isSuccess(result); +}; + +Common.prototype.getErrorObject = function (result) { + return new WebAPIException(result.error); +}; + +Common.prototype.getResultObject = function (result) { + return result.result; +}; + +Common.prototype.callIfPossible = function(callback) { + if (!_type.isNullOrUndefined(callback)) { + callback.apply(callback, [].slice.call(arguments, 1)); + } +}; + +Common.prototype.getTypeMismatch = function(msg) { + _getTypeMismatch(msg); +}; + +Common.prototype.throwTypeMismatch = function(msg) { + _throwTypeMismatch(msg); +}; + +Common.prototype.getInvalidValues = function(msg) { + return _getException('InvalidValuesError', + msg || 'There\'s a problem with input value.'); +}; + +Common.prototype.throwInvalidValues = function(msg) { + throw this.getInvalidValues(msg); +}; + +Common.prototype.getIOError = function (msg) { + return _getException('IOError', msg || 'Unexpected IO error.'); +}; + +Common.prototype.throwIOError = function (msg) { + throw this.getIOError(msg); +}; + +Common.prototype.getNotSupported = function (msg) { + return _getException(WebAPIException.NOT_SUPPORTED_ERR, msg || 'Not supported.'); +}; + +Common.prototype.throwNotSupported = function (msg) { + throw this.getNotSupported(msg); +}; + +Common.prototype.getNotFound = function (msg) { + return _getException('NotFoundError', msg || 'Not found.'); +}; + +Common.prototype.throwNotFound = function (msg) { + throw this.getNotFound(msg); +}; + +Common.prototype.getUnknownError = function (msg) { + return _getException('UnknownError', msg || 'Unknown error.'); +}; + +Common.prototype.throwUnknownError = function (msg) { + throw this.getUnknownError(msg); +}; + +Common.prototype.throwTypeMismatch = function(msg) { + _throwTypeMismatch(msg); +}; + +Common.prototype.sort = function (arr, sortMode) { + var _getSortProperty = function (obj, props) { + for (var i = 0; i < props.length; ++i) { + if (!obj.hasOwnProperty(props[i])) { + return null; + } + obj = obj[props[i]]; + } + return obj; + }; + + if (sortMode instanceof tizen.SortMode) { + var props = sortMode.attributeName.split('.'); + arr.sort(function (a, b) { + var aValue = _getSortProperty(a, props); + var bValue = _getSortProperty(b, props); + + if (sortMode.order === 'DESC') { + return aValue < bValue; + } + return bValue < aValue; + }); + } + return arr; +}; + +Common.prototype.filter = function (arr, filter) { + if (_type.isNullOrUndefined(arr)) + return arr; + if (filter instanceof tizen.AttributeFilter || + filter instanceof tizen.AttributeRangeFilter || + filter instanceof tizen.CompositeFilter) { + arr = arr.filter(function(element) { + return filter._filter(element); + }); + } + return arr; +}; + +Common.prototype.repackFilter = function (filter) { + if (filter instanceof tizen.AttributeFilter) { + return { + filterType: "AttributeFilter", + attributeName: filter.attributeName, + matchFlag: filter.matchFlag, + matchValue: filter.matchValue, + }; + } + if (filter instanceof tizen.AttributeRangeFilter) { + return { + filterType: "AttributeRangeFilter", + attributeName: filter.attributeName, + initialValue: _type.isNullOrUndefined(filter.initialValue) ? null : filter.initialValue, + endValue: _type.isNullOrUndefined(filter.endValue) ? null : filter.endValue + }; + } + if (filter instanceof tizen.CompositeFilter) { + var _f = []; + var filters = filter.filters; + + for (var i = 0; i < filters.length; ++i) { + _f.push(this.repackFilter(filters[i])); + } + + return { + filterType: "CompositeFilter", + type: filter.type, + filters: _f + }; + } + + return null; +} + var _common = new Common(); + + return { + Type : _type, + Converter : _converter, + ArgumentValidator : _validator, + Common : _common + }; +}; + +var _common = new Common(); +var T = _common.Type; +var Converter = _common.Converter; +var AV = _common.ArgumentValidator; +var C = _common.Common; + +var _listeners = {}; +var _nextId = 0; + +extension.setMessageListener(function(msg) { + +}); + +function CallHistory() { +} + +CallHistory.prototype.find = function() { + +} + +CallHistory.prototype.remove = function() { + +} + +CallHistory.prototype.removeBatch = function() { + +} + +CallHistory.prototype.removeAll = function() { + +} + +CallHistory.prototype.addChangeListener = function() { + +} + +CallHistory.prototype.removeChangeListener = function() { + +} + +function RemoteParty(data) { + +} + +function CallHistoryEntry(data) { + +} + +// Exports +var CallHistoryObject = new CallHistory(); + +exports.find = CallHistoryObject.find; +exports.remove = CallHistoryObject.remove; +exports.removeBatch = CallHistoryObject.removeBatch; +exports.removeAll = CallHistoryObject.removeAll; +exports.addChangeListener = CallHistoryObject.addChangeListener; +exports.removeChangeListener = CallHistoryObject.removeChangeListener; diff --git a/src/callhistory/callhistory_extension.cc b/src/callhistory/callhistory_extension.cc new file mode 100644 index 00000000..24855939 --- /dev/null +++ b/src/callhistory/callhistory_extension.cc @@ -0,0 +1,24 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "callhistory/callhistory_extension.h" +#include "callhistory/callhistory_instance.h" + +// This will be generated from power_api.js +extern const char kSource_callhistory_api[]; + +common::Extension* CreateExtension() { + return new CallHistoryExtension; +} + +CallHistoryExtension::CallHistoryExtension() { + SetExtensionName("tizen.callhistory"); + SetJavaScriptAPI(kSource_callhistory_api); +} + +CallHistoryExtension::~CallHistoryExtension() {} + +common::Instance* CallHistoryExtension::CreateInstance() { + return new extension::callhistory::CallHistoryInstance; +} diff --git a/src/callhistory/callhistory_extension.h b/src/callhistory/callhistory_extension.h new file mode 100644 index 00000000..3924eae4 --- /dev/null +++ b/src/callhistory/callhistory_extension.h @@ -0,0 +1,19 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CALLHISTORY_CALLHISTORY_EXTENSION_H_ +#define CALLHISTORY_CALLHISTORY_EXTENSION_H_ + +#include "common/extension.h" + +class CallHistoryExtension : public common::Extension { +public: + CallHistoryExtension(); + virtual ~CallHistoryExtension(); + +private: + virtual common::Instance* CreateInstance(); +}; + +#endif // CALLHISTORY_CALLHISTORY_EXTENSION_H_ diff --git a/src/callhistory/callhistory_instance.cc b/src/callhistory/callhistory_instance.cc new file mode 100644 index 00000000..645435ae --- /dev/null +++ b/src/callhistory/callhistory_instance.cc @@ -0,0 +1,66 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "callhistory/callhistory_instance.h" + +#include "common/picojson.h" +#include "common/logger.h" +#include "common/platform_exception.h" + +namespace extension { +namespace callhistory { + +namespace { +// The privileges that required in CallHistory API +const std::string kPrivilegeCallHistoryRead = "http://tizen.org/privilege/callhistory.read"; +const std::string kPrivilegeCallHistoryWrite = "http://tizen.org/privilege/callhistory.write"; +} + +using namespace common; + +CallHistoryInstance::CallHistoryInstance() { + using namespace std::placeholders; +#define REGISTER_SYNC(c,x) \ + RegisterSyncHandler(c, std::bind(&CallHistoryInstance::x, this, _1, _2)); + REGISTER_SYNC("remove", Remove); + REGISTER_SYNC("addChangeListener", AddChangeListener); + REGISTER_SYNC("removeChangeListener", RemoveChangeListener); +#undef REGISTER_SYNC +#define REGISTER_ASYNC(c,x) \ + RegisterHandler(c, std::bind(&CallHistoryInstance::x, this, _1, _2)); + REGISTER_ASYNC("find", Find); + REGISTER_ASYNC("removeBatch", RemoveBatch); + REGISTER_ASYNC("removeAll", RemoveAll); +#undef REGISTER_ASYNC +} + +CallHistoryInstance::~CallHistoryInstance() { +} + +void CallHistoryInstance::Find(const picojson::value& args, picojson::object& out) { + +} + +void CallHistoryInstance::Remove(const picojson::value& args, picojson::object& out) { + +} + +void CallHistoryInstance::RemoveBatch(const picojson::value& args, picojson::object& out) { + +} + +void CallHistoryInstance::RemoveAll(const picojson::value& args, picojson::object& out) { + +} + +void CallHistoryInstance::AddChangeListener(const picojson::value& args, picojson::object& out) { + +} + +void CallHistoryInstance::RemoveChangeListener(const picojson::value& args, picojson::object& out) { + +} + +} // namespace callhistory +} // namespace extension diff --git a/src/callhistory/callhistory_instance.h b/src/callhistory/callhistory_instance.h new file mode 100644 index 00000000..1718e781 --- /dev/null +++ b/src/callhistory/callhistory_instance.h @@ -0,0 +1,31 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CALLHISTORY_CALLHISTORY_INSTANCE_H_ +#define CALLHISTORY_CALLHISTORY_INSTANCE_H_ + +#include "common/extension.h" +#include "callhistory.h" + +namespace extension { +namespace callhistory { + +class CallHistoryInstance : public common::ParsedInstance { +public: + CallHistoryInstance(); + virtual ~CallHistoryInstance(); + +private: + void Find(const picojson::value& args, picojson::object& out); + void Remove(const picojson::value& args, picojson::object& out); + void RemoveBatch(const picojson::value& args, picojson::object& out); + void RemoveAll(const picojson::value& args, picojson::object& out); + void AddChangeListener (const picojson::value& args, picojson::object& out); + void RemoveChangeListener(const picojson::value& args, picojson::object& out); +}; + +} // namespace callhistory +} // namespace extension + +#endif // CALLHISTORY_CALLHISTORY_INSTANCE_H_ diff --git a/src/callhistory/callhistory_utils.cc b/src/callhistory/callhistory_utils.cc new file mode 100644 index 00000000..899f6764 --- /dev/null +++ b/src/callhistory/callhistory_utils.cc @@ -0,0 +1,3 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. diff --git a/src/callhistory/callhistory_utils.h b/src/callhistory/callhistory_utils.h new file mode 100644 index 00000000..899f6764 --- /dev/null +++ b/src/callhistory/callhistory_utils.h @@ -0,0 +1,3 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. diff --git a/src/tizen-wrt.gyp b/src/tizen-wrt.gyp index 4942c8cd..cc82400f 100644 --- a/src/tizen-wrt.gyp +++ b/src/tizen-wrt.gyp @@ -14,6 +14,7 @@ 'power/power.gyp:*', 'messageport/messageport.gyp:*', #'calendar/calendar.gyp:*', + 'callhistory/callhistory.gyp:*', 'bookmark/bookmark.gyp:*', #'datasync/datasync.gyp:*', 'contact/contact.gyp:*',