<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.
 *
 * UsbProDevice.cpp
 * UsbPro device
 * Copyright (C) 2006-2007 <NAME>
 *
 * The device creates two ports, one in and one out, but you can only use one
 * at a time.
 */

#include <google/protobuf/stubs/common.h>
#include <google/protobuf/service.h>
#include <iomanip>
#include <iostream>
#include <string>

#include "ola/BaseTypes.h"
#include "ola/Closure.h"
#include "ola/Logging.h"
#include "olad/Preferences.h"
#include "plugins/usbpro/UsbProDevice.h"
#include "plugins/usbpro/WidgetDetector.h"

namespace ola {
namespace plugin {
namespace usbpro {

using google::protobuf::RpcController;
using ola::plugin::usbpro::Request;
using ola::plugin::usbpro::Reply;

/*
 * Create a new device
 *
 * @param owner  the plugin that owns this device
 * @param name  the device name
 * @param dev_path  path to the pro widget
 */
UsbProDevice::UsbProDevice(const ola::PluginAdaptor *plugin_adaptor,
                           ola::AbstractPlugin *owner,
                           const string &name,
                           UsbWidget *widget,
                           uint16_t esta_id,
                           uint16_t device_id,
                           uint32_t serial):
    UsbDevice(owner, name, widget),
    m_got_parameters(false),
    m_in_shutdown(false),
    m_plugin_adaptor(plugin_adaptor),
    m_serial() {
  m_widget->SetMessageHandler(this);

  std::stringstream str;
  str << std::setfill('0');
  uint8_t *ptr = reinterpret_cast<uint8_t*>(&serial);
  for (int i = DeviceInformation::SERIAL_LENGTH - 1; i >= 0; i--) {
    int digit = (10 * (ptr[i] & 0xf0) >> 4) + (ptr[i] & 0x0f);
    str <<  std::setw(2)  << digit;
  }
  m_serial = str.str();

  GetParameters();  // update our local values

  UsbProInputPort *input_port = new UsbProInputPort(
      this,
      0,
      m_plugin_adaptor->WakeUpTime(),
      "");
  AddPort(input_port);
  UsbProOutputPort *output_port = new UsbProOutputPort(this, 0, "");
  AddPort(output_port);
  m_enabled = true;
  (void) esta_id;
  (void) device_id;
}


/*
 * Destroy this device
 */<commit_msg> * add throttling to the usb pro device<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.
 *
 * UsbProDevice.cpp
 * UsbPro device
 * Copyright (C) 2006-2007 <NAME>
 *
 * The device creates two ports, one in and one out, but you can only use one
 * at a time.
 */

#include <google/protobuf/stubs/common.h>
#include <google/protobuf/service.h>
#include <iomanip>
#include <iostream>
#include <string>

#include "ola/BaseTypes.h"
#include "ola/Closure.h"
#include "ola/Logging.h"
#include "olad/PortDecorators.h"
#include "olad/Preferences.h"
#include "plugins/usbpro/UsbProDevice.h"
#include "plugins/usbpro/WidgetDetector.h"

namespace ola {
namespace plugin {
namespace usbpro {

using google::protobuf::RpcController;
using ola::plugin::usbpro::Request;
using ola::plugin::usbpro::Reply;

/*
 * Create a new device
 *
 * @param owner  the plugin that owns this device
 * @param name  the device name
 * @param dev_path  path to the pro widget
 */
UsbProDevice::UsbProDevice(const ola::PluginAdaptor *plugin_adaptor,
                           ola::AbstractPlugin *owner,
                           const string &name,
                           UsbWidget *widget,
                           uint16_t esta_id,
                           uint16_t device_id,
                           uint32_t serial):
    UsbDevice(owner, name, widget),
    m_got_parameters(false),
    m_in_shutdown(false),
    m_plugin_adaptor(plugin_adaptor),
    m_serial() {
  m_widget->SetMessageHandler(this);

  std::stringstream str;
  str << std::setfill('0');
  uint8_t *ptr = reinterpret_cast<uint8_t*>(&serial);
  for (int i = DeviceInformation::SERIAL_LENGTH - 1; i >= 0; i--) {
    int digit = (10 * (ptr[i] & 0xf0) >> 4) + (ptr[i] & 0x0f);
    str <<  std::setw(2)  << digit;
  }
  m_serial = str.str();

  GetParameters();  // update our local values

  UsbProInputPort *input_port = new UsbProInputPort(
      this,
      0,
      m_plugin_adaptor->WakeUpTime(),
      "");
  AddPort(input_port);
  OutputPort *output_port = new ThrottledOutputPortDecorator(
      new UsbProOutputPort(this, 0, ""),
      plugin_adaptor->WakeUpTime(),
      10,  // start with 10 tokens in the bucket
      190);  // 200 frames per second seems to be the limit

  AddPort(output_port);
  m_enabled = true;
  (void) esta_id;
  (void) device_id;
}


/*
 * Destroy this device
 */
{'fraction_non_alphanumeric': 0.10640478223740393, 'fraction_numerical': 0.016737830913748933, 'mean_word_length': 3.0779944289693595, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 28, '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': '2246089', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1836, 'n_words': 588}