void HttpClient::onCall() { // prepare HTTP request _client.request().clear(); _client.request().header().set("Content-Type", "text/xml"); _client.request().setMethod("POST"); std::ostream& os = _client.request().body(); // format XML-RPC request beginMessage(os); while( ! advanceMessage() ) { if(_client.request().buffer().size() > 8192) { _client.send(false); } } finishMessage(); // send HTTP request and start receiving HTTP reply _client.send(true); std::istream& is = _client.receive(); // parse XML-RPC reply Client::processResult(is); // discard remaining data std::streamsize all = std::numeric_limits<std::streamsize>::max(); is.ignore(all); }
void activate(SynthId synth) { beginMessage(); oscPacket() .openMessage("/synth/activate", 1) .int32(synth.id()) .closeMessage(); }
void free(NodeId node) { beginMessage(); oscPacket() .openMessage("/node/free", 1) .int32(node.id()) .closeMessage(); m_engine->nodeIdAllocator().free(node.id()); }
void set(NodeId node, size_t index, double value) { beginMessage(); oscPacket() .openMessage("/node/set", 3) .int32(node.id()) .int32(index) .float32(value) .closeMessage(); }
void mapOutput(SynthId synth, size_t index, AudioBusId bus, BusMappingFlags flags=kBusMappingInternal) { beginMessage(); oscPacket() .openMessage("/synth/map/output", 4) .int32(synth.id()) .int32(index) .int32(bus.id()) .int32(flags) .closeMessage(); }
GroupId group(GroupId parent) { beginMessage(); const int32_t nodeId = m_engine->nodeIdAllocator().alloc(); oscPacket() .openMessage("/group/new", 3) .int32(nodeId) .int32(parent.id()) .int32(0) // add action .closeMessage(); return GroupId(nodeId); }
void HttpClient::onInvoke() { // prepare HTTP request _client.request().clear(); _client.request().header().set("Content-Type", "text/xml"); _client.request().setMethod("POST"); std::ostream& os = _client.request().body(); // format XML-RPC request beginMessage(os); while( ! advanceMessage() ) { if(_client.request().buffer().size() > 8192) { _client.beginSend(false); return; } } finishMessage(); _client.beginReceive(); }
SynthId synth(const char* synthDef, GroupId parent, const std::vector<float>& controls, const std::list<Value>& options=std::list<Value>()) { beginMessage(); const int32_t nodeId = m_engine->nodeIdAllocator().alloc(); oscPacket() .openMessage("/synth/new", 4 + OSCPP::Tags::array(controls.size()) + OSCPP::Tags::array(options.size())) .string(synthDef) .int32(nodeId) .int32(parent.id()) .int32(0) .putArray(controls.begin(), controls.end()); oscPacket().openArray(); for (const auto& x : options) { x.put(oscPacket()); } oscPacket().closeArray(); oscPacket().closeMessage(); return SynthId(nodeId); }
AREXPORT int ArNMEAParser::parse(const char *buf, int n) { int result = 0; if (n < 0) { return result|ParseError; } if (n == 0) { return result|ParseFinished; } #ifdef DEBUG_ARNMEAPARSER std::cerr << "\t[ArNMEAParser: given " << n << " bytes of data.]\n"; std::cerr << "\t[ArNMEAParser: parsing chunk \""; ArNMEAParser_printBuf(stderr, buf, n); std::cerr << "\"]\n"; #endif for (int i = 0; i < n; i++) { // Check for message start if (buf[i] == '$') { beginMessage(); continue; } // Otherwise, we must be in a sentece to do anything if (!inMessage) continue; // Reached the CRLF at the end? if (buf[i] == '\r') { gotCR = true; continue; } if (buf[i] == '\n') { if (gotCR) { Message msg; msg.message = ¤tMessage; msg.timeParseStarted = currentMessageStarted; HandlerMap::iterator h = myHandlers.find(currentMessage[0]); if (h != myHandlers.end()) { #ifdef DEBUG_ARNMEAPARSER fprintf(stderr, "\t[ArNMEAParser: Got complete message, calling handler for %s...]\n", currentMessage[0].c_str()); #endif h->second->invoke(msg); result |= ParseUpdated; } endMessage(); } // a syntax error or no data, abort the message and start looking for the next one. if(currentField != "") ArLog::log(ArLog::Normal, "ArNMEAParser: Warning: NMEA parse error (currentField=\"%s\"), resetting parser.", currentField.c_str()); endMessage(); continue; } // Are we in the final checksum field? if (inChecksum) { checksumBuf[checksumBufOffset++] = buf[i]; if (checksumBufOffset > 1) // two bytes of checksum { int checksumRec = (int) strtol(checksumBuf, NULL, 16); if (checksumRec != currentChecksum) { ArLog::log(ArLog::Normal, "%s: Warning: Skipping message with incorrect checksum.", myName); std::string nmeaText = ""; for(MessageVector::const_iterator i = currentMessage.begin(); i != currentMessage.end(); ++i) { if(i != currentMessage.begin()) nmeaText += ","; nmeaText += *i; } ArLog::log(ArLog::Normal, "%s: Message provided checksum \"%s\" = 0x%x (%d). Calculated checksum is 0x%x (%d). NMEA message ID was: \"%s\"", myName, checksumBuf, checksumRec, checksumRec, currentChecksum, currentChecksum, nmeaText.c_str()); // abort the message and start looking for the next one. endMessage(); } } continue; } // Got to the checksum? if (buf[i] == '*') { nextField(); if (!ignoreChecksum) beginChecksum(); continue; } // Every byte in a message between $ and * XORs to form the // checksum: currentChecksum ^= buf[i]; // Time to start a new field? if (buf[i] == ',') { nextField(); continue; } // Else, we must be in the middle of a field // TODO we could use strchr to look ahead in the buf // for the end of the field (',' or '*') or end of the buf, and copy more // than one byte at a time. currentField += buf[i]; if (currentField.size() > MaxFieldSize) { endMessage(); continue; } } return result; }