comparison core/OSCClient.cpp @ 270:de37582ce6f3 prerelease

Added OSCServer and OSCClient
author Liam Donovan <l.b.donovan@qmul.ac.uk>
date Tue, 17 May 2016 15:56:18 +0100
parents
children e4392164b458
comparison
equal deleted inserted replaced
260:afdddd5f189f 270:de37582ce6f3
1 /***** OSCClient.cpp *****/
2 #include <OSCClient.h>
3
4 OSCClient::OSCClient(){}
5
6 void OSCClient::sendQueue(void* ptr){
7 OSCClient *instance = (OSCClient*)ptr;
8 instance->queueSend();
9 }
10
11 void OSCClient::setup(int _port, const char* _address, bool scheduleTask){
12 address = _address;
13 port = _port;
14
15 socket.setServer(address);
16 socket.setPort(port);
17
18 if (scheduleTask)
19 createAuxTasks();
20 }
21
22 void OSCClient::createAuxTasks(){
23 char name [30];
24 sprintf (name, "OSCSendTask %i", port);
25 OSCSendTask = BeagleRT_createAuxiliaryTask(sendQueue, BEAGLERT_AUDIO_PRIORITY-5, name, this, true);
26 }
27
28 void OSCClient::queueMessage(oscpkt::Message msg){
29 outQueue.push(msg);
30 }
31
32 void OSCClient::queueSend(){
33 if (!outQueue.empty()){
34 pw.init().startBundle();
35 while(!outQueue.empty()){
36 pw.addMessage(outQueue.front());
37 outQueue.pop();
38 }
39 pw.endBundle();
40 outBuffer = pw.packetData();
41 socket.send(outBuffer, pw.packetSize());
42 }
43 }
44
45 void OSCClient::sendMessageNow(oscpkt::Message msg){
46 pw.init().addMessage(msg);
47 outBuffer = pw.packetData();
48 socket.send(outBuffer, pw.packetSize());
49 }
50
51 // OSCMessageFactory
52 OSCMessageFactory& OSCMessageFactory::to(std::string addr){
53 msg.init(addr);
54 return *this;
55 }
56
57 OSCMessageFactory& OSCMessageFactory::add(std::string in){
58 msg.pushStr(in);
59 return *this;
60 }
61 OSCMessageFactory& OSCMessageFactory::add(int in){
62 msg.pushInt32(in);
63 return *this;
64 }
65 OSCMessageFactory& OSCMessageFactory::add(float in){
66 msg.pushFloat(in);
67 return *this;
68 }
69 OSCMessageFactory& OSCMessageFactory::add(bool in){
70 msg.pushBool(in);
71 return *this;
72 }
73 OSCMessageFactory& OSCMessageFactory::add(void *ptr, int size){
74 msg.pushBlob(ptr, size);
75 return *this;
76 }
77 oscpkt::Message OSCMessageFactory::end(){
78 return msg;
79 }