Symbian
 Developer Library

DEVELOPER LIBRARY

[Index] [Glossary] [Previous] [Next]



Location: k32std.h
Link against: ekern.lib

Class DLogicalChannel

DLogicalChannel

Support

Supported from 5.0

Description

The Kernel side logical channel.

This class defines the Kernel side interface to the logical device. The class consists of a number of virtual functions which must be overriden in a derived class.

A Kernel side logical channel is created by a factory object, an instance of a DLogicalDevice derived class.

Derivation

CBaseBase class for all classes to be instantiated on the heap
CObjectImplements reference counting to track concurrent references to itself
DLogicalChannelThe Kernel side logical channel

Defined in DLogicalChannel:
Cancel(), Close(), Complete(), CompleteAll(), Control(), DLogicalChannel(), Device(), DoCancel(), DoControl(), DoCreateL(), DoRequest(), IsPending(), Request(), SetBehaviour(), iDevice, iRequestStatus, iThread, iValidRequests, ~DLogicalChannel()

Inherited from CBase:
operator new()

Inherited from CObject:
AccessCount(), Dec(), FullName(), Inc(), Name(), Open(), Owner(), SetName(), SetNameL(), SetOwner(), UniqueID()

See also:


Construction and destruction


DLogicalChannel()

protected : DLogicalChannel(DLogicalDevice* aDevice);

Description

Constructs the object with a pointer to the LDD factory object.

The specified LDD factory object is responsible for the construction of this logical channel.

The LDD factory object keeps a count of the number of logical channels constructed from it; this count is incremented by one. The LDD factory object cannot be freed while any logical channel constructed from it remains open.

Typically, a derived class constructor:

Parameters

DLogicalDevice* aDevice

A pointer to the LDD factory object that is constructing this logical channel.

See also:


~DLogicalChannel()

protected : ~DLogicalChannel();

Description

Destructor.

The LDD factory object keeps a count of the number of logical channels constructed from it; the logical channel's destructor reduces this count by one. The LDD factory object cannot be freed while any logical channel constructed from it remains open.

Typically, there are number of requirements on a derived class.

If the device performs power handling, and this is implemented by the logical channel, then the derived class's destructor must ask the power handler to power down the device; the steps involved are:

The typical instruction sequence is:

...
    iPowerHandler->PowerStandby();
    ...
    Power::RemovePowerHandler(iPowerHandler);
    ...
    delete iPowerHandler;
    ...

where iPowerHandler is of type DPowerHandler*.

If the logical channel creates a physical channel, then it has ownership of this physical channel and is responsible for its destruction; typically, this done by the derived class's destructor.

It is also good practice for the derived class destructor to:

See also:

[Top]


Functions called by the Kernel


Request()

void Request(TInt aReqNo,TRequestStatus& aStatus,TAny* a1,TAny* a2);

Description

Performs the initial handling of an asynchronous request.

The function is called by the Kernel as a result of a user side call to RBusLogicalChannel::DoRequest().

The function calls this class's DoRequest() to handle the request.

Parameters

TInt aReqNo

A number identifying the request. The number must be a value in the range 0 to (KMaxRequests-1) inclusive otherwise the requesting thread is panicked with a KERN-EXEC 10. The number must also be valid as set by a call to this class's SetBehaviour(), otherwise the requesting thread is panicked with a KERN-EXEC 10. If a request associated with this number is still outstanding, then the requesting thread is panicked with a KERN-EXEC 9. The highest four bits can be used to define device specific flags. The constant KChanRequestNoReservedMask defines these four bits.

TRequestStatus& aStatus

The request status associated with the specified request number. The function sets this to KRequestPending before calling DoRequest().

TAny* a1

A pointer to a parameter passed from the user side; this may be Null.

TAny* a2

A pointer to a parameter passed from the user side; this may be Null.

See also:


Cancel()

void Cancel(TUint aReqMask);

Description

Performs the initial handling of an asynchronous request cancellation.

The function is called by the Kernel as result of a user side call to RBusLogicalChannel::DoCancel().

Each bit in the TUint argument corresponds to the request number specified in the original asynchronous request. For each outstanding request specified in the argument, the function:

Parameters

TUint aReqMask

A set of bits identifying the requests to be cancelled: Bit 0x0001 corresponds to request number 0, bit 0x0002 corresponds to request number 1, bit 0x0004 corresponds to request number 2 etc.

See also:


Control()

TInt Control(TInt aFunction,TAny* a1,TAny* a2);

Description

Performs the initial handling of a synchronous request.

The function is called by the Kernel as a result of a user side call to either:

This function runs in the context of the Kernel server, if the user side called RBusLogicalChannel::DoSvControl().

The function calls this class's DoControl() to handle the request.

Parameters

TInt aFunction

A number identifying specific functionality.

TAny* a1

If specified, a parameter passed from the user side; may be Null.

TAny* a2

If specified, a parameter passed from the user side; may be Null.

Return value

TInt

The value retrurned from the call to this class's DoControl().

See also:

[Top]


Functions that need an implementation


DoRequest()

protected : virtual void DoRequest(TInt aReqNo,TAny* a1,TAny* a2) = 0;

Description

Handles an asynchronous request.

The function is called by this class's Request() function as a result of a user side asynchronous Kernel Executive type request. A Kernel Executive type request means that no allocation or de-allocation of memory on the Kernel heap is possible.

Up to 4 asynchronous requests, each identified by a different request number (0 - 3), can be outstanding at the same time. By default, no requests are enabled. DLogicalChannel::SetBehaviour() must be called to enable the appropriate requests.

Typically, the function is implemented as a series of switch statements.

Completion of the request at some later time, involving the setting of the TRequestStatus object and the signalling of the originator's thread, is handled by a call to the logical channel's DLogicalChannel::Complete() function. As this updates the ready queue and writes to the user side address space, it must not be called by the Interrupt Service Routine directly (ISR); instead, the ISR should queue a Delayed Function Call (DFC) which can safely call it.

Parameters

TInt aReqNo

A number identifying the request.

TAny* a1

A pointer to a parameter passed from the user side; this may be Null.

TAny* a2

A pointer to a parameter passed from the user side; this may be Null.

Notes:

See also:


DoCancel()

protected : virtual void DoCancel(TInt aReqNo) = 0;

Description

Handles the cancellation of an asynchronous request.

This function is called by this class's Cancel() function.

Parameters

TInt aReqNo

The specific request to be cancelled.

Notes:

See also:

[Top]


Functions with default implementation


DoCreateL()

protected : virtual void DoCreateL(TInt aUnit,CBase* aDriver,const TDesC* anInfo,const TVersion& aVer);

Description

Performs secondary initialisation of the logical channel.

The function is called by the Kernel as part of the construction and initialization of this logical channel object and is a result of a user side call to RBusLogicalChannel::DoCreate().

The default implementation is empty.

If the device has power handling capability, and this is implemented in this logical channel, then its power handler should be created here, registered with the system's power model, and the device powered on.

The typical instruction sequence is:

...
    iPowerHandler=new (ELeave) DDerivedPowerHandler(this);
    ...
    User::LeaveIfError(Power::AddPowerHandler(iPowerHandler));
    ...
    iPowerHandler->PowerOn();
    ...

where iPowerHandler is of type DPowerHandler* and is, typically, a data member of the class derived from DLogicalChannel.

This function should also check the requested version against the version with which this logical channel was built.

For those drivers which implement unit numbers but do not employ a PDD, then the specified unit number should be verified here.

Parameters

TInt aUnit

This is the value originally passed as a parameter to the user side handle RBusLogicalChannel. The device driver framework does not apply meaning to the idea of a unit.

CBase* aDriver

If the LDD factory object, a DlogicalDevice, needs a physical device, then this is a pointer to the physical channel. If the LDD factory object does not need a physical device, then this is Null. Note that the physical channel is constructed by a call to the PDD factory object DPhysicalDevice::CreateL().

const TDesC* anInfo

A pointer to a descriptor containing extra information for the device. This is the value originally passed as a parameter to the user side handle RBusLogicalChannel. The device driver framework does not apply meaning to the content.

const TVersion& aVer

The version requested by the thread which is opening this channel through its user side handle RBusLogicalChannel

See also:


DoControl()

protected : virtual TInt DoControl(TInt aFunction,TAny* a1,TAny* a2);

Description

Handles a synchronous request.

The function is called by this class's Control() function as a result of a user side synchronous Kernel Executive type request or a synchronous Kernel Server type request. The function can only allocate or de-allocate memory on the Kernel heap when running in the context of the Kernel server

Implementers must use the function number to distinguish between the two situations.

Typically, DoControl() is implemented as a switch statement based on the function number passed to it.

Device drivers can be queried about their capabilities; this is often implemented by DoControl().

The default implementation returns KErrNotSupported.

Parameters

TInt aFunction

A number identifying specific functionality.

TAny* a1

If specified, a parameter from the user side; may be Null.

TAny* a2

If specified, a parameter from the user side; may be Null.

Return value

TInt

Implementation dependent but expected to be KErrNone if successful or one of the other system wide error codes. The default implementation returns KerrNotSupported.

See also:


Close()

protected : virtual void Close();

Description

Closes the logical channel.

This function is called by the Kernel in the context of the Kernel Server as a result of closing the user side handle to this logical channel, i.e. as a result of a user side call to Close() on the RBusLogicalChannel.

The default implementation makes a base call to CObject::Close() to reduce the reference count. An implementation provided by a derived class should make a base call to this Close() function after it has done its own specific processing.

Notes:

See also:

[Top]


Information


IsPending()

protected : TBool IsPending(TInt aReqNo) const;

Description

Determines whether the request associated with the specified request number is pending.

Parameters

TInt aReqNo

The request number.

Return value

TBool

True, if the request is pending; false, otherwise.

See also:


Device()

protected : DLogicalDevice* Device();

Description

Gets a pointer to the LDD factory object that created this logical channel.

Return value

DLogicalDevice*

A pointer to the LDD factory object.

[Top]


Setting


Complete()

protected : void Complete(TInt aReqNo);
protected : void Complete(TInt aReqNo,TInt aReason);

Description

Completes the outstanding request identified by the specified request number.

Parameters

TInt aReqNo

The request number identifying the request.

TInt aReason

The request completion code. If not specified, defaults to KErrNone.

Notes:

See also:


CompleteAll()

protected : void CompleteAll(TInt aReason);

Description

Completes all outstanding requests.

Parameters

TInt aReason

The request completion code with which all outstanding requests are completed.


SetBehaviour()

protected : void SetBehaviour(TUint aValidRequests);

Description

Defines which request numbers are valid.

The maximum possible request number is the value of KMaxRequests-1.

Typically, this function is called by the constructor of the derived class. In any event, it must be called before any asynchronous requests are made.

Parameters

TUint aValidRequests

A set of bits identifying the request numbers which are valid: bit 0x0001 corresponds to request number 0, bit 0x0002 corresponds to request number 1, bit 0x0004 corresponds to request number 2 etc

Notes:

See also:

[Top]


Protected data members


iThread

DThread* iThread;

Description

A pointer to the thread associated with this channel.

[Top]


Internal members


iRequestStatus

private : TRequestStatus *iRequestStatus[KMaxRequests];

Description

This is internal and is not intended for use.


iValidRequests

private :   TUint iValidRequests;

Description

This is internal and is not intended for use.


iDevice

private : DLogicalDevice *iDevice;

Description

This is internal and is not intended for use.