Browse Source

Add JackWinSemaphore class.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1699 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/0.68
sletz 18 years ago
parent
commit
142fb9792c
4 changed files with 229 additions and 3 deletions
  1. +3
    -2
      ChangeLog
  2. +1
    -1
      windows/JackWinEvent.h
  3. +156
    -0
      windows/JackWinSemaphore.cpp
  4. +69
    -0
      windows/JackWinSemaphore.h

+ 3
- 2
ChangeLog View File

@@ -14,11 +14,12 @@ Andrzej Szombierski
Jackdmp changes log
---------------------------

2007-11-01 Stephane Letz <letz@grame.fr>
2007-11-02 Stephane Letz <letz@grame.fr>

* Correct ALSA driver Attach method: internal driver may have changed the buffer_size and sample_rate values.
* Add JackWinSemaphore class.

2007-10-31 Stephane Letz <letz@grame.fr>
2007-10-01 Stephane Letz <letz@grame.fr>

* Server and user directory related code moved in a JackTools file.
* Client name rewritting to remove path characters (used in fifo naming).


+ 1
- 1
windows/JackWinEvent.h View File

@@ -31,7 +31,7 @@ namespace Jack
//http://bob.developpez.com/tutapiwin/article_56.php

/*!
\brief Inter process synchronization using system wide events.
\brief Inter process synchronization using system wide events.
*/

class JackWinEvent : public JackSynchro


+ 156
- 0
windows/JackWinSemaphore.cpp View File

@@ -0,0 +1,156 @@
/*
Copyright (C) 2004-2005 Grame

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include "JackWinSemaphore.h"
#include "JackError.h"

namespace Jack
{

void JackWinSemaphore::BuildName(const char* name, const char* server_name, char* res)
{
sprintf(res, "jack_pipe.%s_%s", server_name, name);
}

bool JackWinSemaphore::Signal()
{
BOOL res;
assert(fSemaphore);

if (fFlush)
return true;
if (!(res = ReleaseSemaphore(fSemaphore, 1, NULL))) {
jack_error("JackWinSemaphore::Signal name = %s err = %ld", fName, GetLastError());
}
return res;
}

bool JackWinSemaphore::SignalAll()
{
BOOL res;
assert(fSemaphore);

if (fFlush)
return true;

if (!(res = ReleaseSemaphore(fSemaphore, 1, NULL))) {
jack_error("JackWinSemaphore::SignalAll name = %s err = %ld", fName, GetLastError());
}
return res;
}

bool JackWinSemaphore::Wait()
{
DWORD res;

if ((res = WaitForSingleObject(fSemaphore, INFINITE)) == WAIT_TIMEOUT) {
jack_error("JackWinSemaphore::TimedWait name = %s time_out", fName);
}

return (res == WAIT_OBJECT_0);
}

bool JackWinSemaphore::TimedWait(long usec)
{
DWORD res;

if ((res = WaitForSingleObject(fSemaphore, usec / 1000)) == WAIT_TIMEOUT) {
jack_error("JackWinSemaphore::TimedWait name = %s time_out", fName);
}

return (res == WAIT_OBJECT_0);
}

// Client side : get the published semaphore from server
bool JackWinSemaphore::ConnectInput(const char* name, const char* server_name)
{
BuildName(name, server_name, fName);
JackLog("JackWinSemaphore::Connect %s\n", fName);

// Temporary...
if (fSemaphore) {
JackLog("Already connected name = %s\n", name);
return true;
}

if ((fSemaphore = OpenSemaphore(SEMAPHORE_ALL_ACCESS , FALSE, fName)) == NULL) {
jack_error("Connect: can't check in named event name = %s err = %ld", fName, GetLastError());
return false;
} else {
return true;
}
}

bool JackWinSemaphore::Connect(const char* name, const char* server_name)
{
return ConnectInput(name, server_name);
}

bool JackWinSemaphore::ConnectOutput(const char* name, const char* server_name)
{
return ConnectInput(name, server_name);
}

bool JackWinSemaphore::Disconnect()
{
if (fSemaphore) {
JackLog("JackWinSemaphore::Disconnect %s\n", fName);
CloseHandle(fSemaphore);
fSemaphore = NULL;
return true;
} else {
return false;
}
}

bool JackWinSemaphore::Allocate(const char* name, const char* server_name, int value)
{
BuildName(name, server_name, fName);
JackLog("JackWinSemaphore::Allocate name = %s val = %ld\n", fName, value);

if ((fSemaphore = CreateSemaphore(NULL, value, 32767, fName)) == NULL) {
jack_error("Allocate: can't check in named event name = %s err = %ld", fName, GetLastError());
return false;
} else if (GetLastError() == ERROR_ALREADY_EXISTS) {
jack_error("Allocate: named semaphore already exist name = %s", fName);
CloseHandle(fSemaphore);
fSemaphore = NULL;
return false;
} else {
return true;
}
}

void JackWinSemaphore::Destroy()
{
if (fSemaphore != NULL) {
JackLog("JackWinSemaphore::Destroy %s\n", fName);
CloseHandle(fSemaphore);
fSemaphore = NULL;
} else {
jack_error("JackWinSemaphore::Destroy synchro == NULL");
}
}


} // end of namespace


+ 69
- 0
windows/JackWinSemaphore.h View File

@@ -0,0 +1,69 @@
/*
Copyright (C) 2004-2005 Grame

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __JackWinSemaphore__
#define __JackWinSemaphore__

#include "JackSynchro.h"
#include <windows.h>
#include <stdio.h>
#include <assert.h>

namespace Jack
{

/*!
\brief Inter process synchronization using system wide semaphore.
*/

class JackWinSemaphore : public JackSynchro
{

private:

HANDLE fSemaphore;

protected:

void BuildName(const char* name, const char* server_name, char* res);

public:

JackWinSemaphore(): JackSynchro(), fSemaphore(NULL)
{}
virtual ~JackWinSemaphore()
{}

bool Signal();
bool SignalAll();
bool Wait();
bool TimedWait(long usec);

bool Allocate(const char* name, const char* server_name, int value);
bool Connect(const char* name, const char* server_name);
bool ConnectInput(const char* name, const char* server_name);
bool ConnectOutput(const char* name, const char* server_name);
bool Disconnect();
void Destroy();
};

} // end of namespace

#endif


Loading…
Cancel
Save