Merge pull request #23 from jackaudio/device_reservation_fixes
[jack2.git] / posix / JackSocketServerNotifyChannel.cpp
blob5f4b6032d4490004a78ad24492c2ae9c93b5b8d3
1 /*
2 Copyright (C) 2004-2008 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
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
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "JackSocketServerNotifyChannel.h"
21 #include "JackError.h"
22 #include "JackRequest.h"
23 #include "JackConstants.h"
24 #include "JackNotification.h"
25 #include "JackServerGlobals.h"
27 namespace Jack
30 int JackSocketServerNotifyChannel::Open(const char* server_name)
32 if (fRequestSocket.Connect(jack_server_dir, server_name, 0) < 0) {
33 jack_error("Cannot connect to server socket");
34 return -1;
35 } else {
36 fRequestSocket.SetNonBlocking(true);
37 JackServerGlobals::fRTNotificationSocket = fRequestSocket.GetFd();
38 return 0;
42 void JackSocketServerNotifyChannel::Close()
44 fRequestSocket.Close();
48 The requirement is that the Notification from RT thread can be delivered... not sure using a socket is adequate here...
49 Can the write operation block?
50 A non blocking write operation shoud be used : check if write can succeed, and ignore the notification otherwise
51 (since its mainly used for XRun, ignoring a notification is OK, successive XRun will come...)
53 void JackSocketServerNotifyChannel::Notify(int refnum, int notify, int value)
55 JackClientNotificationRequest req(refnum, notify, value);
56 if (req.Write(&fRequestSocket) < 0) {
57 jack_error("Could not write notification ref = %d notify = %d", refnum, notify);
61 void JackSocketServerNotifyChannel::NotifyQuit()
63 Notify(-1, kQUIT, 0);
66 } // end of namespace