void ProfileManager::refresh_config(Profile* profile) { Configuration* config = profile->get_configuration(); try { logger << setlevel(config->get(Variable("Presage.ProfileManager.LOGGER"))); } catch (Configuration::ConfigurationException& ex) { // if no config is available, turn on full logging for profile // manager logger << setlevel("ALL"); } delete config; flush_cached_log_messages(); }
ContextTracker::ContextTracker(Configuration* config, PluginRegistry* registry, PresageCallback* callback, const char wChars[], const char tChars[], const char bChars[], const char cChars[]) : wordChars (wChars), separatorChars (tChars), blankspaceChars(bChars), controlChars (cChars), pluginRegistry (registry), logger ("ContextTracker", std::cerr) //tokenizer (pastStream, blankspaceChars, separatorChars) { if (callback) { context_tracker_callback = callback; } else { throw new PresageException("Invalid callback object"); } contextChangeDetector = new ContextChangeDetector(wordChars, separatorChars, blankspaceChars, controlChars); // set pointer to this context tracker in plugin registry so that // plugins can be constructed when next iterator is requested // if (pluginRegistry) { pluginRegistry->setContextTracker(this); } // read config values Variable* variable; Value value; try { variable = new Variable("Presage.ContextTracker.LOGGER"); value = config->get(*variable); logger << setlevel(value); logger << INFO << "LOGGER: " << value << endl; delete variable; variable = new Variable("Presage.ContextTracker.SLIDING_WINDOW_SIZE"); value = config->get(*variable); logger << INFO << "SLIDING_WINDOWS_SIZE: " << value << endl; contextChangeDetector->set_sliding_window_size(value); delete variable; } catch (Configuration::ConfigurationException ex) { logger << ERROR << "Caught ConfigurationException: " << ex.what() << endl; } }
void CompBand::changepar (int npar, int value) { switch (npar) { case 0: setvolume (value); break; case 1: PLratio = value; setratio(0,value); break; case 2: PMLratio = value; setratio(1,value); break; case 3: PMHratio = value; setratio(2,value); break; case 4: PHratio = value; setratio(3,value); break; case 5: PLthres = value; setthres(0,value); break; case 6: PMLthres = value; setthres(1,value); break; case 7: PMHthres = value; setthres(2,value); break; case 8: PHthres = value; setthres(3,value); break; case 9: setCross1 (value); break; case 10: setCross2 (value); break; case 11: setCross3(value); break; case 12: setlevel(value); break; }; };
unsigned int cmd_setlevel(callbackp *callbacki) { USERS *recver; if ((recver = seek_user(callbacki->param[3], callbacki->param[2], callbacki->g_ape)) == NULL) { send_error(callbacki->call_user, "UNKNOWN_USER", "102", callbacki->g_ape); } else { setlevel(callbacki->call_user, recver, getchan(callbacki->param[2], callbacki->g_ape), atoi(callbacki->param[4]), callbacki->g_ape); } return (FOR_NOTHING); }
ARPAPlugin::ARPAPlugin(Configuration* config, ContextTracker* ct) : Plugin(config, ct, "ARPAPlugin", "ARPAPlugin, a plugin relying on an ARPA language model", "ARPAPlugin, long description." ) { Value value; try { value = config->get(LOGGER); logger << setlevel(value); logger << INFO << "LOGGER: " << value << endl; } catch (Configuration::ConfigurationException ex) { logger << WARN << "Caught ConfigurationException: " << ex.what() << endl; } try { value = config->get(VOCABFILENAME); logger << INFO << "VOCABFILENAME: " << value << endl; vocabFilename = value; } catch (Configuration::ConfigurationException ex) { logger << ERROR << "Caught fatal ConfigurationException: " << ex.what() << endl; throw PresageException("Unable to init " + name + " predictive plugin."); } try { value = config->get(ARPAFILENAME); logger << INFO << "ARPAFILENAME: " << value << endl; arpaFilename = value; } catch (Configuration::ConfigurationException ex) { logger << ERROR << "Caught fatal ConfigurationException: " << ex.what() << endl; throw PresageException("Unable to init " + name + " predictive plugin."); } try { value = config->get(TIMEOUT); logger << INFO << "TIMEOUT: " << value << endl; timeout = atoi(value.c_str()); } catch (Configuration::ConfigurationException ex) { logger << ERROR << "Caught fatal ConfigurationException: " << ex.what() << endl; throw PresageException("Unable to init " + name + " predictive plugin."); } loadVocabulary(); createARPATable(); }
SmoothedCountPlugin::SmoothedCountPlugin(Configuration* config, ContextTracker* ct) : Plugin(config, ct, "SmoothedCountPlugin", "SmoothedCountPlugin, a linear interpolating unigram bigram trigram plugin", "SmoothedCountPlugin, long description." ) { Value value; try { value = config->get(LOGGER); logger << setlevel(value); logger << INFO << "LOGGER: " << value << endl; } catch (Configuration::ConfigurationException ex) { logger << WARN << "Caught ConfigurationException: " << ex.what() << endl; } try { value = config->get(UNIGRAM_WEIGHT); unigram_weight = toDouble(value); value = config->get(BIGRAM_WEIGHT); bigram_weight = toDouble(value); value = config->get(TRIGRAM_WEIGHT); trigram_weight = toDouble(value); value = config->get(DBFILENAME); dbfilename = value; } catch (Configuration::ConfigurationException ex) { logger << ERROR << "Caught fatal ConfigurationException: " << ex.what() << endl; throw PresageException("Unable to init " + name + " predictive plugin."); } // open database #if defined(HAVE_SQLITE3_H) int result = sqlite3_open(dbfilename.c_str(), &db); assert(result == SQLITE_OK); #elif defined(HAVE_SQLITE_H) db = sqlite_open(dbfilename.c_str(), 0777, NULL); assert(db != NULL); #endif }
RecencyPlugin::RecencyPlugin(Configuration* config, ContextTracker* ct) : Plugin(config, ct, "RecencyPlugin", "RecencyPlugin, a statistical recency promotion plugin", "RecencyPlugin, based on a recency promotion principle, generates predictions by assigning exponentially decaying probability values to previously encountered tokens. Tokens are assigned a probability value that decays exponentially with their distance from the current token, thereby promoting context recency." ) { // init default values lambda = 1; n_0 = 1; cutoff_threshold = 20; // read values from config try { Value value = config->get(LOGGER); logger << setlevel(value); logger << INFO << "LOGGER: " << value << endl; } catch (Configuration::ConfigurationException ex) { logger << WARN << "Caught ConfigurationException: " << ex.what() << endl; } try { Value value = config->get(LAMBDA); lambda = toDouble(value); logger << INFO << "LAMBDA: " << value << endl; value = config->get(N_0); n_0 = toDouble(value); logger << INFO << "N_0: " << value << endl; value = config->get(CUTOFF_THRESHOLD); cutoff_threshold = toInt(value); logger << INFO << "CUTOFF_THRESHOLD: " << value << endl; } catch (Configuration::ConfigurationException ex) { logger << ERROR << "Caught fatal ConfigurationException: " << ex.what() << endl; throw PresageException("Unable to init " + name + " predictive plugin."); } }
int main(int argc, char **argv) { int ups_fd, stat_fd, ch; int flags; int pstatus, poldstat = 1; int bstatus, boldstat = 1; int count = 0; int bcount = 0; int tries = 0; int ikill = 0; int ioctlbit; char *self = argv[0]; char killchar = ' '; struct upsdef *pups; while ((ch = getopt(argc, argv, "kc:d:r:s:t:")) != -1) switch (ch) { case 'k': ikill = 1; break; case 'c': config_file = optarg; break; case 'd': upsport = optarg; break; case 'r': rcpowerfail = optarg; break; case 's': upsstat = optarg; break; case 't': upstype = optarg; break; case '?': default: usage(self); } argc -= optind; argv += optind; if (argc > 0) usage(self); parse_config(config_file); if (upsport == NULL || upstype == NULL || upsstat == NULL) { usage(self); } for (pups = ups; pups; pups = pups->next) { if (strcmp(pups->tag, upstype) == 0) break; } if (!pups) { fprintf(stderr, "Error: %s: UPS <%s> unknown\n", self, argv[2]); exit(1); } /* Start syslog. */ openlog(self, LOG_CONS | LOG_PERROR, LOG_DAEMON); if ((ups_fd = open(upsport, O_RDWR | O_NDELAY)) < 0) { syslog(LOG_ERR, "%s: %s", upsport, strerror(errno)); closelog(); exit(1); } /* Kill the inverter and close out if inverter kill was selected */ if (ikill) { if (pups->killtime) { /* Explicitly clear both DTR and RTS as soon as possible */ ioctlbit = TIOCM_RTS; ioctl(ups_fd, TIOCMBIC, &ioctlbit); ioctlbit = TIOCM_DTR; ioctl(ups_fd, TIOCMBIC, &ioctlbit); /* clear killpower, apply cablepower to enable monitoring */ setlevel(ups_fd, pups->kill.line, !pups->kill.inverted); setlevel(ups_fd, pups->cablepower.line, !pups->cablepower.inverted); if (pups->kill.line == TIOCM_ST) { /* Send BREAK (TX high) to kill the UPS inverter. */ tcsendbreak(ups_fd, 1000 * pups->killtime); } else { /* Force high to send the UPS the inverter kill signal. */ setlevel(ups_fd, pups->kill.line, pups->kill.inverted); sleep(pups->killtime); } ioctl(ups_fd, TIOCMGET, &flags); /* * Feb/05/2001 Added support for Tripplite Omnismart 450PNP, this * UPS shutdowns inverter when data is sent over the Tx line * (jhcaiced) */ if (pups->flags & UPS_TXD_KILL_INVERTER) { sleep(2); write(ups_fd, &killchar, 1); } close(ups_fd); /************************************************************/ /* We never should have gotten here. */ /* The inverter kill has failed for one reason or another. */ /* If still in powerfail mode, exit with an error. */ /* If power is ok (power has returned) let rc.0 finish the */ /* reboot. */ /************************************************************/ if (getlevel(&pups->powerok, flags) == 0) { fprintf(stderr, "%s: UPS inverter kill failed.\n", self); exit(1); } /* if (getlevel(&pups->powerok,flags) == 0) */ /* Otherwise, exit normaly, power has returned. */ exit(0); } else { fprintf(stderr, "Error: %s: UPS <%s> has no support for killing the inverter.\n", self, pups->tag); exit(1); } /* if (pups->kill) */ } /* if (ikill) */ /****************************************/ /* If no kill signal, monitor the line. */ /****************************************/ /* Explicitly clear both DTR and RTS as soon as possible */ ioctl(ups_fd, TIOCMBIC, TIOCM_RTS); ioctl(ups_fd, TIOCMBIC, TIOCM_DTR); /* clear killpower, apply cablepower to enable monitoring */ setlevel(ups_fd, pups->kill.line, !pups->kill.inverted); setlevel(ups_fd, pups->cablepower.line, !pups->cablepower.inverted); /* Daemonize. */ #ifdef DEBUG closelog(); setsid(); #else switch (fork()) { case 0: /* Child */ closelog(); setsid(); break; case -1: /* Error */ syslog(LOG_ERR, "can't fork."); closelog(); exit(1); default: /* Parent */ closelog(); exit(0); } #endif /* switch(fork()) */ /* Restart syslog. */ openlog(self, LOG_CONS, LOG_DAEMON); /* Create an info file for powerfail scripts. */ unlink(upsstat); if ((stat_fd = open(upsstat, O_CREAT | O_WRONLY, 0644)) >= 0) { write(stat_fd, "OK\n", 3); close(stat_fd); } /* Give the UPS a chance to reach a stable state. */ sleep(2); /* Now sample the line. */ while (1) { /* Get the status. */ ioctl(ups_fd, TIOCMGET, &flags); /* Calculate present status. */ pstatus = getlevel(&pups->powerok, flags); bstatus = getlevel(&pups->battok, flags); if (pups->cableok.line) { /* Check the connection. */ tries = 0; while (getlevel(&pups->cableok, flags) == 0) { /* Keep on trying, and warn every two minutes. */ if ((tries % 60) == 0) syslog(LOG_ALERT, "UPS connection error"); sleep(2); tries++; ioctl(ups_fd, TIOCMGET, &flags); } /* while(getlevel(&pups->cableok,flags) */ if (tries > 0) syslog(LOG_ALERT, "UPS connection OK"); } else { /* * Do pseudo-cable check, bad power on startup == possible bad * cable */ if (tries < 1) { tries++; /* Do startup failure check */ if (!pstatus) { /* * Power is out: assume bad cable, but semi-scram to be * safe */ syslog(LOG_ALERT, "No power on startup; UPS connection error?"); /* * Set status registers to prevent further processing * until */ /* the status of the cable is changed. */ poldstat = pstatus; boldstat = bstatus; powerfail(PFM_CABLE); } /* if (!pstatus) */ } /* if (tries < 1) */ } /* if (pups->cableok.line) */ /* If anything has changed, process the change */ if (pstatus != poldstat || bstatus != boldstat) { count++; if (count < 4) { /* Wait a little to ride out short brown-outs */ sleep(1); continue; } /* if (count < 4) */ if (pstatus != poldstat) { if (pstatus) { /* Power is OK */ syslog(LOG_ALERT, "Line power restored"); powerfail(PFM_OK); } else { /* Power has FAILED */ if (bstatus) { /* Battery OK, normal shutdown */ syslog(LOG_ALERT, "Line power has failed"); powerfail(PFM_FAIL); } else { /* Low Battery, SCRAM! */ syslog(LOG_ALERT, "UPS battery power is low!"); powerfail(PFM_SCRAM); } /* if (bstatus) */ } /* if (pstatus) */ } /* if (pstatus != poldstat) */ if (bstatus != boldstat) { if (!bstatus && !pstatus) { /* Power is out and Battery is now low, SCRAM! */ syslog(LOG_ALERT, "UPS battery power is low!"); powerfail(PFM_SCRAM); } else { /* Battery status has changed */ if (bstatus) { /* Battery power is back */ syslog(LOG_ALERT, "UPS battery power is now OK"); } /* if (!bstatus) */ } /* if (!bstatus && !pstatus) */ } /* if (bstatus != boldstat) */ } /* if (pstatus != poldstat || bstatus != * boldstat) */ if (!bstatus && pstatus) { /* Line power is OK and UPS signals battery is low */ /* Log a message to the syslog every 10 minutes */ if ((bcount % 300) == 0) syslog(LOG_ALERT, "UPS battery power is low!"); bcount++; } else { /* Reset count */ bcount = 0; } /* if (!bstatus && pstatus) */ /* Reset count, remember status and sleep 2 seconds. */ count = 0; poldstat = pstatus; boldstat = bstatus; sleep(2); } /* while(1) */ /* Never happens */ return (0); }
void join(USERS *user, CHANNEL *chan, acetables *g_ape) { userslist *list, *ulist; CHANLIST *chanl; FIRE_EVENT_NULL(join, user, chan, g_ape); RAW *newraw; json_item *jlist = json_new_object(); if (isonchannel(user, chan)) { return; } list = xmalloc(sizeof(*list)); // TODO is it free ? list->userinfo = user; list->level = 1; list->next = chan->head; chan->head = list; chanl = xmalloc(sizeof(*chanl)); // TODO is it free ? chanl->chaninfo = chan; chanl->next = user->chan_foot; user->chan_foot = chanl; if (chan->interactive) { json_item *user_list = json_new_array(); json_item *uinfo = json_new_object(); json_set_property_objN(uinfo, "user", 4, get_json_object_user(user)); json_set_property_objN(uinfo, "pipe", 4, get_json_object_channel(chan)); newraw = forge_raw(RAW_JOIN, uinfo); post_raw_channel_restricted(newraw, chan, user, g_ape); ulist = chan->head; while (ulist != NULL) { json_item *juser = get_json_object_user(ulist->userinfo); if (ulist->userinfo != user) { //make_link(user, ulist->userinfo); } json_set_property_intN(juser, "level", 5, ulist->level); json_set_element_obj(user_list, juser); ulist = ulist->next; } json_set_property_objN(jlist, "users", 5, user_list); } json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan)); newraw = forge_raw(RAW_CHANNEL, jlist); post_raw(newraw, user, g_ape); #if 0 if (user->flags & FLG_AUTOOP) { setlevel(NULL, user, chan, 3); } #endif }
void Predictor::set_logger (const std::string& level) { logger << setlevel (level); logger << INFO << "LOGGER: " << level << endl; }
DivideOperator::DivideOperator(QObject *parent) : QObject(parent) { setName("/"); setlevel(5); }
MinusOperator::MinusOperator(QObject *parent) : QObject(parent) { setName("-"); setlevel(6); }
void join(USERS *user, CHANNEL *chan, acetables *g_ape) { userslist *list, *ulist; CHANLIST *chanl; FIRE_EVENT_NULL(join, user, chan, g_ape); RAW *newraw; json *jlist = NULL; char level[8]; if (isonchannel(user, chan)) { return; } list = (userslist *)xmalloc(sizeof(*list)); // is it free ? list->userinfo = user; list->level = 1; list->next = chan->head; chan->head = list; chanl = (CHANLIST *)xmalloc(sizeof(*chanl)); // is it free ? chanl->chaninfo = chan; chanl->next = user->chan_foot; user->chan_foot = chanl; if (chan->interactive) { jlist = NULL; set_json("user", NULL, &jlist); json_attach(jlist, get_json_object_user(user), JSON_OBJECT); set_json("pipe", NULL, &jlist); json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT); newraw = forge_raw(RAW_JOIN, jlist); post_raw_channel_restricted(newraw, chan, user, g_ape); jlist = NULL; set_json("users", NULL, &jlist); ulist = chan->head; while (ulist != NULL) { struct json *juser = NULL; if (ulist->userinfo != user) { //make_link(user, ulist->userinfo); } sprintf(level, "%i", ulist->level); set_json("level", level, &juser); json_concat(juser, get_json_object_user(ulist->userinfo)); json_attach(jlist, juser, JSON_ARRAY); ulist = ulist->next; } } set_json("pipe", NULL, &jlist); json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT); newraw = forge_raw(RAW_CHANNEL, jlist); post_raw(newraw, user, g_ape); #if 0 if (user->flags & FLG_AUTOOP) { setlevel(NULL, user, chan, 3); } #endif }
static void rm(size_t pend, const char *base, const int olddir, int ssub, int level) { struct stat st; if (lstat(base, &st) < 0) { if (fflag == 0 || errno != ENOENT) { if (sysv3) fprintf(stderr, "%s: %s non-existent\n", progname, path); else fprintf(stderr, "%s: %s\n", path, strerror(errno)); errcnt |= 4; } return; } if ((st.st_mode&S_IFMT) == S_IFDIR) { if (rflag) { struct direc *dp; struct getdb *db; int df, err; if (ssub == 0 && (iflag #ifdef SUS || (!fflag && ontty && access(base, W_OK) < 0) #endif )) { msg("directory %s: ? ", path); if (confirm() == 0) return; } if ((df = open(base, O_RDONLY #ifdef O_DIRECTORY | O_DIRECTORY #endif #ifdef O_NOFOLLOW | O_NOFOLLOW #endif )) < 0 || (db = getdb_alloc(base, df)) == NULL) { if (errno == EMFILE) { int sres; sres = subproc(pend, base, level); if (sres >= 0) { errcnt |= sres; goto remove; } } /* * Maybe the directory is empty and can just * be removed. */ if (rmfile(base, &st) < 0) { fprintf(stderr, "%s: cannot read " "directory %s\n", progname, path); errcnt |= 4; } return; } if (fchdir(df) < 0) { if (rmfile(base, &st) < 0) { fprintf(stderr, "%s: cannot chdir to %s\n", progname, path); errcnt |= 4; } getdb_free(db); close(df); return; } setlevel(level, db, df); while ((dp = getdir(db, &err)) != NULL) { if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || dp->d_name[1] == '.' && dp->d_name[2] == '\0')) continue; rm(catpath(pend, dp->d_name), dp->d_name, df, 0, level + 1); path[pend] = '\0'; } if (err) { fprintf(stderr, "%s: error reading directory %s\n", progname, path); errcnt |= 4; } if (olddir >= 0 && fchdir(olddir) < 0) { fprintf(stderr, "%s: cannot change backwards\n", progname); exit(1); } getdb_free(db); close(df); } else { fprintf(stderr, "%s: %s directory\n", progname, path); errcnt |= 1; return; } } if (ssub == 0) remove: rmfile(base, &st); }