26f7ec1a5b259fdd9f5971f709ce3f659aecf5ee
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / architecture / osclib / faust / src / osc / OSCListener.h
1 /*
2
3 Copyright (C) 2011 Grame
4
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.
9
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.
14
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
18
19 Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France
20 research@grame.fr
21
22 */
23
24
25 #ifndef __OSCListener__
26 #define __OSCListener__
27
28 #include "smartpointer.h"
29 #include "MessageProcessor.h"
30
31 // oscpack include files
32 #include "ip/UdpSocket.h"
33 #include "osc/OscPacketListener.h"
34
35 namespace oscfaust
36 {
37
38 //--------------------------------------------------------------------------
39 /*!
40 \brief an OSC listener that converts OSC input to Messages
41
42 OSCListener makes the glue between the oscpack library
43 and the faust lib osc messages representation
44 \see Message in Message.h
45 */
46 class OSCListener : public osc::OscPacketListener, public smartable
47 {
48 UdpListeningReceiveSocket *fSocket; ///< the udp socket listener
49 MessageProcessor * fMsgHandler;
50 bool fRunning;
51 int fPort;
52
53 public:
54 static SMARTP<OSCListener> create(MessageProcessor * mp, int port)
55 { return new OSCListener(mp, port); }
56
57 /*!
58 \brief process OSC messages
59
60 \param m the OSC message (pre-processed by the base class)
61 \param remoteEndpoint the sender IP address
62 */
63 virtual void ProcessMessage( const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint );
64 virtual void run();
65 virtual void stop() { fRunning=false; if (fSocket) fSocket->AsynchronousBreak(); }
66 virtual void setPort(int port) { fPort = port; }
67 virtual void restart(int port) { fPort = port; if (fSocket) fSocket->AsynchronousBreak(); }
68
69 protected:
70 OSCListener(MessageProcessor * mp, int port);
71 virtual ~OSCListener();
72
73 };
74 typedef class SMARTP<OSCListener> SOSCListener;
75
76 } // end namespoace
77
78 #endif