Example #1
0
  bool InBandBytestream::handleIq( const IQ& iq ) // data or open request, always 'set'
  {
    const IBB* i = iq.findExtension<IBB>( ExtIBB );
    if( !i || !m_handler || iq.subtype() != IQ::Set )
      return false;

    if( !m_open )
    {
      if( i->type() == IBBOpen )
      {
        returnResult( iq.from(), iq.id() );
        m_open = true;
        m_handler->handleBytestreamOpen( this );
        return true;
      }
      return false;
    }

    if( i->type() == IBBClose )
    {
      returnResult( iq.from(), iq.id() );
      closed();
      return true;
    }

    if( ( m_lastChunkReceived + 1 ) != i->seq() )
    {
      m_open = false;
      returnError( iq.from(), iq.id(), StanzaErrorTypeModify, StanzaErrorItemNotFound );
      return false;
    }

    if( i->data().empty() )
    {
      m_open = false;
      returnError( iq.from(), iq.id(), StanzaErrorTypeModify, StanzaErrorBadRequest );
      return false;
    }

    returnResult( iq.from(), iq.id() );
    m_handler->handleBytestreamData( this, i->data() );
    m_lastChunkReceived++;
    return true;
  }
Example #2
0
        virtual void ExecuteNativeCode()
        {
            TRACE_FUNCTION;
            AsyncErrorFunction errorResult = [this](const char * msg) {
                SetErrorMessage(msg);
            };

            AsyncReturnHelper returnResult(mReturnResult);
            mTask(returnResult, errorResult);
        }
Example #3
0
void CBaiduTranslater::translate(const QString &src, const QString from, const QString to)
{
    //if (m_networkAccessManager == nullptr)
        //return;

    /* create query url */
    QUrl url(m_url);
    QUrlQuery query;
    query.addQueryItem("from", from);
    query.addQueryItem("to", to);
    query.addQueryItem("client_id", m_client_id);
    query.addQueryItem("q", src);
    url.setQuery(query);

    // create http request header
    QNetworkRequest request(url);

    // send GET request to get result
    QNetworkReply *reply = m_networkAccessManager->get(request);

    /* return data */
    connect(reply, &QNetworkReply::readyRead, [=]{
        QByteArray data = reply->readAll();
        //qDebug(data);
        CBaiduTranslateResult result = decodeJsonData(data);

        emit finished(result);

        if (isCli)
        {
            tmpResult = result;
            returnResult();
        }

        reply->close();
    });

    /* finish request */
    connect(reply, &QNetworkReply::finished, [=]{
        reply->deleteLater();
    });

    /* error */
    auto pError = static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error);
    connect(reply, pError, [=](QNetworkReply::NetworkError){
        reply->deleteLater();
    });
}
Example #4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    progressBar = new QProgressBar(ui->statusBar);
    progressBar->setAlignment(Qt::AlignRight);
    progressBar->setMaximumSize(180, 19);
    ui->statusBar->addPermanentWidget(progressBar);
    progressBar->setValue(0);

    ui->pushButton_startStitch->setEnabled(false);

    connect(&watcher, SIGNAL(finished()), this, SLOT(returnResult()));
    connect(&stitch, SIGNAL(sendProgress(QString,int)), this, SLOT(progressBarStatus(QString,int)));
}
Example #5
0
/* 
 getresult(char *line);
 input: array of charecters line[], holds stdin from user or file
 output: returns interger evaluations of input expression or long min-long as error 
 overview: this function is basically a state machine with cases: no nums found, first num found, oporator found, seccond num found
 if cant find one then an error message with print and will wait for next input
 */
int getresult (char *line){
        numLen = 0, numLen2 = 0;i = 0; //reset globals for each itteration
        int firstN = 0, seccondN = 0;
        char oporator;
        short error = 0, neg = 1;
        short pass = 0;
        while(line[i] >= ' '  && error == 0){
                c = line[i];
                //if first interger has not been found either find valid integer or return error
                if(pass == 0){
                    if((c < '0' || c > '9') && c != ' ' && c != '-'|| (c == '-' && neg == -1)){
                        error = 1;
                        printf("calc Usage Error input %d: calc arguments are integer, operator(+-*/), integer\n",(pass+1));
                    }
		    else if(c == '-'){
			neg = -1;
			i++;
	            }
                    else if(c == ' '){
                        i++;;
                    }
                    else{
                        pass = 1;
			firstN = nextNum(line, pass);
                        firstN = reverse(firstN, numLen) * neg;
                    }
                }
                //if first integer has been found either find valid oporator or return error
                else if(pass == 1){
                    if(c != '+' && c != '-' && c != '*' && c != '/' && c != ' '){
                        error = 1;
                        printf("calc Usage Error input %d: calc arguments are integer, operator(+-*/), integer\n",(pass+1));
                    }
                    else if(c == ' '){
                        i++;
                    }
                    else{
                        pass = 2;
                        oporator = c;
                        i++;
                        c = line[i];
		        neg = 1;
                    }
                }
                //if oporator found either find valid integer or return error
                else if(pass == 2){
                   if((c < '0' || c > '9') && c != ' ' && c != '-'|| (c == '-' && neg == -1)){
                        error = 1;
                        printf("calc Usage Error input %d: calc arguments are integer, operator(+-*/), integer\n",(pass+1));
                    }
		    else if(c == '-'){
			neg = -1;
                        i++;
		    }
                    else if(c == ' '){
                        i++;
                    }
                    else{
                        pass = 3;
			seccondN = nextNum(line, pass);
                        seccondN = reverse(seccondN, numLen2);

                    }
                }
                //if seccond num foundcontinue to end of line make sure nothing else there
                else{
                   if(c != ' ' && c != '\0'){
                        error = 1;
                        printf("calc Usage Error3: calc arguments are integer, operator(+-*/), integer\n");
                    }
                    i++;
                }
        }
    return returnResult(firstN,seccondN,oporator,error,pass);
}
Example #6
0
MainWindow::~MainWindow()
{
    disconnect(&watcher, SIGNAL(finished()), this, SLOT(returnResult()));
    disconnect(&stitch, SIGNAL(sendProgress(QString,int)), this, SLOT(progressBarStatus(QString,int)));
    delete ui;
}
void launch_server() {
    int s = socket(AF_INET, SOCK_STREAM, 0);
    struct sockaddr_in a;

    memset(&a, 0, sizeof(struct sockaddr_in));
    a.sin_family = AF_INET;
    a.sin_port = 0;
    if((a.sin_addr.s_addr = getPublicIPAddr()) == 0) {
	fprintf(stderr, "Could not get public ip address. Exiting...\n");
	exit(0);
    }

    if(mybind(s, &a) < 0) {
	fprintf(stderr, "mybind() failed. Exiting...\n");
	exit(0);
    }

    printf("%s %u\n", inet_ntoa(a.sin_addr), ntohs(a.sin_port));
    
    if(listen(s, 0) < 0) {
	perror("listen"); exit(0);
    }

    memset(&a, 0, sizeof(struct sockaddr_in));
    socklen_t alen = sizeof(struct sockaddr_in);
    int asock = -1;
    while((asock = accept(s, (struct sockaddr *)&a, &alen)) > 0) {
	/* Single-threaded */

	char *fname;
	int nparams;
	arg_type *a = NULL;
	return_type ret;

	recvCall(asock, &fname, &nparams, &a);

#ifdef _DEBUG_1_
	printf("launch_server(), before makeCall()\n"); fflush(stdout);
#endif

	makeCall(fname, nparams, a, &ret);

#ifdef _DEBUG_1_
	printf("launch_server(), after makeCall()\n"); fflush(stdout);
#endif

	returnResult(asock, &ret);

	free(fname);
	freeArgs(a);
	freeRet(ret);

	shutdown(asock, SHUT_RDWR); close(asock);
	asock = -1;
    }

    /* WARNING -- massive memory, linked list of registered
     * functions! We assume that the process exits at this
     * point, and so do not bother freeing the memory. */
    return;
}
status_t ResultProcessor::handleMetadataDone(Message &msg)
{
    status_t status = NO_ERROR;
    Camera3Request* request = msg.request;
    int reqId = request->getId();
    LOGR("%s for <Request %d>", __FUNCTION__, reqId);

    int index = mRequestsInTransit.indexOfKey(reqId);
    if (index == NAME_NOT_FOUND) {
        LOGE("Request %d was not registered:find the bug", reqId);
        return BAD_VALUE;
    }
    RequestState_t *reqState = mRequestsInTransit.valueAt(index);

    if (msg.data.meta.resultIndex >= 0) {
        /**
         * New Partial metadata result path. The result buffer is not the
         * settings but a separate buffer stored in the request.
         * The resultIndex indicates which one.
         * This can be returned straight away now that we have declared 3.2
         * device version. No need to enforce the order between shutter events
         * result and buffers. We do not need to store the partials either.
         * we can return them directly
         */
        status = returnResult(reqState, msg.data.meta.resultIndex);
        return status;
    }
    /**
     * FROM THIS POINT TO THE END OF THIS METHOD IS OLD CODE PATH
     * This code path will be clean up once all PSL implement the return of
     * metadata results using a different buffer than the settings buffer
     */
    ReadWriteRequest rwRequest(request);
    reqState->pendingPartialResults.add(&rwRequest.mMembers.mSettings);
    LOGR(" <Request %d> Metadata arrived %d/%d", reqId,
            reqState->pendingPartialResults.size(),mPartialResultCount);
    /**
     * <v3.1 behavior>
     * metadata is only returned to client if shutter notification has already
     * been given to client as well. Leave now as we have already stored it
     * to the pending partial vector.
     */
    if (!reqState->isShutterDone) {
        LOGR("metadata arrived before shutter, storing");
        return NO_ERROR;
    }

    /**
     * <v3.1 behavior>
     * Return metadata when all partial results have been accumulated. This
     * is only 1 currently . No partial results possible yet
     */
    unsigned int resultsReceived = reqState->pendingPartialResults.size();
    bool allMetaReceived = (resultsReceived == mPartialResultCount);

    if (allMetaReceived) {
        returnPendingPartials(reqState);
    }

    bool allMetadataDone = (reqState->partialResultReturned == mPartialResultCount);
    bool allBuffersDone = (reqState->buffersReturned == reqState->buffersToReturn);
    if (allBuffersDone && allMetadataDone) {
        status = recycleRequest(request);
    }

    /**
     * if the metadata done for the next request is available then send it.
     *
     */
    if (allMetadataDone) {
        returnStoredPartials();
    }

    return status;
}
UtlBoolean TaoPhoneComponentAdaptor::handleMessage(OsMsg& rMsg)
{
        UtlBoolean handled = FALSE;
        int msgType = ((TaoMessage&)rMsg).getMsgSubType();

        if( TaoMessage::REQUEST_PHONECOMPONENT == msgType)
        {
                switch (((TaoMessage&)rMsg).getCmd())
                {
                case TaoMessage::BUTTON_PRESS:
                        if (TAO_SUCCESS == buttonPress((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::BUTTON_UP:
                        if (TAO_SUCCESS == buttonUp((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::BUTTON_DOWN:
                        if (TAO_SUCCESS == buttonDown((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::BUTTON_GET_INFO:
                        if (TAO_SUCCESS == getButtonInfo((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::BUTTON_SET_INFO:
                        if (TAO_SUCCESS == setButtonInfo((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::BUTTON_GET_PHONELAMP:
                        if (TAO_SUCCESS == getAssociatedPhoneLamp((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::HOOKSWITCH_GET_STATE:
                        if (TAO_SUCCESS == getHookswState((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::HOOKSWITCH_SET_STATE:
                        if (TAO_SUCCESS == setHookswState((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::HOOKSWITCH_GET_CALL:
                        if (TAO_SUCCESS == getHookswCall((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::LAMP_GET_MODE:
                        if (TAO_SUCCESS == getHookswCall((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::LAMP_GET_SUPPORTED_MODES:
                        if (TAO_SUCCESS == getHookswCall((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::LAMP_GET_BUTTON:
                        if (TAO_SUCCESS == getHookswCall((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::LAMP_SET_MODE:
                        if (TAO_SUCCESS == setLampMode((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
        /* ----------------------------- PHONEDISPALY --------------------------------- */
                case TaoMessage::DISPLAY_GET_DISPLAY:
                        if (TAO_SUCCESS == getDisplay((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::DISPLAY_GET_ROWS:
                        if (TAO_SUCCESS == getDisplayRows((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::DISPLAY_GET_COLS:
                        if (TAO_SUCCESS == getDisplayColumns((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::DISPLAY_SET_DISPLAY:
                        if (TAO_SUCCESS == setDisplay((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::DISPLAY_GET_CONTRAST:
                        if (TAO_SUCCESS == getDisplayContrast((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::DISPLAY_SET_CONTRAST:
                        if (TAO_SUCCESS == setDisplayContrast((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
        /* ----------------------------- PHONEMIC --------------------------------- */
                case TaoMessage::MIC_GET_GAIN:
                        if (TAO_SUCCESS == getMicGain((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::MIC_SET_GAIN:
                        if (TAO_SUCCESS == setMicGain((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
        /* ----------------------------- PHONERINGER --------------------------------- */
                case TaoMessage::RINGER_SET_INFO:
                        if (TAO_SUCCESS == setRingerInfo((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_SET_PATTERN:
                        if (TAO_SUCCESS == setRingerPattern((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_SET_VOLUME:
                        if (TAO_SUCCESS == setRingerVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_GET_INFO:
                        if (TAO_SUCCESS == getRingerInfo((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_GET_PATTERN:
                        if (TAO_SUCCESS == getRingerPattern((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_GET_VOLUME:
                        if (TAO_SUCCESS == getRingerVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_GET_MAX_PATTERN_INDEX:
                        if (TAO_SUCCESS == getMaxRingPatternIndex((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_GET_NUMBER_OF_RINGS:
                        if (TAO_SUCCESS == getNumberOfRings((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_IS_ON:
                        if (TAO_SUCCESS == isRingerOn((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
        /* ----------------------------- PHONESPEAKER --------------------------------- */
                case TaoMessage::SPEAKER_SET_VOLUME:
                        if (TAO_SUCCESS == setSpeakerVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::SPEAKER_GET_VOLUME:
                        if (TAO_SUCCESS == getSpeakerVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::SPEAKER_GET_NOMINAL_VOLUME:
                        if (TAO_SUCCESS == getSpeakerNominalVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
        /* ----------------------------- PHONEEXTSPEAKER --------------------------------- */
                case TaoMessage::EXTSPEAKER_SET_VOLUME:
                        if (TAO_SUCCESS == setExtSpeakerVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::EXTSPEAKER_GET_VOLUME:
                        if (TAO_SUCCESS == getExtSpeakerVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::EXTSPEAKER_GET_NOMINAL_VOLUME:
                        if (TAO_SUCCESS == getExtSpeakerNominalVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
        /* ----------------------------- PHONEGROUP --------------------------------- */
                case TaoMessage::PHONEGROUP_ACTIVATE:
                        if (TAO_SUCCESS == activateGroup((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::PHONEGROUP_DEACTIVATE:
                        if (TAO_SUCCESS == deactivateGroup((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::PHONEGROUP_GET_COMPONENTS:
                        if (TAO_SUCCESS == getGroupComponents((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::PHONEGROUP_GET_DESCRIPTION:
                        if (TAO_SUCCESS == getGroupDescription((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::PHONEGROUP_GET_TYPE:
                        if (TAO_SUCCESS == getGroupType((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::PHONEGROUP_IS_ACTIVATED:
                        if (TAO_SUCCESS == isGroupActivated((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::COMPONENT_RESULT:
                        if (TAO_SUCCESS == returnResult((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;

                default:
                  break;
                }
        }
        else if (TaoMessage::RESPONSE_PHONECOMPONENT == msgType)
        {
                if (TAO_SUCCESS == returnResult((TaoMessage&)rMsg))
                        handled = TRUE;
        }

        if (!handled)
        {
                TaoMessage*     pMsg = (TaoMessage*) &rMsg;

                pMsg->setArgCnt(1);
                pMsg->setArgList("-1");

                if (mpSvrTransport->postMessage(*pMsg))
                        handled = TRUE;
        }

        return handled;
}