示例#1
0
文件: ardrone.cpp 项目: UCAPA/ucapa
    void ARDrone::setVideoRecord(bool activate)
    {
        m_video->stop();

        // Enable or disable video record
        if (activate)
            AT_CONFIG("video:video_on_usb", "TRUE");
        else
            AT_CONFIG("video:video_on_usb", "FALSE");

        // Reset the configuration
        setDefaultConfig();
    }
示例#2
0
文件: ardrone.cpp 项目: UCAPA/ucapa
    ARDrone::ARDrone(std::string sessionId, std::string userId, std::string appId,
                     const std::string ardIp,
                     const unsigned short ardATCmdsPort,
                     const unsigned short ardNavdataPort,
                     const unsigned short ardVideoPort,
                     const unsigned short ardControlPort,
                     ARDroneConnections* connectionHandler,
                     Navdata* navdata,
                     Video* video)
        : m_sessionId(sessionId)
        , m_userId(userId)
        , m_appId(appId)
        , m_ardIp(ardIp)
        , m_ardATCmdsPort(ardATCmdsPort)
        , m_ardNavdataPort(ardNavdataPort)
        , m_ardVideoPort(ardVideoPort)
        , m_ardControlPort(ardControlPort)
        , m_altitudeMax(2.0f)
        , m_verticalSpeed(.7f)
        , m_rotationSpeed(3.0f)
        , m_euler_angle_max(0.26f)
        , m_isWithoutShell(false)
        , m_isOutdoor(false)
        , m_connectionsHandler(connectionHandler)
        , m_indexCmd(1)
        , m_navdata(navdata)
        , m_video(video)
    {
        m_video->setCallbackInitFunc([this]() {this->m_connectionsHandler->sendInitVideoData();});

        AT_CONFIG("custom:session_id", sessionId);
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
        AT_CONFIG("custom:profile_id", userId);
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
        AT_CONFIG("custom:application_id", appId);
        std::this_thread::sleep_for(std::chrono::milliseconds(100));

        setAltitudeMax(m_altitudeMax);
        setVerticalSpeed(m_verticalSpeed);
        setRotationSpeed(m_rotationSpeed);
        setSpeed(m_euler_angle_max);
        setIsWithoutShell(false);
        setIsOutdoor(false);

        // Initialize the ARDrone video stream (Codecs, etc..)
        setDefaultConfig();

        initNavdata();
    }
示例#3
0
int LitmusDevice::initDev(const char* devName) {

  dev_buf.status = empty;
  dev_buf.work = idle;
  dev_buf.size = 0;
  assert(pthread_mutex_init(&dev_buf.mutex, 0)==0);
  assert(pthread_cond_init(&dev_buf.full, 0)==0);
  assert(pthread_cond_init(&dev_buf.empty, 0)==0);
	
  strcpy(this->dev_buf.devName, devName);
  dev_buf.devFD = open(dev_buf.devName, O_RDWR);
  if (dev_buf.devFD < 0) {
    perror("could not open feathertrace");
    return 1;
  }

  nbrEvents = 0;
  setDefaultConfig();

  pthread_create(&asynch_reader, NULL, dev_reader_func, (void*) &dev_buf);
  return 0;
}
示例#4
0
void WSettings::checkConfigFile()
{
    //default config file "~/.WifiAssist/config.ini"
    //check is path exists
    QDir dir;
    QString config_path = dir.homePath()+"/.WifiAssist";
    QString filename = config_path+"/config.ini";
    dir.setPath(config_path);
    //if not exist,mkdir and Then set default config file.
    if(!dir.exists())
    {
        dir.mkdir(config_path);
    }

    QFile file;
    file.setFileName(filename);
    if(!file.exists())
    {
        m_settings = new QSettings(filename,QSettings::IniFormat);
        setDefaultConfig();
    }
    else
        m_settings = new QSettings(filename,QSettings::IniFormat);
}
示例#5
0
/**
 * @brief Creates a new configuration service with the default system
 *        configuration.
 */
ConfigService::ConfigService()
{
  setDefaultConfig();
}
示例#6
0
void Log::initMe()
{
    setDefaultConfig();

    m_interceptMouseEvents = m_settings ? m_settings->value("Log/mouseEvents", false).toBool() : false;
    m_interceptQtMessages = m_settings ? m_settings->value("Log/messagesQt", true).toBool() : false;
    m_logRotateCounter = m_settings ? m_settings->value("Log/logRotateCounter", 5).toLongLong() : 5;
    QString logRotateFileSize = m_settings ? m_settings->value("Log/logRotateFileSize", "50mb").toString() : "50mb";
    if (logRotateFileSize.contains("kb", Qt::CaseInsensitive))
        m_logRotateFileSize = logRotateFileSize.remove("kb", Qt::CaseInsensitive).toInt() * 1024;
    else if (logRotateFileSize.contains("mb", Qt::CaseInsensitive))
        m_logRotateFileSize = logRotateFileSize.remove("mb", Qt::CaseInsensitive).toInt() * 1024000;
    else
        m_logRotateFileSize = logRotateFileSize.toInt();

    m_sync = m_settings ? m_settings->value("Log/synchronously", true).toBool() : true;
    m_enabled = m_settings ? m_settings->value("Log/enabled", true).toBool() : true;

    m_isInited = true;

    /// do logrotate if needed
    logRotate();

    /// process it after exit from Core::init because gCore->scene() is not inited yet
    if (m_interceptMouseEvents)
        QTimer::singleShot(0, this, SLOT(initMouseHandler()));


    /// Setting up the qDebug handler only after m_isInited = true ensures that
    /// qDebug statements within the logger initialization don't cause stack (as
    /// warnings need to be logged if a log call is made during logger init.)
    if (m_interceptQtMessages)
        startCustomHandler();

    if (m_enabled) {
        QString context_size = m_settings ? m_settings->value("Log/contextMaxSize", "1kb").toString() : "1kb";
        int s = 0;
        if (context_size.contains("kb", Qt::CaseInsensitive))
            s = context_size.remove("kb", Qt::CaseInsensitive).toInt() * 1024;
        else if (context_size.contains("mb", Qt::CaseInsensitive))
            s = context_size.remove("mb", Qt::CaseInsensitive).toInt() * 1024000;
        else
            s = logRotateFileSize.toInt();

        m_logProcessor = new LogProcessor();
        m_logProcessor->setContextSize(s);
        m_logProcessor->setMouseEventFile(m_settings ? m_settings->value("Log/mouseLogFilename", "").toString() : "");
        m_logProcessor->setFilters(this->getFilters());
        m_logProcessor->setGeneralMatrix( this->getGeneralLevelsSettings());
        m_logProcessor->setModulesMatrix( this->getModulesLevelsSettings());

        /// synchronous or asynchronous
        ///
        if (m_sync) {
            log_stderr("Log is synchronous");
            connect(this, SIGNAL(logMessage(CuteReport::LogLevel,QString,QString,QString)), m_logProcessor, SLOT(push(CuteReport::LogLevel,QString,QString,QString)), Qt::DirectConnection);
        } else {
            log_stderr("Log is asynchronous");
            m_processorThread = new QThread(this);
            m_logProcessor->moveToThread(m_processorThread);
            connect(this, SIGNAL(logMessage(CuteReport::LogLevel,QString,QString,QString)), m_logProcessor, SLOT(push(CuteReport::LogLevel,QString,QString,QString)), Qt::QueuedConnection);
            m_processorThread->start(QThread::LowestPriority);

            log_stderr(QString("Log current thread pointer is %1").arg(qint64(this->thread())));
            log_stderr(QString("Log processor thread pointer is %1").arg(qint64(m_logProcessor->thread())));
        }
    }

}
示例#7
0
文件: httpd.c 项目: K1N62/Rhino
int main(int argc, char* argv[]) {

  // Variable declarations
  int i, port, sd_current, addrlen, handlingMethod, fifo, setval, max_fd;
  struct sockaddr_in sin, pin;
  configuration config;
  char error[1024];
  pthread_t handler;
  pthread_attr_t att;
  pid_t pid;
  fd_set rfds;

  // Set execution to true
  execute = true;

  // Clear file creation mask.
  umask(0);

  // Set default handling method to thread
  handlingMethod = _THREAD;

  // Get size of pin ..
  addrlen = sizeof(pin);

  // Signal handlers
  signal(SIGPIPE, SIG_IGN);
  signal(SIGINT, sig_handle_int);
  signal(SIGABRT, sig_handle_int);

  // Set default config
  setDefaultConfig(&config);

  // Set root dir to current running directory
  path_init(&config);
  rootDir(argv[0]);

  // Parse config file
  if (parseConfig(&config) == -1) {
    exit(-1);
  }

  // Check arguments
  if(argc > 1) {
    for(i = 1; i < argc; i++) {
      switch(argv[i][1]) {
        // Help
        case 'h':
          printHelp();
          return 3;
          break;
        // Port
        case 'p':
          i++;
          if(i >= argc) {
            printHelp();
            return 3;
          }
          if(argv[i][0] != '-') {
            if((port = atoi(argv[i])) != 0 && port < 65536) {
              config.listenPort = port;
              printf("Port number: %d\n", port);
            }
            else {
              printHelp();
              return 3;
            }
          }
          else {
            printHelp();
            return 3;
          }
          break;
        // Deamonize
        case 'd':
          // Start daemon if set
          printf("Starting daemon...\n");
          daemonfunc();
          break;
        // Log file
        case 'l':
          i++;
          if(i >= argc) {
            printHelp();
            return 3;
          }
          if(argv[i][0] != '-') {
            strncpy(config.accLogPath, argv[i], sizeof(config.accLogPath));
          }
          else {
            printHelp();
            return 3;
          }
          break;
        // Mode of operation
        case 's':
          i++;
          if(i >= argc) {
            printHelp();
            return 3;
          }
          if(strncmp(argv[i], "thread", 6) == 0)
            handlingMethod = _THREAD;
          else if(strncmp(argv[i], "fork", 4) == 0)
            handlingMethod = _FORK;
          else {
            printHelp();
            return 3;
          }
          break;
        case 'c':
          i++;
          if(i >= argc) {
            printHelp();
            return 3;
          }
          if(argv[i][0] != '-') {
            strncpy(config.configPath, argv[i], sizeof(config.configPath));
          }
          else {
            printHelp();
            return 3;
          }
          break;
      }
    }
  }

  // Init logfunctions
  if (log_init(&config) == -1) {
    exit(-1);
  }

  // Create fifo if prefork is set
  if (handlingMethod == _FORK) {
      // Create the named fifo pipe
      mkfifo(config.fifoPath, 0666);
      // Try opening the pipe
      if((fifo = open(config.fifoPath, O_RDWR)) == -1) {
        sprintf(error, "Unable to open FIFO-pipe, %s", strerror(errno));
        log_server(LOG_CRIT, error);
        execute = false;    // Terminate
      }
  }

  // Check super user
  if (getuid() != 0) {
    perror("You have to be root to run this program");
    exit(-1);
  }

  // Set root directory to document root
  chdir(config.basedir);
  if (chroot(config.basedir) == -1) {
    sprintf(error, "Unable to change root directory, %s", strerror(errno));
    log_server(LOG_ERR, error);
    execute = false;  // Terminate
  }

  // Drop root privileges
  if (setgid(getgid()) == -1) {
    sprintf(error, "Unable to change user, %s", strerror(errno));
    log_server(LOG_ERR, error);
    execute = false;  // Terminate
  }
  if (setuid(getuid()) == -1) {
    sprintf(error, "Unable to change user, %s", strerror(errno));
    log_server(LOG_ERR, error);
    execute = false;  // Terminate
  }

  // Create listening socket
  // Domain -> AF_INET = IPV4
  // Type -> SOCK_STREAM = TCP
  if((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
      sprintf(error, "Unable to open socket, %s", strerror(errno));
      log_server(LOG_ERR, error);
      execute = false;  // Terminate
  }

  // Zeroize sin
  memset(&sin, 0, sizeof(sin));
  // Set domain
  sin.sin_family = AF_INET;
  // Set any in address
  sin.sin_addr.s_addr = INADDR_ANY;
  // Set port, hton converts byteorder
  sin.sin_port = htons(config.listenPort);

  // Try binding the socket
	if(bind(sd, (struct sockaddr*) &sin, sizeof(sin)) == -1) {
    sprintf(error, "Unable to bind socket, %s", strerror(errno));
    log_server(LOG_ERR, error);
    execute = false;  // Terminate
	}

  // Start to listen for requests
  if(listen(sd, config.backlog) == -1) {
    sprintf(error, "Too loud unable to listen, %s", strerror(errno));
    log_server(LOG_ERR, error);
    execute = false;  // Terminate
	}

  // Init thread lock
  pthread_mutex_init(&thread_lock, NULL);

  // If handling method is set to thread
  if(handlingMethod == _THREAD) {

    // Init thread attr
    pthread_attr_init(&att);
    // Set threads to detached state
    pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED);
    // Set system scope
    pthread_attr_setscope(&att, PTHREAD_SCOPE_SYSTEM);
    // Set RoundRobin scheduling
    pthread_attr_setschedpolicy(&att, SCHED_RR); // Not supported in LINUX pthreads

    // Start accepting requests
    while(execute) {

      // Accept a request from queue, blocking
      if ((sd_current = accept(sd, (struct sockaddr*) &pin, (socklen_t*) &addrlen)) == -1) {
        if (execute) {
          sprintf(error, "Unable to accept request, %s", strerror(errno));
          log_server(LOG_ERR, error);
        }
    		close(sd_current);
        execute = false;    // Terminate
  	  } else {

        // Shit happens, if server is out of memory just skip the request
        _rqhd_args *args = malloc(sizeof(_rqhd_args));
        if (args == NULL) {
          sprintf(error, "Unable to allocate memory, %s", strerror(errno));
          log_server(LOG_CRIT, error);
      		close(sd_current);
        } else {
          // Set arguments
          args->sd      = sd_current;
          args->pin     = pin;
          args->config  = &config;
        }

        // Create thread
        if(pthread_create(&handler, &att, requestHandle, args) != 0) {
          sprintf(error, "Unable to start thread, %s", strerror(errno));
          log_server(LOG_CRIT, error);
          close(sd_current);
          execute = false;    // Terminate
        }
      }
    }

      // Destroy attributes
      pthread_attr_destroy(&att);
    }
  // Else if handling method is set to fork
  else if(handlingMethod == _FORK) {

    max_fd = sd;
    if (fifo > sd)
      max_fd = fifo;

    // Start accepting requests
    while(execute) {

      FD_ZERO(&rfds);
      FD_SET(sd, &rfds);
      FD_SET(fifo, &rfds);

      // Accept request or handle child
      setval = select(max_fd + 1, &rfds, NULL, NULL, NULL);

      if (FD_ISSET(sd, &rfds)) {
        // Accept a request from queue
        if ((sd_current = accept(sd, (struct sockaddr*) &pin, (socklen_t*) &addrlen)) == -1) {
          if (execute) {
            sprintf(error, "Unable to accept request, %s", strerror(errno));
            log_server(LOG_ERR, error);
          }
      		close(sd_current);
          execute = false;    // Terminate
    	  } else {

          // Fork
          if((pid = fork()) == 0) {
            // CHILD ----------------------------------------------------

            // Shit happens, if server is out of memory just skip the request
            _rqhd_args *args = malloc(sizeof(_rqhd_args));
            if (args == NULL) {
              sprintf(error, "Unable to allocate memory, %s", strerror(errno));
              log_server(LOG_CRIT, error);
          		close(sd_current);
            } else {
              // Set arguments
              args->sd      = sd_current;
              args->pin     = pin;
              args->config  = &config;

              // Call request handler
              requestHandle(args);
            }
            // Tell parent I'm done
            pid_t id = getpid();
            if (write(fifo, &id, sizeof(pid_t)) == -1) {
                sprintf(error, "Unable to send pid, %s", strerror(errno));
                log_server(LOG_ERR, error);
            }

            // Done
            execute = false;

          } else if(pid > 0) {
            // PARENT ---------------------------------------------------
            // Parent don't handle dirty work
            close(sd_current);
          } else {
            sprintf(error, "Unable to fork, %s", strerror(errno));
            log_server(LOG_CRIT, error);
            close(sd_current);
            execute = false;    // Terminate
          }
        }
      } else if (FD_ISSET(fifo, &rfds)) {
        // Get child pid from fifo and wait for it
        pid_t child;
        if (read(fifo, &child, sizeof(pid_t)) == -1) {
          sprintf(error, "Unable to read pid, %s", strerror(errno));
          log_server(LOG_ERR, error);
        }
        waitpid(child, NULL, 0);
      } else if (setval == -1){
        // Error
        sprintf(error, "Select failed or was interrupted, %s", strerror(errno));
        log_server(LOG_ERR, error);
        execute = false;    // Terminate
      }

    }

    // Close fifo
    close(fifo);
  }
  // Else not a valid handling method
  else {
    sprintf(error, "Invalid handling method is set");
    log_server(LOG_ERR, error);
  }

  // Clean up
  pthread_mutex_destroy(&thread_lock);
  close(sd);
  log_destroy();
  if (pid != 0)
    printf("Cleanup complete, no one will know I was here.\n");

  return 0;
}