/*
 * Author: Jon Trulson <jtrulson@ics.com>
 * Copyright (c) 2016 Intel Corporation.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include <iostream>
#include <stdexcept>
#include <string>

#include "ozwinterface.hpp"

using namespace upm;
using namespace std;


ozwInterface::ozwInterface(int nodeID) :
  m_instance(0)
{
  // Save our device's ID
  m_nodeID = nodeID;

  // create the OZW instance here if it does not already exist, and
  // store the pointer in our class to save on some typing.
  m_instance = OZW::instance();

  // now see if it has been initialized yet for init()
  m_initialized = m_instance->isInitialized();

  setDebug(false);
}

ozwInterface::~ozwInterface()
{
}

void ozwInterface::init(string devicePath, bool isHID)
{
  // if we are already intitialized, don't try to do it again...

  if (!m_initialized)
    m_instance->init(devicePath, isHID);

  // either it threw, or we are initialized now...
  m_initialized = true;
}

void ozwInterface::setDebug(bool enable)
{
  m_debugging = enable;

  // we also enable/disable debugging in OZW
  m_instance->setDebug(enable);
}
