void CCDKSWindow::AddText(char *txt, bool wrap, int pos, int maxch) { if (maxch == -1) maxch = m_pSWindow->boxWidth-2; if (wrap) { std::istringstream fullstrm(txt); std::string line; while (fullstrm) { if (!std::getline(fullstrm, line)) break; if (line.length() > maxch) { while (line.length() > maxch) { std::string::size_type strpos = line.find_last_of(" \t\r\n", maxch-1); if (strpos == std::string::npos) strpos = maxch-1; addCDKSwindow(m_pSWindow, const_cast<char *>(line.substr(0, strpos).c_str()), pos); line.erase(0, strpos+1); } addCDKSwindow(m_pSWindow, const_cast<char *>(line.c_str()), pos); } else addCDKSwindow(m_pSWindow, const_cast<char *>(line.c_str()), pos); } } else { std::istringstream strstrm(txt); std::string line; while (strstrm) { if (std::getline(strstrm, line)) addCDKSwindow(m_pSWindow, const_cast<char *>(line.c_str()), pos); } } }
int show_info(CDKSCREEN *screen) { char *title = "<C>Wifi Info"; char *mesg; CDKSWINDOW *swindow; swindow = newCDKSwindow(screen, CENTER, CENTER, 0, 0, title, 100, TRUE, FALSE); mesg = "<C>Use the Arrow to move window."; addCDKSwindow(swindow, mesg, BOTTOM); mesg = "<C>Hit Enter to exit."; addCDKSwindow(swindow, mesg, BOTTOM); execCDKSwindow(swindow, "iwlist scanning 2>/dev/null", BOTTOM); activateCDKSwindow(swindow, 0); destroyCDKSwindow(swindow); return 0; }
void message_logged() { message_t *message; char time[12], line[255]; message = (message_t*) log.messages.tail->data; if (message->type <= display_log_type) { strftime(time, 12, "%X", localtime(&message->time)); snprintf(line, 255, "</B>%s<!B> %s: %s", time, message->source, message->description); addCDKSwindow(log_swindow, line, BOTTOM); } }
void change_display_log_type(message_type type) { node_t *node; message_t *message; char time[12], line[255]; if (type == display_log_type) return; display_log_type = NOTHING; cleanCDKSwindow(log_swindow); for (node = log.messages.head; node; node = node->next) { message = (message_t*) node->data; if (message->type <= type) { strftime(time, 12, "%X", localtime(&message->time)); snprintf(line, 255, "</B>%s<!B> %s: %s", time, message->source, message->description); addCDKSwindow(log_swindow, line, BOTTOM); } } display_log_type = type; }
/* * Demonstrate a scrolling-window. */ int main (int argc, char **argv) { /* Declare variables. */ CDKSCREEN *cdkscreen = 0; CDKSWINDOW *swindow = 0; WINDOW *cursesWin = 0; char *title = "<C></5>Error Log"; char *mesg[5]; CDK_PARAMS params; CDKparseParams(argc, argv, ¶ms, CDK_CLI_PARAMS); /* Set up CDK. */ cursesWin = initscr(); cdkscreen = initCDKScreen (cursesWin); /* Start CDK colors. */ initCDKColor(); /* Create the scrolling window. */ swindow = newCDKSwindow (cdkscreen, CDKparamValue(¶ms, 'X', CENTER), CDKparamValue(¶ms, 'Y', CENTER), CDKparamValue(¶ms, 'H', 6), CDKparamValue(¶ms, 'W', 65), title, 100, CDKparamValue(¶ms, 'N', TRUE), CDKparamValue(¶ms, 'S', FALSE)); /* Is the window null. */ if (swindow == 0) { /* Exit CDK. */ destroyCDKScreen (cdkscreen); endCDK(); /* Print out a message and exit. */ printf ("Oops. Can not seem to create the scrolling window. Is the window too small??\n"); ExitProgram (EXIT_FAILURE); } /* Draw the scrolling window. */ drawCDKSwindow (swindow, ObjOf(swindow)->box); /* Load up the scrolling window. */ addCDKSwindow (swindow, "<C></11>TOP: This is the first line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<L></11>1: This is another line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<C></11>2: This is another line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<R></11>3: This is another line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<C></11>4: This is another line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<L></11>5: This is another line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<C></11>6: This is another line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<C>Done. You can now play.", BOTTOM); addCDKSwindow (swindow, "<C>This is being added to the top.", TOP); /* Activate the scrolling window. */ activateCDKSwindow (swindow, 0); /* Check how the user exited this widget. */ if (swindow->exitType == vESCAPE_HIT) { mesg[0] = "<C>You hit escape to leave this widget."; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, mesg, 3); } else if (swindow->exitType == vNORMAL) { mesg[0] = "<C>You hit return to exit this widget."; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, mesg, 3); } /* Clean up. */ destroyCDKSwindow (swindow); destroyCDKScreen (cdkscreen); endCDK(); ExitProgram (EXIT_SUCCESS); }
int main() { char *mesg[4],*infobuf[2]; char *shared_memory; char string[1024],temp[1024]; FILE *file; Nodeinfo *mynode; int segment_id, sem_id, i = 1024, k = 1024, line, j, count; void *buf; signal(SIGTERM, cleanup_handler); signal(SIGINT, cleanup_handler); req.tv_nsec = 5000000; cursesWin = initscr(); cdkscreen = initCDKScreen(cursesWin); initCDKColor(); sprintf(temp,"<C></B/3>Process Migration - GUI for Statistics and Testing"); mesg[0] = copyChar(temp); title = newCDKLabel(cdkscreen, CENTER, TOP, mesg,1,1,0); setCDKLabel (title, mesg, 1, 1); drawCDKLabel (title, 1); freeChar (mesg[0]); loadDaemon = newCDKSwindow (cdkscreen, (COLS - 50) * 0.10, (LINES - 12) * 0.40, 12, 50, "<C></B/5>Load Daemon", 1000, 1, 0); commsDaemon = newCDKSwindow (cdkscreen, (COLS - 50) * 0.90, (LINES - 12) * 0.40, 12, 50, "<C></B/5>Communication Daemon", 1000, 1, 0); migrateDaemon = newCDKSwindow (cdkscreen, (COLS - 50) * 0.10, (LINES - 12) * 0.90, 12, 50, "<C></B/5>Migration Control Daemon", 1000, 1, 0); extraInfo = newCDKSwindow (cdkscreen, (COLS - 50) * 0.90, (LINES - 12) * 0.90, 12, 50, "<C></B/5>Information", 1000, 1, 0); //setCDKSwindowBackgroundColor(loadDaemon, "</5>"); //setCDKSwindowBackgroundColor(commsDaemon, "</5>"); //setCDKSwindowBackgroundColor(migrateDaemon, "</5>"); //setCDKSwindowBackgroundColor(extraInfo, "</5>"); file = fopen("/var/log/load","r"); while(fgets(string, 1025, file) != NULL) { substr(&temp[0],&string[0]); addCDKSwindow (loadDaemon, temp, BOTTOM); } fclose(file); file = fopen("/var/log/migrate","r"); while(fgets(string, 1025, file) != NULL) { substr(&temp[0],&string[0]); addCDKSwindow (migrateDaemon, temp, BOTTOM); } fclose(file); buf = malloc(33); file = fopen(INFO_SHM_ID_PATH,"r"); fgets(string,33,file); segment_id = atoi(string); fclose(file); file = fopen(INFO_SEM_ID_PATH,"r"); fgets(string,33,file); sem_id = atoi(string); fclose(file); info = newCDKLabel(cdkscreen, 0, (LINES - 5) * 0.15, infobuf,3,0,0); shared_memory = (void *) shmat(segment_id, 0, 0); //setCDKLabelBackgroundColor(info, "</55>"); refreshCDKScreen(cdkscreen); binary_semaphore_post(sem_id); cp_loadlog(); cp_migratelog(); for(;;) { if(i-- == 0) { cp_loadlog(); i = 1024; } file = popen("diff /tmp/migrate/load.temp /var/log/load | sed 1d | wc -l","r"); strcpy(string,"\0"); fgets(string, 1025, file); count = atoi(string); pclose(file); sprintf(string,"count: %d",count); if(count != 0) { file = popen("diff /tmp/migrate/load.temp /var/log/load | sed 1d","r"); for(j = 0; j < count; j++) { fgets(string, 1025, file); substr(&temp[0],&string[0]); addCDKSwindow (loadDaemon, temp, BOTTOM); } pclose(file); i = 0; } /*if(k-- == 0) { cp_migratelog(); k = 1024; } file = popen("diff /tmp/migrate/migrate.temp /var/log/migrate | sed 1d | wc -l","r"); strcpy(string,"\0"); fgets(string, 1025, file); count = atoi(string); pclose(file); sprintf(string,"count: %d",count); if(count != 0) { file = popen("diff /tmp/migrate/migrate.temp /var/log/migrate | sed 1d","r"); for(j = 0; j < count; j++) { fgets(string, 1025, file); substr(&temp[0],&string[0]); addCDKSwindow (migrateDaemon, temp, BOTTOM); } pclose(file); k = 0; }*/ binary_semaphore_wait(sem_id); memcpy(buf, shared_memory, 33); binary_semaphore_post(sem_id); mynode = nodeinfo__unpack(NULL, 33, buf); if(mynode == NULL) { fprintf(stderr,"error unpacking message\n"); exit(1); } sprintf(temp,"\t\t\t\t\t\t\t</B/U/7>STATISTICS"); infobuf[0] = copyChar(temp); sprintf(temp,"\t</B>Load:<!B> %0.2f\t</B>No. of peers connected:<!B> %d\t</B>No. of processes migrated:<!B> %d\t</B>No. of processes accepted:<!B> %d\t",mynode->load,mynode->np,mynode->npm,mynode->npa); infobuf[1] = copyChar(temp); sprintf(temp,"\t\t\t\t</B>Upper Threshold:<!B> %.2f\t</B>Lower Threshold:<!B> %.2f",mynode->uthresh,mynode->lthresh); infobuf[2] = copyChar(temp); setCDKLabel (info, infobuf, 3, 0); drawCDKLabel (info, 0); freeChar (infobuf[0]); freeChar (infobuf[1]); freeChar (infobuf[2]); sleep(1); } exit(0); }