arcsscriptcomponent.h
1 /*
2  name: include/arcs/arcsscriptcomponent.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 __ARCSSCRIPTCOMPONENT_H__
30 #define __ARCSSCRIPTCOMPONENT_H__
31 
32 #include <arcs/arcsabstractcomponent.h>
33 #include <arcs/arcsqdynamicobject.h>
34 #include <QScriptEngine>
35 #include <QHash>
36 
37 
39 
44 class ARCSScriptQObjectProxy : public QObject, public ARCSQDynamicObject
45 {
46 public:
47  ARCSScriptQObjectProxy(QObject* parent =0);
48 
49  virtual int qt_metacall(QMetaObject::Call, int id, void** arguments);
50  virtual QStringList getSignalList();
51  virtual QStringList getSlotList();
52 
53  virtual int prepareSignalConnect(QString sigName, QString sltName, QString objectName, QString actualSlot, bool simulate=false);
54  virtual int prepareSlotConnect(QString sigName, QString sltName, QString objectName, QString actualSignal, bool simulate=false);
55 
56  virtual int cleanSlotConnect(QString sigName, QString sltName, QString objectName, QString actualSignal);
57  virtual int cleanSignalConnect(QString sigName, QString sltName, QString objectName, QString actualSlot);
58 
59  bool setScript(QString s);
60 
61  static QScriptValue callSignal(QScriptContext* ctx, QScriptEngine* engine);
62  //static QScriptValue callSignalScript(QScriptContext* ctx, QScriptEngine* engine);
63 
64 private:
65  QScriptEngine* engine;
66  QString scriptString;
67  QList<int> paramSlotCount;
68  QList<QList<int> > paramSlotType;
69  QList<int> paramSignalCount;
70  QList<QList<int> > paramSignalType;
71 
72  QStringList slotList;
73  QStringList signalList;
74 
75  static QString computeParamList(QString slt);
76  void createCallSignalScript();
77  static int paramCount(QString s);
78 
79  QHash<QString, QStringList> signalCollection;
80 };
81 
82 
83 
85 
115 {
116 
117  public:
120 
121  virtual QString toString() { return scriptString; }
122  virtual bool parseString(QString s);
123  virtual QStringList getSignals() { return proxy->getSignalList(); }
124  virtual QStringList getSlots() { return proxy->getSlotList(); }
125 
126  protected:
127  virtual void getProxySlot (QString slot, ObjectList &obj, QStringList &proxySlot);
128  virtual void getProxySignal (QString signal, ObjectList &obj, QStringList &proxySignal);
129  virtual bool genuineInstanciate () { return true; }
130  virtual void genuineDestroy () {}
131 
132 
133 private:
134  QString scriptString;
135  ARCSScriptQObjectProxy* proxy;
136 };
137 
138 
139 
140 
141 
142 #endif // __ARCSSCRIPTCOMPONENT_H__
This component will be a QObject proxy in order to implement script behaviours */.
virtual void getProxySlot(QString slot, ObjectList &obj, QStringList &proxySlot)
Creates a proxy slot to interface a component to native ARCS components.
virtual QString toString()
Defines a basic seralization mechanism.
virtual bool genuineInstanciate()
This method should implement the instanciation of the actual component.
virtual QStringList getSlots()
Returns the names of the available slots.
virtual int cleanSlotConnect(QString sigName, QString sltName, QString objectName, QString actualSignal)
virtual int cleanSignalConnect(QString sigName, QString sltName, QString objectName, QString actualSlot)
virtual int prepareSignalConnect(QString sigName, QString sltName, QString objectName, QString actualSlot, bool simulate=false)
Prepares a connection with a slot which does not belong to this object.
virtual QStringList getSignals()
Returns the names of the availables signals.
Class handling the generic description of a component.
virtual void getProxySignal(QString signal, ObjectList &obj, QStringList &proxySignal)
Creates a proxy signal to interface a component to native ARCS components.
virtual int prepareSlotConnect(QString sigName, QString sltName, QString objectName, QString actualSignal, bool simulate=false)
Prepares a connection with a slot which is belonging to this object.
virtual void genuineDestroy()
This method should implement the destruction of the actual component.
virtual QStringList getSignalList()
Interface to extend QObject functionnalities in order to make objects with dynamic signals or slots...
Scripting components.
virtual QStringList getSlotList()
virtual bool parseString(QString s)
Defines a basic seralization mechanism.
virtual int qt_metacall(QMetaObject::Call, int id, void **arguments)
Method performing the actual callback task.