VREP_DLLEXPORT void* v_repMessage(int message,int* auxiliaryData,void* customData,int* replyData) { // This is called quite often. Just watch out for messages/events you want to handle simLockInterface(1); // This function should not generate any error messages: int errorModeSaved; simGetIntegerParameter(sim_intparam_error_report_mode,&errorModeSaved); simSetIntegerParameter(sim_intparam_error_report_mode,sim_api_errormessage_ignore); void* retVal=NULL; // Acknowledgment message display: // ***************************************************************** static int auxConsoleHandleForAcknowledgmentDisplay=-1; static int acknowledgmentDisplayStartTime=0; if (displayAcknowledgment) { auxConsoleHandleForAcknowledgmentDisplay=simAuxiliaryConsoleOpen("Acknowledgments",10,2+4+16,NULL,NULL,NULL,NULL); simAuxiliaryConsolePrint(auxConsoleHandleForAcknowledgmentDisplay,"The wiimote plugin is courtesy of Eric Rohmer.\n\nThe wiimote plugin contains WiiYourself! wiimote code by gl.tter\nhttp://gl.tter.org"); acknowledgmentDisplayStartTime=timeGetTime(); displayAcknowledgment=false; } if ( (auxConsoleHandleForAcknowledgmentDisplay!=-1)&&(timeGetTime()-acknowledgmentDisplayStartTime>5000) ) { simAuxiliaryConsoleClose(auxConsoleHandleForAcknowledgmentDisplay); auxConsoleHandleForAcknowledgmentDisplay=-1; } // ***************************************************************** // Clean-up at simulation end: // ***************************************************************** if (message==sim_message_eventcallback_simulationended) { if (auxConsoleHandleForAcknowledgmentDisplay!=-1) { simAuxiliaryConsoleClose(auxConsoleHandleForAcknowledgmentDisplay); auxConsoleHandleForAcknowledgmentDisplay=-1; } for (int i=0;i<4;i++) // for the 4 devices { while (startCountPerDevice[i]>0) { startCountOverall--; startCountPerDevice[i]--; if (startCountOverall==0) killThread(); } } } // ***************************************************************** simSetIntegerParameter(sim_intparam_error_report_mode,errorModeSaved); // restore previous settings simLockInterface(0); return(retVal); }
void ChinavisionAPI::deinit() { killThread(); if(m_dataReadyEvent) { CloseHandle(m_dataReadyEvent); m_dataReadyEvent = NULL; } if(m_exitEvent) { CloseHandle(m_exitEvent); m_exitEvent = NULL; } }
void LUA_END_CALLBACK(SLuaCallBack* p) { // the callback function of the new Lua command simLockInterface(1); int result=-1; // error if (p->inputArgCount>0) { // Ok, we have at least 1 input argument if (p->inputArgTypeAndSize[0*2+0]==sim_lua_arg_int) { // Ok, we have (at least) 1 int as argument if ( (p->inputInt[0]>=0)&&(p->inputInt[0]<4)&&(startCountPerDevice[p->inputInt[0]]>0) ) { startCountOverall--; startCountPerDevice[p->inputInt[0]]--; if (startCountPerDevice[p->inputInt[0]]==0) { // No one is using this device anymore... we remove it EnterCriticalSection(&m_cs); _allDevices[p->inputInt[0]]->Disconnect(); delete _allDevices[p->inputInt[0]]; _allDevices[p->inputInt[0]]=NULL; LeaveCriticalSection(&m_cs); } if (startCountOverall==0) killThread(); result=1; } else simSetLastError(LUA_END,"Invalid device index."); // output an error } else simSetLastError(LUA_END,"Wrong argument type/size."); // output an error } else simSetLastError(LUA_END,"Not enough arguments."); // output an error // Now we prepare the return value: p->outputArgCount=1; // 1 return value p->outputArgTypeAndSize=(simInt*)simCreateBuffer(p->outputArgCount*2*sizeof(simInt)); // x return values takes x*2 simInt for the type and size buffer p->outputArgTypeAndSize[2*0+0]=sim_lua_arg_int; // The return value is an int p->outputArgTypeAndSize[2*0+1]=1; // Not used (table size if the return value was a table) p->outputInt=(simInt*)simCreateBuffer(1*sizeof(result)); // 1 int return value p->outputInt[0]=result; // This is the int value we want to return simLockInterface(0); }
void LUA_END_CALLBACK(SLuaCallBack* p) { // the callback function of the new Lua command int result=-1; // error if (p->inputArgCount>0) { // Ok, we have at least 1 input argument if (p->inputArgTypeAndSize[0*2+0]==sim_lua_arg_int) { // Ok, we have (at least) 1 int as argument if ( (p->inputInt[0]<4)&&(startCountPerDevice[p->inputInt[0]]>0) ) { startCountOverall--; startCountPerDevice[p->inputInt[0]]--; if (startCountPerDevice[p->inputInt[0]]==0) { EnterCriticalSection(&m_cs); deinitCapture(p->inputInt[0]); delete[] captureInfo[p->inputInt[0]].mTargetBuf; openCaptureDevices[p->inputInt[0]]=false; LeaveCriticalSection(&m_cs); } if (startCountOverall==0) killThread(); result=1; } else simSetLastError(LUA_END,"Invalid device index."); // output an error } else simSetLastError(LUA_END,"Wrong argument type/size."); // output an error } else simSetLastError(LUA_END,"Not enough arguments."); // output an error // Now we prepare the return value: p->outputArgCount=1; // 1 return value p->outputArgTypeAndSize=(simInt*)simCreateBuffer(p->outputArgCount*2*sizeof(simInt)); // x return values takes x*2 simInt for the type and size buffer p->outputArgTypeAndSize[2*0+0]=sim_lua_arg_int; // The return value is an int p->outputArgTypeAndSize[2*0+1]=1; // Not used (table size if the return value was a table) p->outputInt=(simInt*)simCreateBuffer(1*sizeof(result)); // 1 int return value p->outputInt[0]=result; // This is the int value we want to return }
MotionExecution::MotionExecution(QWidget *parent, QStringList *myMotion) : QDialog(parent), m_ui(new Ui::MotionExecution) { m_ui->setupUi(this); motion = myMotion; playThread = new executionThread(myMotion); connect(playThread, SIGNAL(stepExecuted(int)),this, SLOT(updateDialog(int))); connect(m_ui->stopExecutionButton, SIGNAL(clicked()), playThread, SLOT(killThread())); connect(playThread, SIGNAL(finished()), this, SLOT(hide())); playThread->start(); show(); }
bool Thread::stopThread (const int timeOutMilliseconds) { bool cleanExit = true; // agh! You can't stop the thread that's calling this method! How on earth // would that work?? bassert (getCurrentThreadId() != getThreadId()); const RecursiveMutex::ScopedLockType sl (startStopLock); if (isThreadRunning()) { signalThreadShouldExit(); notify(); if (timeOutMilliseconds != 0) { cleanExit = waitForThreadToExit (timeOutMilliseconds); } if (isThreadRunning()) { bassert (! cleanExit); // very bad karma if this point is reached, as there are bound to be // locks and events left in silly states when a thread is killed by force.. killThread(); threadHandle = nullptr; threadId = 0; cleanExit = false; } else { cleanExit = true; } } return cleanExit; }
void initUmdImageDriver() { CfwConfig config; memset( &config, 0, sizeof( CfwConfig ) ); getCfwConfig( &config ); mode = config.umdmode; executable = config.executebootbin; log( "umdmode %d exec %d\n", mode, executable ); switch ( mode ) { case MODE_MARCH33: { sceIoDelDrv( "isofs" ); killModule( "sceIsofs_driver" ); if ( !findProc( "pspMarch33_Driver", NULL, 0xcee8593c ) ) { sceIoDelDrv( "umd" ); } killModule( "pspMarch33_Driver" ); killSema( "Semaphore", "MediaManSema" ); break; } case MODE_NP9660: { sceIoDelDrv( "isofs" ); killModule( "sceIsofs_driver" ); sceIoDelDrv( "umd" ); killThread( "Thread", "SceNpUmdMount" ); killEventHandler( "SceUmdMedia" ); killModule( "sceNp9660_driver" ); killEventFlag( "EventFlag", "SceUmdManState" ); killEventFlag( "EventFlag", "SceMediaManUser" ); break; } } }
void LUA_START_CALLBACK(SLuaCallBack* p) { // the callback function of the new Lua command int result=-1; // error int returnResolution[2]={0,0}; if (p->inputArgCount>2) { // Ok, we have at least 3 input argument if ( (p->inputArgTypeAndSize[0*2+0]==sim_lua_arg_int)&&(p->inputArgTypeAndSize[1*2+0]==sim_lua_arg_int)&&(p->inputArgTypeAndSize[2*2+0]==sim_lua_arg_int) ) { // Ok, we have (at least) 3 ints as argument if ( (countCaptureDevices()>p->inputInt[0])&&(p->inputInt[0]>=0)&&(p->inputInt[0]<4) ) { if (!openCaptureDevices[p->inputInt[0]]) { // We can set the new resolution bool goOn=true; if (startCountOverall==0) { // Launch the thread! _camThreadLaunched=false; CreateThread(NULL,0,_camThread,NULL,THREAD_PRIORITY_NORMAL,NULL); while (!_camThreadLaunched) Sleep(2); if (deviceCount<1) { simSetLastError(LUA_START,"ESCAPI initialization failure or no devices found."); // output an error killThread(); goOn=false; } } if (goOn) { captureInfo[p->inputInt[0]].mWidth=p->inputInt[1]; captureInfo[p->inputInt[0]].mHeight=p->inputInt[2]; captureInfo[p->inputInt[0]].mTargetBuf=new int[p->inputInt[1]*p->inputInt[2]]; if (initCapture(p->inputInt[0],&captureInfo[p->inputInt[0]])!=0) { doCapture(p->inputInt[0]); openCaptureDevices[p->inputInt[0]]=true; returnResolution[0]=p->inputInt[1]; returnResolution[1]=p->inputInt[2]; result=1; // success! startCountOverall++; startCountPerDevice[p->inputInt[0]]++; } else { delete[] captureInfo[p->inputInt[0]].mTargetBuf; simSetLastError(LUA_START,"Device may already be in use."); // output an error } } } else { // We have to retrieve the current resolution returnResolution[0]=captureInfo[p->inputInt[0]].mWidth; returnResolution[1]=captureInfo[p->inputInt[0]].mHeight; result=0; startCountOverall++; startCountPerDevice[p->inputInt[0]]++; } } else simSetLastError(LUA_START,"Invalid device index."); // output an error } else simSetLastError(LUA_START,"Wrong argument type/size."); // output an error } else simSetLastError(LUA_START,"Not enough arguments."); // output an error // Now we prepare the return value: if (result>-1) { p->outputArgCount=3; // 3 return values p->outputArgTypeAndSize=(simInt*)simCreateBuffer(p->outputArgCount*2*sizeof(simInt)); // x return values takes x*2 simInt for the type and size buffer p->outputArgTypeAndSize[2*0+0]=sim_lua_arg_int; // The return value is an int p->outputArgTypeAndSize[2*0+1]=1; // Not used (table size if the return value was a table) p->outputArgTypeAndSize[2*1+0]=sim_lua_arg_int; // The return value is an int p->outputArgTypeAndSize[2*1+1]=1; // Not used (table size if the return value was a table) p->outputArgTypeAndSize[2*2+0]=sim_lua_arg_int; // The return value is an int p->outputArgTypeAndSize[2*2+1]=1; // Not used (table size if the return value was a table) p->outputInt=(simInt*)simCreateBuffer(3*sizeof(result)); // 1 int return value p->outputInt[0]=result; // This is the int value we want to return p->outputInt[1]=returnResolution[0]; // This is the int value we want to return p->outputInt[2]=returnResolution[1]; // This is the int value we want to return } else { p->outputArgCount=1; // 1 return value p->outputArgTypeAndSize=(simInt*)simCreateBuffer(p->outputArgCount*2*sizeof(simInt)); // x return values takes x*2 simInt for the type and size buffer p->outputArgTypeAndSize[2*0+0]=sim_lua_arg_int; // The return value is an int p->outputArgTypeAndSize[2*0+1]=1; // Not used (table size if the return value was a table) p->outputInt=(simInt*)simCreateBuffer(1*sizeof(result)); // 1 int return value p->outputInt[0]=result; // This is the int value we want to return } }