mmappfw_plat/mpx_common_api/inc/mpxuser.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:  mpx user helper classes
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MPXUSER_H
       
    20 #define MPXUSER_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <e32cmn.h>
       
    24 #include <s32strm.h>
       
    25 #include <badesca.h>
       
    26 #include <w32std.h>
       
    27 #include <mpxitemid.h>
       
    28 
       
    29 // MACRO
       
    30 #if !defined(MPX_ASSERT)
       
    31 _LIT(KMPX, "MPX");
       
    32 _LIT(_KMPXAssertErrorInfo, "**MPX ASSERT**: error %d file %s line %d");
       
    33 #define MPX_ASSERT_S(a) _S(a)
       
    34 #define MPX_ASSERT_ALWAYS(c) {\
       
    35     if (!(c)) {RDebug::Print(_KMPXAssertErrorInfo, 0, MPX_ASSERT_S(__FILE__), __LINE__);\
       
    36     User::Invariant();}\
       
    37     }
       
    38 #define MPX_ASSERT_EX_ALWAYS(c,e) {\
       
    39     if (!(c)) {RDebug::Print(_KMPXAssertErrorInfo, e, MPX_ASSERT_S(__FILE__), __LINE__);\
       
    40     User::Panic(KMPX, (e));}\
       
    41     }
       
    42 #ifdef _DEBUG
       
    43 #define MPX_ASSERT(c) MPX_ASSERT_ALWAYS(c)
       
    44 #define MPX_ASSERT_EX(c,e) MPX_ASSERT_EX_ALWAYS(c,e)
       
    45 #else
       
    46 #define MPX_ASSERT(c)
       
    47 #define MPX_ASSERT_EX(c,e)
       
    48 #endif // _DEBUG
       
    49 #define MPX_ASSERT_WORD_ALIGNED(x) MPX_ASSERT((((TUint)x)&3)==0)
       
    50 #endif // MPX_ASSERT
       
    51 
       
    52 // CONSTANTS
       
    53 const TInt KMPXBufGranularity = 0x100; // 256 bytes
       
    54 
       
    55 // Generic type for voice/video/VOIP calls
       
    56 const TInt KMPXCallTypeGenericVoice( -1 );
       
    57 
       
    58 class CMPXMedia;
       
    59 class TMPXAttribute;
       
    60 
       
    61 
       
    62 /**
       
    63 * Set of static functions for MPX clients.
       
    64 *
       
    65 * @lib MPXCommon.lib
       
    66 */
       
    67 NONSHARABLE_CLASS(MPXUser)
       
    68     {
       
    69 public: // static helper functions
       
    70 
       
    71     /**
       
    72     * Helper to recreate a buffer.
       
    73     *
       
    74     * @since S60 3.2.3
       
    75     * @param aSize the size of buffer
       
    76     * @param aBuf buf object
       
    77     */
       
    78     IMPORT_C static void RecreateBufferL(TInt aSize, CBufBase*& aBuf);
       
    79 
       
    80     /**
       
    81     * Helper to create an descriptor array from buf.
       
    82     *
       
    83     * @since S60 3.2.3
       
    84     * @param aBuf buf object
       
    85     * @param aArray object
       
    86     */
       
    87     IMPORT_C  static void CreateFromBufferL(const CBufBase &aBuf,
       
    88                                             CDesCArray*& aArray);
       
    89     /**
       
    90     * Helper to create a buffer.
       
    91     *
       
    92     * @since S60 3.2.3
       
    93     * @param aSize the size of buffer
       
    94     * @return aBuf buf object
       
    95     */
       
    96     IMPORT_C static CBufBase* CreateBufferLC(TInt aSize);
       
    97 
       
    98     /**
       
    99     * Helper to create a buffer from descriptor array.
       
   100     *
       
   101     * @since S60 3.2.3
       
   102     * @param aArray array object
       
   103     * @param aBuf buf object
       
   104     * @return the size of buffer
       
   105     */
       
   106     IMPORT_C  static void CreateBufferL(const MDesCArray* aArray,
       
   107                                         CBufBase*& aBuf);
       
   108 
       
   109     /**
       
   110     * Fill up the buffer from a message.
       
   111     *
       
   112     * @since S60 3.2.3
       
   113     * @param aMessage the message
       
   114     * @param aMsgSlot message slot index
       
   115     * @param aBuffer buffer object
       
   116     * @leave KErrArgument Invalid Message
       
   117     */
       
   118     IMPORT_C static void CreateBufferL(const RMessage2& aMessage,
       
   119                                        TInt aMsgSlot,
       
   120                                        CBufBase*& aBuffer);
       
   121 
       
   122     /**
       
   123     * Fill up the buffer from a desriptormessage.
       
   124     *
       
   125     * @since S60 3.2.3
       
   126     * @param aDes descriptor
       
   127     * @param aBuffer buffer object
       
   128     */
       
   129     IMPORT_C static void CreateBufferL(const TDesC& aDes,
       
   130                                        CBufBase*& aBuffer);
       
   131 
       
   132     /**
       
   133     * Creates a narrow heap descriptor from a unicode descriptor.
       
   134     * No character conversion.
       
   135     *
       
   136     * @since S60 3.2.3
       
   137     * @param aDes source data
       
   138     * @return new heap buffer object
       
   139     */
       
   140     IMPORT_C static HBufC8* Alloc8L(const TDesC& aDes);
       
   141 
       
   142     /**
       
   143     * Creates a zero-terminated narrow heap descriptor from a unicode descriptor.
       
   144     * No character conversion.
       
   145     *
       
   146     * @since S60 3.2.3
       
   147     * @param aDes source data
       
   148     * @return new heap buffer object
       
   149     */
       
   150     IMPORT_C static HBufC8* Alloc8ZL(const TDesC& aDes);
       
   151 
       
   152     /**
       
   153     * Creates a heap descriptor from a narrow descriptor.
       
   154     * No character conversion.
       
   155     *
       
   156     * @since S60 3.2.3
       
   157     * @param aDes source data
       
   158     * @return new heap buffer object
       
   159     */
       
   160     IMPORT_C static HBufC* AllocL(const TDesC8& aDes);
       
   161 
       
   162     /**
       
   163     * Creates a narrow ptr descriptor on a unicode descriptor.
       
   164     *
       
   165     * @since S60 3.2.3
       
   166     * @param aDes source data
       
   167     * @return ptr descriptor
       
   168     */
       
   169     IMPORT_C static TPtrC8 Ptr(const TDesC& aDes);
       
   170 
       
   171     /**
       
   172     * Creates a unicode ptr descriptor on a narrow descriptor.
       
   173     *
       
   174     * @since S60 3.2.3
       
   175     * @param aDes source data
       
   176     * @return ptr descriptor
       
   177     */
       
   178     IMPORT_C static TPtrC Ptr(const TDesC8& aDes);
       
   179 
       
   180     /**
       
   181     * Internalize a descriptor from a stream.
       
   182     *
       
   183     * @since S60 3.2.3
       
   184     * @param aArray descriptor array
       
   185     * @param aStream stream object
       
   186     */
       
   187     IMPORT_C static void InternalizeL(CDesCArray*& aArray,
       
   188                                       RReadStream& aStream);
       
   189 
       
   190     /**
       
   191     * Externalize a descriptor to a stream.
       
   192     *
       
   193     * @since S60 3.2.3
       
   194     * @param aArray descriptor array
       
   195     * @param aStream stream object
       
   196     */
       
   197     IMPORT_C static void ExternalizeL(const MDesCArray* aArray,
       
   198                                       RWriteStream& aStream);
       
   199 
       
   200     /**
       
   201     * Group attributes belonging to one content into an item in the array.
       
   202     *
       
   203     * @since S60 3.2.3
       
   204     * @param aSrc attribute array source
       
   205     * @param aDest array with attributes merged
       
   206     */
       
   207     IMPORT_C static void MergeAttributeL(const TArray<TMPXAttribute>& aSrc,
       
   208                                          RArray<TMPXAttribute>& aDest);
       
   209 
       
   210     /**
       
   211     *  Return Process Id.
       
   212     *
       
   213     *  @since S60 3.2.3
       
   214     *  @param aId thread id of the client
       
   215     *  @return  id of the process which owns the thread
       
   216     */
       
   217     IMPORT_C static TProcessId ProcessIdL(TThreadId aId);
       
   218 
       
   219     /**
       
   220     *  Add array items in aSrc into sorted array aDest if the item is not in
       
   221     *  the aDest yet. 
       
   222     *
       
   223     *  @since S60 3.2.3
       
   224     *  @param aSrc souce array
       
   225     *  @param aDest destination array
       
   226     */
       
   227     IMPORT_C static void MergeArray(const MDesCArray& aSrc, CDesCArray& aDest);
       
   228 
       
   229     /**
       
   230      *  Copies elements from one array of descriptors to another.
       
   231      *
       
   232      *  @since S60 3.2.3
       
   233      *  @param aSrc souce array
       
   234      *  @param aDest destination array
       
   235      */
       
   236     IMPORT_C static void CopyArrayL(const MDesCArray& aSrc, CDesCArray& aDest);
       
   237 
       
   238     /**
       
   239      *  Compare two uids.
       
   240      *
       
   241      *  @since S60 3.2.3
       
   242      *  @param aId1 the first uid
       
   243      *  @param aId2 the second uid
       
   244      *  @return zero if the two uids are equal.
       
   245      *        a negative value(-1), if the first uid is less than the second.
       
   246      *        a positive value(1),  if the first uid is greater than the second.
       
   247      */
       
   248     IMPORT_C static TInt CompareUids(const TUid& aId1, const TUid& aId2);
       
   249 
       
   250     /**
       
   251      *  Compare two sorted arrays of uids.
       
   252      *
       
   253      *  @since S60 3.2.3
       
   254      *  @param aArray1 the first array of uids
       
   255      *  @param aArray2 the second array of uids
       
   256      *  @return zero if the content of two arrays are equal.
       
   257      *        a positive value(1),  if the ids count in the first array is
       
   258      *        more than the second's and the first array contains all of uids
       
   259      *        in the second array.
       
   260      *        otherwise, -1 returned.
       
   261      */
       
   262     IMPORT_C static TInt CompareOrderedUidArrays(const TArray<TUid>& aArray1,
       
   263                                                  const TArray<TUid>& aArray2);
       
   264 
       
   265     /**
       
   266     * Helper to create an array from stream.
       
   267     *
       
   268     * @since S60 3.2.3
       
   269     * @param aArray array object returned
       
   270     * @param aStream stream object
       
   271     */
       
   272     IMPORT_C static void InternalizeL(RArray<TMPXItemId>& aArray, RReadStream& aStream);
       
   273 
       
   274     /**
       
   275     * Helper to externalize an array to stream.
       
   276     *
       
   277     * @since S60 3.2.3
       
   278     * @param aArray array object
       
   279     * @param aStream stream object
       
   280     */
       
   281     IMPORT_C static void ExternalizeL(const TArray<TMPXItemId>& aArray, RWriteStream& aStream);
       
   282 
       
   283     /**
       
   284     * Helper to get the window group ID associated with a process.
       
   285     *
       
   286     * @since S60 3.2.3
       
   287     * @param aProcId process ID
       
   288     * @return The Window Group ID associated with this process.  Or KErrNotFound if there is none.
       
   289     */
       
   290     IMPORT_C static TInt FindWindowGroupIdL( TProcessId aProcId, RWsSession& aWsSession );
       
   291 
       
   292     /**
       
   293     * Check if there is the given type call ongoing.
       
   294     *
       
   295     * @since S60 3.2.3
       
   296     * @param aCallType Call type defined in TPSTelephonyCallState
       
   297     * @return ETrue if there is ongoing calls.  EFalse otherwise.
       
   298     */
       
   299     IMPORT_C static TBool IsCallOngoing( TInt aCallType );
       
   300 
       
   301     /**
       
   302      * Complete file name with file path of dll.
       
   303      *
       
   304      * @since S60 3.2.3
       
   305      * @param aFileName file name will be completed with dll's path
       
   306      * @return error code if an error occured. In case of an error aFileName will
       
   307      *         not be changed
       
   308      */
       
   309     IMPORT_C static TInt CompleteWithDllPath(const TDesC& aDllName, TDes& aFileName);
       
   310 
       
   311     /**
       
   312      * Helper method to complete file name with file path of dll.
       
   313      *
       
   314      * @since S60 3.2.3
       
   315      * @param aFileName file name will be completed with dll's path
       
   316      * @return error code if an error occured. In case of an error aFileName will
       
   317      *         not be changed
       
   318      */
       
   319     inline static TInt CompleteWithDllPath(TDes& aFileName)
       
   320         {
       
   321         TFileName dllName;
       
   322         Dll::FileName(dllName);
       
   323         return CompleteWithDllPath(dllName, aFileName);
       
   324         }
       
   325     };
       
   326 #endif   // MPXUSER_H
       
   327 
       
   328 // End of File