This repository has been archived by the owner on Oct 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
osc.h
96 lines (74 loc) · 2.51 KB
/
osc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef SUMATOR_H
#define SUMATOR_H
#include "reference.h"
#include "include/oscpkt.hh"
class OSCMessage : public Reference {
OBJ_TYPE(OSCMessage,Reference);
private:
oscpkt::Message* message;
protected:
static void _bind_methods();
public:
OSCMessage() { message = new oscpkt::Message(); }
OSCMessage(oscpkt::Message* msg) : message(msg) {}
virtual ~OSCMessage() { delete message; }
void init(const String& s);
void pushBool(bool b);
void pushInt32(int32_t i);
void pushInt64(int64_t h);
void pushFloat(float f);
void pushDouble(double d);
void pushStr(const String& s);
//OSCMessage& pushBlob(void *ptr, size_t num_bytes);
void clear();
oscpkt::Message* getMessage() const;
};
class OSCPacketReader : public Reference {
OBJ_TYPE(OSCPacketReader,Reference);
private:
oscpkt::PacketReader* pr;
protected:
static void _bind_methods();
public:
enum ErrorCode { OK_NO_ERROR=0,
// errors raised by the Message class:
MALFORMED_ADDRESS_PATTERN, MALFORMED_TYPE_TAGS, MALFORMED_ARGUMENTS, UNHANDLED_TYPE_TAGS,
// errors raised by ArgReader
TYPE_MISMATCH, NOT_ENOUGH_ARG, PATTERN_MISMATCH,
// errors raised by PacketReader/PacketWriter
INVALID_BUNDLE, INVALID_PACKET_SIZE, BUNDLE_REQUIRED_FOR_MULTI_MESSAGES } ;
OSCPacketReader() { pr = new oscpkt::PacketReader(); }
//OSCPacketReader(const void *ptr, size_t sz) { pr(ptr, sz); }
virtual ~OSCPacketReader() { delete pr; }
void init(const String& v);
String popMessage();
bool isOk() const;
oscpkt::ErrorCode getErr() const;
};
class OSCPacketWriter : public Reference {
OBJ_TYPE(OSCPacketWriter,Reference);
private:
oscpkt::PacketWriter* pw;
protected:
static void _bind_methods();
public:
enum ErrorCode { OK_NO_ERROR=0,
// errors raised by the Message class:
MALFORMED_ADDRESS_PATTERN, MALFORMED_TYPE_TAGS, MALFORMED_ARGUMENTS, UNHANDLED_TYPE_TAGS,
// errors raised by ArgReader
TYPE_MISMATCH, NOT_ENOUGH_ARG, PATTERN_MISMATCH,
// errors raised by PacketReader/PacketWriter
INVALID_BUNDLE, INVALID_PACKET_SIZE, BUNDLE_REQUIRED_FOR_MULTI_MESSAGES } ;
OSCPacketWriter() { pw = new oscpkt::PacketWriter(); }
virtual ~OSCPacketWriter() { delete pw; }
void init();
void startBundle();
void endBundle();
void addMessage(Ref<OSCMessage> message);
bool isOk();
oscpkt::ErrorCode getErr();
uint32_t packetSize();
char* packetData();
String get_packet_string();
};
#endif