Jamoma API  0.6.0.a19
TTNetReceive.cpp
1 /*
2  * Jamoma Network Receiver
3  * Copyright © 2010, Tim Place
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #include "TTNetReceive.h"
10 
11 #define thisTTClass TTNetReceive
12 #define thisTTClassName "net.receive"
13 #define thisTTClassTags "network, receive"
14 
15 
17 mPort(0),
18 mMode(kTTSymEmpty),
19 mSocket(NULL)
20 {
23 
24  // callback from mSocket
25  addMessageWithArguments(networkSocketReceive);
26  addMessageProperty(networkSocketReceive, hidden, YES);
27 }
28 
29 
30 TTNetReceive::~TTNetReceive()
31 {
32  ;
33 }
34 
35 
36 void TTNetReceive::bind()
37 {
38  if (mPort && mMode && (mMode != kTTSymEmpty)) {
39  char portAsCString[8];
40  TTString address = "";
41 
42  snprintf(portAsCString, 8, "%i", mPort);
43  delete mSocket;
44  mSocket = new TTNetSocket(this, address, TTString(portAsCString), mMode);
45  }
46 }
47 
48 
50 {
51  TTUInt16 newPort = newValue;
52  TTErr err = kTTErrNone;
53 
54  if (mPort != newPort) {
55  mPort = newPort;
56  bind();
57  }
58  return err;
59 }
60 
61 
63 {
64  TTSymbol newMode = newValue;
65  TTErr err = kTTErrNone;
66 
67  if (mMode != newMode) {
68  mMode = newMode;
69  bind();
70  }
71  return err;
72 }
73 
74 
76 {
77  this->sendNotification(TTSymbol("receivedMessage"), message);
78  return kTTErrNone;
79 }
80 
TTSymbol mMode
"tcp" or "udp"
Definition: TTNetReceive.h:23
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTErr setMode(const TTValue &value)
Setter.
TTErr sendNotification(const TTSymbol name, const TTValue &arguments)
Send a notification.
Symbol type.
Definition: TTBase.h:282
16-bit unsigned integer, range is 0 through 65,535.
Definition: TTBase.h:276
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
TTErr networkSocketReceive(const TTValue &message, TTValue &unusedOutput)
Callback from socket receive.
No Error.
Definition: TTBase.h:343
TTErr setPort(const TTValue &value)
Setter.
The TTString class is used to represent a string.
Definition: TTString.h:34
TT_OBJECT_CONSTRUCTOR
Constructor macro.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTUInt16 mPort
port number
Definition: TTNetReceive.h:22
#define addMessageProperty(messageName, propertyName, initialValue)
A convenience macro to be used for registering properties of messages.
Definition: TTMessage.h:37