static qint64 runningApplicationPid(const QString &appRoot = QString()) { qint64 pid = readPidFileOfApplication(appRoot); if (pid > 0) { QString name = ProcessInfo(pid).processName().toLower(); if (name == "treefrog" || name == "treefrogd") return pid; } return -1; }
void MessageOutput(_In_ std::wofstream& sFile, _In_ MESSAGE_STRUCT& msg, _In_ std::set<ProcessInfo>& processes) { std::wstring messageType; switch (int(msg.body.messageType.operationStatus.ioOpType)) { case 0: messageType = std::wstring(L"IRP_MJ_CREATE"); break; case 3: messageType = std::wstring(L"IRP_MJ_READ"); break; case 4: messageType = std::wstring(L"IRP_MJ_WRITE"); break; default: messageType = std::to_wstring(int(msg.body.messageType.operationStatus.ioOpType)); break; } std::wstring procPath = std::wstring(L"Not available"); std::set<ProcessInfo>::iterator targetProc; targetProc = std::find(processes.begin(), processes.end(), ProcessInfo((int) msg.body.messageType.operationStatus.pid, L"")); if (targetProc != processes.end()) procPath = targetProc->getPath(); time_t rawtime; tm timestruct; time(&rawtime); localtime_s(×truct, &rawtime); WCHAR mountPoint[MAX_PATH]; memset(mountPoint, 0, sizeof(WCHAR) * MAX_PATH); DWORD recevied = 0; std::wstring volumePath = L"\\\\" + std::wstring(msg.body.messageType.operationStatus.guid + 2) + L"\\"; if ((::GetVolumePathNamesForVolumeNameW(volumePath.c_str(), mountPoint, MAX_PATH, &recevied)) && (recevied > 0)) volumePath = std::wstring(mountPoint); else if (::GetLastError() != ERROR_MORE_DATA) std::wcerr << L"Warning! Can't resolve guid to mount point, guid used as path. Errorcode: " << ::GetLastError() << std::endl; if (sFile.is_open()) { sFile << timestruct.tm_hour << L":" << timestruct.tm_min << L":" << timestruct.tm_sec << L";"; sFile << timestruct.tm_mday << L"." << timestruct.tm_mon + 1 << L"." << timestruct.tm_year + 1900 << L";"; sFile << msg.body.messageType.operationStatus.pid << L";" << procPath << L";"; sFile << messageType << L";"; sFile << volumePath + std::wstring(msg.body.messageType.operationStatus.path) << L";" << std::endl; } std::wcout << L"PID: " << msg.body.messageType.operationStatus.pid << std::endl; std::wcout << L"op: " << messageType << std::endl; std::wcout << L"path: " << volumePath + std::wstring(msg.body.messageType.operationStatus.path) << std::endl << std::endl; }
IndexCounters::IndexCounters() : ServerStatusSection( "indexCounters" ) { _memSupported = ProcessInfo().blockCheckSupported(); _btreeMemHits = 0; _btreeMemMisses = 0; _btreeAccesses = 0; _maxAllowed = ( numeric_limits< long long >::max() ) / 2; _resets = 0; }
/* Return the process list. This will be */ std::vector<ProcessInfo> ProcessManager::list( bool includeSystemApps ) { std::vector<ProcessInfo> list; std::list<const ProcessBase*> running = WebAppManager::instance()->runningApps(); for( std::list<const ProcessBase*>::iterator it=running.begin(); it != running.end(); it++ ) { if( (*it)->appId().size() || (!(*it)->appId().size() && includeSystemApps ) ) list.push_back( ProcessInfo( (*it)->processId(), (*it)->appId() ) ); } return list; }
QList<qint64> ProcessInfo::childProcessIds() const { QList<qint64> ids; QList<qint64> allPids = allConcurrentPids(); for (QListIterator<qint64> it(allPids); it.hasNext(); ) { qint64 p = it.next(); if (ProcessInfo(p).ppid() == pid()) { ids << p; } } return ids; }
static int ReadHub() { int length; /* number of bytes we read */ char *ch; char *linech; #ifdef EXTREMEDEBUG FILE *fp; #endif if (HubSock == NOSOCKET) return 0; /* read in a line */ length = recv(HubSock, buffer, BUFSIZE, 0); /* hub closed connection */ if (length == 0) return 0; /* error in read */ if (length == -1) { if ((errno == EWOULDBLOCK) || (errno == EAGAIN)) /* there's just nothing to read */ return 2; else { /* the connection was closed */ putlog(LOG1, "Read error from server: %s", strerror(errno)); return 0; } } Network->RecvB += length; /* * buffer may not be big enough to read the whole last line * so it may contain only part of it */ buffer[length] = '\0'; #ifdef EXTREMEDEBUG if ((fp = fopen("hybserv.hubinfo", "a+"))) { fprintf(fp, "%s", buffer); fclose(fp); } #endif /* * buffer could possibly contain several lines of info, especially if * this is the inital connect burst, so go through, and record each line * (until we hit a \n) and process it separately */ ch = buffer; linech = spill + offset; /* * The following routine works something like this: buffer may contain * several full lines, and then a partial line. If this is the case, * loop through buffer, storing each character in 'spill' until we hit a * \n or \r. When we do, process the line. When we hit the end of * buffer, spill will contain the partial line that buffer had, and * offset will contain the index of spill where we left off, so the next * time we recv() from the hub, the beginning characters of buffer will * be appended to the end of spill, thus forming a complete line. If * buffer does not contain a partial line, then linech will simply point * to the first index of 'spill' (offset will be zero) after we process * all of buffer's lines, and we can continue normally from there. */ while (*ch) { char tmp; #ifdef DEBUGMODE int ii; #endif tmp = *ch; if (IsEOL(tmp)) { *linech = '\0'; if (nextparam) { /* * It is possible nextparam will not be NULL here if there is a * line like: * PASS password :TS * where the text after the colon does not have any spaces, so we * reach the \n and do not execute the code below which sets the * next index of param[] to nextparam. Do it here. */ param[paramc++] = nextparam; } #ifdef DEBUGMODE for (ii = 0; ii < paramc; ii++) fprintf(stderr, "%s ", param[ii]); fprintf(stderr, "\n"); #endif /* * Make sure paramc is non-zero, because if the line starts with a * \n, we will immediately come here, without initializing param[0] */ if (paramc) { /* process the line */ ProcessInfo(paramc, param); } linech = spill; offset = 0; paramc = 0; nextparam = NULL; /* * If the line ends in \r\n, then this algorithm would have only * picked up the \r. We don't want an entire other loop to do the * \n, so advance ch here. */ if (IsEOL(*(ch + 1))) ch++; } else { /* make sure we don't overflow spill[] */ if (linech >= (spill + (sizeof(spill) - 1))) { ch++; continue; } *linech++ = tmp; if (tmp == ' ') { /* * Only set the space character to \0 if this is the very first * parameter, or if nextparam is not NULL. If nextparam is NULL, * then we've hit a parameter that starts with a colon (:), so * leave it as a whole parameter. */ if (nextparam || (paramc == 0)) *(linech - 1) = '\0'; if (paramc == 0) { /* * Its the first parameter - set it to the beginning of spill */ param[paramc++] = spill; nextparam = linech; } else { if (nextparam) { param[paramc++] = nextparam; if (*nextparam == ':') { /* * We've hit a colon, set nextparam to NULL, so we know not * to set any more spaces to \0 */ nextparam = NULL; /* * Unfortunately, the first space has already been set to \0 * above, so reset to to a space character */ *(linech - 1) = ' '; } else nextparam = linech; if (paramc >= MAXPARAM) nextparam = NULL; } } } offset++; } /* * Advance ch to go to the next letter in the buffer */ ch++; } return 1; } /* ReadHub() */
int main(int argc, char* argv[]) { bool LongFlag=false; bool HierFlag=true; int ResetUsage=0; int DeleteUser=0; int SetFactor=0; int SetPrio=0; int SetAccum=0; int SetBegin=0; int SetLast=0; bool ResetAll=false; int GetResList=0; std::string pool; bool GroupRollup = false; myDistro->Init( argc, argv ); config(); MinLastUsageTime=time(0)-60*60*24; // Default to show only users active in the last day for (int i=1; i<argc; i++) { if (IsArg(argv[i],"setprio")) { if (i+2>=argc) usage(argv[0]); SetPrio=i; i+=2; } else if (IsArg(argv[i],"setfactor")) { if (i+2>=argc) usage(argv[0]); SetFactor=i; i+=2; } else if (IsArg(argv[i],"setbegin")) { if (i+2>=argc) usage(argv[0]); SetBegin=i; i+=2; } else if (IsArg(argv[i],"setaccum")) { if (i+2>=argc) usage(argv[0]); SetAccum=i; i+=2; } else if (IsArg(argv[i],"setlast")) { if (i+2>=argc) usage(argv[0]); SetLast=i; i+=2; } else if (IsArg(argv[i],"resetusage")) { if (i+1>=argc) usage(argv[0]); ResetUsage=i; i+=1; } else if (IsArg(argv[i],"delete",3)) { if (i+1>=argc) usage(argv[0]); DeleteUser=i; i+=1; } else if (IsArg(argv[i],"resetall")) { ResetAll=true; } else if (IsArg(argv[i],"long",1)) { LongFlag=true; } else if (IsArg(argv[i],"hierarchical",2) || IsArg(argv[i],"heir")) { HierFlag=true; DashHier=true; } else if (IsArg(argv[i],"flat",2)) { HierFlag=false; DashHier=true; } else if (IsArg(argv[i],"grouprollup")) { GroupRollup=true; } else if (IsArg(argv[i],"grouporder")) { GroupOrder=true; HierFlag = false; DashHier = true; } else if (IsArg(argv[i],"quotas",1)) { DetailFlag |= DetailQuotas; DashQuota = true; } else if (IsArg(argv[i],"surplus")) { DetailFlag |= DetailSurplus; DashQuota = true; } else if (IsArg(argv[i],"sortkey",2)) { DetailFlag |= DetailSortKey; DashSortKey = true; } else if (IsArg(argv[i],"all")) { DetailFlag |= DetailAll; DashAll = true; } else if (IsArg(argv[i],"most",2)) { DetailFlag |= DetailMost; #ifdef DEBUG DetailFlag |= DetailGroup; #endif DashAll = true; } else if (IsArg(argv[i],"groupid")) { DetailFlag |= DetailGroup; } else if (IsArg(argv[i],"order")) { DetailFlag |= DetailOrder; } else if (IsArg(argv[i],"activefrom")) { if (argc-i<=3) usage(argv[0]); int month=atoi(argv[i+1]); int day=atoi(argv[i+2]); int year=atoi(argv[i+3]); MinLastUsageTime=CalcTime(month,day,year); // printf("Date translation: %d/%d/%d = %d\n",month,day,year,FromDate); i+=3; } else if (IsArg(argv[i],"allusers")) { MinLastUsageTime=-1; } else if (IsArg(argv[i],"usage",2)) { DetailFlag |= DetailUsage | DetailUseTime1 | DetailUseTime2; } else if (IsArg(argv[i],"priority",4)) { DetailFlag |= DetailPrios; } else if (IsArg(argv[i],"getreslist",6)) { if (argc-i<=1) usage(argv[0]); GetResList=i; i+=1; } else if (IsArg(argv[i],"pool",1)) { if (argc-i<=1) usage(argv[0]); pool = argv[i+1]; i++; } else { usage(argv[0]); } } //---------------------------------------------------------- // Get info on our negotiator Daemon negotiator(DT_NEGOTIATOR, NULL, (pool != "") ? pool.c_str() : NULL); if (!negotiator.locate()) { fprintf(stderr, "%s: Can't locate negotiator in %s\n", argv[0], (pool != "") ? pool.c_str() : "local pool"); exit(1); } if (SetPrio) { // set priority char* tmp; if( ! (tmp = strchr(argv[SetPrio+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the priority of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } float Priority=atof(argv[SetPrio+2]); // send request Sock* sock; if( !(sock = negotiator.startCommand(SET_PRIORITY, Stream::reli_sock, 0) ) || !sock->put(argv[SetPrio+1]) || !sock->put(Priority) || !sock->end_of_message()) { fprintf( stderr, "failed to send SET_PRIORITY command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The priority of %s was set to %f\n",argv[SetPrio+1],Priority); } else if (SetFactor) { // set priority char* tmp; if( ! (tmp = strchr(argv[SetFactor+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the priority of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } float Factor=atof(argv[SetFactor+2]); if (Factor<1) { fprintf( stderr, "Priority factors must be greater than or equal to " "1.\n"); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(SET_PRIORITYFACTOR, Stream::reli_sock, 0) ) || !sock->put(argv[SetFactor+1]) || !sock->put(Factor) || !sock->end_of_message()) { fprintf( stderr, "failed to send SET_PRIORITYFACTOR command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The priority factor of %s was set to %f\n",argv[SetFactor+1],Factor); } else if (SetAccum) { // set accumulated usage char* tmp; if( ! (tmp = strchr(argv[SetAccum+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the Accumulated usage of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } float accumUsage=atof(argv[SetAccum+2]); if (accumUsage<0.0) { fprintf( stderr, "Usage must be greater than 0 seconds\n"); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(SET_ACCUMUSAGE, Stream::reli_sock, 0) ) || !sock->put(argv[SetAccum+1]) || !sock->put(accumUsage) || !sock->end_of_message()) { fprintf( stderr, "failed to send SET_ACCUMUSAGE command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The Accumulated Usage of %s was set to %f\n",argv[SetAccum+1],accumUsage); } else if (SetBegin) { // set begin usage time char* tmp; if( ! (tmp = strchr(argv[SetBegin+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the begin usage time of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } int beginTime=atoi(argv[SetBegin+2]); if (beginTime<0) { fprintf( stderr, "Time must be greater than 0 seconds\n"); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(SET_BEGINTIME, Stream::reli_sock, 0) ) || !sock->put(argv[SetBegin+1]) || !sock->put(beginTime) || !sock->end_of_message()) { fprintf( stderr, "failed to send SET_BEGINTIME command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The Begin Usage Time of %s was set to %d\n", argv[SetBegin+1],beginTime); } else if (SetLast) { // set last usage time char* tmp; if( ! (tmp = strchr(argv[SetLast+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the last usage time of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } int lastTime=atoi(argv[SetLast+2]); if (lastTime<0) { fprintf( stderr, "Time must be greater than 0 seconds\n"); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(SET_LASTTIME, Stream::reli_sock, 0) ) || !sock->put(argv[SetLast+1]) || !sock->put(lastTime) || !sock->end_of_message()) { fprintf( stderr, "failed to send SET_LASTTIME command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The Last Usage Time of %s was set to %d\n", argv[SetLast+1],lastTime); } else if (ResetUsage) { // set priority char* tmp; if( ! (tmp = strchr(argv[ResetUsage+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the priority of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(RESET_USAGE, Stream::reli_sock, 0) ) || !sock->put(argv[ResetUsage+1]) || !sock->end_of_message()) { fprintf( stderr, "failed to send RESET_USAGE command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The accumulated usage of %s was reset\n",argv[ResetUsage+1]); } else if (DeleteUser) { // remove a user record from the accountant char* tmp; if( ! (tmp = strchr(argv[DeleteUser+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the record you wish\n", argv[0] ); fprintf( stderr, "\tto delete (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(DELETE_USER, Stream::reli_sock, 0) ) || !sock->put(argv[DeleteUser+1]) || !sock->end_of_message()) { fprintf( stderr, "failed to send DELETE_USER command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The accountant record named %s was deleted\n",argv[DeleteUser+1]); } else if (ResetAll) { // send request if( ! negotiator.sendCommand(RESET_ALL_USAGE, Stream::reli_sock, 0) ) { fprintf( stderr, "failed to send RESET_ALL_USAGE command to negotiator\n" ); exit(1); } printf("The accumulated usage was reset for all users\n"); } else if (GetResList) { // get resource list char* tmp; if( ! (tmp = strchr(argv[GetResList+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the priority of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(GET_RESLIST, Stream::reli_sock, 0) ) || !sock->put(argv[GetResList+1]) || !sock->end_of_message()) { fprintf( stderr, "failed to send GET_RESLIST command to negotiator\n" ); exit(1); } // get reply sock->decode(); AttrList* ad=new AttrList(); if (!ad->initAttrListFromStream(*sock) || !sock->end_of_message()) { fprintf( stderr, "failed to get classad from negotiator\n" ); exit(1); } sock->close(); delete sock; if (LongFlag) ad->fPrint(stdout); else PrintResList(ad); } else { // list priorities Sock* sock; if (!(sock = negotiator.startCommand((GroupRollup) ? GET_PRIORITY_ROLLUP : GET_PRIORITY, Stream::reli_sock, 0)) || !sock->end_of_message()) { fprintf(stderr, "failed to send %s command to negotiator\n", (GroupRollup) ? "GET_PRIORITY_ROLLUP" : "GET_PRIORITY"); exit(1); } // get reply sock->decode(); AttrList* ad=new AttrList(); if (!ad->initAttrListFromStream(*sock) || !sock->end_of_message()) { fprintf( stderr, "failed to get classad from negotiator\n" ); exit(1); } sock->close(); delete sock; // if no details specified, show priorities if ( ! DetailFlag) { DetailFlag = DetailDefault; #ifdef DEBUG DetailFlag |= DetailGroup; #endif } // if showing only prio, don't bother showing groups if ( ! (DetailFlag & ~DetailPrios) && GroupPrioIsMeaningless) { if ( ! DashHier ) HierFlag = false; HideGroups = !HierFlag; } if (LongFlag) ad->fPrint(stdout); else ProcessInfo(ad,GroupRollup,HierFlag); } exit(0); return 0; }
ProcessInfo AudioSession::GetOwnerProcess() { return ProcessInfo(this->ownerProcessId); }
Command* Runtime::Debugger::ProcessCommand(const wstring &line) { #ifdef _DEBUG wcout << L"input: |" << line << L"|" << endl; #endif // parser input is_next = is_next_line = false; Parser parser; Command* command = parser.Parse(L"?" + line); if(command) { switch(command->GetCommandType()) { case EXE_COMMAND: ProcessExe(static_cast<Load*>(command)); break; case SRC_COMMAND: ProcessSrc(static_cast<Load*>(command)); break; case ARGS_COMMAND: ProcessArgs(static_cast<Load*>(command)); break; case QUIT_COMMAND: ClearBreaks(); ClearProgram(); wcout << L"goodbye." << endl; exit(0); break; case LIST_COMMAND: { FilePostion* file_pos = static_cast<FilePostion*>(command); wstring file_name; if(file_pos->GetFileName().size() > 0) { file_name = file_pos->GetFileName(); } else { file_name = cur_file_name; } int line_num; if(file_pos->GetLineNumber() > 0) { line_num = file_pos->GetLineNumber(); } else { line_num = cur_line_num; } const wstring &path = base_path + file_name; if(FileExists(path) && line_num > 0) { SourceFile src_file(path, cur_line_num); if(!src_file.Print(line_num)) { wcout << L"invalid line number." << endl; is_error = true; } } else { wcout << L"source file or line number doesn't exist, ensure the program is running." << endl; is_error = true; } } break; case BREAK_COMMAND: ProcessBreak(static_cast<FilePostion*>(command)); break; case BREAKS_COMMAND: ProcessBreaks(); break; case PRINT_COMMAND: ProcessPrint(static_cast<Print*>(command)); break; case RUN_COMMAND: if(!cur_program) { ProcessRun(); } else { wcout << L"instance already running." << endl; is_error = true; } break; case CLEAR_COMMAND: { wcout << L" are sure you want to clear all breakpoints? [y/n] "; wstring line; getline(wcin, line); if(line == L"y" || line == L"yes") { ClearBreaks(); } } break; case DELETE_COMMAND: ProcessDelete(static_cast<FilePostion*>(command)); break; case NEXT_COMMAND: if(interpreter) { is_next = true; } else { wcout << L"program is not running." << endl; } break; case NEXT_LINE_COMMAND: if(interpreter) { is_next_line = true; } else { wcout << L"program is not running." << endl; } break; case JUMP_OUT_COMMAND: if(interpreter) { is_jmp_out = true; } else { wcout << L"program is not running." << endl; } break; case CONT_COMMAND: if(!interpreter) { wcout << L"program is not running." << endl; } cur_line_num = -2; break; case INFO_COMMAND: ProcessInfo(static_cast<Info*>(command)); break; case STACK_COMMAND: if(interpreter) { wcout << L"stack:" << endl; StackMethod* method = cur_frame->method; wcerr << L" frame: pos=" << cur_call_stack_pos << L", class=" << method->GetClass()->GetName() << L", method=" << PrintMethod(method); const long ip = cur_frame->ip; if(ip > -1) { StackInstr* instr = cur_frame->method->GetInstruction(ip); wcerr << L", file=" << method->GetClass()->GetFileName() << L":" << instr->GetLineNumber() << endl; } else { wcerr << endl; } long pos = cur_call_stack_pos - 1; do { StackMethod* method = cur_call_stack[pos]->method; wcerr << L" frame: pos=" << pos << L", class=" << method->GetClass()->GetName() << L", method=" << PrintMethod(method); const long ip = cur_call_stack[pos]->ip; if(ip > -1) { StackInstr* instr = cur_call_stack[pos]->method->GetInstruction(ip); wcerr << L", file=" << method->GetClass()->GetFileName() << L":" << instr->GetLineNumber() << endl; } else { wcerr << endl; } } while(--pos); } else { wcout << L"program is not running." << endl; } break; default: break; } is_error = false; ref_mem = NULL; return command; } else { wcout << L"-- Unable to process command --" << endl; } is_error = false; ref_mem = NULL; return NULL; }
//........................................................................ void StateRender::Render() { static double dTime = 0.0; static double frameRenderTime = 0.0, frameIdleTime = 0.0, fps = 0.0; static Vector4f vDirLight(1.0f, 1.0f, 1.0f, 0.0f); // Reset glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Update camera position/view g_pCamera->Update(); // 3D RENDERING //////////////////////////////////////////// // // Render terrain //g_pTerrain->Render(); // Render objects //g_pObjectManager->GetObject("cube")->SetWorldPos(g_pCamera->Pos() + g_pCamera->Target() * 10.0f); g_pObjectManager->GetObject("quad")->SetWorldPos(g_pCamera->Pos() + Vector3f(0.0f, 0.0f, 250.0f)); g_pObjectManager->Render(); // 2D RENDERING //////////////////////////////////////////// // float y = 0.0f; static float hFont = (float)g_pFont->FontHeight(); // Enable blending for texture transparency glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glUseProgram(g_pFont->fontProgramID()); // 1s updates static process_info pi; if (g_lFrame % 60 == 0) { pi = ProcessInfo(); fps = g_dFPS; frameIdleTime = g_dFrameIdleTime; frameRenderTime = g_dFrameRenderTime; } // current state g_pFont->RenderString_ss(2, y += hFont, "ApplicationState::%s", g_pStateHandler->CurrentType().c_str()); // current fps g_pFont->RenderString_ss(2, y += hFont * 2, "FPS: %.2f (%.4f -- %.4f)", fps, frameRenderTime, frameIdleTime); // process info g_pFont->RenderString_ss(2, y += hFont * 2, "process id %d", pi.process_id); g_pFont->RenderString_ss(2, y += hFont, "process CPU: %.2f%%", pi.process_cpu); g_pFont->RenderString_ss(2, y += hFont, "physical %.2f Mb virtual %.2f Mb", pi.process_physical, pi.process_virtual); Vector3f pos = g_pCamera->Pos(); Vector3f target = g_pCamera->Target(); // camera info g_pFont->RenderString_s(2, y += hFont * 2, "Camera info:"); g_pFont->RenderString_ss(2, y += hFont, "pos [ %.1f %.1f %.1f ]", pos.x, pos.y, pos.z); g_pFont->RenderString_ss(2, y += hFont, "target [ %.1f %.1f %.1f ]", target.x, target.y, target.z); g_pFont->RenderString_ss(2, y += hFont, "heading [ %.1f ] elevation [ %.1f ]", g_pCamera->Heading(), g_pCamera->Elevation()); // geometry info static float nVerts = (float)g_pObjectManager->GetObject("terrain")->nVertices() / 1000.0f; static float nTris = (float)g_pObjectManager->GetObject("terrain")->nIndices() / 3000.0f; static std::string name = g_pObjectManager->GetObject("terrain")->ObjectName().c_str(); g_pFont->RenderString_ss(2, y += hFont, "object: '%s' triangles: %.2fk vertices: %.2fk", name.c_str(), nTris, nVerts); // restore blending glDisable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, 0); // restore wireframe mode if (bWireframeState) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Swap buffers! glutSwapBuffers(); }
//....................................................................................... void StateMain::Render() { if (g_clearState) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); static int dt = 1; static int t = dt; static GLSLProgram *shaderBasic = m_pProgramManager->Program("basicProgram1"); static Vector4f traceColor = Vector4f(1.0f, 1.0f, 0.0f, 1.0f); static Vector4f pointColor = Vector4f(0.0f, 1.0f, 0.0f, 1.0f); static Vector4f lineColor = Vector4f(0.0f, 0.0f, 1.0f, 1.0f); static Matrix4f matModel(MATRIX_IDENTITY); m_pCamera->Update(); matModel.Identity(); // Update coordinates and interpolation // Update((float)t / 60.0f); t += dt; if (t == 0) dt = -dt; if (t == 60) dt = -dt; // 3D RENDERING //////////////////////////////////////////// // glUseProgram(shaderBasic->ProgramID()); glUniformMatrix4fv(shaderBasic->GetUniform("uniformModelMatrix"), 1, GL_TRUE, (const GLfloat *)&matModel); glUniformMatrix4fv(shaderBasic->GetUniform("uniformViewMatrix"), 1, GL_TRUE, (const GLfloat *)&m_pCamera->ViewMatrix()); glUniformMatrix4fv(shaderBasic->GetUniform("uniformProjectionMatrix"), 1, GL_TRUE, (const GLfloat *)&m_pCamera->ProjectionMatrix()); // Render curve trace glUniform4fv(shaderBasic->GetUniform("uniformColor"), 1, (const GLfloat *)&traceColor); glBindVertexArray(vaoPoints2); glEnableVertexAttribArray(shaderBasic->GetAttribute("attributePosition")); glDrawArrays(GL_LINE_STRIP, 0, nTrace); glDisableVertexAttribArray(shaderBasic->GetAttribute("attributePosition")); glBindVertexArray(0); // Render interpolation lines glUniform4fv(shaderBasic->GetUniform("uniformColor"), 1, (const GLfloat *)&lineColor); glBindVertexArray(vaoLines); glEnableVertexAttribArray(shaderBasic->GetAttribute("attributePosition")); glDrawArrays(GL_LINES, 0, 2 * nLines); glDisableVertexAttribArray(shaderBasic->GetAttribute("attributePosition")); glBindVertexArray(0); // Render points glUniform4fv(shaderBasic->GetUniform("uniformColor"), 1, (const GLfloat *)&pointColor); glBindVertexArray(vaoPoints); glEnableVertexAttribArray(shaderBasic->GetAttribute("attributePosition")); glDrawArrays(GL_POINTS, 0, nLines); glDisableVertexAttribArray(shaderBasic->GetAttribute("attributePosition")); glBindVertexArray(0); // 2D RENDERING //////////////////////////////////////////// // float y = 0.0f; static float hFont = (float)m_pFont->FontHeight(); static process_info pi; // Enable blending for texture transparency glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glUseProgram(m_pFont->fontProgramID()); // current state m_pFont->RenderString_ss(2, y += hFont, "ApplicationState::STATE_MAIN1"); // current fps m_pFont->RenderString_ss(2, y += hFont * 2, "FPS: %.2f", g_dFPS); if (g_lFrame % 60 == 0) pi = ProcessInfo(); m_pFont->RenderString_ss(2, y += hFont * 2, "process id %d", pi.process_id); m_pFont->RenderString_ss(2, y += hFont, "process CPU: %.2f%%", pi.process_cpu); m_pFont->RenderString_ss(2, y += hFont, "physical %.2f mb virtual %.2f mb", pi.process_physical, pi.process_virtual); Vector3f pos = m_pCamera->Pos(); Vector3f target = m_pCamera->Target(); m_pFont->RenderString_s(2, y += hFont * 2, "Camera info:"); m_pFont->RenderString_ss(2, y += hFont, "pos [ %.1f %.1f %.1f ]", pos.x, pos.y, pos.z); m_pFont->RenderString_ss(2, y += hFont, "target [ %.1f %.1f %.1f ]", target.x, target.y, target.z); m_pFont->RenderString_ss(2, y += hFont, "heading [ %.1f ] elevation [ %.1f ]", m_pCamera->Heading(), m_pCamera->Elevation()); m_pFont->RenderString_ss(2, y += hFont * 2, "t = %d", t); // render console static GLSLProgram *consoleShader = m_pProgramManager->Program("consoleProgram1"); static Vector4f consoleColor = Vector4f(0.0f, 0.0f, 0.0f, 0.7f); glUseProgram(consoleShader->ProgramID()); glUniform4fv(consoleShader->GetUniform("uniformColor"), 1, (const GLfloat *)&consoleColor); glBindVertexArray(vao); glEnableVertexAttribArray(consoleShader->GetAttribute("attributePosition")); glDrawArrays(GL_TRIANGLES, 0, 18); glDisableVertexAttribArray(consoleShader->GetAttribute("attributePosition")); glBindVertexArray(0); //glUseProgram(m_pFont->fontProgramID()); // restore blending and textures glDisable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, 0); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Swap buffers! glutSwapBuffers(); }
void ProcessInfo::kill(QList<qint64> pids) { for (QListIterator<qint64> it(pids); it.hasNext(); ) { ProcessInfo(it.next()).kill(); } }
void ProcessInfo::kill(qint64 ppid) { ProcessInfo(ppid).kill(); }
static DWORD ProcessArgs( int argc, char* argv[] ) { DWORD dwError = 0; DWORD iArg = 0; DWORD dwArgsLeft = argc; PSTR pszArg = NULL; if (!argc || !argv) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } iArg++; // skip first argument dwArgsLeft--; if (!dwArgsLeft) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } pszArg = argv[iArg++]; dwArgsLeft--; if (!VmAfdStringCompareA(pszArg, "help", TRUE)) { ShowUsage(); } else if (!VmAfdStringCompareA(pszArg, "join", TRUE)) { dwError = ProcessJoin( dwArgsLeft, dwArgsLeft > 0 ? &argv[iArg] : NULL); } else if (!VmAfdStringCompareA(pszArg, "leave", TRUE)) { dwError = ProcessLeave( dwArgsLeft, dwArgsLeft > 0 ? &argv[iArg] : NULL); } else if (!VmAfdStringCompareA(pszArg, "info", TRUE)) { dwError = ProcessInfo( dwArgsLeft, dwArgsLeft > 0 ? &argv[iArg] : NULL); } else { dwError = ERROR_INVALID_PARAMETER; } BAIL_ON_VMAFD_ERROR(dwError); cleanup: return dwError; error: if (dwError == ERROR_INVALID_PARAMETER || dwError == ERROR_INVALID_COMMAND_LINE) { ShowUsage(); } goto cleanup; }
// Get PID and name of each process that has our DLL loaded. static bool GetProcesses(std::vector<ProcessInfo>& processes) { // PSAPI function pointers. BOOL (WINAPI* lpfEnumProcesses)(DWORD*, DWORD, DWORD*); BOOL (WINAPI* lpfEnumProcessModules)(HANDLE, HMODULE*, DWORD, LPDWORD ); DWORD (WINAPI* lpfGetModuleBaseName)(HANDLE, HMODULE, LPCTSTR, DWORD); bool found = false; // Load library and get function pointers. HINSTANCE hInstLib = LoadLibraryA("PSAPI.DLL"); if (!hInstLib) { DBG("Failed to load PSAPI.DLL"); return false; } // Get procedure addresses. lpfEnumProcesses = (BOOL (WINAPI*)(DWORD*,DWORD,DWORD*)) GetProcAddress(hInstLib, "EnumProcesses"); lpfEnumProcessModules = (BOOL (WINAPI*)(HANDLE, HMODULE*, DWORD, LPDWORD)) GetProcAddress( hInstLib, "EnumProcessModules" ); lpfGetModuleBaseName =(DWORD (WINAPI*)(HANDLE, HMODULE, LPCTSTR, DWORD )) GetProcAddress( hInstLib, "GetModuleBaseNameW" ); if (!lpfEnumProcesses || !lpfEnumProcessModules || !lpfGetModuleBaseName) { DBG("GetProcAddress failed"); FreeLibrary(hInstLib); return false; } DWORD pidList[1000]; DWORD iCbneeded; if (!lpfEnumProcesses(pidList, sizeof(pidList), &iCbneeded)) { DBG("EnumProcesses failed"); FreeLibrary(hInstLib); return false; } // How many processes are there? int iNumProc = iCbneeded/sizeof(DWORD); // Get and match the name of each process for (int i = 0; i < iNumProc; ++i) { // First, get a handle to the process HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pidList[i]); if (processHandle) { // Get modules loaded by process int maxModules = 1000; HMODULE* hMod = 0; while (1) { hMod = new HMODULE[maxModules]; // Determine number of modules if (!lpfEnumProcessModules(processHandle, hMod, maxModules*sizeof(HMODULE), &iCbneeded)) { DWORD err = GetLastError(); if (err = ERROR_PARTIAL_COPY) { // This means that we are looking at the SYSTEM process. Skip it. delete[] hMod; hMod = 0; break; } } else if (iCbneeded <= maxModules*sizeof(HMODULE)) break; delete[] hMod; if (maxModules > 50000) { DBG("maxModules: " << maxModules); return false; // This is getting ridiculous... } } if (!hMod) continue; // Explorer? TCHAR executableName[MAX_PATH]; if (!lpfGetModuleBaseName(processHandle, hMod[0], executableName, MAX_PATH)) { DBG("GetModuleBaseName failed for process " << pidList[i]); return false; } //DBG("PROCESS " << wxAscii(executableName)); if (!_tcsicmp(executableName, wxT("explorer.exe"))) { // Explorer must always be killed processes.push_back(ProcessInfo(pidList[i], executableName, wxT(""))); continue; } // Check if any of the modules are our DLL int numModules = iCbneeded/sizeof(HMODULE); for (int j = 1; j < numModules; ++j) { TCHAR name[MAX_PATH]; if (!lpfGetModuleBaseName(processHandle, hMod[j], name, MAX_PATH)) { DBG("GetModuleBaseName failed for module " << j); return false; } if (!_tcsicmp(name, wxT("tortoiseshell.dll")) || !_tcsicmp(name, wxT("tortoiseshell64.dll"))) { DBG("Process " << pidList[i] << " has " << wxAscii(name) << " loaded"); // Yes, this process must be terminated windowTitle.clear(); EnumWindows(EnumWindowsCallback, pidList[i]); processes.push_back(ProcessInfo(pidList[i], executableName, windowTitle)); } } delete[] hMod; CloseHandle(processHandle); } } FreeLibrary(hInstLib); DBG("GetProcesses SUCCESS"); return true; }