epoc32/include/mw/coemop.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/coemop.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     2
// All rights reserved.
williamr@2
     3
// This component and the accompanying materials are made available
williamr@2
     4
// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
williamr@2
     5
// which accompanies this distribution, and is available
williamr@2
     6
// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2
     7
//
williamr@2
     8
// Initial Contributors:
williamr@2
     9
// Nokia Corporation - initial contribution.
williamr@2
    10
//
williamr@2
    11
// Contributors:
williamr@2
    12
//
williamr@2
    13
// Description:
williamr@2
    14
//
williamr@2
    15
williamr@2
    16
#ifndef __COEMOP_H__
williamr@2
    17
#define __COEMOP_H__
williamr@2
    18
williamr@2
    19
#include <e32std.h>
williamr@2
    20
williamr@2
    21
/** Declares an object type, ETypeId, for a class, in order to allow the object 
williamr@2
    22
provider mechanism to locate and provide objects from the class.
williamr@2
    23
williamr@2
    24
@publishedAll
williamr@2
    25
@released
williamr@2
    26
@see MObjectProvider */
williamr@2
    27
#define DECLARE_TYPE_ID(id) enum { ETypeId = id };
williamr@2
    28
williamr@2
    29
//
williamr@2
    30
// Used to wrap object type IDs in a standardised manner. Object type IDs must be asserted 
williamr@2
    31
// in an ETypeId member data property by any types of object which 
williamr@2
    32
// are capable of being retrieved by the MObjectProvider interface
williamr@2
    33
//
williamr@2
    34
class TTypeUid : public TUid
williamr@2
    35
/** Part of the object provider mechanism, this class encapsulates the Uid that 
williamr@2
    36
identifies the type of object that an object provider is to get.
williamr@2
    37
williamr@2
    38
The class is also used to encapsulate a pointer to the object that the object 
williamr@2
    39
provider has found.
williamr@2
    40
williamr@2
    41
An object that is intended to be capable of being retrieved by the object 
williamr@2
    42
provider mechanism must include enum {ETypeId = 0xabcdefgh}; in its class 
williamr@2
    43
definition, where 0xabcdefgh is the Uid value. The macro DECLARE_TYPE_ID can 
williamr@2
    44
be used to do this.
williamr@2
    45
williamr@2
    46
An instance of this class is passed to the MObjectProvider::MopSupplyObject() 
williamr@2
    47
function implemented by an object provider. A TTypeUid::Ptr is also returned 
williamr@2
    48
by this function.
williamr@2
    49
williamr@2
    50
@publishedAll
williamr@2
    51
@released
williamr@2
    52
@see MObjectProvider */
williamr@2
    53
	{
williamr@2
    54
public:
williamr@2
    55
	class Ptr
williamr@2
    56
	/** Encapsulates a pointer to an object fetched by an object provider.
williamr@2
    57
williamr@2
    58
	The class has no public constructor. TTypeUid::MakePtr() or TTypeUid::Null() 
williamr@2
    59
	must be used to construct instances of this class. */
williamr@2
    60
		{
williamr@2
    61
		friend class TTypeUid;
williamr@2
    62
	private:
williamr@2
    63
		explicit inline Ptr(TAny* aPtr)
williamr@2
    64
			: iPtr(aPtr)
williamr@2
    65
			{}
williamr@2
    66
	public:
williamr@2
    67
		inline TAny* Pointer() const
williamr@2
    68
		/** Retrieves the pointer to an object which is encapsulated by the Ptr.
williamr@2
    69
	
williamr@2
    70
		@return A pointer to an object. */
williamr@2
    71
			{return iPtr;}
williamr@2
    72
	private:
williamr@2
    73
		TAny* iPtr;
williamr@2
    74
		};
williamr@2
    75
public:
williamr@2
    76
	inline TTypeUid(TInt aUid)
williamr@2
    77
	/** Constructor that takes a Uid value.
williamr@2
    78
	
williamr@2
    79
	@param aUid The Uid value that defines the type of object that an object provider 
williamr@2
    80
	is to get. */
williamr@2
    81
		{ iUid = aUid; }
williamr@2
    82
	inline static Ptr Null()
williamr@2
    83
	/** Constructs a Ptr which encapsulates a NULL pointer.
williamr@2
    84
	
williamr@2
    85
	@return The constructed Ptr object */
williamr@2
    86
		{ return Ptr(NULL); }
williamr@2
    87
	template <class T> inline Ptr MakePtr(T* aT) const
williamr@2
    88
	/** Constructs a Ptr which encapsulates the specified object pointer.
williamr@2
    89
	
williamr@2
    90
	@param aT A pointer to the object which is to be encapsulated.
williamr@2
    91
	@return The constructed Ptr object */
williamr@2
    92
		{ __ASSERT_DEBUG(iUid == T::ETypeId,User::Invariant()); return Ptr(aT); }
williamr@2
    93
	};
williamr@2
    94
williamr@2
    95
williamr@2
    96
class MObjectProvider
williamr@2
    97
/** An interface that allows an object to be part of a network of object providers.
williamr@2
    98
williamr@2
    99
The object provider mechanism can be used to find and access objects of a 
williamr@2
   100
given type, where the type is defined by a TTypeUid object. Object providers 
williamr@2
   101
may be arranged in a hierarchy, i.e. an object provider may have a parent-child 
williamr@2
   102
relationship with another object provider.
williamr@2
   103
williamr@2
   104
An object provider must provide an implementation for the MopSupplyObject() 
williamr@2
   105
function and can choose to provide an implementation for the MopNext() function. 
williamr@2
   106
Typically, it will also have functionality to define who its parent is.
williamr@2
   107
williamr@2
   108
CCoeControl is an example of a class that implements this interface. Top level 
williamr@2
   109
controls must have the view or app UI set as their object provider. This is 
williamr@2
   110
done by calling CCoeControl::SetMopParent() on the view or the app UI. The 
williamr@2
   111
view or app UI does this by calling the top level control's CCoeControl::SetMopParent() 
williamr@2
   112
function. 
williamr@2
   113
williamr@2
   114
@publishedAll 
williamr@2
   115
@released */
williamr@2
   116
	{
williamr@2
   117
public:
williamr@2
   118
	template<class T>
williamr@2
   119
	T* MopGetObject(T*& aPtr) 
williamr@2
   120
	/** Gets an object of the type defined by the template parameter.
williamr@2
   121
	
williamr@2
   122
	The object may be supplied directly by this object provider, or by other object 
williamr@2
   123
	providers higher up the hierarchy.
williamr@2
   124
	
williamr@2
   125
	@param aPtr A reference to a pointer to an object of a type that is to be 
williamr@2
   126
	retrieved.
williamr@2
   127
	@return A pointer to an object of the type required, or NULL if none can be 
williamr@2
   128
	found. */
williamr@2
   129
		{ return (aPtr=(T*)MopGetById(T::ETypeId)); }
williamr@2
   130
		
williamr@2
   131
	
williamr@2
   132
	template<class T>	
williamr@2
   133
	T*  MopGetObjectNoChaining(T*& aPtr)
williamr@2
   134
	/** Gets an object of the type defined by the template parameter.
williamr@2
   135
	
williamr@2
   136
	The object will be supplied directly by this object provider, or NULL 
williamr@2
   137
	will be returned, this function does not recurse through the object chain.
williamr@2
   138
		
williamr@2
   139
	@param aPtr A reference to a pointer to an object of a type that is to be 
williamr@2
   140
	retrieved.
williamr@2
   141
	@return A pointer to an object of the type required, or NULL if none can be 
williamr@2
   142
	found. */
williamr@2
   143
		{ return (aPtr=(T*)MopGetByIdNoChaining(T::ETypeId)); }
williamr@2
   144
	
williamr@2
   145
	/**
williamr@2
   146
	@publishedAll 
williamr@2
   147
	@released */
williamr@2
   148
	MObjectProvider* FindParent(MObjectProvider* aMopToFind);
williamr@2
   149
	
williamr@2
   150
private: // must be overridden
williamr@2
   151
	/** Gets an object whose type is encapsulated by the specified TTypeUid object.
williamr@2
   152
williamr@2
   153
	@param aId Encapsulates the Uid that identifies the type of object required.
williamr@2
   154
	@return Encapsulates the pointer to the object provided. 
williamr@2
   155
	Note that the encapsulated pointer may be NULL.
williamr@2
   156
williamr@2
   157
	@publishedAll 
williamr@2
   158
	@released */
williamr@2
   159
	virtual TTypeUid::Ptr MopSupplyObject(TTypeUid aId) = 0;
williamr@2
   160
williamr@2
   161
protected:
williamr@2
   162
	IMPORT_C MObjectProvider();
williamr@2
   163
williamr@2
   164
private: // may be overridden to continue chain of responsibility
williamr@2
   165
	/**
williamr@2
   166
	@publishedAll 
williamr@2
   167
	@released */
williamr@2
   168
	IMPORT_C virtual MObjectProvider* MopNext();
williamr@2
   169
	IMPORT_C virtual void MObjectProvider_Reserved1();
williamr@2
   170
	IMPORT_C virtual void MObjectProvider_Reserved2();
williamr@2
   171
williamr@2
   172
private: 
williamr@2
   173
	IMPORT_C TAny* MopGetById(TTypeUid aId);
williamr@2
   174
	IMPORT_C TAny* MopGetByIdNoChaining(TTypeUid aId);
williamr@2
   175
	
williamr@2
   176
private:
williamr@2
   177
	TInt iMObjectProvider_Reserved1;
williamr@2
   178
	};
williamr@2
   179
williamr@2
   180
#endif	// __COEMOP_H__