int SecCamera::startSnapshot(size_t* captureSize) { LOG_TIME_START(0); stopPreview(); LOG_TIME_END(0); int ret; LOG_TIME_START(1); // prepare ret = _v4l2Cam->setupBufs(_snapshotWidth, _snapshotHeight, _snapshotPixfmt, 1, 1); CHECK_EQ(ret, 1); ret = _v4l2Cam->mapBuf(0); CHECK_EQ(ret, 0); _v4l2Cam->qBuf(0); _v4l2Cam->startStream(true); LOG_TIME_END(1); LOG_CAMERA("%s: stopPreview(%lu), prepare(%lu) us", __func__, LOG_TIME(0), LOG_TIME(1)); _v4l2Cam->mapBufInfo(0, NULL, captureSize); return 0; }
int SecCamera::getSnapshot(int xth) { int index; int skipFirstNFrames = xth; LOG_TIME_START(0); // skip frames while (skipFirstNFrames) { LOGV("skipFrames %d", skipFirstNFrames); _v4l2Cam->waitFrame(); index = _v4l2Cam->dqBuf(); _v4l2Cam->qBuf(index); skipFirstNFrames--; } _v4l2Cam->waitFrame(); index = _v4l2Cam->dqBuf(); LOG_TIME_END(0); LOG_TIME_START(1); _v4l2Cam->startStream(false); LOG_TIME_END(1); LOG_CAMERA("%s: get frame after skip %d(%lu), stopStream(%lu)", __func__, xth, LOG_TIME(0), LOG_TIME(1)); return 0; }
int processWait(Proc_ID process, int *exitCode, int waitTimeSecs) { int iReturnCode = DIAGLIB_OK; if(process == 0) { return RETURN_LOG_BAD_FUNCTION_CALL; } LOG_TIME(L"Waiting for process pid=%ld --> ",process); HANDLE hHandle; if(NULL == (hHandle = ::OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION,0,process))) { LOG_LASTERROR(L"OpenProcess failed"); return RETURN_LOG_INTERNAL_ERROR; } if(DIAGLIB_OK == (iReturnCode = processWaitFromHandle(hHandle, exitCode, waitTimeSecs))) { LOG(L"DONE\n"); } if(!CloseHandle( hHandle )) { LOG_LASTERROR(L"CloseHandle failed"); } return iReturnCode; }
int processStart(Proc_NAME process, Proc_ID *id, int waitTimeSecs, int *exitCode) { int iReturnCode = DIAGLIB_OK; if(process.empty() || id == NULL) { return RETURN_LOG_BAD_FUNCTION_CALL; } LOG_TIME(L"Ask for start process named '%ls' --> ",process.c_str()); STARTUPINFO siStartupInfo; PROCESS_INFORMATION piProcessInfo; ZeroMemory(&siStartupInfo, sizeof(siStartupInfo)); ZeroMemory(&piProcessInfo, sizeof(piProcessInfo)); siStartupInfo.cb = sizeof(siStartupInfo); if (!CreateProcess(NULL,(LPWSTR)process.c_str(),0,0,false,0,NULL,NULL, &siStartupInfo, &piProcessInfo)) { LOG_LASTERROR(L"CreateProcess failed"); iReturnCode = DIAGLIB_ERR_PROCESS_START_FAILED; } else { *id=piProcessInfo.dwProcessId; Sleep(100); LOG(L"STARTED with pid=%ld\n",*id); if(waitTimeSecs>0) { iReturnCode=processWait(*id, exitCode, waitTimeSecs); } } return iReturnCode; }
int processKill(Proc_ID process) { int iReturnCode = DIAGLIB_OK; if(process == 0) { return RETURN_LOG_BAD_FUNCTION_CALL; } LOG_TIME(L"Ask for killing pid=%ld --> ",process); HANDLE hHandle = NULL; if(NULL == (hHandle = ::OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,0,process))) { LOG_LASTERROR(L"OpenProcess failed"); return RETURN_LOG_INTERNAL_ERROR; } DWORD dwExitCode = 0; if(!::TerminateProcess(hHandle,dwExitCode)) { LOG_LASTERROR(L"TerminateProcess failed"); iReturnCode = DIAGLIB_ERR_PROCESS_KILL_FAILED; } else { if(!::GetExitCodeProcess(hHandle,&dwExitCode)) { LOG_LASTERROR(L"GetExitCodeProcess failed"); iReturnCode = RETURN_LOG_INTERNAL_ERROR; } else { LOG(L"FOUND and KILLED (Return code = %ld)\n",dwExitCode); } } if(!CloseHandle( hHandle )) { LOG_LASTERROR(L"CloseHandle failed"); } return iReturnCode; }
void EndpointServiceProxy::deliverMsg(const long connectionId, const string& msg, long mid, int msgType){ MilliTimer tStart; ReadLock lock(mutex_); EndpointServicePrx proxy = getProxy(connectionId); if(!proxy){ LOG_ERROR("EndpointServiceProxy::deliverMsg => get proxy failure : cid = " << connectionId); return; } try{ proxy->deliverMsg(connectionId, msg); }catch(std::exception& e){ std::cout<<"EndpointServicePrx deliverMsg catch exception ="<<e.what()<<std::endl; }catch(...){ std::cout<<"EndpointServicePrx deliverMsg unknow exception"<<std::endl; } LOG_TIME("EndpointServicePrx::deliverMsg|" << tStart.elapsed() ); return; }
int log_mesg (int id , int n , enum type_log t , char * mesg , ...) { Log * lg = NULL ; if ((lg = malloc (sizeof(Log))) == NULL) return -1 ; LOG_ID(lg) = id ; LOG_TYPE(lg) = t ; LOG_TIME(lg) = time(NULL) ; if (n) { if ((LOG_MESG(lg) = malloc (n+1)) == NULL) { free(lg); return -1 ; } va_list ap ; va_start (ap , mesg) ; vsnprintf (LOG_MESG(lg) , n , mesg , ap); LOG_MESG(lg)[n] = '\0' ; } else { if ((LOG_MESG(lg) = strdup(mesg)) == NULL) { free(lg); return -1 ; } } sem_wait(&(LISTE_SEMAPHORE(file_logs))); liste_add(file_logs , LISTE_QUEUE(file_logs) , lg); sem_post(&(LISTE_SEMAPHORE(file_logs))); sem_post(&(sem_log)) ; return 0 ; }
void QuadBackground::Render(OpenGL * openGL) { struct timespec start,end; SET_TIME(&start); OpenGLSettings(); //Draw object SetMatrices(openGL); //glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textureID); glUniform1i(openGL->renderData.textureLocation,0); //Debugging - Draw a solid color to texture if (ENABLE_TEXTURE_COLOR) { u_int32_t * pxData = new u_int32_t[textureWidth*textureHeight]; for (int i=0;i<(textureWidth*textureHeight);i++) { pxData[i] = 123912048; } glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, pxData); delete[] pxData; } //Update the texture glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,imageWidth,imageHeight, GL_RGBA, GL_UNSIGNED_BYTE, imagePixels); openGL->DrawGLObject(testCube); openGL->DrawGLObject(texturedQuad); ResetGLSettings(); SET_TIME(&end); LOG_TIME("QuadBG Render", start, end); }
int main(int argc, char **argv) { #ifdef USE_MPI MPI_Init(&argc, &argv); #endif if (argc != 5) { LOG_ERROR("I want width, height, zombies, iterations.\n"); #ifdef USE_MPI MPI_Finalize(); #endif exit(1); } int width = atoi(argv[1]); int height = atoi(argv[2]); int people = (int) (width * height * INITIAL_DENSITY); int zombies = atoi(argv[3]); int iters = atoi(argv[4]); initRandom(0); WorldPtr input, output; double ratio = divideWorld(&width, &height, &input, &output); // there should not be any output prior to this point #ifdef REDIRECT initRedirectToFiles(input); #endif LOG_DEBUG("World size is %d x %d at position [%d, %d] of %d x %d\n", input->localWidth, input->localHeight, input->globalX, input->globalY, input->globalColumns, input->globalRows); if (input->globalX == 0 && input->globalY == 0) { randomDistribution(input, people * ratio, zombies, 0); } else { // no zombies elsewhere randomDistribution(input, people * ratio, 0, 0); } #ifndef NIMAGES printWorld(input, false); #endif Timer timer = startTimer(); Stats cumulative = NO_STATS; for (int i = 0; i < iters; i++) { simulateStep(input, output); output->stats.clock = cumulative.clock = output->clock; Stats stats = output->stats; mergeStats(&cumulative, stats, false); printStatistics(output, cumulative); WorldPtr temp = input; input = output; output = temp; input->stats = stats; } double elapsedTime = getElapsedTime(timer); #ifdef _OPENMP int numThreads = omp_get_max_threads(); #else int numThreads = 1; #endif LOG_TIME("Simulation took %f milliseconds with %d threads\n", elapsedTime, numThreads); // this is a clean up // we destroy both worlds destroyWorld(input); destroyWorld(output); destroyRandom(); #ifdef REDIRECT finishRedirectToFiles(); #endif #ifdef USE_MPI MPI_Finalize(); #endif }
void ARController::ProcessFrame(Engine * engine) { if (!isInitialized) return; frameCount++; //Calc FPS struct timespec currentTime; SET_TIME(¤tTime); double frameTimeMicrosec = calc_time_double(lastFrameTime,currentTime); lastFrameTime = currentTime; float frameFps = (float)(1000000.0/frameTimeMicrosec); fpsAverage = (fpsAverage+frameFps)/2.0f; char fpsString[10]; sprintf(fpsString,"%3.1f",fpsAverage); fpsLabel->SetText(fpsString); int debugLevel = debugUI->GetIntegerParameter("ARControllerDebug"); bool useGuess = debugUI->GetBooleanParameter("UseGuess"); bool showEntireBinary = debugUI->GetBooleanParameter("Show Entire Binary"); //This section is the default per-frame operations FrameItem * item = frameList->next(); item->clearOldData(); //engine->getTime(&item->time); LOGV(LOGTAG_ARCONTROLLER,"Processing frame #%d, FPS=%f.",frameCount,fpsAverage); //Loose objects: QR=%d, Rect=%d, Circ=%d, FP=%d", //frameCount,fpsAverage,(int)QRCode::instanceCount,DebugRectangle::instanceCount,DebugCircle::instanceCount, FinderPattern::instanceCount); //If paused, keep reusing image until unpaused if (!paused) { getImages(engine); } else { //Need to refresh the RGB image cvtColor(*grayImage, *rgbImage, CV_GRAY2RGBA, 4); } vector<Drawable*> debugVector; item->qrCode = qrFinder->LocateQRCodes(*grayImage, debugVector, ( frameList->size() > 1) ? frameList->getRelative(-1)->qrCode : NULL); //What happens past here depends on the state if (controllerState == ControllerStates::Loading) { //Update world loader worldLoader->Update(engine); WorldStates::WorldState worldState = worldLoader->GetState(); if (worldState == WorldStates::LookingForCode) { debugUI->SetLabelValue("State","Searching"); if (item->qrCode != NULL && item->qrCode->isValidCode()) { struct timespec decodeStart,decodeEnd; SET_TIME(&decodeStart); qrDecoder->DecodeQRCode(grayImage,binaryImage,item->qrCode,debugVector); SET_TIME(&decodeEnd); LOG_TIME("Decode",decodeStart,decodeEnd); if (item->qrCode->isDecoded()) { string codeText = "Code="; codeText.append(item->qrCode->TextValue); debugUI->SetLabelValue("CurrentCode",codeText); currentCode = item->qrCode->TextValue; if (debugUI->GetBooleanParameter("CodeOnly")) { LOGI(LOGTAG_ARCONTROLLER,"Code found (%s), still searching since we're in debug mode",currentCode.c_str()); } else if (engine->communicator->IsConnected()) { worldLoader->LoadRealm(item->qrCode->TextValue); } else //If not connected, just add a test object { LOGI(LOGTAG_ARCONTROLLER,"Starting in offline mode."); debugUI->SetLabelValue("State","OfflineMode"); initializeARView(engine); ARObject * myCube1 = new ARObject(OpenGLHelper::CreateMultiColorCube(20),Point3f(0,0,0)); //ARObject * myCube2 = new ARObject(OpenGLHelper::CreateMultiColorCube(20),Point3f(50,10,0)); //augmentedView->AddObject(myCube2); //myCube2->BoundingSphereRadius = 30; //ARObject * myCube3 = new ARObject(OpenGLHelper::CreateMultiColorCube(20),Point3f(-50,-10,0)); //augmentedView->AddObject(myCube3); //myCube3->BoundingSphereRadius = 30; augmentedView->AddObject(myCube1); myCube1->BoundingSphereRadius = 12; SetState(ControllerStates::Running); delete worldLoader; worldLoader = NULL; } } else LOGD(LOGTAG_ARCONTROLLER,"QRCode not decoded"); } } else if (worldState == WorldStates::WaitingForRealm || worldState == WorldStates::WaitingForResources) { if (worldState == WorldStates::WaitingForRealm) debugUI->SetLabelValue("State","WaitRealm"); else debugUI->SetLabelValue("State","WaitRsrc"); } //The world is ready and loaded, so do normal AR processing else if (worldState == WorldStates::WorldReady) { debugUI->SetLabelValue("State","LoadCompl"); initializeARView(engine); LOGD(LOGTAG_ARCONTROLLER,"Populating ARView using loaded world"); worldLoader->PopulateARView(augmentedView); SetState(ControllerStates::Running); currentQRSize = debugUI->GetParameter("QRSize"); //Should be using value from server delete worldLoader; worldLoader = NULL; } else { char stateString[100]; sprintf(stateString,"WrldState=%d",(int)worldState); debugUI->SetLabelValue("State",stateString); LOGW(LOGTAG_ARCONTROLLER,"Unexpected state"); } } else if (controllerState == ControllerStates::Running) { debugUI->SetLabelValue("State","Run"); bool doSkip = false; if (item->qrCode != NULL && item->qrCode->isValidCode()) { if (recheckNext) { LOGD(LOGTAG_ARCONTROLLER,"Rechecking code. Current value = %s",currentCode.c_str()); qrDecoder->DecodeQRCode(grayImage,binaryImage,item->qrCode,debugVector); if (item->qrCode->isDecoded() && item->qrCode->TextValue != currentCode) { if (worldLoader == NULL) worldLoader = new WorldLoader(); else { delete worldLoader; worldLoader = new WorldLoader(); } LOGD(LOGTAG_ARCONTROLLER,"Changing to code %s",currentCode.c_str()); currentCode = item->qrCode->TextValue; worldLoader->LoadRealm(currentCode); SetState(ControllerStates::Loading); delete augmentedView; augmentedView = NULL; recheckNext = false; doSkip = true; } else if (item->qrCode->isDecoded()) recheckNext = false; } else { if (useGuess) positionSelector->GetPreviousResult(item); LOGV(LOGTAG_QR,"Getting position"); currentQRSize = debugUI->GetParameter("QRSize"); //Should be using value from server item->qrCode->QRCodeDimension = currentQRSize; qrLocator->transformPoints(item->qrCode,*(item->rotationMatrix),*(item->translationMatrix),useGuess); debugUI->SetTranslation(item->translationMatrix); debugUI->SetRotation(item->rotationMatrix); } } certaintyIndicator->EnableOutline(recheckNext); if (!doSkip) { //Evaluate the position float resultCertainty = positionSelector->UpdatePosition(engine,item); certaintyIndicator->SetCertainty(resultCertainty); if (resultCertainty > 0 && augmentedView != NULL) { augmentedView->SetFOV(debugUI->GetParameter("FOV")); augmentedView->SetTransformations(item->translationMatrix,item->rotationMatrix,item->gyroRotation); } if (augmentedView != NULL) augmentedView->Update(rgbImage,engine); } } else { char stateString[100]; sprintf(stateString,"ContState=%d",(int)controllerState); debugUI->SetLabelValue("State",stateString); LOGW(LOGTAG_ARCONTROLLER,"Unexpected state: %s",stateString); } if (debugUI->currentDrawMode == DrawModes::BinaryImage) { if (showEntireBinary) { ImageProcessor::SimpleThreshold(grayImage,binaryImage); cvtColor(*binaryImage, *rgbImage, CV_GRAY2RGBA, 4); } else { LOGD(LOGTAG_ARCONTROLLER,"Binary debug draw"); cvtColor(*binaryImage, *rgbImage, CV_GRAY2RGBA, 4); LOGD(LOGTAG_ARCONTROLLER,"Binary debug draw complete"); } } if (drawingLevel == 1 || drawingLevel == 3) { if (item->qrCode != NULL) { item->qrCode->SetDrawingLevel(debugLevel); item->qrCode->Draw(rgbImage); } struct timespec draw_start, draw_end; SET_TIME(&draw_start); while (!debugVector.empty()) { debugVector.back()->Draw(rgbImage); delete debugVector.back(); debugVector.pop_back(); } SET_TIME(&draw_end); LOG_TIME_PRECISE("DebugDrawing",draw_start,draw_end); } else //Still need to clean up debug vector!!!! { struct timespec draw_start, draw_end; SET_TIME(&draw_start); while (!debugVector.empty()) { delete debugVector.back(); debugVector.pop_back(); } SET_TIME(&draw_end); LOG_TIME_PRECISE("DebugCleanup",draw_start,draw_end); } //Do final processing Draw(rgbImage); }
//////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////// PUBLIC FUNCTIONS ///////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// int processUsingLibrary(Lib_ID library, Proc_LIST *processList) { int iReturnCode = DIAGLIB_OK; if(library.empty() || processList==NULL) { return RETURN_LOG_BAD_FUNCTION_CALL; } LOG_TIME(L"Check for use of library '%ls' --> ",library.c_str()); processList->clear(); HANDLE hProcessSnap; HANDLE hProcess; PROCESSENTRY32 pe32; bool bUsed=false; if(INVALID_HANDLE_VALUE == ( hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0))) { LOG_LASTERROR(L"CreateToolhelp32Snapshot failed"); return RETURN_LOG_INTERNAL_ERROR; } pe32.dwSize = sizeof(PROCESSENTRY32); //Get progressMax if request int progressMax = 0; if (!Process32First(hProcessSnap, &pe32)) { LOG_LASTERROR(L"Process32First failed"); if(!CloseHandle( hProcessSnap )) { LOG_LASTERROR(L"CloseHandle failed"); } return RETURN_LOG_INTERNAL_ERROR; } do { progressMax++; } while (Process32Next(hProcessSnap, &pe32)); if (!Process32First(hProcessSnap, &pe32)) { LOG_LASTERROR(L"Process32First failed"); if(!CloseHandle( hProcessSnap )) { LOG_LASTERROR(L"CloseHandle failed"); } return RETURN_LOG_INTERNAL_ERROR; } progressInit(progressMax); int count=0; do { //We avoid the process System because the isModuleUsedByProcess return an error if ( 0 != lstrcmpi(L"System", pe32.szExeFile)) { hProcess = AdvanceOpenProcess(pe32.th32ProcessID, PROCESS_ALL_ACCESS); //If we need the exe name, we need pe32.szExeFile if(DIAGLIB_OK != isModuleUsedByProcess(pe32.th32ProcessID, library.c_str(),&bUsed)) { LOG(L"isModuleUsedByProcess failed with Process '%ls' (pid=%ld)\n",pe32.szExeFile,pe32.th32ProcessID); } else { if(bUsed) { processList->push_back(pe32.th32ProcessID); LOG(L"FOUND Process '%ls' (pid=%ld)\n",pe32.szExeFile,pe32.th32ProcessID); } } } progressIncrement(); } while (Process32Next(hProcessSnap, &pe32)); progressRelease(); if(!CloseHandle( hProcessSnap )) { LOG_LASTERROR(L"CloseHandle failed"); } if(!bUsed) LOG(L"NOT USED\n"); return iReturnCode; }
//////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////// PRIVATE FUNCTIONS //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// int processFillList(Proc_LIST *processList, const wchar_t *processName) { int iReturnCode = DIAGLIB_OK; if(processList == NULL) { return RETURN_LOG_BAD_FUNCTION_CALL; } if(processName) { LOG_TIME(L"Ask for process list (with name = %ls) --> ",processName); } else { LOG_TIME(L"Ask for list of all process --> "); } processList->clear(); EnablePrivilege(SE_DEBUG_NAME); HANDLE hndl; if(INVALID_HANDLE_VALUE == ( hndl=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0))) { LOG_LASTERROR(L"CreateToolhelp32Snapshot failed"); return RETURN_LOG_INTERNAL_ERROR; } PROCESSENTRY32 procEntry={0}; procEntry.dwSize = sizeof( PROCESSENTRY32 ); //Get progressMax if request int progressMax = 0; if (!Process32First(hndl, &procEntry)) { LOG_LASTERROR(L"Process32First failed"); if(!CloseHandle( hndl )) { LOG_LASTERROR(L"CloseHandle failed"); } return RETURN_LOG_INTERNAL_ERROR; } do { progressMax++; } while (Process32Next(hndl, &procEntry)); if(!Process32First(hndl,&procEntry)) { LOG_LASTERROR(L"Process32First failed"); if(!CloseHandle( hndl )) { LOG_LASTERROR(L"CloseHandle failed"); } return RETURN_LOG_INTERNAL_ERROR; } progressInit(progressMax); do { if(procEntry.th32ProcessID != 0) { if(processName == NULL) { processList->push_back(procEntry.th32ProcessID); } else if(0 == _wcsicmp(procEntry.szExeFile,processName)) { processList->push_back(procEntry.th32ProcessID); } } progressIncrement(); } while(Process32Next(hndl,&procEntry)); progressRelease(); if(!CloseHandle( hndl )) { LOG_LASTERROR(L"CloseHandle failed"); } if(processList->size() == 0) { LOG(L"NO PROCESS FOUND\n"); } else { LOG(L"pid="); for (unsigned long i=0; i < processList->size() ; i++) { LOG(L"%ld,",processList->at(i)); } LOG(L"DONE\n"); } return iReturnCode; }
void * logs (void * v) { Log * lg = NULL ; Param_log * p = (Param_log *) v ; FILE * f_g = PARAM_LOG_FG(p) ; FILE * f_c = PARAM_LOG_FC(p) ; FILE * f_s = PARAM_LOG_FS(p) ; if (f_g == NULL) f_g = stdout ; if (f_c == NULL) f_c = stdout ; if (f_s == NULL) f_s = stdout ; int * res = malloc (sizeof(int)) ; *res = -1 ; while (1) { lg = NULL ; sem_wait (&(sem_log)) ; sem_wait(&LISTE_SEMAPHORE(file_logs)); liste_rm(file_logs , NULL , (void **)&lg); sem_post(&LISTE_SEMAPHORE(file_logs)); if (lg != NULL) { t = ctime(&LOG_TIME(lg)) ; t[TIME_BUF_SIZE-2] = '\0' ; fprintf(f_g , "log general %s: %d %s\n" , t , LOG_ID(lg) , LOG_MESG(lg)); switch(LOG_TYPE(lg)) { case LOG_CONNEXION : fprintf(f_c , "log connexion %s: %d %s\n" , t , LOG_ID(lg) , LOG_MESG(lg)); break ; case LOG_STAT : fprintf(f_s , "log stat %s: %d %s\n" , t , LOG_ID(lg) , LOG_MESG(lg)); break ; case LOG_GENERAL : break ; case LOG_DECONNEXION : fclose(f_g); fclose(f_c); fclose(f_s); goto end ; } destroy_log((void *) lg); } } end : *res = 0 ; free(p); pthread_exit(res) ; }
int EDT_UtilReg_LogPermissions(HKEY hRootKey, const wchar_t *wzKey) { int iReturnCode = EDT_OK; int err = ERROR_SUCCESS; HKEY hRegKey; LOG_ENTER(); LOG_TIME(L"registry key (%ls\\%ls) --> \n",hRootKey==HKEY_CURRENT_USER?L"HKCU":L"HKLM",wzKey); if(ERROR_SUCCESS != (err = RegOpenKeyEx(hRootKey, wzKey, 0L, KEY_READ , &hRegKey))) { if(err != ERROR_FILE_NOT_FOUND) { LOG_ERRORCODE(L"RegOpenKeyEx failed",err); return EDT_ERR_REGISTRY_READ_FAILED; } else { LOG_EXIT(L"NOT FOUND\n"); return EDT_ERR_REGISTRY_NOT_FOUND; } } PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL; DWORD lcbSecurityDescriptor = 0; if(ERROR_INSUFFICIENT_BUFFER == (err = RegGetKeySecurity(hRegKey, DACL_SECURITY_INFORMATION, pSecurityDescriptor, &lcbSecurityDescriptor))) { pSecurityDescriptor = (PSECURITY_DESCRIPTOR)malloc(lcbSecurityDescriptor); if(ERROR_SUCCESS != (err = RegGetKeySecurity(hRegKey, DACL_SECURITY_INFORMATION, pSecurityDescriptor, &lcbSecurityDescriptor))) { LOG_ERRORCODE(L"RegQueryValueEx failed",err); iReturnCode = EDT_ERR_REGISTRY_READ_FAILED; } else { BOOL bDaclPresent = FALSE; BOOL bDaclDefaulted = FALSE; PACL pDacl = NULL; GetSecurityDescriptorDacl(pSecurityDescriptor, &bDaclPresent, &pDacl, &bDaclDefaulted); if(bDaclPresent == TRUE) { if(pDacl == NULL) { LOG(L"A NULL discretionary access control list (DACL) found \nA NULL DACL implicitly allows all access to an object.\n"); } else { LOG(L"A discretionary access control list (DACL) was found with Length = %d\n",pDacl->AclSize); LOG(L"Number of Access Control Elements (ACE's): %d\n",pDacl->AceCount); registryLogAces(pDacl); } } else { LOG(L"No discretionary access control list (DACL) found \n"); } LPTSTR StringSecurityDescriptor; ULONG StringSecurityDescriptorLen; ConvertSecurityDescriptorToStringSecurityDescriptor(pSecurityDescriptor,SDDL_REVISION_1,DACL_SECURITY_INFORMATION, &StringSecurityDescriptor,&StringSecurityDescriptorLen); LOG(L"%s\n",(const wchar_t*)StringSecurityDescriptor); //parse info see http://msdn.microsoft.com/en-us/library/aa379570%28v=vs.85%29.aspx LocalFree(StringSecurityDescriptor); } free(pSecurityDescriptor); } else { LOG_ERRORCODE(L"RegGetKeySecurity failed",err); } if(ERROR_SUCCESS != (err = RegCloseKey(hRegKey))) { LOG_ERRORCODE(L"RegCloseKey failed",err); } LOG_EXIT(iReturnCode); return iReturnCode; }
int processGetInfo(Proc_ID process, Proc_INFO *info) { int iReturnCode = DIAGLIB_OK; if(process == 0) { return RETURN_LOG_BAD_FUNCTION_CALL; } if(info==NULL) { return RETURN_LOG_BAD_FUNCTION_CALL; } LOG_TIME(L"Ask info on pid=%ld --> ",process); DWORD bufferSize; HANDLE hHandle = NULL; if(NULL == (hHandle = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,0,process))) { if(ERROR_ACCESS_DENIED != GetLastError()) { LOG_LASTERROR(L"OpenProcess failed"); return RETURN_LOG_INTERNAL_ERROR; } else { LOG(L"ACCESS DENIED\n"); return DIAGLIB_ERR_PROCESS_ACCESS_DENIED; } } info->id=process; bufferSize = G_BUFFER_SIZE; if(!GetModuleBaseName(hHandle,NULL,g_buffer,bufferSize)) { LOG_LASTERROR(L"GetModuleBaseName failed"); iReturnCode = DIAGLIB_ERR_INTERNAL; } else { info->Name=g_buffer; } bufferSize = G_BUFFER_SIZE; if(!GetModuleFileNameEx(hHandle,NULL,g_buffer,bufferSize)) { LOG_LASTERROR(L"GetModuleFileNameEx failed"); iReturnCode = DIAGLIB_ERR_INTERNAL; } else { info->Path=g_buffer; } bufferSize = G_BUFFER_SIZE; if(!GetProcessImageFileName(hHandle,g_buffer,bufferSize)) { LOG_LASTERROR(L"QueryFullProcessImageName failed"); iReturnCode = DIAGLIB_ERR_INTERNAL; } else { info->FullPath=g_buffer; } HMODULE modulesFound[1024]; DWORD spaceActuallyRequired; if(!EnumProcessModules(hHandle,modulesFound,1024,&spaceActuallyRequired)) { LOG_LASTERROR(L"EnumProcessModules failed"); } else { info->modulesLoaded.clear(); for(unsigned int i=0;i<(spaceActuallyRequired/sizeof(HMODULE));i++) { TCHAR szModName[MAX_PATH]; if(GetModuleBaseName(hHandle,modulesFound[i],szModName,sizeof(szModName)/sizeof(TCHAR))) info->modulesLoaded.insert(szModName); //if(GetModuleFileNameEx(hHandle,modulesFound[i],szModName,sizeof(szModName)/sizeof(TCHAR))) //modInfo.path=szModName; } } if(!CloseHandle( hHandle )) { LOG_LASTERROR(L"CloseHandle failed"); } LOG(L"DONE\n"); return iReturnCode; }
static void *surface_thread(void *arg) { ASurface *surface = (ASurface *)arg; void *stream; AndroidSurfaceInfo src, dst; size_t size; LOG_TIME_DEFINE(buff); LOG_TIME_DEFINE(decode); running = 1; while(running == 1) { struct jpeg_frame *jpeg; LOG_TIME_START(buff); size = get_image_buffer(&stream); jpeg = stream; g_clear_screen_client = jpeg->encode_time; LOGD("Jerry: final g_clear_screen_client = %d", g_clear_screen_client); LOG_D("surface get buffer time delay: %d ms\n", (int)(timestamp() - jpeg->timestamp)); src.bits = stream + sizeof(struct jpeg_frame); LOG_TIME_END(buff); if((size > 0) && running) { LOG_TIME_START(decode); lib_ASurface_lock(surface, &dst); lib_ASurface_scaleToFullScreen_skia(surface, &src, &dst, size - sizeof(struct jpeg_frame)); lib_ASurface_unlockAndPost(surface); if(first_frame) { char msg[128]; first_frame = 0; frame_count = 0; last_time = timestamp(); sprintf(msg, "surface:%d:%d", jpeg->width, jpeg->height); } cal_fps(); LOG_TIME_END(decode); LOG_D("surface display time delay: %d ms, decode and display = %ld ms\n", (int)(timestamp() - jpeg->timestamp), LOG_TIME(decode) / 1000); release_image_buffer(); } // LOG_D("------get buff = %ld us, decode and display = %ld us-----\n", // LOG_TIME(buff), LOG_TIME(decode)); g_clear_screen_client = 0; } return ((void *)0); }
void AugmentedView::Render(OpenGL * openGL) { if (!canDraw) return; OpenGLRenderData renderData = openGL->renderData; struct timespec start,end; SET_TIME(&start); SetCameraPosition(renderData); OpenGLSettings(); SelectedObject * newSelection = SelectObjects(openGL); struct timespec now; SET_TIME(&now); double timediff = calc_time_double(lastSelectionTime,now); if (unselectNext) { if (selectedObject != NULL) UpdateObjectPosition(projection,selectedObject); unselectNext = false; } //Only allowed to change selections every 1.0 seconds else if (newSelection != NULL && timediff > 800000.0) { //Unselect object if selected twice if (selectedObject != NULL && selectedObject->arObject == newSelection->arObject) { UpdateObjectPosition(projection,selectedObject); } else { delete selectedObject; selectedObject = newSelection; // //Point3f cameraPosition = getCameraPosition(projection); //Point3f cameraOffset = selectedObject->arObject->position - cameraPosition; ////Initial offset between object and camera selectedObject->objectPositionDelta = getObjectScreenCoord(selectedObject->arObject->position,projection);//scameraOffset; projection.copyTo(selectedObject->originalProjectionMat); cancelSelection->SetVisible(true); releaseSelection->SetVisible(true); //LOGD(LOGTAG_ARINPUT,"CameraPositionOffset(%f,%f,%f)",cameraOffset.x,cameraOffset.y,cameraOffset.z); } lastSelectionTime = now; }else if (newSelection != NULL) { LOGD(LOGTAG_ARINPUT,"Time spacing too short for unselect. Diff=%lf",timediff); } SET_TIME(&now); bool popVector = false; timediff = calc_time_double(cursorShowTime,now); if (timediff < 5000000.0) { objectVector.push_back(testObject); popVector = true; } LOGV(LOGTAG_OPENGL,"Drawing %d ARObjects",objectVector.size()); for (int i=0;i<objectVector.size();i++) { ARObject * object = objectVector.at(i); //LOGV(LOGTAG_OPENGL,"Drawing ARObject at (%f,%f,%f)",object->position.x,object->position.y,object->position.z); //LOGV(LOGTAG_OPENGL,"With rotation (%f,%f,%f)",object->rotation.x,object->rotation.y,object->rotation.z); Mat modelMatrix = Mat::eye(4,4,CV_32F); if (selectedObject != NULL && selectedObject->arObject == object) { //Point3f cameraPosition = getCameraPosition(projection); selectedObject->arObject->position = getObject3DCoord(selectedObject->objectPositionDelta,projection);//selectedObject->objectPositionDelta + cameraPosition; /* Point3f cameraRotation = getCameraRotation(); selectedObject->arObject->rotation = selectedObject->objectRotationDelta + cameraRotation; */ } OpenGLHelper::translate(modelMatrix,Point3f(object->position.x,object->position.y,object->position.z)); OpenGLHelper::rotate(modelMatrix,object->rotation.x, Point3f(1.0f, 0.0f, 0.0f)); OpenGLHelper::rotate(modelMatrix,object->rotation.y, Point3f(0.0f, 1.0f, 0.0f)); OpenGLHelper::rotate(modelMatrix,object->rotation.z, Point3f(0.0f, 0.0f, 1.0f)); Mat tmpModelMatrix; //Use seperate scale for selection indicator if (selectedObject != NULL && selectedObject->arObject == object) { modelMatrix.copyTo(tmpModelMatrix); } OpenGLHelper::scale(modelMatrix,object->scale); Mat mt = Mat(modelMatrix.t()); glUniformMatrix4fv(renderData.modelMatrixLocation, 1, GL_FALSE, mt.ptr<float>(0)); openGL->DrawGLObject(object->glObject); if (selectedObject != NULL && selectedObject->arObject == object) { float selectorSize = object->BoundingSphereRadius*2.25f; OpenGLHelper::scale(tmpModelMatrix,Point3f(selectorSize,selectorSize,selectorSize)); Mat mt = Mat(tmpModelMatrix.t()); glUniformMatrix4fv(renderData.modelMatrixLocation, 1, GL_FALSE, mt.ptr<float>(0)); openGL->DrawGLObject(selectionIndicator->glObject); } } //Get rid of test object if (popVector) objectVector.pop_back(); ResetGLSettings(); SET_TIME(&end); LOG_TIME("AugmentedView Render",start,end); canDraw = false; }
void Url::parseString(const char* urlString, UtlBoolean isAddrSpec) { // If isAddrSpec: // userinfo@hostport;uriParameters?headerParameters // If !isAddrSpec: // DisplayName<userinfo@hostport;urlParameters?headerParameters>;fieldParameters # ifdef TIME_PARSE OsTimeLog timeLog; LOG_TIME("start "); # endif // Try to catch when a name-addr is passed but we are expecting an // addr-spec -- many name-addr's start with '<' or '"'. if (isAddrSpec && (urlString[0] == '<' || urlString[0] == '"')) { OsSysLog::add(FAC_SIP, PRI_ERR, "Url::parseString Invalid addr-spec found (probably name-addr format): '%s'", urlString); } int workingOffset = 0; // begin at the beginning... size_t afterAngleBrackets = UTL_NOT_FOUND; if (isAddrSpec) { mAngleBracketsIncluded = FALSE; } else // ! addr-spec { // Is there a display name on the front? mDisplayName.remove(0); LOG_TIME("display <"); RegEx displayName(DisplayName); if (displayName.SearchAt(urlString, workingOffset)) { LOG_TIME("display > "); switch (displayName.Matches() /* number of substrings that matched */) { case 2: // matched unquoted sequence of tokens displayName.MatchString(&mDisplayName, 1); break; case 3: // matched a double quoted string // see performance note on DisplayName mDisplayName.append("\""); displayName.MatchString(&mDisplayName, 2); mDisplayName.append("\""); break; default: assert(false); } // does not include whitespace or the '<' workingOffset = displayName.AfterMatch(0); } // Are there angle brackets around the URI? LOG_TIME("angles < "); RegEx angleBrackets(AngleBrackets); if (angleBrackets.SearchAt(urlString, workingOffset)) { LOG_TIME("angles > "); // yes, there are angle brackets workingOffset = angleBrackets.MatchStart(1); // inside the angle brackets afterAngleBrackets = angleBrackets.AfterMatch(0); // following the '>' /* * Note: We do not set mAngleBracketsIncluded just because we saw them * That is only used for explicit control from the outside. * The local knowledge of whether or not there are angle brackets * is whether or not afterAngleBrackets == UTL_NOT_FOUND */ } } /* * AMBIGUITY - there is a potential ambiguity when parsing real URLs. * * Consider the url 'foo:333' - it could be: * scheme 'foo' host '333' ('333' is a valid local host name - bad idea, but legal) * or host 'foo' port '333' (and scheme 'sip' is implied) * * Now make it worse by using 'sips' as a hostname: * 'sips:333' * scheme 'sips' host '333' * or host 'sips' port '333' (and scheme 'sip' is implied) * * We resolve the first case by treating anything left of the colon as a scheme if * it is one of the supported schemes. Otherwise, we set the scheme to the * default (sip) and go on so that it will be parsed as a hostname. This does not * do the right thing for the (scheme 'sips' host '333') case, but they get what * they deserve. */ // Parse the scheme (aka url type) LOG_TIME("scheme < "); RegEx supportedScheme(SupportedScheme); if ( (supportedScheme.SearchAt(urlString,workingOffset)) && (supportedScheme.MatchStart(0) == workingOffset) ) { LOG_TIME("scheme > "); // the scheme name matches one of the supported schemes mScheme = static_cast<Scheme>(supportedScheme.Matches()-1); workingOffset = supportedScheme.AfterMatch(0); // past the ':' } else { /* * It did not match one of the supported scheme names * so proceed on the assumption that it's a host and "sip:" is implied * Leave the workingOffset where it is (before the token). * The code below, through the parsing of host and port * treats this as an implicit 'sip:' url; if it parses ok * up to that point, it resets the scheme to SipsUrlScheme */ mScheme = UnknownUrlScheme; } // skip over any '//' following the scheme for the ones we know use that switch (mScheme) { case FileUrlScheme: case FtpUrlScheme: case HttpUrlScheme: case HttpsUrlScheme: case RtspUrlScheme: if (0==strncmp("//", urlString+workingOffset, 2)) { workingOffset += 2; } break; case UnknownUrlScheme: case SipUrlScheme: case SipsUrlScheme: case MailtoUrlScheme: default: break; } if (FileUrlScheme != mScheme) // no user part in file urls { // Parse the username and password LOG_TIME("userpass < "); RegEx usernameAndPassword(UsernameAndPassword); if ( (usernameAndPassword.SearchAt(urlString, workingOffset)) && usernameAndPassword.MatchStart(0) == workingOffset ) { LOG_TIME("userpass > "); usernameAndPassword.MatchString(&mUserId, 1); usernameAndPassword.MatchString(&mPassword, 2); workingOffset = usernameAndPassword.AfterMatch(0); } else { // username and password are optional, so not finding them is ok // leave workingOffset where it is } } // Parse the hostname and port LOG_TIME("hostport < "); RegEx hostAndPort(HostAndPort); if ( (hostAndPort.SearchAt(urlString,workingOffset)) && (hostAndPort.MatchStart(0) == workingOffset) ) { LOG_TIME("hostport > "); hostAndPort.MatchString(&mHostAddress,1); UtlString portStr; if (hostAndPort.MatchString(&portStr,2)) { mHostPort = atoi(portStr.data()); } workingOffset = hostAndPort.AfterMatch(0); if (UnknownUrlScheme == mScheme) { /* * Resolve AMBIGUITY * Since we were able to parse this as a host and port, it is now safe to * set the scheme to the implied 'sip:'. */ mScheme = SipUrlScheme; } } else { if (FileUrlScheme != mScheme) // no host is ok in a file URL { /* * This is not a file URL, so not having a recognized host name is invalid. * * Since we may have been called from a constructor, there is no way to * return an error, but at this point we know this is bad, so instead * we just log an error and set the scheme to the unknown url type and * clear any components that might have been set. */ OsSysLog::add(FAC_SIP, PRI_ERR, "Url::parseString no valid host found at char %d in '%s', " "isAddrSpec = %d", workingOffset, urlString, isAddrSpec ); mScheme = UnknownUrlScheme; mDisplayName.remove(0); mUserId.remove(0); mPassword.remove(0); } } // Next is a path if http, https, or ftp, // OR url parameters if sip or sips. // There can be no Url parameters for http, https, or ftp // because semicolon is a valid part of the path value switch ( mScheme ) { case FileUrlScheme: case FtpUrlScheme: case HttpUrlScheme: case HttpsUrlScheme: case RtspUrlScheme: { // this is an http, https, or ftp URL, so get the path LOG_TIME("path < "); RegEx urlPath(UrlPath); if ( (urlPath.SearchAt(urlString, workingOffset)) && (urlPath.MatchStart(0) == workingOffset) ) { LOG_TIME("path > "); urlPath.MatchString(&mPath,1); workingOffset = urlPath.AfterMatch(1); } } break; case SipUrlScheme: case SipsUrlScheme: { // it may have url parameters of the form ";" param "=" value ... // if it meets the right conditions: if ( isAddrSpec // in addr-spec, any param is a url param || afterAngleBrackets != UTL_NOT_FOUND // inside angle brackets there may be a url param ) { LOG_TIME("urlparm < "); RegEx urlParams(UrlParams); if ( (urlParams.SearchAt(urlString, workingOffset)) && (urlParams.MatchStart(0) == workingOffset) ) { LOG_TIME("urlparm > "); urlParams.MatchString(&mRawUrlParameters, 1); workingOffset = urlParams.AfterMatch(1); // actual parsing of the parameters is in parseUrlParameters // so that it only happens if someone asks for them. } } } break; case MailtoUrlScheme: default: // no path component break; } if (UnknownUrlScheme != mScheme) { // Parse any header or query parameters LOG_TIME("hdrparm < "); RegEx headerOrQueryParams(HeaderOrQueryParams); if( (headerOrQueryParams.SearchAt(urlString, workingOffset)) && (headerOrQueryParams.MatchStart(0) == workingOffset) ) { LOG_TIME("hdrparm > "); headerOrQueryParams.MatchString(&mRawHeaderOrQueryParameters, 1); workingOffset = headerOrQueryParams.AfterMatch(0); // actual parsing of the parameters is in parseHeaderOrQueryParameters // so that it only happens if someone asks for them. } // Parse the field parameters if (!isAddrSpec) // can't have field parameters in an addrspec { if (afterAngleBrackets != UTL_NOT_FOUND) { workingOffset = afterAngleBrackets; } LOG_TIME("fldparm < "); RegEx fieldParameters(FieldParams); if ( (fieldParameters.SearchAt(urlString, workingOffset)) && (fieldParameters.MatchStart(0) == workingOffset) ) { LOG_TIME("fldparm > "); fieldParameters.MatchString(&mRawFieldParameters, 1); // actual parsing of the parameters is in parseFieldParameters // so that it only happens if someone asks for them. } } } # ifdef TIME_PARSE UtlString timeDump; timeLog.getLogString(timeDump); printf("\n%s\n", timeDump.data()); # endif }