DCloudResource::BatchStatusResult DCloudResource::StartBatchStatus() { ASSERT(status_gahp); StringList instance_ids; StringList statuses; const char *instance_id; const char *status; int rc = status_gahp->dcloud_status_all( ResourceName(), m_username, m_password, instance_ids, statuses ); if ( rc == GAHPCLIENT_COMMAND_PENDING ) { return BSR_PENDING; } if ( rc != 0 ) { dprintf( D_ALWAYS, "Error attempting a Deltacloud batch status query: %s\n", status_gahp->getErrorString() ); return BSR_ERROR; } DCloudJob *next_job; List<DCloudJob> my_jobs; registeredJobs.Rewind(); while ( (next_job = (DCloudJob *)registeredJobs.Next()) ) { my_jobs.Insert( next_job ); } instance_ids.rewind(); statuses.rewind(); while ( (instance_id = instance_ids.next()) && (status = statuses.next()) ) { MyString hashname; hashname.formatstr( "%s#%s", ResourceName(), instance_id ); DCloudJob *job = NULL; // TODO We can get rid of the hashtable. rc = DCloudJob::JobsByInstanceId.lookup( HashKey( hashname.Value() ), job ); if ( rc != 0 ) { // Job not found. Probably okay; we might see jobs // submitted via other means, or jobs we've abandoned. dprintf( D_FULLDEBUG, "Job %s on remote host is unknown. Skipping.\n", hashname.Value() ); continue; } ASSERT( job ); job->StatusUpdate( status ); my_jobs.Delete( job ); } my_jobs.Rewind(); while ( (next_job = my_jobs.Next()) ) { next_job->StatusUpdate( NULL ); } return BSR_DONE; }
CreamResource::BatchStatusResult CreamResource::StartBatchStatus() { ASSERT(status_gahp); GahpClient::CreamJobStatusMap results; int rc = status_gahp->cream_job_status_all(ResourceName(), results); if(rc == GAHPCLIENT_COMMAND_PENDING) { return BSR_PENDING; } if(rc != 0) { dprintf(D_ALWAYS, "Error attempting a Cream batch status query: %d\n", rc); return BSR_ERROR; } for(GahpClient::CreamJobStatusMap::const_iterator it = results.begin(); it != results.end(); it++) { const GahpClient::CreamJobStatus & status = it->second; std::string full_job_id = CreamJob::getFullJobId(ResourceName(), status.job_id.c_str()); BaseJob * bjob = NULL; int rc2 = BaseJob::JobsByRemoteId.lookup( HashKey( full_job_id.c_str()), bjob); if(rc2 != 0) { // Job not found. Probably okay; we might see jobs // submitted via other means, or jobs we've abandoned. dprintf(D_FULLDEBUG, "Job %s on remote host is unknown. Skipping.\n", status.job_id.c_str()); continue; } CreamJob * job = dynamic_cast<CreamJob *>(bjob); ASSERT(job); job->NewCreamState(status.job_status.c_str(), status.exit_code, status.failure_reason.c_str()); dprintf(D_FULLDEBUG, "%d.%d %s new status: %s, %d, %s\n", job->procID.cluster, job->procID.proc, status.job_id.c_str(), status.job_status.c_str(), status.exit_code, status.failure_reason.c_str()); } #if DEBUG_CREAM { CreamJob *job; registeredJobs.Rewind(); while ( (job = dynamic_cast<CreamJob*>(registeredJobs.Next())) != NULL ) { if(job->remoteJobId == NULL) { continue; } if(results.find(job->remoteJobId) == results.end()) { dprintf(D_FULLDEBUG, "%d.%d %s NOT updated\n", job->procID.cluster, job->procID.proc, job->remoteJobId); } } } #endif return BSR_DONE; }
void KrSpriteResource::Save( KrEncoder* encoder ) { int i; bool bCompressedResource = false; //true; U32 actionSize = 0; //maks: always use per frame compression to take advantage of malloc_gc /*if(encoder->getCompressed()) { //Save all actions at same compressed data? for(i=0; i < NumActions(); ++i ) { actionSize += actionArr[i]->GetTotalSize(); if(actionSize > 2*1024*1024) { //4MB ~ 13 frames (240x320) //Compress by frame (load frame on demand) bCompressedResource = false; break; } } }*/ encoder->StartTag( KYRATAG_SPRITE, bCompressedResource ); WriteString( encoder->Stream(), ResourceName() ); encoder->WriteCached( ResourceName() ); //maks: don't save unnecessary default icon Uint32 n = NumActions(); /*bool bRemoveIcon = false; //Bug in create actor if(n > 2) //icon, text, other animation { for( int i=0; i < NumActions(); ++i ) { if(actionArr[i]->Name() == "icon") { n--; bRemoveIcon = true; break; } } }*/ SDL_WriteLE32( encoder->Stream(), n ); for(i=0; i < NumActions(); ++i ) { //if(actionArr[i]->Name() != "icon" || !bRemoveIcon) actionArr[i]->Save( encoder, !bCompressedResource ); } encoder->EndTag(); }
PRESLINK AllocResLink( PRES pRes) { PRESLINK prl; PRES pResNew; PRES2 pRes2; LPTSTR pszName; INT cbName; LPTSTR pszType; if (!(prl = (PRESLINK)MyAlloc(sizeof(RESLINK)))) return NULL; prl->prlNext = NULL; prl->cbRes = ResourceSize(pRes); if (!(prl->hRes = GlobalAlloc(GMEM_MOVEABLE, prl->cbRes))) { MyFree(prl); Message(MSG_OUTOFMEMORY); return NULL; } pResNew = (PRES)GlobalLock(prl->hRes); memcpy(pResNew, pRes, prl->cbRes); GlobalUnlock(prl->hRes); pszType = ResourceType(pRes); if (IsOrd(pszType) && OrdID(pszType) == ORDID_RT_DIALOG) { prl->fDlgResource = TRUE; pszName = ResourceName(pRes); cbName = NameOrdLen(pszName); if (!(prl->pszName = MyAlloc(cbName))) { GlobalFree(prl->hRes); MyFree(prl); return NULL; } NameOrdCpy(prl->pszName, pszName); pRes2 = ResourcePart2(pRes); prl->wLanguage = pRes2->LanguageId; } else { prl->fDlgResource = FALSE; prl->pszName = NULL; prl->wLanguage = 0; } return prl; }
int BaseResource::DoBatchStatus() { dprintf(D_FULLDEBUG, "BaseResource::DoBatchStatus for %s.\n", ResourceName()); if ( ( registeredJobs.IsEmpty() || resourceDown ) && m_batchStatusActive == false ) { // No jobs or we can't talk to the schedd, so no point // in polling daemonCore->Reset_Timer( m_batchPollTid, BatchStatusInterval() ); dprintf(D_FULLDEBUG, "BaseResource::DoBatchStatus for %s skipped for %d seconds because %s.\n", ResourceName(), BatchStatusInterval(), resourceDown ? "the resource is down":"there are no jobs registered"); return 0; } GahpClient * gahp = BatchGahp(); if ( gahp && gahp->isStarted() == false ) { int GAHP_INIT_DELAY = 5; dprintf( D_ALWAYS,"BaseResource::DoBatchStatus: gahp server not up yet, delaying %d seconds\n", GAHP_INIT_DELAY ); daemonCore->Reset_Timer( m_batchPollTid, GAHP_INIT_DELAY ); return 0; } daemonCore->Reset_Timer( m_batchPollTid, TIMER_NEVER ); if(m_batchStatusActive == false) { dprintf(D_FULLDEBUG, "BaseResource::DoBatchStatus: Starting bulk job poll of %s\n", ResourceName()); BatchStatusResult bsr = StartBatchStatus(); switch(bsr) { case BSR_DONE: dprintf(D_FULLDEBUG, "BaseResource::DoBatchStatus: Finished bulk job poll of %s\n", ResourceName()); daemonCore->Reset_Timer( m_batchPollTid, BatchStatusInterval() ); return 0; case BSR_ERROR: dprintf(D_ALWAYS, "BaseResource::DoBatchStatus: An error occurred trying to start a bulk poll of %s\n", ResourceName()); daemonCore->Reset_Timer( m_batchPollTid, BatchStatusInterval() ); return 0; case BSR_PENDING: m_batchStatusActive = true; return 0; default: EXCEPT("BaseResource::DoBatchStatus: Unknown BatchStatusResult %d", (int)bsr); } } else { BatchStatusResult bsr = FinishBatchStatus(); switch(bsr) { case BSR_DONE: dprintf(D_FULLDEBUG, "BaseResource::DoBatchStatus: Finished bulk job poll of %s\n", ResourceName()); m_batchStatusActive = false; daemonCore->Reset_Timer( m_batchPollTid, BatchStatusInterval() ); return 0; case BSR_ERROR: dprintf(D_ALWAYS, "BaseResource::DoBatchStatus: An error occurred trying to finish a bulk poll of %s\n", ResourceName()); m_batchStatusActive = false; daemonCore->Reset_Timer( m_batchPollTid, BatchStatusInterval() ); return 0; case BSR_PENDING: return 0; default: EXCEPT("BaseResource::DoBatchStatus: Unknown BatchStatusResult %d", (int)bsr); } } return 0; }
void BaseResource::StartBatchStatusTimer() { if(m_batchPollTid != TIMER_UNSET) { EXCEPT("BaseResource::StartBatchStatusTimer called more than once!"); } dprintf(D_FULLDEBUG, "Grid type for %s will use batch status requests (DoBatchStatus).\n", ResourceName()); m_batchPollTid = daemonCore->Register_Timer( 0, (TimerHandlercpp)&BaseResource::DoBatchStatus, "BaseResource::DoBatchStatus", (Service*)this ); }
static HWND SearchResource(LPCSTR lpName, int type, DLGPROC pDialogProc, LPARAM param, char *lpFileBase, int TotalFileSize, HWND parentWnd) { char *pResAll = lpFileBase + TotalFileSize; PRES pRes = (PRES)lpFileBase; char pszSearchedName[256]; char *pszType = ResourceType(pRes); char *pszName; int size = ResourceSize(pRes); char Name[512],*bb; PDIALOGBOXHEADER pdbh; HWND result; UINT_PTR ul; ul = (UINT_PTR)lpName; if (HIWORD(ul) == 0) { sprintf(pszSearchedName,"%d",LOWORD(ul)); } else if (IsOrd((char *)lpName)) { sprintf(pszSearchedName,"%d",OrdID(lpName)); } else if (lpName[1] == 0 && lpName[3] == 0) { ConvertWideString((char *)lpName,(char *)pszSearchedName); } else { strcpy(pszSearchedName,lpName); } do { if (pRes->HeaderSize+pRes->DataSize == 0) break; if (IsOrd((char *)pRes) && OrdID(pRes) == ORDID_RT_DLGINCLUDE) { /* Ignore include files */ ; } else if (IsOrd((char *)pRes) && OrdID(pRes) == ORDID_RT_RESOURCE32) { /* * This is the dummy resource that identifies a * 32 bit resource file. This resource should be * skipped also. */ } else { /* This is some other kind of a resource. See if it matches */ if (pRes->DataSize) { int size = ResourceSize(pRes); pszType = ResourceType(pRes); if (IsOrd(pszType) && OrdID(pszType) == type) { pszName = ResourceName(pRes); if (!IsOrd(pszName)) { if (pszName[1] == 0 && pszName[3] == 0) ConvertWideString(pszName,Name); else strcpy(Name,pszName); } else { sprintf(Name,"%d",OrdID(pszName)); } if (!strcmp(Name,pszSearchedName)) { /* found it.*/ if (type == 5) { /* Build a dialog box */ pdbh = (PDIALOGBOXHEADER) SkipResHeader(pRes); bb = malloc(size); memcpy(bb,pdbh,size); result = CreateDialogIndirectParam(GetModuleHandle(NULL), (LPDLGTEMPLATE)bb, parentWnd, pDialogProc,param); free(bb); return result; } else if (type == 4) { /* Build a menu */ return (HWND) ReadMenu((char *)SkipResHeader(pRes)); } else if (type == 3) { /* Build an Icon */ HICON hicon; hicon = CreateIconFromResource((PBYTE)SkipResHeader(pRes), size, TRUE, 0x30000); return (HWND)hicon; } else if (type == 1) { /* Build a cursor */ return (HWND)CreateIconFromResource((PBYTE)SkipResHeader(pRes), size, FALSE, 0x30000); } else if (type == 2 || type == 14) { /* Build bitmap */ char *start = SkipResHeader(pRes); bb = malloc(size); memcpy(bb,start,size); return (HWND) bb; } } } } } /* Move to the next resource. */ pRes = (PRES) (((char *) pRes) + pRes->HeaderSize + pRes->DataSize); DWordAlign((PBYTE *)&pRes); } while (pRes < (PRES) ((char *) pResAll + size)); return (HWND) 0; }
bool GetProcessCommandLine(const ::DWORD InProcessID, FString& OutCommandLine) { check(InProcessID); // Initialize the com library, if not already by this thread if (!FWindowsPlatformMisc::CoInitialize()) { UE_LOG(LogVSAccessor, Error, TEXT("ERROR - Could not initialize COM library!")); return false; } bool bSuccess = false; ::IWbemLocator *pLoc = nullptr; if (SUCCEEDED(::CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc))) { FComBSTR ResourceName(TEXT("ROOT\\CIMV2")); ::IWbemServices *pSvc = nullptr; if (SUCCEEDED(pLoc->ConnectServer(ResourceName, nullptr, nullptr, nullptr, 0, 0, 0, &pSvc))) { // Set the proxy so that impersonation of the client occurs if (SUCCEEDED(::CoSetProxyBlanket(pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, nullptr, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, EOAC_NONE))) { ::IEnumWbemClassObject* pEnumerator = nullptr; const FString WQLQuery = FString::Printf(TEXT("SELECT ProcessId, CommandLine FROM Win32_Process WHERE ProcessId=%lu"), InProcessID); FComBSTR WQLBstr(TEXT("WQL")); FComBSTR WQLQueryBstr(*WQLQuery); if (SUCCEEDED(pSvc->ExecQuery(WQLBstr, WQLQueryBstr, WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, nullptr, &pEnumerator))) { while (pEnumerator && !bSuccess) { ::IWbemClassObject *pclsObj = nullptr; ::ULONG uReturn = 0; if (SUCCEEDED(pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn))) { if (uReturn == 1) { ::VARIANT vtProp; ::DWORD CurProcessID = 0; if (SUCCEEDED(pclsObj->Get(TEXT("ProcessId"), 0, &vtProp, 0, 0))) { CurProcessID = vtProp.ulVal; ::VariantClear(&vtProp); } check(CurProcessID == InProcessID); if (SUCCEEDED(pclsObj->Get(TEXT("CommandLine"), 0, &vtProp, 0, 0))) { OutCommandLine = vtProp.bstrVal; ::VariantClear(&vtProp); bSuccess = true; } pclsObj->Release(); } } } pEnumerator->Release(); } } pSvc->Release(); } pLoc->Release(); } // Uninitialize the com library, if we initialized it above (don't call if S_FALSE) FWindowsPlatformMisc::CoUninitialize(); return bSuccess; }
int main(int argc, char **argv) { const char *OPTION_NAMES[OPTION_COUNT] = {"size", "buffer", "message"}; const unsigned int OPTION_DEFAULTS[OPTION_COUNT] = {64, 32, 16}; const char *curr; unsigned int endTime; int hostIndex; int i; int j; int length; char options[255 + 1]; unsigned int optionValues[OPTION_COUNT]; unsigned int repeatPeriod; const SkillResult *results; unsigned short sensorPort; unsigned int *size; unsigned int startTime; double timeOut; struct host_desc targetHost; char targetOptions[255 + 1]; const char* USAGE = "nws_ping [-d] [-repeat seconds] [-size experiment,buffer,message] [-timeout seconds] host ..."; debug = 0; memcpy(optionValues, OPTION_DEFAULTS, sizeof(OPTION_DEFAULTS)); repeatPeriod = 0; sensorPort = DefaultHostPort(SENSOR_HOST); timeOut = DEFAULT_TIMEOUT; for(i = 1; i < argc; i++) { if(*argv[i] == '-') { if(++i == argc) { fprintf(stderr, "usage: %s\n", USAGE); exit(1); } switch(argv[i - 1][1]) { case 'r': repeatPeriod = atoi(argv[i]); break; case 's': /* ** Parse the comma-delimited size list, allowing each element to ** default if unspecified (e.g. "32", "10,,5" and ",,8" are all legal). */ curr = argv[i]; memcpy(optionValues, OPTION_DEFAULTS, sizeof(OPTION_DEFAULTS)); for(size = optionValues; size < &optionValues[OPTION_COUNT]; size++) { if(isdigit((int)*curr)) { *size = 0; for( ; isdigit((int)*curr); curr++) *size = *size * 10 + *curr - '0'; if(*curr == ',') curr++; } else if(*curr == ',') { curr++; } } break; case 't': timeOut = atof(argv[i]); break; case 'd': debug = 1; break; default: fprintf(stderr, "usage: %s\n", USAGE); exit(1); break; } } else { break; } } if(i >= argc) { fprintf(stderr, "usage: %s\n", USAGE); exit(1); } options[0] = '\0'; for(j = 0; j < OPTION_COUNT; j++) sprintf(options, "%s\t%s:%d", options, OPTION_NAMES[j], optionValues[j]); while(1) { startTime = (unsigned int)CurrentTime(); for(hostIndex = i; hostIndex < argc; hostIndex++) { HostDValue(argv[hostIndex], sensorPort, &targetHost); printf("(%dk", optionValues[0]); for(j = 1; j < OPTION_COUNT; j++) { printf(",%dk", optionValues[j]); } printf(") to %s:", HostDImage(&targetHost)); sprintf(targetOptions, "%s\ttarget:%s", options, HostDImage(&targetHost)); UseSkill(tcpMessageMonitor, targetOptions, timeOut, &results, &length); if(results[0].succeeded) { for(j = 0; j < length; j++) printf(" %s: %f %s", ResourceName(results[j].resource), results[j].measurement, ResourceLabel(results[j].resource)); } else printf(" failed"); printf("\n"); } fflush(stdout); if(repeatPeriod == 0) break; endTime = (unsigned int)CurrentTime(); if((endTime - startTime) < repeatPeriod) sleep(repeatPeriod - (endTime - startTime)); } return 0; }