void CodaClientApplication::slotCodaEvent (const Coda::CodaEvent &ev) { printTimeStamp(); std::printf("Event: %s\n", qPrintable(ev.toString())); switch (ev.type()) { case Coda::CodaEvent::LocatorHello: // Commands accepted now switch (m_mode) { case Ping: break; case Launch: m_trkDevice->sendProcessStartCommand(Coda::CodaCallback(this, &CodaClientApplication::handleCreateProcess), m_launchBinary, m_launchUID, m_launchArgs, QString(), m_launchDebug); break; case Install: if (m_installSilently) { m_trkDevice->sendSymbianInstallSilentInstallCommand(Coda::CodaCallback(this, &CodaClientApplication::handleSymbianInstall), m_installSisFile.toAscii(), m_installTargetDrive.toAscii()); } else { m_trkDevice->sendSymbianInstallUIInstallCommand(Coda::CodaCallback(this, &CodaClientApplication::handleSymbianInstall), m_installSisFile.toAscii()); } break; case Uninstall: m_trkDevice->sendSymbianUninstallCommand(Coda::CodaCallback(this, &CodaClientApplication::handleUninstall), m_uninstallPackage); break; case Put: { const unsigned flags = Coda::CodaDevice::FileSystem_TCF_O_WRITE |Coda::CodaDevice::FileSystem_TCF_O_CREAT |Coda::CodaDevice::FileSystem_TCF_O_TRUNC; m_putWriteOk = false; m_trkDevice->sendFileSystemOpenCommand(Coda::CodaCallback(this, &CodaClientApplication::handleFileSystemOpen), m_putRemoteFile.toAscii(), flags); } break; case Stat: { const unsigned flags = Coda::CodaDevice::FileSystem_TCF_O_READ; m_statFstatOk = false; m_trkDevice->sendFileSystemOpenCommand(Coda::CodaCallback(this, &CodaClientApplication::handleFileSystemOpen), m_statRemoteFile.toAscii(), flags); } break; case Invalid: break; } break; case Coda::CodaEvent::RunControlModuleLoadSuspended: { // Debug mode start: Continue: const Coda::CodaRunControlModuleLoadContextSuspendedEvent &me = static_cast<const Coda::CodaRunControlModuleLoadContextSuspendedEvent &>(ev); if (me.info().requireResume) { printTimeStamp(); std::printf("Continuing...\n"); m_trkDevice->sendRunControlResumeCommand(Coda::CodaCallback(), me.id()); } } break; case Coda::CodaEvent::RunControlContextRemoved: // App terminated in debug mode doExit(0); break; default: break; } }
void CodaClientApplication::slotTrkLogMessage(const QString &m) { printTimeStamp(); std::printf("%s\n", qPrintable(m)); }
/* ###### Main program ################################################### */ int main(int argc, char** argv) { union sockaddr_union localAddress; struct pollfd ufds; struct SimpleRedBlackTree objectStorage; struct SimpleRedBlackTree objectDisplay; struct SimpleRedBlackTreeNode* node; unsigned long long now; unsigned long long updateInterval = 1000000; unsigned long long purgeInterval = 30000000; unsigned long long lastUpdate = 0; size_t lastElements = ~0; size_t elements; int result; int reuse; int sd; int n; if(checkIPv6()) { string2address("[::]:0", &localAddress); setPort(&localAddress.sa, 2960); } else { string2address("0.0.0.0:0", &localAddress); setPort(&localAddress.sa, 2960); } for(n = 1;n < argc;n++) { if(!(strncmp(argv[n], "-localaddress=", 14))) { if(string2address((char*)&argv[n][14], &localAddress) == false) { fprintf(stderr, "ERROR: Bad local address <%s>\n", (char*)&argv[n][14]); exit(1); } } else if(!(strncmp(argv[n], "-updateinterval=", 16))) { updateInterval = 1000 * atol((char*)&argv[n][16]); if(updateInterval < 100000) { updateInterval = 100000; } } else if(!(strncmp(argv[n], "-purgeinterval=", 15))) { purgeInterval = 1000 * atol((const char*)&argv[n][15]); if(purgeInterval < 1000000) { purgeInterval = 1000000; } } else if(!(strncmp(argv[n], "-maxpr=", 7))) { maxPRs = atoi((const char*)&argv[n][7]); } else if(!(strncmp(argv[n], "-maxpe=", 7))) { maxPEs = atoi((const char*)&argv[n][7]); } else if(!(strncmp(argv[n], "-maxpu=", 7))) { maxPUs = atoi((const char*)&argv[n][7]); } else if(!(strncmp(argv[n], "-maxlocationsize=", 17))) { maxLocationSize = atoi((const char*)&argv[n][17]); } else if(!(strcmp(argv[n], "-compact"))) { useCompactMode = true; } else if(!(strcmp(argv[n], "-full"))) { useCompactMode = false; } else { printf("Bad argument \"%s\"!\n" ,argv[n]); fprintf(stderr, "Usage: %s {-localaddress=address:port} {-updateinterval=milliseconds} {-purgeinterval=milliseconds} {-compact|-full} {-maxpr=PRs} {-maxpe=PEs} {-maxpu=PUs} {-maxlocationsize=characters}\n", argv[0]); exit(1); } } sd = ext_socket(localAddress.sa.sa_family, SOCK_DGRAM, IPPROTO_UDP); if(sd < 0) { perror("Unable to create socket"); exit(1); } reuse = 1; if(ext_setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) { perror("setsockopt() with SO_REUSEADDR failed"); } if(bindplus(sd, &localAddress, 1) == false) { fputs("ERROR: Unable to bind socket to local address\n", stderr); exit(1); } simpleRedBlackTreeNew(&objectStorage, NULL, cspObjectStorageComparison); simpleRedBlackTreeNew(&objectDisplay, cspObjectDisplayPrint, cspObjectDisplayComparison); puts("Component Status Monitor - Version 1.0"); puts("======================================\n"); installBreakDetector(); printf("\x1b[;H\x1b[2J"); /* The first update should be in 1 second ... */ lastUpdate = getMicroTime() + 1000000 - updateInterval; while(!breakDetected()) { ufds.fd = sd; ufds.events = POLLIN; now = getMicroTime(); while(now - lastUpdate < updateInterval) { now = getMicroTime(); result = ext_poll(&ufds, 1, ((lastUpdate + updateInterval) > now) ? (int)((lastUpdate + updateInterval - now) / 1000) : 0); if((result > 0) && (ufds.revents & POLLIN)) { handleMessage(sd, &objectStorage, &objectDisplay); } else if((result < 0) && (errno == EINTR)) { goto finished; } } purgeCSPObjects(&objectStorage, &objectDisplay, purgeInterval); elements = simpleRedBlackTreeGetElements(&objectStorage); if( (elements != lastElements) || (elements > 0) ) { printf("\x1b[;H"); printTimeStamp(stdout); printf("Current Component Status -- \x1b[31;1m%u PRs\x1b[0m, \x1b[34;1m%u PEs\x1b[0m, \x1b[32;1m%u PUs\x1b[0m\x1b[0K\n\x1b[0K\n\x1b[0K\x1b[;H\n", totalPRs, totalPEs, totalPUs); maxObjectLabelSize = 0; currentPRs = 0; currentPEs = 0; currentPUs = 0; node = simpleRedBlackTreeGetFirst(&objectDisplay); while(node != NULL) { cspObjectDisplayPrint(node, stdout); node = simpleRedBlackTreeGetNext(&objectDisplay, node); } currentObjectLabelSize = maxObjectLabelSize; printf("\x1b[0J"); fflush(stdout); } lastElements = elements; lastUpdate = now; } finished: ext_close(sd); simpleRedBlackTreeDelete(&objectStorage); puts("\nTerminated!"); return(0); }
static void printIdentification(IAAFIdentification* pIdent) { aafWChar wchName[500]; char chName[1000]; AAFRESULT hr = AAFRESULT_SUCCESS; check(pIdent->GetCompanyName(wchName, sizeof (wchName))); convert(chName, sizeof(chName), wchName); printf("CompanyName = \"%s\"\n", chName); check(pIdent->GetProductName(wchName, sizeof (wchName))); convert(chName, sizeof(chName), wchName); printf("ProductName = \"%s\"\n", chName); check(pIdent->GetProductVersionString(wchName, sizeof (wchName))); convert(chName, sizeof(chName), wchName); printf("ProductVersionString = \"%s\"\n", chName); // optional aafProductVersion_t version; hr = pIdent->GetProductVersion(&version); printf("ProductVersion = "); if (hr == AAFRESULT_SUCCESS) { printProductVersion(&version); printf("\n"); } else if (hr == AAFRESULT_PROP_NOT_PRESENT) printf("(optional property not present)\n"); else check(hr); aafUID_t productID; check(pIdent->GetProductID(&productID)); formatGUID(chName, sizeof(chName), &productID); printf("ProductID = %s\n", chName); aafTimeStamp_t timeStamp; check(pIdent->GetDate(&timeStamp)); printf("Date = "); printTimeStamp(&timeStamp); printf("\n"); // optional hr = pIdent->GetRefImplVersion(&version); printf("RefImplVersion = "); if (hr == AAFRESULT_SUCCESS) { printProductVersion(&version); printf("\n"); } else if (hr == AAFRESULT_PROP_NOT_PRESENT) printf("(optional property not present)\n"); else check(hr); // optional hr = pIdent->GetPlatform(wchName, sizeof (wchName)); printf("Platform = "); if (hr == AAFRESULT_SUCCESS) { convert(chName, sizeof(chName), wchName); printf("\"%s\"\n", chName); } else if (hr == AAFRESULT_PROP_NOT_PRESENT) printf("(optional property not present)\n"); else check(hr); aafUID_t generationID; check(pIdent->GetGenerationID(&generationID)); formatGUID(chName, sizeof(chName), &generationID); printf("GenerationID = %s\n", chName); }
void *firstServer(void *mu) { //char buffer[30]; struct timeval in; //Step1: Stays in Loop while(!finish) { pthread_mutex_lock(&mutex); while(My402ListEmpty(depositQ) && !finish) // Changing from While to IF { pthread_cond_wait(&cv,&mutex); } packets *p = (packets*)malloc(sizeof(packets)); p->id = 0; if(!finish) { //printf("\n###DEQUEING Q2: S#1 \t"); My402ListElem *tmp = My402ListLast(depositQ); p = tmp->obj; //printf("PACKET ID# %ld\n",p->id); gettimeofday(&in,NULL); My402ListUnlink(depositQ,tmp); printTimeStamp(in); long di = ((in.tv_sec * 1000000 ) + (in.tv_usec)) - ((p->enterQ2.tv_sec * 1000000) + (p->enterQ2.tv_usec)); avgQ2Service += di; long mi = di /1000 ; int mic = di % 1000; pthread_mutex_lock(&filemu); printf("p%ld leaves Q2, time in Q2 = %ld.%03d ms\n",p->id,mi,mic); pthread_mutex_unlock(&filemu); gettimeofday(&in,NULL); printTimeStamp(in); p->service.tv_sec = in.tv_sec; p->service.tv_usec = in.tv_usec; pthread_mutex_lock(&filemu); if(fileInp) printf("p%ld begins service at S1, requesting %f ms of service\n",p->id,(*(double*)mu)); else printf("p%ld begins service at S1, requesting %.3f ms of service\n",p->id,(1 /(*(double*)mu)) * 1000); pthread_mutex_unlock(&filemu); } if(My402ListEmpty(depositQ) && My402ListEmpty(arrivalQ) && num_of_packs == 0) { finish = 1; } pthread_mutex_unlock(&mutex); if(!interuptflag && p->id != 0) { if(fileInp) { double tm = (*(double*)mu) / 1000.00; int secs = (int) tm; double decm = tm - secs; double milisec = 1000 * decm; // length of time to sleep, in milisecond struct timespec req = {0}; req.tv_sec = secs; req.tv_nsec = milisec * 1000000L; //printf("Server#1 Thread Sleeping for %ld secs %ld ms\n",req.tv_sec,req.tv_nsec); nanosleep(&req, (struct timespec *)NULL); gettimeofday(&in,NULL); printTimeStamp(in); long d1 = ((in.tv_sec * 1000000 ) + (in.tv_usec)) - ((p->service.tv_sec * 1000000) + (p->service.tv_usec)); avgPackService += d1; avgS1Service += d1; long m1 = d1 /1000 ; int mi1 = d1 % 1000; long d2 = ((in.tv_sec * 1000000 ) + (in.tv_usec)) - ((p->start.tv_sec * 1000000) + (p->start.tv_usec)); avgService += (d2/1000000.00); avgServiceSq = (avgServiceSq + (d2/1000000.00) * (d2/1000000.00)); long m2 = d2 /1000 ; int mi2 = d2 % 1000; pthread_mutex_lock(&filemu); printf("p%ld departs from S1, service time = %ld.%03d ms, time in system = %ld.%03d ms\n",p->id,m1,mi1,m2,mi2); pthread_mutex_unlock(&filemu); completedPack++; } else { double tm = 1 / (*(double*)mu); int secs = (int) tm ; double decm = tm - secs; double milisec = 1000 * decm; // length of time to sleep, in milisecond struct timespec req = {0}; req.tv_sec = secs; req.tv_nsec = milisec * 1000000L; //printf("Server#1 Thread Sleeping for %ld secs %ld ms\n",req.tv_sec,req.tv_nsec); nanosleep(&req, (struct timespec *)NULL); gettimeofday(&in,NULL); printTimeStamp(in); long d1 = ((in.tv_sec * 1000000 ) + (in.tv_usec)) - ((p->service.tv_sec * 1000000) + (p->service.tv_usec)); long m1 = d1 /1000 ; int mi1 = d1 % 1000; avgS1Service += d1; avgPackService += d1; long d2 = ((in.tv_sec * 1000000 ) + (in.tv_usec)) - ((p->start.tv_sec * 1000000) + (p->start.tv_usec)); avgService += (d2/1000000.00); avgServiceSq = (avgServiceSq + (d2/1000000.00) * (d2/1000000.00)); long m2 = d2 /1000 ; int mi2 = d2 % 1000; pthread_mutex_lock(&filemu); printf("p%ld departs from S1, service time = %ld.%03d ms, time in system = %ld.%03d ms\n",p->id,m1,mi1,m2,mi2); pthread_mutex_unlock(&filemu); completedPack++; } } //Step2: Goes to sleep } return(0); }