/* * This pops up a message. */ void popupLabelAttrib (CDKSCREEN *screen, char **mesg, int count, chtype attrib) { CDKLABEL *popup = 0; int oldCursState; boolean functionKey; /* Create the label. */ popup = newCDKLabel (screen, CENTER, CENTER, mesg, count, TRUE, FALSE); setCDKLabelBackgroundAttrib(popup, attrib); oldCursState = curs_set(0); /* Draw it on the screen. */ drawCDKLabel (popup, TRUE); /* Wait for some input. */ keypad (popup->win, TRUE); getchCDKObject (ObjOf(popup), &functionKey); /* Kill it. */ destroyCDKLabel (popup); /* Clean the screen. */ curs_set(oldCursState); eraseCDKScreen (screen); refreshCDKScreen (screen); }
int main (void) { /* *INDENT-EQLS* */ CDKSCREEN *cdkscreen = 0; CDKLABEL *stopSign = 0; CDKLABEL *title = 0; const char *mesg[5]; const char *sign[4]; chtype key; boolean functionKey; cdkscreen = initCDKScreen (NULL); /* Start CDK Colors. */ initCDKColor (); /* Set the labels up. */ mesg[0] = "<C><#HL(40)>"; mesg[1] = "<C>Press </B/16>r<!B!16> for the </B/16>red light"; mesg[2] = "<C>Press </B/32>y<!B!32> for the </B/32>yellow light"; mesg[3] = "<C>Press </B/24>g<!B!24> for the </B/24>green light"; mesg[4] = "<C><#HL(40)>"; sign[0] = " <#DI> "; sign[1] = " <#DI> "; sign[2] = " <#DI> "; /* Declare the labels. */ title = newCDKLabel (cdkscreen, CENTER, TOP, (CDK_CSTRING2) mesg, 5, FALSE, FALSE); stopSign = newCDKLabel (cdkscreen, CENTER, CENTER, (CDK_CSTRING2) sign, 3, TRUE, TRUE); /* Do this until they hit q or escape. */ for (;;) { drawCDKLabel (title, FALSE); drawCDKLabel (stopSign, TRUE); key = (chtype)getchCDKObject (ObjOf (stopSign), &functionKey); if (key == KEY_ESC || key == 'q' || key == 'Q') { break; } else if (key == 'r' || key == 'R') { sign[0] = " </B/16><#DI> "; sign[1] = " o "; sign[2] = " o "; } else if (key == 'y' || key == 'Y') { sign[0] = " o "; sign[1] = " </B/32><#DI> "; sign[2] = " o "; } else if (key == 'g' || key == 'G') { sign[0] = " o "; sign[1] = " o "; sign[2] = " </B/24><#DI> "; } /* Set the contents of the label and re-draw it. */ setCDKLabel (stopSign, (CDK_CSTRING2) sign, 3, TRUE); } /* Clean up. */ destroyCDKLabel (title); destroyCDKLabel (stopSign); destroyCDKScreen (cdkscreen); endCDK (); ExitProgram (EXIT_SUCCESS); }
/* * This is a callback to the scrolling list which displays information * about the current file. (and the whole directory as well) */ static int displayFileInfoCB (EObjectType objectType GCC_UNUSED, void *object, void *clientData, chtype key GCC_UNUSED) { /* Declare local variables. */ CDKENTRY *entry = (CDKENTRY *)object; CDKFSELECT *fselect = (CDKFSELECT *)clientData; CDKLABEL *infoLabel; struct stat fileStat; struct passwd *pwEnt; struct group *grEnt; char *filename; char *filetype; char *mesg[10]; char temp[100]; char stringMode[15]; int len; int intMode; /* Get the file name. */ filename = fselect->entryField->info; /* Get specific information about the files. */ lstat (filename, &fileStat); /* Determine the file type. */ switch (mode2Filetype(fileStat.st_mode)) { case 'l': filetype = "Symbolic Link"; break; case '@': filetype = "Socket"; break; case '-': filetype = "Regular File"; break; case 'd': filetype = "Directory"; break; case 'c': filetype = "Character Device"; break; case 'b': filetype = "Block Device"; break; case '&': filetype = "FIFO Device"; break; default: filetype = "Unknown"; break; } /* Get the user name and group name. */ pwEnt = getpwuid (fileStat.st_uid); grEnt = getgrgid (fileStat.st_gid); /* Convert the mode_t type to both string and int. */ intMode = mode2Char (stringMode, fileStat.st_mode); /* Create the message. */ sprintf (temp, "Directory : </U>%s", fselect->pwd); mesg[0] = copyChar (temp); sprintf (temp, "Filename : </U>%s", filename); mesg[1] = copyChar (temp); sprintf (temp, "Owner : </U>%s<!U> (%d)", pwEnt->pw_name, (int)fileStat.st_uid); mesg[2] = copyChar (temp); sprintf (temp, "Group : </U>%s<!U> (%d)", grEnt->gr_name, (int)fileStat.st_gid); mesg[3] = copyChar (temp); sprintf (temp, "Permissions: </U>%s<!U> (%o)", stringMode, intMode); mesg[4] = copyChar (temp); sprintf (temp, "Size : </U>%ld<!U> bytes", (long) fileStat.st_size); mesg[5] = copyChar (temp); sprintf (temp, "Last Access: </U>%s", ctime (&fileStat.st_atime)); len = (int)strlen (temp); temp[len] = '\0'; temp[len-1] = '\0'; mesg[6] = copyChar (temp); sprintf (temp, "Last Change: </U>%s", ctime (&fileStat.st_ctime)); len = (int)strlen (temp); temp[len] = '\0'; temp[len-1] = '\0'; mesg[7] = copyChar (temp); sprintf (temp, "File Type : </U>%s", filetype); mesg[8] = copyChar (temp); /* Create the pop up label. */ infoLabel = newCDKLabel (entry->obj.screen, CENTER, CENTER, mesg, 9, TRUE, FALSE); drawCDKLabel (infoLabel, TRUE); wgetch (infoLabel->win); /* Clean up some memory. */ destroyCDKLabel (infoLabel); freeCharList (mesg, 9); /* Redraw the file selector. */ drawCDKFselect (fselect, ObjOf(fselect)->box); return (TRUE); }
/* * This displays the marker(s) on the given day. */ static int displayCalendarMarkCB (EObjectType objectType GCC_UNUSED, void *object, void *clientData, chtype key GCC_UNUSED) { /* *INDENT-EQLS* */ CDKCALENDAR *calendar = (CDKCALENDAR *)object; CDKLABEL *label = 0; struct AppointmentInfo *appointmentInfo = (struct AppointmentInfo *)clientData; int found = 0; int day = 0; int month = 0; int year = 0; int mesgLines = 0; const char *type = 0; char *mesg[10], temp[256]; int x; /* Look for the marker in the list. */ for (x = 0; x < appointmentInfo->appointmentCount; x++) { /* Get the day month year. */ /* *INDENT-EQLS* */ day = appointmentInfo->appointment[x].day; month = appointmentInfo->appointment[x].month; year = appointmentInfo->appointment[x].year; /* Determine the appointment type. */ if (appointmentInfo->appointment[x].type == vBirthday) { type = "Birthday"; } else if (appointmentInfo->appointment[x].type == vAnniversary) { type = "Anniversary"; } else if (appointmentInfo->appointment[x].type == vAppointment) { type = "Appointment"; } else { type = "Other"; } /* Find the marker by the day/month/year. */ if ((day == calendar->day) && (month == calendar->month) && (year == calendar->year) && (appointmentInfo->appointment[x].description != 0)) { /* Create the message for the label widget. */ sprintf (temp, "<C>Appointment Date: %02d/%02d/%d", day, month, year); mesg[mesgLines++] = copyChar (temp); mesg[mesgLines++] = copyChar (" "); mesg[mesgLines++] = copyChar ("<C><#HL(35)>"); sprintf (temp, " Appointment Type: %s", type); mesg[mesgLines++] = copyChar (temp); mesg[mesgLines++] = copyChar (" Description :"); sprintf (temp, " %s", appointmentInfo->appointment[x].description); mesg[mesgLines++] = copyChar (temp); mesg[mesgLines++] = copyChar ("<C><#HL(35)>"); mesg[mesgLines++] = copyChar (" "); mesg[mesgLines++] = copyChar ("<C>Press space to continue."); found = 1; break; } } /* If we didn't find the marker, create a different message. */ if (found == 0) { sprintf (temp, "<C>There is no appointment for %02d/%02d/%d", calendar->day, calendar->month, calendar->year); mesg[mesgLines++] = copyChar (temp); mesg[mesgLines++] = copyChar ("<C><#HL(30)>"); mesg[mesgLines++] = copyChar ("<C>Press space to continue."); } /* Create the label widget. */ label = newCDKLabel (ScreenOf (calendar), CENTER, CENTER, (CDK_CSTRING2)mesg, mesgLines, TRUE, FALSE); drawCDKLabel (label, ObjOf (label)->box); waitCDKLabel (label, ' '); destroyCDKLabel (label); /* Clean up the memory used. */ for (x = 0; x < mesgLines; x++) { freeChar (mesg[x]); } /* Redraw the calendar widget. */ drawCDKCalendar (calendar, ObjOf (calendar)->box); return (FALSE); }
int main (int argc, char **argv) { /* Declare variables. */ CDKSCREEN *cdkscreen = 0; CDKLABEL *demo = 0; WINDOW *cursesWin = 0; int boxLabel = 0; char *mesg[4], temp[256]; struct tm *currentTime; time_t clck; int ret; /* Parse up the command line. */ while ((ret = getopt (argc, argv, "b")) != -1) { switch (ret) { case 'b' : boxLabel = 1; } } /* Set up CDK */ cursesWin = initscr(); cdkscreen = initCDKScreen (cursesWin); /* Start CDK Colors */ initCDKColor(); /* Set the labels up. */ mesg[0] = "</1/B>HH:MM:SS"; /* Declare the labels. */ demo = newCDKLabel (cdkscreen, CENTER, CENTER, mesg, 1, boxLabel, FALSE); /* Is the label null??? */ if (demo == 0) { /* Clean up the memory. */ destroyCDKScreen (cdkscreen); /* End curses... */ endCDK(); /* Spit out a message. */ printf ("Oops. Can't seem to create the label. Is the window too small?\n"); ExitProgram (EXIT_FAILURE); } curs_set(0); wtimeout (WindowOf(demo), 50); /* Do this for-a-while... */ do { /* Get the current time. */ time(&clck); currentTime = localtime (&clck); /* Put the current time in a string. */ sprintf (temp, "<C></B/29>%02d:%02d:%02d", currentTime->tm_hour, currentTime->tm_min, currentTime->tm_sec); mesg[0] = copyChar (temp); /* Set the label contents. */ setCDKLabel (demo, mesg, 1, ObjOf(demo)->box); /* Clean up the memory used. */ freeChar (mesg[0]); /* Draw the label, and sleep. */ drawCDKLabel (demo, ObjOf(demo)->box); napms (500); } while (wgetch(WindowOf(demo)) == ERR); /* Clean up */ destroyCDKLabel (demo); destroyCDKScreen (cdkscreen); endCDK(); ExitProgram (EXIT_SUCCESS); }
void PlayInfoBox::draw(void) { drawCDKLabel (infobox, TRUE); }
void __drawCDKLabel (CDKLABEL * label, int box) { return drawCDKLabel(label, box); }
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); }