javauis/remconobserver_akn/src/javaremconmanager.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008-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:  Java RemCon Observer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <jdebug.h>
       
    20 
       
    21 #include "javaremconmanager.h"
       
    22 #include "javaremconobservable.h"
       
    23 #include "panics.h"
       
    24 
       
    25 // ======== STATIC VARIABLES ========
       
    26 
       
    27 /**
       
    28 * Singleton
       
    29 */
       
    30 
       
    31 NONSHARABLE_CLASS(RemConnGlobals)
       
    32 {
       
    33 public:
       
    34     RemConnGlobals() : mObservable(0) {}
       
    35 
       
    36 public:
       
    37     CJavaRemConObservable* mObservable;
       
    38 };
       
    39 
       
    40 
       
    41 #if defined(__WINSCW__)
       
    42 
       
    43 #include <pls.h>
       
    44 RemConnGlobals* getRemConnGlobals()
       
    45 {
       
    46     // Access the PLS of this process
       
    47     RemConnGlobals* globals  =
       
    48         Pls<RemConnGlobals>(TUid::Uid(0x200211E1));
       
    49     return globals;
       
    50 }
       
    51 
       
    52 #else
       
    53 
       
    54 static RemConnGlobals* sGlobals = 0;
       
    55 
       
    56 RemConnGlobals* getRemConnGlobals()
       
    57 {
       
    58     if (sGlobals == 0)
       
    59     {
       
    60         sGlobals = new RemConnGlobals();
       
    61     }
       
    62     return sGlobals;
       
    63 }
       
    64 #endif
       
    65 
       
    66 
       
    67 
       
    68 
       
    69 // ======== MEMBER FUNCTIONS ========
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CJavaRemConManager::ConstructL()
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CJavaRemConManager::ConstructL()
       
    76 {
       
    77     DEBUG("+ CJavaRemConManager::ConstructL()");
       
    78     RemConnGlobals* globals = getRemConnGlobals();
       
    79     if (globals->mObservable == 0)
       
    80     {
       
    81         globals->mObservable = CJavaRemConObservable::NewL();
       
    82         RThread thread;
       
    83         iCreatorThreadId = thread.Id();
       
    84     }
       
    85     DEBUG("- CJavaRemConManager::ConstructL()");
       
    86 }
       
    87 
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CJavaRemConManager* CJavaRemConManager::NewL()
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 EXPORT_C CJavaRemConManager* CJavaRemConManager::NewL()
       
    94 {
       
    95     CJavaRemConManager* self = CJavaRemConManager::NewLC();
       
    96     CleanupStack::Pop(self);
       
    97     return self;
       
    98 }
       
    99 
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CJavaRemConManager* CJavaRemConManager::NewLC()
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 EXPORT_C CJavaRemConManager* CJavaRemConManager::NewLC()
       
   106 {
       
   107     CJavaRemConManager* self = new(ELeave) CJavaRemConManager;
       
   108     CleanupStack::PushL(self);
       
   109     self->ConstructL();
       
   110     return self;
       
   111 }
       
   112 
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CJavaRemConManager::CJavaRemConManager()
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 CJavaRemConManager::CJavaRemConManager() : iSet(EFalse)
       
   119 {
       
   120     DEBUG("+ CJavaRemConManager::CJavaRemConManager()");
       
   121 
       
   122     DEBUG("- CJavaRemConManager::CJavaRemConManager()");
       
   123 }
       
   124 
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CJavaRemConManager::~CJavaRemConManager()
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 CJavaRemConManager::~CJavaRemConManager()
       
   131 {
       
   132     DEBUG("+ CJavaRemConManager::~CJavaRemConManager()");
       
   133     __ASSERT_DEBUG(!iSet, User::Panic(KJavaRemConPanicCategory,
       
   134                                       EJavaRemConPanicObserverNotRemoved)
       
   135                   );
       
   136 
       
   137     RThread thread;
       
   138     if (thread.Id() == iCreatorThreadId)
       
   139     {
       
   140         delete getRemConnGlobals()->mObservable;
       
   141         getRemConnGlobals()->mObservable = NULL;
       
   142     }
       
   143     DEBUG("- CJavaRemConManager::~CJavaRemConManager()");
       
   144 }
       
   145 
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CJavaRemConManager::SetObserver
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C void CJavaRemConManager::SetObserverL(
       
   152     CJavaRemConObserver &aObserver)
       
   153 {
       
   154     DEBUG("+ CJavaRemConManager::SetObserverL()");
       
   155     if (iSet)
       
   156     {
       
   157         User::Leave(KErrInUse);
       
   158     }
       
   159     getRemConnGlobals()->mObservable->AddObserverL(aObserver);
       
   160     iSet = ETrue;
       
   161     DEBUG("- CJavaRemConManager::SetObserverL()");
       
   162 }
       
   163 
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // CJavaRemConManager::RemoveObserver
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 EXPORT_C void CJavaRemConManager::RemoveObserver(
       
   170     CJavaRemConObserver &aObserver)
       
   171 {
       
   172     DEBUG("+ CJavaRemConManager::RemoveObserverL()");
       
   173     __ASSERT_DEBUG(iSet, User::Panic(KJavaRemConPanicCategory,
       
   174                                      EJavaRemConPanicObserverNotSet)
       
   175                   );
       
   176 
       
   177     CJavaRemConObservable* observable = getRemConnGlobals()->mObservable;
       
   178     if (observable)
       
   179     {
       
   180         observable->RemoveObserver(aObserver);
       
   181     }
       
   182 
       
   183     iSet = EFalse;
       
   184     DEBUG("- CJavaRemConManager::RemoveObserver()");
       
   185 }
       
   186 
       
   187 
       
   188 // End Of File