vpnui/vpnecomnotifier/src/vpnecomnotifier.cpp
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2008 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:   VPN Ecom Notifier's implementation file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <eikenv.h>
       
    22 #include <bautils.h>
       
    23 
       
    24 #include "logvpncommon.h"
       
    25 
       
    26 #include <uikon/eiksrvui.h>  // Eikon server ui (for suppressing app -key)
       
    27 
       
    28 #include "vpnecomnotifier.h"
       
    29 
       
    30 #include "vpndialogmanagerecomstub.h"
       
    31 
       
    32 
       
    33 
       
    34 
       
    35 
       
    36 CArrayPtrFlat<MEikSrvNotifierBase2>* createNotifierArrayL()
       
    37     {
       
    38     CArrayPtrFlat<MEikSrvNotifierBase2>* notifierList = new (ELeave) CArrayPtrFlat<MEikSrvNotifierBase2>(2);
       
    39     CleanupStack::PushL(notifierList);
       
    40 
       
    41     CVpnDialogManagerEcomStub* dlgManager = new (ELeave) CVpnDialogManagerEcomStub();
       
    42     CleanupStack::PushL(dlgManager);
       
    43     
       
    44     CVpnNotifier* notifier = new (ELeave) CVpnNotifier(KUidVpnDialogNotifier, 
       
    45                                                        KVpnNotifierResource, 
       
    46                                                        dlgManager);
       
    47     CleanupStack::PushL(notifier);
       
    48     
       
    49     notifierList->AppendL(notifier);
       
    50     
       
    51     CleanupStack::Pop(3); // notifierList, dlgManager, notifier
       
    52     
       
    53     return notifierList;
       
    54     }
       
    55 
       
    56 CArrayPtr<MEikSrvNotifierBase2>* NotifierArray()
       
    57     {
       
    58     CArrayPtrFlat<MEikSrvNotifierBase2>* notifierList = NULL;
       
    59     
       
    60     TRAPD(err, notifierList = createNotifierArrayL()); 
       
    61     if(err)
       
    62         {
       
    63         notifierList->ResetAndDestroy();
       
    64         delete notifierList;
       
    65         notifierList = NULL;
       
    66         }
       
    67            
       
    68     return notifierList;
       
    69     }
       
    70 
       
    71 const TImplementationProxy ImplementationTable[]=
       
    72     {
       
    73     IMPLEMENTATION_PROXY_ENTRY(0x10200EC8, NotifierArray)
       
    74     };
       
    75 
       
    76 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
    77     {
       
    78     aTableCount = sizeof(ImplementationTable)/sizeof(TImplementationProxy);
       
    79     return ImplementationTable;
       
    80     }
       
    81 
       
    82 
       
    83 
       
    84 
       
    85 CVpnNotifier::CVpnNotifier(const TUid& aNotifierUid, const TDesC& aResourceFilename,
       
    86                                CVpnDialogManagerEcomStub* aDialogManager)
       
    87     {
       
    88     LOG_("-> CVpnNotifier::CVpnNotifier()");
       
    89     iEikEnv = CEikonEnv::Static();
       
    90     iNotifierUid = aNotifierUid;
       
    91     iResourceFilename.Set(aResourceFilename);
       
    92     iDialogManager = aDialogManager;
       
    93     // Added to overcome uninstallation problems
       
    94     iResourceFileLoaded = EFalse;
       
    95     LOG_("<- CVpnNotifier::CVpnNotifier()");
       
    96     }
       
    97 
       
    98 CVpnNotifier::~CVpnNotifier()
       
    99     {
       
   100     LOG_("-> CVpnNotifier::~CVpnNotifier()");
       
   101     delete iDialogManager;
       
   102     LOG_("<- CVpnNotifier::~CVpnNotifier()");
       
   103     }
       
   104 
       
   105 CVpnNotifier::TNotifierInfo CVpnNotifier::RegisterL()
       
   106     {
       
   107     LOG_("-> CVpnNotifier::RegisterL()");
       
   108 
       
   109     iInfo.iUid = iNotifierUid;
       
   110     iInfo.iChannel = KCrystalScreenOutputChannel;
       
   111     iInfo.iPriority = ENotifierPriorityLow;
       
   112 
       
   113     LOG_("<- CVpnNotifier::RegisterL()");
       
   114 
       
   115     return iInfo;
       
   116     }
       
   117 
       
   118 // Added to overcome uninstallation problems    
       
   119 void CVpnNotifier::LoadResourceFileL()
       
   120     {
       
   121     LOG_("-> CVpnNotifier::LoadResourceFileL()");
       
   122     if (!iResourceFileLoaded)
       
   123         {
       
   124         TFileName fileName = GetResourceFileNameL();
       
   125         iResourceFileOffset = iEikEnv->AddResourceFileL(fileName);
       
   126         iResourceFileLoaded = ETrue;
       
   127         }
       
   128 
       
   129     LOG_("<- CVpnNotifier::LoadResourceFileL()");
       
   130     }
       
   131 
       
   132 
       
   133 void CVpnNotifier::CloseManagerDll() 
       
   134     {
       
   135     if (iRealDialogManager) 
       
   136         {
       
   137         LOG_(" Closing old dialog manager instance");
       
   138 
       
   139 
       
   140         LOG_(" Deleting");
       
   141         delete iRealDialogManager;
       
   142         iRealDialogManager = NULL;
       
   143 
       
   144         iDialogManager->SetDialogManager(NULL);
       
   145 
       
   146         LOG_(" Closing library");
       
   147 
       
   148         iDialogManagerLib.Close();
       
   149         
       
   150         LOG_(" Close completed");
       
   151         }
       
   152     }
       
   153 
       
   154 // Added to overcome uninstallation problems
       
   155 void CVpnNotifier::UnloadResourceFile()
       
   156     {
       
   157     LOG_("-> CVpnNotifier::UnloadResourceFile()");
       
   158 
       
   159 
       
   160     if (iResourceFileLoaded)
       
   161         {
       
   162         iEikEnv->DeleteResourceFile(iResourceFileOffset);
       
   163         iResourceFileLoaded = EFalse;
       
   164         }
       
   165 
       
   166 
       
   167 
       
   168     LOG_("<- CVpnNotifier::UnloadResourceFile()");
       
   169     }
       
   170     
       
   171 CVpnNotifier::TNotifierInfo CVpnNotifier::Info() const
       
   172     {
       
   173     return iInfo;
       
   174     }
       
   175 
       
   176 void CVpnNotifier::StartL(const TDesC8& aBuffer, TInt aReturnValue, const RMessagePtr2& aMessage)
       
   177     {
       
   178     LOG_("-> CVpnNotifier::StartL()");
       
   179     __ASSERT_DEBUG(aBuffer.Length() >= 4, _L("Input buffer is empty"));
       
   180 
       
   181     // Only one dialog can be shown at a time
       
   182     if (iDialog)
       
   183         {
       
   184         User::Leave(KErrInUse);
       
   185         }
       
   186     
       
   187     // Store output data references
       
   188     iMessage = aMessage;
       
   189     iReturnValue = aReturnValue;
       
   190 
       
   191     // Get input data to the local memory space
       
   192     HBufC8* input = HBufC8::NewL(aBuffer.Length());
       
   193     CleanupStack::PushL(input);
       
   194     input->Des().Copy(aBuffer);
       
   195 
       
   196     // The input consist of two parts in a single descriptor:
       
   197     // TVpnDialogInfo and the actual input that goes to the dialogs
       
   198 
       
   199     // First analyze the TVpnDialogInput info
       
   200     TVpnDialogInfo dialogInfo;
       
   201     TPckg<TVpnDialogInfo> pkgDialogInfo(dialogInfo);
       
   202     pkgDialogInfo.Copy(input->Left(sizeof(TVpnDialogInfo))); // 8 bit buffer -> size = length
       
   203 
       
   204     TInt dialogId = dialogInfo.DialogId();
       
   205     TInt noteDialogId = dialogInfo.NoteDialogId();
       
   206     
       
   207 
       
   208     // Then store the actual dialog input for later use
       
   209     TInt strLen = dialogInfo.NoteExtraInput().Length();
       
   210     if (strLen > 0) 
       
   211         {
       
   212         // Additional extra input (i.e. string replacement) was specified
       
   213         // in the dialog info structure, take it into use and pass it on.
       
   214         iInput = dialogInfo.NoteExtraInput().AllocL();
       
   215         }
       
   216     else 
       
   217         {
       
   218         iInput = HBufC8::NewL(input->Size() - sizeof(TVpnDialogInfo));
       
   219         iInput->Des().Copy(input->Mid(sizeof(TVpnDialogInfo)));
       
   220         }
       
   221 
       
   222     CleanupStack::PopAndDestroy(); // input
       
   223 
       
   224     if (!LaunchDialogL(dialogId, noteDialogId, *iInput))
       
   225         {
       
   226         User::Leave(KErrNotSupported);
       
   227         }
       
   228     LOG_("<- CVpnNotifier::StartL()");
       
   229     }
       
   230 
       
   231 TPtrC8 CVpnNotifier::StartL( const TDesC8& /*aBuffer*/ )
       
   232     {
       
   233     LOG_("-> CVpnNotifier::StartL()");
       
   234     
       
   235     __ASSERT_DEBUG(EFalse, User::Panic(_L("Synchronous StartL not used"), 0)); // should here be ret KNullDesC8() also?
       
   236     
       
   237     LOG_("<- CVpnNotifier::StartL()");
       
   238     
       
   239     return NULL;
       
   240     }
       
   241 
       
   242 TPtrC8 CVpnNotifier::UpdateL( const TDesC8& /*aBuffer*/ )
       
   243     {
       
   244     LOG_("-> CVpnNotifier::UpdateL()");
       
   245 
       
   246     LOG_("<- CVpnNotifier::UpdateL()");
       
   247 
       
   248     return KNullDesC8();
       
   249     }
       
   250 
       
   251 void CVpnNotifier::Cancel()
       
   252     {
       
   253     LOG_("-> CVpnNotifier::Cancel()");
       
   254     if (iDialog)
       
   255         {
       
   256         TRAP_IGNORE(iDialog->CancelL());
       
   257         iDialog = NULL;
       
   258         }
       
   259     LOG_("<- CVpnNotifier::Cancel()");
       
   260     }
       
   261 
       
   262 void CVpnNotifier::Release()
       
   263     {
       
   264     LOG_("-> CVpnNotifier::Release()");
       
   265 
       
   266     UnloadResourceFile();
       
   267     CloseManagerDll();
       
   268     delete this;
       
   269 
       
   270     LOG_("<- CVpnNotifier::Release()");
       
   271     }
       
   272 
       
   273 TBool CVpnNotifier::LaunchDialogL(TInt aDialogId, TInt aNoteDialogId, const TDesC8& aInput)
       
   274     {
       
   275     LOG_("-> CVpnNotifier::LaunchDialogL()");
       
   276 	((CEikServAppUi*)(CEikonEnv::Static())->EikAppUi())->SuppressAppSwitching(ETrue);
       
   277 
       
   278     // To ensure that we indeed do get the most recent (possibly updated) version
       
   279     // of both the resource file, and the DLL that uses resource IDs.
       
   280     UnloadResourceFile();
       
   281     LoadResourceFileL();
       
   282     
       
   283     CloseManagerDll();
       
   284     LoadManagerDllL();
       
   285 
       
   286     iDialog = iDialogManager->LaunchDialogL(this, aDialogId, aNoteDialogId, aInput);
       
   287     if (iDialog)
       
   288         {
       
   289         LOG_("<- CVpnNotifier::LaunchDialogL() (ETrue)");
       
   290         return ETrue;
       
   291         }
       
   292     else
       
   293         {
       
   294         UnloadResourceFile();
       
   295         CloseManagerDll();
       
   296         LOG_("<- CVpnNotifier::LaunchDialogL() (couldn't instantiate dialog)");
       
   297         return EFalse;
       
   298         }
       
   299     }
       
   300     
       
   301 TFileName CVpnNotifier::GetResourceFileNameL()
       
   302     {
       
   303     LOG_("-> CVpnNotifier::GetResourceFileNameL()");
       
   304     RFs& fsSession = iEikEnv->FsSession(); 
       
   305 
       
   306     TDriveList driveList;
       
   307     User::LeaveIfError(fsSession.DriveList(driveList));
       
   308 
       
   309     TInt driveNumber;
       
   310     TDriveName drive = _L("a:");
       
   311 
       
   312     TFileName resName;
       
   313     TInt foundIt = EFalse;
       
   314 
       
   315     LOG_(" Starting drive letter iteration");
       
   316     for (driveNumber = EDriveA, drive[0] = 'a';
       
   317          driveNumber <= EDriveZ;
       
   318          driveNumber++, drive[0]++)
       
   319         {
       
   320         if (!driveList[driveNumber])
       
   321             {
       
   322             LOG_("  Continue");
       
   323             continue;
       
   324             }
       
   325 
       
   326         TParse parse;
       
   327         parse.Set(drive, &iResourceFilename, NULL);
       
   328 
       
   329         resName.Copy(parse.FullName()); 
       
   330         
       
   331         LOG_1("  Resource filename: '%S'", &resName);
       
   332 
       
   333         BaflUtils::NearestLanguageFile(iEikEnv->FsSession(), resName);
       
   334 
       
   335         TEntry entry;
       
   336         if (fsSession.Entry(resName, entry) == KErrNone)
       
   337             {
       
   338             LOG_("  Found it!");
       
   339             foundIt = ETrue;
       
   340             break;
       
   341             }
       
   342         }
       
   343 
       
   344     if (!foundIt)
       
   345         {
       
   346         LOG_(" Didn't find it!");
       
   347         User::Leave(KErrNotFound);
       
   348         }
       
   349 
       
   350     LOG_("<- CVpnNotifier::GetResourceFileNameL()");
       
   351 
       
   352     // If the file name was found, it will stay in the cleanup stack
       
   353     return resName;
       
   354     }
       
   355 
       
   356 void CVpnNotifier::DialogCompleteL(TInt aReturnCode, TVpnDialogOutput& aOutput)
       
   357     {
       
   358     LOG_("-> CVpnNotifier::DialogCompleteL()");
       
   359 
       
   360     // NOTE! this doesn't work with own notifier server 
       
   361     // Activate apps -key again
       
   362     //
       
   363 	((CEikServAppUi*)(CEikonEnv::Static())->EikAppUi())->SuppressAppSwitching(EFalse);
       
   364 
       
   365     TPckgBuf<TVpnDialogOutput> outBuf(aOutput);
       
   366     iMessage.WriteL(iReturnValue, outBuf);
       
   367     iMessage.Complete(aReturnCode);
       
   368     iDialog = NULL;
       
   369     delete iInput; iInput = NULL;
       
   370     // Added to overcome uninstallation problems
       
   371     UnloadResourceFile();
       
   372     iManager->CancelNotifier(iNotifierUid);
       
   373 
       
   374     LOG_("<- CVpnNotifier::DialogCompleteL()");
       
   375 
       
   376     }
       
   377 
       
   378 void CVpnNotifier::DialogComplete(TInt aReturnCode)
       
   379     {
       
   380     LOG_("-> CVpnNotifier::DialogComplete()");
       
   381 
       
   382     // NOTE! this doesn't work with own notifier server 
       
   383     // Activate apps -key again
       
   384     //
       
   385 	((CEikServAppUi*)(CEikonEnv::Static())->EikAppUi())->SuppressAppSwitching(EFalse);
       
   386 
       
   387     iMessage.Complete(aReturnCode);
       
   388     iDialog = NULL;
       
   389     delete iInput; iInput = NULL;
       
   390     // Added to overcome uninstallation problems
       
   391     UnloadResourceFile();
       
   392     iManager->CancelNotifier(iNotifierUid);    
       
   393 
       
   394     LOG_("<- CVpnNotifier::DialogComplete()");
       
   395 
       
   396     }
       
   397 
       
   398 void CVpnNotifier::LoadManagerDllL() 
       
   399     {
       
   400     LOG_("-> CVpnNotifier::LoadManagerDll()");
       
   401 
       
   402     LOG_(" Loading manager again");
       
   403 
       
   404     TInt status = iDialogManagerLib.Load(KVpnDialogManagerDll, KNullUid);
       
   405 
       
   406     LOG_1(" DLL load status: %d", status);
       
   407 
       
   408     if (status == KErrNone)
       
   409         {
       
   410         LOG_(" Suitable DLL found, instantiating VPN dialog manager");
       
   411         
       
   412         TLibraryFunction entry = iDialogManagerLib.Lookup(1);
       
   413         
       
   414         LOG_(" Entry point found");
       
   415 
       
   416         // Constructor at the given ordinal may leave, even if it's not evident
       
   417         // from the syntax
       
   418         iRealDialogManager = (MVpnDialogManager*)entry();
       
   419         iDialogManager->SetDialogManager(iRealDialogManager);
       
   420 
       
   421         LOG_(" Dialog manager instantiated");
       
   422         }
       
   423     else 
       
   424         {
       
   425         LOG_(" (LEAVE) Dialog manager DLL not found!");
       
   426         User::Leave(status);
       
   427         }
       
   428 
       
   429     LOG_("<- CVpnNotifier::LoadManagerDll() (OK)");
       
   430     }
       
   431 
       
   432 
       
   433 
       
   434 
       
   435