File: JaRuleOutputPort.cpp

package info (click to toggle)
ola 0.10.9.nojsmin-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 17,440 kB
  • sloc: cpp: 132,294; python: 14,445; javascript: 7,109; sh: 4,713; ansic: 2,189; java: 518; xml: 253; makefile: 175
file content (99 lines) | stat: -rw-r--r-- 3,161 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * JaRuleOutputPort.cpp
 * A JaRule output port that uses a widget.
 * Copyright (C) 2015 Simon Newton
 */

#include "plugins/usbdmx/JaRuleOutputPort.h"

#include <string>

#include "libs/usb/JaRulePortHandle.h"
#include "ola/Logging.h"
#include "ola/strings/Format.h"
#include "olad/Device.h"

namespace ola {
namespace plugin {
namespace usbdmx {

using ola::usb::JaRulePortHandle;
using ola::usb::JaRuleWidget;

JaRuleOutputPort::JaRuleOutputPort(Device *parent,
                                   unsigned int index,
                                   JaRuleWidget *widget)
    : BasicOutputPort(parent, index, true, true),
      m_port_index(index),
      m_widget(widget),
      m_port_handle(NULL) {
}

JaRuleOutputPort::~JaRuleOutputPort() {
  // The shutdown process is a bit tricky, since there may be callbacks pending
  // in the JaRulePortHandle. Releasing the port handle will run any pending
  // callbacks.
  m_widget->ReleasePort(m_port_index);
}

bool JaRuleOutputPort::Init() {
  m_port_handle = m_widget->ClaimPort(m_port_index);
  return m_port_handle != NULL;
}

std::string JaRuleOutputPort::Description() const {
  return "Port " + ola::strings::IntToString(PortId() + 1);
}

bool JaRuleOutputPort::WriteDMX(const DmxBuffer &buffer,
                                OLA_UNUSED uint8_t priority) {
  m_port_handle->SendDMX(buffer);
  return true;
}

void JaRuleOutputPort::SendRDMRequest(ola::rdm::RDMRequest *request,
                                      ola::rdm::RDMCallback *callback) {
  m_port_handle->SendRDMRequest(request, callback);
}

void JaRuleOutputPort::RunFullDiscovery(
    ola::rdm::RDMDiscoveryCallback *callback) {
  m_port_handle->RunFullDiscovery(callback);
}

void JaRuleOutputPort::RunIncrementalDiscovery(
    ola::rdm::RDMDiscoveryCallback *callback) {
  m_port_handle->RunIncrementalDiscovery(callback);
}

bool JaRuleOutputPort::PreSetUniverse(Universe *old_universe,
                                      Universe *new_universe) {
  if (old_universe == NULL && new_universe != NULL) {
    m_port_handle->SetPortMode(ola::usb::CONTROLLER_MODE);
  }
  return true;
}

void JaRuleOutputPort::PostSetUniverse(Universe *old_universe,
                                       Universe *new_universe) {
  if (old_universe != NULL && new_universe == NULL) {
    m_port_handle->SetPortMode(ola::usb::RESPONDER_MODE);
  }
}
}  // namespace usbdmx
}  // namespace plugin
}  // namespace ola