JackWinNamedPipeServerChannel.h 2.82 KB
Newer Older
sletz's avatar
sletz committed
1
/*
2
 Copyright (C) 2004-2008 Grame
sletz's avatar
sletz committed
3

4
5
6
7
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation; either version 2.1 of the License, or
 (at your option) any later version.
sletz's avatar
sletz committed
8

9
10
11
12
 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 Lesser General Public License for more details.
sletz's avatar
sletz committed
13

14
15
16
 You should have received a copy of the GNU Lesser General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
sletz's avatar
sletz committed
17

18
 */
sletz's avatar
sletz committed
19

sletz's avatar
sletz committed
20
21
22
23
24

#ifndef __JackWinNamedPipeServerChannel__
#define __JackWinNamedPipeServerChannel__

#include "JackWinNamedPipe.h"
25
#include "JackPlatformPlug.h"
sletz's avatar
sletz committed
26
#include "JackConstants.h"
sletz's avatar
sletz committed
27
28
29
30
31
#include <list>

namespace Jack
{

sletz's avatar
sletz committed
32
33
class JackServer;

sletz's avatar
sletz committed
34
35
36
37
38
39
40
class JackClientPipeThread : public JackRunnableInterface
{

    private:

        JackWinNamedPipeClient* fPipe;
        JackServer*	fServer;
41
        JackThread fThread;
sletz's avatar
sletz committed
42
43
        int fRefNum;

sletz's avatar
sletz committed
44
        void ClientAdd(char* name, int pid, int uuid, int* shared_engine, int* shared_client, int* shared_graph, int* result);
45
46
        void ClientRemove();
        void ClientKill();
sletz's avatar
sletz committed
47
48
49
50
51
52
53
54

        static HANDLE fMutex;

    public:

        JackClientPipeThread(JackWinNamedPipeClient* pipe);
        virtual ~JackClientPipeThread();

55
56
        int Open(JackServer* server);   // Open the Server/Client connection
        void Close();                   // Close the Server/Client connection
sletz's avatar
sletz committed
57

sletz's avatar
Cleanup    
sletz committed
58
        bool HandleRequest();
sletz's avatar
sletz committed
59
60
61

        // JackRunnableInterface interface
        bool Execute();
sletz's avatar
sletz committed
62

sletz's avatar
sletz committed
63
        // To be used for find out if the object can be deleted
sletz's avatar
sletz committed
64
65
        bool IsRunning()
        {
sletz's avatar
sletz committed
66
            return (fRefNum >= 0);
sletz's avatar
sletz committed
67
68
69
70
71
72
73
        }
};

/*!
\brief JackServerChannel using pipe.
*/

74
class JackWinNamedPipeServerChannel : public JackRunnableInterface
sletz's avatar
sletz committed
75
76
77
78
79
80
{

    private:

        JackWinNamedPipeServer fRequestListenPipe;	// Pipe to create request socket for the client
        JackServer*	fServer;
81
        JackThread fThread;                         // Thread to execute the event loop
sletz's avatar
sletz committed
82
        char fServerName[JACK_SERVER_CONTROL_NAME_SIZE];
sletz's avatar
sletz committed
83
84
85

        std::list<JackClientPipeThread*> fClientList;

86
        void ClientAdd(JackWinNamedPipeClient* pipe);
sletz's avatar
sletz committed
87
88
89
90

    public:

        JackWinNamedPipeServerChannel();
91
        ~JackWinNamedPipeServerChannel();
sletz's avatar
sletz committed
92

sletz's avatar
sletz committed
93
94
        int Open(const char* server_name, JackServer* server);  // Open the Server/Client connection
        void Close();                                           // Close the Server/Client connection
sletz's avatar
sletz committed
95

sletz's avatar
sletz committed
96
        int Start();
sletz's avatar
sletz committed
97
        void Stop();
sletz's avatar
sletz committed
98
99
100
101
102
103
104
105
106
107
108

        // JackRunnableInterface interface
        bool Init();
        bool Execute();
};


} // end of namespace

#endif