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 * @author Lukasz Marek (l.marek@samsung.com)
22 #include "WidgetInterface.h"
24 #include <dpl/exception.h>
25 #include <dpl/log/log.h>
26 #include <dpl/optional.h>
27 #include <dpl/string.h>
28 #include <wrt-commons/widget-interface-dao/widget_interface_dao.h>
29 #include <Commons/Exception.h>
31 namespace WrtDeviceApis {
32 using namespace WidgetInterfaceDB;
34 WidgetInterfaceObject::WidgetInterfaceObject(int widgetHandle)
38 m_dao.reset(new WidgetInterfaceDAO(widgetHandle));
40 Catch(WidgetInterfaceDAO::Exception::DatabaseError)
42 ReThrow(Commons::PlatformException);
46 WidgetInterfaceObject::~WidgetInterfaceObject()
51 void WidgetInterfaceObject::setItem(const std::string& key,
52 const std::string& value,
57 m_dao->setItem(key, value, readOnly);
59 Catch(WidgetInterfaceDAO::Exception::DatabaseError)
61 ReThrow(Commons::PlatformException);
63 Catch(WidgetInterfaceDAO::Exception::LocalStorageValueNoModifableException)
65 LogError("Cannot delete item. Item is readonly");
66 ReThrow(Commons::LocalStorageValueNoModifableException);
70 void WidgetInterfaceObject::removeItem(const std::string& key)
74 m_dao->removeItem(key);
76 Catch(WidgetInterfaceDAO::Exception::DatabaseError)
78 ReThrow(Commons::PlatformException);
80 Catch(WidgetInterfaceDAO::Exception::LocalStorageValueNoModifableException)
82 LogError("Cannot delete item. Item is readonly");
83 ReThrow(Commons::LocalStorageValueNoModifableException);
87 DPL::Optional<std::string> WidgetInterfaceObject::getValue(
88 const std::string& key) const
92 return m_dao->getValue(key);
94 Catch(WidgetInterfaceDAO::Exception::DatabaseError)
96 ReThrow(Commons::PlatformException);
100 void WidgetInterfaceObject::clear(bool removeReadOnly)
104 m_dao->clear(removeReadOnly);
106 Catch(WidgetInterfaceDAO::Exception::DatabaseError)
108 ReThrow(Commons::PlatformException);
112 size_t WidgetInterfaceObject::getStorageSize() const
116 return m_dao->getStorageSize();
118 Catch(WidgetInterfaceDAO::Exception::DatabaseError)
120 ReThrow(Commons::PlatformException);
124 std::string WidgetInterfaceObject::getKeyByIndex(size_t index) const
128 return m_dao->getKeyByIndex(index);
130 Catch(WidgetInterfaceDAO::Exception::DatabaseError)
132 ReThrow(Commons::PlatformException);
134 Catch(WidgetInterfaceDAO::Exception::InvalidArgumentException)
136 ReThrow(Commons::InvalidArgumentException);