Jack2  1.9.9
JackSocketServerNotifyChannel.cpp
1 /*
2 Copyright (C) 2004-2008 Grame
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #include "JackSocketServerNotifyChannel.h"
21 #include "JackError.h"
22 #include "JackRequest.h"
23 #include "JackConstants.h"
24 #include "JackNotification.h"
25 #include "JackServerGlobals.h"
26 
27 namespace Jack
28 {
29 
30 int JackSocketServerNotifyChannel::Open(const char* server_name)
31 {
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;
39  }
40 }
41 
42 void JackSocketServerNotifyChannel::Close()
43 {
44  fRequestSocket.Close();
45 }
46 
47 /*
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...)
52 */
53 void JackSocketServerNotifyChannel::Notify(int refnum, int notify, int value)
54 {
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);
58  }
59 }
60 
61 void JackSocketServerNotifyChannel::NotifyQuit()
62 {
63  Notify(-1, kQUIT, 0);
64 }
65 
66 } // end of namespace
67 
68 
SERVER_EXPORT void jack_error(const char *fmt,...)
Definition: JackError.cpp:91