void ItemAttributeMgr::SetRealEx(Attr attr, const real_t &v, bool persist) {
    // first check if it can be stored as integer
    if(_IsInt(v)) {
        // store as integer
        SetIntEx(attr, static_cast<int32>(v), persist);
    } else {
        // store as real
        PyRep *oldValue = NULL;
        if(GetNotify() == true && !IsRechargable(attr)) {
            // get old value
            oldValue = PyGet(attr);
        }
        // set the attribute value
        EVEAdvancedAttributeMgr::SetReal(attr, v);
        // check if we shall save to DB
        if(GetSave() == true && (persist || IsPersistent(attr))) {
            // save to DB
            m_factory.db().UpdateAttribute_double(m_item.itemID(), attr, v);
        }
        if(GetNotify() == true) {
            std::map<Attr, TauCap>::const_iterator i = m_tauCap.find(attr);
            if(i != m_tauCap.end()) {
                // build the special list for rechargables
                PyList *l = new PyList;

                l->AddItemReal( v );
                l->AddItemLong( Win32TimeNow() );
                l->AddItem( _PyGet( GetReal( i->second.tau ) / 5.0 ) );
                l->AddItem( PyGet( i->second.cap ) );

                oldValue = l;
            }
            // send change
            _SendAttributeChange(attr, oldValue, new PyFloat(v));
        }
    }
}
/*
 * Creates a new HTTP ProtocolHeaders event and enqueues it in HTTPProtocolHeadersEventQ
 *
 * @param protocolInfo
 *
 * @return bool
 */
bool HTTPSourceMMIExtensionEventHandler::HTTPProtocolHeadersEventManager::SetHTTPProtocolHeadersEvent
(
  HTTPSourceMMIHelper *pHTTPSourceMMIHelper,
  void *protocolHeadersEventInfo,
  void *pClientData
)
{
  bool rsltCode = false;
  HTTPStackNotificationCbData *protocolData = (HTTPStackNotificationCbData*)protocolHeadersEventInfo;

  if (GetNotify())
  {
    HTTPProtocolHeadersEvent protocolHeaderEvent = { protocolData->m_msgType,
                                                     protocolData->m_method,
                                                     protocolData->m_protocolHeaders};

    rsltCode = m_eventQManager.Enqueue(protocolHeaderEvent);
    if (rsltCode)
    {
       rsltCode = HTTPSourceMMIExtensionEventHandler::NotifyEvent(pHTTPSourceMMIHelper,
                                                                 OMX_ALL,
                                                                 QOMX_HTTP_IndexConfigStreamingProtocolHeadersEvent,
                                                                 pClientData);
      QTV_MSG_PRIO( QTVDIAG_STREAMING, QTVDIAG_PRIO_MEDIUM,
                     "HTTP ProtocolHeader Event Queued:" );
    }
    else
    {
      if (pHTTPSourceMMIHelper)
      {
        pHTTPSourceMMIHelper->ProcessAuthHandlingDiscarded();
        QTV_MSG_PRIO( QTVDIAG_STREAMING, QTVDIAG_PRIO_HIGH,
                   "HTTPProtocolHeadersEventManager: Auth handling would be discarded");
      }
    }
  }
  else
  {
    if (pHTTPSourceMMIHelper)
    {
      pHTTPSourceMMIHelper->ProcessAuthHandlingDiscarded();
      QTV_MSG_PRIO( QTVDIAG_STREAMING, QTVDIAG_PRIO_LOW,
                  "HTTPProtocolHeadersEventManager: Dropping the Protocol HeadersEvent");
    }
  }
  return rsltCode;
}
LRESULT CPPNumEdit::SendNotify(UINT uNotifyCode)
{
	TRACE(_T("CPPNumEdit::SendNotify()\t%X\n"), uNotifyCode);

	if (uNotifyCode >= PPNUMEDIT_MAX_EVENTS)
		return 0;

	//If the notification code is not CANCEL or the editing value is not validate
	//then don't send the notification
	if ((uNotifyCode != PPNUMEDIT_CANCEL_DATA) && (!IsValidate()))
		return 0;

	// Make sure this is a valid window
	if (!IsWindow(GetSafeHwnd()))
		return 0;

	// See if the user wants to be notified
	if (GetNotify() == FALSE)
		return 0;

	NM_PPNUM_EDIT lpnm;
	
	lpnm.iValue		  = GetValue();
	lpnm.iEvent		  = uNotifyCode;
	lpnm.hdr.hwndFrom = m_hWnd;
    lpnm.hdr.idFrom   = GetDlgCtrlID();

	if (uNotifyCode == PPNUMEDIT_CANCEL_DATA)
		lpnm.hdr.code = UDM_PPNUMEDIT_CANCEL;
	else if (uNotifyCode == PPNUMEDIT_ENTER_DATA)
		lpnm.hdr.code = UDM_PPNUMEDIT_ENTER;
	else if (uNotifyCode < PPNUMEDIT_HOTKEY_HEX)
		lpnm.hdr.code = UDM_PPNUMEDIT_MOVE;
	else lpnm.hdr.code = UDM_PPNUMEDIT_HOTKEY;


	CWnd *pOwner = GetOwner();
    if (pOwner && IsWindow(pOwner->m_hWnd))
        return pOwner->SendMessage(WM_NOTIFY, lpnm.hdr.idFrom, (LPARAM)&lpnm);
    else
        return 0;
}
bool ItemAttributeMgr::Load(bool notify) {

    // save & set notify state
    bool old_notify = GetNotify();
    SetNotify(notify);

    // save & set save state
    bool old_save = GetSave();
    SetSave(false);

    // delete old contents
    EVEAdvancedAttributeMgr::Delete();
    // load the new contents
    bool res = m_factory.db().LoadItemAttributes(item().itemID(), *this);

    // restore save state
    SetSave(old_save);

    // restore notify state
    SetNotify(old_notify);

    return res;
}
Exemple #5
0
int audio_thread(void *param)
{
    SND_EVENT evnt;

    int       buffsize;
    int      samples;
    int       err;
    char     *errstr;
    int       active;

    if((err = CreateBuffer(snd_format|PCM_RING,0, &hBuff)) != 0)
    {
        errstr = "Cannot create sound buffer\n\r";
        goto exit_whith_error;
    };

    SetVolume(hBuff,-900,-900);

    if((err = GetBufferSize(hBuff, &buffsize)) != 0)
    {
        errstr = "Cannot get buffer size\n\r";
        goto exit_whith_error;
    };

    __sync_or_and_fetch(&threads_running,AUDIO_THREAD);

    resampler_size = buffsize = buffsize/2;

    samples = buffsize/4;

    while( player_state != CLOSED)
    {
        uint32_t  offset;
        double    event_stamp, wait_stamp;
        int       too_late = 0;

        switch(sound_state)
        {
            case PREPARE:

                mutex_lock(&astream.lock);
                    if(astream.count < buffsize*2)
                    {
                        memset(astream.buffer+astream.count,
                               0, buffsize*2-astream.count);
                        astream.count = buffsize*2;
                    };

                    SetBuffer(hBuff, astream.buffer, 0, buffsize*2);
                    astream.count -= buffsize*2;
                    if(astream.count)
                        memcpy(astream.buffer, astream.buffer+buffsize*2, astream.count);
                mutex_unlock(&astream.lock);

                SetTimeBase(hBuff, audio_base);

            case PAUSE_2_PLAY:
                GetTimeStamp(hBuff, &last_time_stamp);
//                printf("last audio time stamp %f\n", last_time_stamp);

                if((err = PlayBuffer(hBuff, 0)) !=0 )
                {
                    errstr = "Cannot play buffer\n\r";
                    goto exit_whith_error;
                };
                active = 1;
                sync_audio(hBuff, buffsize);
                sound_state = PLAY;
//                printf("render: set audio latency to %f\n", audio_delta);

                /* breaktrough */

            case PLAY:
                GetNotify(&evnt);

                if(evnt.code != 0xFF000001)
                {
                    printf("invalid event code %d\n\r", evnt.code);
                    continue;
                }

                if(evnt.stream != hBuff)
                {
                    printf("invalid stream %x hBuff= %x\n\r",
                            evnt.stream, hBuff);
                    continue;
                };

                offset = evnt.offset;

                mutex_lock(&astream.lock);
                if(astream.count < buffsize)
                {
                    memset(astream.buffer+astream.count,
                           0, buffsize-astream.count);
                    astream.count = buffsize;
                };

                SetBuffer(hBuff, astream.buffer, offset, buffsize);

                {
                    double  val = 0;
                    int16_t *src = (int16_t*)astream.buffer;
                    int samples = buffsize/2;
                    int i;

                    for(i = 0, val = 0; i < samples/2; i++, src++)
                        if(val < abs(*src))
                            val= abs(*src); // * *src;

                    sound_level_0 = val; //sqrt(val / (samples/2));

                    for(i = 0, val = 0; i < samples/2; i++, src++)
                        if(val < abs(*src))
                            val= abs(*src); // * *src;

                    sound_level_1 = val; //sqrt(val / (samples/2));

 //                   printf("%d\n", sound_level);
                };

                samples_written+= buffsize/4;

                astream.count -= buffsize;
                if(astream.count)
                    memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
                mutex_unlock(&astream.lock);
                break;

            case PLAY_2_STOP:
                if( active )
                {
                    ResetBuffer(hBuff, SND_RESET_ALL);
                    audio_base = -1.0;
                    active = 0;
                }
                sound_state = STOP;
                break;

            case PLAY_2_PAUSE:
                if( active )
                {
                    StopBuffer(hBuff);
                };
                sound_state = PAUSE;

            case PAUSE:
            case STOP:
                delay(1);
        };
    }

    __sync_and_and_fetch(&threads_running,~AUDIO_THREAD);

    StopBuffer(hBuff);
    DestroyBuffer(hBuff);

    return 0;

exit_whith_error:

    printf(errstr);
    return -1;

};
Exemple #6
0
void TSAppSrv::OnHttpRq(const uint64& SockId, const PHttpRq& HttpRq) {
	// last appropriate error code, start with bad request
	int ErrStatusCd = THttp::BadRqStatusCd;
    try {
        // check http-request correctness - return if error
        EAssertR(HttpRq->IsOk(), "Bad HTTP request!");
        // check url correctness - return if error
		PUrl HttpRqUrl = HttpRq->GetUrl();
		EAssertR(HttpRqUrl->IsOk(), "Bad request URL!");
        // extract function name
		TStr FunNm = HttpRqUrl->GetPathSeg(0);
		// check if we have the function registered
		if (FunNm == "favicon.ico") {
			PHttpResp HttpResp = THttpResp::New(THttp::OkStatusCd,
				THttp::ImageIcoFldVal, false, Favicon.GetSIn());
			SendHttpResp(SockId, HttpResp); 
			return;
		} else if (!FunNm.Empty() && !FunNmToFunH.IsKey(FunNm)) { 
			ErrStatusCd = THttp::ErrNotFoundStatusCd;
			GetNotify()->OnStatusFmt("[AppSrv] Unknown function '%s'!", FunNm.CStr());
			TExcept::Throw("Unknown function '" + FunNm + "'!");
		}
        // extract parameters
        PUrlEnv HttpRqUrlEnv = HttpRq->GetUrlEnv();
		TStrKdV FldNmValPrV; HttpRqUrlEnv->GetKeyValPrV(FldNmValPrV);
        
		// report call
		if (ShowParamP) {  GetNotify()->OnStatus(HttpRq->GetUrl()->GetUrlStr()); }
		// request parsed well, from now on it's internal error
		ErrStatusCd = THttp::InternalErrStatusCd;
		// processed requested function
		if (!FunNm.Empty()) {
			// prepare request environment
			PSAppSrvRqEnv RqEnv = TSAppSrvRqEnv::New(this, SockId, HttpRq, FunNmToFunH);
			// retrieve function
			PSAppSrvFun SrvFun = FunNmToFunH.GetDat(FunNm);
			// call function
			SrvFun->Exec(FldNmValPrV, RqEnv);
		} else {
			// internal SAppSrv call
			if (!ListFunP) {
				// we are not allowed to list functions
				ErrStatusCd = THttp::ErrNotFoundStatusCd;
				TExcept::Throw("Unknown page");
			}
			// prepare a list of registered functions
            PJsonVal FunArrVal = TJsonVal::NewArr();
			int KeyId = FunNmToFunH.FFirstKeyId();
			while (FunNmToFunH.FNextKeyId(KeyId)) {
                FunArrVal->AddToArr(TJsonVal::NewObj("name", FunNmToFunH.GetKey(KeyId)));
			}
            PJsonVal ResVal = TJsonVal::NewObj();
            ResVal->AddToObj("port", GetPortN());
            ResVal->AddToObj("connections", GetConns());            
            ResVal->AddToObj("functions", FunArrVal);
			TStr ResStr = ResVal->SaveStr();
			// prepare response
			PHttpResp HttpResp = THttpResp::New(THttp::OkStatusCd, 
				THttp::AppJSonFldVal, false, TMIn::New(ResStr));
			// send response
			SendHttpResp(SockId, HttpResp); 
		}
    } catch (PExcept Except) {
		// known internal error
		TNotify::StdNotify->OnNotifyFmt(ntErr, "Error: %s", Except->GetMsgStr().CStr());
		TNotify::StdNotify->OnNotifyFmt(ntErr, "Error location info: %s", Except->GetLocStr().CStr());

        PJsonVal ErrorVal = TJsonVal::NewObj();
        ErrorVal->AddToObj("message", Except->GetMsgStr());
        ErrorVal->AddToObj("location", Except->GetLocStr());
        PJsonVal ResVal = TJsonVal::NewObj("error", ErrorVal);
        TStr ResStr = ResVal->SaveStr();
        // prepare response
		PHttpResp HttpResp = THttpResp::New(ErrStatusCd,
            THttp::AppJSonFldVal, false, TMIn::New(ResStr));
        // send response
	    SendHttpResp(SockId, HttpResp);
    } catch (...) {
		TNotify::StdNotify->OnNotify(ntErr, "Unknown internal error");
		// unknown internal error
        PJsonVal ResVal = TJsonVal::NewObj("error", "Unknown internal error");
        TStr ResStr = ResVal->SaveStr();
        // prepare response
		PHttpResp HttpResp = THttpResp::New(ErrStatusCd,
            THttp::AppJSonFldVal, false, TMIn::New(ResStr));
        // send response
	    SendHttpResp(SockId, HttpResp);
    }
}
Exemple #7
0
void TSAppSrv::OnHttpRq(const uint64& SockId, const PHttpRq& HttpRq) {
	// last appropriate error code, start with bad request
	int ErrStatusCd = THttp::BadRqStatusCd;
    try {
        // check http-request correctness - return if error
        EAssertR(HttpRq->IsOk(), "Bad HTTP request!");
        // check url correctness - return if error
        PUrl RqUrl = HttpRq->GetUrl();
        EAssertR(RqUrl->IsOk(), "Bad request URL!");
        // extract function name
        PUrl HttpRqUrl = HttpRq->GetUrl();
        TStr FunNm = HttpRqUrl->GetPathSeg(0);
		// check if we have the function registered
		if (FunNm == "favicon.ico") {
			PHttpResp HttpResp = THttpResp::New(THttp::OkStatusCd,
				THttp::ImageIcoFldVal, false, Favicon.GetSIn());
			SendHttpResp(SockId, HttpResp); 
			return;
		} else if (!FunNm.Empty() && !FunNmToFunH.IsKey(FunNm)) { 
			ErrStatusCd = THttp::ErrNotFoundStatusCd;
			GetNotify()->OnStatusFmt("[AppSrv] Unknown function '%s'!", FunNm.CStr());
			TExcept::Throw("Unknown function '" + FunNm + "'!");
		}
        // extract parameters
        TStrKdV FldNmValPrV;
        PUrlEnv HttpRqUrlEnv = HttpRq->GetUrlEnv();
        const int Keys = HttpRqUrlEnv->GetKeys();
        for (int KeyN = 0; KeyN < Keys; KeyN++) {
            TStr KeyNm = HttpRqUrlEnv->GetKeyNm(KeyN);
            const int Vals = HttpRqUrlEnv->GetVals(KeyN);
            for (int ValN = 0; ValN < Vals; ValN++) {
                TStr Val = HttpRqUrlEnv->GetVal(KeyN, ValN);
                FldNmValPrV.Add(TStrKd(KeyNm, Val));
            }
        }
		// report call
		if (ShowParamP) {  GetNotify()->OnStatus(" " + HttpRq->GetUrl()->GetUrlStr()); }
		// request parsed well, from now on it's internal error
		ErrStatusCd = THttp::InternalErrStatusCd;
		// processed requested function
		if (!FunNm.Empty()) {
			// prepare request environment
			PSAppSrvRqEnv RqEnv = TSAppSrvRqEnv::New(this, SockId, HttpRq, FunNmToFunH);
			// retrieve function
			PSAppSrvFun SrvFun = FunNmToFunH.GetDat(FunNm);
			// call function
			SrvFun->Exec(FldNmValPrV, RqEnv);
		} else {
			// internal SAppSrv call
			if (!ListFunP) {
				// we are not allowed to list functions
				ErrStatusCd = THttp::ErrNotFoundStatusCd;
				TExcept::Throw("Unknown page");
			}
			// prepare a list of registered functions
			PXmlTok TopTok = TXmlTok::New("registered-functions");
			int KeyId = FunNmToFunH.FFirstKeyId();
			while (FunNmToFunH.FNextKeyId(KeyId)) {
				PXmlTok FunTok = TXmlTok::New("function");
				FunTok->AddArg("name", FunNmToFunH.GetKey(KeyId));
				TopTok->AddSubTok(FunTok);
			}
			TStr ResXmlStr; TXmlDoc::New(TopTok)->SaveStr(ResXmlStr);
			PSIn BodySIn = TMIn::New(TSAppSrvFun::XmlHdStr + ResXmlStr);
			// prepare response
			PHttpResp HttpResp = THttpResp::New(THttp::OkStatusCd, 
				THttp::TextXmlFldVal, false, BodySIn);
			// send response
			SendHttpResp(SockId, HttpResp); 
		}
    } catch (PExcept Except) {
		// known internal error
		PXmlTok TopTok = TXmlTok::New("error");
		TopTok->AddSubTok(TXmlTok::New("message", Except->GetMsgStr()));
		TopTok->AddSubTok(TXmlTok::New("location", Except->GetLocStr()));
		PXmlDoc ErrorXmlDoc = TXmlDoc::New(TopTok); 
        TStr ResXmlStr; ErrorXmlDoc->SaveStr(ResXmlStr);
        // prepare response
		PHttpResp HttpResp = THttpResp::New(ErrStatusCd, 
            THttp::TextHtmlFldVal, false, 
			TMIn::New(TSAppSrvFun::XmlHdStr + ResXmlStr));
        // send response
	    SendHttpResp(SockId, HttpResp); 
    } catch (...) {
		// unknown internal error
		PXmlDoc ErrorXmlDoc = TXmlDoc::New(TXmlTok::New("error")); 
        TStr ResXmlStr; ErrorXmlDoc->SaveStr(ResXmlStr);
        // prepare response
        PHttpResp HttpResp = THttpResp::New(ErrStatusCd, 
            THttp::TextHtmlFldVal, false, 
			TMIn::New(TSAppSrvFun::XmlHdStr + ResXmlStr));
        // send response
	    SendHttpResp(SockId, HttpResp); 
    }
}
Exemple #8
0
void TSAppSrv::OnHttpRq(const int& SockId, const PHttpRq& HttpRq) {
    PHttpResp HttpResp;
    try {
        // check http-request correctness - return if error
        EAssertR(HttpRq->IsOk(), "Bad HTTP request!");
        // check url correctness - return if error
        PUrl RqUrl = HttpRq->GetUrl();
        EAssertR(RqUrl->IsOk(), "Bad request URL!");
        // extract function name
        PUrl HttpRqUrl = HttpRq->GetUrl();
        TStr FunNm = HttpRqUrl->GetPathSeg(0);
        EAssertR(FunNmToFunH.IsKey(FunNm) || FunNm.Empty(), "Unknown function '" + FunNm + "' !");
        // extract parameters
        TStrKdV FldNmValPrV;
        PUrlEnv HttpRqUrlEnv = HttpRq->GetUrlEnv();
        const int Keys = HttpRqUrlEnv->GetKeys();
        for (int KeyN = 0; KeyN < Keys; KeyN++) {
            TStr KeyNm = HttpRqUrlEnv->GetKeyNm(KeyN);
            const int Vals = HttpRqUrlEnv->GetVals(KeyN);
            for (int ValN = 0; ValN < Vals; ValN++) {
                TStr Val = HttpRqUrlEnv->GetVal(KeyN, ValN);
                FldNmValPrV.Add(TStrKd(KeyNm, Val));
            }
        }
        // log the call
        TStr TimeNow = TTm::GetCurLocTm().GetWebLogDateTimeStr(true);
        GetNotify()->OnStatus(TStr::Fmt("[%s] Request %s", TimeNow.CStr(), FunNm.CStr()));
		// prepare request environment
		PSAppSrvRqEnv RqEnv = TSAppSrvRqEnv::New(this, SockId, HttpRq);
		PSIn BodySIn; TStr ContTypeVal;
		if (!FunNm.Empty()) {
			// call function
			PSAppSrvFun SrvFun = FunNmToFunH.GetDat(FunNm);
			if (SrvFun->GetFunOutType() == saotXml) {
				PXmlDoc ResXmlDoc = SrvFun->Exec(FldNmValPrV, RqEnv);        
				TStr ResXmlStr; ResXmlDoc->SaveStr(ResXmlStr);
				//ResXmlDoc->SaveTxt(TFile::GetUniqueFNm("test.xml"));
				BodySIn = TMIn::New(XmlHdStr + ResXmlStr);
				ContTypeVal = THttp::TextXmlFldVal;
			} else if (SrvFun->GetFunOutType() == saotJSon) {
				TStr ResStr = SrvFun->ExecJSon(FldNmValPrV, RqEnv);
				BodySIn = TMIn::New(ResStr);
				//ContTypeVal = THttp::TextHtmlFldVal;
				ContTypeVal = THttp::AppJSonFldVal;
			} else {
				BodySIn = SrvFun->ExecCustom(FldNmValPrV, RqEnv, ContTypeVal);
			}
		} else {
			PXmlTok TopTok = TXmlTok::New("registered-functions");
			int KeyId = FunNmToFunH.FFirstKeyId();
			while (FunNmToFunH.FNextKeyId(KeyId)) {
				PXmlTok FunTok = TXmlTok::New("function");
				FunTok->AddArg("name", FunNmToFunH.GetKey(KeyId));
				TopTok->AddSubTok(FunTok);
			}
			PXmlDoc ResXmlDoc = TXmlDoc::New(TopTok);
			TStr ResXmlStr; ResXmlDoc->SaveStr(ResXmlStr);
			BodySIn = TMIn::New(XmlHdStr + ResXmlStr);
			ContTypeVal = THttp::TextXmlFldVal;
		}
        // prepare response
        HttpResp = THttpResp::New(THttp::OkStatusCd, 
            ContTypeVal, false, BodySIn);
        // send response
    } catch (PExcept Except) {
		PXmlTok TopTok = TXmlTok::New("error");
		TopTok->AddSubTok(TXmlTok::New("message", Except->GetMsgStr()));
		TopTok->AddSubTok(TXmlTok::New("location", Except->GetLocStr()));
		PXmlDoc ErrorXmlDoc = TXmlDoc::New(TopTok); 
        TStr ResXmlStr; ErrorXmlDoc->SaveStr(ResXmlStr);
        HttpResp = THttpResp::New(THttp::OkStatusCd, 
            THttp::TextHtmlFldVal, false, 
			TMIn::New(XmlHdStr + ResXmlStr));
    } catch (...) {
		PXmlDoc ErrorXmlDoc = TXmlDoc::New(TXmlTok::New("error")); 
        TStr ResXmlStr; ErrorXmlDoc->SaveStr(ResXmlStr);
        HttpResp = THttpResp::New(THttp::OkStatusCd, 
            THttp::TextHtmlFldVal, false, 
			TMIn::New(XmlHdStr + ResXmlStr));
    }
    SendHttpResp(SockId, HttpResp); 
}