6ae087e290ac2b12567df412a607216c894b9114
[framework/web/wrt-installer.git] / src / misc / feature_logic.cpp
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 #include "feature_logic.h"
18
19 #include <list>
20
21 #include <dpl/assert.h>
22 #include <dpl/noncopyable.h>
23 #include <dpl/string.h>
24 #include <dpl/foreach.h>
25 #include <dpl/log/log.h>
26 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
27 #include <dpl/wrt-dao-ro/global_dao_read_only.h>
28
29 namespace Jobs {
30 namespace WidgetInstall {
31 namespace {
32 const DPL::String PRIVILEGE_TESTAUTOMATION =
33     L"http://tizen.org/privilege/testautomation";
34 const DPL::String DEVICE_CAPABILITY_TESTAUTOMATION = L"testautomation";
35 }
36 FeatureLogic::FeatureLogic(const WrtDB::TizenAppId & tzAppid) :
37     m_rejected(false)
38 {
39     WrtDB::WidgetDAOReadOnly widgetDao(tzAppid);
40     WidgetFeatureSet featureSet = widgetDao.getFeaturesList();
41     FOREACH(it, featureSet) {
42         LogInfo("Feature name : " << it->name);
43         WrtDB::DeviceCapabilitySet dcs;
44         if (!DPL::StringCompare(it->name, PRIVILEGE_TESTAUTOMATION)) {
45             // special privilege
46             // This privilege doesn't have plugin in the target
47             // only use to special behavior
48             dcs.insert(DEVICE_CAPABILITY_TESTAUTOMATION);
49         } else {
50             // normal privilege
51             dcs = WrtDB::GlobalDAOReadOnly::GetDeviceCapability(it->name);
52         }
53         FOREACH(devCap, dcs) {
54             LogInfo("--- dev cap  : " << *devCap);
55         }
56         Feature feature(*it, dcs);
57         m_featureList.push_back(feature);
58     }
59     m_currentFeature = m_featureList.begin();
60
61     // ok we must set iterator on the first processable node
62     if (!isProcessable()) {
63         next();
64     }
65 }
66
67 bool FeatureLogic::isDone() const
68 {
69     return m_currentFeature == m_featureList.end();
70 }
71
72 bool FeatureLogic::next()
73 {
74     while (!isDone()) {
75         if (m_currentFeature->currentCap !=
76             m_currentFeature->devCapSet.end())
77         {
78             m_currentFeature->currentCap++;
79         } else {
80             ++m_currentFeature;
81         }
82         // we moved pointer
83         if (isProcessable()) {
84             return true;
85         }
86     }
87     return false;
88 }
89
90 void FeatureLogic::setAceResponse(bool allowed)
91 {
92     Assert(isProcessable() && "Wrong usage");
93     if (!allowed) {
94         m_currentFeature->rejected = true;
95         m_rejected = true;
96     }
97 }
98
99 DPL::String FeatureLogic::getDevice() const
100 {
101     return *(m_currentFeature->currentCap);
102 }
103
104 bool FeatureLogic::isProcessable() const
105 {
106     if (isDone()) {
107         return false;
108     }
109
110     if (m_currentFeature->currentCap == m_currentFeature->devCapSet.end()) {
111         return false;
112     }
113
114     return true;
115 }
116 } // namespace WidgetInstall
117 } // namespace Jobs
118