Jack2  1.9.12
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  return 0;
38  }
39 }
40 
41 void JackSocketServerNotifyChannel::Close()
42 {
43  fRequestSocket.Close();
44 }
45 
46 /*
47 The requirement is that the Notification from RT thread can be delivered... not sure using a socket is adequate here...
48 Can the write operation block?
49 A non blocking write operation shoud be used : check if write can succeed, and ignore the notification otherwise
50 (since its mainly used for XRun, ignoring a notification is OK, successive XRun will come...)
51 */
52 void JackSocketServerNotifyChannel::Notify(int refnum, int notify, int value)
53 {
54  JackClientNotificationRequest req(refnum, notify, value);
55  if (req.Write(&fRequestSocket) < 0) {
56  jack_error("Could not write notification ref = %d notify = %d", refnum, notify);
57  }
58 }
59 
60 void JackSocketServerNotifyChannel::NotifyQuit()
61 {
62  Notify(-1, kQUIT, 0);
63 }
64 
65 } // end of namespace
66 
67