Jamoma API  0.6.0.a19
TTNetSend.cpp
1 /*
2  * Jamoma Network Sender
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 "TTNetSend.h"
10 
11 #define thisTTClass TTNetSend
12 #define thisTTClassName "net.send"
13 #define thisTTClassTags "network, send"
14 
15 
17 mAddress(kTTSymEmpty),
18 mPort(0),
19 mMode(kTTSymEmpty),
20 mSocket(NULL)
21 {
25 
27 }
28 
29 
30 TTNetSend::~TTNetSend()
31 {
32  ;
33 }
34 
35 
36 void TTNetSend::connect()
37 {
38  if (mAddress && mPort && mMode && (mAddress != kTTSymEmpty) && (mMode != kTTSymEmpty)) {
39  char portAsCString[8];
40 
41  snprintf(portAsCString, 8, "%i", mPort);
42  delete mSocket;
43  mSocket = new TTNetSocket(this, mAddress.c_str(), TTString(portAsCString), mMode);
44  }
45 }
46 
47 
48 TTErr TTNetSend::setAddress(const TTValue& newValue)
49 {
50  TTSymbol newAddress = newValue;
51  TTErr err = kTTErrNone;
52 
53  if (mAddress != newAddress) {
54  mAddress = newAddress;
55  connect();
56  }
57  return err;
58 }
59 
60 
61 TTErr TTNetSend::setPort(const TTValue& newValue)
62 {
63  TTUInt16 newPort = newValue;
64  TTErr err = kTTErrNone;
65 
66  if (mPort != newPort) {
67  mPort = newPort;
68  connect();
69  }
70  return err;
71 }
72 
73 
74 TTErr TTNetSend::setMode(const TTValue& newValue)
75 {
76  TTSymbol newMode = newValue;
77  TTErr err = kTTErrNone;
78 
79  if (mMode != newMode) {
80  mMode = newMode;
81  connect();
82  }
83  return err;
84 }
85 
86 
87 TTErr TTNetSend::send(const TTValue& arguments, TTValue& unusedOutput)
88 {
89  if (mSocket) {
90  TTValue message = arguments;
91 
92  message.toString();
93  return mSocket->Send(message);
94  }
95  else
96  return kTTErrGeneric;
97 }
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTString toString(TTBoolean quotes=YES) const
Return the content as a single string with spaces between elements.
Definition: TTValue.h:351
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
const char * c_str() const
Return a pointer to the internal string as a C-string.
Definition: TTSymbol.h:77
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
Definition: TTBase.h:344
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
No Error.
Definition: TTBase.h:343
The TTString class is used to represent a string.
Definition: TTString.h:34
TT_OBJECT_CONSTRUCTOR
Constructor macro.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34