tizen beta release
[framework/web/wrt-commons.git] / modules / ace / engine / Subject.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 #include <dpl/log/log.h>
17 #include <dpl/foreach.h>
18
19 #include <dpl/ace/Subject.h>
20 #include <dpl/ace/Serializer.h>
21 #include <dpl/ace/NodeFactory.h>
22
23 bool Subject::matchSubject(const AttributeSet *attrSet,
24         bool &isUndetermined) const
25 {
26     bool result = true;
27     Attribute::MatchResult match = Attribute::MatchResult::MRUndetermined;
28
29     FOREACH(it, targetAttributes)
30     {
31         AttributeSet::const_iterator attr =
32             std::find_if(attrSet->begin(),
33                          attrSet->end(),
34                          AceDB::BaseAttribute::UnaryPredicate(&(*it)));
35         if (attr == attrSet->end()) {
36             LogError("Cannot find attribute value for " << *(it->getName()));
37             Assert(false &&
38                    "Attribute for subject hasn't been found."
39                    "It shoud not happen. This attribute should be undetermined,"
40                    "not missing");
41             result = false; //According to BONDI 1.0 for signle subject all attributes must match
42             isUndetermined = true;
43             break;
44         }
45
46         match = it->matchAttributes(&(*(*attr)));
47
48         if (match == Attribute::MatchResult::MRUndetermined) {
49             result = false;
50             isUndetermined = true;
51             ///          LogError("Subject doesn match and UNDETERMINED");
52             break; //According to BONDI 1.0 for signle subject all attributes must match
53         } else if (match == Attribute::MatchResult::MRFalse) {
54             result = false;
55             //            LogError("Subject doesn match and DETERMINED");
56             break; //According to BONDI 1.0 for signle subject all attributes must match
57         }
58     }
59
60     return result;
61 }
62
63 const std::list<Attribute>& Subject::getTargetAttributes() const
64 {
65     return targetAttributes;
66 }
67
68 Subject::Subject(std::istream& is)
69 {
70     Serializer* serializer = Serializer::getInstance();
71
72     subjectId = serializer->deserializeString(is);
73     targetAttributes = serializer->deserializeListAttributes(is);
74 }
75
76 bool Subject::serialize (std::ostream& os)
77 {
78     Serializer* serializer = Serializer::getInstance();
79
80     serializer->serializeString(os, subjectId);
81     serializer->serializeListAttributes(os, targetAttributes);
82
83     return 0;
84 }