mmappfw_plat/mpx_common_definition_api/inc/mpxcmn.h
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Common utility functions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MPXCMN_H
       
    20 #define MPXCMN_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 #include <bamdesca.h>
       
    26 #include <badesca.h> 
       
    27 #include <s32mem.h>
       
    28 #include <mpxuser.h>
       
    29 #include <mpxsession.h>
       
    30 #include <mpxcommonframeworkdefs.h>
       
    31 
       
    32 /**
       
    33 * Helper to copy an array.
       
    34 *
       
    35 * @since S60 3.2.3
       
    36 * @param aSrc soure
       
    37 * @param sDest destination
       
    38 */ 
       
    39 template<typename T> 
       
    40 inline void CopyArrayL(const TArray<T>& aSrc, RArray<T>& aDest);
       
    41 
       
    42 /**
       
    43 * Helper to copy a descriptor array.
       
    44 *
       
    45 * @since S60 3.2.3
       
    46 * @param aSrc soure
       
    47 * @param sDest destination
       
    48 */ 
       
    49 inline void CopyArrayL(const MDesCArray& aSrc, CDesCArray& aDest);
       
    50 
       
    51 /**
       
    52 * Helper to transfer a buffer from server.
       
    53 *
       
    54 * @since S60 3.2.3
       
    55 * @param aSess session object
       
    56 * @param aCmd Cmd to read buffer from server
       
    57 * @param aSize size of buffer
       
    58 * @param aBuffer buffer to returned
       
    59 */ 
       
    60 inline void TransferBufferFromServerL(const RMPXSession& aSess, 
       
    61                                       TInt aCmd, 
       
    62                                       TInt aSize,
       
    63                                       CBufBase*& aBuffer);
       
    64 
       
    65 /**
       
    66 * Helper to create an array from stream.
       
    67 * Note: class T should public default C++ constructor.
       
    68 * 
       
    69 * @since S60 3.2.3
       
    70 * @param aArray array object returned
       
    71 * @param aStream stream object
       
    72 */ 
       
    73 template<typename T> 
       
    74 inline void InternalizeL(RPointerArray<T>& aArray, RReadStream& aStream);
       
    75 
       
    76 /**
       
    77 * Helper to create an array from stream.
       
    78 * Note: CBased class T contains NewL().
       
    79 * 
       
    80 * @since S60 3.2.3
       
    81 * @param aArray array object returned
       
    82 * @param aStream stream object
       
    83 */ 
       
    84 template<typename T> 
       
    85 inline void InternalizeCObjectArrayL(RPointerArray<T>& aArray, 
       
    86                                      RReadStream& aStream);
       
    87 
       
    88 /**
       
    89 * Helper to create an array from stream.
       
    90 *
       
    91 * @since S60 3.2.3
       
    92 * @param aArray array object returned
       
    93 * @param aStream stream object
       
    94 */ 
       
    95 template<typename T> 
       
    96 inline void InternalizeL(RArray<T>& aArray, RReadStream& aStream);
       
    97 
       
    98 /**
       
    99 * Helper to create a descriptor array from stream.
       
   100 *
       
   101 * @since S60 3.2.3
       
   102 * @param aArray descriptor array object returned
       
   103 * @param aStream stream object
       
   104 */ 
       
   105 inline void InternalizeL(CDesCArray& aArray, RReadStream& aStream);
       
   106 
       
   107 /**
       
   108 * Helper to externalize an array to stream.
       
   109 *
       
   110 * @since S60 3.2.3
       
   111 * @param aArray array object 
       
   112 * @param aStream stream object
       
   113 */ 
       
   114 template<typename T> 
       
   115 inline void ExternalizeL(const TArray<T*>& aArray, RWriteStream& aStream);
       
   116 
       
   117 /**
       
   118 * Helper to externalize an array to stream.
       
   119 *
       
   120 * @since S60 3.2.3
       
   121 * @param aArray array object 
       
   122 * @param aStream stream object
       
   123 */ 
       
   124 template<typename T> 
       
   125 inline void ExternalizeL(const TArray<T>& aArray, RWriteStream& aStream);
       
   126 
       
   127 /**
       
   128 * Helper to externalize a descriptor array to stream.
       
   129 *
       
   130 * @since S60 3.2.3
       
   131 * @param aArray descriptor array object 
       
   132 * @param aStream stream object
       
   133 */ 
       
   134 inline void ExternalizeL(const MDesCArray& aArray, RWriteStream& aStream);
       
   135 
       
   136 /**
       
   137 * Helper to create an array from buf.
       
   138 *
       
   139 * @since S60 3.2.3
       
   140 * @param aBuf buf object
       
   141 * @param aArray array object returned
       
   142 */ 
       
   143 template<typename T> 
       
   144 inline void CreateFromBufferL(const CBufBase &aBuf, CArrayFix<T>*& aArray);
       
   145 
       
   146 /**
       
   147 * Helper to create a descriptor array from buf.
       
   148 *
       
   149 * @since S60 3.2.3
       
   150 * @param aBuf buf object
       
   151 * @param aArray descriptor array object returned
       
   152 */ 
       
   153 inline void CreateFromBufferL(const CBufBase &aBuf, CDesCArray*& aArray);
       
   154 
       
   155 /**
       
   156 * Helper to create an array from buf.
       
   157 *
       
   158 * @since S60 3.2.3
       
   159 * @param aBuf buf object
       
   160 * @param aArray array object returned
       
   161 */ 
       
   162 template<typename T> 
       
   163 inline void CreateFromBufferL(const CBufBase &aBuf, RPointerArray<T>& aArray);
       
   164 
       
   165 /**
       
   166 * Helper to create an array from buf.
       
   167 *
       
   168 * @since S60 3.2.3
       
   169 * @param aBuf buf object
       
   170 * @param aArray array object returned
       
   171 */ 
       
   172 template<typename T> 
       
   173 inline void CreateFromBufferL(const CBufBase &aBuf, RArray<T>& aArray);
       
   174 
       
   175 /**
       
   176 * Helper to create an object from buf.
       
   177 * Note: use C++ default constructor to create a new object.
       
   178 *
       
   179 * @since S60 3.2.3
       
   180 * @param aBuf buf object
       
   181 * @param aObject created
       
   182 */ 
       
   183 template<typename T>
       
   184 inline void CreateFromBufferL(const CBufBase &aBuf, T*& aObject);
       
   185 
       
   186 /**
       
   187 * Helper to create an object from buf.
       
   188 * Note: class T must implement T::NewL() constructor.
       
   189 *
       
   190 * @since S60 3.2.3
       
   191 * @param aBuf buf object
       
   192 * @param aObject created
       
   193 */ 
       
   194 template<typename T>
       
   195 inline void NewFromBufferL(const CBufBase &aBuf, T*& aObject);
       
   196 
       
   197 
       
   198 /**
       
   199 * Helper to create an object from a message buffer.
       
   200 *
       
   201 * @since S60 3.2.3
       
   202 * @param aMessage the message
       
   203 * @param aMsgSlot message slot index
       
   204 */
       
   205 template<typename T>
       
   206 inline void CreateFromMessageL(const RMessage2& aMessage, 
       
   207                                TInt aMsgSlot,
       
   208                                T*& aObject);
       
   209                               
       
   210 /**
       
   211 * Helper to create an object from a message buffer.
       
   212 * Note: class T must implement T::NewL() constructor.
       
   213 *
       
   214 * @since S60 3.2.3
       
   215 * @param aMessage the message
       
   216 * @param aMsgSlot message slot index
       
   217 */
       
   218 template<typename T>
       
   219 inline void NewFromMessageL(const RMessage2& aMessage, 
       
   220                             TInt aMsgSlot,
       
   221                             T*& aObject);
       
   222 
       
   223 /**
       
   224 * Copy an object into the buffer.
       
   225 *
       
   226 * @since S60 3.2.3
       
   227 * @param aObj the object
       
   228 * @param aBuffer buffer object
       
   229 */
       
   230 template<typename T> 
       
   231 inline void CreateBufferL(const T& aObj, CBufBase*& aBuffer);
       
   232 
       
   233 /**
       
   234 * Fill up the buffer from an array.
       
   235 *
       
   236 * @since S60 3.2.3
       
   237 * @param aArray an array of object
       
   238 * @param aBuffer buffer object
       
   239 */
       
   240 template<typename T> 
       
   241 inline void CreateBufferL(const TArray<T>& aArray, CBufBase*& aBuffer);
       
   242 
       
   243 /**
       
   244 * Fill up the buffer from an array.
       
   245 *
       
   246 * @since S60 3.2.3
       
   247 * @param aArray an array of object pointer
       
   248 * @param aBuffer buffer object
       
   249 */
       
   250 template<typename T> 
       
   251 inline void CreateBufferL(const TArray<T*>& aArray, CBufBase*& aBuffer);
       
   252 
       
   253 /**
       
   254 * Helper to transfer an array from server.
       
   255 *
       
   256 * @since S60 3.2.3
       
   257 * @param aSess session object
       
   258 * @param aCmd Cmd to read buffer from server
       
   259 * @param aSize size of buffer
       
   260 * @param aArray array to returned
       
   261 */ 
       
   262 template<typename T> 
       
   263 void ArrayFromServerL(const RMPXSession& aSess, 
       
   264                       TInt aCmd, 
       
   265                       TInt aSize,
       
   266                       CArrayFixBase*& aArray);
       
   267 
       
   268 /**
       
   269 * Helper to transfer an array from server.
       
   270 *
       
   271 * @since S60 3.2.3
       
   272 * @param aSess session object
       
   273 * @param aCmd Cmd to read buffer from server
       
   274 * @param aSize size of buffer
       
   275 * @param aArray array to returned
       
   276 */ 
       
   277 template<typename T> 
       
   278 void ArrayFromServerL(const RMPXSession& aSess, 
       
   279                       TInt aCmd, 
       
   280                       TInt aSize,
       
   281                       RPointerArray<T>& aArray);
       
   282 
       
   283 /**
       
   284 * Helper to transfer an array from server.
       
   285 *
       
   286 * @since S60 3.2.3
       
   287 * @param aSess session object
       
   288 * @param aCmd Cmd to read buffer from server
       
   289 * @param aSize size of buffer
       
   290 * @param aArray array to returned
       
   291 */ 
       
   292 template<typename T> 
       
   293 void ArrayFromServerL(const RMPXSession& aSess, 
       
   294                       TInt aCmd, 
       
   295                       TInt aSize,
       
   296                       RArray<T>& aArray);
       
   297 
       
   298 /**
       
   299 *  Packages an object of type T into a descriptor and writes back to the 
       
   300 *  client space in message slot aMsgSlot of aMessage.
       
   301 *
       
   302 *  @since S60 3.2.3
       
   303 *  @param aMessage message object
       
   304 *  @param aMsgSlot message slot
       
   305 *  @param aValue value
       
   306 */
       
   307 template<typename T> void WriteL(const RMessage2& aMessage,
       
   308                                  TInt aMsgSlot, T aValue);
       
   309                       
       
   310 /** 
       
   311  * An array of pointers to objects that auto cleanup.
       
   312  *
       
   313  * @lib mpxcommon.lib
       
   314  */
       
   315 template<class T> 
       
   316 class RMPXPointerArray : public RPointerArray<T>
       
   317     {
       
   318  public:
       
   319     /** 
       
   320     * Constructor.
       
   321     *
       
   322     * @since S60 3.2.3
       
   323     */
       
   324     inline RMPXPointerArray();
       
   325 
       
   326     /** 
       
   327     * Closes the array and frees all 
       
   328     * resources (including deleting objects in the array). 
       
   329     *
       
   330     * @since S60 3.2.3
       
   331     */
       
   332     inline void Close();
       
   333 
       
   334     /** 
       
   335     * Destructor.
       
   336     *
       
   337     * @since S60 3.2.3
       
   338     */
       
   339     inline ~RMPXPointerArray();
       
   340     };
       
   341 
       
   342 /**
       
   343 * Helper to delete an item from array.
       
   344 *
       
   345 * @since S60 3.2.3
       
   346 * @param aItem an item in the array to be deleted
       
   347 * @param aArray array object returned
       
   348 */ 
       
   349 template<typename T> 
       
   350 inline void DeleteL(const T* aItem, RPointerArray<T>& aArray);
       
   351 
       
   352 #include "mpxcmn.inl"
       
   353 
       
   354 #endif  // MPXCMN_H
       
   355 
       
   356 // End of File