• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenLightingProject / ola / 16911433572

12 Aug 2025 02:08PM UTC coverage: 45.869% (-0.04%) from 45.909%
16911433572

Pull #1739

github

web-flow
Merge 02faeaa2d into 3566c28d9
Pull Request #1739: New web UI, store highest channel number used

7157 of 16316 branches covered (43.86%)

20915 of 45597 relevant lines covered (45.87%)

52.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.94
/plugins/stageprofi/StageProfiPlugin.cpp
1
/*
2
 * This program is free software; you can redistribute it and/or modify
3
 * it under the terms of the GNU General Public License as published by
4
 * the Free Software Foundation; either version 2 of the License, or
5
 * (at your option) any later version.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU Library General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15
 *
16
 * StageProfiPlugin.cpp
17
 * The StageProfi plugin for ola
18
 * Copyright (C) 2006 Simon Newton
19
 */
20

21
#include "plugins/stageprofi/StageProfiPlugin.h"
22

23
#include <stdlib.h>
24
#include <stdio.h>
25
#include <string>
26
#include <vector>
27

28
#include "ola/Logging.h"
29
#include "ola/stl/STLUtils.h"
30
#include "olad/PluginAdaptor.h"
31
#include "ola/network/IPV4Address.h"
32
#include "ola/network/TCPSocket.h"
33
#include "olad/Preferences.h"
34
#include "plugins/stageprofi/StageProfiDetector.h"
35
#include "plugins/stageprofi/StageProfiDevice.h"
36
#include "plugins/stageprofi/StageProfiWidget.h"
37

38
namespace ola {
39
namespace plugin {
40
namespace stageprofi {
41

42
using ola::io::ConnectedDescriptor;
43
using std::auto_ptr;
44
using std::string;
45
using std::vector;
46

47
const char StageProfiPlugin::STAGEPROFI_DEVICE_PATH[] = "/dev/ttyUSB0";
48
const char StageProfiPlugin::STAGEPROFI_DEVICE_NAME[] = "StageProfi Device";
49
const char StageProfiPlugin::PLUGIN_NAME[] = "StageProfi";
50
const char StageProfiPlugin::PLUGIN_PREFIX[] = "stageprofi";
51
const char StageProfiPlugin::DEVICE_KEY[] = "device";
52

53
namespace {
54

55
void DeleteStageProfiDevice(StageProfiDevice *device) {
×
56
  delete device;
×
57
}
×
58
}  // namespace
59

60
StageProfiPlugin::~StageProfiPlugin() {
2✔
61
}
2✔
62

63
bool StageProfiPlugin::StartHook() {
1✔
64
  vector<string> device_names = m_preferences->GetMultipleValue(DEVICE_KEY);
1✔
65
  m_detector.reset(new StageProfiDetector(
1✔
66
      m_plugin_adaptor, device_names,
1✔
67
      NewCallback(this, &StageProfiPlugin::NewWidget)));
1✔
68
  m_detector->Start();
1✔
69
  return true;
1✔
70
}
1✔
71

72
bool StageProfiPlugin::StopHook() {
1✔
73
  m_detector->Stop();
1✔
74

75
  DeviceMap::iterator iter = m_devices.begin();
1✔
76
  for (; iter != m_devices.end(); ++iter) {
1✔
77
    DeleteDevice(iter->second);
×
78
  }
79
  m_devices.clear();
1✔
80
  return true;
1✔
81
}
82

83
string StageProfiPlugin::Description() const {
×
84
    return
×
85
"StageProfi Plugin\n"
×
86
"----------------------------\n"
87
"\n"
88
"This plugin creates devices with one output port.\n"
89
"\n"
90
"--- Config file : ola-stageprofi.conf ---\n"
91
"\n"
92
"device = /dev/ttyUSB0\n"
93
"device = 192.168.1.250\n"
94
"The device to use either as a path for the USB version or an IP address\n"
95
"for the LAN version. Multiple devices are supported.\n"
96
"\n";
×
97
}
98

99
bool StageProfiPlugin::SetDefaultPreferences() {
1✔
100
  if (!m_preferences) {
1✔
101
    return false;
102
  }
103

104
  bool save = false;
1✔
105

106
  save |= m_preferences->SetDefaultValue(DEVICE_KEY, StringValidator(),
1✔
107
                                         STAGEPROFI_DEVICE_PATH);
108

109
  if (save) {
1✔
110
    m_preferences->Save();
1✔
111
  }
112

113
  if (m_preferences->GetValue(DEVICE_KEY).empty()) {
1✔
114
    return false;
115
  }
116
  return true;
117
}
118

119
void StageProfiPlugin::NewWidget(const std::string &widget_path,
×
120
                                 ConnectedDescriptor *descriptor) {
121
  OLA_INFO << "New StageProfiWidget: " << widget_path;
×
122

123
  DeviceMap::iterator iter = STLLookupOrInsertNull(&m_devices, widget_path);
×
124
  if (iter->second) {
×
125
    OLA_WARN << "Pre-existing StageProfiDevice for " << widget_path;
×
126
    return;
×
127
  }
128

129
  auto_ptr<StageProfiDevice> device(new StageProfiDevice(
×
130
      this,
131
      new StageProfiWidget(
132
          m_plugin_adaptor, descriptor, widget_path,
×
133
          NewSingleCallback(this, &StageProfiPlugin::DeviceRemoved,
×
134
                            widget_path)),
×
135
      STAGEPROFI_DEVICE_NAME));
×
136

137
  if (!device->Start()) {
×
138
    OLA_INFO << "Failed to start StageProfiDevice";
×
139
    return;
×
140
  }
141

142
  m_plugin_adaptor->RegisterDevice(device.get());
×
143
  iter->second = device.release();
×
144
}
×
145

146
void StageProfiPlugin::DeviceRemoved(std::string widget_path) {
×
147
  OLA_INFO << "StageProfi device " << widget_path << " was removed";
×
148
  StageProfiDevice *device = STLReplacePtr(&m_devices, widget_path, NULL);
×
149
  if (device) {
×
150
    // Since this is called within the call stack of the StageProfiWidget
151
    // itself, we need to schedule deletion for later.
152
    m_plugin_adaptor->UnregisterDevice(device);
×
153
    device->Stop();
×
154
    m_plugin_adaptor->Execute(
×
155
        NewSingleCallback(DeleteStageProfiDevice, device));
×
156
  }
157
  m_detector->ReleaseWidget(widget_path);
×
158
}
×
159

160
void StageProfiPlugin::DeleteDevice(StageProfiDevice *device) {
×
161
  if (device) {
×
162
    m_plugin_adaptor->UnregisterDevice(device);
×
163
    device->Stop();
×
164
    delete device;
×
165
  }
166
}
×
167
}  // namespace stageprofi
168
}  // namespace plugin
169
}  // namespace ola
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc