datacommsserver/esockserver/inc/ss_rmetaextensioncontainer.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // ss_rmetaextensioncontainer.h
       
    15 // 
       
    16 
       
    17 /**
       
    18 @file
       
    19 @prototype 
       
    20 @publishedPartner 
       
    21 */
       
    22 
       
    23 #ifndef SYMBIAN_SS_RMETAEXTENSIONCONTAINER
       
    24 #define SYMBIAN_SS_RMETAEXTENSIONCONTAINER
       
    25 
       
    26 #include <e32cmn.h>
       
    27 #include <elements/metadata.h>
       
    28 
       
    29 
       
    30 #ifdef MEC_UNITTEST
       
    31 class TMetaExtensionContainerSpy;
       
    32 #endif
       
    33 
       
    34 namespace ESock
       
    35 {
       
    36 
       
    37 class CMetaExtensionContainerImplBase;
       
    38 class CMetaExtensionContainer;
       
    39 class CMetaExtensionContainerArray;
       
    40 class TMetaExtensionContainerMetaType;
       
    41 
       
    42 
       
    43 enum TMecPanic
       
    44     {
       
    45     ENoImplementation = 1,      // No implementation opened for the RMEC instance
       
    46     EInvalidSelfReference = 2,  // Trying to open an RMEC using itself as the source RMEC 
       
    47     EAlreadyOpen = 3,           // Trying to open a reference against a new RMEC without closing this one
       
    48     EUsingEmptyContainer = 4,   // An explicit attempt was made to open an RMEC which was created with no extensions (wasteful - RMECs should always hold something of value)
       
    49     EIllegalState = 5, 			// Should never happen. Indicates bad logic or bad code.
       
    50     };
       
    51 
       
    52 /**
       
    53 Represents a read only meta extension container.
       
    54 
       
    55 @prototype
       
    56 @publishedPartner
       
    57 */
       
    58 class RMetaExtensionContainerC
       
    59 	{
       
    60 #ifdef MEC_UNITTEST
       
    61 	friend class ::TMetaExtensionContainerSpy;
       
    62 #endif
       
    63 	friend class ESock::TMetaExtensionContainerMetaType;
       
    64 
       
    65 public:
       
    66     /**
       
    67     Default c'tor. 
       
    68     */
       
    69     IMPORT_C RMetaExtensionContainerC();
       
    70     
       
    71     /**
       
    72     D'tor
       
    73     */
       
    74     IMPORT_C ~RMetaExtensionContainerC();
       
    75 
       
    76     /**
       
    77     Opens a reference against a specific container. This RMetaExtensionContainerC must not be open already.
       
    78     @param aSource Container to open this instance against. A reference will be automatically added to the source container.
       
    79     */
       
    80     IMPORT_C void Open(const RMetaExtensionContainerC& aSource);
       
    81     
       
    82     /**
       
    83 	Releases a reference to the underlying container implementation
       
    84 	*/
       
    85 	IMPORT_C void Close();
       
    86 
       
    87 	/**
       
    88 	Finds the extension specified within the container
       
    89 	@param aTypeId The STypeId of the meta extension to find
       
    90 	@return A pointer to the meta extension or NULL if it wasn't found
       
    91 	*/
       
    92 	IMPORT_C const Meta::SMetaData* FindExtension(const Meta::STypeId& aTypeId) const;
       
    93 
       
    94 	/**
       
    95 	Finds the extension specified within the container
       
    96 	@param aTypeId The STypeId of the meta extension to find
       
    97 	@return A reference to the meta extension
       
    98 	@exception Leaves with KErrNotFound if the meta extension was not present in the container
       
    99 	*/
       
   100 	IMPORT_C const Meta::SMetaData& FindExtensionL(const Meta::STypeId& aTypeId) const;
       
   101 	
       
   102 protected:
       
   103     /**
       
   104     Opens an additional reference to the underlying container implementation.
       
   105     */
       
   106     IMPORT_C void Open();
       
   107 
       
   108     /**
       
   109 	Returns a pointer to the container implementation being represented by this interface
       
   110 	@internalTechnology
       
   111 	*/
       
   112 	inline CMetaExtensionContainerImplBase* Container() const;
       
   113 
       
   114 	/**
       
   115 	Sets the initial container implementation to be represented by this interface
       
   116 	@internalTechnology
       
   117 	*/
       
   118 	inline void SetContainer(CMetaExtensionContainerImplBase* aContainer);
       
   119         
       
   120 private:
       
   121 	// A pointer to the container implementation
       
   122 	mutable CMetaExtensionContainerImplBase* iContainerImpl;
       
   123 	};
       
   124 
       
   125 
       
   126 /**
       
   127 Represents an appendable meta extension container.
       
   128 @prototype
       
   129 @publishedPartner
       
   130 */
       
   131 class RMetaExtensionContainer : public RMetaExtensionContainerC
       
   132 	{
       
   133 #ifdef MEC_UNITTEST
       
   134     friend class ::TMetaExtensionContainerSpy;
       
   135 #endif
       
   136 
       
   137 public:
       
   138     /**
       
   139     Default c'tor
       
   140     */
       
   141     IMPORT_C RMetaExtensionContainer();
       
   142     
       
   143     /**
       
   144     If the container is already open a reference is added to the container.
       
   145     If the container is not open a new appendable root meta extension container will be created and a reference added.
       
   146     */
       
   147     IMPORT_C void Open();
       
   148 
       
   149     /**
       
   150     A new appendable meta extension container will be created using the supplied container as the base container to build on.
       
   151 	The container must not already be open.
       
   152 	@param aBaseContainer Container to use as the base meta extension container. A reference will be automatically added to this.
       
   153 	*/
       
   154 	IMPORT_C void Open(const RMetaExtensionContainerC& aBaseContainer);
       
   155 	
       
   156     /**
       
   157     Releases a reference to the underlying container implementation
       
   158     */
       
   159     IMPORT_C void Close();
       
   160     
       
   161 	/**
       
   162 	Finds the extension specified within the container
       
   163 	@param aTypeId The STypeId of the meta extension to find
       
   164 	@return A pointer to the meta extension or NULL if it wasn't found
       
   165 	*/
       
   166 	IMPORT_C const Meta::SMetaData* FindExtension(const Meta::STypeId& aTypeId) const;
       
   167 
       
   168 	/**
       
   169 	Finds the extension specified within the container
       
   170 	@param aTypeId The STypeId of the meta extension to find
       
   171 	@return A reference to the meta extension
       
   172 	@exception Leaves with KErrNotFound if the meta extension was not present in the container
       
   173 	*/
       
   174 	IMPORT_C const Meta::SMetaData& FindExtensionL(const Meta::STypeId& aTypeId) const;
       
   175 	
       
   176 	/**
       
   177 	Adds a meta extension to the container, which will take ownership on success.
       
   178 	@param aExtension The meta extension to add
       
   179 	@return KErrAlreadyExists If a meta extension of the same type is in the container
       
   180 			KErrNone If the meta extension was added successfully
       
   181 			Other system-wide error codes
       
   182 	*/
       
   183 	IMPORT_C TInt AppendExtension(const Meta::SMetaData* aExtension);
       
   184 
       
   185 	/**
       
   186 	Adds a meta extension to the container, which will take ownership on success.
       
   187 	@param aExtension The meta extension to add
       
   188 	@exception Leaves with KErrAlreadyExists If a meta extension of the same type is in the container,
       
   189 			or other system-wide error codes
       
   190 	*/
       
   191 	IMPORT_C void AppendExtensionL(const Meta::SMetaData* aExtension);
       
   192 
       
   193 	/**
       
   194 	Appends a container to the list of container implementations.
       
   195 	@aBaseContainer Appends an existing container. Extensions in aBaseContainer container will override
       
   196 	any extensions of the same type already present in the container this method is called on.
       
   197 	@exception Leaves with KErrNone on success, 
       
   198 			KErrAlreadyExists if the container is already present, 
       
   199 			or any other system-wide error code.
       
   200 	*/
       
   201 	IMPORT_C void AppendContainerL(const RMetaExtensionContainerC& aBaseContainer);
       
   202 
       
   203 private:
       
   204 	/**
       
   205 	@return Returns an implementation of an appendable extension container instance or
       
   206 	NULL if one isn't available at present
       
   207 	*/
       
   208 	CMetaExtensionContainer* AppendableExtensionContainer() const;
       
   209 	
       
   210 	/**
       
   211 	@return Returns an implementation of an appendable container array instance or
       
   212 	NULL if one isn't available at present
       
   213 	*/
       
   214 	CMetaExtensionContainerArray* AppendableContainerArray() const;
       
   215 
       
   216 	/**
       
   217     Creates a new container implementations
       
   218     @exception Any system wide error code
       
   219     */
       
   220     void CreateExtensionContainerL();
       
   221 
       
   222 	/**
       
   223     Creates a new container implementations
       
   224     @exception Any system wide error code
       
   225     */
       
   226     void CreateContainerArrayL();
       
   227 
       
   228 private:
       
   229     TBool iIsLazyCreationDone:1; // Used for lazy creation of the container impl.
       
   230 	TBool iIsOpen:1;
       
   231     mutable CMetaExtensionContainer* iCurrentExtensionContainer;	// Not owned
       
   232 	};
       
   233 
       
   234 
       
   235 
       
   236 /**
       
   237 @internalTechnology
       
   238 */
       
   239 CMetaExtensionContainerImplBase* RMetaExtensionContainerC::Container() const
       
   240 	{
       
   241 	return iContainerImpl;
       
   242     }
       
   243 
       
   244 
       
   245 /**
       
   246 @internalTechnology
       
   247 */
       
   248 inline void RMetaExtensionContainerC::SetContainer(CMetaExtensionContainerImplBase* aContainer)
       
   249 	{
       
   250 	ASSERT(aContainer);		 // Don't allow setting it to NULL
       
   251 	iContainerImpl = aContainer;
       
   252 	}
       
   253 
       
   254 
       
   255 
       
   256 } // namespace ESock
       
   257 
       
   258 #endif
       
   259 // SYMBIAN_SS_RMETAEXTENSIONCONTAINER
       
   260