All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] phonesim: Add timer to set the variable with the delay
@ 2012-02-29  9:37 Oleg Zhurakivskyy
  2012-02-29  9:37 ` [PATCH 1/2] phonesim: Minor reflow in SimChat::command() Oleg Zhurakivskyy
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Oleg Zhurakivskyy @ 2012-02-29  9:37 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 595 bytes --]

Hello,

Please find the changes in order to permit to set variables
with the delay (specify the delay in milliseconds):

<chat>
	<set name="AAA" value="BBB" delay="30000"/>
</chat>

This might be useful to simulate SIM PIN unlocking cases, etc.

Regards,
Oleg

Oleg Zhurakivskyy (2):
  phonesim: Minor reflow in SimChat::command()
  phonesim: Add timer to set the variable with the delay

 src/phonesim.cpp |   49 ++++++++++++++++++++++++++++++++++++++-----------
 src/phonesim.h   |   14 ++++++++++++++
 2 files changed, 52 insertions(+), 11 deletions(-)

-- 
1.7.5.4


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] phonesim: Minor reflow in SimChat::command()
  2012-02-29  9:37 [PATCH 0/2] phonesim: Add timer to set the variable with the delay Oleg Zhurakivskyy
@ 2012-02-29  9:37 ` Oleg Zhurakivskyy
  2012-02-29  9:37 ` [PATCH 2/2] phonesim: Add timer to set the variable with the delay Oleg Zhurakivskyy
  2012-03-04 20:56 ` [PATCH 0/2] " Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Oleg Zhurakivskyy @ 2012-02-29  9:37 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1645 bytes --]

Preparation in order to set the variable with the delay,
call setVariable() just from one place.
---
 src/phonesim.cpp |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/phonesim.cpp b/src/phonesim.cpp
index 09d6306..6931317 100644
--- a/src/phonesim.cpp
+++ b/src/phonesim.cpp
@@ -331,22 +331,24 @@ bool SimChat::command( const QString& cmd )
     for ( int varNum = 0; varNum < variables.size(); ++varNum ) {
     	QString variable = variables[varNum];
 	QString value = values[varNum];
-        if ( value != "*" ) {
+        QString val;
+
+        if ( value == "*" )
+            val = wild;
+        else {
             int index = value.indexOf( "${*}" );
-            if ( index == -1 ) {
-                state()->rules()->setVariable( variable, value );
-            } else {
+            if ( index != -1 ) {
                 if ( wild.length() > 0 && wild[wild.length() - 1] == 0x1A ) {
                     // Strip the terminating ^Z from SMS PDU's.
                     wild = wild.left( wild.length() - 1 );
                 }
-                state()->rules()->setVariable
-                    ( variable, value.left( index ) + wild +
-                    value.mid( index + 4 ) );
-            }
-        } else {
-            state()->rules()->setVariable( variable, wild );
+
+                val = value.left( index ) + wild + value.mid( index + 4 );
+            } else
+                val = value;
         }
+
+        state()->rules()->setVariable( variable, val );
     }
 
     // Switch to the new state.
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] phonesim: Add timer to set the variable with the delay
  2012-02-29  9:37 [PATCH 0/2] phonesim: Add timer to set the variable with the delay Oleg Zhurakivskyy
  2012-02-29  9:37 ` [PATCH 1/2] phonesim: Minor reflow in SimChat::command() Oleg Zhurakivskyy
@ 2012-02-29  9:37 ` Oleg Zhurakivskyy
  2012-03-04 20:56 ` [PATCH 0/2] " Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Oleg Zhurakivskyy @ 2012-02-29  9:37 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3342 bytes --]

In order to set the variable with the delay, specify the
delay in milliseconds:

<chat>
	<set name="AAA" value="BBB" delay="30000"/>
</chat>
---
 src/phonesim.cpp |   29 +++++++++++++++++++++++++++--
 src/phonesim.h   |   14 ++++++++++++++
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/src/phonesim.cpp b/src/phonesim.cpp
index 6931317..44401fe 100644
--- a/src/phonesim.cpp
+++ b/src/phonesim.cpp
@@ -268,8 +268,12 @@ SimChat::SimChat( SimState *state, SimXmlNode& e )
         } else if ( n->tag == "switch" ) {
             switchTo = n->getAttribute( "name" );
         } else if ( n->tag == "set" ) {
-	    variables += n->getAttribute( "name" );
+            QString name = n->getAttribute( "name" );
+	    variables += name;
 	    values += n->getAttribute( "value" );
+            int delay = n->getAttribute( "delay" ).toInt();
+            if (delay)
+                delays[name] = delay;
         } else if ( n->tag == "newcall" ) {
             newCallVar = n->getAttribute( "name" );
         } else if ( n->tag == "forgetcall" ) {
@@ -331,6 +335,7 @@ bool SimChat::command( const QString& cmd )
     for ( int varNum = 0; varNum < variables.size(); ++varNum ) {
     	QString variable = variables[varNum];
 	QString value = values[varNum];
+        int delay = delays.value(variable, 0);
         QString val;
 
         if ( value == "*" )
@@ -348,7 +353,18 @@ bool SimChat::command( const QString& cmd )
                 val = value;
         }
 
-        state()->rules()->setVariable( variable, val );
+        if (delay) {
+            QVariantTimer *timer = new QVariantTimer(this->state()->rules());
+
+            timer->param = QVariant::fromValue(QPairKV(variable, val));
+
+            timer->setSingleShot( true );
+
+            connect(timer, SIGNAL(timeout()), this->state()->rules(),
+                    				SLOT(delaySetVariable()));
+            timer->start( delay );
+        } else
+            state()->rules()->setVariable( variable, val );
     }
 
     // Switch to the new state.
@@ -1637,6 +1653,15 @@ void SimRules::delayTimeout()
     timer->deleteLater();
 }
 
+void SimRules::delaySetVariable()
+{
+    QVariantTimer *timer = (QVariantTimer *)sender();
+    QPairKV kv = timer->param.value<QPairKV>();
+
+    setVariable( kv.first, kv.second );
+
+    delete timer;
+}
 
 void SimRules::dialCheck( const QString& number, bool& ok )
 {
diff --git a/src/phonesim.h b/src/phonesim.h
index aa693cd..ce69155 100644
--- a/src/phonesim.h
+++ b/src/phonesim.h
@@ -162,6 +162,7 @@ private:
     bool eol;
     QStringList variables;
     QStringList values;
+    QMap<QString, int> delays;
     QString newCallVar;
     QString forgetCallId;
     bool listSMS;
@@ -315,6 +316,7 @@ private slots:
     void tryReadCommand();
     void destruct();
     void delayTimeout();
+    void delaySetVariable();
     void dialCheck( const QString& number, bool& ok );
 
 private:
@@ -373,4 +375,16 @@ public:
     int channel;
 };
 
+class QVariantTimer : public QTimer
+{
+    Q_OBJECT
+public:
+    QVariantTimer( QObject *parent = 0 ) : QTimer(parent) { }
+    QVariant param;
+};
+
+typedef QPair<QString,QString> QPairKV;
+
+Q_DECLARE_METATYPE(QPairKV);
+
 #endif
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] phonesim: Add timer to set the variable with the delay
  2012-02-29  9:37 [PATCH 0/2] phonesim: Add timer to set the variable with the delay Oleg Zhurakivskyy
  2012-02-29  9:37 ` [PATCH 1/2] phonesim: Minor reflow in SimChat::command() Oleg Zhurakivskyy
  2012-02-29  9:37 ` [PATCH 2/2] phonesim: Add timer to set the variable with the delay Oleg Zhurakivskyy
@ 2012-03-04 20:56 ` Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2012-03-04 20:56 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 748 bytes --]

Hi Oleg,

On 02/29/2012 03:37 AM, Oleg Zhurakivskyy wrote:
> Hello,
> 
> Please find the changes in order to permit to set variables
> with the delay (specify the delay in milliseconds):
> 
> <chat>
> 	<set name="AAA" value="BBB" delay="30000"/>
> </chat>
> 
> This might be useful to simulate SIM PIN unlocking cases, etc.
> 
> Regards,
> Oleg
> 
> Oleg Zhurakivskyy (2):
>   phonesim: Minor reflow in SimChat::command()
>   phonesim: Add timer to set the variable with the delay
> 
>  src/phonesim.cpp |   49 ++++++++++++++++++++++++++++++++++++++-----------
>  src/phonesim.h   |   14 ++++++++++++++
>  2 files changed, 52 insertions(+), 11 deletions(-)
> 

Both patches have been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-03-04 20:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-29  9:37 [PATCH 0/2] phonesim: Add timer to set the variable with the delay Oleg Zhurakivskyy
2012-02-29  9:37 ` [PATCH 1/2] phonesim: Minor reflow in SimChat::command() Oleg Zhurakivskyy
2012-02-29  9:37 ` [PATCH 2/2] phonesim: Add timer to set the variable with the delay Oleg Zhurakivskyy
2012-03-04 20:56 ` [PATCH 0/2] " Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.