phoneengine/parserrecognizer/src/parserrecognizer.cpp
branchGCC_SURGE
changeset 51 f39ed5e045e0
parent 40 bab96b7ed1a4
parent 46 bc5a64e5bc3c
equal deleted inserted replaced
40:bab96b7ed1a4 51:f39ed5e045e0
     1 /*!
       
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Recognizes the parser messages that needs to be notified to 
       
    15 *               the world using QtHighway.
       
    16 */
       
    17 
       
    18 #include <xqservicerequest.h>
       
    19 #include <pevirtualengine.h>
       
    20 #include "parserrecognizer.h"
       
    21 #include "qtphonelog.h"
       
    22 
       
    23 ParserRecognizer::ParserRecognizer(QObject* parent) 
       
    24     : 
       
    25     QObject(parent),
       
    26     m_currentRequest(0)
       
    27 {
       
    28 }
       
    29 
       
    30 ParserRecognizer::~ParserRecognizer()
       
    31 {
       
    32     delete m_currentRequest;
       
    33 }
       
    34 
       
    35 void ParserRecognizer::sendMessage(const int message, const int callId)
       
    36 {
       
    37     Q_UNUSED(callId); // for now
       
    38     PHONE_DEBUG2("ParserRecognizer::sendMessage message:", message);
       
    39     QString api;
       
    40     QString method;
       
    41     bool recognized = true;
       
    42     
       
    43     switch(message) {
       
    44     case MEngineMonitor::EPEMessageActivateRfsDeep:
       
    45         api = "com.nokia.services.telephony";
       
    46         method = "activateDeepRestoreFactorySettings()";
       
    47         break;
       
    48     
       
    49     case MEngineMonitor::EPEMessageActivateRfsNormal:
       
    50         api = "com.nokia.services.telephony";
       
    51         method = "activateNormalRestoreFactorySettings()";
       
    52         break;
       
    53     
       
    54     case MEngineMonitor::EPEMessageShowBTDeviceAddress:
       
    55         api = "com.nokia.services.bluetooth";
       
    56         method = "showBluetoothDeviceAddress()";
       
    57         break;
       
    58     
       
    59     case MEngineMonitor::EPEMessageShowBTLoopback:
       
    60         api = "com.nokia.services.bluetooth";
       
    61         method = "showBluetoothLoopback()";
       
    62         break;
       
    63     
       
    64     case MEngineMonitor::EPEMessageBTDebugMode:
       
    65         api = "com.nokia.services.bluetooth";
       
    66         method = "activateBluetoothDebugMode()";
       
    67         break;
       
    68     
       
    69     case MEngineMonitor::EPEMessageShowVersion:
       
    70         api = "com.nokia.services.devicemanager";
       
    71         method = "showVersionNumber()";
       
    72         break;
       
    73     
       
    74     case MEngineMonitor::EPEMessageSSRequestFailed:
       
    75         api = "com.nokia.services.telephony";
       
    76         method = "supplementaryServiceRequestFailed()";
       
    77         break;
       
    78     
       
    79     default:
       
    80       recognized = false;
       
    81       break;        
       
    82     }
       
    83     
       
    84     if (recognized && (!m_currentRequest)) {
       
    85         PHONE_DEBUG2("ParserRecognizer::sendMessage api:", api);
       
    86         PHONE_DEBUG2("ParserRecognizer::sendMessage method:", method);
       
    87         m_currentRequest = new XQServiceRequest(api, method, false);
       
    88         // Due to a Qt Highway bug in assignment operator implementation we 
       
    89         // need to set request as asynchronous with a setter function.
       
    90         m_currentRequest->setSynchronous(false);
       
    91         connect(
       
    92             m_currentRequest, SIGNAL(requestCompleted(const QVariant &)), 
       
    93             this, SLOT(requestCompleted(const QVariant &)));
       
    94         connect(
       
    95             m_currentRequest, SIGNAL(requestError(int)), 
       
    96             this, SLOT(requestError(int)));
       
    97         
       
    98         int exceptionAsError = 0;
       
    99         bool requestOk = false;
       
   100         QT_TRYCATCH_ERROR(
       
   101             exceptionAsError, requestOk = m_currentRequest->send());
       
   102         if ((0 != exceptionAsError) || (!requestOk)) {
       
   103             PHONE_DEBUG2("ParserRecognizer::sendMessage exceptionAsError:", 
       
   104                 exceptionAsError);
       
   105             PHONE_DEBUG2("ParserRecognizer::sendMessage requestOk:", 
       
   106                 requestOk);
       
   107             requestCompleted(QVariant());
       
   108         }
       
   109     }
       
   110 }
       
   111 
       
   112 void ParserRecognizer::requestCompleted(const QVariant &returnValue)
       
   113 {
       
   114     PHONE_DEBUG("ParserRecognizer::requestCompleted");
       
   115     Q_UNUSED(returnValue);
       
   116     
       
   117     delete m_currentRequest;
       
   118     m_currentRequest = NULL;
       
   119 }
       
   120 
       
   121 void ParserRecognizer::requestError(int error)
       
   122 {
       
   123     PHONE_DEBUG2("ParserRecognizer::requestError", error);
       
   124     
       
   125     delete m_currentRequest;
       
   126     m_currentRequest = NULL;
       
   127 }