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.
19 * @file AceDaoReadOnly.h
20 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
21 * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
26 #include <openssl/md5.h>
27 #include <dpl/assert.h>
28 #include <dpl/foreach.h>
30 #include <ace-dao-ro/AceDatabase.h>
31 #include <ace-dao-ro/AceDAOUtilities.h>
32 #include <ace-dao-ro/AceDAOReadOnly.h>
37 const char* ACE_DB_DATABASE = "/opt/dbspace/.ace.db";
38 DPL::DB::SqlConnection::Flag::Type ACE_DB_FLAGS =
39 DPL::DB::SqlConnection::Flag::UseLucene;
42 DPL::DB::ThreadDatabaseSupport AceDaoUtilities::m_databaseInterface(
43 ACE_DB_DATABASE, ACE_DB_FLAGS);
45 BaseAttribute::Type AceDaoUtilities::intToAttributeType(int val)
49 return BaseAttribute::Type::Subject;
51 return BaseAttribute::Type::Environment;
53 return BaseAttribute::Type::Resource;
55 return BaseAttribute::Type::FunctionParam;
57 return BaseAttribute::Type::WidgetParam;
60 Assert(0 && "Unknown Attribute type value");
61 return BaseAttribute::Type::Subject; //remove compilation warrning
65 int AceDaoUtilities::attributeTypeToInt(BaseAttribute::Type type)
67 // we cannot cast enum -> int because this cast will be removed from next c++ standard
69 case BaseAttribute::Type::Subject:
71 case BaseAttribute::Type::Environment:
73 case BaseAttribute::Type::Resource:
75 case BaseAttribute::Type::FunctionParam:
77 case BaseAttribute::Type::WidgetParam:
81 Assert(0 && "Unknown Attribute type!");
82 return 0; //remove compilation warrning
86 int AceDaoUtilities::preferenceToInt(PreferenceTypes p)
89 case PreferenceTypes::PREFERENCE_PERMIT:
91 case PreferenceTypes::PREFERENCE_DENY:
93 case PreferenceTypes::PREFERENCE_BLANKET_PROMPT:
95 case PreferenceTypes::PREFERENCE_SESSION_PROMPT:
97 case PreferenceTypes::PREFERENCE_ONE_SHOT_PROMPT:
105 PreferenceTypes AceDaoUtilities::intToPreference(int p)
109 return PreferenceTypes::PREFERENCE_PERMIT;
111 return PreferenceTypes::PREFERENCE_DENY;
113 return PreferenceTypes::PREFERENCE_BLANKET_PROMPT;
115 return PreferenceTypes::PREFERENCE_SESSION_PROMPT;
117 return PreferenceTypes::PREFERENCE_ONE_SHOT_PROMPT;
120 return PreferenceTypes::PREFERENCE_DEFAULT;
124 VerdictTypes AceDaoUtilities::intToVerdict(int v)
128 return VerdictTypes::VERDICT_UNKNOWN;
130 return VerdictTypes::VERDICT_DENY;
132 return VerdictTypes::VERDICT_PERMIT;
134 return VerdictTypes::VERDICT_INAPPLICABLE;
137 Assert(0 && "Cannot convert int to verdict");
138 return VerdictTypes::VERDICT_UNKNOWN; // remove compile warrning
142 int AceDaoUtilities::verdictToInt(VerdictTypes v)
145 case VerdictTypes::VERDICT_UNKNOWN:
147 case VerdictTypes::VERDICT_DENY:
149 case VerdictTypes::VERDICT_PERMIT:
151 case VerdictTypes::VERDICT_INAPPLICABLE:
155 Assert(0 && "Unknown Verdict value");
156 return -1; // remove compile warrning
160 bool AceDaoUtilities::getSubjectByUri(const std::string &uri,
161 DPL::DB::ORM::ace::AceSubject::Row &row)
163 using namespace DPL::DB::ORM;
164 using namespace DPL::DB::ORM::ace;
165 ACE_DB_SELECT(select, AceSubject, &m_databaseInterface);
166 select->Where(Equals<AceSubject::id_uri>(DPL::FromUTF8String(uri)));
167 std::list<AceSubject::Row> rows = select->GetRowList();
176 bool AceDaoUtilities::getResourceByUri(const std::string &uri,
177 DPL::DB::ORM::ace::AceDevCap::Row &row)
179 using namespace DPL::DB::ORM;
180 using namespace DPL::DB::ORM::ace;
181 ACE_DB_SELECT(select, AceDevCap, &m_databaseInterface);
182 select->Where(Equals<AceDevCap::id_uri>(DPL::FromUTF8String(uri)));
183 std::list<AceDevCap::Row> rows = select->GetRowList();