2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <dpl/log/log.h>
17 #include <dpl/foreach.h>
19 #include <dpl/ace/Subject.h>
20 #include <dpl/ace/Serializer.h>
21 #include <dpl/ace/NodeFactory.h>
23 bool Subject::matchSubject(const AttributeSet *attrSet,
24 bool &isUndetermined) const
27 Attribute::MatchResult match = Attribute::MatchResult::MRUndetermined;
29 FOREACH(it, targetAttributes)
31 AttributeSet::const_iterator attr =
32 std::find_if(attrSet->begin(),
34 AceDB::BaseAttribute::UnaryPredicate(&(*it)));
35 if (attr == attrSet->end()) {
36 LogError("Cannot find attribute value for " << *(it->getName()));
38 "Attribute for subject hasn't been found."
39 "It shoud not happen. This attribute should be undetermined,"
41 result = false; //According to BONDI 1.0 for signle subject all attributes must match
42 isUndetermined = true;
46 match = it->matchAttributes(&(*(*attr)));
48 if (match == Attribute::MatchResult::MRUndetermined) {
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) {
55 // LogError("Subject doesn match and DETERMINED");
56 break; //According to BONDI 1.0 for signle subject all attributes must match
63 const std::list<Attribute>& Subject::getTargetAttributes() const
65 return targetAttributes;
68 Subject::Subject(std::istream& is)
70 Serializer* serializer = Serializer::getInstance();
72 subjectId = serializer->deserializeString(is);
73 targetAttributes = serializer->deserializeListAttributes(is);
76 bool Subject::serialize (std::ostream& os)
78 Serializer* serializer = Serializer::getInstance();
80 serializer->serializeString(os, subjectId);
81 serializer->serializeListAttributes(os, targetAttributes);