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 "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)
|
||||
return;
|
||||
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);
|
||||
_SetIcons(consumer);
|
||||
TRACE(("Register %s MidiPortConsumer\n", consumer->Name()));
|
||||
consumer->Register();
|
||||
MidiPortConsumer* consumer = NULL;
|
||||
MidiPortProducer* producer = NULL;
|
||||
|
||||
MidiPortProducer* producer = new MidiPortProducer(fd, path);
|
||||
_SetIcons(producer);
|
||||
TRACE(("Register %s MidiPortProducer\n", producer->Name()));
|
||||
producer->Register();
|
||||
int flags = fcntl(fd, F_GETFL);
|
||||
|
||||
DeviceEndpoints* deviceEndpoints = new DeviceEndpoints(fd, consumer, producer);
|
||||
fDeviceEndpointsMap.Put(path, deviceEndpoints);
|
||||
if ((flags & O_ACCMODE) != O_RDONLY) {
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -259,12 +277,16 @@ DeviceWatcher::_RemoveDevice(const char* path)
|
||||
}
|
||||
|
||||
TRACE((" _RemoveDevice(\"%s\") unregistering\n", path));
|
||||
deviceEndpoints->fConsumer->Unregister();
|
||||
deviceEndpoints->fProducer->Unregister();
|
||||
if (deviceEndpoints->fConsumer)
|
||||
deviceEndpoints->fConsumer->Unregister();
|
||||
if (deviceEndpoints->fProducer)
|
||||
deviceEndpoints->fProducer->Unregister();
|
||||
|
||||
TRACE((" _RemoveDevice(\"%s\") releasing\n", path));
|
||||
deviceEndpoints->fConsumer->Release();
|
||||
deviceEndpoints->fProducer->Release();
|
||||
if (deviceEndpoints->fConsumer)
|
||||
deviceEndpoints->fConsumer->Release();
|
||||
if (deviceEndpoints->fProducer)
|
||||
deviceEndpoints->fProducer->Release();
|
||||
|
||||
TRACE((" _RemoveDevice(\"%s\") removing from map\n", path));
|
||||
fDeviceEndpointsMap.Remove(path);
|
||||
|
||||
Reference in New Issue
Block a user