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

OpenLightingProject / ola / 5329180527

21 Jun 2023 01:46AM UTC coverage: 45.027% (-0.1%) from 45.16%
5329180527

push

github

web-flow
Merge pull request #1787 from peternewman/kinet-port-out

Add Kinet portout support, closes #1544

7602 of 17641 branches covered (43.09%)

146 of 146 new or added lines in 6 files covered. (100.0%)

21411 of 47551 relevant lines covered (45.03%)

55.79 hits per line

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

50.0
/plugins/kinet/KiNetPlugin.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
 * KiNetPlugin.cpp
17
 * The KiNet plugin for ola
18
 * Copyright (C) 2013 Simon Newton
19
 */
20

21
#include <string>
22
#include <vector>
23

24
#include "ola/Logging.h"
25
#include "ola/network/IPV4Address.h"
26
#include "olad/PluginAdaptor.h"
27
#include "olad/Preferences.h"
28
#include "plugins/kinet/KiNetDevice.h"
29
#include "plugins/kinet/KiNetNode.h"
30
#include "plugins/kinet/KiNetPlugin.h"
31
#include "plugins/kinet/KiNetPluginDescription.h"
32

33

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

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

42
const char KiNetPlugin::POWER_SUPPLY_KEY[] = "power_supply";
43
const char KiNetPlugin::PLUGIN_NAME[] = "KiNET";
44
const char KiNetPlugin::PLUGIN_PREFIX[] = "kinet";
45

46
KiNetPlugin::KiNetPlugin(PluginAdaptor *plugin_adaptor)
1✔
47
    : Plugin(plugin_adaptor) {
1✔
48
}
1✔
49

50
KiNetPlugin::~KiNetPlugin() {}
4✔
51

52
/*
53
 * Start the plugin.
54
 */
55
bool KiNetPlugin::StartHook() {
1✔
56
  m_node = new KiNetNode(m_plugin_adaptor);
1✔
57

58
  if (!m_node->Start()) {
1✔
59
    delete m_node;
×
60
    m_node = NULL;
×
61
    return false;
×
62
  }
63

64
  vector<string> power_supplies_strings = m_preferences->GetMultipleValue(
1✔
65
      POWER_SUPPLY_KEY);
1✔
66
  vector<string>::const_iterator iter = power_supplies_strings.begin();
1✔
67

68
  // TODO(Peter): De-duplicate PSU IPs (via a set?)
69
  for (; iter != power_supplies_strings.end(); ++iter) {
2✔
70
    if (iter->empty()) {
1✔
71
      continue;
1✔
72
    }
73
    IPV4Address target;
×
74
    if (IPV4Address::FromString(*iter, &target)) {
×
75
      string mode = m_preferences->GetValue(KiNetDevice::ModeKey(target));
×
76
      OLA_DEBUG << "Got mode " << mode << " for " << target;
×
77
      KiNetDevice *device = NULL;
×
78
      if (mode.compare(KiNetDevice::PORTOUT_MODE) == 0) {
×
79
        device = new KiNetPortOutDevice(this,
×
80
                                        target,
81
                                        m_plugin_adaptor,
82
                                        m_node,
83
                                        m_preferences);
×
84
      } else {
85
        device = new KiNetDmxOutDevice(this,
×
86
                                       target,
87
                                       m_plugin_adaptor,
88
                                       m_node,
89
                                       m_preferences);
×
90
      }
91

92
      if (!device) {
×
93
        continue;
×
94
      }
95

96
      if (!device->Start()) {
×
97
        delete device;
×
98
        continue;
×
99
      }
100
      m_devices.push_back(device);
×
101
      m_plugin_adaptor->RegisterDevice(device);
×
102
    } else {
×
103
      OLA_WARN << "Invalid power supply IP address: " << *iter;
×
104
    }
105
  }
106
  return true;
1✔
107
}
1✔
108

109

110
/*
111
 * Stop the plugin
112
 * @return true on success, false on failure
113
 */
114
bool KiNetPlugin::StopHook() {
1✔
115
  vector<KiNetDevice*>::iterator iter = m_devices.begin();
1✔
116
  bool ok = true;
1✔
117
  for (; iter != m_devices.end(); ++iter) {
1✔
118
    m_plugin_adaptor->UnregisterDevice(*iter);
×
119
    ok &= (*iter)->Stop();
×
120
    delete *iter;
×
121
  }
122

123
  ok &= m_node->Stop();
1✔
124
  delete m_node;
1✔
125
  m_node = NULL;
1✔
126

127
  return ok;
1✔
128
}
129

130

131
/*
132
 * Return the description for this plugin.
133
 * @return a string description of the plugin
134
 */
135
string KiNetPlugin::Description() const {
×
136
    return plugin_description;
×
137
}
138

139

140
/*
141
 * Set default preferences.
142
 */
143
bool KiNetPlugin::SetDefaultPreferences() {
1✔
144
  bool save = false;
1✔
145

146
  if (!m_preferences) {
1✔
147
    return false;
148
  }
149

150
  save |= m_preferences->SetDefaultValue(POWER_SUPPLY_KEY,
1✔
151
                                         StringValidator(true), "");
1✔
152

153
  if (save) {
1✔
154
    m_preferences->Save();
1✔
155
  }
156
  return true;
157
}
158
}  // namespace kinet
159
}  // namespace plugin
160
}  // 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