Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules / widget_interface_dao / include / wrt-commons / widget-interface-dao / widget_interface_dao.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @author      Lukasz Marek (l.marek@samsung.com)
18  * @version     0.1
19  * @brief
20  */
21
22 #ifndef _WIDGET_INTERFACE_DAO_H_
23 #define _WIDGET_INTERFACE_DAO_H_
24
25 #include <string>
26 #include <boost/optional.hpp>
27 #include <dpl/wrt-dao-ro/common_dao_types.h>
28 #include <dpl/exception.h>
29 #include <sqlite3.h>
30
31 namespace WidgetInterfaceDB {
32
33 class WidgetInterfaceDAO : public WrtDB::SQLiteDAOBase
34 {
35   public:
36
37     /**
38      * WidgetInterfaceDAO Exception classes
39      */
40     class Exception
41     {
42       public:
43         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
44         DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
45         DECLARE_EXCEPTION_TYPE(Base, LocalStorageValueNoModifableException)
46         DECLARE_EXCEPTION_TYPE(Base, InvalidArgumentException)
47     };
48     WidgetInterfaceDAO(WrtDB::DbWidgetHandle widgetHandle);
49     virtual ~WidgetInterfaceDAO();
50
51     static std::string databaseFileName(WrtDB::DbWidgetHandle widgetHandle);
52     void setItem(const std::string& key,
53                  const std::string& value,
54                  bool readOnly,
55                  bool fromConfigXml);
56     void setItem(const std::string& key,
57                  const std::string& value,
58                  bool readOnly);
59     void removeItem(const std::string& key);
60     boost::optional<std::string> getValue(const std::string& key);
61     void clear(bool removeReadOnly);
62     size_t getStorageSize();
63     std::string getKeyByIndex(size_t index);
64
65   private:
66     bool isReadOnly(const std::string& key);
67 };
68 typedef std::unique_ptr<WidgetInterfaceDAO> WidgetInterfaceDAOPtr;
69 }
70 #endif //_WIDGET_INTERFACE_DAO_H_