2 Copyright (C) 2004-2005 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 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 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "JackWinEvent.h"
21 #include "JackError.h"
23 // http://www.codeproject.com/win32/Win32_Event_Handling.asp
24 // http://www.codeproject.com/threads/Synchronization.asp
29 void JackWinEvent::BuildName(const char* name
, char* res
)
31 sprintf(res
, "jack_pipe.%s", name
);
34 bool JackWinEvent::Signal()
42 if (!(res
= SetEvent(fEvent
))) {
43 jack_error("JackWinEvent::Signal name = %s err = %ld", fName
, GetLastError());
49 bool JackWinEvent::SignalAll()
57 if (!(res
= SetEvent(fEvent
))) {
58 jack_error("JackWinEvent::SignalAll name = %s err = %ld", fName
, GetLastError());
64 bool JackWinEvent::Wait()
68 if ((res
= WaitForSingleObject(fEvent
, INFINITE
)) == WAIT_TIMEOUT
) {
69 jack_error("JackWinEvent::TimedWait name = %s time_out", fName
);
72 return (res
== WAIT_OBJECT_0
);
75 bool JackWinEvent::TimedWait(long usec
)
79 if ((res
= WaitForSingleObject(fEvent
, usec
/ 1000)) == WAIT_TIMEOUT
) {
80 jack_error("JackWinEvent::TimedWait name = %s time_out", fName
);
83 return (res
== WAIT_OBJECT_0
);
86 // Client side : get the published semaphore from server
87 bool JackWinEvent::ConnectInput(const char* name
)
89 BuildName(name
, fName
);
90 JackLog("JackWinEvent::Connect %s\n", fName
);
94 JackLog("Already connected name = %s\n", name
);
98 if ((fEvent
= OpenEvent(EVENT_ALL_ACCESS
, FALSE
, fName
)) == NULL
) {
99 jack_error("Connect: can't check in named event name = %s err = %ld", fName
, GetLastError());
106 bool JackWinEvent::Connect(const char* name
)
108 return ConnectInput(name
);
111 bool JackWinEvent::ConnectOutput(const char* name
)
113 return ConnectInput(name
);
116 bool JackWinEvent::Disconnect()
119 JackLog("JackWinEvent::Disconnect %s\n", fName
);
128 bool JackWinEvent::Allocate(const char* name
, int value
)
130 BuildName(name
, fName
);
131 JackLog("JackWinEvent::Allocate name = %s val = %ld\n", fName
, value
);
133 /* create an auto reset event */
134 if ((fEvent
= CreateEvent(NULL
, FALSE
, FALSE
, fName
)) == NULL
) {
135 jack_error("Allocate: can't check in named event name = %s err = %ld", fName
, GetLastError());
142 void JackWinEvent::Destroy()
144 if (fEvent
!= NULL
) {
145 JackLog("JackWinEvent::Destroy %s\n", fName
);
149 jack_error("JackWinEvent::Destroy synchro == NULL");
154 } // end of namespace