Add octave scripts for examples into track list.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / architecture / osclib / oscpack / examples / SimpleReceive.cpp
1 /*
2 Example of two different ways to process received OSC messages using oscpack.
3 Receives the messages from the SimpleSend.cpp example.
4 */
5
6 #include <string.h>
7 #include <iostream>
8
9 #include "osc/OscReceivedElements.h"
10 #include "osc/OscPacketListener.h"
11 #include "ip/UdpSocket.h"
12
13
14 #define PORT 7000
15
16 class ExamplePacketListener : public osc::OscPacketListener {
17 protected:
18
19 virtual void ProcessMessage( const osc::ReceivedMessage& m,
20 const IpEndpointName& remoteEndpoint )
21 {
22 try{
23 // example of parsing single messages. osc::OsckPacketListener
24 // handles the bundle traversal.
25
26 if( strcmp( m.AddressPattern(), "/test1" ) == 0 ){
27 // example #1 -- argument stream interface
28 osc::ReceivedMessageArgumentStream args = m.ArgumentStream();
29 bool a1;
30 osc::int32 a2;
31 float a3;
32 const char *a4;
33 args >> a1 >> a2 >> a3 >> a4 >> osc::EndMessage;
34
35 std::cout << "received '/test1' message with arguments: "
36 << a1 << " " << a2 << " " << a3 << " " << a4 << "\n";
37
38 }else if( strcmp( m.AddressPattern(), "/test2" ) == 0 ){
39 // example #2 -- argument iterator interface, supports
40 // reflection for overloaded messages (eg you can call
41 // (*arg)->IsBool() to check if a bool was passed etc).
42 osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin();
43 bool a1 = (arg++)->AsBool();
44 int a2 = (arg++)->AsInt32();
45 float a3 = (arg++)->AsFloat();
46 const char *a4 = (arg++)->AsString();
47 if( arg != m.ArgumentsEnd() )
48 throw osc::ExcessArgumentException();
49
50 std::cout << "received '/test2' message with arguments: "
51 << a1 << " " << a2 << " " << a3 << " " << a4 << "\n";
52 }
53 }catch( osc::Exception& e ){
54 // any parsing errors such as unexpected argument types, or
55 // missing arguments get thrown as exceptions.
56 std::cout << "error while parsing message: "
57 << m.AddressPattern() << ": " << e.what() << "\n";
58 }
59 }
60 };
61
62 int main(int argc, char* argv[])
63 {
64 ExamplePacketListener listener;
65 UdpListeningReceiveSocket s(
66 IpEndpointName( IpEndpointName::ANY_ADDRESS, PORT ),
67 &listener );
68
69 std::cout << "press ctrl-c to end\n";
70
71 s.RunUntilSigInt();
72
73 return 0;
74 }
75