class library: SynthDef - lazy implementation of removeUGen
[supercollider.git] / include / lang / SC_ComPort.h
blobe9649ab83f3544d26a5b6b121af64a6419543240
1 /*
2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef _SC_ComPort_
22 #define _SC_ComPort_
24 #ifdef _WIN32
25 # include <winsock2.h>
26 typedef int socklen_t;
27 # define bzero( ptr, count ) memset( ptr, 0, count )
28 #else
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #endif
33 #include "SC_Msg.h"
34 #include "SC_Sem.h"
35 #include "boost/atomic.hpp"
37 //////////////////////////////////////////////////////////////////////////////////////////////////////////
39 class SC_CmdPort
41 protected:
42 pthread_t mThread;
44 void Start();
45 virtual ReplyFunc GetReplyFunc()=0;
46 public:
47 SC_CmdPort();
48 virtual ~SC_CmdPort();
50 virtual void* Run()=0;
53 //////////////////////////////////////////////////////////////////////////////////////////////////////////
55 class SC_ComPort : public SC_CmdPort
57 protected:
58 int mPortNum;
59 int mSocket;
60 struct sockaddr_in mBindSockAddr;
62 public:
63 SC_ComPort(int inPortNum);
64 virtual ~SC_ComPort();
66 int Socket() { return mSocket; }
68 int PortNum() const { return mPortNum; }
69 int RealPortNum() const { return ntohs(mBindSockAddr.sin_port); }
72 //////////////////////////////////////////////////////////////////////////////////////////////////////////
74 class SC_UdpInPort : public SC_ComPort
76 protected:
77 struct sockaddr_in mReplySockAddr;
78 virtual ReplyFunc GetReplyFunc();
80 public:
81 SC_UdpInPort(int inPortNum);
82 ~SC_UdpInPort();
84 int PortNum() const { return mPortNum; }
86 void* Run();
89 //////////////////////////////////////////////////////////////////////////////////////////////////////////
91 class SC_UdpCustomInPort : public SC_ComPort
93 protected:
94 struct sockaddr_in mReplySockAddr;
95 virtual ReplyFunc GetReplyFunc();
96 boost::atomic<bool> mRunning;
98 public:
99 SC_UdpCustomInPort(int inPortNum);
100 ~SC_UdpCustomInPort();
102 int PortNum() const { return mPortNum; }
104 void* Run();
107 //////////////////////////////////////////////////////////////////////////////////////////////////////////
109 class SC_TcpInPort : public SC_ComPort
111 SC_Semaphore mConnectionAvailable;
112 int mBacklog;
114 protected:
115 virtual ReplyFunc GetReplyFunc();
117 public:
118 SC_TcpInPort(int inPortNum, int inMaxConnections, int inBacklog);
120 virtual void* Run();
122 void ConnectionTerminated();
125 //////////////////////////////////////////////////////////////////////////////////////////////////////////
127 class SC_TcpConnectionPort : public SC_ComPort
129 SC_TcpInPort *mParent;
131 protected:
132 virtual ReplyFunc GetReplyFunc();
134 public:
135 SC_TcpConnectionPort(SC_TcpInPort *inParent, int inSocket);
136 virtual ~SC_TcpConnectionPort();
138 virtual void* Run();
141 const int kTextBufSize = 8192;
143 //////////////////////////////////////////////////////////////////////////////////////////////////////////
145 class SC_TcpClientPort : public SC_ComPort
147 public:
148 typedef void (*ClientNotifyFunc)(void* clientData);
150 public:
151 SC_TcpClientPort(int inSocket, ClientNotifyFunc notifyFunc=0, void* clientData=0);
152 virtual ~SC_TcpClientPort();
154 virtual void* Run();
155 void Close();
157 protected:
158 virtual ReplyFunc GetReplyFunc();
160 private:
161 struct sockaddr_in mReplySockAddr;
162 int mCmdFifo[2];
163 ClientNotifyFunc mClientNotifyFunc;
164 void* mClientData;
167 //////////////////////////////////////////////////////////////////////////////////////////////////////////
169 #endif