Mercurial > hg > svcore
comparison data/osc/OSCQueue.cpp @ 1713:978c143c767f
Merge from branch single-point
author | Chris Cannam |
---|---|
date | Fri, 17 May 2019 10:02:43 +0100 |
parents | c077a97d055f |
children | 1318e069906b |
comparison
equal
deleted
inserted
replaced
1709:ab4fd193262b | 1713:978c143c767f |
---|---|
21 #include "OSCQueue.h" | 21 #include "OSCQueue.h" |
22 | 22 |
23 #include "base/Profiler.h" | 23 #include "base/Profiler.h" |
24 | 24 |
25 #include <iostream> | 25 #include <iostream> |
26 #include <QThread> | |
26 | 27 |
27 #define OSC_MESSAGE_QUEUE_SIZE 1023 | 28 #define OSC_MESSAGE_QUEUE_SIZE 1023 |
28 | 29 |
29 #ifdef HAVE_LIBLO | 30 #ifdef HAVE_LIBLO |
30 | 31 |
87 return 0; | 88 return 0; |
88 } | 89 } |
89 | 90 |
90 #endif | 91 #endif |
91 | 92 |
92 OSCQueue::OSCQueue() : | 93 OSCQueue::OSCQueue(bool withNetworkPort) : |
93 #ifdef HAVE_LIBLO | 94 #ifdef HAVE_LIBLO |
94 m_thread(nullptr), | 95 m_thread(nullptr), |
95 #endif | 96 #endif |
97 m_withPort(withNetworkPort), | |
96 m_buffer(OSC_MESSAGE_QUEUE_SIZE) | 98 m_buffer(OSC_MESSAGE_QUEUE_SIZE) |
97 { | 99 { |
98 Profiler profiler("OSCQueue::OSCQueue"); | 100 Profiler profiler("OSCQueue::OSCQueue"); |
99 | 101 |
100 #ifdef HAVE_LIBLO | 102 #ifdef HAVE_LIBLO |
101 m_thread = lo_server_thread_new(nullptr, oscError); | 103 if (m_withPort) { |
102 | 104 m_thread = lo_server_thread_new(nullptr, oscError); |
103 lo_server_thread_add_method(m_thread, nullptr, nullptr, | 105 |
104 oscMessageHandler, this); | 106 lo_server_thread_add_method(m_thread, nullptr, nullptr, |
105 | 107 oscMessageHandler, this); |
106 lo_server_thread_start(m_thread); | 108 |
107 | 109 lo_server_thread_start(m_thread); |
108 cout << "OSCQueue::OSCQueue: Base OSC URL is " | 110 |
109 << lo_server_thread_get_url(m_thread) << endl; | 111 SVDEBUG << "OSCQueue::OSCQueue: Started OSC thread, URL is " |
112 << lo_server_thread_get_url(m_thread) << endl; | |
113 | |
114 cout << "OSCQueue::OSCQueue: Base OSC URL is " | |
115 << lo_server_thread_get_url(m_thread) << endl; | |
116 } | |
117 #else | |
118 if (m_withPort) { | |
119 SVDEBUG << "OSCQueue::OSCQueue: Note: OSC port support not " | |
120 << "compiled in; not opening port, falling back to " | |
121 << "internal-only queue" << endl; | |
122 m_withPort = false; | |
123 } | |
110 #endif | 124 #endif |
111 } | 125 } |
112 | 126 |
113 OSCQueue::~OSCQueue() | 127 OSCQueue::~OSCQueue() |
114 { | 128 { |
124 } | 138 } |
125 | 139 |
126 bool | 140 bool |
127 OSCQueue::isOK() const | 141 OSCQueue::isOK() const |
128 { | 142 { |
129 #ifdef HAVE_LIBLO | 143 if (!m_withPort) { |
130 return (m_thread != nullptr); | 144 return true; |
145 } else { | |
146 #ifdef HAVE_LIBLO | |
147 return (m_thread != nullptr); | |
131 #else | 148 #else |
132 return false; | 149 return false; |
133 #endif | 150 #endif |
151 } | |
134 } | 152 } |
135 | 153 |
136 QString | 154 QString |
137 OSCQueue::getOSCURL() const | 155 OSCQueue::getOSCURL() const |
138 { | 156 { |
139 QString url = ""; | 157 QString url = ""; |
140 #ifdef HAVE_LIBLO | 158 #ifdef HAVE_LIBLO |
141 url = lo_server_thread_get_url(m_thread); | 159 if (m_thread) { |
160 url = lo_server_thread_get_url(m_thread); | |
161 } | |
142 #endif | 162 #endif |
143 return url; | 163 return url; |
144 } | 164 } |
145 | 165 |
146 int | 166 int |
153 OSCQueue::readMessage() | 173 OSCQueue::readMessage() |
154 { | 174 { |
155 OSCMessage *message = m_buffer.readOne(); | 175 OSCMessage *message = m_buffer.readOne(); |
156 OSCMessage rmessage = *message; | 176 OSCMessage rmessage = *message; |
157 delete message; | 177 delete message; |
178 SVDEBUG << "OSCQueue::readMessage: In thread " | |
179 << QThread::currentThreadId() << ": message follows:\n" | |
180 << rmessage.toString() << endl; | |
158 return rmessage; | 181 return rmessage; |
159 } | 182 } |
160 | 183 |
161 void | 184 void |
162 OSCQueue::postMessage(OSCMessage message) | 185 OSCQueue::postMessage(OSCMessage message) |
178 } | 201 } |
179 | 202 |
180 OSCMessage *mp = new OSCMessage(message); | 203 OSCMessage *mp = new OSCMessage(message); |
181 m_buffer.write(&mp, 1); | 204 m_buffer.write(&mp, 1); |
182 SVDEBUG << "OSCQueue::postMessage: Posted OSC message: target " | 205 SVDEBUG << "OSCQueue::postMessage: Posted OSC message: target " |
183 << message.getTarget() << ", target data " << message.getTargetData() | 206 << message.getTarget() << ", target data " |
184 << ", method " << message.getMethod() << endl; | 207 << message.getTargetData() << ", method " |
208 << message.getMethod() << endl; | |
185 emit messagesAvailable(); | 209 emit messagesAvailable(); |
186 } | 210 } |
187 | 211 |
188 bool | 212 bool |
189 OSCQueue::parseOSCPath(QString path, int &target, int &targetData, | 213 OSCQueue::parseOSCPath(QString path, int &target, int &targetData, |
218 << "target/method or method, where target and data " | 242 << "target/method or method, where target and data " |
219 << "are numeric)" << endl; | 243 << "are numeric)" << endl; |
220 return false; | 244 return false; |
221 } | 245 } |
222 | 246 |
223 SVDEBUG << "OSCQueue::parseOSCPath: good path \"" << path << "\"" << endl; | 247 SVDEBUG << "OSCQueue::parseOSCPath: good path \"" << path |
248 << "\"" << endl; | |
224 | 249 |
225 return true; | 250 return true; |
226 } | 251 } |
227 | 252 |