Adds support for read or write-only midi devices entries.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40419 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -13,6 +13,8 @@
|
|||||||
#include "DeviceWatcher.h"
|
#include "DeviceWatcher.h"
|
||||||
#include "PortDrivers.h"
|
#include "PortDrivers.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
@@ -225,24 +227,40 @@ DeviceWatcher::_AddDevice(const char* path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int fd = open(path, O_RDWR | O_EXCL);
|
int fd = open(path, O_RDWR | O_EXCL);
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
return;
|
if (errno != EACCES)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// maybe it's a input or output only port?
|
||||||
|
fd = open(path, O_RDONLY | O_EXCL);
|
||||||
|
if (fd < 0 && errno == EACCES)
|
||||||
|
fd = open(path, O_WRONLY | O_EXCL);
|
||||||
|
if (fd < 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TRACE(("Doing _AddDevice(\"%s\"); fd=%d\n", path, fd));
|
TRACE(("Doing _AddDevice(\"%s\"); fd=%d\n", path, fd));
|
||||||
|
|
||||||
MidiPortConsumer* consumer = new MidiPortConsumer(fd, path);
|
MidiPortConsumer* consumer = NULL;
|
||||||
_SetIcons(consumer);
|
MidiPortProducer* producer = NULL;
|
||||||
TRACE(("Register %s MidiPortConsumer\n", consumer->Name()));
|
|
||||||
consumer->Register();
|
|
||||||
|
|
||||||
MidiPortProducer* producer = new MidiPortProducer(fd, path);
|
int flags = fcntl(fd, F_GETFL);
|
||||||
_SetIcons(producer);
|
|
||||||
TRACE(("Register %s MidiPortProducer\n", producer->Name()));
|
|
||||||
producer->Register();
|
|
||||||
|
|
||||||
DeviceEndpoints* deviceEndpoints = new DeviceEndpoints(fd, consumer, producer);
|
if ((flags & O_ACCMODE) != O_RDONLY) {
|
||||||
fDeviceEndpointsMap.Put(path, deviceEndpoints);
|
consumer = new MidiPortConsumer(fd, path);
|
||||||
|
_SetIcons(consumer);
|
||||||
|
TRACE(("Register %s MidiPortConsumer\n", consumer->Name()));
|
||||||
|
consumer->Register();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((flags & O_ACCMODE) != O_WRONLY) {
|
||||||
|
producer = new MidiPortProducer(fd, path);
|
||||||
|
_SetIcons(producer);
|
||||||
|
TRACE(("Register %s MidiPortProducer\n", producer->Name()));
|
||||||
|
producer->Register();
|
||||||
|
}
|
||||||
|
|
||||||
|
fDeviceEndpointsMap.Put(path, new DeviceEndpoints(fd, consumer, producer));
|
||||||
TRACE(("Done _AddDevice(\"%s\")\n", path));
|
TRACE(("Done _AddDevice(\"%s\")\n", path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,12 +277,16 @@ DeviceWatcher::_RemoveDevice(const char* path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TRACE((" _RemoveDevice(\"%s\") unregistering\n", path));
|
TRACE((" _RemoveDevice(\"%s\") unregistering\n", path));
|
||||||
deviceEndpoints->fConsumer->Unregister();
|
if (deviceEndpoints->fConsumer)
|
||||||
deviceEndpoints->fProducer->Unregister();
|
deviceEndpoints->fConsumer->Unregister();
|
||||||
|
if (deviceEndpoints->fProducer)
|
||||||
|
deviceEndpoints->fProducer->Unregister();
|
||||||
|
|
||||||
TRACE((" _RemoveDevice(\"%s\") releasing\n", path));
|
TRACE((" _RemoveDevice(\"%s\") releasing\n", path));
|
||||||
deviceEndpoints->fConsumer->Release();
|
if (deviceEndpoints->fConsumer)
|
||||||
deviceEndpoints->fProducer->Release();
|
deviceEndpoints->fConsumer->Release();
|
||||||
|
if (deviceEndpoints->fProducer)
|
||||||
|
deviceEndpoints->fProducer->Release();
|
||||||
|
|
||||||
TRACE((" _RemoveDevice(\"%s\") removing from map\n", path));
|
TRACE((" _RemoveDevice(\"%s\") removing from map\n", path));
|
||||||
fDeviceEndpointsMap.Remove(path);
|
fDeviceEndpointsMap.Remove(path);
|
||||||
|
|||||||
Reference in New Issue
Block a user