arcssheet.h
1 /*
2  name: include/arcs/arcssheet.h
3 
4  This file is part of ARCS - Augmented Reality Component System
5  (version 2-current), written by Jean-Yves Didier
6  for IBISC Laboratory (http://www.ibisc.univ-evry.fr)
7 
8  Copyright (C) 2013 Université d'Evry-Val d'Essonne
9 
10  This program is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Please send bugreports with examples or suggestions to
25  jean-yves.didier__at__ibisc.univ-evry.fr
26 */
27 
28 
29 #ifndef __ARCSSHEET_H__
30 #define __ARCSSHEET_H__
31 
32 #include <arcs/arcscontext.h>
33 #include <arcs/arcsconnection.h>
34 #include <arcs/arcsinit.h>
35 #include <arcs/arcsdll.h>
36 
37 #include <QMutex>
38 #include <QHash>
39 #include <QSet>
40 #include <iostream>
41 
43 
48 class DLL_POINT ARCSSheet
49 {
50 public:
51 
53  ARCSSheet(ARCSContext* ctx=0, QString n=QString::null);
55 
57  ARCSSheet(const ARCSSheet & sheet);
58 
60 
67  ARCSConnection& addConnection(QString src, QString sgn, QString dst, QString slt, bool q = false, bool head=false);
68 
69 
71 
76  ARCSInit& addPreconnect(QString dst, QString slt, QString t, QString val)
77  {
78  return createInit(preconnects, dst, slt, t, val);
79  }
80 
82 
87  ARCSInit& addPostconnect(QString dst, QString slt, QString t, QString val)
88  {
89  return createInit(postconnects, dst, slt, t, val);
90  }
91 
93 
98  ARCSInit& addCleanup(QString dst, QString slt, QString t, QString val)
99  {
100  return createInit(cleanups, dst, slt, t, val);
101  }
102 
103 
105 
110  void getConnections(QStringList & sources, QStringList & signls, QStringList & destinations, QStringList & slts);
111 
113 
118  ARCSConnection & getConnection(QString source, QString sgn, QString dst, QString slt);
119 
120 
121  int getConnectionIndex(ARCSConnection& connection) { return connections.indexOf(connection);}
122  int getConnectionIndex(QString source, QString sgn, QString dst, QString slt);
123 
124  int getPreconnectIndex(ARCSInit& init) { return preconnects.indexOf(init);}
125  int getPostconnectIndex(ARCSInit& init) { return postconnects.indexOf(init); }
126  int getCleanupIndex(ARCSInit& init) { return cleanups.indexOf(init); }
127 
128 
129  ARCSInit& getPreConnect(QString dst,QString slt, QString t, QString val)
130  {
131  return getInit(preconnects,dst,slt,t,val);
132  }
133 
134  ARCSInit& getPostConnect(QString dst,QString slt, QString t, QString val)
135  {
136  return getInit(postconnects,dst,slt,t,val);
137  }
138 
139  ARCSInit& getCleanup(QString dst,QString slt, QString t, QString val)
140  {
141  return getInit(cleanups,dst,slt,t,val);
142  }
143 
144 
145  void swapConnections(int x,int y);
146 
147 
149 
154  void getPreconnects(QStringList & destinations, QStringList & slts, QStringList & types, QStringList & values)
155  {
156  getInits(preconnects, destinations, slts, types, values);
157  }
158 
160 
165  void getPostconnects(QStringList & destinations, QStringList & slts, QStringList & types, QStringList & values)
166  {
167  getInits(postconnects, destinations, slts, types, values);
168  }
169 
171 
176  void getCleanups(QStringList & destinations, QStringList & slts, QStringList & types, QStringList & values)
177  {
178  getInits(cleanups, destinations, slts, types, values);
179  }
180 
182  void activate() { mutex->lock(); preconnect(); connect(); activated = true; mutex->unlock(); postconnect(); }
184  void deactivate() { mutex->lock(); disconnect(); cleanup(); activated = false; mutex->unlock();}
185 
186  void removeConnection(ARCSConnection c) { connections.removeAll(c); }
187  void removePreconnect(ARCSInit i) { preconnects.removeAll(i); }
188  void removePostconnect(ARCSInit i) { postconnects.removeAll(i); }
189  void removeCleanup(ARCSInit i) { cleanups.removeAll(i); }
190  ARCSContext* getContext() { return context; }
191  void setContext(ARCSContext* ctx) { context = ctx; }
192 
193 
195  void preconnect() { batchInit(preconnects); }
197  void connect();
199  void postconnect() { batchInit(postconnects); }
201  void disconnect();
203  void cleanup() { batchInit(cleanups); }
204 
205  void reset();
206  void resetConnections() { connections.clear(); }
207  void resetPreconnects() { preconnects.clear(); }
208  void resetPostconnects() { postconnects.clear(); }
209  void resetCleanups() { cleanups.clear(); }
210  void resetProperties() { properties.clear(); }
211 
212  // Implementing properties
214  void setProperty(QString name,QString value) { properties[name] = value ; }
216  QString getProperty(QString name) {
217  if (properties.contains(name))
218  return properties[name];
219  else
220  return QString();
221  }
222 
223  void removeProperty(QString name) {
224  properties.remove(name);
225  }
226 
227 
229 
231  QStringList getComponentList();
232 
233  void removeComponent(QString name);
234 
235 
237  QStringList getPropertyList() { return properties.keys(); }
238 
239 
241  bool isActivated() { bool r; mutex->lock(); r = activated; mutex->unlock(); return r; }
242 
244  void setName(QString s) { name = s; }
246  QString getName() { return name;}
247 
248  typedef ARCSInit& (ARCSSheet::*AddInvocationMethod) (QString, QString, QString, QString);
249  typedef void (ARCSSheet::*GetInvocationsMethod) (QStringList& , QStringList & , QStringList &, QStringList&);
250 
251  bool isEmpty() { return connections.isEmpty() || preconnects.isEmpty() || postconnects.isEmpty() || cleanups.isEmpty(); }
252 
253  static ARCSSheet null;
254 
255 
256  void swapPreconnects(int x, int y) { swapInits(preconnects,x,y); }
257  void swapPostconnects(int x,int y) { swapInits(postconnects,x,y); }
258  void swapCleanups(int x,int y) { swapInits(cleanups,x,y); }
259 
260  void swapInits(QList<ARCSInit> &lst, int x, int y);
261 
262 
263 
264 private:
265  void removeInitWithComponent(QList<ARCSInit> &lst, QString name);
266  void listComponentInit(QList<ARCSInit>& lst, QSet<QString>& set);
267  void batchInit(QList<ARCSInit> & lst);
268  ARCSInit& createInit(QList<ARCSInit> & lst, QString dst, QString slt, QString t, QString val);
269  ARCSInit& getInit(QList<ARCSInit> &lst, QString dst, QString slt, QString t, QString val);
270  void getInits(QList<ARCSInit> &lst, QStringList & destinations,
271  QStringList & slots, QStringList & types, QStringList& values);
272 
273  ARCSContext* context;
274  QList<ARCSConnection> connections;
275  QList<ARCSInit> preconnects;
276  QList<ARCSInit> postconnects;
277  QList<ARCSInit> cleanups;
278  QString name;
279  QMutex* mutex;
280 
281  QHash<QString,QString> properties;
282 
283  bool activated;
284 };
285 
286 
287 #endif //__ARCSSHEET_H__
void activate()
Definition: arcssheet.h:182
void preconnect()
Definition: arcssheet.h:195
ARCSInit & addCleanup(QString dst, QString slt, QString t, QString val)
Adds a cleanup invocation to the sheet structure.
Definition: arcssheet.h:98
void postconnect()
Definition: arcssheet.h:199
QString getName()
Definition: arcssheet.h:246
QString getProperty(QString name)
Definition: arcssheet.h:216
ARCSInit & addPreconnect(QString dst, QString slt, QString t, QString val)
Adds a pre-connection initialisation to the sheet structure.
Definition: arcssheet.h:76
void deactivate()
Definition: arcssheet.h:184
Desribes an initialization over a component.
Definition: arcsinit.h:46
QStringList getPropertyList()
Definition: arcssheet.h:237
Describes a connection.
void setProperty(QString name, QString value)
Definition: arcssheet.h:214
void getCleanups(QStringList &destinations, QStringList &slts, QStringList &types, QStringList &values)
Allows to retrieve cleanup invocations.
Definition: arcssheet.h:176
void cleanup()
Definition: arcssheet.h:203
void getPostconnects(QStringList &destinations, QStringList &slts, QStringList &types, QStringList &values)
Allows to retrieve postconnection invocations.
Definition: arcssheet.h:165
This class manages components and constants in a given context.
Definition: arcscontext.h:45
bool isActivated()
Definition: arcssheet.h:241
void setName(QString s)
Definition: arcssheet.h:244
ARCSInit & addPostconnect(QString dst, QString slt, QString t, QString val)
Adds a post-connection initialisation to the sheet structure.
Definition: arcssheet.h:87
Maintains connections between objects.
Definition: arcssheet.h:48
void getPreconnects(QStringList &destinations, QStringList &slts, QStringList &types, QStringList &values)
Allows to retrieve preconnection invocations.
Definition: arcssheet.h:154