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 "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) {
if (errno != EACCES)
return; 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;
MidiPortProducer* producer = NULL;
int flags = fcntl(fd, F_GETFL);
if ((flags & O_ACCMODE) != O_RDONLY) {
consumer = new MidiPortConsumer(fd, path);
_SetIcons(consumer); _SetIcons(consumer);
TRACE(("Register %s MidiPortConsumer\n", consumer->Name())); TRACE(("Register %s MidiPortConsumer\n", consumer->Name()));
consumer->Register(); consumer->Register();
}
MidiPortProducer* producer = new MidiPortProducer(fd, path); if ((flags & O_ACCMODE) != O_WRONLY) {
producer = new MidiPortProducer(fd, path);
_SetIcons(producer); _SetIcons(producer);
TRACE(("Register %s MidiPortProducer\n", producer->Name())); TRACE(("Register %s MidiPortProducer\n", producer->Name()));
producer->Register(); producer->Register();
}
DeviceEndpoints* deviceEndpoints = new DeviceEndpoints(fd, consumer, producer); fDeviceEndpointsMap.Put(path, new DeviceEndpoints(fd, consumer, producer));
fDeviceEndpointsMap.Put(path, deviceEndpoints);
TRACE(("Done _AddDevice(\"%s\")\n", path)); TRACE(("Done _AddDevice(\"%s\")\n", path));
} }
@@ -259,11 +277,15 @@ DeviceWatcher::_RemoveDevice(const char* path)
} }
TRACE((" _RemoveDevice(\"%s\") unregistering\n", path)); TRACE((" _RemoveDevice(\"%s\") unregistering\n", path));
if (deviceEndpoints->fConsumer)
deviceEndpoints->fConsumer->Unregister(); deviceEndpoints->fConsumer->Unregister();
if (deviceEndpoints->fProducer)
deviceEndpoints->fProducer->Unregister(); deviceEndpoints->fProducer->Unregister();
TRACE((" _RemoveDevice(\"%s\") releasing\n", path)); TRACE((" _RemoveDevice(\"%s\") releasing\n", path));
if (deviceEndpoints->fConsumer)
deviceEndpoints->fConsumer->Release(); deviceEndpoints->fConsumer->Release();
if (deviceEndpoints->fProducer)
deviceEndpoints->fProducer->Release(); deviceEndpoints->fProducer->Release();
TRACE((" _RemoveDevice(\"%s\") removing from map\n", path)); TRACE((" _RemoveDevice(\"%s\") removing from map\n", path));