+++ /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 "FilterIterator.h"
-#include "common/logger.h"
-#include "common/platform_exception.h"
-
-using namespace common;
-
-namespace extension {
-namespace tizen {
-
-FilterIterator::FilterIterator(AbstractFilterPtr filter)
- : m_root_filter(filter), m_current_state(FIS_NOT_VALID) {
- ScopeLogger();
- if (!m_root_filter) {
- LoggerE("Trying to create FilterIterator with NULL filter");
- m_root_filter = AbstractFilterPtr(new AbstractFilter());
- }
-
- goToNext(m_root_filter);
-}
-
-FilterIteratorState FilterIterator::getState() const {
- return m_current_state;
-}
-
-AbstractFilterPtr FilterIterator::operator*() const {
- return m_current_filter;
-}
-
-AbstractFilterPtr FilterIterator::getCurrentFilter() const {
- return m_current_filter;
-}
-
-bool FilterIterator::isEnd() const {
- return FIS_END == m_current_state;
-}
-
-bool FilterIterator::isInsideCompositeFilter() const {
- return !m_composite_stack.empty();
-}
-
-CompositeFilterPtr FilterIterator::getCurrentCompositeFilter() const {
- if (m_composite_stack.empty()) {
- return CompositeFilterPtr();
- }
-
- return m_composite_stack.top().filter;
-}
-
-int FilterIterator::getCurrentCompositeSubFilterIndex() const {
- if (!isInsideCompositeFilter()) {
- return 0;
- }
-
- return m_composite_stack.top().cur_sub_filter_index;
-}
-
-bool FilterIterator::isLastCompositeSubFilter() const {
- if (!isInsideCompositeFilter()) {
- return false;
- }
-
- CompositeIterState cfilter = m_composite_stack.top();
- return (int)(cfilter.filter->getFilters().size() - 1) == cfilter.cur_sub_filter_index;
-}
-
-void FilterIterator::operator++(int) {
- ScopeLogger();
- this->operator++();
-}
-
-void FilterIterator::operator++() {
- ScopeLogger();
- if (FIS_ATTRIBUTE_FILTER == m_current_state || FIS_ATTRIBUTE_RANGE_FILTER == m_current_state) {
- if (m_composite_stack.empty()) {
- // We are not inside composite filter iteration -> reached THE END
- setReachedEnd();
- } else {
- // We are inside a composite filter -> try move to next sub filter
- goToNextInCurCompositeFilter();
- }
- } else if (FIS_COMPOSITE_START == m_current_state) {
- goToNextInCurCompositeFilter();
- } else if (FIS_COMPOSITE_END == m_current_state) {
- m_composite_stack.pop();
- if (m_composite_stack.empty()) {
- // There is no parent composite filter -> reached THE END
- setReachedEnd();
- } else {
- // There is parent composite filter -> go back and try move to next sub filter
- goToNextInCurCompositeFilter();
- }
- } else if (FIS_NOT_VALID == m_current_state) {
- // There is nothing to do -> reached THE END
- setReachedEnd();
- }
-}
-
-void FilterIterator::goToNextInCurCompositeFilter() {
- ScopeLogger();
- CompositeIterState& cur_cs = m_composite_stack.top();
- AbstractFilterPtrVector sub_filters = cur_cs.filter->getFilters();
- const size_t next_filter_index = cur_cs.cur_sub_filter_index + 1;
- if (next_filter_index >= sub_filters.size()) {
- // Reached last item of composite filter
- m_current_filter = cur_cs.filter;
- m_current_state = FIS_COMPOSITE_END;
- } else {
- cur_cs.cur_sub_filter_index = next_filter_index;
- // There is next item inside this composite filter
- goToNext(sub_filters[next_filter_index]);
- }
-}
-
-void FilterIterator::setReachedEnd() {
- ScopeLogger();
- m_current_state = FIS_END;
- m_current_filter = AbstractFilterPtr();
-}
-
-void FilterIterator::goToNext(AbstractFilterPtr next) {
- ScopeLogger();
- switch (next->getFilterType()) {
- case ATTRIBUTE_FILTER: {
- m_current_state = FIS_ATTRIBUTE_FILTER;
- } break;
- case ATTRIBUTE_RANGE_FILTER: {
- m_current_state = FIS_ATTRIBUTE_RANGE_FILTER;
- } break;
- case COMPOSITE_FILTER: {
- m_current_state = FIS_COMPOSITE_START;
- CompositeIterState cf_state;
- cf_state.filter = castToCompositeFilter(next);
- cf_state.cur_sub_filter_index = -1;
- m_composite_stack.push(cf_state);
- } break;
- case ABSTRACT_FILTER: {
- LoggerE("Reached AbstractFilter!!");
- m_current_state = FIS_NOT_VALID;
- } break;
- }
-
- m_current_filter = next;
-}
-
-} // Tizen
-} // DeviceAPI
+++ /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 __TIZEN_TIZEN_FILTER_ITERATOR_H__
-#define __TIZEN_TIZEN_FILTER_ITERATOR_H__
-
-#include "AbstractFilter.h"
-#include "AttributeFilter.h"
-#include "AttributeRangeFilter.h"
-#include "CompositeFilter.h"
-
-#include <stack>
-
-namespace extension {
-namespace tizen {
-
-enum FilterIteratorState {
- FIS_NOT_VALID = 0,
- FIS_ATTRIBUTE_FILTER,
- FIS_ATTRIBUTE_RANGE_FILTER,
- FIS_COMPOSITE_START,
- FIS_COMPOSITE_END,
- FIS_END
-};
-
-class FilterIterator {
- public:
- FilterIterator(AbstractFilterPtr filter);
-
- FilterIteratorState getState() const;
- AbstractFilterPtr operator*() const;
- AbstractFilterPtr getCurrentFilter() const;
- bool isEnd() const;
-
- bool isInsideCompositeFilter() const;
-
- /**
- * Returns null shared pointer if we are not inside composite filter
- */
- CompositeFilterPtr getCurrentCompositeFilter() const;
-
- /**
- * Get index of current sub filter (inside composite filter)
- * Returns 0 if we are not inside composite filter.
- */
- int getCurrentCompositeSubFilterIndex() const;
-
- /**
- * Return true if current sub filter is the last one in current composite filter
- * Returns false if we are not inside composite filter.
- */
- bool isLastCompositeSubFilter() const;
-
- void operator++();
- void operator++(int);
-
- private:
- void setReachedEnd();
- void goToNext(AbstractFilterPtr next);
- void goToNextInCurCompositeFilter();
-
- AbstractFilterPtr m_root_filter;
- FilterIteratorState m_current_state;
- AbstractFilterPtr m_current_filter;
-
- struct CompositeIterState {
- CompositeIterState() : cur_sub_filter_index(0) {
- }
-
- CompositeFilterPtr filter;
- int cur_sub_filter_index;
- };
-
- std::stack<CompositeIterState> m_composite_stack;
-};
-
-} // Tizen
-} // DeviceAPI
-
-#endif // __TIZEN_TIZEN_FILTER_ITERATOR_H__
//#include "DBus/LoadAttachmentProxy.h"
#include <sstream>
-#include "MsgCommon/FilterIterator.h"
#include "common/scope_exit.h"
#include "messaging/DBus/DBusTypes.h"
return op_id++;
}
+/**
+ * Attribute | Attribute filter| Attribute range filter
+ * | supported | supported
+ * ----------------+-----------------+------------------------
+ * id | Yes | No
+ * parentId | Yes | No
+ * serviceId | Yes | No
+ * contentType | Yes | No
+ * name | Yes | No
+ * path | Yes | No
+ * type | Yes | No
+ * synchronizable | Yes | No
+ **/
+
PlatformResult EmailManager::FindFoldersPlatform(FoldersCallbackData* callback) {
ScopeLogger();
int ret = EMAIL_ERROR_UNKNOWN;
- int account_id = ACCOUNT_ID_NOT_INITIALIZED;
email_mailbox_t* mailboxes = NULL;
- email_mailbox_t* nth_mailbox = NULL;
- int mailboxes_count;
+ int mailboxes_count = 0;
SCOPE_EXIT {
if (mailboxes != NULL) {
}
};
- std::lock_guard<std::mutex> lock(m_mutex);
tizen::AbstractFilterPtr filter = callback->getFilter();
if (!filter) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Filter not provided");
}
- for (FilterIterator it(filter); false == it.isEnd(); it++) {
- if (FIS_COMPOSITE_START == it.getState()) {
- CompositeFilterPtr cf = castToCompositeFilter((*it));
- if (cf && INTERSECTION != cf->getType()) {
- return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR, "Invalid Filter Type",
- ("Invalid Filter type: %d", cf->getType()));
- }
- } else if (FIS_ATTRIBUTE_FILTER == it.getState()) {
- AttributeFilterPtr attrf = castToAttributeFilter((*it));
- if (attrf) {
- const std::string attr_name = attrf->getAttributeName();
- if (FIND_FOLDERS_ATTRIBUTE_ACCOUNTID_NAME == attr_name) {
- account_id = static_cast<int>(attrf->getMatchValue()->toLong());
- } else {
- return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "The attribute name is invalid",
- ("The attribute name: %s is invalid", attr_name.c_str()));
- }
- }
- }
+ std::lock_guard<std::mutex> lock(m_mutex);
+ auto account_id = callback->getMessageStorageId();
+
+ if (account_id < 0) {
+ LoggerD("account_id < 0");
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "An unknown error occurred");
}
LoggerD("Listing folders for account ID: %d", account_id);
- if (account_id > 0) {
- ret = email_get_mailbox_list(account_id, -1, &mailboxes, &mailboxes_count);
- if (EMAIL_ERROR_NONE != ret || !mailboxes) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Platform error, cannot get folders",
- ("email_get_mailbox_list error: %d (%s)", ret, get_error_message(ret)));
- }
+ ret = email_get_mailbox_list(account_id, -1, &mailboxes, &mailboxes_count);
+ if (EMAIL_ERROR_NONE != ret || !mailboxes) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Platform error, cannot get folders",
+ ("email_get_mailbox_list error: %d (%s)", ret, get_error_message(ret)));
+ }
- if (mailboxes_count <= 0) {
- LoggerD("Empty mailboxes");
- } else {
- LoggerD("Founded mailboxes: %d", mailboxes_count);
-
- nth_mailbox = mailboxes;
- for (int i = 0; i < mailboxes_count; ++i) {
- std::shared_ptr<MessageFolder> fd;
- fd = std::make_shared<MessageFolder>(*nth_mailbox);
- callback->addFolder(fd);
- nth_mailbox++;
- }
+ LoggerD("Found mailboxes: %d", mailboxes_count);
+ for (int i = 0; i < mailboxes_count; ++i) {
+ auto fd = std::make_shared<MessageFolder>(mailboxes[i]);
+ if (filter->isMatching(fd.get())) {
+ callback->addFolder(fd);
}
}
+
return PlatformResult(ErrorCode::NO_ERROR);
}
return m_filter;
}
+void FoldersCallbackData::setMessageStorageId(int id) {
+ m_message_storage_id = id;
+}
+
+int FoldersCallbackData::getMessageStorageId() const {
+ return m_message_storage_id;
+}
+
} // messaging
} // extension
void setFilter(tizen::AbstractFilterPtr filter);
tizen::AbstractFilterPtr getFilter() const;
+ void setMessageStorageId(int id);
+ int getMessageStorageId() const;
+
private:
std::vector<std::shared_ptr<MessageFolder>> m_folders;
tizen::AbstractFilterPtr m_filter;
+ int m_message_storage_id = -1;
};
} // messaging
'MsgCommon/AttributeRangeFilter.h',
'MsgCommon/CompositeFilter.cpp',
'MsgCommon/CompositeFilter.h',
- 'MsgCommon/FilterIterator.cpp',
- 'MsgCommon/FilterIterator.h',
'message_callback_user_data.cc',
'message_callback_user_data.h',
'messages_callback_user_data.cc',
callback->AddToQueue();
auto service = manager_.getMessageService(getServiceIdFromJSON(data));
+ callback->setMessageStorageId(service->getMsgServiceId());
service->getMsgStorage()->findFolders(callback);
}