void menuscreen_key_handler(const char *key) { MenuToken token = MENUTOKEN_NONE; MenuResult res; debug(RPT_DEBUG, "%s(\"%s\")", __FUNCTION__, key); if ((menu_key != NULL) && (strcmp(key, menu_key) == 0)) { token = MENUTOKEN_MENU; } else if ((enter_key != NULL) && (strcmp(key, enter_key) == 0)) { token = MENUTOKEN_ENTER; } else if ((up_key != NULL) && (strcmp(key, up_key) == 0)) { token = MENUTOKEN_UP; } else if ((down_key != NULL) && (strcmp(key, down_key) == 0)) { token = MENUTOKEN_DOWN; } else if ((left_key != NULL) && (strcmp(key, left_key) == 0)) { token = MENUTOKEN_LEFT; } else if ((right_key != NULL) && (strcmp(key, right_key) == 0)) { token = MENUTOKEN_RIGHT; } else { token = MENUTOKEN_OTHER; } /* Is the menu already active ? */ if (!active_menuitem) { debug(RPT_DEBUG, "%s: Activating menu screen", __FUNCTION__); menuscreen_switch_item(menuscreen_get_main()); return; } res = menuitem_process_input(active_menuitem, token, key, keymask); switch (res) { case MENURESULT_ERROR: report(RPT_ERR, "%s: Error from menuitem_process_input", __FUNCTION__); break; case MENURESULT_NONE: handle_none(); break; case MENURESULT_ENTER: handle_enter(); break; case MENURESULT_CLOSE: handle_close(); break; case MENURESULT_QUIT: handle_quit(); break; case MENURESULT_PREDECESSOR: handle_predecessor(); break; case MENURESULT_SUCCESSOR: handle_successor(); break; default: assert(!"unexpected menuresult"); break; } }
Daemon::Daemon(int argc, char *argv[]) : QCoreApplication(argc, argv) { initSettings(); char defaultLogFilename[] = DEFAULT_LOG_FILE; char* logFilename = defaultLogFilename; int port = DEFAULT_LOCAL_PORT; bool isDaemon = true; bool runWiFiScanner = true; bool runMovementDetector = true; bool recordScans = false; bool runAllAlgorithms = false; ////////////////////////////////////////////////////////// // Make sure no other arguments have been given QStringList args = QCoreApplication::arguments(); QStringListIterator argsIter(args); argsIter.next(); // moled while (argsIter.hasNext()) { QString arg = argsIter.next(); if (arg == "-h") { usage(); } else if (arg == "-v") { version(); } else if (arg == "-d") { debug = true; } else if (arg == "-n") { isDaemon = false; logFilename = NULL; } else if (arg == "-l") { logFilename = argsIter.next().toAscii().data(); } else if (arg == "-s") { mapServerURL = argsIter.next(); } else if (arg == "-f") { staticServerURL = argsIter.next(); } else if (arg == "-r") { rootPathname = argsIter.next(); } else if (arg == "-p") { port = argsIter.next().toInt(); } else if (arg == "--no-accelerometer") { runMovementDetector = false; } else if (arg == "--no-wifi") { runWiFiScanner = false; } else if (arg == "-S") { recordScans = true; } else if (arg == "-A") { runAllAlgorithms = true; } else if (arg == "-H") { SpeedSensor::HibernateWhenInactive = true; } else { usage(); } } // Seed rng QTime time = QTime::currentTime(); qsrand((uint)time.msec()); settings = new QSettings(QSettings::SystemScope, MOLE_ORGANIZATION, MOLE_APPLICATION, this); ////////////////////////////////////////////////////////// // Read default settings if (settings->contains("wifi_scanning")) { runWiFiScanner = settings->value("wifi_scanning").toBool(); } if (settings->contains("movement_detector")) { runMovementDetector = settings->value("movement_detector").toBool(); } if (settings->contains("map_server_url")) { mapServerURL = settings->value("map_server_url").toString(); } if (settings->contains("fingerprint_server_url")) { staticServerURL = settings->value("fingerprint_server_url").toString(); } if (settings->contains("port")) { port = settings->value("port").toInt(); } if (settings->contains("root_path")) { rootPathname = settings->value("root_path").toString(); } if (isDaemon) { daemonize(); } else { qDebug() << "not daemonizing"; } ////////////////////////////////////////////////////////// // check a few things before daemonizing initCommon(this, logFilename); qWarning() << "Starting mole daemon " << "debug=" << debug << "port=" << port << "wifi_scanning=" << runWiFiScanner << "movement_detector=" << runMovementDetector << "logFilename=" << logFilename << "map_server_url=" << mapServerURL << "fingerprint_server_url=" << staticServerURL << "rootPath=" << rootPathname; // start create map directory if (!rootDir.exists("map")) { bool ret = rootDir.mkdir("map"); if (!ret) { qFatal("Failed to create map directory. Exiting..."); exit(-1); } qDebug() << "created map dir"; } // end create map directory // reset session cookie on MOLEd restart resetSessionCookie(); m_localizer = new Localizer(this, runAllAlgorithms); if (runMovementDetector && SpeedSensor::haveAccelerometer()) { m_scanQueue = new ScanQueue(this, m_localizer, 0, recordScans); } else { // since we are not detecting motion, only use this many scans // for localization const int maxActiveQueueLength = 12; m_scanQueue = new ScanQueue(this, m_localizer, maxActiveQueueLength, recordScans); } m_binder = new Binder(this, m_localizer, m_scanQueue); m_proximity = new Proximity(this, m_localizer); m_localServer = new LocalServer(this, m_localizer, m_binder, port); m_scanner = 0; if (runWiFiScanner) { m_scanner = new Scanner(this); connect(m_scanner, SIGNAL(setWiFiDesc(QString)), m_binder, SLOT(setWiFiDesc(QString))); connect(m_scanner, SIGNAL(addReading(QString,QString,qint16,qint8)), m_scanQueue, SLOT(addReading(QString,QString,qint16,qint8))); connect(m_scanner, SIGNAL(scanCompleted()), m_scanQueue, SLOT(scanCompleted())); } m_speedSensor = 0; if (runMovementDetector && SpeedSensor::haveAccelerometer()) { m_speedSensor = new SpeedSensor(this); connect(m_speedSensor, SIGNAL(hibernate(bool)), m_scanner, SLOT(handleHibernate(bool))); connect(m_speedSensor, SIGNAL(hibernate(bool)), m_localizer, SLOT(handleHibernate(bool))); connect(m_speedSensor, SIGNAL(motionChange(Motion)), m_localizer, SLOT(handleMotionChange(Motion))); connect(m_speedSensor, SIGNAL(motionChange(Motion)), m_scanQueue, SLOT(handleMotionChange(Motion))); } connect(this, SIGNAL(aboutToQuit()), SLOT(handle_quit())); if (runWiFiScanner) { m_scanner->start(); } }
static apr_status_t ftp_protocol_loop(struct lfd_sess * sess) { apr_status_t rc = APR_SUCCESS; int rnfrto; // "rename from" and "rename to" should go togheter char * temp_name; temp_name = NULL; rnfrto = 0; while(APR_SUCCESS == rc) { apr_pool_clear(sess->loop_pool); rc = lfd_cmdio_get_cmd_and_arg(sess, &sess->ftp_cmd_str, &sess->ftp_arg_str); if(APR_SUCCESS != rc) return rc; // special case if(lfd_cmdio_cmd_equals(sess, "RNTO")) { if(rnfrto) { rnfrto = 0; rc = handle_rnto(sess, temp_name); } else rc = handle_bad_rnto(sess); continue; } // here we treat all the other cases if(rnfrto){ rnfrto = 0; rc = handle_bad_rnto(sess); continue; } if(lfd_cmdio_cmd_equals(sess, "PASV")) { rc = handle_pasv(sess); } else if(lfd_cmdio_cmd_equals(sess, "SYST")) { rc = handle_syst(sess); } else if(lfd_cmdio_cmd_equals(sess, "USER")) { rc = handle_user(sess); } else if(lfd_cmdio_cmd_equals(sess, "PASS")) { rc = handle_pass(sess); } else if(lfd_cmdio_cmd_equals(sess, "QUIT")) { rc = handle_quit(sess); return rc; } else if(lfd_cmdio_cmd_equals(sess, "ABOR")) { rc = handle_abort(sess); } else if(lfd_cmdio_cmd_equals(sess, "PORT")) { rc = handle_port(sess); } else if(lfd_cmdio_cmd_equals(sess, "RMD")) { rc = handle_dir_remove(sess); } else if(lfd_cmdio_cmd_equals(sess, "MKD")) { rc = handle_dir_create(sess); } else if(lfd_cmdio_cmd_equals(sess, "PWD")) { rc = handle_pwd(sess); } else if(lfd_cmdio_cmd_equals(sess, "CWD")) { rc = handle_cwd(sess); } else if(lfd_cmdio_cmd_equals(sess, "CDUP")) { rc = handle_cdup(sess); } else if(lfd_cmdio_cmd_equals(sess, "RNFR")) { rc = handle_rnfr(sess, &temp_name); if(APR_SUCCESS == rc && NULL != temp_name) rnfrto = 1; } else if(lfd_cmdio_cmd_equals(sess, "TYPE")) { rc = handle_type(sess); } else if(lfd_cmdio_cmd_equals(sess, "RETR")) { rc = handle_retr(sess); } else if(lfd_cmdio_cmd_equals(sess, "STOR")) { rc = handle_stor(sess); } else if(lfd_cmdio_cmd_equals(sess, "DELE")) { rc = handle_dele(sess); } else if(lfd_cmdio_cmd_equals(sess, "STOU")) { rc = handle_stou(sess); } else if(lfd_cmdio_cmd_equals(sess, "LIST")) { rc = handle_list(sess); } else if(lfd_cmdio_cmd_equals(sess, "FEAT")) { rc = handle_feat(sess); } else if(lfd_cmdio_cmd_equals(sess, "APPE")) { rc = handle_appe(sess); } else if(lfd_cmdio_cmd_equals(sess, "SITE")) { rc = handle_site(sess); } else if(lfd_cmdio_cmd_equals(sess, "ALLO")) { rc = lfd_cmdio_write(sess, FTP_ALLOOK, "ALLO command ignored."); } else if(lfd_cmdio_cmd_equals(sess, "REIN")) { rc = lfd_cmdio_write(sess, FTP_COMMANDNOTIMPL, "REIN not implemented."); } else if(lfd_cmdio_cmd_equals(sess, "ACCT")) { rc = lfd_cmdio_write(sess, FTP_COMMANDNOTIMPL, "ACCT not implemented."); } else if(lfd_cmdio_cmd_equals(sess, "SMNT")) { rc = lfd_cmdio_write(sess, FTP_COMMANDNOTIMPL, "SMNT not implemented."); } else //default { printf("The cmd [%s] has no installed handler! \n", sess->ftp_cmd_str); if(NULL != sess->ftp_arg_str) printf("The cmd args were [%s] \n", sess->ftp_arg_str); lfd_cmdio_write(sess, FTP_COMMANDNOTIMPL, "Command not implemented."); } } return rc; }
int cli_connect (struct cli_context *ctx) { int argc = ctx->argc; char **argv = ctx->argv; int ret; int opt; int option_index; struct gluster_url *url = NULL; glfs_t *fs = NULL; uint16_t port = GLUSTER_DEFAULT_PORT; struct xlator_option *xlator_options = NULL; struct xlator_option *option; while ((opt = getopt_long (argc, argv, "o:p:", connect_options, &option_index)) != -1) { switch (opt) { case 'o': option = parse_xlator_option (optarg); if (option == NULL) { error (0, errno, "%s", optarg); goto err; } if (append_xlator_option (&xlator_options, option) == -1) { error (0, errno, "append_xlator_option: %s", optarg); goto err; } break; case 'p': port = strtoport (optarg); if (port == 0) { goto err; } break; default: goto err; } } ret = gluster_parse_url (argv[argc - 1], &url); if (ret == -1) { printf ("Usage: %s [OPTION]... URL\n" "Connect to a Gluster volume for this session.\n\n" " -o, --xlator-option=OPTION specify a translator option for the\n" " connection. Multiple options are supported\n" " and take the form xlator.key=value.\n" " -p, --port=PORT specify the port on which to connect\n", argv[0]); goto err; } url->port = port; ret = gluster_getfs (&fs, url); if (ret == -1) { error (0, errno, "failed to connect to %s/%s", url->host, url->volume); goto err; } ret = apply_xlator_options (fs, &xlator_options); if (ret == -1) { error (0, errno, "failed to apply translator options"); goto err; } ret = cli_disconnect (ctx); if (ret == -1) { error (0, 0, "failed to terminate previous connection"); goto err; } ctx->fs = fs; ctx->url = url; // TODO(craigcabrey): Look into using asprintf here. // 5 is the length of the string format: (%s/%s) size_t length = strlen (ctx->url->host) + strlen (ctx->url->volume) + 5; ctx->conn_str = malloc (length); if (ctx->conn_str == NULL) { error (0, errno, "malloc"); handle_quit (ctx); } snprintf (ctx->conn_str, length, "(%s/%s)", ctx->url->host, ctx->url->volume); goto out; err: ret = -1; gluster_url_free (url); out: return ret; }
void ircInterface::onMessage(std::string msg){ /* while(pkge.find("\r\n") != std::string::npos){ std::string msg = pkge.substr(0, pkge.find("\r\n")); pkge = pkge.substr(pkge.find("\r\n") + 2); */ //std::cout << "ircInterface: raw message is : "<<msg<<std::endl; ircLog::instance()->logf(FILENAME, "raw message is: %s", msg.c_str()); //alot of the control strings will start with the type sperated from the //contents of the message with a space std::string type = msg.substr(0, msg.find_first_of(' ')); //first check for messages that start with message names //check for ping if(!type.compare(PING)) { _connStatus->pingRcvd(); sendPong(); return; } else if(!type.compare(ERROR)) { //TODO need to figure out hwat to do here //for now lets just try and not spam the other levels return; } else if(!type.compare("IRCERROR")) { //handle connection errors in conn status _connStatus->connectionIoError(); } //now check for messages that start with nicks or server titles else { _connStatus->pingRcvd(); //type is actually a prefix containing the host mask etc std::string prefix = type; // the actual message past the prefix msg = msg.substr(msg.find_first_of(' ')+1); //the first part of that message should be the type type = msg.substr(0, msg.find_first_of(' ')); //check first to see if it is a private message //most irc messaages are private messages if(!type.compare(PRIVMSG)) { handle_privmsg(msg, prefix); } else if(!type.compare(NOTICE)) { if(_connStatus->state() == CS_IDLE) { _connStatus->connected(); } handle_notice(msg, prefix); } else if(!type.compare(QUIT)) { ircEvent e = handle_quit(msg, prefix); notifyEvent(e); } else if(!type.compare(JOIN)) { ircEvent e = handle_join(msg, prefix); notifyEvent(e); } else if(!type.compare(PART)) { ircEvent e = handle_part(msg, prefix); notifyEvent(e); } else if(!type.compare(NICK)) { ircEvent e = handle_nick(msg, prefix); notifyEvent(e); } else if(!type.compare(INSPIRCDVARS)) { handle_vars(msg); } else if(!type.compare(NICKLIST)) { //add function to parse the nicklist std::vector<ircEvent> e = handle_nicklist(msg); for(unsigned int i = 0; i < e.size(); ++i) { notifyEvent(e[i]); } } else if(!type.compare("001")) { _connStatus->registered(); } } // } }
void do_menu_command( long menuResult) { short menuID; short menuItem; menuID= GET_MENU_ID(menuResult); menuItem= GET_MENU_ITEM(menuResult); switch (menuID) { case mApple: switch (menuItem) { case iAbout: break; default: #if defined(OP_PLATFORM_MAC_CFM) && !defined(OP_PLATFORM_MAC_CARBON_FLAG) { Str255 daName; GetMenuItemText(GetMenuHandle(mApple), menuItem, daName); OpenDeskAcc(daName); } #endif break; } break; case mFile: switch (menuItem) { case iOpen: case iOpenPassive: handle_open(menuItem==iOpen, false); break; case iOpenActiveUI: case iOpenPassiveUI: handle_open(menuItem==iOpenActiveUI, true); break; case iClose: close_front_window(); break; case iQuit: handle_quit(); break; } break; case mSpecial: switch(menuItem) { case iSendPacket: send_packet(); break; case iSendStream: send_stream(); break; case iProtocolAlive: is_alive(); break; case iAcceptingConnections: accepting_connections= !accepting_connections; check_menu_item(menuID, menuItem, accepting_connections); break; case iActiveEnumeration: active_enumeration= !active_enumeration; check_menu_item(menuID, menuItem, active_enumeration); break; case iSetTimeout: set_timeout(); break; case iGetInfo: report_info(); break; case iGetConfigString: // get_config_string(); break; } break; case mWindowMenu: switch(menuItem) { case iCascade: case iTile: cascade_or_tile_windows(menuItem==iCascade); break; } } #if OP_PLATFORM_MAC_CFM || OP_PLATFORM_MAC_MACHO HiliteMenu(0); #endif adjust_menus(); return; }