void DataGenerator::_export_raw_data(GUINT32 num_bytes, const QString &fn) { bool success = false; try{ CREATE_AND_OPEN_OUTPUT_FILE(fn); class rng_data_source : public GUtil::IInput{ GUtil::CryptoPP::RNG &m_rng; public: rng_data_source(GUtil::CryptoPP::RNG &r) :m_rng(r) {} virtual GUINT32 ReadBytes(byte *b, GUINT32 len, GUINT32 to_read){ to_read = Min(len, to_read); m_rng.Fill(b, to_read); return to_read; } } rng_source(m_rng); rng_source.Pump(&outfile, num_bytes, DEFAULT_CHUNK_SIZE, [&](int p) -> bool{ emit ProgressUpdated(p); return m_cancel; }); success = true; } catch(const Exception<> &ex){ emit NotifyError(std::shared_ptr<std::exception>( static_cast<std::exception*>((Exception<> *)ex.Clone())) ); } if(success) emit NotifyInfo(tr("Raw data exported")); }
void nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition) { if (mCleared || !mAllowed) return; // we should not pass null back to the DOM. if (!aPosition) { NotifyError(nsIDOMGeoPositionError::POSITION_UNAVAILABLE); return; } // Ensure that the proper context is on the stack (bug 452762) nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1")); if (!stack || NS_FAILED(stack->Push(nsnull))) return; // silently fail mCallback->HandleEvent(aPosition); // remove the stack JSContext* cx; stack->Pop(&cx); mHasSentData = PR_TRUE; }
bool CMySqlDatabase::DbCrud( QString& strSql, QString& strError ) { // // Unicode(UCS) =====> MBCS // if ( bExpiration ) { return false; } QByteArray byteSql = pCodec->fromUnicode( strSql ); int nSize = byteSql.count( ); const char* pSql = byteSql.data( ); int nRet = mysql_real_query( &hConnect, pSql, nSize ); GetErrorMsg( nRet, strError, true, strSql ); //mysql_num_rows(); bool bRet = ( 0 == nRet ); if ( !bRet ) { strError = "访问数据库失败,可能是网络故障,请检查网络!\n" + strError; //CCommonFunction::MsgBox( NULL, "提示", strError, QMessageBox::Information ); //CStartupProcess::GetFrame( )->UpdateInfo( strError ); emit NotifyError( strError ); } return bRet; }
void DataGenerator::_gen_dist_geometric(GUINT32 N, double E, const QString &fn) { bool success = false; char buf[SMALL_BUFFER_SIZE]; GUINT32 progress_increment = N / 100; try{ CREATE_AND_OPEN_OUTPUT_FILE(fn); for(GUINT32 i = 0; i < N; i++){ if(0 == i % progress_increment) emit ProgressUpdated((double)i/N * 100); if(m_cancel) throw CancelledOperationException<>(); const GUINT64 X = m_rng.Geometric(E); int len = sprintf(buf, "%llu\n", X); outfile.Write(buf, len); } emit ProgressUpdated(100); success = true; } catch(const Exception<> &ex){ emit NotifyError(std::shared_ptr<std::exception>( static_cast<std::exception*>((Exception<> *)ex.Clone())) ); } if(success) emit NotifyInfo(tr("Geometric distribution generated")); }
NS_IMETHODIMP ItemTask::Run() { int ret = EWS_FAIL; char * err_msg = NULL; void * remoteResponse = NULL; if (EWS_FAIL == NotifyBegin(this)) { return NS_OK; } NS_FAILED_WARN(m_ItemsCallback->RemoteOperation(&remoteResponse)); m_ItemsCallback->GetRemoteResult(&ret); m_ItemsCallback->GetRemoteMessage(&err_msg); NotifyError(this, ret, err_msg); nsCOMPtr<nsIRunnable> resultrunnable = new ItemDoneTask(ret, m_ItemsCallback, remoteResponse, m_pEwsTaskCallbacks, this); NS_DispatchToMainThread(resultrunnable); return NS_OK; }
NS_IMETHODIMP SmsRequest::NotifyThreadListFailed(int32_t aError) { if (mParent) { return SendMessageReply(MessageReply(ReplyThreadListFail(aError))); } return NotifyError(aError); }
NS_IMETHOD Run() { nsresult rv; nsCOMPtr<IMailEwsMsgFolder> ewsFolder(do_QueryInterface(m_Folder, &rv)); if (NS_FAILED(rv)) { NotifyError(m_Runnable, (int)rv, "unable to get ews folder"); } else if (m_Result == EWS_SUCCESS) { rv = ewsFolder->ClientRename(m_NewName, m_MsgWindow); if (NS_FAILED(rv)) { NotifyError(m_Runnable, (int)rv, "unable to rename folder"); } } NotifyEnd(m_Runnable, m_Result); return NS_OK; }
NS_IMETHODIMP SmsRequest::NotifyDeleteMessageFailed(int32_t aError) { if (mParent) { return SendMessageReply(MessageReply(ReplyMessageDeleteFail(aError))); } return NotifyError(aError); }
void View_Cancha::initialize(SDL_Renderer * gRenderer) { if( !texturaCancha.loadFromFile( "Images/canchafubol.jpg",gRenderer) ) { NotifyError("No se pudo cargar la Imagen de la cancha, se usara una imagen por defecto", "View_Jugador"); texturaCancha.loadFromFile("Images/pelota.png",gRenderer); } }
bool CError::NotifyError( LPSTR szFilename, int iLine, int iColumn, DWORD dwStrResourceDescription) { WCHAR szBuffer[ MAX_LANG_ERROR_STR]; if( 0 >= LoadStringW( NULL, dwStrResourceDescription, szBuffer, sizeof(szBuffer))) return FALSE; return NotifyError( szFilename, iLine, iColumn, szBuffer); }
NS_IMETHODIMP nsGeolocationRequest::Allow() { nsRefPtr<nsGeolocationService> geoService = nsGeolocationService::GetInstance(); // Kick off the geo device, if it isn't already running nsresult rv = geoService->StartDevice(); if (NS_FAILED(rv)) { // Location provider error NotifyError(nsIDOMGeoPositionError::POSITION_UNAVAILABLE); return NS_OK; } nsCOMPtr<nsIDOMGeoPosition> lastPosition = geoService->GetCachedPosition(); DOMTimeStamp cachedPositionTime; if (lastPosition) lastPosition->GetTimestamp(&cachedPositionTime); // check to see if we can use a cached value // // either: // a) the user has specified a maximumAge which allows us to return a cached value, // -or- // b) the cached position time is some reasonable value to return to the user (<30s) PRUint32 maximumAge = 30 * PR_MSEC_PER_SEC; if (mOptions) { PRInt32 tempAge; nsresult rv = mOptions->GetMaximumAge(&tempAge); if (NS_SUCCEEDED(rv)) { if (tempAge >= 0) maximumAge = tempAge; } } if (lastPosition && maximumAge > 0 && ( (PR_Now() / PR_USEC_PER_MSEC ) - maximumAge <= cachedPositionTime) ) { // okay, we can return a cached position mAllowed = PR_TRUE; // send the cached location SendLocation(lastPosition); } PRInt32 timeout; if (mOptions && NS_SUCCEEDED(mOptions->GetTimeout(&timeout)) && timeout > 0) { if (timeout < 10) timeout = 10; mTimeoutTimer = do_CreateInstance("@mozilla.org/timer;1"); mTimeoutTimer->InitWithCallback(this, timeout, nsITimer::TYPE_ONE_SHOT); } mAllowed = PR_TRUE; return NS_OK; }
NS_IMETHODIMP nsGeolocationRequest::Cancel() { NotifyError(nsIDOMGeoPositionError::PERMISSION_DENIED); // remove ourselves from the locators callback lists. mLocator->RemoveRequest(this); return NS_OK; }
// Open an audio/video file. void OnFileOpen(HWND hwnd) { IFileOpenDialog *pFileOpen = NULL; IShellItem *pItem = NULL; PWSTR pszFilePath = NULL; // Create the FileOpenDialog object. HRESULT hr = CoCreateInstance(__uuidof(FileOpenDialog), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileOpen)); if (FAILED(hr)) { goto done; } // Show the Open dialog box. hr = pFileOpen->Show(NULL); if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { // The user canceled the dialog. Do not treat as an error. hr = S_OK; goto done; } else if (FAILED(hr)) { goto done; } // Get the file name from the dialog box. hr = pFileOpen->GetResult(&pItem); if (FAILED(hr)) { goto done; } hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); if (FAILED(hr)) { goto done; } // Display the file name to the user. hr = g_pPlayer->OpenURL(pszFilePath); if (SUCCEEDED(hr)) { UpdateUI(hwnd, OpenPending); } done: if (FAILED(hr)) { NotifyError(hwnd, L"Could not open the file.", hr); UpdateUI(hwnd, Closed); } CoTaskMemFree(pszFilePath); SafeRelease(&pItem); SafeRelease(&pFileOpen); }
// Handler for Media Session events. void OnPlayerEvent(HWND hwnd, WPARAM pUnkPtr) { HRESULT hr = g_pPlayer->HandleEvent(pUnkPtr); if (FAILED(hr)) { NotifyError(hwnd, L"An error occurred.", hr); } UpdateUI(hwnd, g_pPlayer->GetState()); }
HRESULT CPreview::OnReadSample( HRESULT hrStatus, DWORD /* dwStreamIndex */, DWORD /* dwStreamFlags */, LONGLONG /* llTimestamp */, IMFSample *pSample // Can be NULL ) { HRESULT hr = S_OK; IMFMediaBuffer *pBuffer = NULL; EnterCriticalSection(&m_critsec); if (FAILED(hrStatus)) { hr = hrStatus; } if (SUCCEEDED(hr)) { if (pSample) { // Get the video frame buffer from the sample. hr = pSample->GetBufferByIndex(0, &pBuffer); // Draw the frame. if (SUCCEEDED(hr)) { hr = m_draw.DrawFrame(pBuffer); } } } // Request the next frame. if (SUCCEEDED(hr)) { hr = m_pReader->ReadSample( (DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, NULL, // actual NULL, // flags NULL, // timestamp NULL // sample ); } if (FAILED(hr)) { NotifyError(hr); } SafeRelease(&pBuffer); LeaveCriticalSection(&m_critsec); return hr; }
NS_IMETHODIMP MobileMessageCallback::NotifyGetSmscAddress(const nsAString& aSmscAddress) { AutoJSAPI jsapi; if (NS_WARN_IF(!jsapi.Init(mDOMRequest->GetOwner()))) { return NotifyError(nsIMobileMessageCallback::INTERNAL_ERROR); } JSContext* cx = jsapi.cx(); JSString* smsc = JS_NewUCStringCopyN(cx, aSmscAddress.BeginReading(), aSmscAddress.Length()); if (!smsc) { return NotifyError(nsIMobileMessageCallback::INTERNAL_ERROR); } JS::Rooted<JS::Value> val(cx, JS::StringValue(smsc)); return NotifySuccess(val); }
// Append a string as a token to the token vector int CExpression::AppendString(const char* str, bool editorMode, bool singleQuotes) { Token Tok; int i; for (i = 1; ; i++) { // End quote and not a "" double quote escape if (str[i] == '"') { // Double "" if (!singleQuotes && str[i+1] == '"') { Tok.str += '"'; if(editorMode) Tok.str += '"'; i++; // Skip } else // Terminate break; } else if (singleQuotes && str[i] == '\'') { break; } // Null found inside string else if (str[i] == NULL) { // Report an error (string not closed) NotifyError("Syntax error: Unclosed string quote"); i--; break; // exit } else Tok.str += str[i]; }//for // Append this token if (singleQuotes) Tok.t = T_VARIABLENAME; else { Tok.str.Replace("$n", "\n"); Tok.str.Replace("$q", "\""); Tok.str.Replace("$t", "\t"); Tok.t = T_STRINGLITERAL; } Tok.length = Tok.str.GetLength() + 2; // Don't forget the quotes toks.push_back(Tok); return i; }
NS_IMETHODIMP SmsRequest::NotifyReadMessageListFailed(int32_t aError) { if (mParent) { return SendMessageReply(MessageReply(ReplyCreateMessageListFail(aError))); } if (mCursor) { static_cast<SmsCursor*>(mCursor.get())->Disconnect(); } return NotifyError(aError); }
NS_IMETHODIMP SmsRequestManager::NotifyReadMessageListFailed(PRInt32 aRequestId, PRInt32 aError) { SmsRequest* request = GetRequest(aRequestId); nsCOMPtr<nsIDOMMozSmsCursor> cursor = request->GetCursor(); if (cursor) { static_cast<SmsCursor*>(cursor.get())->Disconnect(); } return NotifyError(aRequestId, aError); }
bool wxLuaDebugTarget::Run() { wxCHECK_MSG(m_pThread == NULL, false, wxT("wxLuaDebugTarget::Run already called")); // Assume something is going to go wrong m_fErrorsSeen = true; m_pThread = new LuaThread(this); // Start the thread if ((m_pThread != NULL) && (m_pThread->Create() == wxTHREAD_NO_ERROR) && (m_pThread->Run() == wxTHREAD_NO_ERROR)) { // Wait for the connection to the server to complete if (!IsConnected()) { wxMessageBox(wxT("Unable to connect to server"), wxT("wxLua client"), wxOK | wxCENTRE, NULL); } else { // OK, now we can start running. m_runCondition.Wait(); m_fRunning = true; m_fErrorsSeen = false; size_t idx, count = m_bufferArray.GetCount(); for (idx = 0; idx < count; ++idx) { wxString luaBuffer = m_bufferArray.Item(idx); wxString bufFilename = luaBuffer.BeforeFirst(wxT('\0')); wxString buf = luaBuffer.AfterFirst(wxT('\0')); wxLuaCharBuffer char_buf(buf); int rc = m_wxlState.LuaDoBuffer(char_buf, char_buf.Length(), wx2lua(bufFilename)); m_fErrorsSeen = (rc != 0); if (m_fErrorsSeen) { NotifyError(wxlua_LUA_ERR_msg(rc)); break; } } m_bufferArray.Clear(); } } return !m_fErrorsSeen; }
nsresult nsGeolocationRequest::Init() { // This method is called before the user has given permission for this request. // check to see if we have a geolocation provider, if not, notify an error and bail. nsRefPtr<nsGeolocationService> geoService = nsGeolocationService::GetInstance(); if (!geoService->HasGeolocationProvider()) { NotifyError(nsIDOMGeoPositionError::POSITION_UNAVAILABLE); return NS_ERROR_FAILURE; } return NS_OK; }
DataGenerator::DataGenerator(QWidget *parent) :QWidget(parent), ui(new Ui::DataGenerator), m_cancel(false) { ui->setupUi(this); // This connection will be queued because errors are emitted // from the background thread connect(this, SIGNAL(NotifyError(std::shared_ptr<std::exception>)), this, SLOT(_handle_error(std::shared_ptr<std::exception>))); connect(this, SIGNAL(ProgressUpdated(int)), this, SLOT(_handle_progress(int))); }
NS_IMETHODIMP MobileMessageCallback::NotifySegmentInfoForTextGot(int32_t aSegments, int32_t aCharsPerSegment, int32_t aCharsAvailableInLastSegment) { AutoJSAPI jsapi; if (NS_WARN_IF(!jsapi.Init(mDOMRequest->GetOwner()))) { return NotifyError(nsIMobileMessageCallback::INTERNAL_ERROR); } SmsSegmentInfo info; info.mSegments = aSegments; info.mCharsPerSegment = aCharsPerSegment; info.mCharsAvailableInLastSegment = aCharsAvailableInLastSegment; JSContext* cx = jsapi.cx(); JS::Rooted<JS::Value> val(cx); if (!ToJSValue(cx, info, &val)) { JS_ClearPendingException(cx); return NotifyError(nsIMobileMessageCallback::INTERNAL_ERROR); } return NotifySuccess(val, true); }
NS_IMETHODIMP MobileMessageCallback::NotifyGetSmscAddress(const nsAString& aSmscAddress) { AutoJSContext cx; JSString* smsc = JS_NewUCStringCopyN(cx, static_cast<const jschar *>(aSmscAddress.BeginReading()), aSmscAddress.Length()); if (!smsc) { return NotifyError(nsIMobileMessageCallback::INTERNAL_ERROR); } JS::Rooted<JS::Value> val(cx, STRING_TO_JSVAL(smsc)); return NotifySuccess(val); }
// Handler for WM_CREATE message. LRESULT OnCreateWindow(HWND hwnd) { // Initialize the player object. HRESULT hr = CPlayer::CreateInstance(hwnd, hwnd, &g_pPlayer); if (SUCCEEDED(hr)) { UpdateUI(hwnd, Closed); return 0; // Success. } else { NotifyError(NULL, L"Could not initialize the player object.", hr); return -1; // Destroy the window } }
void MainWindow::OnFileOpen() { OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(ofn)); WCHAR szFileName[MAX_PATH]; szFileName[0] = L'\0'; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = m_hwnd; ofn.hInstance = m_hInstance; ofn.lpstrFilter = L"All (*.*)/0*.*/0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_FILEMUSTEXIST; HRESULT hr; if (GetOpenFileName(&ofn)) { hr = m_pPlayer->OpenFile(szFileName); // Update the state of the UI. UpdateUI(); // Invalidate the appliction window, in case there is an old video // frame from the previous file and there is no video now. (eg, the // new file is audio only, or we failed to open this file.) InvalidateRect(m_hwnd, NULL, FALSE); // Update the seek bar to match the current state. UpdateSeekBar(); if (SUCCEEDED(hr)) { // If this file has a video stream, we need to notify // the VMR about the size of the destination rectangle. // Invoking our OnSize() handler does this. OnSize(); } else { NotifyError(m_hwnd, TEXT("Cannot open this file."), hr); } } }
NS_IMETHODIMP nsGeolocationRequest::Notify(nsITimer* aTimer) { // If we haven't gotten an answer from the geolocation // provider yet, cancel the request. Same logic as // ::Cancel, just a different error if (!mHasSentData) { NotifyError(nsIDOMGeoPositionError::TIMEOUT); // remove ourselves from the locator's callback lists. mLocator->RemoveRequest(this); } mTimeoutTimer = nsnull; return NS_OK; }
void MediaRecorder::Resume(ErrorResult& aResult) { LOG(PR_LOG_DEBUG, ("MediaRecorder.Resume")); if (mState != RecordingState::Paused) { aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } MOZ_ASSERT(mSessions.Length() > 0); nsresult rv = mSessions.LastElement()->Resume(); if (NS_FAILED(rv)) { NotifyError(rv); return; } mState = RecordingState::Recording; }
void DataGenerator::_gen_dist_normal(GUINT32 N, double mean, double sigma, bool discrete, const QString &fn) { bool success = false; char buf[2*SMALL_BUFFER_SIZE]; GUINT32 progress_increment = N / 100; GUINT32 progress_mem = progress_increment; try{ CREATE_AND_OPEN_OUTPUT_FILE(fn); GUINT32 i; int len; for(i = 0; i < N; i+=2){ if(i >= progress_mem){ emit ProgressUpdated((double)i/N * 100); progress_mem += progress_increment; } if(m_cancel) throw CancelledOperationException<>(); if(discrete){ GUtil::Pair<int> X = m_rng.N_Discrete2(mean, sigma); len = sprintf(buf, "%d\n", X.First); if(i != N-1) len += sprintf(buf + len, "%d\n", X.Second); } else{ GUtil::Pair<GFLOAT64> X = m_rng.N2(mean, sigma); len = sprintf(buf, "%.100f\n", X.First); if(i != N-1) len += sprintf(buf + len, "%.100f\n", X.Second); } outfile.Write(buf, len); } emit ProgressUpdated(100); success = true; } catch(const Exception<> &ex){ emit NotifyError(std::shared_ptr<std::exception>( static_cast<std::exception*>((Exception<> *)ex.Clone())) ); } if(success) emit NotifyInfo(tr("Normal distribution generated")); }
void MediaRecorder::Resume(ErrorResult& aResult) { if (mState != RecordingState::Paused) { aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } MOZ_ASSERT(mSession != nullptr); if (mSession) { nsresult rv = mSession->Resume(); if (NS_FAILED(rv)) { NotifyError(rv); return; } mState = RecordingState::Recording; } }