• 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

48.57
/plugins/openpixelcontrol/OPCPlugin.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
 * OPCPlugin.cpp
17
 * The Open Pixel Control Plugin.
18
 * Copyright (C) 2014 Simon Newton
19
 */
20

21
#include "plugins/openpixelcontrol/OPCPlugin.h"
22

23
#include <memory>
24
#include <string>
25
#include <vector>
26

27
#include "ola/Logging.h"
28
#include "ola/network/SocketAddress.h"
29
#include "olad/Device.h"
30
#include "olad/PluginAdaptor.h"
31
#include "olad/Preferences.h"
32
#include "plugins/openpixelcontrol/OPCDevice.h"
33

34
namespace ola {
35
namespace plugin {
36
namespace openpixelcontrol {
37

38
using ola::network::IPV4SocketAddress;
39
using std::string;
40
using std::vector;
41

42
const char OPCPlugin::LISTEN_KEY[] = "listen";
43
const char OPCPlugin::PLUGIN_NAME[] = "Open Pixel Control";
44
const char OPCPlugin::PLUGIN_PREFIX[] = "openpixelcontrol";
45
const char OPCPlugin::TARGET_KEY[] = "target";
46

47
OPCPlugin::~OPCPlugin() {}
2✔
48

49
bool OPCPlugin::StartHook() {
1✔
50
  // Start Target (output) devices.
51
  AddDevices<OPCClientDevice>(TARGET_KEY);
1✔
52

53
  // Start listen (input) devices.
54
  AddDevices<OPCServerDevice>(LISTEN_KEY);
1✔
55
  return true;
1✔
56
}
57

58
bool OPCPlugin::StopHook() {
1✔
59
  OPCDevices::iterator iter = m_devices.begin();
1✔
60
  for (; iter != m_devices.end(); ++iter) {
1✔
61
    m_plugin_adaptor->UnregisterDevice(*iter);
×
62
    (*iter)->Stop();
×
63
    delete *iter;
×
64
  }
65
  m_devices.clear();
1✔
66
  return true;
1✔
67
}
68

69
string OPCPlugin::Description() const {
×
70
    return
×
71
"OPC Plugin\n"
×
72
"----------------------------\n"
73
"\n"
74
"This plugin creates OPC Client and/or OPC Server Devices.\n"
75
"\n"
76
"--- Config file : ola-opc.conf ---\n"
77
"\n"
78
"target = <IP>:<port>\n"
79
"Create a Open Pixel Control client, connected to the IP:port.\n"
80
"Multiple targets can be specified and a device will be created\n"
81
"for each.\n"
82
"\n"
83
"listen = <IP>:<port>\n"
84
"Create an Open Pixel Control server, listening on IP:port.\n"
85
"To listen on any address use listen = 0.0.0.0.\n"
86
"Multiple listen keys can be specified and a device will be created\n"
87
"for each.\n"
88
"\n"
89
"target_<IP>:<port>_channel = <channel>\n"
90
"The Open Pixel Control channels to use for the specified device.\n"
91
"Multiple channels can be specified and an output port will be created\n"
92
"for each.\n"
93
"\n"
94
"listen_<IP>:<port>_channel = <channel>\n"
95
"The Open Pixel Control channels to use for the specified device.\n"
96
"Multiple channels can be specified and an input port will be created\n"
97
"for each.\n"
98
"\n";
×
99
}
100

101
bool OPCPlugin::SetDefaultPreferences() {
1✔
102
  if (!m_preferences) {
1✔
103
    return false;
×
104
  }
105
  // No defaults.
106
  return true;
107
}
108

109
template <typename DeviceClass>
110
void OPCPlugin::AddDevices(const std::string &key) {
2✔
111
  vector<string> addresses = m_preferences->GetMultipleValue(key);
2✔
112
  vector<string>::const_iterator iter = addresses.begin();
2✔
113
  for (; iter != addresses.end(); ++iter) {
2✔
114
    IPV4SocketAddress target;
×
115
    if (!IPV4SocketAddress::FromString(*iter, &target)) {
×
116
      OLA_WARN << "Invalid Open Pixel Control address: " << *iter;
×
117
      continue;
×
118
    }
119

120
    std::auto_ptr<DeviceClass> device(new DeviceClass(
×
121
        this, m_plugin_adaptor, m_preferences, target));
122

123
    if (!device->Start()) {
×
124
      OLA_INFO << "Failed to start OPCDevice";
×
125
      continue;
126
    }
127

128
    m_plugin_adaptor->RegisterDevice(device.get());
×
129
    OLA_INFO << "Added OPC device";
×
130
    m_devices.push_back(device.release());
×
131
  }
132
}
2✔
133
}  // namespace openpixelcontrol
134
}  // namespace plugin
135
}  // 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