Showing the changes to interface/src/scripting/OSCScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -14,7 +14,9 @@ · 13 unmodified lines | |||
| 14 | #include <QtEndian> | 14 | #include <QtEndian> |
| 15 | #include <QNetworkDatagram> | 15 | #include <QNetworkDatagram> |
| 16 | 16 | ||
| 17 | #include "ScriptContext.h" | ||
| 17 | #include "ScriptEngine.h" | 18 | #include "ScriptEngine.h" |
| 19 | #include "ScriptValue.h" | ||
| 18 | #include "OSCScriptingInterface.h" | 20 | #include "OSCScriptingInterface.h" |
| 19 | 21 | ||
| 20 | 22 | ||
| @@ -179,26 +181,29 @@ void OSCScriptingInterface::readPacket() { · 158 unmodified lines | |||
| 179 | emit packetReceived(addr, args); | 181 | emit packetReceived(addr, args); |
| 180 | } | 182 | } |
| 181 | 183 | ||
| 182 | void OSCScriptingInterface::sendPacket(const QString& address, const QVariantList& arguments) { | 184 | ScriptValue OSCScriptingInterface::sendPacket(ScriptContext* context, ScriptEngine* engine) { |
| 183 | Q_ASSERT(_socket); | 185 | auto instance = DependencyManager::get<OSCScriptingInterface>(); |
| 184 | 186 | ||
| 185 | // FIXME: how do you get the script engine??? | 187 | if (context->argumentCount() == 0) { |
| 186 | struct HackRemoveThis { | 188 | engine->raiseException("Address is required"); |
| 187 | void raiseException(QString msg) { | 189 | return engine->undefinedValue(); |
| 188 | qCCritical(osc_cat) << msg; | 190 | } |
| 189 | } | 191 | |
| 190 | }; | 192 | auto address = context->argument(0).toString(); |
| 193 | QVariantList arguments; | ||
| 191 | 194 | ||
| 192 | auto scriptEngine = std::make_unique<HackRemoveThis>(); //_scriptManager->engine(); | 195 | for (int i = 1; i < context->argumentCount(); i++) { |
| 196 | arguments.append(context->argument(i).toVariant()); | ||
| 197 | } | ||
| 193 | 198 | ||
| 194 | if (address.length() < 2 || !address.startsWith('/') || address.endsWith('/')) { | 199 | if (address.length() < 2 || !address.startsWith('/') || address.endsWith('/')) { |
| 195 | scriptEngine->raiseException("address must be at least two characters and start with '/'"); | 200 | engine->raiseException("Address must be at least two characters and start with '/'"); |
| 196 | return; | 201 | return engine->undefinedValue(); |
| 197 | } | 202 | } |
| 198 | 203 | ||
| 199 | if (auto match = invalidCharacters.match(address); match.hasMatch()) { | 204 | if (auto match = invalidCharacters.match(address); match.hasMatch()) { |
| 200 | scriptEngine->raiseException(QString("address contains invalid character '%1'").arg(match.captured())); | 205 | engine->raiseException(QString("Address contains invalid character '%1'").arg(match.captured())); |
| 201 | return; | 206 | return engine->undefinedValue(); |
| 202 | } | 207 | } |
| 203 | 208 | ||
| 204 | auto pad4 = [](QByteArray& array) { | 209 | auto pad4 = [](QByteArray& array) { |
| @@ -226,8 +231,8 @@ void OSCScriptingInterface::sendPacket(const QString& address, const QVariantLis · 21 unmodified lines | |||
| 226 | auto map = arg.toMap(); | 231 | auto map = arg.toMap(); |
| 227 | auto typeName = map.value("type").toString(); | 232 | auto typeName = map.value("type").toString(); |
| 228 | if (!typeNameMap.contains(typeName[0])) { | 233 | if (!typeNameMap.contains(typeName[0])) { |
| 229 | scriptEngine->raiseException(QString("Unknown type '%c' on argument %d").arg(typeName).arg(i)); | 234 | engine->raiseException(QString("Unknown type '%c' on argument %d").arg(typeName).arg(i)); |
| 230 | return; | 235 | return engine->undefinedValue(); |
| 231 | } | 236 | } |
| 232 | expectedType = typeNameMap[typeName[0]]; | 237 | expectedType = typeNameMap[typeName[0]]; |
| 233 | value = map.value("value"); | 238 | value = map.value("value"); |
| @@ -268,8 +273,8 @@ void OSCScriptingInterface::sendPacket(const QString& address, const QVariantLis · 34 unmodified lines | |||
| 268 | auto stringArg = value.toString(); | 273 | auto stringArg = value.toString(); |
| 269 | 274 | ||
| 270 | if (stringArg.contains(QChar(0))) { | 275 | if (stringArg.contains(QChar(0))) { |
| 271 | scriptEngine->raiseException("String contains null (0x00) character"); | 276 | engine->raiseException("String contains null (0x00) character"); |
| 272 | return; | 277 | return engine->undefinedValue(); |
| 273 | } | 278 | } |
| 274 | 279 | ||
| 275 | bodyBytes.append(stringArg.toUtf8()); | 280 | bodyBytes.append(stringArg.toUtf8()); |
| @@ -301,8 +306,8 @@ void OSCScriptingInterface::sendPacket(const QString& address, const QVariantLis · 25 unmodified lines | |||
| 301 | break; | 306 | break; |
| 302 | 307 | ||
| 303 | default: | 308 | default: |
| 304 | scriptEngine->raiseException(QString("Unserializable type %1").arg(value.typeName())); | 309 | engine->raiseException(QString("Unserializable type %1").arg(value.typeName())); |
| 305 | return; | 310 | return engine->undefinedValue(); |
| 306 | } | 311 | } |
| 307 | } | 312 | } |
| 308 | 313 | ||
| @@ -313,7 +318,9 @@ void OSCScriptingInterface::sendPacket(const QString& address, const QVariantLis · 4 unmodified lines | |||
| 313 | // pack the header + body data together for the datagram | 318 | // pack the header + body data together for the datagram |
| 314 | bytes.append(bodyBytes); | 319 | bytes.append(bodyBytes); |
| 315 | 320 | ||
| 316 | _socket->writeDatagram(bytes, QHostAddress(_sendHost.get()), _sendPort.get()); | 321 | instance->_socket->writeDatagram(bytes, QHostAddress(instance->_sendHost.get()), instance->_sendPort.get()); |
| 322 | |||
| 323 | qCDebug(osc_cat) << QHostAddress(instance->_sendHost.get()) << instance->_sendPort.get() << ":" << bytes.toHex(' '); | ||
| 317 | 324 | ||
| 318 | qCDebug(osc_cat) << QHostAddress(_sendHost.get()) << _sendPort.get() << ":" << bytes.toHex(' '); | 325 | return engine->undefinedValue(); |
| 319 | } | 326 | } |