MCFContextInterface Class Reference

class MCFContextInterface
MCFContextInterface provides possibility to use CF services related to context manipulation:
  • Define contexts

  • Publish contexts

  • Subscribe contexts

  • Unsubscribe contexts

  • Request contexts Every context source plug-in has a reference to MCFContextInterface by default.

Define context: Before any context can be used in any way it must be defined. Context is defined by a source, type and security policy:
  _LIT( KSource, "Source" );
  _LIT( KType, "Type" );
  _LIT_SECURITY_POLICY_PASS( KPassSec );
  TInt err = iCF.DefineContext( KSource, KType, KPassSec );
  if( err != KErrNone )
    {
    // Handle error...
    }
Publish context: To publish a context the context being publish needs to be defined. To publish a context a new context object must be configured. Context object is configured by setting a source, type and a new value for the context:
  _LIT( KSource, "Source" );
  _LIT( KType, "Type" );
  _LIT( KValue, "NewValue" );
  CCFContextObject* context = CCFContextObject::NewLC();
  context->SetSourceL( KSource );
  context->SetTypeL( KType );
  context->SetValueL( KValue );
  RThread thread;
  CleanupClosePushL( thread );
  TInt err = iCF.PublishContext( *context, thread );
  if( err != KErrNone )
    {
    // Handle error...
    }
  CleanupStack::PopAndDestroy( &thread );
  CleanupStack::PopAndDestroy( context );
It is suggested that only one CCFContextObject* instance is kept as a member variable to save memory.
Subscribe context: To subscribe a context the context being subscribed needs to be defined. A context subscription will not lead to an error even a context which has not been defined is subscribed. Context indications will be received only after the context subscribed is defined. To subscribe a context a new context subscription is made and passed it to Context Framework:
  _LIT( KSource, "Source" );
  _LIT( KType, "Type" );
  CCFContextSubscription* subscription = CCFContextSubscription::NewLC();
  subscription->SetContextSourceL( KSource );
  subscription->SetContextTypeL( KType );
  RThread thread;
  CleanupClosePushL( thread );
  TInt err = iCF.SubscribeContext( *subscription, this, thread );
  if( err != KErrNone )
    {
    // Handle error...
    }
  CleanupStack::PopAndDestroy( &thread );
  CleanupStack::PopAndDestroy( subscription );
It is assumed that 'this' is derived directly from MCFContextSubscriptionListener interface. Context subscription can also be configured more to give more precise indications.
Request context: To request a context the context being requested needs to be defined. Context is requested by defining a context query and passing it to Context Framework:
  _LIT( KSource, "Source" );
  _LIT( KType, "Type" );
  CCFContextQuery* query = CCFContextQuery::NewLC( KSource, KType );
  RThread thread;
  CleanupClosePushL( thread );
  RContextObjectArray results;
  TInt err = iCF.RequestContext( results, *query, thread );
  if( err == KErrNone && results.Count() )
    {
    // Handle request results...
    }
  else
    {
    // Handle error...
    }
  results.ResetAndDestroy();
  CleanupStack::PopAndDestroy( &thread );
  CleanupStack::PopAndDestroy( query );
Remove subscriptions: If a context source plug-in has subscribed contexts it is necessary that also all the contexts will be unsubscribed. Unsubscription can be done by defining a single subscription or to remove all the subscriptions from the particular subscriber:
  _LIT( KSource, "Source" );
  _LIT( KType, "Type" );
  CCFContextSubscription* subscription = CCFContextSubscription::NewLC();
  subscription->SetContextSourceL( KSource );
  subscription->SetContextTypeL( KType );
  iCF.UnsubscribeContext( *subscription, *this );
  CleanupStack::PopAndDestroy( subscription );
 iCF.UnsubscribeContexts( *this );
It is assumed that 'this' is derived directly from MCFContextSubscriptionListener interface.
Since
S60 5.0 -

Constructor & Destructor Documentation

~MCFContextInterface()

~MCFContextInterface()[protected, inline, virtual]

Member Functions Documentation

DefineContext(const TDesC &, const TDesC &, const TSecurityPolicy &)

TInt DefineContext(const TDesC &aContextSource,
const TDesC &aContextType,
const TSecurityPolicy &aReadWritePolicy
)[pure virtual]

Defines a new context in Context Framework. Every context needs to be defined before it can be published, subscribed or requested.

Security policy for reading and writing is the same.

If some client subscribes for this context, the contex owner will not be notified. Use one of the followinf DefineContext methods to receive context susbsription notifications.

Since
S60 5.0

Parameters

const TDesC & aContextSourceSource of the context.
const TDesC & aContextTypeType of the context.
const TSecurityPolicy & aReadWritePolicyNeeded capabilities for reading and writing of the context.

DefineContext(const TDesC &, const TDesC &, const TSecurityPolicy &, MCFContextSource &)

TInt DefineContext(const TDesC &aContextSource,
const TDesC &aContextType,
const TSecurityPolicy &aReadWritePolicy,
MCFContextSource &aOwner
)[pure virtual]

Defines a new context in Context Framework. Every context needs to be defined before it can be published, subscribed or requested.

Security policy for reading and writing is the same.

If some client subscribes for this context, the contex owner will be notified through MCFContextSource interface.

Since
S60 5.0

Parameters

const TDesC & aContextSourceSource of the context.
const TDesC & aContextTypeType of the context.
const TSecurityPolicy & aReadWritePolicyNeeded capabilities for reading and writing of the context.
MCFContextSource & aOwnerOwner of the context.

DefineContext(const TDesC &, const TDesC &, const TSecurityPolicy &, const TSecurityPolicy &, MCFContextSource &)

TInt DefineContext(const TDesC &aContextSource,
const TDesC &aContextType,
const TSecurityPolicy &aReadPolicy,
const TSecurityPolicy &aWritePolicy,
MCFContextSource &aOwner
)[pure virtual]

Defines a new context in Context Framework. Every context needs to be defined before it can be published, subscribed or requested.

Security policy for reading and writing are different.

If some client subscribes for this context, the contex owner will be notified through MCFContextSource interface.

Since
S60 5.0

Parameters

const TDesC & aContextSourceSource of the context.
const TDesC & aContextTypeType of the context.
const TSecurityPolicy & aReadPolicy
const TSecurityPolicy & aWritePolicy
MCFContextSource & aOwner

GetSecurityPolicy(const TDesC &, const TDesC &, TSecurityPolicy &)

TInt GetSecurityPolicy(const TDesC &aContextSource,
const TDesC &aContextType,
TSecurityPolicy &aPolicy
)[pure virtual]

Gets the security policy of particular action.

Parameters

const TDesC & aContextSourceContext Source.
const TDesC & aContextTypeContext Type.
TSecurityPolicy & aPolicysecurity policy which will be set by this method.

PublishContext(CCFContextObject &, RThread &)

TInt PublishContext(CCFContextObject &aContext,
RThread &aClientThread
)[pure virtual]

Publishes a new value of a context into Context Framework. Subscribed clients will be notified of the change. Context must have been defined before it can be published.

Since
S60 5.0

Parameters

CCFContextObject & aContextContext object to be added.
RThread & aClientThread

PublishContext(CCFContextObject &, CCFContextDataObject &, RThread &)

TInt PublishContext(CCFContextObject &aContext,
CCFContextDataObject &aData,
RThread &aClientThread
)[pure virtual]

Publishes a new value of a context into Context Framework. Subscribed clients will be notified of the change. Context can be associated with a specific data object. If a subscriber has requested to receive also data objects the data object is associated in the context indication. Context must have been defined before it can be published.

Since
S60 5.0

Parameters

CCFContextObject & aContextContext object to be added.
CCFContextDataObject & aDataData object associated the context.
RThread & aClientThread

RequestContext(RContextObjectArray &, CCFContextQuery &, RThread &)

TInt RequestContext(RContextObjectArray &aResultBuffer,
CCFContextQuery &aContextQuery,
RThread &aClientThread
)[pure virtual]
Requests latest context.
  • KErrNotFound: Requested context not defined

  • KErrAccessDenied: Insufficient capabilities for the context

Since
S60 5.0

Parameters

RContextObjectArray & aResultBufferContext objects.
CCFContextQuery & aContextQueryContext query.
RThread & aClientThreadClient thread where function is called.

SubscribeContext(CCFContextSubscription *, MCFContextSubscriptionListener *, RThread &)

TInt SubscribeContext(CCFContextSubscription *aSubscription,
MCFContextSubscriptionListener *aListener,
RThread &aClientThread
)[pure virtual]
Adds new context subscription in Context Framework. Context Framework takes ownership from aSubscription. Possible error codes:
  • KErrNotFound: Published context not defined

  • KErrAccessDenied: Insufficient capabilities for the context

Since
S60 5.0

Parameters

CCFContextSubscription * aSubscriptionNew subscription.
MCFContextSubscriptionListener * aListenerSubscription listener.
RThread & aClientThreadClient thread where function is called.

UnsubscribeContext(CCFContextSubscription &, MCFContextSubscriptionListener &)

voidUnsubscribeContext(CCFContextSubscription &aSubscription,
MCFContextSubscriptionListener &aListener
)[pure virtual]

Remove a context subscription from Context Framework.

Since
S60 5.0

Parameters

CCFContextSubscription & aSubscriptionNew subscription.
MCFContextSubscriptionListener & aListenerSubscription listener.

UnsubscribeContexts(MCFContextSubscriptionListener &)

voidUnsubscribeContexts(MCFContextSubscriptionListener &aObserver)[pure virtual]

Remove all subscriptions for the particular listener.

Since
S60 5.0

Parameters

MCFContextSubscriptionListener & aObserverListener whose subscriptions will be removed.