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:
Philippe Houdoin
2011-02-10 13:19:22 +00:00
parent 443a3c5991
commit 3db9c51d0f
+27 -5
View File
@@ -13,6 +13,8 @@
#include "DeviceWatcher.h"
#include "PortDrivers.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <new>
@@ -225,24 +227,40 @@ DeviceWatcher::_AddDevice(const char* path)
}
int fd = open(path, O_RDWR | O_EXCL);
if (fd < 0)
if (fd < 0) {
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));
MidiPortConsumer* consumer = new MidiPortConsumer(fd, path);
MidiPortConsumer* consumer = NULL;
MidiPortProducer* producer = NULL;
int flags = fcntl(fd, F_GETFL);
if ((flags & O_ACCMODE) != O_RDONLY) {
consumer = new MidiPortConsumer(fd, path);
_SetIcons(consumer);
TRACE(("Register %s MidiPortConsumer\n", consumer->Name()));
consumer->Register();
}
MidiPortProducer* producer = new MidiPortProducer(fd, path);
if ((flags & O_ACCMODE) != O_WRONLY) {
producer = new MidiPortProducer(fd, path);
_SetIcons(producer);
TRACE(("Register %s MidiPortProducer\n", producer->Name()));
producer->Register();
}
DeviceEndpoints* deviceEndpoints = new DeviceEndpoints(fd, consumer, producer);
fDeviceEndpointsMap.Put(path, deviceEndpoints);
fDeviceEndpointsMap.Put(path, new DeviceEndpoints(fd, consumer, producer));
TRACE(("Done _AddDevice(\"%s\")\n", path));
}
@@ -259,11 +277,15 @@ DeviceWatcher::_RemoveDevice(const char* path)
}
TRACE((" _RemoveDevice(\"%s\") unregistering\n", path));
if (deviceEndpoints->fConsumer)
deviceEndpoints->fConsumer->Unregister();
if (deviceEndpoints->fProducer)
deviceEndpoints->fProducer->Unregister();
TRACE((" _RemoveDevice(\"%s\") releasing\n", path));
if (deviceEndpoints->fConsumer)
deviceEndpoints->fConsumer->Release();
if (deviceEndpoints->fProducer)
deviceEndpoints->fProducer->Release();
TRACE((" _RemoveDevice(\"%s\") removing from map\n", path));