[Messaging] MsgCommon with Tizen filters
authorJerzy Pabich <j.pabich@samsung.com>
Fri, 19 Dec 2014 18:30:23 +0000 (19:30 +0100)
committerJerzy Pabich <j.pabich@samsung.com>
Sat, 20 Dec 2014 09:31:59 +0000 (10:31 +0100)
[Verification] Message derives from FilterableObject and
its constructor works fine:

var m = new tizen.Message("messaging.email");

Change-Id: Ia457e8b48a898106166ecf257a84dbc2052cd4d4
Signed-off-by: Jerzy Pabich <j.pabich@samsung.com>
17 files changed:
src/messaging/MsgCommon/AbstractFilter.cpp [new file with mode: 0644]
src/messaging/MsgCommon/AbstractFilter.h [new file with mode: 0644]
src/messaging/MsgCommon/Any.cpp [new file with mode: 0644]
src/messaging/MsgCommon/Any.h [new file with mode: 0644]
src/messaging/MsgCommon/AttributeFilter.cpp [new file with mode: 0644]
src/messaging/MsgCommon/AttributeFilter.h [new file with mode: 0644]
src/messaging/MsgCommon/AttributeRangeFilter.cpp [new file with mode: 0644]
src/messaging/MsgCommon/AttributeRangeFilter.h [new file with mode: 0644]
src/messaging/MsgCommon/CompositeFilter.cpp [new file with mode: 0644]
src/messaging/MsgCommon/CompositeFilter.h [new file with mode: 0644]
src/messaging/MsgCommon/FilterIterator.cpp [new file with mode: 0644]
src/messaging/MsgCommon/FilterIterator.h [new file with mode: 0644]
src/messaging/MsgCommon/SortMode.cpp [new file with mode: 0644]
src/messaging/MsgCommon/SortMode.h [new file with mode: 0644]
src/messaging/message.cc
src/messaging/message.h
src/messaging/messaging.gyp

diff --git a/src/messaging/MsgCommon/AbstractFilter.cpp b/src/messaging/MsgCommon/AbstractFilter.cpp
new file mode 100644 (file)
index 0000000..7352b10
--- /dev/null
@@ -0,0 +1,260 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "AbstractFilter.h"
+//#include "JSAttributeFilter.h"
+//#include "JSAttributeRangeFilter.h"
+//#include "JSCompositeFilter.h"
+#include "common/platform_exception.h"
+#include "common/logger.h"
+//#include <JSUtil.h>
+#include <algorithm>
+
+namespace extension {
+namespace tizen {
+
+using namespace common;
+
+AbstractFilter::AbstractFilter(FilterType filter_type) :
+        m_filter_type(filter_type)
+{
+}
+
+AbstractFilter::~AbstractFilter()
+{
+}
+
+FilterType AbstractFilter::getFilterType() const
+{
+    return m_filter_type;
+}
+
+//JSValueRef AbstractFilter::makeJSValue(JSContextRef context,
+//        AbstractFilterPtr native)
+//{
+//    LOGD("Entered");
+//
+//    if (!native) {
+//        LOGE("Native is null");
+//        throw UnknownException("Native is null");
+//    }
+//
+//    switch (native->getFilterType()) {
+//        case ATTRIBUTE_FILTER:
+//            return JSAttributeFilter::makeJSObject(context, native);
+//        case ATTRIBUTE_RANGE_FILTER:
+//            return JSAttributeRangeFilter::makeJSObject(context, native);
+//        case COMPOSITE_FILTER:
+//            return JSCompositeFilter::makeJSObject(context, native);
+//        default:
+//            LOGE("Unsupported filter type");
+//            throw UnknownException("Unsupported filter type");
+//    }
+//}
+//
+//AbstractFilterPtr AbstractFilter::getPrivateObject(JSContextRef context,
+//        JSValueRef value)
+//{
+//    JSObjectRef object = JSUtil::JSValueToObject(context, value);
+//
+//    if (!JSValueIsObjectOfClass(context, value, JSAttributeFilter::getClassRef()) &&
+//        !JSValueIsObjectOfClass(context, value, JSAttributeRangeFilter::getClassRef()) &&
+//        !JSValueIsObjectOfClass(context, value, JSCompositeFilter::getClassRef())) {
+//        LOGE("JSObjectRef:%p - Object type is not JSAttributeFilter, "
+//                "JSAttributeRangeFilter nor JSCompositeFilter", object);
+//        throw TypeMismatchException("Object type is not valid filter");
+//    }
+//
+//    AbstractFilterHolder* priv =
+//            static_cast<AbstractFilterHolder*>(JSObjectGetPrivate(object));
+//    if (!priv) {
+//        LOGE("Holder is null");
+//        throw UnknownException("Holder is null");
+//    }
+//    if (!(priv->ptr)) {
+//        LOGE("Priv is null");
+//        throw UnknownException("Priv is null");
+//    }
+//    return priv->ptr;
+//}
+
+
+bool AbstractFilter::isMatching(const FilterableObject* const tested_object) const
+{
+    LoggerE("Calling isMatching on AbstractFilter!");
+    throw UnknownException("Method not supported");
+}
+
+AttributeFilterPtr castToAttributeFilter(AbstractFilterPtr from)
+{
+    if(ATTRIBUTE_FILTER != from->getFilterType()) {
+        LoggerE("Trying to get AttributeFilterPtr but filter's type is: %d",
+                from->getFilterType());
+        return AttributeFilterPtr();
+    }
+
+    return std::dynamic_pointer_cast<AttributeFilter>(from);
+}
+
+AttributeRangeFilterPtr castToAttributeRangeFilter(AbstractFilterPtr from)
+{
+    if(ATTRIBUTE_RANGE_FILTER != from->getFilterType()) {
+        LoggerE("Trying to get AttributeRangeFilterPtr but filter's type is: %d",
+                from->getFilterType());
+        return AttributeRangeFilterPtr();
+    }
+
+    return std::dynamic_pointer_cast<AttributeRangeFilter>(from);
+}
+
+CompositeFilterPtr castToCompositeFilter(AbstractFilterPtr from)
+{
+    if(COMPOSITE_FILTER != from->getFilterType()) {
+        LoggerE("Trying to get CompositeFilterPtr but filter's type is: %d",
+                from->getFilterType());
+        return CompositeFilterPtr();
+    }
+
+    return std::dynamic_pointer_cast<CompositeFilter>(from);
+}
+
+namespace {
+
+inline std::string convertToLowerCase(const std::string& input_string)
+{
+    std::string output_string = input_string;
+    std::transform(output_string.begin(), output_string.end(), output_string.begin(),
+            ::tolower);
+    return output_string;
+}
+
+} // Anonymous namespace
+
+bool FilterUtils::isStringMatching(const std::string& key,
+        const std::string& value,
+        tizen::FilterMatchFlag flag)
+{
+    switch(flag)
+    {
+        case tizen::ENDSWITH: {
+            if (key.empty()) {
+                return false;
+            }
+            if (key.size() > value.size()) {
+                return false;
+            }
+            std::string lvalue = convertToLowerCase(value);
+            std::string lkey = convertToLowerCase(key);
+            return lvalue.substr(lvalue.size() - lkey.size(), lkey.size()) == lkey;
+        }
+
+        case tizen::EXACTLY: {
+            return key == value;
+        }
+
+        case tizen::STARTSWITH: {
+            if (key.empty()) {
+                return false;
+            }
+            if (key.size() > value.size()) {
+                return false;
+            }
+            std::string lvalue = convertToLowerCase(value);
+            std::string lkey = convertToLowerCase(key);
+            return lvalue.substr(0, lkey.size()) == lkey;
+        }
+
+        case tizen::CONTAINS: {
+            if (key.empty()) {
+                return false;
+            }
+            if (key.size() > value.size()) {
+                return false;
+            }
+            std::string lvalue = convertToLowerCase(value);
+            std::string lkey = convertToLowerCase(key);
+            return lvalue.find(lkey) != std::string::npos;
+        }
+
+        default: {
+            LoggerE("Unknown match flag");
+            return false;
+        }
+    }
+}
+
+bool FilterUtils::isAnyStringMatching(const std::string& key,
+        const std::vector<std::string>& values,
+        tizen::FilterMatchFlag flag)
+{
+    for(auto it = values.begin(); it != values.end(); ++it) {
+        if(isStringMatching(key,*it,flag)) {
+            return true;
+        }
+    }
+    return false;
+}
+
+bool FilterUtils::isTimeStampInRange(const time_t& time_stamp,
+        tizen::AnyPtr& initial_value,
+        tizen::AnyPtr& end_value)
+{
+    time_t from_time = 0;
+    time_t to_time = 0;
+
+    bool initial_is_valid_time_value = false;
+    if (initial_value && !initial_value->isNullOrUndefined()) {
+        try {
+            struct tm ftime; // TODO = *initial_value->toDateTm();
+            from_time = mktime(&ftime);
+            initial_is_valid_time_value = true;
+        }
+        catch(...) {
+            LoggerE("Unknown exception occured during execution of Any::toDateTm()");
+        }
+    }
+    if(!initial_is_valid_time_value) {
+        LoggerE("initialValue is not Time!");
+        throw InvalidValuesException("initialValue is not Time!");
+    }
+
+    bool end_is_valid_time_value = false;
+    if (end_value && !end_value->isNullOrUndefined()) {
+        try {
+            struct tm ttime; // TODO =  *end_value->toDateTm();
+            to_time = mktime(&ttime);
+            end_is_valid_time_value = true;
+        }
+        catch(...) {
+            LoggerE("Unknown exception occured during execution of Any::toDateTm()");
+        }
+    }
+    if(end_is_valid_time_value) {
+        LoggerE("endValue is not Time!");
+        throw InvalidValuesException("endValue is not Time!");
+    }
+
+    bool is_in_range = FilterUtils::isBetweenTimeRange(time_stamp, from_time, to_time);
+
+    LoggerD("%d is%s in time range <%d, %d>", time_stamp, (is_in_range ? "" : " NOT"),
+            from_time, to_time);
+
+    return is_in_range;
+}
+
+} //Tizen
+} //DeviceAPI
diff --git a/src/messaging/MsgCommon/AbstractFilter.h b/src/messaging/MsgCommon/AbstractFilter.h
new file mode 100644 (file)
index 0000000..6f54286
--- /dev/null
@@ -0,0 +1,160 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef __TIZEN_TIZEN_ABSTRACT_FILTER_H__
+#define __TIZEN_TIZEN_ABSTRACT_FILTER_H__
+
+#include <memory>
+#include <vector>
+#include <sstream>
+//#include <JSArray.h>
+
+#include "Any.h"
+
+namespace extension {
+namespace tizen {
+
+class AttributeFilter;
+typedef std::shared_ptr<AttributeFilter> AttributeFilterPtr;
+
+class AttributeRangeFilter;
+typedef std::shared_ptr<AttributeRangeFilter> AttributeRangeFilterPtr;
+
+class CompositeFilter;
+typedef std::shared_ptr<CompositeFilter> CompositeFilterPtr;
+
+class AbstractFilter;
+typedef std::shared_ptr<AbstractFilter> AbstractFilterPtr;
+typedef std::vector<AbstractFilterPtr> AbstractFilterPtrVector;
+
+struct AbstractFilterHolder {
+    AbstractFilterPtr ptr;
+};
+
+enum FilterType {
+    ABSTRACT_FILTER = 0,
+    ATTRIBUTE_FILTER,
+    ATTRIBUTE_RANGE_FILTER,
+    COMPOSITE_FILTER
+};
+
+enum FilterMatchFlag {
+    EXACTLY = 0,
+    FULLSTRING,
+    CONTAINS,
+    STARTSWITH,
+    ENDSWITH,
+    EXISTS
+};
+
+class FilterableObject {
+public:
+    virtual ~FilterableObject(){}
+
+    virtual bool isMatchingAttribute(const std::string& attribute_name,
+            const FilterMatchFlag match_flag,
+            AnyPtr match_value) const = 0;
+
+    virtual bool isMatchingAttributeRange(const std::string& attribute_name,
+            AnyPtr initial_value,
+            AnyPtr end_value) const = 0;
+};
+
+class AbstractFilter {
+public:
+    AbstractFilter(FilterType type = ABSTRACT_FILTER);
+    virtual ~AbstractFilter();
+
+    FilterType getFilterType() const;
+
+//    static JSValueRef makeJSValue(JSContextRef context, AbstractFilterPtr priv);
+//    static AbstractFilterPtr getPrivateObject(JSContextRef context,
+//            JSValueRef value);
+
+    virtual bool isMatching(const FilterableObject* const filtered_object) const;
+
+protected:
+    FilterType m_filter_type;
+};
+
+/**
+ * Returns NULL shared_ptr if cast is not possible (incorrect type)
+ */
+AttributeFilterPtr castToAttributeFilter(AbstractFilterPtr from);
+AttributeRangeFilterPtr castToAttributeRangeFilter(AbstractFilterPtr from);
+CompositeFilterPtr castToCompositeFilter(AbstractFilterPtr from);
+
+
+//class JSFilterArray : public Common::JSArray<AbstractFilterPtr> {
+//public:
+//    JSFilterArray(JSContextRef ctx, JSObjectRef array):
+//            JSArray<AbstractFilterPtr>(ctx, array, AbstractFilter::getPrivateObject,
+//                    AbstractFilter::makeJSValue)
+//    {
+//    }
+//    JSFilterArray(JSContextRef ctx):
+//            JSArray<AbstractFilterPtr>(ctx, AbstractFilter::getPrivateObject,
+//                    AbstractFilter::makeJSValue)
+//    {
+//    }
+//    void operator=(const std::vector<AbstractFilterPtr>& list)
+//    {
+//        overwrite(list);
+//    }
+//};
+
+
+
+class FilterUtils {
+public:
+    static bool isStringMatching(const std::string& key,
+            const std::string& value,
+            tizen::FilterMatchFlag flag);
+    static bool isAnyStringMatching(const std::string& key,
+            const std::vector<std::string>& values,
+            tizen::FilterMatchFlag flag);
+    static bool isTimeStampInRange(const time_t& time_stamp,
+            tizen::AnyPtr& initial_value,
+            tizen::AnyPtr& end_value);
+
+    static inline bool isBetweenTimeRange(const time_t current,
+            const time_t from,
+            const time_t to)
+    {
+        return ((current - from) >= 0 ) && ((to - current) >= 0);
+    }
+
+    static inline std::string boolToString(const bool src)
+    {
+        if(src) {
+            return "true";
+        }
+        else {
+            return "false";
+        }
+    }
+};
+
+} // Tizen
+} // DeviceAPI
+
+
+#include "AttributeFilter.h"
+#include "AttributeRangeFilter.h"
+#include "CompositeFilter.h"
+
+#endif // __TIZEN_TIZEN_ABSTRACT_FILTER_H__
diff --git a/src/messaging/MsgCommon/Any.cpp b/src/messaging/MsgCommon/Any.cpp
new file mode 100644 (file)
index 0000000..5283dd1
--- /dev/null
@@ -0,0 +1,109 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "Any.h"
+//#include <JSUtil.h>
+
+namespace extension {
+namespace tizen {
+
+Any::Any(picojson::value value) :
+//        m_context(context),
+        m_value(value)
+{
+//    JSValueProtect(m_context, m_value);
+}
+
+Any::~Any()
+{
+//    JSValueUnprotect(m_context, m_value);
+}
+
+//JSContextRef Any::getContext() const
+//{
+//    return m_context;
+//}
+
+picojson::value Any::getValue() const
+{
+    return m_value;
+}
+
+void Any::setValue(picojson::value value)
+{
+//    JSValueUnprotect(m_context, m_value);
+//    m_context = context;
+    m_value = value;
+//    JSValueProtect(m_context, m_value);
+}
+
+bool Any::isNullOrUndefined() const
+{
+    //TODO is it check for undefined?
+    return m_value.is<picojson::null>();
+}
+
+bool Any::toBool() const
+{
+    return m_value.get<bool>();
+}
+
+long Any::toLong() const
+{
+    return static_cast<long>(m_value.get<double>());
+}
+
+unsigned long Any::toULong() const
+{
+    return static_cast<unsigned long>(m_value.get<double>());
+}
+
+long long Any::toLongLong() const
+{
+    return static_cast<long long>(m_value.get<double>());
+}
+
+unsigned long long Any::toULongLong() const
+{
+    return static_cast<unsigned long long>(m_value.get<double>());
+}
+
+double Any::toDouble() const
+{
+    return m_value.get<double>();
+}
+
+std::string Any::toString() const
+{
+    return m_value.get<std::string>();
+}
+
+std::tm* Any::toDateTm() const
+{
+    //TODO is it ok?
+    std::time_t time = static_cast<std::time_t>(m_value.get<double>());
+    return gmtime(&time);
+}
+
+std::time_t Any::toTimeT() const
+{
+    //TODO is it ok?
+    return static_cast<std::time_t>(m_value.get<double>());
+}
+
+} // Tizen
+} // Device_API
diff --git a/src/messaging/MsgCommon/Any.h b/src/messaging/MsgCommon/Any.h
new file mode 100644 (file)
index 0000000..2daa5fc
--- /dev/null
@@ -0,0 +1,77 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef __TIZEN_TIZEN_ANY_H__
+#define __TIZEN_TIZEN_ANY_H__
+
+#include <memory>
+//#include <JavaScriptCore/JavaScript.h>
+#include <string>
+#include <ctime>
+#include "common/picojson.h"
+
+namespace extension {
+namespace tizen {
+
+enum PrimitiveType {
+    PrimitiveType_NoType,
+    PrimitiveType_Null,
+    PrimitiveType_Boolean,
+    PrimitiveType_Long,
+    PrimitiveType_ULong,
+    PrimitiveType_LongLong,
+    PrimitiveType_ULongLong,
+    PrimitiveType_Double,
+    PrimitiveType_String,
+    PrimitiveType_Time,
+    PrimitiveType_Object,
+    PrimitiveType_PlatformObject
+};
+
+class Any;
+typedef std::shared_ptr<Any> AnyPtr;
+
+class Any {
+public:
+    Any(picojson::value value);
+    virtual ~Any();
+
+//    JSContextRef getContext() const;
+    picojson::value getValue() const;
+    void setValue(picojson::value value);
+
+    bool isNullOrUndefined() const;
+
+    bool toBool() const;
+    long toLong() const;
+    unsigned long toULong() const;
+    long long toLongLong() const;
+    unsigned long long toULongLong() const;
+    double toDouble() const;
+    std::string toString() const;
+    std::tm* toDateTm() const;
+    std::time_t toTimeT() const;
+
+private:
+//    JSContextRef m_context;
+    picojson::value m_value;
+};
+
+} // Tizen
+} // DeviceAPI
+
+#endif // __TIZEN_TIZEN_ANY_H__
diff --git a/src/messaging/MsgCommon/AttributeFilter.cpp b/src/messaging/MsgCommon/AttributeFilter.cpp
new file mode 100644 (file)
index 0000000..1943d71
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "AttributeFilter.h"
+#include "common/platform_exception.h"
+#include "common/logger.h"
+
+namespace extension {
+namespace tizen {
+
+AttributeFilter::AttributeFilter(const std::string &attribute_name) :
+        AbstractFilter(ATTRIBUTE_FILTER),
+        m_attribute_name(attribute_name),
+        m_match_flag(EXACTLY)
+{
+}
+
+AttributeFilter::~AttributeFilter()
+{
+}
+
+std::string AttributeFilter::getAttributeName() const
+{
+    return m_attribute_name;
+}
+
+void AttributeFilter::setAttributeName(const std::string &attribute_name)
+{
+    m_attribute_name = attribute_name;
+}
+
+FilterMatchFlag AttributeFilter::getMatchFlag() const
+{
+    return m_match_flag;
+}
+
+void AttributeFilter::setMatchFlag(FilterMatchFlag match_flag)
+{
+    m_match_flag = match_flag;
+}
+
+AnyPtr AttributeFilter::getMatchValue() const
+{
+    return m_match_value;
+}
+
+void AttributeFilter::setMatchValue(AnyPtr match_value)
+{
+    m_match_value = match_value;
+}
+
+bool AttributeFilter::isMatching(const FilterableObject* const filtered_object) const
+{
+    if(!filtered_object) {
+        LoggerE("Invalid object: NULL!");
+        throw common::InvalidValuesException("Invalid object");
+    }
+
+    return filtered_object->isMatchingAttribute(m_attribute_name, m_match_flag,
+            m_match_value);
+}
+
+} // Tizen
+} // DeviceAPI
diff --git a/src/messaging/MsgCommon/AttributeFilter.h b/src/messaging/MsgCommon/AttributeFilter.h
new file mode 100644 (file)
index 0000000..4930d29
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef __TIZEN_TIZEN_ATTRIBUTE_FILTER_H__
+#define __TIZEN_TIZEN_ATTRIBUTE_FILTER_H__
+
+#include "AbstractFilter.h"
+#include "Any.h"
+#include <string>
+
+namespace extension {
+namespace tizen {
+
+class AttributeFilter;
+typedef std::shared_ptr<AttributeFilter> AttributeFilterPtr;
+
+class AttributeFilter: public AbstractFilter {
+public:
+    AttributeFilter(const std::string &attribute_name);
+    virtual ~AttributeFilter();
+
+    std::string getAttributeName() const;
+    void setAttributeName(const std::string &attribute_name);
+    FilterMatchFlag getMatchFlag() const;
+    void setMatchFlag(FilterMatchFlag match_flag);
+    AnyPtr getMatchValue() const;
+    void setMatchValue(AnyPtr match_value);
+
+    virtual bool isMatching(const FilterableObject* const filtered_object) const;
+private:
+    std::string m_attribute_name;
+    FilterMatchFlag m_match_flag;
+    AnyPtr m_match_value;
+};
+
+} // Tizen
+} // DeviceAPI
+
+#endif // __TIZEN_TIZEN_ABSTRACT_FILTER_H__
diff --git a/src/messaging/MsgCommon/AttributeRangeFilter.cpp b/src/messaging/MsgCommon/AttributeRangeFilter.cpp
new file mode 100644 (file)
index 0000000..6a754c5
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "AttributeRangeFilter.h"
+#include "common/platform_exception.h"
+#include "common/logger.h"
+
+namespace extension {
+namespace tizen {
+
+AttributeRangeFilter::AttributeRangeFilter(const std::string &attribute_name) :
+        m_attribute_name(attribute_name)
+{
+    m_filter_type = ATTRIBUTE_RANGE_FILTER;
+}
+
+AttributeRangeFilter::~AttributeRangeFilter()
+{
+
+}
+
+std::string AttributeRangeFilter::getAttributeName() const
+{
+    return m_attribute_name;
+}
+
+void AttributeRangeFilter::setAttributeName(const std::string &attribute_name)
+{
+    m_attribute_name = attribute_name;
+}
+
+
+AnyPtr AttributeRangeFilter::getInitialValue() const
+{
+    return m_initial_value;
+}
+
+void AttributeRangeFilter::setInitialValue(AnyPtr initial_value)
+{
+    m_initial_value = initial_value;
+}
+
+AnyPtr AttributeRangeFilter::getEndValue() const
+{
+    return m_end_value;
+}
+
+void AttributeRangeFilter::setEndValue(AnyPtr end_value)
+{
+    m_end_value = end_value;
+}
+
+bool AttributeRangeFilter::isMatching(const FilterableObject* const filtered_object) const
+{
+    if(!filtered_object) {
+        LoggerE("Invalid object: NULL!");
+        throw common::InvalidValuesException("Invalid object");
+    }
+
+    return filtered_object->isMatchingAttributeRange(m_attribute_name, m_initial_value,
+            m_end_value);
+}
+
+} // Tizen
+} // DeviceAPI
diff --git a/src/messaging/MsgCommon/AttributeRangeFilter.h b/src/messaging/MsgCommon/AttributeRangeFilter.h
new file mode 100644 (file)
index 0000000..0f8a1d3
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef __TIZEN_TIZEN_ATTRIBUTE_RANGE_FILTER_H__
+#define __TIZEN_TIZEN_ATTRIBUTE_RANGE_FILTER_H__
+
+#include "AbstractFilter.h"
+#include "Any.h"
+#include <string>
+
+namespace extension {
+namespace tizen {
+
+class AttributeRangeFilter;
+typedef std::shared_ptr<AttributeRangeFilter> AttributeRangeFilterPtr;
+
+class AttributeRangeFilter: public AbstractFilter {
+public:
+    AttributeRangeFilter(const std::string &attribute_name);
+    virtual ~AttributeRangeFilter();
+
+    std::string getAttributeName() const;
+    void setAttributeName(const std::string &attribute_name);
+
+    AnyPtr getInitialValue() const;
+    void setInitialValue(AnyPtr initial_value);
+
+    AnyPtr getEndValue() const;
+    void setEndValue(AnyPtr end_value);
+
+    virtual bool isMatching(const FilterableObject* const filtered_object) const;
+private:
+    std::string m_attribute_name;
+    AnyPtr m_initial_value;
+    AnyPtr m_end_value;
+};
+
+} // Tizen
+} // DeviceAPI
+
+#endif // __TIZEN_TIZEN_ATTRIBUTE_RANGE_FILTER_H__
diff --git a/src/messaging/MsgCommon/CompositeFilter.cpp b/src/messaging/MsgCommon/CompositeFilter.cpp
new file mode 100644 (file)
index 0000000..1c4fa4e
--- /dev/null
@@ -0,0 +1,132 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file        CompositeFilter.cpp
+ */
+
+#include "CompositeFilter.h"
+#include "common/platform_exception.h"
+//#include <GlobalContextManager.h>
+#include "common/logger.h"
+
+namespace extension {
+namespace tizen {
+
+CompositeFilter::CompositeFilter(CompositeFilterType type):
+        AbstractFilter(COMPOSITE_FILTER),
+        m_type(type)
+//        m_context(NULL)
+{
+}
+
+CompositeFilter::~CompositeFilter()
+{
+}
+
+CompositeFilterType CompositeFilter::getType() const
+{
+    return m_type;
+}
+
+void CompositeFilter::setType(CompositeFilterType type)
+{
+    m_type = type;
+}
+
+//JSContextRef CompositeFilter::getContext() const
+//{
+//    return m_context;
+//}
+
+const AbstractFilterPtrVector& CompositeFilter::getFilters() const
+{
+    return m_filters;
+}
+
+//void CompositeFilter::setFilters(const AbstractFilterPtrVector &filters)
+//{
+//    if (Common::GlobalContextManager::getInstance()->isAliveGlobalContext(
+//            m_context) && m_js_filters) {
+//        *m_js_filters = filters;
+//    }
+//    m_filters = filters;
+//}
+//
+//JSFilterArray CompositeFilter::getJSFilters(JSContextRef global_ctx)
+//{
+//    if (!m_context && !global_ctx) {
+//        LOGE("Context is not set");
+//        throw Common::UnknownException("Context is not set");
+//    }
+//    else if (!m_context && global_ctx) {
+//        m_context = global_ctx;
+//    }
+//
+//    if (!Common::GlobalContextManager::getInstance()->isAliveGlobalContext(
+//            m_context)) {
+//        LOGE("Context is not alive");
+//        throw Common::UnknownException("Context is not alive");
+//    }
+//    else if (!m_js_filters) {
+//        m_js_filters = std::shared_ptr<JSFilterArray>(new JSFilterArray(
+//                m_context));
+//        *m_js_filters = m_filters;
+//        m_filters.clear();
+//    }
+//    return *m_js_filters;
+//}
+
+
+bool CompositeFilter::isMatching(const FilterableObject* const filtered_object) const
+{
+    if(!filtered_object) {
+        LoggerE("Invalid object: NULL!");
+        throw common::InvalidValuesException("Invalid object");
+    }
+
+    bool composite_result = false;
+
+    const AbstractFilterPtrVector src_filters = getFilters();
+    if(src_filters.empty()) {
+        //No filters present -> object match composite filter
+        composite_result = true;
+    }
+    else {
+        AbstractFilterPtrVector::const_iterator it = src_filters.begin();
+        AbstractFilterPtrVector::const_iterator end_it = src_filters.end();
+        for(;it != end_it; it++) {
+
+            const bool last_result = (*it)->isMatching(filtered_object);
+            if(INTERSECTION == m_type) {
+                composite_result = last_result;
+                if(!last_result) {  //First false result causes whole composite
+                    break;                  //filter to be false -> object does not match
+                }
+            } else if(UNION == m_type && last_result) { //First true result causes
+                composite_result = true;                    //composite filter to be
+                break;                                      //true -> object match
+            }
+        }
+    }
+
+    return composite_result;
+}
+
+
+} // Tizen
+} // DeviceAPI
diff --git a/src/messaging/MsgCommon/CompositeFilter.h b/src/messaging/MsgCommon/CompositeFilter.h
new file mode 100644 (file)
index 0000000..09741b1
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file        CompositeFilter.h
+ */
+
+#ifndef __TIZEN_TIZEN_COMPOSITE_FILTER_H__
+#define __TIZEN_TIZEN_COMPOSITE_FILTER_H__
+
+#include "AbstractFilter.h"
+//#include <JSArray.h>
+
+namespace extension {
+namespace tizen {
+
+enum CompositeFilterType {
+    UNION,
+    INTERSECTION
+};
+
+class CompositeFilter;
+typedef std::shared_ptr<CompositeFilter> CompositeFilterPtr;
+
+class CompositeFilter: public AbstractFilter {
+public:
+    CompositeFilter(CompositeFilterType type);
+    virtual ~CompositeFilter();
+
+    CompositeFilterType getType() const;
+    void setType(CompositeFilterType type);
+    const AbstractFilterPtrVector& getFilters() const;
+    void setFilters(const AbstractFilterPtrVector &filter);
+//    JSFilterArray getJSFilters(JSContextRef ctx);
+//    JSContextRef getContext() const;
+
+    virtual bool isMatching(const FilterableObject* const filtered_object) const;
+private:
+    CompositeFilterType m_type;
+    AbstractFilterPtrVector m_filters;
+//    JSContextRef m_context;
+//    std::shared_ptr<JSFilterArray> m_js_filters;
+
+};
+
+} //Tizen
+} //DeviceAPI
+
+#endif // __TIZEN_TIZEN_COMPOSITE_FILTER_H__
diff --git a/src/messaging/MsgCommon/FilterIterator.cpp b/src/messaging/MsgCommon/FilterIterator.cpp
new file mode 100644 (file)
index 0000000..2310e7f
--- /dev/null
@@ -0,0 +1,179 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "FilterIterator.h"
+#include "common/platform_exception.h"
+#include "common/logger.h"
+
+using namespace common;
+
+namespace extension {
+namespace tizen {
+
+FilterIterator::FilterIterator(AbstractFilterPtr filter) :
+        m_root_filter(filter),
+        m_current_state(FIS_NOT_VALID)
+{
+    if(!m_root_filter) {
+        LoggerE("Cannot create FilterIterator for NULL filter");
+        throw UnknownException("filter is NULL");
+    }
+
+    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 (cfilter.filter->getFilters().size() - 1) == cfilter.cur_sub_filter_index;
+}
+
+void FilterIterator::operator++(int)
+{
+    this->operator++();
+}
+
+void FilterIterator::operator++()
+{
+    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()
+{
+    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()
+{
+    m_current_state = FIS_END;
+    m_current_filter = AbstractFilterPtr();
+}
+
+void FilterIterator::goToNext(AbstractFilterPtr next)
+{
+    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
diff --git a/src/messaging/MsgCommon/FilterIterator.h b/src/messaging/MsgCommon/FilterIterator.h
new file mode 100644 (file)
index 0000000..c3842bb
--- /dev/null
@@ -0,0 +1,102 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#ifndef __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)
+        {
+        }
+
+        CompositeIterState(const CompositeIterState& other) :
+                filter(other.filter),
+                cur_sub_filter_index(other.cur_sub_filter_index)
+        {
+        }
+
+        CompositeFilterPtr filter;
+        int cur_sub_filter_index;
+    };
+
+    std::stack<CompositeIterState> m_composite_stack;
+};
+
+} // Tizen
+} // DeviceAPI
+
+#endif // __TIZEN_TIZEN_FILTER_ITERATOR_H__
diff --git a/src/messaging/MsgCommon/SortMode.cpp b/src/messaging/MsgCommon/SortMode.cpp
new file mode 100644 (file)
index 0000000..fd4d6f8
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#include "SortMode.h"
+
+namespace extension {
+namespace tizen {
+
+SortMode::SortMode(const std::string &attribute_name, SortModeOrder order) :
+        m_attribute_name(attribute_name),
+        m_order(order)
+{
+
+}
+
+SortMode::~SortMode()
+{
+
+}
+
+std::string SortMode::getAttributeName() const
+{
+    return m_attribute_name;
+}
+
+void SortMode::setAttributeName(const std::string &attribute_name)
+{
+    m_attribute_name = attribute_name;
+}
+
+SortModeOrder SortMode::getOrder() const
+{
+    return m_order;
+}
+
+void SortMode::setOrder(SortModeOrder order)
+{
+    m_order = order;
+}
+
+} // Tizen
+} // DeviceAPI
diff --git a/src/messaging/MsgCommon/SortMode.h b/src/messaging/MsgCommon/SortMode.h
new file mode 100644 (file)
index 0000000..fd0b200
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef __TIZEN_TIZEN_SORT_MODE_H__
+#define __TIZEN_TIZEN_SORT_MODE_H__
+
+#include <memory>
+#include <string>
+
+namespace extension {
+namespace tizen {
+
+class SortMode;
+typedef std::shared_ptr<SortMode> SortModePtr;
+
+enum SortModeOrder {
+    ASC,
+    DESC
+};
+
+class SortMode {
+public:
+    SortMode(const std::string &attribute_name, SortModeOrder order);
+    virtual ~SortMode();
+
+    std::string getAttributeName() const;
+    void setAttributeName(const std::string &attribute_name);
+    SortModeOrder getOrder() const;
+    void setOrder(SortModeOrder order);
+
+private:
+    std::string m_attribute_name;
+    SortModeOrder m_order;
+};
+
+} // Tizen
+} // DeviceAPI
+
+#endif // __TIZEN_TIZEN_SORT_MODE_H__
index f9e65354921dc5f37da5fd10e595888d05da9f6c..280837f3cff2a98e276b0f819b257de11a86b9ac 100644 (file)
@@ -1494,94 +1494,94 @@ const std::string SUBJECT = MESSAGE_ATTRIBUTE_SUBJECT;
 
 } //namespace MESSAGE_FILTER_ATTRIBUTE
 
-//bool Message::isMatchingAttribute(const std::string& attribute_name,
-//            const FilterMatchFlag match_flag,
-//            AnyPtr match_value) const
-//{
-//    LoggerD("Entered");
-//    auto key = match_value->toString();
-//    LoggerD("attribute_name:%s match_flag:%d matchValue:%s", attribute_name.c_str(),
-//            match_flag, key.c_str());
-//
-//    using namespace MESSAGE_FILTER_ATTRIBUTE;
-//
-//    if (ID == attribute_name) {
-//        return FilterUtils::isStringMatching(key, std::to_string(getId()),
-//                match_flag);
-//    }
-//    else if (SERVICE_ID == attribute_name) {
-//        if(is_service_is_set()) {
-//            return FilterUtils::isStringMatching(key, std::to_string(getServiceId()),
-//                    match_flag);
-//        }
-//    }
-//    else if (FOLDER_ID == attribute_name) {
-//        return FilterUtils::isStringMatching(key, std::to_string(getFolderId()),
-//                match_flag);
-//    }
-//    else if (TYPE == attribute_name) {
-//        const std::string msgTypeStr = MessagingUtil::messageTypeToString(getType());
-//        return FilterUtils::isStringMatching(key, msgTypeStr, match_flag);
-//    }
-//    else if (FROM == attribute_name) {
-//        return FilterUtils::isStringMatching(key, getFrom() , match_flag);
-//    }
-//    else if (TO == attribute_name) {
-//        return FilterUtils::isAnyStringMatching(key, getTO(), match_flag);
-//    }
-//    else if (CC == attribute_name) {
-//        return FilterUtils::isAnyStringMatching(key, getCC(), match_flag);
-//    }
-//    else if (BCC == attribute_name) {
-//        return FilterUtils::isAnyStringMatching(key, getBCC(), match_flag);
-//    }
-//    else if (BODY_PLAIN_BODY == attribute_name) {
-//        if(getBody()) {
-//            return FilterUtils::isStringMatching(key, getBody()->getPlainBody(),
-//                    match_flag);
-//        }
-//    }
-//    else if (IS_READ == attribute_name) {
-//        return FilterUtils::isStringMatching(key, FilterUtils::boolToString(getIsRead()),
-//                match_flag);
-//    }
-//    else if (HAS_ATTACHMENT == attribute_name) {
-//        return FilterUtils::isStringMatching(key,
-//                FilterUtils::boolToString(getHasAttachment()),
-//                match_flag);
-//    }
-//    else if (IS_HIGH_PRIORITY == attribute_name) {
-//        return FilterUtils::isStringMatching(key,
-//                FilterUtils::boolToString(getIsHighPriority()),
-//                match_flag);
-//    }
-//    else if (SUBJECT == attribute_name) {
-//        return FilterUtils::isStringMatching(key, getSubject(), match_flag);
-//    }
-//    else {
-//        LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str());
-//    }
-//
-//    return false;
-//}
+bool Message::isMatchingAttribute(const std::string& attribute_name,
+            const FilterMatchFlag match_flag,
+            AnyPtr match_value) const
+{
+    LoggerD("Entered");
+    auto key = match_value->toString();
+    LoggerD("attribute_name:%s match_flag:%d matchValue:%s", attribute_name.c_str(),
+            match_flag, key.c_str());
 
-//bool Message::isMatchingAttributeRange(const std::string& attribute_name,
-//            AnyPtr initial_value,
-//            AnyPtr end_value) const
-//{
-//    LoggerD("Entered attribute_name: %s", attribute_name.c_str());
-//
-//    using namespace MESSAGE_FILTER_ATTRIBUTE;
-//    if(TIMESTAMP == attribute_name) {
-//        return FilterUtils::isTimeStampInRange(getTimestamp(), initial_value,
-//                end_value);
-//    }
-//    else {
-//        LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str());
-//    }
-//
-//    return false;
-//}
+    using namespace MESSAGE_FILTER_ATTRIBUTE;
+
+    if (ID == attribute_name) {
+        return FilterUtils::isStringMatching(key, std::to_string(getId()),
+                match_flag);
+    }
+    else if (SERVICE_ID == attribute_name) {
+        if(is_service_is_set()) {
+            return FilterUtils::isStringMatching(key, std::to_string(getServiceId()),
+                    match_flag);
+        }
+    }
+    else if (FOLDER_ID == attribute_name) {
+        return FilterUtils::isStringMatching(key, std::to_string(getFolderId()),
+                match_flag);
+    }
+    else if (TYPE == attribute_name) {
+        const std::string msgTypeStr = MessagingUtil::messageTypeToString(getType());
+        return FilterUtils::isStringMatching(key, msgTypeStr, match_flag);
+    }
+    else if (FROM == attribute_name) {
+        return FilterUtils::isStringMatching(key, getFrom() , match_flag);
+    }
+    else if (TO == attribute_name) {
+        return FilterUtils::isAnyStringMatching(key, getTO(), match_flag);
+    }
+    else if (CC == attribute_name) {
+        return FilterUtils::isAnyStringMatching(key, getCC(), match_flag);
+    }
+    else if (BCC == attribute_name) {
+        return FilterUtils::isAnyStringMatching(key, getBCC(), match_flag);
+    }
+    else if (BODY_PLAIN_BODY == attribute_name) {
+        if(getBody()) {
+            return FilterUtils::isStringMatching(key, getBody()->getPlainBody(),
+                    match_flag);
+        }
+    }
+    else if (IS_READ == attribute_name) {
+        return FilterUtils::isStringMatching(key, FilterUtils::boolToString(getIsRead()),
+                match_flag);
+    }
+    else if (HAS_ATTACHMENT == attribute_name) {
+        return FilterUtils::isStringMatching(key,
+                FilterUtils::boolToString(getHasAttachment()),
+                match_flag);
+    }
+    else if (IS_HIGH_PRIORITY == attribute_name) {
+        return FilterUtils::isStringMatching(key,
+                FilterUtils::boolToString(getIsHighPriority()),
+                match_flag);
+    }
+    else if (SUBJECT == attribute_name) {
+        return FilterUtils::isStringMatching(key, getSubject(), match_flag);
+    }
+    else {
+        LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str());
+    }
+
+    return false;
+}
+
+bool Message::isMatchingAttributeRange(const std::string& attribute_name,
+            AnyPtr initial_value,
+            AnyPtr end_value) const
+{
+    LoggerD("Entered attribute_name: %s", attribute_name.c_str());
+
+    using namespace MESSAGE_FILTER_ATTRIBUTE;
+    if(TIMESTAMP == attribute_name) {
+        return FilterUtils::isTimeStampInRange(getTimestamp(), initial_value,
+                end_value);
+    }
+    else {
+        LoggerD("attribute:%s is NOT SUPPORTED", attribute_name.c_str());
+    }
+
+    return false;
+}
 
 } //messaging
 } //extension
index bb204d3b726369dd29a145dda4de2d0639d92fc1..ae3d7f3e1cb044e96ec5ed18bb86cb241a6e0131 100644 (file)
@@ -20,6 +20,7 @@
 #include "message_attachment.h"
 #include "messaging_util.h"
 #include "message_body.h"
+#include "MsgCommon/AbstractFilter.h"
 
 namespace extension {
 namespace messaging {
@@ -37,7 +38,9 @@ enum AttachmentType {
     EXTERNAL = 0, INLINE = 1
 };
 
-class Message { //TODO : public Tizen::FilterableObject {
+using namespace tizen;
+
+class Message : public FilterableObject {
 public:
 // constructor
     Message();
@@ -65,7 +68,7 @@ public:
     int getServiceId() const;
     TelNetworkDefaultDataSubs_t getSimIndex() const;
 
-    // attributes setters (virtual because some of them can be overriden in sub classes)
+// attributes setters (virtual because some of them can be overriden in sub classes)
     virtual void setId(int id);
     virtual void setConversationId(int id);
     virtual void setFolderId(int id);
@@ -140,14 +143,15 @@ public:
     static std::shared_ptr<MessageBody> convertEmailToMessageBody(email_mail_data_t& mail);
     static AttachmentPtrVector convertEmailToMessageAttachment(email_mail_data_t& mail);
 
-//  // Tizen::FilterableObject
-//  virtual bool isMatchingAttribute(const std::string& attribute_name,
-//          const Tizen::FilterMatchFlag match_flag,
-//          Tizen::AnyPtr match_value) const;
+    // tizen::FilterableObject
+    virtual bool isMatchingAttribute(const std::string& attribute_name,
+          const FilterMatchFlag match_flag,
+          AnyPtr match_value) const;
+
+    virtual bool isMatchingAttributeRange(const std::string& attribute_name,
+          AnyPtr initial_value,
+          AnyPtr end_value) const;
 
-//  virtual bool isMatchingAttributeRange(const std::string& attribute_name,
-//          Tizen::AnyPtr initial_value,
-//          Tizen::AnyPtr end_value) const;
 protected:
     //! Message id
     int m_id;
@@ -177,7 +181,7 @@ protected:
     std::vector<std::string> m_cc;
     //! Message BlindCarbonCopy recipients (used only for email)
     std::vector<std::string> m_bcc;
-//  //! MessageBody (object containg plainBody and htmlBody for emails)
+    //! MessageBody (object containg plainBody and htmlBody for emails)
     std::shared_ptr<MessageBody> m_body;
     //! Service id
     int m_service_id;
@@ -201,6 +205,7 @@ protected:
     AttachmentPtrVector m_attachments;
     //! SIM index which indicate a sim to send message.
     TelNetworkDefaultDataSubs_t m_sim_index;
+
 private:
     static std::vector<std::string> split(const std::string& input,
             char delimiter);
index e4afa9dcbc46ad8972dd8930edbe8f14c676d9ad..a092a9fe601d14797f180f30fde30d1c7ece3561 100644 (file)
@@ -46,6 +46,8 @@
         'message_attachment.h',
         'message_body.cc',
         'message_body.h',
+        'message_callback_user_data.cc',
+        'message_callback_user_data.h',
         'DBus/Connection.cpp',
         'DBus/Connection.h',
         'DBus/EmailSignalProxy.cpp',
         #'DBus/SendProxy.h',
         'DBus/SyncProxy.cpp',
         'DBus/SyncProxy.h',
-        'message_callback_user_data.cc',
-        'message_callback_user_data.h'
+        'MsgCommon/Any.cpp',
+        'MsgCommon/Any.h',
+        'MsgCommon/AbstractFilter.cpp',
+        'MsgCommon/AbstractFilter.h',
+        'MsgCommon/SortMode.cpp',
+        'MsgCommon/SortMode.h',
+        'MsgCommon/AttributeFilter.cpp',
+        'MsgCommon/AttributeFilter.h',
+        'MsgCommon/AttributeRangeFilter.cpp',
+        'MsgCommon/AttributeRangeFilter.h',
+        'MsgCommon/CompositeFilter.cpp',
+        'MsgCommon/CompositeFilter.h',
+        'MsgCommon/FilterIterator.cpp',
+        'MsgCommon/FilterIterator.h',
       ],
       'includes': [
         '../common/pkg-config.gypi',