JackSocketNotifyChannel.cpp

00001 /*
00002 Copyright (C) 2004-2008 Grame  
00003   
00004   This program is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU Lesser General Public License as published by
00006   the Free Software Foundation; either version 2.1 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU Lesser General Public License for more details.
00013   
00014   You should have received a copy of the GNU Lesser General Public License
00015   along with this program; if not, write to the Free Software 
00016   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 
00018 */
00019 
00020 #include "JackRequest.h"
00021 #include "JackSocketNotifyChannel.h"
00022 #include "JackError.h"
00023 #include "JackConstants.h"
00024 
00025 namespace Jack
00026 {
00027 
00028 // Server to client
00029 int JackSocketNotifyChannel::Open(const char* name)
00030 {
00031     JackLog("JackSocketNotifyChannel::Open name = %s\n", name);
00032 
00033     // Connect to client listen socket
00034     if (fNotifySocket.Connect(jack_client_dir, name, 0) < 0) {
00035         jack_error("Cannot connect client socket");
00036         return -1;
00037     }
00038     // Use a time out for notifications
00039     fNotifySocket.SetReadTimeOut(SOCKET_TIME_OUT);
00040     return 0;
00041 }
00042 
00043 void JackSocketNotifyChannel::Close()
00044 {
00045     JackLog("JackSocketNotifyChannel::Close\n");
00046     fNotifySocket.Close();
00047 }
00048 
00049 void JackSocketNotifyChannel::ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2, int* result)
00050 {
00051     JackClientNotification event(name, refnum, notify, sync, value1, value2);
00052     JackResult res;
00053 
00054     // Send notification
00055     if (event.Write(&fNotifySocket) < 0) {
00056         jack_error("Could not write notification");
00057         fNotifySocket.Close();
00058         *result = -1;
00059         return;
00060     }
00061 
00062     // Read the result in "synchronous" mode only
00063     if (sync) {
00064         // Get result : use a time out
00065         if (res.Read(&fNotifySocket) < 0) {
00066             jack_error("Could not read result");
00067             fNotifySocket.Close();
00068             *result = -1;
00069         } else {
00070             *result = res.fResult;
00071         }
00072     } else {
00073         *result = 0;
00074     }
00075 }
00076 
00077 } // end of namespace
00078 
00079 

Generated on Thu Feb 14 11:16:02 2008 for Jackdmp by  doxygen 1.5.1