void StAndroidGlue::fetchState(StString& theNewFile, StQuaternion<double>& theQuaternion) { StMutexAuto aLock(myFetchLock); theQuaternion = myQuaternion; if(!myDndPath.isEmpty()) { theNewFile = myDndPath; myDndPath.clear(); } }
void LinkTask::unref() { PoolThreadMgr::Lock aLock(&_lock); if(!(--_refCounter)) { aLock.unLock(); delete this; } }
/** @brief set the image processing mgr * * this is the way to defined the chained process of all images. * each time an image is received, this TaskMgr is clone * @param aMgr set a TaskMgr or NULL to remove the previous one */ void PoolThreadMgr::setTaskMgr(const TaskMgr *aMgr) { TaskMgr *refBackgrounMgr = NULL; if(aMgr) refBackgrounMgr = new TaskMgr(*aMgr); Lock aLock(&_lock); delete _taskMgr; _taskMgr = refBackgrounMgr; }
void LinkTask::setEventCallback(TaskEventCallback *aEventCbk) { PoolThreadMgr::Lock aLock(&_lock); if(aEventCbk) aEventCbk->ref(); if(_eventCbkPt) _eventCbkPt->unref(); _eventCbkPt = aEventCbk; }
void StAndroidGlue::setOrientation(float theAzimuthDeg, float thePitchDeg, float theRollDeg, float theScreenRotDeg) { const StQuaternion<double> anOriYaw = StQuaternion<double>(StVec3<double>::DY(), stToRadians((double )theAzimuthDeg)); const StQuaternion<double> anOriPitch = StQuaternion<double>(StVec3<double>::DX(), stToRadians(90.0 + (double )thePitchDeg)); const StQuaternion<double> anOriRoll = StQuaternion<double>(StVec3<double>::DZ(), stToRadians((double )-theRollDeg + (double )theScreenRotDeg)); StQuaternion<double> anOri = StQuaternion<double>::multiply(anOriPitch, anOriYaw); anOri = StQuaternion<double>::multiply(anOriRoll, anOri); StMutexAuto aLock(myFetchLock); myQuaternion = anOri; }
/** @brief abort all process */ void PoolThreadMgr::abort() { Lock aLock(&_lock); _suspendFlag = true; while(_runningThread) pthread_cond_wait(&_cond,&_lock); for(std::list<TaskMgr*>::iterator i = _processQueue.begin(); i != _processQueue.end();++i) delete *i; _processQueue.clear(); _suspendFlag = false; }
void StAndroidGlue::setQuaternion(const StQuaternion<float>& theQ, const float theScreenRotDeg) { // do the magic - convert quaternion from Android coordinate system to sView coordinate system const StQuaternion<double> anOriPitch = StQuaternion<double>(StVec3<double>::DX(), stToRadians(90.0)); const StQuaternion<double> anOriRoll = StQuaternion<double>(StVec3<double>::DZ(), stToRadians(-270.0 + (double )theScreenRotDeg)); const StQuaternion<double> anOriAnd((double )theQ.y(), (double )theQ.z(), (double )theQ.x(), (double )theQ.w()); StQuaternion<double> anOri = StQuaternion<double>::multiply(anOriAnd, anOriPitch); anOri = StQuaternion<double>::multiply(anOriRoll, anOri); StMutexAuto aLock(myFetchLock); myQuaternion = anOri; }
void WECpiFeederThread::add2MsgQueue(ByteStream& Ibs) { //TODO creating copy is NOT good; later read from socket using a SBS messageqcpp::SBS aSbs(new messageqcpp::ByteStream(Ibs)); Ibs.reset(); //forcefully clearing it mutex::scoped_lock aLock(fMsgQMutex); //cout << "pushing to the MsgQueue" << endl; fMsgQueue.push(aSbs); fFeederCond.notify_one(); // as per preference of Damon aLock.unlock(); }
void PoolThreadMgr::removeProcess(TaskMgr *aProcess,bool aFlag) { Lock aLock(&_lock,aFlag); for(std::list<TaskMgr*>::iterator i = _processQueue.begin(); i != _processQueue.end();++i) { if(*i == aProcess) { _processQueue.erase(i); break; } } }
void PoolThreadMgr::quit() { Lock aLock(&_lock); _stopFlag = true; pthread_cond_broadcast(&_cond); aLock.unLock(); for(std::vector<pthread_t>::iterator i = _threadID.begin(); i != _threadID.end();++i) { void *returnThread; while(pthread_join(*i,&returnThread)); } _stopFlag = false; _threadID.clear(); }
void* PoolThreadMgr::_run(void *arg) { PoolThreadMgr* processMgrPt = (PoolThreadMgr*)arg; Lock aLock(&processMgrPt->_lock); processMgrPt->_runningThread++; while(1) { bool aBroadcastFlag = true; processMgrPt->_runningThread--; while(processMgrPt->_suspendFlag || (!processMgrPt->_stopFlag && processMgrPt->_processQueue.empty())) { if(aBroadcastFlag) { pthread_cond_broadcast(&processMgrPt->_cond); // synchro if abort aBroadcastFlag = false; } pthread_cond_wait(&processMgrPt->_cond,&processMgrPt->_lock); } processMgrPt->_runningThread++; if(!processMgrPt->_processQueue.empty()) { TaskMgr *processPt = processMgrPt->_processQueue.front(); TaskMgr::TaskWrap *aNextTask = processPt->next(); aLock.unLock(); try { aNextTask->process(); } catch(ProcessException &exp) { aNextTask->error(exp.getErrMsg()); } catch(...) { aNextTask->error("Unknowed exception!"); } aLock.lock(); delete aNextTask; } else break; // stop } processMgrPt->_runningThread--; return NULL; }
void One2OneChannel::read(unsigned char *buffer, size_t len) { MutexLock aLock(m_sync); if (true == m_bEmpty) { // One thread has arrived. m_bEmpty = false; // No error should occur logically. // The "wait" shall be waken up only by cond.signal from the writer. // Wait till the writer comes. ec_rv_fatal( pthread_cond_wait(&m_cond, &m_sync) ) memcpy(buffer, m_pBuff, len); // No error should occur logically. ec_rv_fatal( pthread_cond_signal(&m_cond) ) }
/** Check what sort of reporting can be done using the devices currently * enabled (including the VMM device) and notify the guest and the front-end. */ void Mouse::sendMouseCapsNotifications(void) { bool fAbsDev, fRelDev, fCanAbs, fNeedsHostCursor; { AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS); getDeviceCaps(&fAbsDev, &fRelDev); fCanAbs = supportsAbs(); fNeedsHostCursor = guestNeedsHostCursor(); } if (fAbsDev) updateVMMDevMouseCaps(VMMDEV_MOUSE_HOST_HAS_ABS_DEV, 0); else updateVMMDevMouseCaps(0, VMMDEV_MOUSE_HOST_HAS_ABS_DEV); /** @todo this call takes the Console lock in order to update the cached * callback data atomically. However I can't see any sign that the cached * data is ever used again. */ mParent->onMouseCapabilityChange(fCanAbs, fRelDev, fNeedsHostCursor); }
/** Check what sort of reporting can be done using the devices currently * enabled. Does not consider the VMM device. */ void Mouse::getDeviceCaps(bool *pfAbs, bool *pfRel) { bool fAbsDev = false; bool fRelDev = false; AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS); for (unsigned i = 0; i < MOUSE_MAX_DEVICES; ++i) if (mpDrv[i]) { if (mpDrv[i]->u32DevCaps & MOUSE_DEVCAP_ABSOLUTE) fAbsDev = true; if (mpDrv[i]->u32DevCaps & MOUSE_DEVCAP_RELATIVE) fRelDev = true; } if (pfAbs) *pfAbs = fAbsDev; if (pfRel) *pfRel = fRelDev; }
void WECpiFeederThread::feedData2Cpi() { const boost::posix_time::seconds TIME_OUT(2); while(isContinue()) { mutex::scoped_lock aLock(fMsgQMutex); if(fMsgQueue.empty()) { boost::system_time const abs_time = boost::get_system_time()+ TIME_OUT; bool aTimedOut = fFeederCond.timed_wait(aLock, abs_time); if(!isContinue()) { aLock.unlock(); break; } // to handle spurious wake ups and timeout wake ups if((fMsgQueue.empty())||(!aTimedOut)) { aLock.unlock(); continue; } } messageqcpp::SBS aSbs = fMsgQueue.front(); fMsgQueue.pop(); aLock.unlock(); try { fOwner.pushData2Cpimport((*aSbs)); //cout << "Finished PUSHING data " << endl; } catch(runtime_error& e) { //cout << "Caught exception : " << e.what() << endl; //break; } aSbs.reset(); //forcefully clearing it // We start sending data request from here ONLY if(getQueueSize() == WEDataLoader::MAX_QSIZE) fOwner.sendDataRequest(); } cout << "CpiFeedThread Stopped!! " << endl; fStopped = true; }
HRESULT Mouse::reportMultiTouchEventToDevice(uint8_t cContacts, const uint64_t *pau64Contacts, uint32_t u32ScanTime) { HRESULT hrc = S_OK; PPDMIMOUSEPORT pUpPort = NULL; { AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS); unsigned i; for (i = 0; i < MOUSE_MAX_DEVICES; ++i) { if ( mpDrv[i] && (mpDrv[i]->u32DevCaps & MOUSE_DEVCAP_MULTI_TOUCH)) { pUpPort = mpDrv[i]->pUpPort; break; } } } if (pUpPort) { int vrc = pUpPort->pfnPutEventMultiTouch(pUpPort, cContacts, pau64Contacts, u32ScanTime); if (RT_FAILURE(vrc)) hrc = setError(VBOX_E_IPRT_ERROR, tr("Could not send the multi-touch event to the virtual device (%Rrc)"), vrc); } else { hrc = E_UNEXPECTED; } return hrc; }
/** * Send an absolute pointer event to the emulated absolute device we deem most * appropriate. * * @returns COM status code */ HRESULT Mouse::reportAbsEventToMouseDev(int32_t x, int32_t y, int32_t dz, int32_t dw, uint32_t fButtons) { if ( x < VMMDEV_MOUSE_RANGE_MIN || x > VMMDEV_MOUSE_RANGE_MAX) return S_OK; if ( y < VMMDEV_MOUSE_RANGE_MIN || y > VMMDEV_MOUSE_RANGE_MAX) return S_OK; if ( x != mcLastX || y != mcLastY || dz || dw || fButtons != mfLastButtons) { PPDMIMOUSEPORT pUpPort = NULL; { AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS); for (unsigned i = 0; !pUpPort && i < MOUSE_MAX_DEVICES; ++i) { if (mpDrv[i] && (mpDrv[i]->u32DevCaps & MOUSE_DEVCAP_ABSOLUTE)) pUpPort = mpDrv[i]->pUpPort; } } if (!pUpPort) return S_OK; int vrc = pUpPort->pfnPutEventAbs(pUpPort, x, y, dz, dw, fButtons); if (RT_FAILURE(vrc)) return setError(VBOX_E_IPRT_ERROR, tr("Could not send the mouse event to the virtual mouse (%Rrc)"), vrc); mfLastButtons = fButtons; } return S_OK; }
void StAndroidGlue::setOpenPath(const jstring theOpenPath, const jstring theMimeType, const jboolean theIsLaunchedFromHistory) { JNIEnv* aJniEnv = myActivity->env; StString anOpenPath = stStringFromJava(aJniEnv, theOpenPath); StString aMimeType = stStringFromJava(aJniEnv, theMimeType); const StString ST_FILE_PROTOCOL("file://"); if(anOpenPath.isStartsWith(ST_FILE_PROTOCOL)) { const size_t aCutFrom = ST_FILE_PROTOCOL.getLength(); const StString aPath = anOpenPath.subString(aCutFrom, (size_t )-1); anOpenPath.fromUrl(aPath); } StMutexAuto aLock(myFetchLock); if(myCreatePath.isEmpty()) { myCreatePath = anOpenPath; } // ignore outdated intent from history list - use C++ recent list instead if(!theIsLaunchedFromHistory) { myDndPath = anOpenPath; } }
void LinkTask::ref() { PoolThreadMgr::Lock aLock(&_lock); ++_refCounter; }
double StKeysState::getKeyTime(const StVirtKey theKey) const { StMutexAuto aLock(myLock); const double aResult = myTimes[theKey]; return aResult; }
void StKeysState::reset() { StMutexAuto aLock(myLock); stMemZero(myKeys, sizeof(myKeys)); }
void StBrowserPlugin::stWindowLoop() { // do not load plugin until it is placed on screen StWindow aParentWin(myResMgr, myParentWin); for(;;) { #ifndef _WIN32 const int32_t anActiveNb = #endif ST_PLUGIN_QUEUE.increment(); if(aParentWin.isParentOnScreen() #ifndef _WIN32 || anActiveNb <= 1 #endif ) { break; } ST_PLUGIN_QUEUE.decrement(); StThread::sleep(10); if(myToQuit) { return; } } // Load image viewer myStApp = new StImageViewer(myResMgr, myParentWin, new StOpenInfo()); if(!myStApp->open()) { ST_PLUGIN_QUEUE.decrement(); myStApp.nullify(); return; } ST_PLUGIN_QUEUE.decrement(); bool isFileOpened = false; bool isFullscreen = false; bool isFullLoaded = false; myIsActive = true; for(;;) { if(myStApp->closingDown()) { myStApp.nullify(); myIsActive = false; return; } myIsActive = myStApp->isActive(); if(myToQuit) { myStApp->exit(0); } else if(!isFileOpened && myIsActive) { // load the image StMutexAuto aLock(myMutex); if(myPreviewUrl.isEmpty()) { if(!myFullPath.isEmpty()) { myOpenInfo.setPath(myFullPath); aLock.unlock(); myStApp->open(myOpenInfo); isFileOpened = true; } } else if(!myPreviewPath.isEmpty()) { myOpenInfo.setPath(myPreviewPath); aLock.unlock(); myStApp->open(myOpenInfo); isFileOpened = true; } } StHandle<StWindow> aWin = myStApp->getMainWindow(); if(myIsActive) { aWin->show(); } else { aWin->hide(); } myStApp->processEvents(); if(aWin->isFullScreen()) { StMutexAuto aLock(myMutex); if(!isFullscreen && !myFullPath.isEmpty()) { myOpenInfo.setPath(myFullPath); aLock.unlock(); myStApp->open(myOpenInfo); isFullscreen = true; } else if(!isFullLoaded && NPNFuncs.pluginthreadasynccall != NULL) { aLock.unlock(); NPNFuncs.pluginthreadasynccall(nppInstance, StBrowserPlugin::doLoadFullSize, this); isFullLoaded = true; } } else if(isFullscreen) { StMutexAuto aLock(myMutex); if(!myPreviewPath.isEmpty()) { myOpenInfo.setPath(myPreviewPath); aLock.unlock(); myStApp->open(myOpenInfo); isFullscreen = false; } } } }
/** * Initialization, called at the beginning * * initializes the map of indexed folders and adds the watches * */ bool FolderWatcher::startWatch() { // read file std::string line; log("opennig file %s", _indexes_file_path.c_str()); std::ifstream in (_indexes_file_path.c_str()); if(!in){ log("Cannot open index file (%s)", _indexes_file_path.c_str()); return false; } WCHAR file_name [MAX_PATH * MB_CUR_MAX]; DWORD error; const long notifyFilter = FILE_NOTIFY_CHANGE_FILE_NAME // A file has been added, deleted, or renamed in this directory. | FILE_NOTIFY_CHANGE_DIR_NAME // A subdirectory has been created, removed, or renamed. | FILE_NOTIFY_CHANGE_NAME // This directory's name has changed. // | FILE_NOTIFY_CHANGE_ATTRIBUTES // The value of an attribute of this file, such as last access time, has changed. | FILE_NOTIFY_CHANGE_SIZE // This file's size has changed. | FILE_NOTIFY_CHANGE_LAST_WRITE // This file's last modification time has changed. // | FILE_NOTIFY_CHANGE_LAST_ACCESS // This file's last access time has changed. // | FILE_NOTIFY_CHANGE_CREATION // This file's creation time has changed. // | FILE_NOTIFY_CHANGE_EA // This file's extended attributes have been modified. // | FILE_NOTIFY_CHANGE_SECURITY // This file's security information has changed. // | FILE_NOTIFY_CHANGE_STREAM_NAME // A file stream has been added, deleted, or renamed in this directory. // | FILE_NOTIFY_CHANGE_STREAM_SIZE // This file stream's size has changed. // | FILE_NOTIFY_CHANGE_STREAM_WRITE // This file stream's data has changed. ; const bool watchSubdirs = true; WatchedFolder aWatchedFolder; aWatchedFolder._modified = false; log("locking"); RaiiLocker aLock(_lock); while(std::getline(in,line)){ log("line=%s", line.c_str()); if(line.empty()){ continue; }else if(line.at(0) == CHAR_MODIFIED){ log("folder already signaled modified : %s", line.c_str()); continue; }else if(line.size()>=2 && line.substr(0,2) == "//"){ // a comment line, ignore continue; }else{ log("add_watch for dir=%s", line.c_str()); int count_chars = mbstowcs( NULL, line.c_str(), 0); mbstowcs(file_name, line.c_str(), count_chars); log("path converted to wide string"); // null terminated string file_name[count_chars] = 0; try { log("calling add_watch"); int watchId = _win32FSHook->add_watch((const WCHAR *)file_name, notifyFilter, watchSubdirs, error, &callback); if(watchId == 0 ) { log("error add_watch for dir=%s err=%d", line.c_str(), error); }else{ log("Watch installed for directory %s",line.c_str()); aWatchedFolder._path = line; _indexed_folders.insert(std::make_pair(watchId, aWatchedFolder)); } }catch(...){ log("error add_watch : default catch"); } } } return (_indexed_folders.size() > 0); }
/** @brief add a process in the process queue. * Notice that after calling this methode aProcess will be own by PoolThreadMgr, * do not modify or even delete it. * @param aProcess a background process * @param aFlag if true lock the queue which is the default */ void PoolThreadMgr::addProcess(TaskMgr *aProcess,bool aFlag) { Lock aLock(&_lock,aFlag); _processQueue.push_back(aProcess); pthread_cond_broadcast(&_cond); }
int LinkTask::getRefCounter() const { PoolThreadMgr::Lock aLock(&_lock); return _refCounter; }