<commit_before>/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *  ola-throughput.cpp
 *  Send a bunch of frames quickly to load test the server.
 *  Copyright (C) 2005-2010 <NAME>
 */

#include <errno.h>
#include <getopt.h>
#include <stdlib.h>
#include <ola/DmxBuffer.h>
#include <ola/Logging.h>
#include <ola/StreamingClient.h>
#include <ola/StringUtils.h>

#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;
using ola::StreamingClient;


typedef struct {
  unsigned int universe;
  unsigned int sleep_time;
  bool help;
} options;


/*
 * parse our cmd line options
 */
void ParseOptions(int argc, char *argv[], options *opts) {
  static struct option long_options[] = {
      {"help", no_argument, 0, 'h'},
      {"sleep", required_argument, 0, 's'},
      {"universe", required_argument, 0, 'u'},
      {0, 0, 0, 0}
    };

  opts->sleep_time = 40000;
  opts->universe = 1;
  opts->help = false;

  int c;
  int option_index = 0;

  while (1) {
    c = getopt_long(argc, argv, "hs:u:", long_options, &option_index);

    if (c == -1)
      break;

    switch (c) {
      case 0:
        break;
      case 'h':
        opts->help = true;
        break;
      case 's':
        opts->sleep_time = atoi(optarg);
        break;
      case 'u':
        opts->universe = atoi(optarg);
        break;
      case '?':
        break;
      default:
        break;
    }
  }
}


/*
 * Display the help message
 */
void DisplayHelpAndExit(char arg[]) {
  cout << "Usage: " << arg <<
  " --dmx <dmx_data> --universe <universe_id>\n"
  "\n"
  "Send DMX512 data to OLA. If dmx data isn't provided we read from stdin.\n"
  "\n"
  "  -h, --help                   Display this help message and exit.\n"
  "  -s, --sleep <time_in_uS>     Time to sleep between frames.\n"
  "  -u, --universe <universe_id> Id of universe to send data for.\n"
  << endl;
  exit(1);
}


/*
 * Main
 */
int main(int argc, char *argv[]) {
  ola::InitLogging(ola::OLA_LOG_WARN, ola::OLA_LOG_STDERR);
  StreamingClient ola_client;
  options opts;

  ParseOptions(argc, argv, &opts);

  if (opts.help)
    DisplayHelpAndExit(argv[0]);

  if (!ola_client.Setup()) {
    OLA_FATAL << "Setup failed";
    exit(1);
  }

  while (1) {
    usleep(opts.sleep_time);
    ola::DmxBuffer buffer;
    buffer.Blackout();

    if (!ola_client.SendDmx(opts.universe, buffer)) {
      cout << "Send DMX failed" << endl;
      return false;
    }
  }
  return 0;<commit_msg>* Switch ola-throughput to use the flags module<commit_after>/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * ola-throughput.cpp
 * Send a bunch of frames quickly to load test the server.
 * Copyright (C) 2005-2010 <NAME>
 */

#include <errno.h>
#include <stdlib.h>
#include <ola/base/Flags.h>
#include <ola/base/Init.h>
#include <ola/DmxBuffer.h>
#include <ola/Logging.h>
#include <ola/StreamingClient.h>
#include <ola/StringUtils.h>

#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;
using ola::StreamingClient;

DEFINE_s_uint32(universe, u, 1, "The universe to send data on");
DEFINE_s_uint32(sleep, s, 40000, "Time between DMX updates in micro-seconds");

/*
 * Main
 */
int main(int argc, char *argv[]) {
  ola::AppInit(argc, argv);
  ola::SetHelpString("[options]", "Send DMX512 data to OLA.");
  ola::ParseFlags(&argc, argv);
  ola::InitLoggingFromFlags();

  StreamingClient ola_client;
  if (!ola_client.Setup()) {
    OLA_FATAL << "Setup failed";
    exit(1);
  }

  ola::DmxBuffer buffer;
  buffer.Blackout();

  while (1) {
    usleep(FLAGS_sleep);
    if (!ola_client.SendDmx(FLAGS_universe, buffer)) {
      cout << "Send DMX failed" << endl;
      return false;
    }
  }
  return 0;
{'fraction_non_alphanumeric': 0.12502468891961288, 'fraction_numerical': 0.017183488050562908, 'mean_word_length': 3.2024896265560168, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5871180', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1640, 'n_words': 573}