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 * This file contains the definition of feature dao class.
19 * @file widget_dao.cpp
20 * @author Jaroslaw Osmanski (j.osmanski@samsung.com)
21 * @author Pawel Sikorski (p.sikorski@samsung.com)
23 * @brief This file contains the definition of feature configuration.
26 #include <dpl/wrt-dao-rw/feature_dao.h>
27 #include <dpl/foreach.h>
28 #include <dpl/db/orm.h>
29 #include <orm_generator_wrt.h>
30 #include <dpl/wrt-dao-ro/webruntime_database.h>
33 namespace FeatureDAO {
35 FeatureHandle RegisterFeature(const PluginMetafileData::Feature &feature,
36 const DbPluginHandle pluginHandle)
40 LogDebug("Registering Feature " << feature.m_name);
41 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
43 if (FeatureDAOReadOnly::isFeatureInstalled(feature.m_name)) {
44 LogError(" >> Feature " << feature.m_name <<
45 " is already registered.");
50 using namespace DPL::DB::ORM;
51 using namespace DPL::DB::ORM::wrt;
55 LogInfo(" |-- Registering feature " << feature.m_name);
57 FeaturesList::Row row;
58 row.Set_FeatureName(DPL::FromUTF8String(feature.m_name));
59 row.Set_PluginPropertiesId(pluginHandle);
61 WRT_DB_INSERT(insert, FeaturesList, &WrtDatabase::interface())
66 FeatureHandle featureHandle =
67 FeatureDAOReadOnly(feature.m_name).GetFeatureHandle();
69 //register device capabilities
70 // Device Capabilities is unused in current version
71 FOREACH(itdev, feature.m_deviceCapabilities)
75 if (FeatureDAOReadOnly::isDeviceCapabilityInstalled(*itdev)) {
76 LogInfo(" | |--DeviceCap " << *itdev <<
77 " already installed!");
79 WRT_DB_SELECT(select, DeviceCapabilities, &WrtDatabase::interface())
81 select->Where(Equals<DeviceCapabilities::DeviceCapName>(
82 DPL::FromUTF8String(*itdev)));
85 select->GetSingleValue<DeviceCapabilities::DeviceCapID>();
87 LogInfo(" | |--Register DeviceCap: " << *itdev);
89 DeviceCapabilities::Row row;
90 row.Set_DeviceCapName(DPL::FromUTF8String(*itdev));
92 WRT_DB_INSERT(insert, DeviceCapabilities, &WrtDatabase::interface())
94 deviceCapID = insert->Execute();
97 FeatureDeviceCapProxy::Row row;
98 row.Set_FeatureUUID(featureHandle);
99 row.Set_DeviceCapID(deviceCapID);
101 WRT_DB_INSERT(insert, FeatureDeviceCapProxy, &WrtDatabase::interface())
106 transaction.Commit();
108 return featureHandle;
110 Catch(DPL::DB::SqlConnection::Exception::Base){
111 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
112 "Failure during Registering Feature");
116 void UnregisterFeature(FeatureHandle featureHandle)
120 LogDebug("Unregistering Feature " << featureHandle);
121 DPL::DB::ORM::wrt::ScopedTransaction transaction(
122 &WrtDatabase::interface());
124 if (FeatureDAOReadOnly::isFeatureInstalled(featureHandle)) {
125 LogError("Feature handle is invalid");
129 using namespace DPL::DB::ORM;
130 using namespace DPL::DB::ORM::wrt;
132 // Unregister DeviceCapabilities
133 FeatureDAOReadOnly::DeviceCapabilitiesList capabilitiesList =
134 FeatureDAOReadOnly(featureHandle).GetDeviceCapabilities();
136 FOREACH(it, capabilitiesList) {
137 WRT_DB_DELETE(del, DeviceCapabilities, &WrtDatabase::interface())
139 Equals<DeviceCapabilities::DeviceCapName>(
140 DPL::FromUTF8String(*it)));
144 // Unregister Feature
145 WRT_DB_DELETE(del, FeaturesList, &WrtDatabase::interface())
146 del->Where(Equals<FeaturesList::FeatureUUID>(featureHandle));
148 transaction.Commit();
152 Catch(DPL::DB::SqlConnection::Exception::Base){
153 ReThrowMsg(FeatureDAOReadOnly::Exception::DatabaseError,
154 "Fail to unregister Feature");
159 } // namespace FeatureDAO