messagingapp/msgappfw/server/src/ccsserver.cpp
branchRCL_3
changeset 57 ebe688cedc25
equal deleted inserted replaced
54:fa1df4b99609 57:ebe688cedc25
       
     1 /*
       
     2  * Copyright (c) 2007 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:  CS Server main class. Co-ordinates server startup,
       
    15  *                shutdown and receives client requests.
       
    16  *
       
    17  */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <ccsdefs.h>
       
    22 #include <ccsconversationentry.h>
       
    23 
       
    24 // USER INCLUDES
       
    25 #include "ccsdebug.h"
       
    26 #include "ccsserver.h"
       
    27 #include "ccssession.h"
       
    28 #include "ccsplugininterface.h"
       
    29 #include "ccsconversationevent.h"
       
    30 #include "ccsconversationcache.h"
       
    31 #include "ccscontactsmanager.h"
       
    32 #include "ccsbackuphandler.h"
       
    33 //Costant Declaration
       
    34 
       
    35 // ============================== MEMBER FUNCTIONS ============================
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // CCsServer::NewL
       
    39 // Two Phase Construction
       
    40 // ----------------------------------------------------------------------------
       
    41 CCsServer* CCsServer::NewL()
       
    42 {
       
    43     //TODO check the print macro for warning
       
    44     //TODO handle all error conditions
       
    45 
       
    46     PRINT ( _L("Enter CCsServer::NewL") );
       
    47 
       
    48     CCsServer* self = new (ELeave) CCsServer;
       
    49     CleanupStack::PushL(self);
       
    50     self->ConstructL();
       
    51     self->StartL(KCsServerName);
       
    52     CleanupStack::Pop(self);
       
    53 
       
    54     PRINT ( _L("End CCsServer::NewL") );
       
    55 
       
    56     return self;
       
    57 }
       
    58 
       
    59 // ----------------------------------------------------------------------------
       
    60 // CCsServer::CCsServer
       
    61 // Constructor
       
    62 // ----------------------------------------------------------------------------
       
    63 CCsServer::CCsServer() :
       
    64     CServer2(EPriorityLow)
       
    65 {
       
    66 }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // CCsServer::DeletePlugins
       
    70 // Unload the plugins for backup/restore
       
    71 // ----------------------------------------------------------------------------
       
    72 void CCsServer::DeletePlugins()
       
    73 {
       
    74     if (iConversationPlugin) {
       
    75         delete iConversationPlugin;
       
    76         iConversationPlugin = NULL;
       
    77     }
       
    78 }
       
    79 
       
    80 // ----------------------------------------------------------------------------
       
    81 // CCsServer::LoadPlugins
       
    82 // Load the plugins after a backup/restore
       
    83 // ----------------------------------------------------------------------------
       
    84 
       
    85 void CCsServer::LoadPlugins()
       
    86 {
       
    87     iConversationPlugin = CCsPluginInterface::NewL();
       
    88     // Create the plugin for the required entries
       
    89     iConversationPlugin->InstantiatePluginL(this);
       
    90     //fetch all initial set of messages
       
    91     iConversationPlugin->GetConversationsL();
       
    92     RefreshConversations();
       
    93 }
       
    94 
       
    95 // ----------------------------------------------------------------------------
       
    96 // CCsServer::ConstructL
       
    97 // Second phase constructor
       
    98 // ----------------------------------------------------------------------------
       
    99 void CCsServer::ConstructL()
       
   100 {
       
   101     PRINT ( _L("Enter CCsServer::ConstructL") );
       
   102 
       
   103     // Create contacts manager and resgiter for events
       
   104     iContactsManager = new CCsContactsManager();
       
   105     
       
   106     iConversationPlugin = CCsPluginInterface::NewL();
       
   107 
       
   108     // Create the plugin for the required entries
       
   109     iConversationPlugin->InstantiatePluginL(this);
       
   110     
       
   111     //fetch all initial set of messages
       
   112     iConversationPlugin->GetConversationsL();
       
   113     
       
   114     // create cache
       
   115     iConversationCache = CCsConversationCache::NewL(iContactsManager, this);
       
   116 
       
   117     iCsCachingStatus = KCachingStatusUnknown;
       
   118 	
       
   119     iBackUpHandler = CCsBackUpHandler::NewL(*this);
       
   120     
       
   121     PRINT ( _L("End CCsServer::ConstructL") );
       
   122 }
       
   123 
       
   124 // ----------------------------------------------------------------------------
       
   125 // CCsServer::~CCsServer
       
   126 // Destructor
       
   127 // ----------------------------------------------------------------------------
       
   128 CCsServer::~CCsServer()
       
   129 {
       
   130     PRINT ( _L("Enter CCsServer::~CCsServer") );
       
   131 
       
   132     // delete cache
       
   133     if (iConversationCache)
       
   134     {
       
   135         delete iConversationCache;
       
   136         iConversationCache = NULL;
       
   137     }
       
   138 
       
   139     // delete the plugin interface object
       
   140     if (iConversationPlugin)
       
   141     {
       
   142         delete iConversationPlugin;
       
   143         iConversationPlugin = NULL;
       
   144     }
       
   145 
       
   146     // Delete the contact manager
       
   147     if (iContactsManager)
       
   148     {
       
   149         delete iContactsManager;
       
   150         iContactsManager = NULL;
       
   151     }
       
   152 
       
   153 	if(iBackUpHandler)
       
   154 	{
       
   155 		delete iBackUpHandler;
       
   156 		iBackUpHandler = NULL;
       
   157 	}
       
   158     REComSession::FinalClose();
       
   159 
       
   160     PRINT ( _L("End CCsServer::~CCsServer") );
       
   161 }
       
   162 
       
   163 // ----------------------------------------------------------------------------
       
   164 // CCsServer::NewSessionL
       
   165 // Constructor
       
   166 // ----------------------------------------------------------------------------
       
   167 CSession2* CCsServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const
       
   168 {
       
   169     TVersion serverVersion(1, 0, 0);
       
   170     if (!User::QueryVersionSupported(serverVersion, aVersion))
       
   171         User::Leave(KErrNotSupported);
       
   172 
       
   173     CCsSession* session = CCsSession::NewL(const_cast<CCsServer*> (this));
       
   174 
       
   175     PRINT ( _L("CCsServer::NewSessionL - New Session Created") );
       
   176 
       
   177     return session;
       
   178 }
       
   179 
       
   180 // ----------------------------------------------------------------------------
       
   181 // CCsServer::ConversationCacheInterface
       
   182 // Get the cache interface
       
   183 // ----------------------------------------------------------------------------
       
   184 CCsConversationCache* CCsServer::ConversationCacheInterface()
       
   185 {
       
   186     return iConversationCache;
       
   187 }
       
   188 
       
   189 // ----------------------------------------------------------------------------
       
   190 // CCsServer::AddConversations
       
   191 // This is to handle the new conversation event callback from plugin dll
       
   192 // The idea is to add entries to the cache and at the same time
       
   193 // update the client UI
       
   194 // ----------------------------------------------------------------------------
       
   195 void CCsServer::AddConversations(
       
   196                                  const RPointerArray<CCsConversationEntry>& aConversationEntryLists)
       
   197 {
       
   198     PRINT ( _L("Enter CCsServer::AddConversations") );
       
   199 
       
   200     iConversationCache->HandleConversations(aConversationEntryLists,
       
   201                                             KConversationEventNew);
       
   202 
       
   203     PRINT ( _L("End CCsServer::AddConversations") );
       
   204 }
       
   205 
       
   206 // ----------------------------------------------------------------------------
       
   207 // CCsServer::ModifyConversations
       
   208 // This is to handle the modify conversation event callback from plugin dll
       
   209 // The idea is to update entries to the cache and at the same time update
       
   210 // the client UI
       
   211 // ----------------------------------------------------------------------------
       
   212 void CCsServer::ModifyConversations(
       
   213                                     const RPointerArray<CCsConversationEntry>& aConversationEntryLists)
       
   214 {
       
   215     PRINT ( _L("Enter CCsServer::ModifyConversations") );
       
   216 
       
   217     iConversationCache->HandleConversations(aConversationEntryLists,
       
   218                                             KConversationEventUpdate);
       
   219 
       
   220     PRINT ( _L("End CCsServer::ModifyConversations") );
       
   221 }
       
   222 
       
   223 // ----------------------------------------------------------------------------
       
   224 // CCsServer::DeleteConversations
       
   225 // This is to handle the delete event callback from plugin dll
       
   226 // The idea is to delete entries to the cache and at the same time update the client UI
       
   227 // ----------------------------------------------------------------------------
       
   228 void CCsServer::DeleteConversations(
       
   229                                     const RPointerArray<CCsConversationEntry>& aConversationEntryLists)
       
   230 {
       
   231     PRINT ( _L("Enter CCsServer::DeleteConversations") );
       
   232 
       
   233     iConversationCache->HandleConversations(aConversationEntryLists,
       
   234                                             KConversationEventDelete);
       
   235 
       
   236     PRINT ( _L("End CCsServer::DeleteConversations") );
       
   237 }
       
   238 
       
   239 // ----------------------------------------------------------------------------
       
   240 // CCsServer::NotifySessions
       
   241 // Callback for on-the-fly data changes
       
   242 // ----------------------------------------------------------------------------
       
   243 void CCsServer::NotifySessions(CCsClientConversation* aConversation,
       
   244                                TUint32 aEvent)
       
   245 {
       
   246     iSessionIter.SetToFirst();
       
   247     CCsSession* session;
       
   248     while ( (session = (CCsSession*) iSessionIter++) != NULL)
       
   249     {
       
   250         TRAPD(error, session->HandleChangeEventL( aConversation, aEvent ));
       
   251         if (error != KErrNone)
       
   252         {
       
   253             PRINT1 ( _L("CCsServer::NotifySessions - Error:%d"), error );
       
   254         }
       
   255     }
       
   256 }
       
   257 
       
   258 // ----------------------------------------------------------------------------
       
   259 // CCsServer::CachingCompleted
       
   260 // This is to get caching complete event from plugins
       
   261 // ----------------------------------------------------------------------------
       
   262 void CCsServer::CachingCompleted()
       
   263 {
       
   264     // NOTE:- NO CHECK DONE NOW ON NUMBER OF PLUGINS TO KEEP IT SIMPLE.
       
   265     // NOT EXPECTED TO BE MORE THAN 1 PLUGIN FOR TB 9.2.
       
   266     iCsCachingStatus = KCachingStatusCompleted;
       
   267 }
       
   268 
       
   269 // ----------------------------------------------------------------------------
       
   270 // CCsServer::RefreshConversations
       
   271 // Refresh conversations.
       
   272 // ----------------------------------------------------------------------------
       
   273 void CCsServer::RefreshConversations()
       
   274 {
       
   275     // NOTE:- NO CHECK DONE NOW ON NUMBER OF PLUGINS TO KEEP IT SIMPLE.
       
   276     // NOT EXPECTED TO BE MORE THAN 1 PLUGIN FOR TB 9.2.
       
   277 
       
   278     // Delete and recreate cache.
       
   279     if (iConversationCache)
       
   280     {
       
   281         delete iConversationCache;
       
   282         iConversationCache = NULL;
       
   283 
       
   284         iCsCachingStatus = KCachingStatusUnknown;
       
   285         TRAPD(error, iConversationCache = CCsConversationCache::
       
   286                 NewL(iContactsManager, this));
       
   287         if (error != KErrNone)
       
   288         {
       
   289             PRINT1 ( _L("CCsServer::RefreshConversations - Error:%d"), error );
       
   290         }
       
   291     }
       
   292 
       
   293     // Notify client to refresh
       
   294     NotifySessions(NULL, KConversationEventRefresh);
       
   295     NotifySessions(NULL, KConversationEventListRefresh);
       
   296     // Read again.
       
   297     TRAPD(error, iConversationPlugin->GetConversationsL());
       
   298     if (error != KErrNone)
       
   299     {
       
   300         PRINT1 ( _L("CCsServer::RefreshConversations - Error:%d"), error );
       
   301     }
       
   302 }
       
   303 
       
   304 // end of file