ARPDAS_QNX6 1.0
|
00001 /* tma.c Defines TMA support services */ 00002 #include <stdlib.h> 00003 #include <string.h> 00004 #include <unistd.h> 00005 #include <limits.h> 00006 #include "nortlib.h" 00007 #include "tmctime.h" 00008 #if HAVE_NL_CONS_H 00009 #include "nl_cons.h" 00010 #endif 00011 #include "tma.h" 00012 #include "oui.h" 00013 char rcsid_tma_c[] = 00014 "$Header: /cvsroot/arp-das/QNX6/tmlib/src/tma.c,v 1.2 2008/08/20 22:01:12 ntallen Exp $"; 00015 00016 tma_prtn *tma_partitions = NULL; 00017 long int tma_runbasetime = 0L; 00018 int tma_is_holding = 0; 00019 00020 /* 00021 >Command Text Goes Here 00022 Initialize Holding Next: 00:00:00 State: 00:00:00 Run: 00:00:00 00023 SNAME HOLDING NEXT NEXTTIME STATE STATETIME RUN RUNTIME 00024 */ 00025 00026 void tma_time(tma_prtn *p, unsigned int col, long int t) { 00027 char ts[9]; 00028 int hh, h; 00029 00030 if (p->row >= 0) { 00031 #if HAVE_NL_CONS_H 00032 ts[8] = '\0'; 00033 hh = t % 60; 00034 h = hh % 10; 00035 ts[7] = h+'0'; 00036 ts[6] = hh/10 + '0'; 00037 ts[5] = ':'; 00038 t /= 60; 00039 hh = t % 60; 00040 h = hh % 10; 00041 ts[4] = h+'0'; 00042 ts[3] = hh/10 + '0'; 00043 ts[2] = ':'; 00044 t /= 60; 00045 hh = t % 100; 00046 h = hh % 10; 00047 ts[1] = h+'0'; 00048 ts[0] = hh/10 + '0'; 00049 nlcon_display(p->console, p->row + 1, col, ts, TMA_ATTR); 00050 #endif 00051 } 00052 } 00053 00054 static void update_holding(tma_prtn *p) { 00055 #if HAVE_NL_CONS_H 00056 if (p->row >= 0) 00057 nlcon_display(p->console, p->row + 1, HOLDING_COL, 00058 tma_is_holding ? "Holding" : " ", HOLDING_ATTR); 00059 #endif 00060 } 00061 00062 void tma_hold(int hold) { 00063 int i, update; 00064 00065 update = 0; 00066 if (hold) { 00067 if (! tma_is_holding) { 00068 tma_is_holding = 1; 00069 update = 1; 00070 } 00071 } else { 00072 if (tma_is_holding) { 00073 tma_is_holding = 0; 00074 update = 1; 00075 } 00076 } 00077 #if HAVE_NL_CONS_H 00078 if (update) 00079 for (i = 0; i < tma_n_partitions; i++) update_holding(&tma_partitions[i]); 00080 #endif 00081 } 00082 00083 void tma_new_state(unsigned int partition, const char *name) { 00084 tma_prtn *p; 00085 00086 if (partition < tma_n_partitions) { 00087 int log_level = -2; 00088 if ( *name == '_' ) { 00089 name++; 00090 log_level--; 00091 } 00092 nl_error( log_level, "%sEntering State %s", ci_time_str(), name ); 00093 p = &tma_partitions[partition]; 00094 p->basetime = (tma_runbasetime == 0L) ? 0L : itime(); 00095 p->lastcheck = p->basetime; 00096 p->nexttime = 0; 00097 #if HAVE_NL_CONS_H 00098 if (p->row >= 0) { 00099 nlcon_display(p->console, p->row + 1, STATE_COL, 00100 " State: ", TMA_ATTR); 00101 nlcon_display(p->console, p->row + 1, RUN_COL, 00102 " Run: ", TMA_ATTR); 00103 nlcon_display(p->console, p->row + 1, SNAME_COL, 00104 " Next: ", TMA_ATTR); 00105 nlcon_display(p->console, p->row + 1, SNAME_COL, 00106 name, TMA_ATTR); 00107 nlcon_display(p->console, p->row + 1, RUNTIME_COL, 00108 RUNTIME_STRING, TMA_ATTR); 00109 update_holding(p); 00110 tma_time(p, STATETIME_COL, 0); 00111 } 00112 #endif 00113 } 00114 } 00115 00116 /* specify the next significant time for a partition */ 00117 void tma_next_cmd(unsigned int partn, const char *next_cmd) { 00118 #if HAVE_NL_CONS_H 00119 tma_prtn *p; 00120 const char *txt; 00121 int len; 00122 00123 if (partn < tma_n_partitions) { 00124 p = &tma_partitions[partn]; 00125 if (p->row >= 0) { 00126 nlcon_display(p->console, p->row, 0, ">", TMA_ATTR); 00127 nlcon_display(p->console, p->row, 1, 00128 " " 00129 " ", CMD_ATTR); 00130 len = strlen(next_cmd); 00131 if (len > 79) txt = next_cmd + (len - 79); 00132 else txt = next_cmd; 00133 nlcon_display(p->console, p->row, 1, txt, CMD_ATTR); 00134 } 00135 } 00136 #endif 00137 } 00138 00139 void tma_init_options(int argc, char **argv) { 00140 int c, con_index, part_index; 00141 00142 tma_partitions = malloc(sizeof(tma_prtn) * tma_n_partitions); 00143 if (tma_partitions == NULL) 00144 nl_error(3, "No memory for partitions table"); 00145 for (c = 0; c < tma_n_partitions; c++) { 00146 tma_partitions[c].row = -1; 00147 tma_partitions[c].cmds = NULL; 00148 tma_partitions[c].next_cmd = -1; 00149 tma_partitions[c].waiting = 0; 00150 tma_partitions[c].next_str = NULL; 00151 } 00152 00153 optind = OPTIND_RESET; /* start from the beginning */ 00154 opterr = 0; /* disable default error message */ 00155 con_index = 0; 00156 part_index = 0; 00157 while ((c = getopt(argc, argv, opt_string)) != -1) { 00158 switch (c) { 00159 #if HAVE_NL_CONS_H 00160 case 'a': /* move on to the next console */ 00161 con_index++; 00162 break; 00163 case 'r': 00164 if (part_index < tma_n_partitions) { 00165 tma_partitions[part_index].row = atoi(optarg); 00166 tma_partitions[part_index].console = con_index; 00167 part_index++; 00168 } 00169 break; 00170 #endif 00171 case '?': 00172 nl_error(3, "Unrecognized Option -%c", optopt); 00173 } 00174 } 00175 }