1.1 --- a/epoc32/include/coemop.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/coemop.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,180 @@
1.4 -coemop.h
1.5 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +// All rights reserved.
1.7 +// This component and the accompanying materials are made available
1.8 +// 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
1.9 +// which accompanies this distribution, and is available
1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.11 +//
1.12 +// Initial Contributors:
1.13 +// Nokia Corporation - initial contribution.
1.14 +//
1.15 +// Contributors:
1.16 +//
1.17 +// Description:
1.18 +//
1.19 +
1.20 +#ifndef __COEMOP_H__
1.21 +#define __COEMOP_H__
1.22 +
1.23 +#include <e32std.h>
1.24 +
1.25 +/** Declares an object type, ETypeId, for a class, in order to allow the object
1.26 +provider mechanism to locate and provide objects from the class.
1.27 +
1.28 +@publishedAll
1.29 +@released
1.30 +@see MObjectProvider */
1.31 +#define DECLARE_TYPE_ID(id) enum { ETypeId = id };
1.32 +
1.33 +//
1.34 +// Used to wrap object type IDs in a standardised manner. Object type IDs must be asserted
1.35 +// in an ETypeId member data property by any types of object which
1.36 +// are capable of being retrieved by the MObjectProvider interface
1.37 +//
1.38 +class TTypeUid : public TUid
1.39 +/** Part of the object provider mechanism, this class encapsulates the Uid that
1.40 +identifies the type of object that an object provider is to get.
1.41 +
1.42 +The class is also used to encapsulate a pointer to the object that the object
1.43 +provider has found.
1.44 +
1.45 +An object that is intended to be capable of being retrieved by the object
1.46 +provider mechanism must include enum {ETypeId = 0xabcdefgh}; in its class
1.47 +definition, where 0xabcdefgh is the Uid value. The macro DECLARE_TYPE_ID can
1.48 +be used to do this.
1.49 +
1.50 +An instance of this class is passed to the MObjectProvider::MopSupplyObject()
1.51 +function implemented by an object provider. A TTypeUid::Ptr is also returned
1.52 +by this function.
1.53 +
1.54 +@publishedAll
1.55 +@released
1.56 +@see MObjectProvider */
1.57 + {
1.58 +public:
1.59 + class Ptr
1.60 + /** Encapsulates a pointer to an object fetched by an object provider.
1.61 +
1.62 + The class has no public constructor. TTypeUid::MakePtr() or TTypeUid::Null()
1.63 + must be used to construct instances of this class. */
1.64 + {
1.65 + friend class TTypeUid;
1.66 + private:
1.67 + explicit inline Ptr(TAny* aPtr)
1.68 + : iPtr(aPtr)
1.69 + {}
1.70 + public:
1.71 + inline TAny* Pointer() const
1.72 + /** Retrieves the pointer to an object which is encapsulated by the Ptr.
1.73 +
1.74 + @return A pointer to an object. */
1.75 + {return iPtr;}
1.76 + private:
1.77 + TAny* iPtr;
1.78 + };
1.79 +public:
1.80 + inline TTypeUid(TInt aUid)
1.81 + /** Constructor that takes a Uid value.
1.82 +
1.83 + @param aUid The Uid value that defines the type of object that an object provider
1.84 + is to get. */
1.85 + { iUid = aUid; }
1.86 + inline static Ptr Null()
1.87 + /** Constructs a Ptr which encapsulates a NULL pointer.
1.88 +
1.89 + @return The constructed Ptr object */
1.90 + { return Ptr(NULL); }
1.91 + template <class T> inline Ptr MakePtr(T* aT) const
1.92 + /** Constructs a Ptr which encapsulates the specified object pointer.
1.93 +
1.94 + @param aT A pointer to the object which is to be encapsulated.
1.95 + @return The constructed Ptr object */
1.96 + { __ASSERT_DEBUG(iUid == T::ETypeId,User::Invariant()); return Ptr(aT); }
1.97 + };
1.98 +
1.99 +
1.100 +class MObjectProvider
1.101 +/** An interface that allows an object to be part of a network of object providers.
1.102 +
1.103 +The object provider mechanism can be used to find and access objects of a
1.104 +given type, where the type is defined by a TTypeUid object. Object providers
1.105 +may be arranged in a hierarchy, i.e. an object provider may have a parent-child
1.106 +relationship with another object provider.
1.107 +
1.108 +An object provider must provide an implementation for the MopSupplyObject()
1.109 +function and can choose to provide an implementation for the MopNext() function.
1.110 +Typically, it will also have functionality to define who its parent is.
1.111 +
1.112 +CCoeControl is an example of a class that implements this interface. Top level
1.113 +controls must have the view or app UI set as their object provider. This is
1.114 +done by calling CCoeControl::SetMopParent() on the view or the app UI. The
1.115 +view or app UI does this by calling the top level control's CCoeControl::SetMopParent()
1.116 +function.
1.117 +
1.118 +@publishedAll
1.119 +@released */
1.120 + {
1.121 +public:
1.122 + template<class T>
1.123 + T* MopGetObject(T*& aPtr)
1.124 + /** Gets an object of the type defined by the template parameter.
1.125 +
1.126 + The object may be supplied directly by this object provider, or by other object
1.127 + providers higher up the hierarchy.
1.128 +
1.129 + @param aPtr A reference to a pointer to an object of a type that is to be
1.130 + retrieved.
1.131 + @return A pointer to an object of the type required, or NULL if none can be
1.132 + found. */
1.133 + { return (aPtr=(T*)MopGetById(T::ETypeId)); }
1.134 +
1.135 +
1.136 + template<class T>
1.137 + T* MopGetObjectNoChaining(T*& aPtr)
1.138 + /** Gets an object of the type defined by the template parameter.
1.139 +
1.140 + The object will be supplied directly by this object provider, or NULL
1.141 + will be returned, this function does not recurse through the object chain.
1.142 +
1.143 + @param aPtr A reference to a pointer to an object of a type that is to be
1.144 + retrieved.
1.145 + @return A pointer to an object of the type required, or NULL if none can be
1.146 + found. */
1.147 + { return (aPtr=(T*)MopGetByIdNoChaining(T::ETypeId)); }
1.148 +
1.149 + /**
1.150 + @publishedAll
1.151 + @released */
1.152 + MObjectProvider* FindParent(MObjectProvider* aMopToFind);
1.153 +
1.154 +private: // must be overridden
1.155 + /** Gets an object whose type is encapsulated by the specified TTypeUid object.
1.156 +
1.157 + @param aId Encapsulates the Uid that identifies the type of object required.
1.158 + @return Encapsulates the pointer to the object provided.
1.159 + Note that the encapsulated pointer may be NULL.
1.160 +
1.161 + @publishedAll
1.162 + @released */
1.163 + virtual TTypeUid::Ptr MopSupplyObject(TTypeUid aId) = 0;
1.164 +
1.165 +protected:
1.166 + IMPORT_C MObjectProvider();
1.167 +
1.168 +private: // may be overridden to continue chain of responsibility
1.169 + /**
1.170 + @publishedAll
1.171 + @released */
1.172 + IMPORT_C virtual MObjectProvider* MopNext();
1.173 + IMPORT_C virtual void MObjectProvider_Reserved1();
1.174 + IMPORT_C virtual void MObjectProvider_Reserved2();
1.175 +
1.176 +private:
1.177 + IMPORT_C TAny* MopGetById(TTypeUid aId);
1.178 + IMPORT_C TAny* MopGetByIdNoChaining(TTypeUid aId);
1.179 +
1.180 +private:
1.181 + TInt iMObjectProvider_Reserved1;
1.182 + };
1.183 +
1.184 +#endif // __COEMOP_H__