JackSocketServerNotifyChannel.cpp 2.09 KB
Newer Older
sletz's avatar
sletz committed
1
/*
sletz's avatar
sletz committed
2
Copyright (C) 2004-2008 Grame
sletz's avatar
sletz committed
3
4

This program is free software; you can redistribute it and/or modify
sletz's avatar
sletz committed
5
6
7
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

sletz's avatar
sletz committed
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

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

*/

#include "JackSocketServerNotifyChannel.h"
#include "JackError.h"
#include "JackRequest.h"
#include "JackConstants.h"
24
#include "JackNotification.h"
25
#include "JackServerGlobals.h"
sletz's avatar
sletz committed
26
27
28
29

namespace Jack
{

30
int JackSocketServerNotifyChannel::Open(const char* server_name)
sletz's avatar
sletz committed
31
{
32
    if (fRequestSocket.Connect(jack_server_dir, server_name, 0) < 0) {
sletz's avatar
sletz committed
33
34
35
        jack_error("Cannot connect to server socket");
        return -1;
    } else {
sletz's avatar
sletz committed
36
        fRequestSocket.SetNonBlocking(true);
37
        JackServerGlobals::fRTNotificationSocket = fRequestSocket.GetFd();
sletz's avatar
sletz committed
38
39
40
41
42
43
44
45
46
47
        return 0;
    }
}

void JackSocketServerNotifyChannel::Close()
{
    fRequestSocket.Close();
}

/*
sletz's avatar
sletz committed
48
49
50
The requirement is that the Notification from RT thread can be delivered... not sure using a socket is adequate here...
Can the write operation block?
A non blocking write operation shoud be used : check if write can succeed, and ignore the notification otherwise
sletz's avatar
sletz committed
51
52
(since its mainly used for XRun, ignoring a notification is OK, successive XRun will come...)
*/
sletz's avatar
sletz committed
53
void JackSocketServerNotifyChannel::Notify(int refnum, int notify, int value)
sletz's avatar
sletz committed
54
55
56
{
    JackClientNotificationRequest req(refnum, notify, value);
    if (req.Write(&fRequestSocket) < 0) {
sletz's avatar
sletz committed
57
        jack_error("Could not write notification ref = %d notify = %d", refnum, notify);
sletz's avatar
sletz committed
58
59
60
    }
}

61
62
void JackSocketServerNotifyChannel::NotifyQuit()
{
sletz's avatar
sletz committed
63
    Notify(-1, kQUIT, 0);
64
}
65

sletz's avatar
sletz committed
66
67
68
} // end of namespace