arcscompositecomponent.cpp
1 /*
2  name: lib/arcscompositecomponent.cpp
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 #include <arcs/arcscompositecomponent.h>
30 #include <arcs/arcsxmlhandler.h>
31 
32 
33 ARCSCompositeComponent::ARCSCompositeComponent() : ARCSAbstractComponent()
34 {
35  //context = 0;
36  //sheet(context);
37 
38 }
39 
40 
41 ARCSCompositeComponent::~ARCSCompositeComponent()
42 {
43 }
44 
45 
46 
48 {
49  bool b = context.instanciatePool();
50  sheet.preconnect();
51  sheet.connect();
52  sheet.postconnect();
53  return b;
54 }
55 
57 {
58  sheet.disconnect();
59  sheet.cleanup();
60 }
61 
62 
64 {
65  return proxySlots.uniqueKeys();
66 }
67 
69 {
70  return proxySignals.uniqueKeys();
71 }
72 
73 
74 
75 
77 {
78  ARCSXMLHandler xmlHandler;
79  xmlHandler.storeCompositeComponent(this);
80  return xmlHandler.getContents();
81 }
82 
83 
84 bool ARCSCompositeComponent::addMethod(QMap<QString, ARCSMethod> &list , QString proxy, QString id, QString method)
85 {
86  ARCSAbstractComponent* cmp = context.getComponent(id);
87  if ( cmp == 0)
88  return false;
89 
90  list.insertMulti(proxy,ARCSMethod(cmp, method));
91  return true;
92 }
93 
94 
96 {
97  ARCSXMLHandler xmlHandler;
98  xmlHandler.setContents(s);
99  return xmlHandler.parseCompositeComponent(this);
100 }
101 
103 {
104  ARCSXMLHandler xmlHandler;
105  xmlHandler.openFile(fn);
106  return xmlHandler.parseCompositeComponent(this);
107 }
108 
110 {
111  ARCSXMLHandler xmlHandler;
112  xmlHandler.storeCompositeComponent(this);
113  return xmlHandler.saveFile(fn);
114 }
115 
116 void ARCSCompositeComponent::getProxySlot(QString slot, ObjectList & obj, QStringList& proxySlot)
117 {
118  QList<ARCSMethod> lst = proxySlots.values(slot);
119 
120  // inversion mandatory since calls must be performed in the right order.
121  for (int i = lst.count() - 1 ; i >= 0 ; i--)
122  {
123  ObjectList objects;
124  QStringList methods;
125  ARCSAbstractComponent::getProxySlot(lst[i].getComponent(),lst[i].getMethodName(), objects, methods);
126 
127  obj << objects;
128  proxySlot << methods;
129  }
130 }
131 
132 
133 void ARCSCompositeComponent::getProxySignal(QString signal, ObjectList& obj, QStringList& proxySignal)
134 {
135  QList<ARCSMethod> lst = proxySignals.values(signal);
136 
137  // inversion mandatory since calls must be performed in the right order.
138  for (int i = lst.count()-1 ; i >=0 ; i--)
139  {
140  ObjectList objects;
141  QStringList methods;
142  ARCSAbstractComponent::getProxySignal(lst[i].getComponent(),lst[i].getMethodName(), objects, methods);
143 
144  obj << objects;
145  proxySignal << methods;
146  }
147 }
148 
149 
151 void ARCSCompositeComponent::getProxyMethods(QMap<QString,ARCSMethod> & /*list*/,QStringList& /*proxies*/, QStringList& /*objects*/, QStringList& /*methods*/)
152 {
153 
154 }
155 
156 
157 
bool setContents(QString s)
Gives the content to parse.
virtual QString toString()
Defines a basic seralization mechanism.
void preconnect()
Definition: arcssheet.h:195
void postconnect()
Definition: arcssheet.h:199
virtual bool parseString(QString s)
Defines a basic seralization mechanism.
virtual void getProxySignal(QString signal, ObjectList &obj, QStringList &proxySignal)=0
Creates a proxy signal to interface a component to native ARCS components.
void disconnect()
Definition: arcssheet.cpp:172
virtual void getProxySlot(QString slot, ObjectList &obj, QStringList &proxySlot)
Creates a proxy slot to interface a component to native ARCS components.
bool openFile(QString s)
Opens a file given its path. The file should describe either an application or a composite component...
virtual void getProxySlot(QString slot, ObjectList &obj, QStringList &proxySlot)=0
Creates a proxy slot to interface a component to native ARCS components.
Class handling the generic description of a component.
virtual bool saveFile(QString fn)
Defines a way to save a component description inside a file.
void cleanup()
Definition: arcssheet.h:203
ARCSAbstractComponent * getComponent(QString name)
Retrieves a component by its id.
virtual QStringList getSignals()
Returns the names of the availables signals.
void connect()
Definition: arcssheet.cpp:161
bool saveFile(QString s)
Saves a file given its path. The file will describe either an application or a composite component...
A class describing a component/method pair.
Definition: arcsmethod.h:39
bool instanciatePool()
Instanciates the whole pool of components inside the context.
virtual void getProxySignal(QString signal, ObjectList &obj, QStringList &proxySignal)
Creates a proxy signal to interface a component to native ARCS components.
virtual bool genuineInstanciate()
This method should implement the instanciation of the actual component.
virtual QStringList getSlots()
Returns the names of the available slots.
virtual bool loadFile(QString fn)
Defines a way to load a component description from a file.
virtual void genuineDestroy()
This method should implement the destruction of the actual component.
This is an XML Handler for all ARCS native XML formats.