usbmgmt/usbmgr/host/functiondrivers/ms/msmm/refppnotifier/src/refppnotifier.cpp
changeset 0 c9bc50fca66e
equal deleted inserted replaced
-1:000000000000 0:c9bc50fca66e
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include "refppnotifier.h"
       
    24 #include <ecom/implementationproxy.h>
       
    25 #include "refppnotifier.hrh"
       
    26 #include <techview/eikinfo.h>
       
    27 #include <dialog.rsg>
       
    28 #include <techview/eiklabel.h>
       
    29 #include <usb/hostms/srverr.h>
       
    30 #include <usb/hostms/policypluginnotifier.hrh>
       
    31 const TUid KMsmmRefNotifierChannel = {0x10009D48}; //0x10208C14
       
    32 /**
       
    33   Initialize and put the notifiers in this DLL into the array and return it.
       
    34   
       
    35   @return  CArrayPtr<MEikSrvNotifierBase2>*   The array contents the notifiers in this dll.      
       
    36  */
       
    37 CArrayPtr<MEikSrvNotifierBase2>* NotifierArray()
       
    38     {
       
    39     CArrayPtrFlat<MEikSrvNotifierBase2>* subjects=NULL;
       
    40     TRAPD(err, subjects = new(ELeave) CArrayPtrFlat<MEikSrvNotifierBase2>(1));
       
    41     if( err == KErrNone )
       
    42         {
       
    43         TRAP(err, subjects->AppendL(CMsmmRefPolicyPluginNotifier::NewL()));
       
    44         return(subjects);
       
    45         }
       
    46     else
       
    47         {
       
    48         return NULL;
       
    49         }
       
    50     }
       
    51 
       
    52 //Adding ECOM SUPPORT
       
    53 /**
       
    54   Build up the table contains the implementation ID and the notifier array.
       
    55  */
       
    56 const TImplementationProxy ImplementationTable[] =
       
    57     {
       
    58     IMPLEMENTATION_PROXY_ENTRY(KUidMsmmReferenceNotifierImp, NotifierArray)
       
    59     };
       
    60 
       
    61 /**
       
    62   Initialize and put the notifiers in this DLL into the array and return it.
       
    63   @param  aTableCount    a TInt reference, when return it contains the entry number in the 
       
    64                              array of ImplementationTable[].
       
    65   @return     CArrayPtr<MEikSrvNotifierBase2>*   The table of implementations.      
       
    66  */
       
    67 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
    68     {
       
    69     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
    70     return ImplementationTable;
       
    71     }
       
    72 
       
    73 // Member functions
       
    74 /**
       
    75   Static method to initialize a CMsmmRefPolicyPluginNotifier object. This method may leave. 
       
    76  
       
    77   @return     CMsmmRefPolicyPluginNotifier*   a pointer to an object of CMsmmRefPolicyPluginNotifier
       
    78  */
       
    79 CMsmmRefPolicyPluginNotifier* CMsmmRefPolicyPluginNotifier::NewL()
       
    80     {
       
    81     CMsmmRefPolicyPluginNotifier* self = CMsmmRefPolicyPluginNotifier::NewLC();
       
    82     CleanupStack::Pop(self);
       
    83     return self;
       
    84     }
       
    85 /**
       
    86   Static method to initialize a CMsmmRefPolicyPluginNotifier object. This method may leave. 
       
    87 
       
    88   @return     CMsmmRefPolicyPluginNotifier*   a pointer to an object of CMsmmRefPolicyPluginNotifier
       
    89  */
       
    90 CMsmmRefPolicyPluginNotifier* CMsmmRefPolicyPluginNotifier::NewLC()
       
    91     {
       
    92     CMsmmRefPolicyPluginNotifier* self = new (ELeave) CMsmmRefPolicyPluginNotifier();
       
    93     CleanupStack::PushL(self);
       
    94     self->ConstructL();
       
    95     return self;
       
    96     }
       
    97 /**
       
    98   Constructor.
       
    99  */
       
   100 CMsmmRefPolicyPluginNotifier::CMsmmRefPolicyPluginNotifier():iDialogIsVisible(EFalse),iDialogPtr(0)
       
   101     {
       
   102     iCoeEnv = CCoeEnv::Static();
       
   103     }
       
   104 
       
   105 /**
       
   106   Destructor.
       
   107  */
       
   108 CMsmmRefPolicyPluginNotifier::~CMsmmRefPolicyPluginNotifier()
       
   109     {
       
   110     iCoeEnv->DeleteResourceFile(iOffset);    
       
   111     if (iDialogIsVisible)
       
   112     	{
       
   113     	delete iDialogPtr;
       
   114     	}
       
   115     }
       
   116 
       
   117 /**
       
   118   This method is called when client of this notifier disconnect from notify server.
       
   119  */
       
   120 void CMsmmRefPolicyPluginNotifier::Release()
       
   121     {
       
   122     delete this;
       
   123     }
       
   124 
       
   125 /**
       
   126   This method is called when notify server starts and get all the plug-ins of notifiers.
       
   127   By calling this method notify server knows the ID, channel and priority of this notifier.
       
   128  */
       
   129 MEikSrvNotifierBase2::TNotifierInfo CMsmmRefPolicyPluginNotifier::RegisterL()
       
   130     {
       
   131     iInfo.iUid      = TUid::Uid(KUidMountPolicyNotifier);
       
   132     iInfo.iChannel  = KMsmmRefNotifierChannel;
       
   133     iInfo.iPriority = ENotifierPriorityLow;
       
   134     return iInfo;
       
   135     }
       
   136 
       
   137 /**
       
   138   This method just returns the same TNotifierInfo as it is in RegisterL().
       
   139  */
       
   140 MEikSrvNotifierBase2::TNotifierInfo CMsmmRefPolicyPluginNotifier::Info() const
       
   141     {
       
   142     return iInfo;
       
   143     }
       
   144 
       
   145 /**
       
   146   Starts the notifier.
       
   147 
       
   148    This is called as a result of a client-side call to RNotifier::StartNotifier(), 
       
   149    which the client uses to start a notifier from which it does not expect a response.
       
   150 
       
   151    The function is synchronous, but it should be implemented so that it completes as 
       
   152    soon as possible, allowing the notifier framework to enforce its priority mechanism.
       
   153 
       
   154    It is not possible to to wait for a notifier to complete before returning from this
       
   155    function unless the notifier is likely to finish implementing its functionality immediately.
       
   156 
       
   157   @param   aBuffer    the message sent from client.
       
   158 
       
   159   @return      TPtrC8     Defines an empty or null literal descriptor 
       
   160                           for use with 8-bit descriptors
       
   161  */
       
   162 TPtrC8 CMsmmRefPolicyPluginNotifier::StartL(const TDesC8& /*aBuffer*/)
       
   163     {
       
   164     return KNullDesC8();
       
   165     }
       
   166 /**
       
   167   Starts the notifier.
       
   168 
       
   169   This is called as a result of a client-side call to the asynchronous function 
       
   170   RNotifier::StartNotifierAndGetResponse(). This means that the client is waiting, 
       
   171   asynchronously, for the notifier to tell the client that it has finished its work.
       
   172 
       
   173   It is important to return from this function as soon as possible, and derived 
       
   174   classes may find it useful to take a copy of the reply-slot number and the 
       
   175   RMessage object.
       
   176 
       
   177   The implementation of a derived class must make sure that Complete() is called 
       
   178   on the RMessage object when the notifier is deactivated.
       
   179 
       
   180   This function may be called multiple times if more than one client starts 
       
   181   the notifier.
       
   182 
       
   183   @param   aBuffer    Data that can be passed from the client-side. The format 
       
   184                           and meaning of any data is implementation dependent. 
       
   185                           
       
   186               aReplySlot  Identifies which message argument to use for the reply. 
       
   187                           This message argument will refer to a modifiable descriptor, 
       
   188                           a TDes8 type, into which data can be returned. The format and 
       
   189                           meaning of any returned data is implementation dependent.
       
   190                           
       
   191              aMessage     Encapsulates a client request. 
       
   192 */
       
   193 void CMsmmRefPolicyPluginNotifier::StartL(const TDesC8& aBuffer, 
       
   194                                           TInt /*aReplySlot*/, 
       
   195                                           const RMessagePtr2& aMessage)
       
   196     {
       
   197     // extract the notifier request parameters
       
   198     iMessage   = aMessage;
       
   199 
       
   200     const TUint8* Buffer= aBuffer.Ptr();
       
   201     const THostMsErrData* Data = reinterpret_cast<const THostMsErrData*>(Buffer);
       
   202     
       
   203     HBufC16* HeapBuf = HBufC16::NewL(aBuffer.Length());
       
   204     CleanupStack::PushL(HeapBuf);
       
   205     _LIT(KFormat1,"MSMMErr:%d SymbianErr:%d %S %S on Drive %c");
       
   206     TPtr16 PtrBuf = HeapBuf->Des();
       
   207     
       
   208     PtrBuf.Format(KFormat1,Data->iError,Data->iE32Error,&Data->iProductString,&Data->iManufacturerString,Data->iDriveName);
       
   209     
       
   210     if (iDialogIsVisible && iDialogPtr)
       
   211     	{
       
   212     	delete iDialogPtr;
       
   213 	    }
       
   214     iDialogPtr = CRefPPDialog::NewL(&iDialogIsVisible);
       
   215     iDialogPtr->PrepareLC(R_NOTIFIER_DIALOG);
       
   216     CEikLabel *pLabel = static_cast<CEikLabel *> (iDialogPtr->ControlOrNull(EReferencePPNotifierMsg));
       
   217     pLabel->SetTextL(PtrBuf);
       
   218     
       
   219     iDialogPtr->RunLD();
       
   220     iDialogIsVisible = ETrue;
       
   221     
       
   222     CleanupStack::Pop(HeapBuf);
       
   223 
       
   224     // complete    
       
   225     iMessage.Complete(KErrNone);
       
   226     }
       
   227 
       
   228 /**
       
   229   Cancels an active notifier.
       
   230 
       
   231   This is called as a result of a client-side call to RNotifier::CancelNotifier().
       
   232 
       
   233   An implementation should free any relevant resources and complete any outstanding 
       
   234   messages, if relevant. 
       
   235  */
       
   236 void CMsmmRefPolicyPluginNotifier::Cancel()
       
   237     {
       
   238     if (iDialogIsVisible && iDialogPtr)
       
   239 	    {
       
   240     	delete iDialogPtr;
       
   241 	    iDialogPtr = NULL;
       
   242 	    }
       
   243     }
       
   244 
       
   245 /**
       
   246   Updates a currently active notifier with new data.This is called as a result 
       
   247   of a client-side call to RNotifier::UpdateNotifier().
       
   248  
       
   249   @param aBuffer   Data that can be passed from the client-side. The format 
       
   250                        and meaning of any data is implementation dependent. 
       
   251   
       
   252   @return    KNullDesC8()  Defines an empty or null literal descriptor for use 
       
   253                            with 8-bit descriptors.  
       
   254  */
       
   255 TPtrC8 CMsmmRefPolicyPluginNotifier::UpdateL(const TDesC8& /*aBuffer*/)
       
   256     {
       
   257     return KNullDesC8();
       
   258     }
       
   259 /**
       
   260   Second phase construction.
       
   261  */    
       
   262 void CMsmmRefPolicyPluginNotifier::ConstructL()
       
   263     {
       
   264     _LIT(KResFileName,"z:\\resource\\apps\\dialog.rsc");
       
   265     iOffset=iCoeEnv->AddResourceFileL(KResFileName);
       
   266     }
       
   267 
       
   268 // End of file