Skip to contentSkip to conversation

Patch Description

PATCH In review Yang Gu 3 participants 7 messages Sep 30, 2010 – Oct 14, 2010 Kbuild

lore
Share & tools
lore

Yang Gu

author
#0 lore raw

v2 cover Patch Description

This series of patches fix the compilation problem, as well as some memory leak. But the main focus is to enable Qt script so that phonesim GUI can be controlled using JavaScript. In the meantime, D-Bus support is added for the sake of test automation.

Here are several examples:
1. call.js (stands for incoming call and copy it to /tmp/call/) tabRegistration.gbIncomingCall.leCaller.text = "12345"; tabRegistration.gbIncomingCall.pbIncomingCall.click();

Then we set the path of script and run the script with its name
dbus-send --system --print-reply --dest=org.phonesim / org.phonesim.Script.SetPath string:/tmp/call dbus-send --system --print-reply --dest=org.phonesim / org.phonesim.Script.Run string:call.js

Now we have simulated an incoming call.

2. sms.js (stands for incoming sms and copy it to /tmp/sms/) tabSMS.gbMessage1.leMessageSender.text = "Yang"; tabSMS.gbMessage1.leSMSClass.text = "1"; tabSMS.gbMessage1.teSMSText.setPlainText("This message is sent automatically from phonesim"); tabSMS.gbMessage1.pbSendSMSMessage.click();

Then we do the similar things as first example:
dbus-send --system --print-reply --dest=org.phonesim / org.phonesim.Script.SetPath string:/tmp/sms dbus-send --system --print-reply --dest=org.phonesim / org.phonesim.Script.Run string:sms.js

Now we have simulated an incoming sms.

3. Get the current path for script
dbus-send --system --print-reply --dest=org.phonesim / org.phonesim.Script.GetPath

4. Make script return some string
The string can be any string, number, bool, date, etc in JavaScript, but it couldn't be a object because of some side effect. Refer "QScriptValue Class Reference" for details. For example, if you want to know the current incoming number, you may write a script as below:
// number.js
tabRegistration.gbIncomingCall.leCaller.text

After running the script the similar way as above, you may get the number.

By the way, you may need below file (/etc/dbus-1/system.d/phonesim.conf) so that phonesim can register its service in system bus:
<!-- This configuration file specifies the required security policies

     for oFono core daemon to work. -->

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>

<!-- ../system.conf have denied everything, so we just punch some holes -->

<policy user="root">

    <allow own="org.phonesim"/>
    <allow send_destination="org.phonesim"/>

</policy>

<policy at_console="true">
<allow send_destination="org.phonesim"/>
</policy>

<policy context="default">
<deny send_destination="org.phonesim"/>
</policy>

</busconfig>

Comments are welcome!

------------
Yang Gu (3):
Move def of class ControlWidget to header file Some instances in ControlWidget need to be deleted Enable Qt Script

 Makefile.am     |    5 +-
 configure.ac    |    2 +-
 src/control.cpp |  165 ++++++++++++++++++++++++++++++++-----------------------
 src/control.h   |  106 +++++++++++++++++++++++++++++++++++-
 4 files changed, 203 insertions(+), 75 deletions(-)
author
#1 lore raw

PATCH v2 1/3 Move def of class ControlWidget to header file

Currently any modification on control.cpp will result in some unrelated obj to be regenerated, because the definition of class ControlWidget is in this .cpp file. This patch wants to fix this problem.

---
 Makefile.am     |    5 +---
 src/control.cpp |   69 ------------------------------------------------------
 src/control.h   |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 70 insertions(+), 74 deletions(-)
Makefile.am +1 -4
index 34198a5..f124b08 100644
@@ -53,15 +53,12 @@ MAINTAINERCLEANFILES = Makefile.in \
 	aclocal.m4 configure depcomp missing install-sh
 
 
-$(src_phonesim_OBJECTS): src/control.moc src/ui_controlbase.h
+$(src_phonesim_OBJECTS): src/ui_controlbase.h
 
 QT_V_MOC   = $(QT_V_MOC_$(V))
 QT_V_MOC_  = $(QT_V_MOC_$(AM_DEFAULT_VERBOSITY))
 QT_V_MOC_0 = @echo "  MOC   " $@;
 
-src/control.moc: src/control.cpp
-	$(QT_V_MOC)$(MOC) $(QT_CFLAGS) $(INCLUDES) $< -o $@
-
 src/moc_%.cpp: src/%.h
 	$(QT_V_MOC)$(MOC) $< -o $@
 
src/control.cpp +0 -69

87 lines not on this page · raw message

src/control.h +69 -1

77 lines not on this page · raw message

Signature · 1 line
1.7.0.4
author
#2 lore raw

PATCH v2 2/3 Some instances in ControlWidget need to be deleted

In reply to Yang Gu
---
 src/control.cpp |    6 ++++++
 src/control.h   |    1 +
 2 files changed, 7 insertions(+), 0 deletions(-)
src/control.cpp +6 -0
index 458ee43..9e2c1f0 100644
@@ -89,6 +89,12 @@ void ControlWidget::closeEvent(QCloseEvent *event)
     hide();
 }
 
+ControlWidget::~ControlWidget()
+{
+    delete ui;
+    delete translator;
+}
+
 Control::Control(const QString& ruleFile, SimRules *sr, QObject *parent)
         : HardwareManipulator(sr, parent),
         widget(new ControlWidget(ruleFile, this))
src/control.h +1 -0
index 3577e8d..95536dc 100644
@@ -31,6 +31,7 @@ class ControlWidget : public QWidget
 Q_OBJECT
 public:
     ControlWidget( const QString&, Control*);
+    ~ControlWidget();
 
     void handleFromData( const QString& );
     void handleToData( const QString& );
Signature · 1 line
1.7.0.4
author
#3 lore raw

PATCH v2 3/3 Enable Qt Script

In reply to Yang Gu

This patch is to enable Qt script so that GUI can be controlled using JavaScript. In the meantime, D-Bus support is added for the sake of test automation.

---
 configure.ac    |    2 +-
 src/control.cpp |   90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/control.h   |   35 +++++++++++++++++++++
 3 files changed, 126 insertions(+), 1 deletions(-)
configure.ac +1 -1
index 4d10494..d5d674e 100644
@@ -21,7 +21,7 @@ AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization],
 	fi
 ])
 
-PKG_CHECK_MODULES(QT, QtCore QtGui QtXml QtNetwork, dummy=yes,
+PKG_CHECK_MODULES(QT, QtCore QtGui QtXml QtNetwork  QtScript, dummy=yes,
 						AC_MSG_ERROR(Qt is required))
 AC_SUBST(QT_CFLAGS)
 AC_SUBST(QT_LIBS)
src/control.cpp +90 -0

105 lines not on this page · raw message

src/control.h +35 -0
index 95536dc..e455437 100644
@@ -21,11 +21,45 @@
 #define CONTROL_H
 
 #include <hardwaremanipulator.h>
+#include <QtDBus/QtDBus>
+#include <QtScript>
 #include "ui_controlbase.h"
 #include "attranslator.h"
 
 class Control;
 
+class Script: public QDBusAbstractAdaptor
+{
+Q_OBJECT
+    Q_CLASSINFO("D-Bus Interface", "org.phonesim.Script")
+    Q_CLASSINFO("D-Bus Introspection", ""
+"  <interface name=\"org.phonesim.Script\">\n"
+"    <method name=\"SetPath\">\n"
+"      <arg direction=\"in\" type=\"s\" name=\"path\"/>\n"
+"    </method>\n"
+"    <method name=\"GetPath\">\n"
+"      <arg direction=\"out\" type=\"s\" name=\"path\"/>\n"
+"    </method>\n"
+"    <method name=\"Run\">\n"
+"      <arg direction=\"in\" type=\"s\" name=\"name\"/>\n"
+"      <arg direction=\"out\" type=\"s\" name=\"result\"/>\n"
+"    </method>\n"
+"  </interface>\n"
+        "")
+
+public:
+    Script(QObject *obj, Ui_ControlBase *ui);
+
+public slots:
+    void SetPath(const QString &path, const QDBusMessage &msg);
+    QString GetPath();
+    QString Run(const QString &name, const QDBusMessage &msg);
+
+private:
+    QString dirPath;
+    QScriptEngine engine;
+};
+
 class ControlWidget : public QWidget
 {
 Q_OBJECT
@@ -73,6 +107,7 @@ protected:
 
 private:
     Ui_ControlBase *ui;
+    Script *script;
     Control *p;
     AtTranslator *translator;
 
Signature · 1 line
1.7.0.4
#4 lore raw
In reply to Yang Gu

Hi Yang,

Quoted 6 lines · Yang Gu

This series of patches fix the compilation problem, as well as some memory leak. But the main focus is to enable Qt script so that phonesim GUI can be controlled using JavaScript. In the meantime, D-Bus support is added for the sake of test automation.

Here are several examples:
1. call.js (stands for incoming call and copy it to /tmp/call/) tabRegistration.gbIncomingCall.leCaller.text = "12345"; tabRegistration.gbIncomingCall.pbIncomingCall.click();

So this is a great idea and all the patches have been pushed. I've done a couple of quick modifications afterward. More info below.

Quoted 22 lines

Then we set the path of script and run the script with its name
dbus-send --system --print-reply --dest=org.phonesim / org.phonesim.Script.SetPath string:/tmp/call dbus-send --system --print-reply --dest=org.phonesim / org.phonesim.Script.Run string:call.js

Now we have simulated an incoming call.

2. sms.js (stands for incoming sms and copy it to /tmp/sms/) tabSMS.gbMessage1.leMessageSender.text = "Yang"; tabSMS.gbMessage1.leSMSClass.text = "1"; tabSMS.gbMessage1.teSMSText.setPlainText("This message is sent automatically from phonesim"); tabSMS.gbMessage1.pbSendSMSMessage.click();

Then we do the similar things as first example:
dbus-send --system --print-reply --dest=org.phonesim / org.phonesim.Script.SetPath string:/tmp/sms dbus-send --system --print-reply --dest=org.phonesim / org.phonesim.Script.Run string:sms.js

Now we have simulated an incoming sms.

3. Get the current path for script
dbus-send --system --print-reply --dest=org.phonesim / org.phonesim.Script.GetPath

Quoted 7 lines

4. Make script return some string
The string can be any string, number, bool, date, etc in JavaScript, but it couldn't be a object because of some side effect. Refer "QScriptValue Class Reference" for details. For example, if you want to know the current incoming number, you may write a script as below:
// number.js
tabRegistration.gbIncomingCall.leCaller.text

After running the script the similar way as above, you may get the number.

This is really valuable information. Can you submit a patch that adds a quick document describing this functionality? Alternatively, adding a new section to the HACKING file might be an option as well.

Quoted 20 lines

By the way, you may need below file (/etc/dbus-1/system.d/phonesim.conf) so that phonesim can register its service in system bus:
<!-- This configuration file specifies the required security policies

     for oFono core daemon to work. -->

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>

<!-- ../system.conf have denied everything, so we just punch some holes -->

<policy user="root">

    <allow own="org.phonesim"/>
    <allow send_destination="org.phonesim"/>

</policy>

<policy at_console="true">
<allow send_destination="org.phonesim"/>
</policy>

Quoted 7 lines

<policy context="default">
<deny send_destination="org.phonesim"/>
</policy>

</busconfig>

One of the changes I made was to have phonesim register to the system bus. This makes the above DBus configuration file unnecessary. Running phonesim on the system bus was too much of a security risk, and wasn't really needed.

Regards,
-Denis

#5 lore raw

Hi Denis,

Quoted 12 lines
Quoted 2 lines

Then we set the path of script and run the script with its name dbus-send --system --print-reply --dest=org.phonesim /

org.phonesim.Script.SetPath string:/tmp/call

Quoted 1 line

dbus-send --system --print-reply --dest=org.phonesim / org.phonesim.Script.Run

string:call.js

Quoted 1 line

One of the changes I made was to have phonesim register to the system bus. This makes the above DBus configuration file unnecessary. Running phonesim on the system bus was too much of a security risk, and wasn't really needed.

Thanks for the modifications afterward, and I'm fine with most of them. One question is why you renamed the service name to "org.ofono.phonesim". I wonder why the phonesim should have relationship with ofono?

Regards,
-Yang

#6 lore raw

Hi Yang,

Quoted 10 lines · Yang

Hi Denis,

Quoted 7 lines
Quoted 2 lines

Then we set the path of script and run the script with its name dbus-send --system --print-reply --dest=org.phonesim /

org.phonesim.Script.SetPath string:/tmp/call

Quoted 1 line

dbus-send --system --print-reply --dest=org.phonesim / org.phonesim.Script.Run

string:call.js

Quoted 1 line
Quoted 7 lines
Quoted 5 lines

One of the changes I made was to have phonesim register to the system bus. This makes the above DBus configuration file unnecessary. Running phonesim on the system bus was too much of a security risk, and wasn't really needed.

Thanks for the modifications afterward, and I'm fine with most of them. One question is why you renamed the service name to "org.ofono.phonesim". I wonder why the phonesim should have relationship with ofono?

In theory the service name should be related to the project website / domain name. Since we do not own org.phonesim, we put it on the org.ofono prefix.

Regards,
-Denis