|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qvaluespacemanager_p.h" |
|
43 |
|
44 QTM_BEGIN_NAMESPACE |
|
45 |
|
46 Q_GLOBAL_STATIC(QValueSpaceManager, valueSpaceManager); |
|
47 |
|
48 QValueSpaceManager *QValueSpaceManager::instance() |
|
49 { |
|
50 return valueSpaceManager(); |
|
51 } |
|
52 |
|
53 QValueSpaceManager::QValueSpaceManager() |
|
54 : type(Uninit) |
|
55 { |
|
56 } |
|
57 |
|
58 void QValueSpaceManager::initServer() |
|
59 { |
|
60 Q_ASSERT(Uninit == type); |
|
61 |
|
62 commonInit(QAbstractValueSpaceLayer::Server); |
|
63 } |
|
64 |
|
65 void QValueSpaceManager::init() |
|
66 { |
|
67 if(Uninit != type) |
|
68 return; // Already initialized |
|
69 |
|
70 commonInit(QAbstractValueSpaceLayer::Client); |
|
71 } |
|
72 |
|
73 void QValueSpaceManager::commonInit(QAbstractValueSpaceLayer::Type vsltype) |
|
74 { |
|
75 Q_ASSERT(Uninit == type); |
|
76 |
|
77 // Install all the dormant layers |
|
78 for(int ii = 0; ii < funcs.count(); ++ii) |
|
79 install(funcs[ii]()); |
|
80 funcs.clear(); |
|
81 |
|
82 type = (vsltype == QAbstractValueSpaceLayer::Server)?Server:Client; |
|
83 |
|
84 for(int ii = 0; ii < layers.count(); ++ii) { |
|
85 if(!initLayer(layers.at(ii))) { |
|
86 layers.removeAt(ii); |
|
87 --ii; |
|
88 } |
|
89 } |
|
90 } |
|
91 |
|
92 bool QValueSpaceManager::isServer() const |
|
93 { |
|
94 return (Server == type); |
|
95 } |
|
96 |
|
97 void QValueSpaceManager::install(QAbstractValueSpaceLayer * layer) |
|
98 { |
|
99 Q_ASSERT(Uninit == type); |
|
100 Q_ASSERT(layer); |
|
101 unsigned int cOrder = layer->order(); |
|
102 int inserted = -1; |
|
103 for(int ii = 0; !inserted && ii < layers.count(); ++ii) { |
|
104 unsigned int lOrder = layers.at(ii)->order(); |
|
105 Q_ASSERT(layer != layers.at(ii)); |
|
106 if(lOrder < cOrder) { |
|
107 // Do nothing |
|
108 } else if(lOrder == cOrder) { |
|
109 if(layers.at(ii)->id() > layer->id()) { |
|
110 layers.insert(ii, layer); |
|
111 inserted = ii; |
|
112 } |
|
113 } else if(lOrder > cOrder) { |
|
114 layers.insert(ii, layer); |
|
115 inserted = ii; |
|
116 } |
|
117 } |
|
118 |
|
119 if(-1 == inserted) { |
|
120 inserted = layers.count(); |
|
121 layers.append(layer); |
|
122 } |
|
123 } |
|
124 |
|
125 void QValueSpaceManager::install(QValueSpace::LayerCreateFunc func) |
|
126 { |
|
127 Q_ASSERT(Uninit == type); |
|
128 funcs.append(func); |
|
129 } |
|
130 |
|
131 QList<QAbstractValueSpaceLayer *> const & QValueSpaceManager::getLayers() |
|
132 { |
|
133 init(); // Fallback init |
|
134 |
|
135 return layers; |
|
136 } |
|
137 |
|
138 bool QValueSpaceManager::initLayer(QAbstractValueSpaceLayer* layer) |
|
139 { |
|
140 Q_ASSERT(Uninit != type); |
|
141 |
|
142 return layer->startup((type==Client)?QAbstractValueSpaceLayer::Client: |
|
143 QAbstractValueSpaceLayer::Server); |
|
144 } |
|
145 |
|
146 QTM_END_NAMESPACE |