Hi Dan,
Thank for your reply.
There is no difference to subclassing IOSCSIPeripheraldeviceType00
than subclassing IOBlockStorageServices, I still need to subclass
all those IO related methods, that's why I had my questions posted
here.
Wenhua
Dan Markarian <email@hidden> wrote:
Hi Wenhua,
Why not subclass AsyncReadWrite(), EjectTheMedium(), FormatMedium(),
etc, in IOSCSIPeripheralDeviceType00? IOBlockStorageServices routes
those calls through there.
Dan
On 8 Jun 2005, at 3:56 PM, Wenhua Liu wrote:
> Hi,
>
> I'm writing my logical unit driver by subclassing
> IOSCSIPeripheralDeviceType00 and
> IOBlockStorageServices(class of device services nub).
> I need to implement some common functions in most of
> I/O related methods in class IOBlockStorageServices,
> such as doAsyncReadWrite, doSyncReadWrite,
> doEjectMedia, doFormatMedia and others. If all this
> methods call a common method, I just need to rewrite
> this method, this would be the best way. But there is
> no such a method, so this is not doable.
>
> If I rewrite all thoses metho! ds, it'll be too much
> work, the worse thing is I have to maintain all those
> methods even I don't change them. So I have another
> idea.
>
> 1. By subclassing IOBlockStorageServices, my driver
> can provide the same interface to the clients.
> 2. By embedding an object of class
> IOBlockStorageServices in my subclass, my driver can
> reuse the methods of class IOBlockStorageServices.
>
> Here is the definition of my subclass
>
> class MyIOBlockStorageServices : public
> IOBlockStorageServices
> {
> OSDeclareDefaultStructors (MyIOBlockStorageServices)
>
> private:
> IOBlockStorageServices parentObject;
>
> public:
> virtual IOReturn doAsyncReadWrite (
> IOMemoryDescriptor * buffer,
> UInt32 block,
> UInt32 nblks,
> IOStorageCompletion completion );
>
> // more methods defined here
>
> };
>
> H! ere is the implementation of method
> doAsyncReadWrite():
>
> IOReturn
> MyIOBlockStorageServices :: doAsyncReadWrite (
> IOMemoryDescriptor * buffer,
> UInt32 block,
> UInt32 nblks,
> IOStorageCompletion completion )
> {
> // do some common stuff here
>
> // call parentObject's same method
>
> return parentObject->doAsyncReadWrite (buffer, block,
> nblks, completion);
> }
>
>
> People may ask why I don't implentment my own method
> using super::doAsyncReadWrite(). I want to do so, but
> for my special purpose, I can't do it.
>
>
> My question is: in order to implement my subclass like
> what I described above, what should I
> do(initialization, attach, registration, or something
> else) to make sure when parentObject is referenced for
> calling its methods, everything is valid?