phonesim: Refactor SimApplication api, add a UI.
PATCH 2/2 phonesim: Refactor SimApplication api, add a UI.
Try to move all the AT parsing / generating out of applications, just send ready envelopes, terminal responses, commands between the application and the SimRules class.
--- src/control.cpp | 35 +++++++++++ src/control.h | 1 + src/controlbase.ui | 71 ++++++++++++++++++++++ src/hardwaremanipulator.cpp | 42 +++++++++++++ src/hardwaremanipulator.h | 7 ++ src/phonesim.cpp | 138 +++++++++++++++++++++++++++++++++++++++---- src/phonesim.h | 6 ++ src/simapplication.cpp | 137 ++++++++++++++---------------------------- src/simapplication.h | 27 +++++---- 9 files changed, 349 insertions(+), 115 deletions(-)
src/control.cpp +35 -0
@@ -49,6 +49,7 @@ public: void handleFromData( const QString& ); void handleToData( const QString& ); + void handleNewApp(); private slots: void sendSQ();
@@ -70,6 +71,9 @@ private slots: void sendEVMNotify(); void sendUSSD(); void cancelUSSD(); + void simInsertRemove(); + void simAppStart(); + void simAppAbort(); signals: void unsolicitedCommand(const QString &);
@@ -134,12 +138,17 @@ ControlWidget::ControlWidget(const QString &ruleFile, Control *parent) connect(ui->pbNotifyUDHEnhanced, SIGNAL(clicked()), this, SLOT(sendEVMNotify())); connect(ui->pbSendUSSD, SIGNAL(clicked()), this, SLOT(sendUSSD())); connect(ui->pbCancelUSSD, SIGNAL(clicked()), this, SLOT(cancelUSSD())); + connect(ui->cbSimInserted, SIGNAL(clicked()), this, SLOT(simInsertRemove())); + connect(ui->pbStart, SIGNAL(clicked()), this, SLOT(simAppStart())); + connect(ui->pbAbort, SIGNAL(clicked()), this, SLOT(simAppAbort())); QStringList headers; headers << "Sender" << "Priority" << "Notification Status"; ui->twMessageList->setHorizontalHeaderLabels( headers ); ui->twMessageList->verticalHeader()->hide(); + handleNewApp(); + show(); }
@@ -473,3 +482,29 @@ void ControlWidget::cancelUSSD() ui->lblResponse->setText( "" ); ui->leUSSDString->setText( "" ); } + +void ControlWidget::simInsertRemove() +{ + p->setSimPresent( ui->cbSimInserted->isChecked() ); +} + +void ControlWidget::handleNewApp() +{ + ui->lblApplicationName->setText( "Current application: " + + p->getSimAppName() ); +} + +void Control::handleNewApp() +{ + widget->handleNewApp(); +} + +void ControlWidget::simAppStart() +{ + p->simAppStart(); +} + +void ControlWidget::simAppAbort() +{ + p->simAppAbort(); +}
src/control.h +1 -0
@@ -36,6 +36,7 @@ public slots: void handleFromData( const QString& ); void handleToData( const QString& ); void setPhoneNumber( const QString& ); +void handleNewApp (); protected: virtual void warning( const QString&, const QString& );
src/controlbase.ui +71 -0
77 lines not on this page · raw message
src/hardwaremanipulator.cpp +42 -0
57 lines not on this page · raw message
src/hardwaremanipulator.h +7 -0
@@ -34,6 +34,8 @@ Q_OBJECT public:HardwareManipulator (SimRules *sr, QObject *parent=0 ); QSMSMessageList &getSMSList (); +bool getSimPresent (); +QString getSimAppName (); public slots: virtual void handleFromData( const QString& );
@@ -43,6 +45,10 @@ public slots: virtual void sendSMS( const QSMSMessage& m ); virtual void sendVMNotify( int type, int count, const QList<QVMMessage> &received, const QList<QVMMessage> &deleted, const QString &mailbox ); virtual void sendUSSD( bool cancel, bool response, const QString &content ); + virtual void setSimPresent( bool present ); + virtual void simAppStart(); + virtual void simAppAbort(); + virtual void handleNewApp(); signals: void unsolicitedCommand(const QString &cmd);
@@ -63,6 +69,7 @@ protected: private:QSMSMessageList SMSList;SimRules *rules; +bool simPresent; };class HardwareManipulatorFactory
src/phonesim.cpp +127 -11
197 lines not on this page · raw message
src/phonesim.h +6 -0
@@ -31,6 +31,7 @@#include <qmap.h> #include <qtimer.h> #include <qpointer.h> +#include <qsimcontrolevent.h> #include <string.h> #include <stdlib.h>
@@ -307,6 +308,9 @@ public slots:// Send a response line. void respond( const QString& resp ) { respond( resp, 0 ); } + void proactiveCommandNotify( const QByteArray& cmd ); + void callControlEventNotify( const QSimControlEvent& event ); + private slots:void tryReadCommand ();void destruct ();
@@ -352,6 +356,8 @@ private: QMap< QString, SimPhoneBook * > phoneBooks;CallManager *_callManager; + + bool simCsimOk( const QByteArray& payload ); };
src/simapplication.cpp +45 -92
203 lines not on this page · raw message
src/simapplication.h +15 -12
@@ -31,41 +31,44 @@ class SimApplicationPrivate; class SimApplication : public QObject {Q_OBJECT - friend class SimRules; public: -SimApplication ( QObject *parent =0 ); + SimApplication( SimRules *rules, QObject *parent = 0 ); ~SimApplication (); - void command( const QSimCommand& cmd, -QObject *target,const char *slot, - QSimCommand::ToPduOptions options - = QSimCommand::NoPduOptions ); + virtual bool envelope( const QSimEnvelope& env ); + virtual bool response( const QSimTerminalResponse& resp ); + virtual QByteArray fetch( bool clear = false ); + + virtual const QString getName() = 0; public slots: - void controlEvent( const QSimControlEvent& event ); virtual void start(); virtual void abort(); protected slots: + void command( const QSimCommand& cmd, +QObject *target,const char *slot, + QSimCommand::ToPduOptions options + = QSimCommand::NoPduOptions ); + void controlEvent( const QSimControlEvent& event ); + virtual void mainMenu() = 0; virtual void mainMenuSelection( int id ); virtual void mainMenuHelpRequest( int id ); private:SimApplicationPrivate *d; - -void setSimRules (SimRules *rules ); - bool execute( const QString& cmd ); - void response( const QSimTerminalResponse& resp ); }; class DemoSimApplication : public SimApplication {Q_OBJECT public: - DemoSimApplication( QObject *parent = 0 ); + DemoSimApplication( SimRules *rules, QObject *parent = 0 ); ~DemoSimApplication (); +const QString getName (); + protected slots:void mainMenu ();void mainMenuSelection (int id );
Signature · 1 line
1.6.1
Hi Andrew,
Quoted 16 lines
Try to move all the AT parsing / generating out of applications, just send ready envelopes, terminal responses, commands between the application and the SimRules class.
--- src/control.cpp | 35 +++++++++++ src/control.h | 1 + src/controlbase.ui | 71 ++++++++++++++++++++++ src/hardwaremanipulator.cpp | 42 +++++++++++++ src/hardwaremanipulator.h | 7 ++ src/phonesim.cpp | 138 +++++++++++++++++++++++++++++++++++++++---- src/phonesim.h | 6 ++ src/simapplication.cpp | 137 ++++++++++++++---------------------------- src/simapplication.h | 27 +++++---- 9 files changed, 349 insertions(+), 115 deletions(-)
This patch has now been applied, thanks.
Regards,
-Denis