#include "common/logger.h"
#include "common/converter.h"
#include "common/scope_exit.h"
+#include "common/tools.h"
#include "alarm_instance.h"
#include "alarm_utils.h"
#include "common/extension.h"
#include "common/logger.h"
#include "common/platform_result.h"
+#include "common/tools.h"
using namespace common;
using namespace tools;
#include <bundle.h>
#include <bundle_internal.h>
-#include "application/application_instance.h"
-#include "application/application_utils.h"
#include "common/current_application.h"
#include "common/logger.h"
#include "common/platform_result.h"
-#include "common/task-queue.h"
#include "common/scope_exit.h"
+#include "common/task-queue.h"
+#include "common/tools.h"
+
+#include "application/application_instance.h"
+#include "application/application_utils.h"
using namespace common;
using namespace tools;
#include <bundle_internal.h>
#include "common/logger.h"
+#include "common/tools.h"
+
#include "application/application_utils.h"
using namespace common;
#include "bluetooth_internal.h"
#include "common/converter.h"
+#include "common/extension.h"
#include "common/logger.h"
#include "common/platform_result.h"
-#include "common/extension.h"
#include "common/task-queue.h"
+#include "common/tools.h"
#include "bluetooth/bluetooth_class.h"
#include "bluetooth/bluetooth_device.h"
#include "bluetooth_device.h"
#include "common/converter.h"
-#include "common/logger.h"
#include "common/extension.h"
+#include "common/logger.h"
+#include "common/tools.h"
#include "bluetooth_adapter.h"
#include "bluetooth_class.h"
#include <sstream>
+#include "common/extension.h"
#include "common/logger.h"
#include "common/platform_result.h"
-#include "common/extension.h"
#include "common/task-queue.h"
+#include "common/tools.h"
#include "bluetooth/bluetooth_instance.h"
#include "bluetooth/bluetooth_util.h"
#include "bluetooth_health_application.h"
#include "common/converter.h"
-#include "common/logger.h"
#include "common/extension.h"
+#include "common/logger.h"
+#include "common/tools.h"
#include "bluetooth_health_profile_handler.h"
#include "bluetooth_util.h"
#include <memory>
#include "common/converter.h"
-#include "common/logger.h"
#include "common/extension.h"
+#include "common/logger.h"
+#include "common/tools.h"
#include "bluetooth_device.h"
#include "bluetooth_util.h"
#include "bluetooth_health_profile_handler.h"
#include "common/converter.h"
-#include "common/logger.h"
#include "common/extension.h"
+#include "common/logger.h"
#include "common/task-queue.h"
+#include "common/tools.h"
#include "bluetooth/bluetooth_adapter.h"
#include "bluetooth/bluetooth_instance.h"
#include "common/converter.h"
#include "common/logger.h"
#include "common/task-queue.h"
+#include "common/tools.h"
namespace extension {
namespace bluetooth {
#include "bluetooth_service_handler.h"
#include "common/converter.h"
-#include "common/logger.h"
#include "common/extension.h"
+#include "common/logger.h"
+#include "common/tools.h"
#include "bluetooth_adapter.h"
#include "bluetooth_util.h"
#include <memory>
#include "common/converter.h"
-#include "common/logger.h"
#include "common/extension.h"
+#include "common/logger.h"
+#include "common/tools.h"
#include "bluetooth_adapter.h"
#include "bluetooth_device.h"
#include "common/logger.h"
#include "common/platform_exception.h"
-#include "common/task-queue.h"
#include "common/scope_exit.h"
+#include "common/task-queue.h"
+#include "common/tools.h"
+
#include "callhistory_instance.h"
#include "callhistory_types.h"
#include <string>
#include <mutex>
#include <map>
-#include "common/callback_user_data.h"
#include "common/picojson.h"
#include "common/platform_result.h"
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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 "common/callback_user_data.h"
-
-namespace common {
-
-CallbackUserData::CallbackUserData() :
- m_is_act(true) {
-}
-
-CallbackUserData::~CallbackUserData() {
-}
-
-void CallbackUserData::setActive(bool act) {
- m_is_act = act;
-}
-
-bool CallbackUserData::isActive() const {
- return m_is_act;
-}
-
-void CallbackUserData::setJson(std::shared_ptr<picojson::value> json) {
- m_json = json;
-}
-
-std::shared_ptr<picojson::value> CallbackUserData::getJson() const {
- return m_json;
-}
-
-} // common
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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.
- */
-
-// Class added for backward compatibility with WRT plugins.
-// TODO To be cleaned/replaced in the future.
-
-#ifndef COMMON_CALLBACK_USER_DATA_H_
-#define COMMON_CALLBACK_USER_DATA_H_
-
-#include "common/picojson.h"
-
-#include <memory>
-
-namespace common {
-
-class CallbackUserData {
-public:
- CallbackUserData();
-
- virtual ~CallbackUserData();
-
- void setActive(bool act);
- bool isActive() const;
-
- void setJson(std::shared_ptr<picojson::value> json);
- std::shared_ptr<picojson::value> getJson() const;
-
- virtual void setError(const std::string& err_name,
- const std::string& err_message) = 0;
-
-protected:
- std::shared_ptr<picojson::value> m_json;
-
-private:
- bool m_is_act;
-};
-
-} // common
-
-#endif // COMMON_CALLBACK_USER_DATA_H_
'task-queue.h',
'tools.cc',
'tools.h',
- 'callback_user_data.cc',
- 'callback_user_data.h',
'optional.h',
'platform_result.cc',
'platform_result.h',
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
-#include "logger.h"
-#include "platform_exception.h"
+#include "common/logger.h"
#define DBUS_REPLY_TIMEOUT (-1)
const int length = val.length();
char* p_val = new char[length+1];
- strncpy(p_val, val.c_str(), length+1); // TODO: is it safe?
+ // copy 'length' characters and add a NULL-character at 'length+1' position
+ strncpy(p_val, val.c_str(), length+1);
arguments_.push_back(ArgumentElement(ArgType::kTypeString, p_val));
}
}
}
-int DBusOperation::InvokeSyncGetInt(const std::string& method,
- DBusOperationArguments* args) {
-
- LoggerD("Enter");
- if (!connection_) {
- connection_ = dbus_bus_get_private(DBUS_BUS_SYSTEM, nullptr);
- }
-
- if (!connection_) {
- LoggerE("dbus_bus_get_private error");
- throw UnknownException("Failed to get dbus connection");
- }
-
- DBusMessage* msg = dbus_message_new_method_call(destination_.c_str(),
- path_.c_str(),
- interface_.c_str(),
- method.c_str());
-
- if (!msg) {
- LoggerE("dbus_message_new_method_call error");
- throw UnknownException("Failed to create dbus message");
- }
-
- DBusMessageIter iter;
- dbus_message_iter_init_append(msg, &iter);
-
- if (nullptr != args) {
- try {
- args->AppendVariant(&iter);
- } catch (const UnknownException& ex) {
- LoggerE("append_variant error");
- dbus_message_unref(msg);
- throw UnknownException("Failed to append dbus variable");
- }
- }
-
- DBusError err;
- dbus_error_init(&err);
- DBusMessage* reply = dbus_connection_send_with_reply_and_block(connection_,
- msg,
- DBUS_REPLY_TIMEOUT,
- &err);
- dbus_message_unref(msg);
-
- if (!reply) {
- LoggerE("dbus_connection_send_with_reply_and_block error %s: %s", err.name, err.message);
- dbus_error_free(&err);
- throw UnknownException("Failed to send request via dbus");
- }
-
- int result = 0;
- dbus_bool_t ret = dbus_message_get_args(reply,
- &err,
- DBUS_TYPE_INT32,
- &result,
- DBUS_TYPE_INVALID);
- dbus_message_unref(reply);
-
- if (!ret) {
- LoggerE("dbus_message_get_args error %s: %s", err.name, err.message);
- dbus_error_free(&err);
- throw UnknownException("Failed to get reply from dbus");
- }
-
- return result;
-}
-
PlatformResult DBusOperation::InvokeSyncGetInt(const std::string& method,
DBusOperationArguments* args, int* result) {
#include <set>
#include <dbus/dbus.h>
-#include "platform_result.h"
+
+#include "common/platform_result.h"
namespace common {
const std::string& interface);
virtual ~DBusOperation();
- int InvokeSyncGetInt(const std::string& method,
- DBusOperationArguments* args);
- //TODO remove throwing methods when they would be not needed any more.
common::PlatformResult InvokeSyncGetInt(const std::string& method,
DBusOperationArguments* args, int* result);
#include <vector>
#include <string>
#include <map>
-#include "common/logger.h"
+
#include "common/assert.h"
+#include "common/logger.h"
+#include "common/tools.h"
// This function is hidden, because each plugin needs to have own implementation.
__attribute__ ((visibility ("hidden"))) common::Extension* CreateExtension() {
#include "common/platform_exception.h"
#include "common/platform_result.h"
-// TODO: this include should be moved to source file
-// it's here, so we don't break other modules using it implicitly
-#include "common/tools.h"
#include "common/XW_Extension.h"
#include "common/XW_Extension_EntryPoints.h"
#include "common/XW_Extension_Permissions.h"
g_idle_add(AfterWorkCallback<void>, d);
}
-//TODO check if it would be needed in future
-//void TaskQueue::AsyncResponse(int callback_handle, const std::shared_ptr<picojson::value>& response) {
-// Async<picojson::value>([callback_handle](const std::shared_ptr<picojson::value>& response) {
-// wrt::common::NativeContext::GetInstance()->InvokeCallback(callback_handle,
-// response->serialize());
-// }, response);
-//}
} // namespace common
*/
void Async(const std::function<void()>& work);
- //TODO not needed now, but maybe in future
-// void AsyncResponse(int callback_handle, const std::shared_ptr<picojson::value>& response);
-
private:
TaskQueue() {}
std::vector<VirtualStorage> GetStorages() const;
- // TODO: add stat method
-
static VirtualFs& GetInstance();
private:
if (status.IsError()) return status;
const JsonObject& contact = FromJson<JsonObject>(args, "contact");
+ long addressBookId = common::stol(FromJson<JsonString>(args, "addressBookId"));
if (!IsNull(contact, "id")) {
LoggerW("Contact already exists");
ContactUtil::ExportContactToContactsRecord(*contacts_record_ptr, contact);
if (status.IsError()) return status;
+ status = ContactUtil::SetIntInRecord(
+ contacts_record, _contacts_contact.address_book_id, addressBookId);
+ if (status.IsError()) return status;
+
int id = -1;
err = contacts_db_insert_record(*contacts_record_ptr, &id);
if (CONTACTS_ERROR_NONE != err) {
if (status.IsError()) return status;
const JsonObject& contact = FromJson<JsonObject>(args, "contact");
- const JsonObject& addressbook = FromJson<JsonObject>(args, "addressBook");
long contactId = common::stol(FromJson<JsonString>(contact, "id"));
if (IsNull(contact, "id")) {
return PlatformResult(ErrorCode::UNKNOWN_ERR, "Contact doesn't exist");
}
- if (IsNull(addressbook, "id")) {
- LoggerE("Contact is not saved in database");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR,
- "Contact is not saved in database");
- }
-
contacts_record_h to_update = nullptr;
int err = contacts_db_get_record(_contacts_contact._uri, contactId, &to_update);
if (CONTACTS_ERROR_NONE != err) {
if (status.IsError()) return status;
const JsonArray& batch_args = FromJson<JsonArray>(args, "batchArgs");
- const JsonObject& addressBook = FromJson<JsonObject>(args, "addressBook");
- if (IsNull(addressBook, "id")) {
- LoggerE("Contact is not saved in database");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR,
- "Contact is not saved in database");
- }
contacts_list_h contacts_list = NULL;
int err = 0;
err = contacts_list_create(&contacts_list);
PlatformResult status = ContactUtil::CheckDBConnection();
if (status.IsError()) return status;
const JsonArray& batch_args = FromJson<JsonArray>(args, "batchArgs");
- const JsonObject& addressBook = FromJson<JsonObject>(args, "addressBook");
- if (IsNull(addressBook, "id")) {
- LoggerE("Contact is not saved in database");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR,
- "Contact is not saved in database");
- }
int length = static_cast<int>(batch_args.size());
int ids[length], i=0;
for (auto& item : batch_args) {
ContactUtil::ContactsRecordHPtr record(&contacts_record,
ContactUtil::ContactsDeleter);
-
- long addressbook_id =
- common::stol(FromJson<JsonString>(args, "addressBook", "id"));
+ long addressbook_id = common::stol(FromJson<std::string>(args, "addressBookId"));
if (IsUnified(addressbook_id)) {
int address_book_id = 0;
status = ContactUtil::GetIntFromRecord(
}
int err;
- long addressbook_id = AddressBookId(args);
+ long addressbook_id = common::stol(FromJson<std::string>(args, "addressBookId"));
if (!IsUnified(addressbook_id)) {
contacts_record_h contacts_record = nullptr;
err = contacts_db_get_record(_contacts_group._uri, id, &contacts_record);
if (status.IsError()) return status;
}
+ const auto sort_mode_it = args.find("sortMode");
+ if (args.end() != sort_mode_it) {
+ if (!sort_mode_it->second.is<picojson::object>()) {
+ LoggerD("Failed to set sort mode.");
+ return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Failed to set sort mode");
+ }
+ const auto sort_mode = sort_mode_it->second;
+ std::string attribute = sort_mode.get("attributeName").to_str();
+
+ Person::PersonProperty property;
+ status = Person::PersonPropertyFromString(attribute, &property);
+ if (status.IsError()) return status;
+
+ bool is_asc = sort_mode.get("order").to_str() == "ASC";
+ error_code = contacts_query_set_sort(contacts_query, property.propertyId, is_asc);
+ status = ContactUtil::ErrorChecker(error_code,
+ "Failed contacts_query_set_sort");
+ if (status.IsError()) return status;
+ }
+
contacts_list_h person_list = nullptr;
error_code =
contacts_db_get_records_with_query(contacts_query, 0, 0, &person_list);
};
// implementation ported from wrt-plugins-tizen
-// TODO: instead of executing multiple queries and combining the results,
-// create multiple filters, combine them into one, add sorting and
-// execute a single query
ContactSearchEngine::ContactSearchEngine()
: addressbook_id_(0),
is_sort_mode_set_ = true;
sort_mode_attribute_ = attribute;
- is_sort_mode_asc_ = sort_mode.get("attributeName").to_str() == "ASC";
+ is_sort_mode_asc_ = sort_mode.get("order").to_str() == "ASC";
return PlatformResult(ErrorCode::NO_ERROR);
}
ContactUtil::ContactsFilterPtr sub_filter_ptr(sub_filter,
ContactUtil::ContactsFilterDeleter);
- // TODO To be supported: start
error_code = contacts_filter_add_str(sub_filter, property_id,
CONTACTS_MATCH_STARTSWITH,
initial_value);
nickname_ptr.release();
}
- // TODO update displayName in JS!
-
return PlatformResult(ErrorCode::NO_ERROR);
}
}
var result = native_.callSync('AddressBook_get', {
- // TODO move to only sending the address book id (in all functions)
- addressBook: this,
id: args.id
});
]);
var result = native_.callSync('AddressBook_add', {
- // TODO move to only sending the address book id (in all functions)
- addressBook: this,
+ addressBookId: this.id,
contact: _toJsonObject(args.contact)
});
}
]);
+ if (args.contact.addressBookId !== this.id && UNIFIED_ADDRESSBOOK_ID !== this.id) {
+ throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
+ }
+
var result = native_.callSync('AddressBook_update', {
- addressBook: this,
contact: _toJsonObject(args.contact)
});
native_.callIfPossible(args.successCallback);
};
+ var thatId = this.id;
+ args.contacts.forEach(function(c) {
+ if (c.addressBookId !== thatId && UNIFIED_ADDRESSBOOK_ID !== thatId) {
+ setTimeout(function() {
+ native_.callIfPossible(args.errorCallback, new WebAPIException(
+ WebAPIException.INVALID_VALUES_ERR,
+ 'Contact is not saved in database'));
+ }, 0);
+
+ return;
+ }
+ });
+
native_.call('AddressBook_updateBatch', {
- addressBook: this,
batchArgs: _toJsonObject(args.contacts)
}, callback);
};
}
var result = native_.callSync('AddressBook_remove', {
- addressBook: this,
id: args.id
});
};
native_.call('AddressBook_removeBatch', {
- addressBook: this,
batchArgs: args.ids
}, callback);
};
}
var result = native_.callSync('AddressBook_getGroup', {
- addressBook: this,
+ addressBookId: this.id,
id: args.groupId
});
if (native_.isFailure(result)) {
}
var result = native_.callSync('AddressBook_removeGroup',
- {addressBook: this, id: args.groupId});
+ {addressBookId: this.id, id: args.groupId});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
return _canEdit > 0;
};
-var _editGuard = new EditGuard();
-
-//TODO: Move sorting and filtering to native code
-var Common = function() {};
-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;
-};
-
-var C = new Common();
+var _editGuard = new EditGuard();
\ No newline at end of file
}
]);
- // TODO implement contact filtering/sorting.
var data = {
filter: utils_.repackFilter(args.filter),
sortMode: args.sortMode
for (var i = 0; i < _result.length; ++i) {
retval.push(self.get(String(_result[i])));
}
- //TODO: Move sorting to native code
- retval = C.sort(retval, args.sortMode);
args.successCallback(retval);
} else {
native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
}
var result = native_.callSync('Person_link', {
- // TODO move to only sending the person id (in all functions)
- person: this,
+ personId: this.id,
id: args.personId
});
if (native_.isFailure(result)) {
}
var result = native_.callSync('Person_unlink', {
- // TODO move to only sending the person id (in all functions)
- person: this,
+ personId: this.id,
id: args.contactId
});
if (native_.isFailure(result)) {
if (status.IsError()) return status;
long id = common::stol(FromJson<JsonString>(args, "id"));
- long person_id = common::stol(FromJson<JsonString>(args, "person", "id"));
+ long person_id = common::stol(FromJson<JsonString>(args, "personId"));
contacts_record_h contacts_record = nullptr;
"Contact is not a member of person");
if (status.IsError()) return status;
- long person_id = common::stol(FromJson<JsonString>(args, "person", "id"));
+ long person_id = common::stol(FromJson<JsonString>(args, "personId"));
if (contacts_person_id != person_id) {
LoggerW("Contact is not a member of person (wrong id's)");
return PlatformResult(ErrorCode::INVALID_VALUES_ERR,
#include "common/picojson.h"
#include "common/platform_result.h"
#include "common/task-queue.h"
+#include "common/tools.h"
#include "common/virtual_fs.h"
+
#include "content/content_manager.h"
namespace extension {
#include "common/converter.h"
#include "common/logger.h"
#include "common/scope_exit.h"
+#include "common/tools.h"
#include "common/virtual_fs.h"
+
#include "content/content_filter.h"
-#include "common/virtual_fs.h"
using namespace std;
using namespace common;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+function _checkClosed(stream) {
+ if (stream._closed) {
+ throw new WebAPIException(WebAPIException.IO_ERR, 'Stream is closed.');
+ }
+}
+
+function _checkReadAccess(mode) {
+ if (mode !== 'r' && mode !== 'rw') {
+ throw new WebAPIException(WebAPIException.IO_ERR, 'Stream is not in read mode.');
+ }
+}
+
+function _checkWriteAccess(mode) {
+ if (mode !== 'a' && mode !== 'w' && mode !== 'rw') {
+ throw new WebAPIException(WebAPIException.IO_ERR, 'Stream is not in write mode.');
+ }
+}
function FileStream(data, mode, encoding) {
var _totalBytes = data.fileSize || 0;
Object.defineProperties(this, {
eof: {
- value: false,
- enumerable: true,
- writable: false
+ get: function() {
+ return _totalBytes < _position;
+ },
+ set: function(v) {
+ },
+ enumerable: true
},
position: {
get: function() {
enumerable: true
},
bytesAvailable: {
- value: this.eof ? -1 : Math.max(0, _totalBytes - _position),
- enumerable: true,
- writable: false
+ get: function() {
+ return this.eof ? -1 : Math.max(0, _totalBytes - _position);
+ },
+ set: function(v) {
+ },
+ enumerable: true
},
_mode: {
value: mode,
enumerable: false
}
});
-}
-function _checkClosed(stream) {
- if (stream._closed) {
- throw new WebAPIException(WebAPIException.IO_ERR, 'Stream is closed.');
- }
+ this.write = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_WRITE);
+
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'stringData',
+ type: types_.STRING
+ }
+ ]);
+
+ _checkClosed(this);
+ _checkWriteAccess(this._mode);
+ if (!arguments.length) {
+ throw new WebAPIException(WebAPIException.NOT_FOUND_ERR,
+ 'Argument "stringData" missing');
+ }
+
+ var data = {
+ location: commonFS_.toRealPath(this._file.fullPath),
+ offset: this.position,
+ length: args.stringData.length,
+ is_base64: false,
+ };
+ var result = native_.callSyncData('File_writeSync', data, "string", args.stringData);
+ if (native_.isFailure(result.reply)) {
+ throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write');
+ }
+ this.position = this.position + result.reply.data_size;
+ _totalBytes = Math.max(this.position, _totalBytes);
+ };
+
+ this.writeBytes = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_WRITE);
+
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'byteData',
+ type: types_.ARRAY
+ }
+ ]);
+ _checkClosed(this);
+ _checkWriteAccess(this._mode);
+ if (!arguments.length) {
+ throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR,
+ 'Argument "byteData" missing');
+ }
+
+ var data = {
+ location: commonFS_.toRealPath(this._file.fullPath),
+ offset: this.position,
+ length: args.byteData.length,
+ is_base64: false,
+ };
+
+ var result = native_.callSyncData('File_writeSync', data, "octet", args.byteData);
+
+ if (native_.isFailure(result.reply)) {
+ throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write');
+ }
+ this.position = this.position + result.reply.data_size;
+ _totalBytes = Math.max(this.position, _totalBytes);
+ };
}
FileStream.prototype.close = function() {
this._closed = true;
};
-function _checkReadAccess(mode) {
- if (mode !== 'r' && mode !== 'rw') {
- throw new WebAPIException(WebAPIException.IO_ERR, 'Stream is not in read mode.');
- }
-}
-
-function _checkWriteAccess(mode) {
- if (mode !== 'a' && mode !== 'w' && mode !== 'rw') {
- throw new WebAPIException(WebAPIException.IO_ERR, 'Stream is not in write mode.');
- }
-}
-
FileStream.prototype.read = function() {
xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_READ);
return result.output;
};
-FileStream.prototype.write = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_WRITE);
-
- var args = validator_.validateArgs(arguments, [
- {
- name: 'stringData',
- type: types_.STRING
- }
- ]);
-
- _checkClosed(this);
- _checkWriteAccess(this._mode);
- if (!arguments.length) {
- throw new WebAPIException(WebAPIException.NOT_FOUND_ERR,
- 'Argument "stringData" missing');
- }
-
- var data = {
- location: commonFS_.toRealPath(this._file.fullPath),
- offset: this.position,
- length: args.stringData.length,
- is_base64: false,
- };
- var result = native_.callSyncData('File_writeSync', data, "string", args.stringData);
- if (native_.isFailure(result.reply)) {
- throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write');
- }
- this.position = this.position + result.reply.data_size;
-};
-
-FileStream.prototype.writeBytes = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_WRITE);
-
- var args = validator_.validateArgs(arguments, [
- {
- name: 'byteData',
- type: types_.ARRAY
- }
- ]);
- _checkClosed(this);
- _checkWriteAccess(this._mode);
- if (!arguments.length) {
- throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR,
- 'Argument "byteData" missing');
- }
-
- var data = {
- location: commonFS_.toRealPath(this._file.fullPath),
- offset: this.position,
- length: args.byteData.length,
- is_base64: false,
- };
-
- var result = native_.callSyncData('File_writeSync', data, "octet", args.byteData);
-
- if (native_.isFailure(result.reply)) {
- throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write');
- }
- this.position = this.position + result.reply.data_size;
-
-};
-
function _isBase64(str) {
var base64 = new RegExp('^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$');
return base64.test(str);
if (!ret.IsError()) {
LoggerD("Updated Message attachment object");
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
picojson::object args;
args[JSON_DATA_MESSAGE_ATTACHMENT] = MessagingUtil::messageAttachmentToJson(
callback->getMessageAttachment());
- obj[JSON_DATA] = picojson::value(args);
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
+ callback->SetSuccess(picojson::value(args));
+ callback->Post();
}
} else if(NOTI_DOWNLOAD_ATTACH_FAIL) {
LoggerD("Load message attachment failed!");
}
if (ret.IsError()) {
LoggerE("Exception in signal callback");
- callback->setError(ret);
- callback->getQueue().resolve(
- callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
- callback->getJson()->serialize()
- );
+ callback->SetError(ret);
+ callback->Post();
}
if(callback) {
if (!ret.IsError()) {
LoggerD("Calling success callback");
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
picojson::object args;
args[JSON_DATA_MESSAGE_BODY] = MessagingUtil::messageBodyToJson(
callback->getMessage()->getBody());
- obj[JSON_DATA] = picojson::value(args);
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
+ callback->SetSuccess(picojson::value(args));
+ callback->Post();
}
} else if(NOTI_DOWNLOAD_BODY_FAIL == status) {
LoggerD("Load message body failed!");
}
if (ret.IsError()) {
- callback->setError(ret);
- callback->getQueue().resolve(
- callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
- callback->getJson()->serialize()
- );
+ callback->SetError(ret);
+ callback->Post();
}
removeCallback(callback);
}
}
-void SyncProxy::addCallback(long op_id, common::CallbackUserData* callbackOwned)
+void SyncProxy::addCallback(long op_id, CallbackUserData* callbackOwned)
{
m_callback_map.insert(std::make_pair(op_id, callbackOwned));
}
-common::CallbackUserData* SyncProxy::getCallback(long op_id) {
- common::CallbackUserData* cb = nullptr;
+CallbackUserData* SyncProxy::getCallback(long op_id) {
+ CallbackUserData* cb = nullptr;
const auto it = m_callback_map.find(op_id);
if (it != m_callback_map.end()) {
return;
}
- std::shared_ptr<picojson::value> response = callback->getJson();
- picojson::object& obj = response->get<picojson::object>();
switch (status) {
case NOTI_DOWNLOAD_FINISH:
LoggerD("Sync finished!");
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- response->serialize()
- );
+ callback->SetSuccess();
+ callback->Post();
break;
case NOTI_DOWNLOAD_FAIL:
- {
LoggerD("Sync failed!");
- callback->setError("UnknownError", "Sync failed!");
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- response->serialize()
- );
- }
- break;
+ callback->SetError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Sync failed!"));
+ callback->Post();
+ break;
}
#ifndef __TIZEN_DBUS_SYNC_PROXY_H__
#define __TIZEN_DBUS_SYNC_PROXY_H__
+#include "messaging/callback_user_data.h"
#include "EmailSignalProxy.h"
#include "common/platform_result.h"
public:
// Callback is owned by this map
- typedef std::map<long, common::CallbackUserData*> CallbackMap;
+ typedef std::map<long, CallbackUserData*> CallbackMap;
virtual ~SyncProxy();
const std::string& iface,
SyncProxyPtr* sync_proxy);
//Passed callback will be owned by this proxy
- void addCallback(long op_id, common::CallbackUserData* callbackOwned);
- common::CallbackUserData* getCallback(long op_id);
+ void addCallback(long op_id, CallbackUserData* callbackOwned);
+ CallbackUserData* getCallback(long op_id);
void removeCallback(long op_id);
protected:
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 "messaging/callback_user_data.h"
+
+#include "common/logger.h"
+
+namespace extension {
+namespace messaging {
+
+CallbackUserData::CallbackUserData(PostQueue& queue, long cid, bool keep /* = false */)
+ : json_(picojson::object()),
+ obj_(json_.get<picojson::object>()),
+ cid_(cid),
+ queue_(queue),
+ result_(common::ErrorCode::NO_ERROR) {
+ LoggerD("Entered");
+ AddJsonData(JSON_CALLBACK_ID, picojson::value(static_cast<double>(cid_)));
+ AddJsonData(JSON_CALLBACK_KEEP, picojson::value(keep));
+}
+
+CallbackUserData::~CallbackUserData() {
+ LoggerD("Entered");
+}
+
+bool CallbackUserData::IsError() const {
+ LoggerD("Entered");
+ return result_.IsError();
+}
+
+void CallbackUserData::SetError(const common::PlatformResult& error) {
+ LoggerD("Entered");
+
+ // keep only the first error
+ if (!IsError()) {
+ result_ = error;
+ SetAction(JSON_CALLBACK_ERROR, error.ToJSON());
+ }
+}
+
+void CallbackUserData::SetSuccess(const picojson::value& data /* = picojson::value()*/) {
+ LoggerD("Entered");
+
+ // do not allow to overwrite the error
+ if (!IsError()) {
+ SetAction(JSON_CALLBACK_SUCCCESS, data);
+ }
+}
+
+void CallbackUserData::SetAction(const char* action, const picojson::value& data) {
+ LoggerD("Entered");
+
+ AddJsonData(JSON_ACTION, picojson::value(action));
+ AddJsonData(JSON_DATA, data);
+}
+
+void CallbackUserData::AddToQueue() {
+ LoggerD("Entered");
+ queue_.add(cid_, PostPriority::HIGH);
+}
+
+void CallbackUserData::Post() {
+ LoggerD("Entered");
+ queue_.resolve(cid_, json_.serialize());
+}
+
+void CallbackUserData::AddAndPost(PostPriority p) {
+ queue_.addAndResolve(cid_, p, json_.serialize());
+}
+
+bool CallbackUserData::HasQueue(const PostQueue& q) const {
+ LoggerD("Entered");
+ return &q == &queue_;
+}
+
+void CallbackUserData::AddJsonData(const char* key, const picojson::value& value) {
+ LoggerD("Entered");
+ // always overwrite
+ obj_[key] = value;
+}
+
+} // messaging
+} // extension
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 MESSAGING_CALLBACK_USER_DATA_H_
+#define MESSAGING_CALLBACK_USER_DATA_H_
+
+#include <memory>
+
+#include "common/picojson.h"
+
+#include "messaging/messaging_util.h"
+
+namespace extension {
+namespace messaging {
+
+class CallbackUserData {
+ public:
+ CallbackUserData(PostQueue& queue, long cid, bool keep = false);
+ virtual ~CallbackUserData();
+
+ bool IsError() const;
+ void SetError(const common::PlatformResult& error);
+ void SetSuccess(const picojson::value& data = picojson::value());
+ void SetAction(const char* action, const picojson::value& data);
+
+ void AddToQueue();
+ void Post();
+ void AddAndPost(PostPriority p);
+ bool HasQueue(const PostQueue& q) const;
+
+ private:
+ void AddJsonData(const char* key, const picojson::value& value);
+
+ picojson::value json_;
+ picojson::object& obj_;
+ long cid_;
+ PostQueue& queue_;
+ common::PlatformResult result_;
+};
+
+} // messaging
+} // extension
+
+#endif // MESSAGING_CALLBACK_USER_DATA_H_
namespace extension {
namespace messaging {
-ConversationCallbackData::ConversationCallbackData(PostQueue& queue):
- m_filter(),
- m_sort(),
- m_limit(0),
- m_offset(0),
- m_is_error(false),
- m_account_id(0),
- m_service_type(UNDEFINED),
- queue_(queue)
-{
- LoggerD("Entered");
-}
-
-ConversationCallbackData::ConversationCallbackData(long cid, PostQueue& queue, bool keep):
- m_filter(),
- m_sort(),
- m_limit(0),
- m_offset(0),
- m_is_error(false),
- m_account_id(0),
- m_service_type(UNDEFINED),
- queue_(queue)
-{
- LoggerD("Entered");
- auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
- picojson::object& o = json->get<picojson::object>();
- o[JSON_CALLBACK_ID] = picojson::value(static_cast<double>(cid));
- o[JSON_CALLBACK_KEEP] = picojson::value(keep);
- setJson(json);
+ConversationCallbackData::ConversationCallbackData(PostQueue& queue, long cid, bool keep /* = false */) :
+ CallbackUserData(queue, cid, keep),
+ m_limit(0),
+ m_offset(0),
+ m_account_id(0),
+ m_service_type(UNDEFINED) {
+ LoggerD("Entered");
}
ConversationCallbackData::~ConversationCallbackData()
return m_conversations;
}
-void ConversationCallbackData::setError(const std::string& err_name,
- const std::string& err_message)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
- auto objData = picojson::object();
-
- objData[JSON_ERROR_NAME] = picojson::value(err_name);
- objData[JSON_ERROR_MESSAGE] = picojson::value(err_message);
-
- obj[JSON_DATA] = picojson::value(objData);
-
- m_is_error = true;
- m_err_name = err_name;
- m_err_message = err_message;
- }
-}
-
-void ConversationCallbackData::SetError(const common::PlatformResult& error)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- m_is_error = true;
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
- auto obj_data = picojson::object();
- obj_data[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
- obj_data[JSON_ERROR_MESSAGE] = picojson::value(error.message());
- obj[JSON_DATA] = picojson::value(obj_data);
- }
-}
-bool ConversationCallbackData::isError() const
-{
- return m_is_error;
-}
-
-std::string ConversationCallbackData::getErrorName() const
-{
- return m_err_name;
-}
-
-std::string ConversationCallbackData::getErrorMessage() const
-{
- return m_err_message;
-}
-
void ConversationCallbackData::setAccountId(int account_id){
m_account_id = account_id;
}
#ifndef MESSAGING_CONVERSATION_CALLBACK_DATA_H_
#define MESSAGING_CONVERSATION_CALLBACK_DATA_H_
-#include "common/callback_user_data.h"
#include <memory>
#include <string>
#include <vector>
+
+#include "messaging/callback_user_data.h"
#include "MsgCommon/AttributeFilter.h"
#include "MsgCommon/SortMode.h"
#include "messaging_util.h"
class Message;
class MessageConversation;
-class ConversationCallbackData: public common::CallbackUserData {
+class ConversationCallbackData : public CallbackUserData {
public:
- ConversationCallbackData(PostQueue& queue);
- ConversationCallbackData(long cid, PostQueue& queue, bool keep = false);
+ ConversationCallbackData(PostQueue& queue, long cid, bool keep = false);
virtual ~ConversationCallbackData();
void setFilter(AbstractFilterPtr filter);
std::vector<std::shared_ptr<MessageConversation>> getConversations() const;
- void setError(const std::string& err_name,
- const std::string& err_message);
- void SetError(const common::PlatformResult& error);
- bool isError() const;
- std::string getErrorName() const;
- std::string getErrorMessage() const;
-
void setAccountId(int account_id);
int getAccountId() const;
long getLimit() const;
long getOffset() const;
- PostQueue& getQueue() { return queue_;};
private:
AbstractFilterPtr m_filter;
SortModePtr m_sort;
long m_limit;
long m_offset;
- bool m_is_error;
- std::string m_err_name;
- std::string m_err_message;
std::vector<std::shared_ptr<MessageConversation>> m_conversations;
int m_account_id;
MessageType m_service_type;
- PostQueue& queue_;
};
}//messaging
int service_id,
MessageType service_type,
PostQueue& queue) :
- m_callback_data(cid, queue, true),
+ m_callback_data(queue, cid, true),
m_id(service_id),
m_msg_type(service_type),
m_is_act(true)
LoggerD("Calling:%s with:%d added conversations", CONVERSATIONSADDED,
filtered.size());
- auto json = m_callback_data.getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(CONVERSATIONSADDED);
- obj[JSON_DATA] = picojson::value(array);
-
- m_callback_data.getQueue().addAndResolve(obj.at(
- JSON_CALLBACK_ID).get<double>(), PostPriority::MEDIUM, json->serialize());
+ m_callback_data.SetAction(CONVERSATIONSADDED, picojson::value(array));
+ m_callback_data.AddAndPost(PostPriority::MEDIUM);
}
void ConversationsChangeCallback::updated(
LoggerD("Calling:%s with:%d added conversations", CONVERSATIONSUPDATED,
filtered.size());
- auto json = m_callback_data.getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(CONVERSATIONSUPDATED);
- obj[JSON_DATA] = picojson::value(array);
-
- m_callback_data.getQueue().addAndResolve(obj.at(
- JSON_CALLBACK_ID).get<double>(), PostPriority::LOW, json->serialize());
+ m_callback_data.SetAction(CONVERSATIONSUPDATED, picojson::value(array));
+ m_callback_data.AddAndPost(PostPriority::LOW);
}
void ConversationsChangeCallback::removed(
LoggerD("Calling:%s with:%d added conversations", CONVERSATIONSREMOVED,
filtered.size());
- auto json = m_callback_data.getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(CONVERSATIONSREMOVED);
- obj[JSON_DATA] = picojson::value(array);
-
- m_callback_data.getQueue().addAndResolve(obj.at(
- JSON_CALLBACK_ID).get<double>(), PostPriority::LAST, json->serialize());
+ m_callback_data.SetAction(CONVERSATIONSREMOVED, picojson::value(array));
+ m_callback_data.AddAndPost(PostPriority::LAST);
}
void ConversationsChangeCallback::setFilter(tizen::AbstractFilterPtr filter)
return false;
}
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- if (callback->isError()) {
- LoggerD("Calling error callback");
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
- callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
- } else {
- LoggerD("Calling success callback");
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
- picojson::object args;
- args[JSON_DATA_MESSAGE] = MessagingUtil::messageToJson(callback->getMessage());
- obj[JSON_DATA] = picojson::value(args);
-
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
- }
- } else {
- LoggerE("Callback id is missing");
+ if (callback->IsError()) {
+ LoggerD("Calling error callback");
callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
+ } else {
+ LoggerD("Calling success callback");
+
+ picojson::object args;
+ args[JSON_DATA_MESSAGE] = MessagingUtil::messageToJson(callback->getMessage());
+ callback->SetSuccess(picojson::value(args));
}
+ callback->Post();
+
delete callback;
callback = NULL;
PlatformResult ret = addDraftMessagePlatform(callback->getAccountId(), message);
if (ret.IsError()) {
LoggerE("%d (%s)", ret.error_code(), ret.message().c_str());
- callback->setError(ret);
+ callback->SetError(ret);
}
}
//Complete task
return false;
}
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- if (callback->isError()) {
- LoggerD("Calling error callback");
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
- callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
- }
- else {
- LoggerD("Calling success callback");
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
- std::vector<picojson::value> recipients;
- auto addToRecipients = [&recipients](std::string& e)->void {
- recipients.push_back(picojson::value(e));
- };
-
- auto toVect = callback->getMessage()->getTO();
- std::for_each(toVect.begin(), toVect.end(), addToRecipients);
-
- auto ccVect = callback->getMessage()->getCC();
- std::for_each(ccVect.begin(), ccVect.end(), addToRecipients);
-
- auto bccVect = callback->getMessage()->getBCC();
- std::for_each(bccVect.begin(), bccVect.end(), addToRecipients);
-
- picojson::object data;
- data[JSON_DATA_RECIPIENTS] = picojson::value(recipients);
- data[JSON_DATA_MESSAGE] = MessagingUtil::messageToJson(callback->getMessage());
- obj[JSON_DATA] = picojson::value(data);
-
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
- callback->getMessage()->setMessageStatus(MessageStatus::STATUS_SENT);
- }
- } else {
- LoggerE("Callback id is missing");
+ if (callback->IsError()) {
+ LoggerD("Calling error callback");
+ callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
+ }
+ else {
+ LoggerD("Calling success callback");
+
+ std::vector<picojson::value> recipients;
+ auto addToRecipients = [&recipients](std::string& e)->void {
+ recipients.push_back(picojson::value(e));
+ };
+
+ auto toVect = callback->getMessage()->getTO();
+ std::for_each(toVect.begin(), toVect.end(), addToRecipients);
+
+ auto ccVect = callback->getMessage()->getCC();
+ std::for_each(ccVect.begin(), ccVect.end(), addToRecipients);
+
+ auto bccVect = callback->getMessage()->getBCC();
+ std::for_each(bccVect.begin(), bccVect.end(), addToRecipients);
+
+ picojson::object data;
+ data[JSON_DATA_RECIPIENTS] = picojson::value(recipients);
+ data[JSON_DATA_MESSAGE] = MessagingUtil::messageToJson(callback->getMessage());
+
+ callback->SetSuccess(picojson::value(data));
+ callback->getMessage()->setMessageStatus(MessageStatus::STATUS_SENT);
}
+ callback->Post();
+
delete callback;
callback = NULL;
if (!platform_result) {
LoggerE("Message send failed");
- callback->setError(platform_result);
+ callback->SetError(platform_result);
if (!g_idle_add(sendEmailCompleteCB, static_cast<void*>(callback))) {
LoggerE("g_idle addition failed");
case EMAIL_ERROR_NO_RESPONSE:
{
LoggerE("Network error %d", error_code);
- common::NetworkException e("Failed to send message");
- callback->setError(e.name(), e.message());
+ callback->SetError(PlatformResult(ErrorCode::NETWORK_ERR, "Failed to send message"));
break;
}
default:
LoggerE("Unknown error %d", error_code);
- common::UnknownException ex("Failed to send message");
- callback->setError(ex.name(),ex.message());
+ callback->SetError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to send message"));
break;
}
} else if (NOTI_SEND_FINISH == status) {
LoggerE("Email cancel job failed, %d", err);
}
- std::shared_ptr<picojson::value> response = callback->getJson();
- picojson::object& obj = response->get<picojson::object>();
-
- if (response->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- callback->setError(PlatformResult(ErrorCode::ABORT_ERR, "Sync aborted by user"));
+ callback->SetError(PlatformResult(ErrorCode::ABORT_ERR, "Sync aborted by user"));
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- response->serialize());
- m_proxy_sync->removeCallback(op_id);
- } else {
- LoggerE("Callback id is missing");
- }
+ callback->Post();
+ m_proxy_sync->removeCallback(op_id);
}
//################################## ^stopSync #################################
LoggerD("Entered");
for (auto it = m_sendRequests.begin(); it != m_sendRequests.end();) {
- if (&it->second->getQueue() == &q) {
+ if (it->second->HasQueue(q)) {
delete it->second;
m_sendRequests.erase(it++);
} else {
return;
}
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- if (callback->isError()) {
- LoggerD("Calling error callback");
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
- } else {
- LoggerD("Calling success callback");
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
- }
+ if (callback->IsError()) {
+ LoggerD("Calling error callback");
+
} else {
- LoggerE("Callback id is missing");
+ LoggerD("Calling success callback");
+
+ callback->SetSuccess();
}
+ callback->Post();
+
delete callback;
callback = NULL;
}
MessagesCallbackUserData* callback = it->callback;
if (NOTI_MAIL_DELETE_FAIL == status) {
LoggerD("Failed to remove mail");
- UnknownException e("Messages remove failed");
- callback->setError(e.name(), e.message());
+ callback->SetError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Messages remove failed"));
}
//if one of mails failed, call error callback
//if all mails are deleted, call success.
callback->SetError(ret);
}
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- if (callback->isError()) {
- LoggerD("Calling error callback");
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize());
- } else {
- LoggerD("Calling success callback");
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
- picojson::array array;
- auto messages = callback->getMessages();
- size_t messages_size = messages.size();
- for (size_t i = 0 ; i < messages_size; ++i) {
- array.push_back(MessagingUtil::messageToJson(messages[i]));
- }
- obj[JSON_DATA] = picojson::value(array);
+ if (callback->IsError()) {
+ LoggerD("Calling error callback");
+ } else {
+ LoggerD("Calling success callback");
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
+ picojson::array array;
+ auto messages = callback->getMessages();
+ size_t messages_size = messages.size();
+ for (size_t i = 0 ; i < messages_size; ++i) {
+ array.push_back(MessagingUtil::messageToJson(messages[i]));
}
- } else {
- LoggerE("Callback id is missing");
+
+ callback->SetSuccess(picojson::value(array));
}
+
+ callback->Post();
+
delete callback;
callback = NULL;
}
}
//Complete task
- LoggerD("callback: %p error: %d messages.size() = %d", callback, callback->isError(),
+ LoggerD("callback: %p error: %d messages.size() = %d", callback, callback->IsError(),
callback->getMessages().size());
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- if (callback->isError()) {
- LoggerD("Calling error callback");
- callback->getQueue().resolve( obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize());
- } else {
- LoggerD("Calling success callback");
- std::vector<picojson::value> response;
- auto messages = callback->getMessages();
- std::for_each(messages.begin(), messages.end(), [&response](MessagePtr &message){
- response.push_back(MessagingUtil::messageToJson(message));
- });
- obj[JSON_DATA] = picojson::value(response);
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+ if (callback->IsError()) {
+ LoggerD("Calling error callback");
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize());
- }
} else {
- LoggerE("Failed to call findMessages callback.");
+ LoggerD("Calling success callback");
+ std::vector<picojson::value> response;
+ auto messages = callback->getMessages();
+ std::for_each(messages.begin(), messages.end(), [&response](MessagePtr &message){
+ response.push_back(MessagingUtil::messageToJson(message));
+ });
+
+ callback->SetSuccess(picojson::value(response));
}
+ callback->Post();
+
delete callback;
callback = NULL;
}
}
//Complete task
- LoggerD("callback: %p error:%d conversations.size()=%d", callback, callback->isError(),
+ LoggerD("callback: %p error:%d conversations.size()=%d", callback, callback->IsError(),
callback->getConversations().size());
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- if (callback->isError()) {
- LoggerD("Calling error callback");
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize());
- } else {
- LoggerD("Calling success callback");
-
- std::vector<picojson::value> response;
- auto messages = callback->getConversations();
- std::for_each(messages.begin(), messages.end(),
- [&response](std::shared_ptr<MessageConversation> &conversation) {
- response.push_back(MessagingUtil::conversationToJson(conversation));
- }
- );
- obj[JSON_DATA] = picojson::value(response);
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+ if (callback->IsError()) {
+ LoggerD("Calling error callback");
+ } else {
+ LoggerD("Calling success callback");
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
+ std::vector<picojson::value> response;
+ auto messages = callback->getConversations();
+ std::for_each(messages.begin(), messages.end(),
+ [&response](std::shared_ptr<MessageConversation> &conversation) {
+ response.push_back(MessagingUtil::conversationToJson(conversation));
}
- } else {
- LoggerE("Failed to call findConversations callback.");
+ );
+
+ callback->SetSuccess(picojson::value(response));
}
+ callback->Post();
+
delete callback;
callback = NULL;
}
}
//Complete task
- LoggerD("callback: %p error:%d folders.size()=%d", callback, callback->isError(),
+ LoggerD("callback: %p error:%d folders.size()=%d", callback, callback->IsError(),
callback->getFolders().size());
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- if (callback->isError()) {
- LoggerD("Calling error callback");
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize());
- } else {
- LoggerD("Calling success callback");
-
- std::vector<picojson::value> response;
- auto folders = callback->getFolders();
- std::for_each(folders.begin(), folders.end(),
- [&response](std::shared_ptr<MessageFolder> &folder) {
- response.push_back(MessagingUtil::folderToJson(folder));
- }
- );
- obj[JSON_DATA] = picojson::value(response);
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+ if (callback->IsError()) {
+ LoggerD("Calling error callback");
+ } else {
+ LoggerD("Calling success callback");
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize());
+ std::vector<picojson::value> response;
+ auto folders = callback->getFolders();
+ std::for_each(folders.begin(), folders.end(),
+ [&response](std::shared_ptr<MessageFolder> &folder) {
+ response.push_back(MessagingUtil::folderToJson(folder));
}
- } else {
- LoggerE("Unknown error when calling findFolders callback.");
+ );
+
+ callback->SetSuccess(picojson::value(response));
}
+ callback->Post();
+
delete callback;
callback = NULL;
}
callback->SetError(ret);
}
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- if (callback->isError()) {
- LoggerD("Calling error callback");
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize());
- } else {
- LoggerD("Calling success callback");
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
- callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize());
- }
+ if (callback->IsError()) {
+ LoggerD("Calling error callback");
} else {
- LoggerE("Unknown error when calling removeConversations callback.");
+ LoggerD("Calling success callback");
+
+ callback->SetSuccess();
}
+ callback->Post();
+
delete callback;
callback = NULL;
}
#include "email-api-mail.h"
#include "email-api-mailbox.h"
-#include "common/callback_user_data.h"
+#include "messaging/callback_user_data.h"
#include "common/GDBus/connection.h"
#include "common/platform_exception.h"
#include "common/platform_result.h"
namespace extension {
namespace messaging {
-FindMsgCallbackUserData::FindMsgCallbackUserData(PostQueue& queue):
- CallbackUserData(),
- m_limit(0),
- m_offset(0),
- m_is_error(false),
- m_account_id(0),
- m_service_type(UNDEFINED),
- queue_(queue)
-{
- LoggerD("Entered");
+FindMsgCallbackUserData::FindMsgCallbackUserData(PostQueue& queue, long cid) :
+ CallbackUserData(queue, cid),
+ m_limit(0),
+ m_offset(0),
+ m_account_id(0),
+ m_service_type(UNDEFINED) {
+ LoggerD("Entered");
}
FindMsgCallbackUserData::~FindMsgCallbackUserData()
return m_messages;
}
-void FindMsgCallbackUserData::setError(const std::string& err_name,
- const std::string& err_message)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- m_is_error = true;
- m_err_name = err_name;
- m_err_message = err_message;
-
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-
- auto obj_error = picojson::object();
- obj_error[JSON_ERROR_NAME] = picojson::value(err_name);
- obj_error[JSON_ERROR_MESSAGE] = picojson::value(err_message);
- obj[JSON_DATA] = picojson::value(obj_error);
- }
-}
-
-void FindMsgCallbackUserData::SetError(const common::PlatformResult& error)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- m_is_error = true;
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
- auto obj_data = picojson::object();
- obj_data[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
- obj_data[JSON_ERROR_MESSAGE] = picojson::value(error.message());
- obj[JSON_DATA] = picojson::value(obj_data);
- }
-}
-
-bool FindMsgCallbackUserData::isError() const
-{
- return m_is_error;
-}
-
-std::string FindMsgCallbackUserData::getErrorName() const
-{
- return m_err_name;
-}
-
-std::string FindMsgCallbackUserData::getErrorMessage() const
-{
- return m_err_message;
-}
-
void FindMsgCallbackUserData::setAccountId(int account_id){
m_account_id = account_id;
}
#ifndef __TIZEN_FIND_MSG_CALLBACK_USER_DATA_H
#define __TIZEN_FIND_MSG_CALLBACK_USER_DATA_H
-#include "common/callback_user_data.h"
#include <memory>
#include <string>
#include <vector>
+
+#include "messaging/callback_user_data.h"
#include "MsgCommon/AttributeFilter.h"
#include "MsgCommon/SortMode.h"
#include "messaging_util.h"
class Message;
-class FindMsgCallbackUserData: public common::CallbackUserData {
+class FindMsgCallbackUserData : public CallbackUserData {
public:
- FindMsgCallbackUserData(PostQueue& queue);
+ FindMsgCallbackUserData(PostQueue& queue, long cid);
virtual ~FindMsgCallbackUserData();
void setFilter(AbstractFilterPtr filter);
void addMessage(std::shared_ptr<Message> msg);
std::vector<std::shared_ptr<Message>> getMessages() const;
- void setError(const std::string& err_name,
- const std::string& err_message);
- void SetError(const common::PlatformResult& error);
- bool isError() const;
- std::string getErrorName() const;
- std::string getErrorMessage() const;
-
void setAccountId(int account_id);
int getAccountId() const;
long getLimit() const;
long getOffset() const;
- PostQueue& getQueue() { return queue_;};
private:
AbstractFilterPtr m_filter;
SortModePtr m_sort;
long m_limit;
long m_offset;
- bool m_is_error;
- std::string m_err_name;
- std::string m_err_message;
std::vector<std::shared_ptr<Message>> m_messages;
int m_account_id;
MessageType m_service_type;
- PostQueue& queue_;
};
}//Messaging
namespace extension {
namespace messaging {
-
-FoldersCallbackData::FoldersCallbackData(PostQueue& queue):
- m_filter(),
- m_is_error(false),
- queue_(queue)
-{
- LoggerD("Entered");
-}
-
-FoldersCallbackData::FoldersCallbackData(long cid, PostQueue& queue, bool keep):
- m_filter(),
- m_is_error(false),
- queue_(queue)
-{
- LoggerD("Entered");
- auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
- picojson::object& o = json->get<picojson::object>();
- o[JSON_CALLBACK_ID] = picojson::value(static_cast<double>(cid));
- o[JSON_CALLBACK_KEEP] = picojson::value(keep);
- setJson(json);
-}
-
FoldersCallbackData::~FoldersCallbackData() {
LoggerD("Entered");
}
return m_filter;
}
-void FoldersCallbackData::setError(const std::string& err_name,
- const std::string& err_message)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- m_is_error = true;
- m_err_name = err_name;
- m_err_message = err_message;
-
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-
- auto obj_error = picojson::object();
- obj_error[JSON_ERROR_NAME] = picojson::value(err_name);
- obj_error[JSON_ERROR_MESSAGE] = picojson::value(err_message);
- obj[JSON_DATA] = picojson::value(obj_error);
- }
-}
-
-void FoldersCallbackData::SetError(const common::PlatformResult& error)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- m_is_error = true;
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
- auto obj_data = picojson::object();
- obj_data[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
- obj_data[JSON_ERROR_MESSAGE] = picojson::value(error.message());
- obj[JSON_DATA] = picojson::value(obj_data);
- }
-}
-
-bool FoldersCallbackData::isError() const
-{
- return m_is_error;
-}
-
-std::string FoldersCallbackData::getErrorName() const
-{
- return m_err_name;
-}
-
-std::string FoldersCallbackData::getErrorMessage() const
-{
- return m_err_message;
-}
-
}//messaging
}//extension
#ifndef __TIZEN_FOLDERS_CALLBACK_DATA_H__
#define __TIZEN_FOLDERS_CALLBACK_DATA_H__
-#include "common/callback_user_data.h"
#include "common/platform_result.h"
#include <memory>
#include <vector>
#include <string>
+#include "messaging/callback_user_data.h"
#include "MsgCommon/AbstractFilter.h"
#include "message_folder.h"
class MessageFolder;
-class FoldersCallbackData: public common::CallbackUserData {
+class FoldersCallbackData : public CallbackUserData {
public:
- FoldersCallbackData(PostQueue& queue);
- FoldersCallbackData(long cid, PostQueue& queue, bool keep = false);
+ using CallbackUserData::CallbackUserData;
virtual ~FoldersCallbackData();
void addFolder(std::shared_ptr<MessageFolder> folder);
void setFilter(tizen::AbstractFilterPtr filter);
tizen::AbstractFilterPtr getFilter() const;
- void setError(const std::string& err_name,
- const std::string& err_message);
- void SetError(const common::PlatformResult& error);
- bool isError() const;
- std::string getErrorName() const;
- std::string getErrorMessage() const;
-
- PostQueue& getQueue() { return queue_;};
private:
std::vector<std::shared_ptr<MessageFolder>> m_folders;
tizen::AbstractFilterPtr m_filter;
- bool m_is_error;
- std::string m_err_name;
- std::string m_err_message;
- PostQueue& queue_;
-
};
}//messaging
int service_id,
MessageType service_type,
PostQueue& queue):
- m_callback_data(cid, queue, true),
+ m_callback_data(queue, cid, true),
m_id(service_id),
m_msg_type(service_type),
m_is_act(true)
LoggerD("Calling:%s with:%d added folders", FOLDERSADDED,
filtered.size());
- auto json = m_callback_data.getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(FOLDERSADDED);
- obj[JSON_DATA] = picojson::value(array);
-
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- m_callback_data.getQueue().addAndResolve(obj.at(
- JSON_CALLBACK_ID).get<double>(), PostPriority::MEDIUM, json->serialize());
- } else {
- LoggerE("Callback id is missing");
- }
+ m_callback_data.SetAction(FOLDERSADDED, picojson::value(array));
+ m_callback_data.AddAndPost(PostPriority::MEDIUM);
}
void FoldersChangeCallback::updated(const FolderPtrVector& folders)
LoggerD("Calling:%s with:%d updated folders", FOLDERSUPDATED,
filtered.size());
- auto json = m_callback_data.getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(FOLDERSUPDATED);
- obj[JSON_DATA] = picojson::value(array);
-
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- m_callback_data.getQueue().addAndResolve(obj.at(
- JSON_CALLBACK_ID).get<double>(), PostPriority::LOW, json->serialize());
- } else {
- LoggerE("Callback id is missing");
- }
+ m_callback_data.SetAction(FOLDERSUPDATED, picojson::value(array));
+ m_callback_data.AddAndPost(PostPriority::LOW);
}
void FoldersChangeCallback::removed(const FolderPtrVector& folders)
LoggerD("Calling:%s with:%d removed folders", FOLDERSREMOVED,
filtered.size());
- auto json = m_callback_data.getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(FOLDERSREMOVED);
- obj[JSON_DATA] = picojson::value(array);
-
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- m_callback_data.getQueue().addAndResolve(obj.at(
- JSON_CALLBACK_ID).get<double>(), PostPriority::LAST, json->serialize());
- } else {
- LoggerE("Callback id is missing");
- }
+ m_callback_data.SetAction(FOLDERSREMOVED, picojson::value(array));
+ m_callback_data.AddAndPost(PostPriority::LAST);
}
void FoldersChangeCallback::setFilter(tizen::AbstractFilterPtr filter)
namespace extension {
namespace messaging {
-MessageCallbackUserData::MessageCallbackUserData(PostQueue& queue):
- common::CallbackUserData(),
- m_is_error(false),
- queue_(queue),
- m_account_id(-1)
-{
- LoggerD("Entered");
+MessageCallbackUserData::MessageCallbackUserData(PostQueue& queue, long cid) :
+ CallbackUserData(queue, cid),
+ m_account_id(0) {
+ LoggerD("Entered");
}
MessageCallbackUserData::~MessageCallbackUserData() {
return m_account_id;
}
-void MessageCallbackUserData::setError(const std::string& err_name,
- const std::string& err_message)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
- auto objData = picojson::object();
-
- objData[JSON_ERROR_NAME] = picojson::value(err_name);
- objData[JSON_ERROR_MESSAGE] = picojson::value(err_message);
-
- obj[JSON_DATA] = picojson::value(objData);
-
- m_is_error = true;
- m_err_name = err_name;
- m_err_message = err_message;
- }
-}
-
-void MessageCallbackUserData::setError(const common::PlatformResult& error)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- m_is_error = true;
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
- auto obj_data = picojson::object();
-
- obj_data[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
- obj_data[JSON_ERROR_MESSAGE] = picojson::value(error.message());
-
- obj[JSON_DATA] = picojson::value(obj_data);
- }
-}
-
-bool MessageCallbackUserData::isError() const
-{
- return m_is_error;
-}
-
-std::string MessageCallbackUserData::getErrorName() const
-{
- return m_err_name;
-}
-
-std::string MessageCallbackUserData::getErrorMessage() const
-{
- return m_err_message;
-}
-
}//messaging
}//extension
#ifndef MESSAGING_MESSAGE_CALLBACK_USER_DATA_H_
#define MESSAGING_MESSAGE_CALLBACK_USER_DATA_H_
-#include "common/callback_user_data.h"
#include "common/platform_result.h"
#include <memory>
#include <string>
+#include "messaging/callback_user_data.h"
namespace extension {
namespace messaging {
class Message;
class PostQueue;
-class MessageCallbackUserData: public common::CallbackUserData {
+class MessageCallbackUserData : public CallbackUserData {
public:
- MessageCallbackUserData(PostQueue& queue);
+ MessageCallbackUserData(PostQueue& queue, long cid);
virtual ~MessageCallbackUserData();
void setMessage(std::shared_ptr<Message> message);
void setAccountId(int account_id);
int getAccountId() const;
- void setError(const std::string& err_name,
- const std::string& err_message);
- void setError(const common::PlatformResult& error);
- bool isError() const;
- std::string getErrorName() const;
- std::string getErrorMessage() const;
-
- PostQueue& getQueue() { return queue_;};
-
private:
- bool m_is_error;
- PostQueue& queue_;
- std::string m_err_name;
- std::string m_err_message;
std::shared_ptr<Message> m_message;
int m_account_id;
-
};
}//messaging
//#################### MessageRecipientsCallbackData ####################
-MessageRecipientsCallbackData::MessageRecipientsCallbackData(PostQueue& queue):
- m_is_error(false),
- m_account_id(-1),
- m_sim_index(TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN),
- m_default_sim_index(TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN),
- queue_(queue)
-{
- LoggerD("Entered");
- m_msg_recipients = std::vector<std::string>();
+MessageRecipientsCallbackData::MessageRecipientsCallbackData(PostQueue& queue, long cid) :
+ CallbackUserData(queue, cid),
+ m_account_id(-1),
+ m_sim_index(TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN),
+ m_default_sim_index(TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN) {
+ LoggerD("Entered");
}
MessageRecipientsCallbackData::~MessageRecipientsCallbackData()
return m_msg_recipients;
}
-void MessageRecipientsCallbackData::setError(const std::string& err_name,
- const std::string& err_message)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- m_is_error = true;
-
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
- auto obj_error = picojson::object();
-
- obj_error[JSON_ERROR_NAME] = picojson::value(err_name);
- obj_error[JSON_ERROR_MESSAGE] = picojson::value(err_message);
-
- obj[JSON_DATA] = picojson::value(obj_error);
- }
-}
-
-void MessageRecipientsCallbackData::setError(const PlatformResult& error)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- m_is_error = true;
-
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
- auto obj_error = picojson::object();
-
- obj_error[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
- obj_error[JSON_ERROR_MESSAGE] = picojson::value(error.message());
-
- obj[JSON_DATA] = picojson::value(obj_error);
- }
-}
-
-bool MessageRecipientsCallbackData::isError() const
-{
- return m_is_error;
-}
-
void MessageRecipientsCallbackData::setAccountId(int account_id){
m_account_id = account_id;
}
sim_index--;
if (sim_index >= sim_count || sim_index < -1) {
LoggerE("Sim index out of bound %d : %d", sim_index, sim_count);
- common::InvalidValuesException err("The index of sim is out of bound");
- this->setError(err.name(), err.message());
+ this->SetError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "The index of sim is out of bound"));
return false;
}
//#################### BaseMessageServiceCallbackData ####################
-BaseMessageServiceCallbackData::BaseMessageServiceCallbackData():
-// CallbackUserData(globalCtx),
- m_is_error(false),
- m_op_handle(-1),
- m_callback_id(-1)
-{
- LoggerD("Entered");
+BaseMessageServiceCallbackData::BaseMessageServiceCallbackData(PostQueue& queue, long cid) :
+ CallbackUserData(queue, cid),
+ m_op_handle(-1) {
+ LoggerD("Entered");
}
BaseMessageServiceCallbackData::~BaseMessageServiceCallbackData()
LoggerD("Entered");
}
-void BaseMessageServiceCallbackData::setError(const std::string& err_name,
- const std::string& err_message)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- m_is_error = true;
-
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-
- auto obj_error = picojson::object();
- obj_error[JSON_ERROR_NAME] = picojson::value(err_name);
- obj_error[JSON_ERROR_MESSAGE] = picojson::value(err_message);
- obj[JSON_DATA] = picojson::value(obj_error);
- }
-}
-
-void BaseMessageServiceCallbackData::setError(const PlatformResult& error)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- m_is_error = true;
-
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
- auto obj_error = picojson::object();
-
- obj_error[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
- obj_error[JSON_ERROR_MESSAGE] = picojson::value(error.message());
-
- obj[JSON_DATA] = picojson::value(obj_error);
- }
-}
-
-bool BaseMessageServiceCallbackData::isError() const
-{
- return m_is_error;
-}
-
void BaseMessageServiceCallbackData::setOperationHandle(const int op_handle)
{
m_op_handle = op_handle;
return m_op_handle;
}
-void BaseMessageServiceCallbackData::setCallbackId(const double callback_id)
-{
- m_callback_id = callback_id;
-}
-
-double BaseMessageServiceCallbackData::getCallbackId() const
-{
- return m_callback_id;
-}
-
//#################### MessageBodyCallbackData ####################
-MessageBodyCallbackData::MessageBodyCallbackData(PostQueue& queue):
- queue_(queue)
-{
- LoggerD("Entered");
-}
-
MessageBodyCallbackData::~MessageBodyCallbackData()
{
LoggerD("Entered");
//#################### MessageAttachmentCallbackData ####################
-MessageAttachmentCallbackData::MessageAttachmentCallbackData(PostQueue& queue):
- m_nth(0),
- queue_(queue)
-{
- LoggerD("Entered");
+MessageAttachmentCallbackData::MessageAttachmentCallbackData(PostQueue& queue, long cid) :
+ BaseMessageServiceCallbackData(queue, cid),
+ m_nth(0) {
+ LoggerD("Entered");
}
MessageAttachmentCallbackData::~MessageAttachmentCallbackData()
//#################### SyncCallbackData ####################
-SyncCallbackData::SyncCallbackData(PostQueue& queue):
-// BaseMessageServiceCallbackData(globalCtx),
- m_is_limit(false),
- m_limit(0),
- m_op_id(-1),
- m_account_id(-1),
- queue_(queue)
-{
- LoggerD("Entered");
+
+SyncCallbackData::SyncCallbackData(PostQueue& queue, long cid) :
+ BaseMessageServiceCallbackData(queue, cid),
+ m_is_limit(false),
+ m_limit(0),
+ m_op_id(-1),
+ m_account_id(-1) {
+ LoggerD("Entered");
}
SyncCallbackData::~SyncCallbackData()
//#################### SyncFolderCallbackData ####################
-SyncFolderCallbackData::SyncFolderCallbackData(PostQueue& queue):
- SyncCallbackData(queue)
-{
- LoggerD("Entered");
-}
-
SyncFolderCallbackData::~SyncFolderCallbackData()
{
LoggerD("Entered");
#include <memory>
#include <string>
+#include "messaging/callback_user_data.h"
#include "common/picojson.h"
-#include "common/callback_user_data.h"
#include "common/platform_result.h"
#include "messaging_util.h"
MMS_ACCOUNT_ID = 102
};
-class MessageRecipientsCallbackData : public common::CallbackUserData {
+class MessageRecipientsCallbackData : public CallbackUserData {
public:
- MessageRecipientsCallbackData(PostQueue& queue);
+ MessageRecipientsCallbackData(PostQueue& queue, long cid);
virtual ~MessageRecipientsCallbackData();
void setMessage(std::shared_ptr<Message> message);
void setMessageRecipients(const std::vector<std::string>& msgRecipients);
const std::vector<std::string>& getMessageRecipients() const;
- void setError(const std::string& err_name,
- const std::string& err_message);
- void setError(const common::PlatformResult& error);
- bool isError() const;
-
void setAccountId(int account_id);
int getAccountId() const;
TelNetworkDefaultDataSubs_t getDefaultSimIndex() const;
bool isSetSimIndex() const;
- PostQueue& getQueue() { return queue_;};
-
private:
std::shared_ptr<Message> m_message;
- bool m_is_error;
std::vector<std::string> m_msg_recipients;
int m_account_id;
TelNetworkDefaultDataSubs_t m_sim_index;
TelNetworkDefaultDataSubs_t m_default_sim_index;
- PostQueue& queue_;
};
-class BaseMessageServiceCallbackData : public common::CallbackUserData {
+class BaseMessageServiceCallbackData : public CallbackUserData {
public:
- BaseMessageServiceCallbackData();
+ BaseMessageServiceCallbackData(PostQueue& queue, long cid);
virtual ~BaseMessageServiceCallbackData();
- void setError(const std::string& err_name,
- const std::string& err_message);
- void setError(const common::PlatformResult& error);
- bool isError() const;
-
/**
* This handle is returned from various native API functions:
* int email_sync_header(..., int *handle);
*/
void setOperationHandle(const int op_handle);
int getOperationHandle() const;
- void setCallbackId(const double callback_id);
- double getCallbackId() const;
protected:
- bool m_is_error;
-
int m_op_handle;
- double m_callback_id;
};
class MessageBodyCallbackData : public BaseMessageServiceCallbackData {
public:
- MessageBodyCallbackData(PostQueue& queue);
+ using BaseMessageServiceCallbackData::BaseMessageServiceCallbackData;
virtual ~MessageBodyCallbackData();
void setMessage(std::shared_ptr<Message> message);
std::shared_ptr<Message> getMessage() const;
- PostQueue& getQueue() { return queue_;};
private:
std::shared_ptr<Message> m_message;
- PostQueue& queue_;
};
class MessageAttachmentCallbackData : public BaseMessageServiceCallbackData {
public:
- MessageAttachmentCallbackData(PostQueue& queue);
+ MessageAttachmentCallbackData(PostQueue& queue, long cid);
virtual ~MessageAttachmentCallbackData();
void setMessageAttachment(std::shared_ptr<MessageAttachment> messageAttachment);
void setNth(const int nth);
int getNth() const;
- PostQueue& getQueue() { return queue_;};
private:
std::shared_ptr<MessageAttachment> m_message_attachment;
int m_nth;
- PostQueue& queue_;
};
class SyncCallbackData : public BaseMessageServiceCallbackData {
public:
- SyncCallbackData(PostQueue& queue);
+ SyncCallbackData(PostQueue& queue, long cid);
virtual ~SyncCallbackData();
void setLimit(const unsigned long limit);
void setAccountId(int account_id);
int getAccountId() const;
- PostQueue& getQueue() { return queue_;};
protected:
bool m_is_limit;
unsigned long m_limit;
long m_op_id;
int m_account_id;
- PostQueue& queue_;
};
class SyncFolderCallbackData : public SyncCallbackData {
public:
- SyncFolderCallbackData(PostQueue& queue);
+ using SyncCallbackData::SyncCallbackData;
virtual ~SyncFolderCallbackData();
void setMessageFolder(std::shared_ptr<MessageFolder> message_folder);
// if the attachment is already saved, then it doesn't need to load again.
if (att->isFilePathSet() && att->isSaved()) {
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- picojson::object args;
- args[JSON_DATA_MESSAGE_ATTACHMENT] = MessagingUtil::messageAttachmentToJson(att);
- obj[JSON_DATA] = picojson::value(args);
-
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
- } else {
- LoggerE("json is incorrect - missing required member");
- }
+ picojson::object args;
+ args[JSON_DATA_MESSAGE_ATTACHMENT] = MessagingUtil::messageAttachmentToJson(att);
+
+ callback->SetSuccess(picojson::value(args));
+ callback->Post();
+
delete callback;
callback = nullptr;
} else {
}
std::shared_ptr<MessageBody> body = callback->getMessage()->getBody();
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- picojson::object args;
- args[JSON_DATA_MESSAGE_BODY] = MessagingUtil::messageBodyToJson(body);
- obj[JSON_DATA] = picojson::value(args);
-
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
- } else {
- LoggerE("json is incorrect - missing required member");
- }
+ picojson::object args;
+ args[JSON_DATA_MESSAGE_BODY] = MessagingUtil::messageBodyToJson(body);
+
+ callback->SetSuccess(picojson::value(args));
+ callback->Post();
+
return FALSE;
}
FoldersCallbackData *callback = static_cast<FoldersCallbackData*>(data);
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
+ picojson::array array;
+ auto each = [&array](std::shared_ptr<MessageFolder> folder)->void {
+ array.push_back(MessagingUtil::folderToJson(folder));
+ };
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- picojson::array array;
- auto each = [&array](std::shared_ptr<MessageFolder> folder)->void {
- array.push_back(MessagingUtil::folderToJson(folder));
- };
+ auto folders = callback->getFolders();
+ for_each(folders.begin(), folders.end(), each);
- auto folders = callback->getFolders();
- for_each(folders.begin(), folders.end(), each);
+ callback->SetSuccess(picojson::value(array));
+ callback->Post();
- obj[JSON_DATA] = picojson::value(array);
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
-
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
- } else {
- LoggerE("json is incorrect - missing required member");
- }
delete callback;
callback = NULL;
namespace extension {
namespace messaging {
-MessagesCallbackUserData::MessagesCallbackUserData(PostQueue& queue):
- common::CallbackUserData(),
- m_is_error(false),
- m_service_type(MessageType::UNDEFINED),
- queue_(queue)
-{
- LoggerD("Entered");
-}
-
-MessagesCallbackUserData::MessagesCallbackUserData(long cid, PostQueue& queue, bool keep):
- common::CallbackUserData(),
- m_is_error(false),
- m_service_type(MessageType::UNDEFINED),
- queue_(queue)
-{
- LoggerD("Entered");
- auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
- picojson::object& o = json->get<picojson::object>();
- o[JSON_CALLBACK_ID] = picojson::value(static_cast<double>(cid));
- o[JSON_CALLBACK_KEEP] = picojson::value(keep);
- setJson(json);
+MessagesCallbackUserData::MessagesCallbackUserData(PostQueue& queue, long cid, bool keep /* = false*/) :
+ CallbackUserData(queue, cid, keep),
+ m_service_type(UNDEFINED) {
+ LoggerD("Entered");
}
MessagesCallbackUserData::~MessagesCallbackUserData() {
return m_messages;
}
-void MessagesCallbackUserData::setError(const std::string& err_name,
- const std::string& err_message)
-{
- LoggerD("Entered");
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
- auto objData = picojson::object();
-
- objData[JSON_ERROR_NAME] = picojson::value(err_name);
- objData[JSON_ERROR_MESSAGE] = picojson::value(err_message);
-
- obj[JSON_DATA] = picojson::value(objData);
-
- m_is_error = true;
- m_err_name = err_name;
- m_err_message = err_message;
- }
-}
-
-void MessagesCallbackUserData::SetError(const common::PlatformResult& error)
-{
- // keep only first error in chain
- if (!m_is_error) {
- LoggerD("Error has not been set yet");
- m_is_error = true;
- picojson::object& obj = m_json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
- auto obj_data = picojson::object();
- obj_data[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
- obj_data[JSON_ERROR_MESSAGE] = picojson::value(error.message());
- obj[JSON_DATA] = picojson::value(obj_data);
- }
-}
-
-bool MessagesCallbackUserData::isError() const
-{
- return m_is_error;
-}
-
-std::string MessagesCallbackUserData::getErrorName() const
-{
- return m_err_name;
-}
-
-std::string MessagesCallbackUserData::getErrorMessage() const
-{
- return m_err_message;
-}
-
void MessagesCallbackUserData::setMessageServiceType(MessageType m_msg_type)
{
m_service_type = m_msg_type;
#ifndef MESSAGING_MESSAGES_CALLBACK_USER_DATA_H_
#define MESSAGING_MESSAGES_CALLBACK_USER_DATA_H_
-#include "common/callback_user_data.h"
#include "common/platform_result.h"
#include <memory>
#include <string>
+#include "messaging/callback_user_data.h"
#include "messaging_util.h"
namespace extension {
class Message;
-class MessagesCallbackUserData: public common::CallbackUserData {
+class MessagesCallbackUserData : public CallbackUserData {
public:
- MessagesCallbackUserData(PostQueue& queue);
- MessagesCallbackUserData(long cid, PostQueue& queue, bool keep = false);
+ MessagesCallbackUserData(PostQueue& queue, long cid, bool keep = false);
virtual ~MessagesCallbackUserData();
void addMessage(std::shared_ptr<Message> msg);
std::vector<std::shared_ptr<Message>> getMessages() const;
- void setError(const std::string& err_name,
- const std::string& err_message);
- void SetError(const common::PlatformResult& error);
- bool isError() const;
- std::string getErrorName() const;
- std::string getErrorMessage() const;
-
void setMessageServiceType(MessageType m_msg_type);
MessageType getMessageServiceType() const;
- PostQueue& getQueue() { return queue_;};
-
private:
std::vector<std::shared_ptr<Message>> m_messages;
- bool m_is_error;
- std::string m_err_name;
- std::string m_err_message;
MessageType m_service_type;
- PostQueue& queue_;
};
}//messaging
int service_id,
MessageType service_type,
PostQueue& queue) :
- m_callback_data(cid, queue, true),
+ m_callback_data(queue, cid, true),
m_service_id(service_id),
m_msg_type(service_type),
m_is_act(true)
LoggerD("Calling:%s with:%d added messages", MESSAGESADDED,
filtered_msgs.size());
- auto json = m_callback_data.getJson();
- picojson::object& obj = json->get<picojson::object>();
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- obj[JSON_ACTION] = picojson::value(MESSAGESADDED);
- obj[JSON_DATA] = picojson::value(array);
-
- m_callback_data.getQueue().addAndResolve(obj.at(
- JSON_CALLBACK_ID).get<double>(), PostPriority::MEDIUM, json->serialize());
- } else {
- LoggerE("json is incorrect - missing required member");
- }
+ m_callback_data.SetAction(MESSAGESADDED, picojson::value(array));
+ m_callback_data.AddAndPost(PostPriority::MEDIUM);
}
void MessagesChangeCallback::updated(const MessagePtrVector& msgs)
LoggerD("Calling:%s with:%d updated messages", MESSAGESUPDATED,
filtered_msgs.size());
- auto json = m_callback_data.getJson();
- picojson::object& obj = json->get<picojson::object>();
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- obj[JSON_ACTION] = picojson::value(MESSAGESUPDATED);
- obj[JSON_DATA] = picojson::value(array);
-
- m_callback_data.getQueue().addAndResolve(obj.at(
- JSON_CALLBACK_ID).get<double>(), PostPriority::LOW, json->serialize());
- } else {
- LoggerE("json is incorrect - missing required member");
- }
+ m_callback_data.SetAction(MESSAGESUPDATED, picojson::value(array));
+ m_callback_data.AddAndPost(PostPriority::LOW);
}
void MessagesChangeCallback::removed(const MessagePtrVector& msgs)
LoggerD("Calling:%s with:%d removed messages", MESSAGESREMOVED,
filtered_msgs.size());
- auto json = m_callback_data.getJson();
- picojson::object& obj = json->get<picojson::object>();
- if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
- obj[JSON_ACTION] = picojson::value(MESSAGESREMOVED);
- LoggerD("MESSAGES: %s", picojson::value(array).serialize().c_str());
- obj[JSON_DATA] = picojson::value(array);
-
- m_callback_data.getQueue().addAndResolve(obj.at(
- JSON_CALLBACK_ID).get<double>(), PostPriority::LAST, json->serialize());
- } else {
- LoggerE("json is incorrect - missing required member");
- }
+ m_callback_data.SetAction(MESSAGESREMOVED, picojson::value(array));
+ m_callback_data.AddAndPost(PostPriority::LAST);
}
void MessagesChangeCallback::setFilter(tizen::AbstractFilterPtr filter)
},
'sources': [
'messaging_api.js',
+ 'callback_user_data.cc',
+ 'callback_user_data.h',
'email_manager.cc',
'email_manager.h',
'messaging_instance.cc',
POST_AND_RETURN(ret, json, obj, JSON_CALLBACK_ERROR)
}
- MessageRecipientsCallbackData* callback = new MessageRecipientsCallbackData(queue_);
+ MessageRecipientsCallbackData* callback = new MessageRecipientsCallbackData(queue_, callbackId);
long simIndex = 0;
int serviceId = 0;
- callback->setJson(json);
callback->setMessage(message);
serviceId = getServiceIdFromJSON(data);
callback->setAccountId(serviceId);
json, obj, JSON_CALLBACK_ERROR)
}
- queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+ callback->AddToQueue();
auto service = manager_.getMessageService(serviceId);
ret = service->sendMessage(callback);
POST_AND_RETURN(ret, json, obj, JSON_CALLBACK_ERROR)
}
- MessageBodyCallbackData* callback = new MessageBodyCallbackData(queue_);
+ MessageBodyCallbackData* callback = new MessageBodyCallbackData(queue_, callbackId);
- callback->setJson(json);
callback->setMessage(message);
- queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+ callback->AddToQueue();
auto service = manager_.getMessageService(getServiceIdFromJSON(data));
ret = service->loadMessageBody(callback);
if (ret.IsError()) {
picojson::value attachment = data.at(LOAD_MESSAGE_ATTACHMENT_ARGS_ATTACHMENT);
const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
- MessageAttachmentCallbackData* callback = new MessageAttachmentCallbackData(queue_);
+ MessageAttachmentCallbackData* callback = new MessageAttachmentCallbackData(queue_, callbackId);
callback->setMessageAttachment(MessagingUtil::jsonToMessageAttachment(attachment));
- auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
- callback->setJson(json);
-
- queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+ callback->AddToQueue();
auto service = manager_.getMessageService(getServiceIdFromJSON(data));
const auto result = service->loadMessageAttachment(callback);
if (result.IsError()) {
+ auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
+ picojson::object& obj = json->get<picojson::object>();
+ obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
POST_AND_RETURN(result, json, obj, JSON_CALLBACK_ERROR)
}
}
limit = static_cast<long>(v_limit.get<double>());
}
- auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
-
- SyncCallbackData *callback = new SyncCallbackData(queue_);
- callback->setJson(json);
+ SyncCallbackData *callback = new SyncCallbackData(queue_, callbackId);
callback->setAccountId(id);
callback->setLimit(limit);
- queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+ callback->AddToQueue();
long op_id = -1;
const auto result = manager_.getMessageService(id)->sync(callback, &op_id);
limit = static_cast<long>(v_limit.get<double>());
}
- auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
-
- SyncFolderCallbackData *callback = new SyncFolderCallbackData(queue_);
- callback->setJson(json);
+ SyncFolderCallbackData *callback = new SyncFolderCallbackData(queue_, callbackId);
callback->setAccountId(id);
callback->setMessageFolder(MessagingUtil::jsonToMessageFolder(v_folder));
callback->setLimit(limit);
- queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+ callback->AddToQueue();
long op_id = -1;
const auto result = manager_.getMessageService(id)->syncFolder(callback, &op_id);
POST_AND_RETURN(ret, json, obj, JSON_CALLBACK_ERROR)
}
- MessageCallbackUserData* callback = new MessageCallbackUserData(queue_);
+ MessageCallbackUserData* callback = new MessageCallbackUserData(queue_, callbackId);
callback->setMessage(message);
int serviceId = getServiceIdFromJSON(data);
callback->setAccountId(serviceId);
- callback->setJson(json);
-
- queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+ callback->AddToQueue();
auto service = manager_.getMessageService(serviceId);
service->getMsgStorage()->addDraftMessage(callback);
}
int serviceId = getServiceIdFromJSON(data);
auto storage = manager_.getMessageService(serviceId)->getMsgStorage();
- FindMsgCallbackUserData* callback = new FindMsgCallbackUserData(queue_);
+ FindMsgCallbackUserData* callback = new FindMsgCallbackUserData(queue_, callbackId);
callback->setFilter(filter);
callback->setLimit(limit);
callback->setOffset(offset);
callback->setAccountId(serviceId);
callback->setSortMode(sortMode);
- callback->setJson(json);
- queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+ callback->AddToQueue();
storage->findMessages(callback);
}
picojson::array messages = data.at(REMOVE_MESSAGES_ARGS_MESSAGES).get<picojson::array>();
const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
- MessagesCallbackUserData* callback = new MessagesCallbackUserData(queue_);
+ MessagesCallbackUserData* callback = new MessagesCallbackUserData(queue_, callbackId);
auto each = [callback] (picojson::value& v)->void {
std::shared_ptr<Message> message;
for_each(messages.begin(), messages.end(), each);
- auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
- callback->setJson(json);
-
auto service = manager_.getMessageService(getServiceIdFromJSON(data));
- queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+ callback->AddToQueue();
service->getMsgStorage()->removeMessages(callback);
}
auto pico_array = pico_messages.get<picojson::array>();
const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
- auto callback = new MessagesCallbackUserData(queue_);
+ auto callback = new MessagesCallbackUserData(queue_, callbackId);
std::for_each(pico_array.begin(), pico_array.end(), [&callback](picojson::value& v)->void {
std::shared_ptr<Message> message;
}
});
- auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
- callback->setJson(json);
-
auto service = manager_.getMessageService(getServiceIdFromJSON(data));
- queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+ callback->AddToQueue();
service->getMsgStorage()->updateMessages(callback);
}
int serviceId = getServiceIdFromJSON(data);
- ConversationCallbackData* callback = new ConversationCallbackData(queue_);
+ ConversationCallbackData* callback = new ConversationCallbackData(queue_, callbackId);
callback->setFilter(filter);
callback->setLimit(limit);
callback->setOffset(offset);
callback->setAccountId(serviceId);
callback->setSortMode(sortMode);
- callback->setJson(json);
- queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+ callback->AddToQueue();
auto storage = manager_.getMessageService(serviceId)->getMsgStorage();
storage->findConversations(callback);
}
picojson::object& obj = json->get<picojson::object>();
obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
- ConversationCallbackData* callback = new ConversationCallbackData(queue_);
+ ConversationCallbackData* callback = new ConversationCallbackData(queue_, callbackId);
PlatformResult ret(ErrorCode::NO_ERROR);
for (auto it = conversations.begin(); it != conversations.end(); ++it) {
callback->addConversation(conversation);
}
- callback->setJson(json);
-
auto service = manager_.getMessageService(getServiceIdFromJSON(data));
- queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+ callback->AddToQueue();
service->getMsgStorage()->removeConversations(callback);
}
POST_AND_RETURN(ret, json, obj, JSON_CALLBACK_ERROR)
}
- FoldersCallbackData* callback = new FoldersCallbackData(queue_);
+ FoldersCallbackData* callback = new FoldersCallbackData(queue_, callbackId);
callback->setFilter(filter);
- callback->setJson(json);
- queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+ callback->AddToQueue();
auto service = manager_.getMessageService(getServiceIdFromJSON(data));
service->getMsgStorage()->findFolders(callback);
}
return false;
}
- if (callback->isError()) {
- callback->getQueue().resolve(
- callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
- callback->getJson()->serialize()
- );
+ if (callback->IsError()) {
callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
}
else {
LoggerD("Calling success callback with: %d recipients", message->getTO().size());
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
std::vector<picojson::value> recipients;
auto addToRecipients = [&recipients](std::string& e)->void {
recipients.push_back(picojson::value(e));
picojson::object data;
data[JSON_DATA_RECIPIENTS] = picojson::value(recipients);
data[JSON_DATA_MESSAGE] = MessagingUtil::messageToJson(message);
- obj[JSON_DATA] = picojson::value(data);
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
+ callback->SetSuccess(picojson::value(data));
callback->getMessage()->setMessageStatus(MessageStatus::STATUS_SENT);
}
+ callback->Post();
+
delete callback;
callback = NULL;
return FALSE;
}
- if (callback->isError()) {
+ if (callback->IsError()) {
LoggerD("Calling error callback");
- callback->getQueue().resolve(
- callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
- callback->getJson()->serialize()
- );
callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
} else {
LoggerD("Calling success callback");
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
picojson::object args;
args[JSON_DATA_MESSAGE] = MessagingUtil::messageToJson(callback->getMessage());
- obj[JSON_DATA] = picojson::value(args);
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
+ callback->SetSuccess(picojson::value(args));
}
+ callback->Post();
+
delete callback;
callback = NULL;
if (!platform_result) {
LoggerE("Message send failed");
- callback->setError(platform_result);
+ callback->SetError(platform_result);
if (!g_idle_add(sendMessageCompleteCB, static_cast<void*>(callback))) {
LoggerE("g_idle addition failed");
callback->getMessage()->getId(),
(MSG_NETWORK_SEND_FAIL == status ? "FAIL" : "TIMEOUT"));
- common::UnknownException e("Send message failed");
- callback->setError(e.name(), e.message());
+ callback->SetError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Send message failed"));
}
if (!g_idle_add(sendMessageCompleteCB, static_cast<void*>(callback))) {
PlatformResult ret = addDraftMessagePlatform(message);
if (ret.IsError()) {
LoggerE("%d (%s)", ret.error_code(), ret.message().c_str());
- callback->setError(ret);
+ callback->SetError(ret);
}
}
}
}
- if (!callback->isError()) {
+ if (!callback->IsError()) {
for (auto it = messages.begin() ; it != messages.end(); ++it) {
const int id = (*it)->getId();
}
}
- if (callback->isError()) {
+ if (callback->IsError()) {
LoggerD("Calling error callback");
- callback->getQueue().resolve(
- callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
- callback->getJson()->serialize()
- );
} else {
LoggerD("Calling success callback");
-
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
+ callback->SetSuccess();
}
+ callback->Post();
+
delete callback;
callback = NULL;
}
break;
}
}
- if (!callback->isError()) {
+ if (!callback->IsError()) {
for (auto it = messages.begin() ; it != messages.end(); ++it) {
LoggerD("updating Message(%p) msg_id:%d", (*it).get(), (*it)->getId());
}
}
- if (callback->isError()) {
+ if (callback->IsError()) {
LoggerD("Calling error callback");
-
- callback->getQueue().resolve(
- callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
- callback->getJson()->serialize()
- );
} else {
LoggerD("Calling success callback");
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
-
auto messages = callback->getMessages();
picojson::array array;
auto each = [&array] (std::shared_ptr<Message> m)->void {
for_each(messages.begin(), messages.end(), each);
- obj[JSON_DATA] = picojson::value(array);
-
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
+ callback->SetSuccess(picojson::value(array));
}
+ callback->Post();
+
delete callback;
callback = NULL;
}
callback->SetError(ret);
}
- if (!callback->isError()) {
+ if (!callback->IsError()) {
int msgListCount = messagesIds.size();
LoggerD("Found %d messages", msgListCount);
callback->SetError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get platform Message structure"));
break;
}
- if (!callback->isError()) {
+ if (!callback->IsError()) {
callback->addMessage(std::shared_ptr<Message>{message});
LoggerD("Created message with id %d:", messagesIds[i]);
}
}
}
- if (callback->isError()) {
+ if (callback->IsError()) {
LoggerD("Calling error callback");
- callback->getQueue().resolve(
- callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
- callback->getJson()->serialize()
- );
} else {
LoggerD("Calling success callback with %d messages:",
callback->getMessages().size());
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
-
std::vector<picojson::value> response;
auto messages = callback->getMessages();
std::for_each(messages.begin(), messages.end(), [&response](MessagePtr &message){
response.push_back(MessagingUtil::messageToJson(message));
});
- obj[JSON_DATA] = picojson::value(response);
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
+ callback->SetSuccess(picojson::value(response));
}
+ callback->Post();
+
delete callback;
callback = NULL;
}
callback->SetError(ret);
}
- if (!callback->isError()) {
+ if (!callback->IsError()) {
int convListCount = conversationsIds.size();
LoggerD("Found %d conversations", convListCount);
}
}
- if (callback->isError()) {
+ if (callback->IsError()) {
LoggerD("Calling error callback");
- callback->getQueue().resolve(
- callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
- callback->getJson()->serialize()
- );
} else {
LoggerD("Calling success callback");
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
std::vector<picojson::value> response;
auto conversations = callback->getConversations();
response.push_back(MessagingUtil::conversationToJson(conversation));
}
);
- obj[JSON_DATA] = picojson::value(response);
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
+ callback->SetSuccess(picojson::value(response));
}
+ callback->Post();
+
delete callback;
callback = NULL;
}
callback->SetError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Error while creatng message handle"));
}
- if (!callback->isError()) {
+ if (!callback->IsError()) {
for(auto it = conversations.begin() ; it != conversations.end(); ++it) {
if((*it)->getType() != type) {
LoggerE("Invalid message type");
}
}
- if (!callback->isError()) {
+ if (!callback->IsError()) {
if(MessageType::SMS == type) {
msg_id_conv_id_map = &m_sms_removed_msg_id_conv_id_map;
conv_id_object_map = &m_sms_removed_conv_id_object_map;
}
}
- if (!callback->isError()) {
+ if (!callback->IsError()) {
int conv_index = 0;
for (auto it = conversations.begin() ; it != conversations.end();
++it, ++conv_index) {
}
}
- if (!callback->isError()) {
+ if (!callback->IsError()) {
error = msg_close_msg_handle(&handle);
if (MSG_SUCCESS != error) {
LoggerW("Cannot close message handle: %d", error);
}
}
- if (callback->isError()) {
+ if (callback->IsError()) {
LoggerD("Calling error callback");
- callback->getQueue().resolve(
- callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
- callback->getJson()->serialize()
- );
} else {
LoggerD("Calling success callback");
- auto json = callback->getJson();
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
- callback->getQueue().resolve(
- obj.at(JSON_CALLBACK_ID).get<double>(),
- json->serialize()
- );
+ callback->SetSuccess();
}
+ callback->Post();
+
delete callback;
callback = NULL;
}
return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "invalid PowerState");
if(current_requested_state_ == POWER_STATE_SCREEN_DIM) {
- int ret = PowerPlatformProxy::GetInstance().UnlockState();
- if (ret < 0) {
- LoggerE("deviceUnlockState error %d", ret);
+ int result = 0;
+ auto error_code = PowerPlatformProxy::GetInstance().UnlockState(&result);
+ if (!error_code || result < 0) {
+ LoggerE("deviceUnlockState error %d", result);
return PlatformResult(ErrorCode::UNKNOWN_ERR,
"device_power_request_unlock error");
}
}
case POWER_STATE_SCREEN_DIM:
{
- ret = PowerPlatformProxy::GetInstance().LockState();
- if (ret < 0) {
- LoggerE("device_power_request_lock error %d", ret);
+ int result = 0;
+ auto error_code = PowerPlatformProxy::GetInstance().LockState(&result);
+ if (!error_code || result < 0) {
+ LoggerE("device_power_request_lock error %d", result);
return PlatformResult(ErrorCode::UNKNOWN_ERR,
"device_power_request_lock error");
}
LoggerE("Platform return value from dim unlock: %d", ret);
if (bright_state_enabled_) {
- ret = PowerPlatformProxy::GetInstance().SetBrightnessFromSettings();
- if (DEVICE_ERROR_NONE != ret) {
- LoggerE("Platform error while setting restore brightness %d", ret);
+ int result = 0;
+ auto error_code = PowerPlatformProxy::GetInstance().SetBrightnessFromSettings(&result);
+ if (!error_code || DEVICE_ERROR_NONE != result) {
+ LoggerE("Platform error while setting restore brightness %d", result);
return PlatformResult(ErrorCode::UNKNOWN_ERR,
"Platform error while setting restore brightness");
}
display_state_e platform_state = DISPLAY_STATE_NORMAL;
if(current_requested_state_ == POWER_STATE_SCREEN_DIM) {
- ret = PowerPlatformProxy::GetInstance().UnlockState();
- if (DEVICE_ERROR_NONE != ret) {
- LoggerE("Failed to UnlockState (%d)", ret);
+ int result = 0;
+ auto error_code = PowerPlatformProxy::GetInstance().UnlockState(&result);
+ if (!error_code || DEVICE_ERROR_NONE != result) {
+ LoggerE("Failed to UnlockState (%d)", result);
}
}
ret = device_display_get_state(&platform_state);
PlatformResult PowerManager::GetScreenBrightness(double* output) {
LoggerD("Enter");
- int brightness = GetPlatformBrightness();
+ int brightness = 0;
+
+ auto error_code = GetPlatformBrightness(&brightness);
+
+ if (!error_code) {
+ LoggerE("Failed to obtain brightness value from platform.");
+ return error_code;
+ }
+
LoggerD("Brightness value: %d", brightness);
int max_brightness;
PlatformResult PowerManager::RestoreScreenBrightness() {
LoggerD("Enter");
- int ret = PowerPlatformProxy::GetInstance().SetBrightnessFromSettings();
- if (DEVICE_ERROR_NONE != ret) {
- LoggerE("Platform error while restoring brightness %d", ret);
+ int result = 0;
+ auto error_code = PowerPlatformProxy::GetInstance().SetBrightnessFromSettings(&result);
+ if (!error_code || DEVICE_ERROR_NONE != result) {
+ LoggerE("Platform error while restoring brightness %d", result);
return PlatformResult(ErrorCode::UNKNOWN_ERR,
"Platform error while restoring brightness");
}
should_be_read_from_cache_ = false;
}
- int ret = PowerPlatformProxy::GetInstance().SetBrightness(brightness);
- if (ret != 0) {
- LoggerE("Platform error while setting %d brightness: %d", brightness, ret);
+ int result = 0;
+ auto error_code = PowerPlatformProxy::GetInstance().SetBrightness(brightness, &result);
+ if (!error_code || result != 0) {
+ LoggerE("Platform error while setting %d brightness: %d", brightness, result);
return PlatformResult(ErrorCode::UNKNOWN_ERR,
"Platform error while setting brightness.");
}
return PlatformResult(ErrorCode::NO_ERROR);
}
-int PowerManager::GetPlatformBrightness(){
+PlatformResult PowerManager::GetPlatformBrightness(int* result) {
LoggerD("Entered");
int brightness = 0;
- int is_custom_mode = PowerPlatformProxy::GetInstance().IsCustomBrightness();
+ int is_custom_mode = 0;
+ auto error_code = PowerPlatformProxy::GetInstance().IsCustomBrightness(&is_custom_mode);
+
+ if (!error_code) {
+ LoggerE("Failed to check if custom brightness is set.");
+ return error_code;
+ }
+
if ((is_custom_mode && current_brightness_ != -1) || should_be_read_from_cache_) {
LoggerD("return custom brightness %d", current_brightness_);
- return current_brightness_;
+ *result = current_brightness_;
+ return PlatformResult(ErrorCode::NO_ERROR);
}
int is_auto_brightness = 0;
}
} else {
LoggerD("Brightness via DBUS");
- brightness = PowerPlatformProxy::GetInstance().GetBrightness();
+ error_code = PowerPlatformProxy::GetInstance().GetBrightness(&brightness);
+
+ if (!error_code) {
+ LoggerE("Failed to obtain brightness via DBUS.");
+ return error_code;
+ }
}
+
LoggerD("BRIGHTNESS(%s) %d", is_auto_brightness == 1 ? "auto" : "fix" , brightness);
- return brightness;
+ *result = brightness;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
}
static PowerManager* GetInstance();
private:
- int GetPlatformBrightness();
+ common::PlatformResult GetPlatformBrightness(int* result);
common::PlatformResult SetPlatformBrightness(int brightness);
common::PlatformResult RestoreSettedBrightness();
return instance;
}
-int PowerPlatformProxy::LockState()
+common::PlatformResult PowerPlatformProxy::LockState(int* result)
{
LoggerD("Entered");
DBusOperationArguments args;
args.AddArgumentString("NULL");
args.AddArgumentInt32(0);
- return dbus_op_.InvokeSyncGetInt("lockstate", &args);
+ return dbus_op_.InvokeSyncGetInt("lockstate", &args, result);
}
-int PowerPlatformProxy::UnlockState()
+common::PlatformResult PowerPlatformProxy::UnlockState(int* result)
{
LoggerD("Entered");
DBusOperationArguments args;
args.AddArgumentString("lcddim");
args.AddArgumentString("keeptimer");
- return dbus_op_.InvokeSyncGetInt("unlockstate", &args);
+ return dbus_op_.InvokeSyncGetInt("unlockstate", &args, result);
}
-int PowerPlatformProxy::SetBrightnessFromSettings()
+common::PlatformResult PowerPlatformProxy::SetBrightnessFromSettings(int* result)
{
LoggerD("Entered");
- return dbus_op_.InvokeSyncGetInt("ReleaseBrightness", NULL);
+ return dbus_op_.InvokeSyncGetInt("ReleaseBrightness", nullptr, result);
}
-int PowerPlatformProxy::SetBrightness(int val)
+common::PlatformResult PowerPlatformProxy::SetBrightness(int val, int* result)
{
LoggerD("Entered");
DBusOperationArguments args;
args.AddArgumentInt32(val);
- return dbus_op_.InvokeSyncGetInt("HoldBrightness", &args);
+ return dbus_op_.InvokeSyncGetInt("HoldBrightness", &args, result);
}
-int PowerPlatformProxy::GetBrightness() {
+common::PlatformResult PowerPlatformProxy::GetBrightness(int* result) {
LoggerD("Entered");
- return dbus_op_.InvokeSyncGetInt("CurrentBrightness", NULL);
+ return dbus_op_.InvokeSyncGetInt("CurrentBrightness", nullptr, result);
}
-int PowerPlatformProxy::IsCustomBrightness() {
+common::PlatformResult PowerPlatformProxy::IsCustomBrightness(int* result) {
LoggerD("Entered");
- return dbus_op_.InvokeSyncGetInt("CustomBrightness", NULL);
+ return dbus_op_.InvokeSyncGetInt("CustomBrightness", nullptr, result);
}
} // namespace power
class PowerPlatformProxy {
public:
- int LockState();
- int UnlockState();
- int SetBrightnessFromSettings();
- int SetBrightness(int val);
+ common::PlatformResult LockState(int* result);
+ common::PlatformResult UnlockState(int* result);
+ common::PlatformResult SetBrightnessFromSettings(int* result);
+ common::PlatformResult SetBrightness(int val, int* result);
- int GetBrightness();
- int IsCustomBrightness();
+ common::PlatformResult GetBrightness(int* result);
+ common::PlatformResult IsCustomBrightness(int* result);
static PowerPlatformProxy& GetInstance();
PowerPlatformProxy();
virtual ~PowerPlatformProxy();
- common::DBusOperation dbus_op_;
+ common::DBusOperation dbus_op_;
};
} // namespace power
#include <runtime_info.h>
#include <vconf.h>
-#include "common/logger.h"
#include "common/extension.h"
+#include "common/logger.h"
#include "common/task-queue.h"
+#include "common/tools.h"
#include "radio/radio_instance.h"
#include "secureelement/secureelement_seservice.h"
#include "common/logger.h"
-#include "common/task-queue.h"
#include "common/platform_result.h"
+#include "common/task-queue.h"
+#include "common/tools.h"
#include "secureelement/secureelement_instance.h"
#include <memory>
#include <mutex>
-#include "common/task-queue.h"
#include "common/logger.h"
#include "common/optional.h"
#include "common/platform_exception.h"
+#include "common/task-queue.h"
+#include "common/tools.h"
+
#include "sensor_instance.h"
using namespace common;
#include <vconf.h>
#include <vconf-keys.h>
+#include "common/converter.h"
+#include "common/logger.h"
#include "common/task-queue.h"
+#include "common/tools.h"
//This constant was originally defined in vconf.h. However, in tizen 3, it
//appears, it is removed (or defined only in vconf-internals.h)
#endif
#include "sound/sound_instance.h"
-#include "common/logger.h"
-#include "common/converter.h"
namespace extension {
namespace sound {
#include <sensor_internal.h>
#include <wifi.h>
+#include "common/converter.h"
+#include "common/logger.h"
+#include "common/task-queue.h"
+#include "common/tools.h"
+
#include "systeminfo/systeminfo_instance.h"
#include "systeminfo/systeminfo_device_capability.h"
#include "systeminfo/systeminfo-utils.h"
-#include "common/logger.h"
-#include "common/converter.h"
-#include "common/task-queue.h"
using common::PlatformResult;
using common::ErrorCode;
#include <unistd.h>
#include <app_manager.h>
#include <pkgmgr-info.h>
-#include "common/scope_exit.h"
+
#include "common/logger.h"
+#include "common/scope_exit.h"
+#include "common/tools.h"
+
#include "utils/utils_instance.h"
using common::PlatformResult;