18b640b81783d1eed2b21ac0b5316aef053ae97a
[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 FeatureLogic::FeatureLogic(const WrtDB::TizenAppId & tzAppid) :
32     m_rejected(false)
33 {
34     WrtDB::WidgetDAOReadOnly widgetDao(tzAppid);
35     WidgetFeatureSet featureSet = widgetDao.getFeaturesList();
36     FOREACH(it, featureSet) {
37         LogInfo("Feature name : " << it->name);
38         WrtDB::DeviceCapabilitySet dcs =
39             WrtDB::GlobalDAOReadOnly::GetDeviceCapability(it->name);
40         FOREACH(devCap, dcs) {
41             LogInfo("--- dev cap  : " << *devCap);
42         }
43         Feature feature(*it, dcs);
44         m_featureList.push_back(feature);
45     }
46     m_currentFeature = m_featureList.begin();
47
48     // ok we must set iterator on the first processable node
49     if (!isProcessable()) {
50         next();
51     }
52 }
53
54 bool FeatureLogic::isDone() const
55 {
56     return m_currentFeature == m_featureList.end();
57 }
58
59 bool FeatureLogic::next()
60 {
61     while (!isDone()) {
62         if (m_currentFeature->currentCap !=
63             m_currentFeature->devCapSet.end())
64         {
65             m_currentFeature->currentCap++;
66         } else {
67             ++m_currentFeature;
68         }
69         // we moved pointer
70         if (isProcessable()) {
71             return true;
72         }
73     }
74     return false;
75 }
76
77 void FeatureLogic::setAceResponse(bool allowed)
78 {
79     Assert(isProcessable() && "Wrong usage");
80     if (!allowed) {
81         m_currentFeature->rejected = true;
82         m_rejected = true;
83     }
84 }
85
86 DPL::String FeatureLogic::getDevice() const
87 {
88     return *(m_currentFeature->currentCap);
89 }
90
91 bool FeatureLogic::isProcessable() const
92 {
93     if (isDone()) {
94         return false;
95     }
96
97     if (m_currentFeature->currentCap == m_currentFeature->devCapSet.end()) {
98         return false;
99     }
100
101     return true;
102 }
103 } // namespace WidgetInstall
104 } // namespace Jobs
105