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.
17 * @file feature_dao_read_only.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
20 * @brief This file contains the implementation of feature dao read only
23 #include <dpl/wrt-dao-ro/feature_dao_read_only.h>
25 #include <dpl/log/log.h>
26 #include <dpl/foreach.h>
27 #include <dpl/db/orm.h>
28 #include <orm_generator_wrt.h>
29 #include <dpl/wrt-dao-ro/webruntime_database.h>
30 #include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
34 FeatureDAOReadOnly::FeatureDAOReadOnly(FeatureHandle featureHandle) :
35 m_featureHandle(featureHandle)
37 if (!isFeatureInstalled(m_featureHandle)) {
38 std::ostringstream exc;
39 exc << "Feature " << m_featureHandle << " not installed.";
41 ThrowMsg(FeatureDAOReadOnly::Exception::FeatureNotExist, exc.str());
45 FeatureDAOReadOnly::FeatureDAOReadOnly(const std::string &featureName)
47 LogDebug("FeatureDAOReadOnly ( " << featureName << " )");
49 using namespace DPL::DB::ORM;
50 using namespace DPL::DB::ORM::wrt;
51 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
52 select->Where(Equals<FeaturesList::FeatureName>(
53 DPL::FromUTF8String(featureName)));
55 m_featureHandle = select->GetSingleValue<FeaturesList::FeatureUUID>();
56 LogDebug(" >> FeatureHandle retrieved: " << m_featureHandle);
58 Catch(DPL::DB::SqlConnection::Exception::Base){
59 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
60 "Failure during creating FeatureDAOReadOnly");
64 #define GET_PLUGIN_DATA(func) \
66 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface()); \
67 LogDebug(# func << ". FeatureHandle: " << m_featureHandle); \
68 std::string ret = PluginDAOReadOnly(GetPluginHandle()).func(); \
69 transaction.Commit(); \
72 Catch(DPL::DB::SqlConnection::Exception::Base) { \
73 std::ostringstream failure("Failure during "); \
75 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError, \
79 std::string FeatureDAOReadOnly::GetInstallURI() const
81 GET_PLUGIN_DATA(getInstallURI)
84 std::string FeatureDAOReadOnly::GetKeyCn() const
86 GET_PLUGIN_DATA(getKeyCn)
89 std::string FeatureDAOReadOnly::GetRootKey() const
91 GET_PLUGIN_DATA(getRootKey)
94 std::string FeatureDAOReadOnly::GetRootKeyFingerprint() const
96 GET_PLUGIN_DATA(getRootKeyFingerprint)
99 std::string FeatureDAOReadOnly::GetLibraryPath() const
101 GET_PLUGIN_DATA(getLibraryPath)
104 std::string FeatureDAOReadOnly::GetLibraryName() const
106 GET_PLUGIN_DATA(getLibraryName)
109 #undef GET_PLUGIN_DATA
111 FeatureHandle FeatureDAOReadOnly::GetFeatureHandle() const
113 return m_featureHandle;
116 std::string FeatureDAOReadOnly::GetName() const
118 LogDebug("Getting Feature Name. Handle: " << m_featureHandle);
120 using namespace DPL::DB::ORM;
121 using namespace DPL::DB::ORM::wrt;
122 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
123 select->Where(Equals<FeaturesList::FeatureUUID>(m_featureHandle));
125 std::string ret = DPL::ToUTF8String(
126 select->GetSingleValue< FeaturesList::FeatureName>());
128 LogDebug(" >> Feature name: " << ret);
131 Catch(DPL::DB::SqlConnection::Exception::Base){
132 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
133 "Failure during getting GetName");
137 DbPluginHandle FeatureDAOReadOnly::GetPluginHandle() const
139 LogDebug("Getting Plugin handle. FHandle: " << m_featureHandle);
141 using namespace DPL::DB::ORM;
142 using namespace DPL::DB::ORM::wrt;
143 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
144 select->Where(Equals<FeaturesList::FeatureUUID>(m_featureHandle));
146 DbPluginHandle pluginHandle =
147 select->GetSingleValue< FeaturesList::PluginPropertiesId>();
149 LogDebug(" >> Plugin Handle: " << pluginHandle);
152 Catch(DPL::DB::SqlConnection::Exception::Base){
153 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
154 "Failure during getting Plugin Handle");
158 FeatureHandleList FeatureDAOReadOnly::GetHandleList()
160 LogDebug("Getting FeatureHandle list.");
162 using namespace DPL::DB::ORM;
163 using namespace DPL::DB::ORM::wrt;
164 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
166 FeatureHandleList ret =
167 select->GetValueList<FeaturesList::FeatureUUID>();
169 std::ostringstream handles;
171 handles << *it << " ";
172 LogDebug(" >> FeatureHandle list retrieved: (" << handles << ")");
176 Catch(DPL::DB::SqlConnection::Exception::Base){
177 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
178 "Failure during getting FeatureHandle list");
182 bool FeatureDAOReadOnly::isFeatureInstalled(const std::string &featureName)
184 LogDebug("Check if Feature is installed. Name: " << featureName);
186 using namespace DPL::DB::ORM;
187 using namespace DPL::DB::ORM::wrt;
188 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
189 select->Where(Equals<FeaturesList::FeatureName>(
190 DPL::FromUTF8String(featureName)));
192 FeaturesList::Select::RowList rows = select->GetRowList();
194 bool flag = !rows.empty();
195 LogDebug(" >> Feature " << featureName <<
196 (flag ? " found." : " not found."));
200 Catch(DPL::DB::SqlConnection::Exception::Base) {
201 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
202 "Failure during checking if Feature is installed");
206 bool FeatureDAOReadOnly::isFeatureInstalled(FeatureHandle handle)
208 LogDebug("Check if Feature is installed. Handle: " << handle);
211 using namespace DPL::DB::ORM;
212 using namespace DPL::DB::ORM::wrt;
213 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
214 select->Where(Equals<FeaturesList::FeatureUUID>(handle));
216 FeaturesList::Select::RowList rows = select->GetRowList();
218 bool flag = !rows.empty();
219 LogDebug(" >> Feature " << handle <<
220 (flag ? " found." : " not found."));
224 Catch(DPL::DB::SqlConnection::Exception::Base){
225 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
226 "Failure during checking if Feature is installed");
230 bool FeatureDAOReadOnly::isDeviceCapabilityInstalled(
231 const std::string &deviceCapName)
233 LogDebug("Check if DeviceCap is installed. Name: " << deviceCapName);
235 using namespace DPL::DB::ORM;
236 using namespace DPL::DB::ORM::wrt;
237 WRT_DB_SELECT(select, DeviceCapabilities, &WrtDatabase::interface())
238 select->Where(Equals<DeviceCapabilities::DeviceCapName>(
239 DPL::FromUTF8String(deviceCapName)));
241 DeviceCapabilities::Select::RowList rows = select->GetRowList();
243 bool flag = !rows.empty();
244 LogDebug(" >> Device Cap " << deviceCapName <<
245 (flag ? "found." : "not found."));
249 Catch(DPL::DB::SqlConnection::Exception::Base){
250 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
251 "Failure during checking if DeviceCap is installed");
255 FeatureDAOReadOnly::DeviceCapabilitiesList
256 FeatureDAOReadOnly::GetDeviceCapabilities() const
259 LogDebug("Get DeviceCap. FeatureHandle: " << m_featureHandle);
260 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
262 using namespace DPL::DB::ORM;
263 using namespace DPL::DB::ORM::wrt;
264 WRT_DB_SELECT(selectDevCP, FeatureDeviceCapProxy, &WrtDatabase::interface())
265 selectDevCP->Where(Equals<FeatureDeviceCapProxy::FeatureUUID>(
268 DeviceCapabilitiesList devCap;
270 std::list<int> deviceIDs =
271 selectDevCP->GetValueList<FeatureDeviceCapProxy::DeviceCapID>();
272 FOREACH(devCId, deviceIDs)
274 WRT_DB_SELECT(selectDevC, DeviceCapabilities, &WrtDatabase::interface())
275 selectDevC->Where(Equals<DeviceCapabilities::DeviceCapID>(*devCId));
277 DPL::String devNames =
278 selectDevC->GetSingleValue<DeviceCapabilities::DeviceCapName>();
280 devCap.insert(DPL::ToUTF8String(devNames));
283 transaction.Commit();
286 Catch(DPL::DB::SqlConnection::Exception::Base){
287 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
288 "Failure during getting DeviceCapabilities names");
292 FeatureHandleListPtr FeatureDAOReadOnly::GetFeatureHandleListForPlugin(
293 DbPluginHandle pluginHandle)
295 LogDebug("Getting FeatureHandle list for pluginHandle: " << pluginHandle);
297 using namespace DPL::DB::ORM;
298 using namespace DPL::DB::ORM::wrt;
300 WRT_DB_SELECT(select, FeaturesList, &WrtDatabase::interface())
301 select->Where(Equals<FeaturesList::PluginPropertiesId>(pluginHandle));
303 FeatureHandleListPtr handles(new FeatureHandleList);
304 FeatureHandleList ret =
305 select->GetValueList<FeaturesList::FeatureUUID>();
309 LogDebug("feature handle: " << *it);
310 handles->push_back(*it);
315 Catch(DPL::DB::SqlConnection::Exception::Base){
317 FeatureDAOReadOnly::Exception::DatabaseError,
318 "Failure during getting FeatureHandle Set for plugin handle");