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

OpenLightingProject / ola / 17141553775

21 Aug 2025 11:23PM UTC coverage: 45.72% (-0.02%) from 45.742%
17141553775

push

github

web-flow
Merge pull request #2014 from peternewman/mac-be

Tidy the Mac OS Endian behaviour

7586 of 17462 branches covered (43.44%)

22424 of 49046 relevant lines covered (45.72%)

53.43 hits per line

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

37.1
/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/StageProfiPluginDescription.h"
37
#include "plugins/stageprofi/StageProfiWidget.h"
38

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

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

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

54
namespace {
55

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

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

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

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

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

84
string StageProfiPlugin::Description() const {
×
85
    return plugin_description;
×
86
}
87

88
bool StageProfiPlugin::SetDefaultPreferences() {
1✔
89
  if (!m_preferences) {
1✔
90
    return false;
91
  }
92

93
  bool save = false;
1✔
94

95
  save |= m_preferences->SetDefaultValue(DEVICE_KEY, StringValidator(),
1✔
96
                                         STAGEPROFI_DEVICE_PATH);
97

98
  if (save) {
1✔
99
    m_preferences->Save();
1✔
100
  }
101

102
  if (m_preferences->GetValue(DEVICE_KEY).empty()) {
1✔
103
    return false;
104
  }
105
  return true;
106
}
107

108
void StageProfiPlugin::NewWidget(const std::string &widget_path,
×
109
                                 ConnectedDescriptor *descriptor) {
110
  OLA_INFO << "New StageProfiWidget: " << widget_path;
×
111

112
  DeviceMap::iterator iter = STLLookupOrInsertNull(&m_devices, widget_path);
×
113
  if (iter->second) {
×
114
    OLA_WARN << "Pre-existing StageProfiDevice for " << widget_path;
×
115
    return;
×
116
  }
117

118
  auto_ptr<StageProfiDevice> device(new StageProfiDevice(
×
119
      this,
120
      new StageProfiWidget(
121
          m_plugin_adaptor, descriptor, widget_path,
×
122
          NewSingleCallback(this, &StageProfiPlugin::DeviceRemoved,
×
123
                            widget_path)),
×
124
      STAGEPROFI_DEVICE_NAME));
×
125

126
  if (!device->Start()) {
×
127
    OLA_INFO << "Failed to start StageProfiDevice";
×
128
    return;
×
129
  }
130

131
  m_plugin_adaptor->RegisterDevice(device.get());
×
132
  iter->second = device.release();
×
133
}
×
134

135
void StageProfiPlugin::DeviceRemoved(std::string widget_path) {
×
136
  OLA_INFO << "StageProfi device " << widget_path << " was removed";
×
137
  StageProfiDevice *device = STLReplacePtr(&m_devices, widget_path, NULL);
×
138
  if (device) {
×
139
    // Since this is called within the call stack of the StageProfiWidget
140
    // itself, we need to schedule deletion for later.
141
    m_plugin_adaptor->UnregisterDevice(device);
×
142
    device->Stop();
×
143
    m_plugin_adaptor->Execute(
×
144
        NewSingleCallback(DeleteStageProfiDevice, device));
×
145
  }
146
  m_detector->ReleaseWidget(widget_path);
×
147
}
×
148

149
void StageProfiPlugin::DeleteDevice(StageProfiDevice *device) {
×
150
  if (device) {
×
151
    m_plugin_adaptor->UnregisterDevice(device);
×
152
    device->Stop();
×
153
    delete device;
×
154
  }
155
}
×
156
}  // namespace stageprofi
157
}  // namespace plugin
158
}  // 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