08020467f403edc32c99c4b4daa5a8b8e889d6f9
[framework/web/wrt-commons.git] / modules / widget_dao / include / dpl / wrt-dao-rw / widget_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  * This file contains the declaration of widget dao class.
18  *
19  * @file    widget_dao.h
20  * @author  Yang Jie (jie2.yang@samsung.com)
21  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
22  * @author  Pawel Sikorski (p.sikorski@samsung.com)
23  * @version 1.0
24  * @brief   This file contains the declaration of widget dao
25  */
26 #ifndef WIDGET_DAO_H
27 #define WIDGET_DAO_H
28
29 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
30 #include <list>
31 #include <string>
32 #include <sys/time.h>
33 #include <ctime>
34 #include <cstdlib>
35 #include <dpl/exception.h>
36 #include <dpl/db/orm.h>
37 #include <dpl/wrt-dao-ro/config_parser_data.h>
38 #include <dpl/wrt-dao-rw/property_dao.h>
39
40 namespace WrtDB {
41
42 class WidgetDAO : public WidgetDAOReadOnly
43 {
44   public:
45     typedef std::list<DPL::String> LanguageTagsList;
46
47     /**
48      * This is a constructor.
49      *
50      * @param[in] widgetHandle application id of widget.
51      * @param[in] widgetGUID application guid of widget.
52      */
53     WidgetDAO(DbWidgetHandle widgetHandle);
54     WidgetDAO(DPL::OptionalString widgetGUID);
55
56     /**
57      * Destructor
58      */
59     virtual ~WidgetDAO();
60
61     /**
62      * This method registers the widget information to the DB when it is installed.
63      *
64      * @see WidgetRegisterInfo
65      * @see UnRegisterWidget()
66      * @param[in] widgetHandle  Widget ID that will be registered.
67      * @param[in] pWidgetRegisterInfo    Specified the widget's information needed to be registered.
68      * @param[in] wacSecurity   Widget's security certificates.
69      */
70     static void registerWidget(
71             const DbWidgetHandle& widgetHandle,
72             const WidgetRegisterInfo &pWidgetRegisterInfo,
73             const IWacSecurity &wacSecurity);
74
75     static DbWidgetHandle registerWidget(
76             const WidgetRegisterInfo &pWidgetRegisterInfo,
77             const IWacSecurity &wacSecurity) __attribute__((deprecated))
78     {
79         //make it more precise due to very fast tests
80         struct timeval tv;
81         gettimeofday(&tv, NULL);
82         srand(time(NULL) + tv.tv_usec);
83         DbWidgetHandle widgetHandle;
84         do {
85             widgetHandle = rand();
86         } while (isWidgetInstalled(widgetHandle));
87
88         registerWidget(widgetHandle, pWidgetRegisterInfo, wacSecurity);
89         return widgetHandle;
90     }
91
92     /**
93      * This method removes a widget's information from EmDB.
94      *
95      * @see RegisterWidget()
96      * @param[in] widgetHandle    widget's app id
97      * @return true if succeed, false if fail.
98      */
99     static void unregisterWidget(DbWidgetHandle widgetHandle);
100
101     /* This method removes widget property
102      */
103     void removeProperty(const PropertyDAOReadOnly::WidgetPropertyKey &key);
104
105     /* This method sets widget property
106      */
107     void setProperty(const PropertyDAOReadOnly::WidgetPropertyKey &key,
108             const PropertyDAOReadOnly::WidgetPropertyValue &value,
109             bool readOnly = false);
110
111     /* set PkgName
112      */
113     void setPkgName(const DPL::OptionalString& pkgName);
114
115     /* This function will update of api-feature status.
116      * If status is true (feature rejected) plugin connected with this
117      * api feature mustn't be loaded durign widget launch.
118      */
119     void updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature);
120
121   private:
122     //Methods used during widget registering
123     static void registerWidgetInfo(
124             const DbWidgetHandle& widgetHandle,
125             const WidgetRegisterInfo &regInfo,
126             const IWacSecurity &wacSecurity);
127     static void registerWidgetExtendedInfo(
128             DbWidgetHandle widgetHandle,
129             const WidgetRegisterInfo &regInfo);
130     static void registerWidgetLocalizedInfo(
131             DbWidgetHandle widgetHandle,
132             const WidgetRegisterInfo &regInfo);
133     static void registerWidgetIcons(
134             DbWidgetHandle widgetHandle,
135             const WidgetRegisterInfo &regInfo);
136     static void registerWidgetStartFile(
137             DbWidgetHandle widgetHandle,
138             const WidgetRegisterInfo &regInfo);
139     static void registerWidgetPreferences(
140             DbWidgetHandle widgetHandle,
141             const WidgetRegisterInfo &regInfo);
142     static void registerWidgetFeatures(
143             DbWidgetHandle widgetHandle,
144             const WidgetRegisterInfo &regInfo);
145     static void registerWidgetWindowModes(
146             DbWidgetHandle widgetHandle,
147             const WidgetRegisterInfo &regInfo);
148     static void registerWidgetWarpInfo(
149             DbWidgetHandle widgetHandle,
150             const WidgetRegisterInfo &regInfo);
151     static void registerWidgetCertificates(
152             DbWidgetHandle widgetHandle,
153             const IWacSecurity &wacSecurity);
154     static void registerLaunchCertificates(
155             DbWidgetHandle widgetHandle,
156             const CertificateChainList &list);
157     static void registerWidgetSettings(
158             DbWidgetHandle widgetHandle,
159             const WidgetRegisterInfo &regInfo);
160     static void registerAppService(
161             DbWidgetHandle widgetHandle,
162             const WidgetRegisterInfo &regInfo);
163 };
164
165 } // namespace WrtDB
166
167 #endif // WIDGET_DAO_H