0165c3d42c5ec322e5540e35a146a084d0eeeca3
3 Copyright (C) 2011 Grame
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France
29 #include "OSCStream.h"
30 #include "OSCControler.h"
34 # include "winsock2.h"
36 # include "ip/NetworkingUtils.h"
44 static const char * kHelloMsg
= "hello";
47 //--------------------------------------------------------------------------
49 //--------------------------------------------------------------------------
50 static string
getHostName()
53 int ret
= gethostname(name
, 512);
54 if (ret
== -1) return "";
60 string name
= getHostName();
63 unsigned long ip
= GetHostByName(name
.c_str());
64 ipStr
<< ((ip
>> 24) & 0xff) << '.'
65 << ((ip
>> 16) & 0xff) << '.'
66 << ((ip
>> 8) & 0xff) << '.'
72 //--------------------------------------------------------------------------
73 // signal data handler
74 //--------------------------------------------------------------------------
75 bool RootNode::acceptSignal( const Message
* msg
)
80 float val
, * buff
= new float[n
];
81 for (int i
= 0; i
< n
; i
++) {
82 if (msg
->param(i
, val
)) // assumes that it receives float values only
85 ret
= false; // set return code to false
86 break; // and stops reading data
89 if (ret
) fIO
->receive (n
, buff
); // call the IO controler receive method with the float data
96 //--------------------------------------------------------------------------
97 bool RootNode::accept( const Message
* msg
)
100 // checks for the 'hello' message first
101 if ((msg
->size() == 1) && (msg
->param(0, val
)) && (val
== kHelloMsg
) ) {
105 else if (MessageDriven::accept (msg
)) // next checks for standard handlers ('get' for example)
107 else if (fIO
) // when still not handled and if a IO controler is set
108 return acceptSignal (msg
); // try to read signal data
112 //--------------------------------------------------------------------------
113 void RootNode::setPorts (int* in
, int* out
, int* err
)
120 //--------------------------------------------------------------------------
121 void RootNode::hello (unsigned long ipdest
) const
123 if (fUPDIn
&& fUDPOut
&& fUDPErr
) { // on 'hello' request
124 unsigned long savedip
= oscout
.getAddress(); // saves the current dest IP
125 oscout
.setAddress(ipdest
); // set the destination IP
126 // and sends its address + the udp port numbers (in, out and err)
127 oscout
<< OSCStart(getOSCAddress().c_str()) << getIP() << *fUPDIn
<< *fUDPOut
<< *fUDPErr
<< OSCEnd();
128 oscout
.setAddress(savedip
); // and restores the dest IP