diff include/OSCClient.h @ 278:3c3d042dad12 prerelease

merge
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 17 May 2016 16:07:45 +0100
parents de37582ce6f3
children e4392164b458
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/OSCClient.h	Tue May 17 16:07:45 2016 +0100
@@ -0,0 +1,61 @@
+/***** OSCClient.h *****/
+#ifndef __OSCClient_H_INCLUDED__
+#define __OSCClient_H_INCLUDED__ 
+
+#include <UdpClient.h>
+#include <BeagleRT.h>
+#include <oscpkt.hh>
+#include <queue>
+
+class OSCMessageFactory{
+    public:
+        OSCMessageFactory& to(std::string);
+        OSCMessageFactory& add(std::string);
+        OSCMessageFactory& add(int);
+        OSCMessageFactory& add(float);
+        OSCMessageFactory& add(bool);
+        OSCMessageFactory& add(void *ptr, int size);
+        oscpkt::Message end();
+    private:
+        oscpkt::Message msg;
+};
+
+class OSCClient{
+    public:
+        OSCClient();
+        
+        // must be called once during setup
+        void setup(int port, const char* address="127.0.0.1", bool scheduleTask = true);
+        
+        // queue a message to be sent during the next aux task OSCSendTask
+        // audio-thread safe
+        void queueMessage(oscpkt::Message);
+        
+        // send a mesage immediately
+        // *** do not use on audio thread! ***
+        // to be used during setup
+        void sendMessageNow(oscpkt::Message);
+        
+        // allows new OSC messages to be created
+        // audio-thread safe
+        // usage: oscClient.queueMessage(oscClient.newMessage.to("/address").add(param).end());
+        OSCMessageFactory newMessage;
+        
+    private:
+        const char* address;
+        int port;
+        
+        UdpClient socket;
+        AuxiliaryTask OSCSendTask;
+        std::queue<oscpkt::Message> outQueue;
+        oscpkt::PacketWriter pw;
+        char* outBuffer;
+        
+        static void sendQueue(void*);
+        
+        void createAuxTasks();
+        void queueSend();
+        
+};
+
+#endif
\ No newline at end of file