JackNetInterface.h 4.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2008 Romain Moret at Grame

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __JackNetInterface__
#define __JackNetInterface__

#include "JackNetTool.h"

namespace Jack
{
    /**
    \Brief This class describes the basic Net Interface, used by both master and slave
    */

    class EXPORT JackNetInterface
    {
moret's avatar
moret committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
        protected:
            session_params_t fParams;
            JackNetSocket fSocket;
            char* fMulticastIP;
            uint fNSubProcess;

            //headers
            packet_header_t fTxHeader;
            packet_header_t fRxHeader;

            //network buffers
            char* fTxBuffer;
            char* fRxBuffer;
            char* fTxData;
            char* fRxData;

            //jack buffers
            NetMidiBuffer* fNetMidiCaptureBuffer;
            NetMidiBuffer* fNetMidiPlaybackBuffer;
            NetAudioBuffer* fNetAudioCaptureBuffer;
            NetAudioBuffer* fNetAudioPlaybackBuffer;

            //sizes
            int fAudioRxLen;
            int fAudioTxLen;
            int fPayloadSize;

moret's avatar
moret committed
61
62
63
64
65
            //utility methods
            jack_nframes_t SetFramesPerPacket();
            int SetNetBufferSize();
            int GetNMidiPckt();
            bool IsNextPacket();
moret's avatar
moret committed
66
67

            //virtual methods : depends on the sub class master/slave
moret's avatar
moret committed
68
            virtual void SetParams();
moret's avatar
moret committed
69
70
71
72
73
74
75
76
77
78
79
80
            virtual bool Init() = 0;

            virtual int SyncRecv() = 0;
            virtual int SyncSend() = 0;
            virtual int DataRecv() = 0;
            virtual int DataSend() = 0;

            virtual int Send ( size_t size, int flags ) = 0;
            virtual int Recv ( size_t size, int flags ) = 0;

            JackNetInterface()
            {}
moret's avatar
moret committed
81
            JackNetInterface ( const char* multicast_ip, int port );
moret's avatar
moret committed
82
            JackNetInterface ( session_params_t& params, JackNetSocket& socket, const char* multicast_ip );
moret's avatar
moret committed
83
84
85

        public:
            virtual ~JackNetInterface();
86
87
88
    };

    /**
moret's avatar
moret committed
89
    \Brief This class describes the Net Interface for masters (NetMaster)
90
91
    */

moret's avatar
moret committed
92
    class EXPORT JackNetMasterInterface : public JackNetInterface
93
    {
moret's avatar
moret committed
94
        protected:
moret's avatar
moret committed
95
96
            bool fRunning;

moret's avatar
moret committed
97
            bool Init();
moret's avatar
moret committed
98
            int SetRxTimeout();
moret's avatar
moret committed
99
            void SetParams();
moret's avatar
moret committed
100
            void Exit();
moret's avatar
moret committed
101
102
103
104
105
106
            int SyncRecv();
            int SyncSend();
            int DataRecv();
            int DataSend();

            int Send ( size_t size, int flags );
moret's avatar
moret committed
107
            int Recv ( size_t size, int flags );
moret's avatar
moret committed
108
109

        public:
moret's avatar
moret committed
110
            JackNetMasterInterface() : fRunning ( false )
moret's avatar
moret committed
111
            {}
moret's avatar
moret committed
112
113
114
115
            JackNetMasterInterface ( session_params_t& params, JackNetSocket& socket, const char* multicast_ip )
                    : JackNetInterface ( params, socket, multicast_ip )
            {}
            ~JackNetMasterInterface()
moret's avatar
moret committed
116
            {}
117
118
119
    };

    /**
moret's avatar
moret committed
120
    \Brief This class describes the Net Interface for slaves (NetDriver and NetAdapter)
121
122
    */

moret's avatar
moret committed
123
    class EXPORT JackNetSlaveInterface : public JackNetInterface
124
    {
moret's avatar
moret committed
125
126
        protected:
            bool Init();
moret's avatar
moret committed
127
            net_status_t GetNetMaster();
moret's avatar
moret committed
128
            net_status_t SendStartToMaster();
moret's avatar
moret committed
129
130
131
132
133
134
135
            void SetParams();
            int SyncRecv();
            int SyncSend();
            int DataRecv();
            int DataSend();

            int Recv ( size_t size, int flags );
moret's avatar
moret committed
136
            int Send ( size_t size, int flags );
moret's avatar
moret committed
137
138

        public:
moret's avatar
moret committed
139
            JackNetSlaveInterface()
moret's avatar
moret committed
140
            {}
moret's avatar
moret committed
141
            JackNetSlaveInterface ( const char* ip, int port ) : JackNetInterface ( ip, port )
moret's avatar
moret committed
142
            {}
moret's avatar
moret committed
143
144
145
146
            ~JackNetSlaveInterface()
            {
                SocketAPIEnd();
            }
147
148
149
150
    };
}

#endif