Cleanup and some added constness.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36249 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz 2010-04-14 09:32:11 +00:00
parent cc9f959d8b
commit 19b8f8a080
2 changed files with 112 additions and 74 deletions

View File

@ -13,7 +13,8 @@
BusManager::BusManager(Stack *stack) BusManager::BusManager(Stack *stack)
: fInitOK(false), : fInitOK(false),
fStack(stack), fStack(stack),
fRootHub(NULL) fRootHub(NULL),
fUSBID(fStack->IndexOfBusManager(this))
{ {
mutex_init(&fLock, "usb busmanager lock"); mutex_init(&fLock, "usb busmanager lock");

View File

@ -6,7 +6,6 @@
* Michael Lotz <mmlr@mlotz.ch> * Michael Lotz <mmlr@mlotz.ch>
* Niels S. Reedijk * Niels S. Reedijk
*/ */
#ifndef _USB_PRIVATE_H #ifndef _USB_PRIVATE_H
#define _USB_PRIVATE_H #define _USB_PRIVATE_H
@ -134,7 +133,8 @@ public:
BusManager * BusManagerAt(int32 index); BusManager * BusManagerAt(int32 index);
status_t AllocateChunk(void **logicalAddress, status_t AllocateChunk(void **logicalAddress,
void **physicalAddress, size_t size); void **physicalAddress,
size_t size);
status_t FreeChunk(void *logicalAddress, status_t FreeChunk(void *logicalAddress,
void *physicalAddress, size_t size); void *physicalAddress, size_t size);
@ -149,7 +149,8 @@ public:
// USB API // USB API
status_t RegisterDriver(const char *driverName, status_t RegisterDriver(const char *driverName,
const usb_support_descriptor *descriptors, const usb_support_descriptor *
descriptors,
size_t descriptorCount, size_t descriptorCount,
const char *republishDriverName); const char *republishDriverName);
@ -157,8 +158,8 @@ public:
const usb_notify_hooks *hooks); const usb_notify_hooks *hooks);
status_t UninstallNotify(const char *driverName); status_t UninstallNotify(const char *driverName);
usb_id USBID() { return 0; }; usb_id USBID() const { return 0; }
const char * TypeName() { return "stack"; }; const char * TypeName() const { return "stack"; }
private: private:
static int32 ExploreThread(void *data); static int32 ExploreThread(void *data);
@ -213,12 +214,13 @@ virtual status_t CancelQueuedTransfers(Pipe *pipe,
virtual status_t NotifyPipeChange(Pipe *pipe, virtual status_t NotifyPipeChange(Pipe *pipe,
usb_change change); usb_change change);
Object * RootObject() { return fRootObject; }; Object * RootObject() const
{ return fRootObject; }
Hub * GetRootHub() { return fRootHub; }; Hub * GetRootHub() const { return fRootHub; }
void SetRootHub(Hub *hub) { fRootHub = hub; }; void SetRootHub(Hub *hub) { fRootHub = hub; }
usb_id USBID() { return fStack->IndexOfBusManager(this); }; usb_id USBID() const { return fUSBID; }
virtual const char * TypeName() = 0; virtual const char * TypeName() = 0;
protected: protected:
@ -236,6 +238,8 @@ private:
ControlPipe * fDefaultPipes[USB_SPEED_MAX + 1]; ControlPipe * fDefaultPipes[USB_SPEED_MAX + 1];
Hub * fRootHub; Hub * fRootHub;
Object * fRootObject; Object * fRootObject;
usb_id fUSBID;
}; };
@ -245,14 +249,15 @@ public:
Object(Object *parent); Object(Object *parent);
virtual ~Object(); virtual ~Object();
Object * Parent() { return fParent; }; Object * Parent() const { return fParent; }
BusManager * GetBusManager() { return fBusManager; }; BusManager * GetBusManager() const
Stack * GetStack() { return fStack; }; { return fBusManager; }
Stack * GetStack() const { return fStack; }
usb_id USBID() { return fUSBID; }; usb_id USBID() const { return fUSBID; }
virtual uint32 Type() { return USB_OBJECT_NONE; }; virtual uint32 Type() const { return USB_OBJECT_NONE; }
virtual const char * TypeName() { return "object"; }; virtual const char * TypeName() const { return "object"; }
// Convenience functions for standard requests // Convenience functions for standard requests
virtual status_t SetFeature(uint16 selector); virtual status_t SetFeature(uint16 selector);
@ -273,7 +278,7 @@ private:
*/ */
class Pipe : public Object { class Pipe : public Object {
public: public:
enum pipeDirection { In, Out, Default }; enum pipeDirection { In, Out, Default };
Pipe(Object *parent); Pipe(Object *parent);
virtual ~Pipe(); virtual ~Pipe();
@ -286,29 +291,37 @@ virtual ~Pipe();
uint8 interval, uint8 interval,
int8 hubAddress, uint8 hubPort); int8 hubAddress, uint8 hubPort);
virtual uint32 Type() { return USB_OBJECT_PIPE; }; virtual uint32 Type() const { return USB_OBJECT_PIPE; }
virtual const char * TypeName() { return "pipe"; }; virtual const char * TypeName() const { return "pipe"; }
int8 DeviceAddress() { return fDeviceAddress; }; int8 DeviceAddress() const
usb_speed Speed() { return fSpeed; }; { return fDeviceAddress; }
pipeDirection Direction() { return fDirection; }; usb_speed Speed() const { return fSpeed; }
uint8 EndpointAddress() { return fEndpointAddress; }; pipeDirection Direction() const { return fDirection; }
size_t MaxPacketSize() { return fMaxPacketSize; }; uint8 EndpointAddress() const
uint8 Interval() { return fInterval; }; { return fEndpointAddress; }
size_t MaxPacketSize() const
{ return fMaxPacketSize; }
uint8 Interval() const { return fInterval; }
// Hub port being the one-based logical port number on the hub // Hub port being the one-based logical port number on the hub
void SetHubInfo(int8 address, uint8 port); void SetHubInfo(int8 address, uint8 port);
int8 HubAddress() { return fHubAddress; }; int8 HubAddress() const
uint8 HubPort() { return fHubPort; }; { return fHubAddress; }
uint8 HubPort() const { return fHubPort; }
virtual bool DataToggle() { return fDataToggle; }; virtual bool DataToggle() const
virtual void SetDataToggle(bool toggle) { fDataToggle = toggle; }; { return fDataToggle; }
virtual void SetDataToggle(bool toggle)
{ fDataToggle = toggle; }
status_t SubmitTransfer(Transfer *transfer); status_t SubmitTransfer(Transfer *transfer);
status_t CancelQueuedTransfers(bool force); status_t CancelQueuedTransfers(bool force);
void SetControllerCookie(void *cookie) { fControllerCookie = cookie; }; void SetControllerCookie(void *cookie)
void * ControllerCookie() { return fControllerCookie; }; { fControllerCookie = cookie; }
void * ControllerCookie() const
{ return fControllerCookie; }
// Convenience functions for standard requests // Convenience functions for standard requests
virtual status_t SetFeature(uint16 selector); virtual status_t SetFeature(uint16 selector);
@ -334,16 +347,18 @@ public:
ControlPipe(Object *parent); ControlPipe(Object *parent);
virtual ~ControlPipe(); virtual ~ControlPipe();
virtual uint32 Type() { return USB_OBJECT_PIPE | USB_OBJECT_CONTROL_PIPE; }; virtual uint32 Type() const { return USB_OBJECT_PIPE
virtual const char * TypeName() { return "control pipe"; }; | USB_OBJECT_CONTROL_PIPE; }
virtual const char * TypeName() const
{ return "control pipe"; }
// The data toggle is not relevant // The data toggle is not relevant
// for control transfers, as they are // for control transfers, as they are
// always enclosed by a setup and // always enclosed by a setup and
// status packet. The toggle always // status packet. The toggle always
// starts at 1. // starts at 1.
virtual bool DataToggle() { return true; }; virtual bool DataToggle() const { return true; }
virtual void SetDataToggle(bool toggle) {}; virtual void SetDataToggle(bool toggle) const {}
status_t SendRequest(uint8 requestType, status_t SendRequest(uint8 requestType,
uint8 request, uint16 value, uint8 request, uint16 value,
@ -373,8 +388,10 @@ class InterruptPipe : public Pipe {
public: public:
InterruptPipe(Object *parent); InterruptPipe(Object *parent);
virtual uint32 Type() { return USB_OBJECT_PIPE | USB_OBJECT_INTERRUPT_PIPE; }; virtual uint32 Type() const { return USB_OBJECT_PIPE
virtual const char * TypeName() { return "interrupt pipe"; }; | USB_OBJECT_INTERRUPT_PIPE; }
virtual const char * TypeName() const
{ return "interrupt pipe"; }
status_t QueueInterrupt(void *data, status_t QueueInterrupt(void *data,
size_t dataLength, size_t dataLength,
@ -387,8 +404,9 @@ class BulkPipe : public Pipe {
public: public:
BulkPipe(Object *parent); BulkPipe(Object *parent);
virtual uint32 Type() { return USB_OBJECT_PIPE | USB_OBJECT_BULK_PIPE; }; virtual uint32 Type() const { return USB_OBJECT_PIPE
virtual const char * TypeName() { return "bulk pipe"; }; | USB_OBJECT_BULK_PIPE; }
virtual const char * TypeName() const { return "bulk pipe"; }
status_t QueueBulk(void *data, status_t QueueBulk(void *data,
size_t dataLength, size_t dataLength,
@ -406,12 +424,14 @@ class IsochronousPipe : public Pipe {
public: public:
IsochronousPipe(Object *parent); IsochronousPipe(Object *parent);
virtual uint32 Type() { return USB_OBJECT_PIPE | USB_OBJECT_ISO_PIPE; }; virtual uint32 Type() const { return USB_OBJECT_PIPE
virtual const char * TypeName() { return "iso pipe"; }; | USB_OBJECT_ISO_PIPE; }
virtual const char * TypeName() const { return "iso pipe"; }
status_t QueueIsochronous(void *data, status_t QueueIsochronous(void *data,
size_t dataLength, size_t dataLength,
usb_iso_packet_descriptor *packetDesc, usb_iso_packet_descriptor *
packetDescriptor,
uint32 packetCount, uint32 packetCount,
uint32 *startingFrameNumber, uint32 *startingFrameNumber,
uint32 flags, uint32 flags,
@ -437,8 +457,9 @@ public:
Interface(Object *parent, Interface(Object *parent,
uint8 interfaceIndex); uint8 interfaceIndex);
virtual uint32 Type() { return USB_OBJECT_INTERFACE; }; virtual uint32 Type() const
virtual const char * TypeName() { return "interface"; }; { return USB_OBJECT_INTERFACE; }
virtual const char * TypeName() const { return "interface"; }
// Convenience functions for standard requests // Convenience functions for standard requests
virtual status_t SetFeature(uint16 selector); virtual status_t SetFeature(uint16 selector);
@ -464,33 +485,41 @@ virtual ~Device();
virtual status_t Changed(change_item **changeList, virtual status_t Changed(change_item **changeList,
bool added); bool added);
virtual uint32 Type() { return USB_OBJECT_DEVICE; }; virtual uint32 Type() const
virtual const char * TypeName() { return "device"; }; { return USB_OBJECT_DEVICE; }
virtual const char * TypeName() const { return "device"; }
ControlPipe * DefaultPipe() { return fDefaultPipe; }; ControlPipe * DefaultPipe() const
{ return fDefaultPipe; }
virtual status_t GetDescriptor(uint8 descriptorType, virtual status_t GetDescriptor(uint8 descriptorType,
uint8 index, uint16 languageID, uint8 index, uint16 languageID,
void *data, size_t dataLength, void *data, size_t dataLength,
size_t *actualLength); size_t *actualLength);
int8 DeviceAddress() const { return fDeviceAddress; }; int8 DeviceAddress() const
{ return fDeviceAddress; }
const usb_device_descriptor * DeviceDescriptor() const; const usb_device_descriptor * DeviceDescriptor() const;
usb_speed Speed() const { return fSpeed; }; usb_speed Speed() const { return fSpeed; }
const usb_configuration_info * Configuration() const; const usb_configuration_info * Configuration() const;
const usb_configuration_info * ConfigurationAt(uint8 index) const; const usb_configuration_info * ConfigurationAt(uint8 index) const;
status_t SetConfiguration(const usb_configuration_info *configuration); status_t SetConfiguration(
const usb_configuration_info *
configuration);
status_t SetConfigurationAt(uint8 index); status_t SetConfigurationAt(uint8 index);
status_t Unconfigure(bool atDeviceLevel); status_t Unconfigure(bool atDeviceLevel);
status_t SetAltInterface(const usb_interface_info *interface); status_t SetAltInterface(
const usb_interface_info *
interface);
void InitEndpoints(int32 interfaceIndex); void InitEndpoints(int32 interfaceIndex);
void ClearEndpoints(int32 interfaceIndex); void ClearEndpoints(int32 interfaceIndex);
virtual status_t ReportDevice( virtual status_t ReportDevice(
usb_support_descriptor *supportDescriptors, usb_support_descriptor *
supportDescriptors,
uint32 supportDescriptorCount, uint32 supportDescriptorCount,
const usb_notify_hooks *hooks, const usb_notify_hooks *hooks,
usb_driver_cookie **cookies, usb_driver_cookie **cookies,
@ -499,8 +528,9 @@ virtual status_t BuildDeviceName(char *string,
uint32 *index, size_t bufferSize, uint32 *index, size_t bufferSize,
Device *device); Device *device);
int8 HubAddress() const { return fHubAddress; }; int8 HubAddress() const
uint8 HubPort() const { return fHubPort; }; { return fHubAddress; }
uint8 HubPort() const { return fHubPort; }
// Convenience functions for standard requests // Convenience functions for standard requests
virtual status_t SetFeature(uint16 selector); virtual status_t SetFeature(uint16 selector);
@ -536,16 +566,17 @@ virtual ~Hub();
virtual status_t Changed(change_item **changeList, virtual status_t Changed(change_item **changeList,
bool added); bool added);
virtual uint32 Type() { return USB_OBJECT_DEVICE | USB_OBJECT_HUB; }; virtual uint32 Type() const { return USB_OBJECT_DEVICE
virtual const char * TypeName() { return "hub"; }; | USB_OBJECT_HUB; }
virtual const char * TypeName() const { return "hub"; }
virtual status_t GetDescriptor(uint8 descriptorType, virtual status_t GetDescriptor(uint8 descriptorType,
uint8 index, uint16 languageID, uint8 index, uint16 languageID,
void *data, size_t dataLength, void *data, size_t dataLength,
size_t *actualLength); size_t *actualLength);
Device * ChildAt(uint8 index) Device * ChildAt(uint8 index) const
{ return fChildren[index]; }; { return fChildren[index]; }
status_t UpdatePortStatus(uint8 index); status_t UpdatePortStatus(uint8 index);
status_t ResetPort(uint8 index); status_t ResetPort(uint8 index);
@ -557,7 +588,8 @@ static void InterruptCallback(void *cookie,
size_t actualLength); size_t actualLength);
virtual status_t ReportDevice( virtual status_t ReportDevice(
usb_support_descriptor *supportDescriptors, usb_support_descriptor *
supportDescriptors,
uint32 supportDescriptorCount, uint32 supportDescriptorCount,
const usb_notify_hooks *hooks, const usb_notify_hooks *hooks,
usb_driver_cookie **cookies, usb_driver_cookie **cookies,
@ -592,29 +624,33 @@ public:
Transfer(Pipe *pipe); Transfer(Pipe *pipe);
~Transfer(); ~Transfer();
Pipe * TransferPipe() { return fPipe; }; Pipe * TransferPipe() const { return fPipe; }
void SetRequestData(usb_request_data *data); void SetRequestData(usb_request_data *data);
usb_request_data * RequestData() { return fRequestData; }; usb_request_data * RequestData() const { return fRequestData; }
void SetIsochronousData(usb_isochronous_data *data); void SetIsochronousData(
usb_isochronous_data * IsochronousData() { return fIsochronousData; }; usb_isochronous_data *data);
usb_isochronous_data * IsochronousData() const
{ return fIsochronousData; }
void SetData(uint8 *buffer, size_t length); void SetData(uint8 *buffer, size_t length);
uint8 * Data() { return (uint8 *)fData.iov_base; }; uint8 * Data() const
size_t DataLength() { return fData.iov_len; }; { return (uint8 *)fData.iov_base; }
size_t DataLength() const { return fData.iov_len; }
void SetPhysical(bool physical); void SetPhysical(bool physical);
bool IsPhysical() { return fPhysical; }; bool IsPhysical() const { return fPhysical; }
void SetVector(iovec *vector, size_t vectorCount); void SetVector(iovec *vector,
iovec * Vector() { return fVector; }; size_t vectorCount);
size_t VectorCount() { return fVectorCount; }; iovec * Vector() { return fVector; }
size_t VectorCount() const { return fVectorCount; }
size_t VectorLength(); size_t VectorLength();
uint16 Bandwidth() { return fBandwidth; }; uint16 Bandwidth() const { return fBandwidth; }
bool IsFragmented() { return fFragmented; }; bool IsFragmented() const { return fFragmented; }
void AdvanceByFragment(size_t actualLength); void AdvanceByFragment(size_t actualLength);
status_t InitKernelAccess(); status_t InitKernelAccess();
@ -623,10 +659,11 @@ public:
void SetCallback(usb_callback_func callback, void SetCallback(usb_callback_func callback,
void *cookie); void *cookie);
void Finished(uint32 status, size_t actualLength); void Finished(uint32 status,
size_t actualLength);
usb_id USBID() { return 0; }; usb_id USBID() const { return 0; }
const char * TypeName() { return "transfer"; }; const char * TypeName() const { return "transfer"; }
private: private:
status_t _CalculateBandwidth(); status_t _CalculateBandwidth();