arcsapplicationcomponent.h
1 /*
2  name: include/arcs/arcsapplicationcomponent.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 __ARCSAPPLICATIONCOMPONENT_H__
30 #define __ARCSAPPLICATIONCOMPONENT_H__
31 
32 #include <arcs/arcsapplicationobject.h>
33 #include <arcs/arcscontrollercomponent.h>
34 #include <arcs/arcsprocess.h>
35 //#include <arcs/arcswrapper.h>
36 
37 
38 class ARCSAppMode;
39 
41 
45 class DLL_EXPORT ARCSApplicationComponent : public QObject, public ARCSAbstractComponent
46 {
47 Q_OBJECT
48 
49 public:
52 
53 
55  bool startApplication();
57  bool stopApplication();
58 
60  ARCS::ARCSAppFlag getCurrentMode() { return currentMode; }
62  void setCurrentMode(ARCS::ARCSAppFlag flag) { currentMode = flag; }
63 
65  ARCSContext* getContext() { return &context ; }
66 
68  void addProcess(ARCSProcess* ap) { processes.append(ap); }
70 
72  void removeProcess(int i) { ARCSProcess* ap = processes.takeAt(i); if (ap) delete ap; }
73 
75  int getProcessCount() { return processes.count(); }
76 
77  void removeComponent(QString name);
78 
79 
80 
81  void swapProcesses(int i,int j) { processes.swap(i,j); }
82 
87  ARCSProcess* getProcess(int idx) { return processes.at(idx); }
88 
89  virtual QStringList getSlots() { return ARCS::getMethodList(defaultCore->metaObject(),QMetaMethod::Slot); }
90  virtual QStringList getSignals() { return ARCS::getMethodList(defaultCore->metaObject(),QMetaMethod::Signal); }
91  virtual QString toString() { return QString::null; }
92  virtual bool parseString(QString s);
93  virtual bool loadFile(QString fn);
94 
96  bool hasFinished() { return applicationFinished ; }
98  void wait();
99 
101 
104  void changeConstant(QString name, QString representation) { context.modifyConstant(name, representation); }
105 
106  static ARCSApplicationComponent* getRunningInstance() { return runningInstance; }
107 
108 
109  virtual QVariant getGenuineComponentInstance();
110 
111 
112  void* getInterface()
113  {
114  ARCSAbstractComponent* cmp = context.getComponent("this");
115  if (cmp)
116  cmp->instanciate();
117 
118  return _interface;
119  }
120  template<typename T> static void setInterface(T* iface) { _interface = iface; }
121 
122 public slots:
124  void finish();
125 
126 signals:
128  void finished();
129 
130 protected:
131 
132  virtual void getProxySlot(QString slot, ObjectList& obj, QStringList &proxySlot)
133  {
134  obj << defaultCore ; proxySlot << slot;
135  }
136  virtual void getProxySignal(QString signal, ObjectList& obj, QStringList &proxySignal)
137  {
138  obj << defaultCore ; proxySignal << signal;
139  }
140 
141  virtual bool genuineInstanciate() { return true; }
142  virtual void genuineDestroy() { }
143 
144 
145 private:
146 
147  static ARCSApplicationComponent* runningInstance;
148 
149  ARCSContext context;
150  QList<ARCSProcess*> processes ;
151 
152  //ARCSApplicationObject* applicationCore;
153  static ARCSApplicationObject* defaultCore;
154 
155  ARCS::ARCSAppFlag currentMode;
156  bool applicationFinished;
157 
158  static void* _interface;
159 };
160 
161 
162 
163 #endif //__ARCSAPPLICATIONCOMPONENT_H__
ARCSAppFlag
Flags to specify in which mode applications should start.
Definition: arcs.h:41
bool instanciate()
Instanciates the real component.
Application objects are used to implement specific interfaces when the application needs to be embedd...
void changeConstant(QString name, QString representation)
This hack allows to change the value of a constant in the constant pool.
This class represents an application.
virtual QVariant getGenuineComponentInstance()
This class is representing a process under ARCS.
Definition: arcsprocess.h:52
void setCurrentMode(ARCS::ARCSAppFlag flag)
void addProcess(ARCSProcess *ap)
ARCS::ARCSAppFlag getCurrentMode()
Class handling the generic description of a component.
virtual bool loadFile(QString fn)
Defines a way to load a component description from a file.
Base class for launching and handling ARCS applications.
Definition: arcsappmode.h:45
QStringList getMethodList(const QMetaObject *object, QMetaMethod::MethodType type)
Helper method for components.
virtual void genuineDestroy()
This method should implement the destruction of the actual component.
virtual QStringList getSlots()
Returns the names of the available slots.
virtual QString toString()
Defines a basic seralization mechanism.
This class manages components and constants in a given context.
Definition: arcscontext.h:45
ARCSProcess * getProcess(int idx)
virtual void getProxySignal(QString signal, ObjectList &obj, QStringList &proxySignal)
Creates a proxy signal to interface a component to native ARCS components.
void removeProcess(int i)
Removes a process in the list of processes managed by the application.
virtual bool genuineInstanciate()
This method should implement the instanciation of the actual component.
virtual bool parseString(QString s)=0
Defines a basic seralization mechanism.
virtual QStringList getSignals()
Returns the names of the availables signals.
For applications requiring event loops.
Definition: arcs.h:45
virtual void getProxySlot(QString slot, ObjectList &obj, QStringList &proxySlot)
Creates a proxy slot to interface a component to native ARCS components.