locationsystemui/locationsysui/privacyverifiernotifierui/contactresolversession/src/contactresolversession.cpp
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     1 /*
       
     2  * Copyright (c) 2010 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: client-side interface implementation for server session.
       
    15  *  
       
    16  */
       
    17 
       
    18 #include "contactresolversession.h"
       
    19 #include "locprivacyinternal.h"
       
    20 #include "locprivacycommon.h"
       
    21 #include "locutilsdebug.h"
       
    22 
       
    23 #include <lbs/epos_cposrequestor.h>
       
    24 #include <lbs/EPos_RPosRequestorStack.h>
       
    25 #include <e32cmn.h>
       
    26 #include <s32strm.h>
       
    27 #include <s32mem.h>
       
    28 
       
    29 //This determines the number of outstanding requests the client may have with the server at any one time. 
       
    30 //The maximum number of slots is 255.
       
    31 TInt KDefaultMessageSlots = 255;
       
    32 const TUid KServerUid3 =
       
    33     {
       
    34     0x101f7a86
       
    35     };
       
    36 _LIT(KServerFilename, "locnotificationserver.exe");
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // RContactResolverSession::RContactResolverSession()
       
    40 // C++ default constructor can NOT contain any code, that might leave.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 EXPORT_C RContactResolverSession::RContactResolverSession() :
       
    44     RSessionBase()
       
    45     {
       
    46     // No implementation required
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // RContactResolverSession::ResolveRequestorsL()
       
    51 // Issues a request for the time to the server.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 EXPORT_C void RContactResolverSession::ResolveRequestorsL(RPointerArray<
       
    55         CPosRequestor>& aRequestors)
       
    56     {
       
    57 
       
    58      LOCUTILSDEBUG( "+RContactResolverSession::ResolveRequestorsL" )
       
    59      
       
    60     RPosRequestorStack* requestors = new (ELeave) RPosRequestorStack;
       
    61     CleanupStack::PushL(requestors);
       
    62 
       
    63     //-------------------------------------------------------------
       
    64     // getting size from the server in first IPC
       
    65     CBufFlat* buffer = CBufFlat::NewL(512);
       
    66     CleanupStack::PushL(buffer);
       
    67     RBufWriteStream writeStream;
       
    68     writeStream.Open(*buffer);
       
    69     CleanupClosePushL(writeStream);
       
    70 
       
    71     TInt count = aRequestors.Count();
       
    72     for (TInt i = 0; i < count; ++i)
       
    73         {
       
    74         requestors->Append(aRequestors[i]);
       
    75         }
       
    76     requestors->ExternalizeL(writeStream);
       
    77     writeStream.CommitL();
       
    78 
       
    79     TPtr8 ptr = buffer->Ptr(0);
       
    80 
       
    81     TIpcArgs args;
       
    82     TInt size = 0;
       
    83     TPckg<TInt> sizePkg(size);
       
    84     args.Set(0, &sizePkg);
       
    85     args.Set(1, &ptr);
       
    86 
       
    87     TInt in = SendReceive(ELocPrivacyGetSize, args);
       
    88 
       
    89     CleanupStack::PopAndDestroy(&writeStream);
       
    90     CleanupStack::PopAndDestroy(buffer);
       
    91     CleanupStack::PopAndDestroy(requestors);
       
    92     //-------------------------------------------------------------
       
    93     //-------------------------------------------------------------
       
    94     // allocating the buffer of the size obtained in the first IPC
       
    95     // and getting the data from the server in the 2nd IPC
       
    96 
       
    97     // This call waits for the server to complete the request before
       
    98     // proceeding. When it returns, the new time will be in aTime.
       
    99 
       
   100 
       
   101     CBufFlat* buffer1 = CBufFlat::NewL(512);
       
   102     CleanupStack::PushL(buffer1);
       
   103     buffer1->ResizeL(size);
       
   104     
       
   105     TPtr8 bufPtr = buffer1->Ptr(0);
       
   106     TIpcArgs ipcArgs;
       
   107     ipcArgs.Set(0, &bufPtr);
       
   108     in = SendReceive(ELocPrivacyResolve, ipcArgs);
       
   109     
       
   110     //-------------------------------------------------------------
       
   111 
       
   112     RBufReadStream readStream;
       
   113     readStream.Open(*buffer1);
       
   114     CleanupClosePushL(readStream);
       
   115     RPosRequestorStack* requestors2 = new (ELeave) RPosRequestorStack;
       
   116     CleanupStack::PushL(requestors2);
       
   117     requestors2->InternalizeL(readStream);
       
   118     TInt cnt = requestors2->Count();
       
   119     aRequestors.Reset();
       
   120     for (TInt i = 0; i < cnt; ++i)
       
   121         {
       
   122         CPosRequestor * entry = requestors2->operator [](i);
       
   123         aRequestors.Append(entry);
       
   124         }
       
   125     CleanupStack::PopAndDestroy(requestors2);
       
   126     CleanupStack::PopAndDestroy(&readStream);
       
   127     CleanupStack::PopAndDestroy(buffer1);
       
   128  
       
   129     LOCUTILSDEBUG( "-RContactResolverSession::ResolveRequestorsL" )
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // RContactResolverSession::Connect()
       
   134 // Connects to the server and create a session.
       
   135 // -----------------------------------------------------------------------------
       
   136 
       
   137 EXPORT_C TInt RContactResolverSession::Connect()
       
   138     {
       
   139     LOCUTILSDEBUG( "+RContactResolverSession::Connect" )
       
   140     
       
   141     TInt error = StartServer();
       
   142 
       
   143     if (KErrNone == error)
       
   144         {
       
   145         error = CreateSession(KLocPrivacyServerName, Version(),
       
   146                 KDefaultMessageSlots);
       
   147         }
       
   148     LOCUTILSDEBUG( "-RContactResolverSession::Connect" )
       
   149     return error;
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // StartServer()
       
   154 // Starts the server if it is not already running
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TInt RContactResolverSession::StartServer()
       
   158     {
       
   159     LOCUTILSDEBUG( "+RContactResolverSession::StartServer" )
       
   160     
       
   161     TInt result;
       
   162 
       
   163     TFindServer findServer(KLocPrivacyServerName);
       
   164     TFullName name;
       
   165 
       
   166     result = findServer.Next(name);
       
   167     if (result == KErrNone)
       
   168         {
       
   169         // Server already running
       
   170         return KErrNone;
       
   171         }
       
   172 
       
   173     result = CreateServerProcess();
       
   174     if (result != KErrNone)
       
   175         {
       
   176         return result;
       
   177         }
       
   178     LOCUTILSDEBUG( "-RContactResolverSession::StartServer" )
       
   179     
       
   180     return KErrNone;
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CreateServerProcess()
       
   185 // Creates a server process
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 TInt RContactResolverSession::CreateServerProcess()
       
   189     {
       
   190     LOCUTILSDEBUG( "+RContactResolverSession::CreateServerProcess" )
       
   191     
       
   192     TInt result;
       
   193 
       
   194     const TUidType serverUid(KNullUid, KNullUid, KServerUid3);
       
   195 
       
   196     RProcess server;
       
   197     TRequestStatus status;
       
   198     result = server.Create(KServerFilename, KNullDesC, serverUid);
       
   199 
       
   200     if (result != KErrNone)
       
   201         {
       
   202         server.Close();
       
   203         return KErrNotFound;
       
   204         }
       
   205 
       
   206     server.Rendezvous(status);
       
   207 
       
   208     if (status != KRequestPending)
       
   209         {
       
   210         User::WaitForRequest(status);
       
   211         server.Kill(KErrNone);
       
   212         server.Close();
       
   213         return (status.Int());
       
   214         }
       
   215     else
       
   216         {
       
   217         server.Resume();
       
   218         }
       
   219 
       
   220     User::WaitForRequest(status);
       
   221     server.Close();
       
   222 
       
   223     if (status != KErrNone)
       
   224         {
       
   225         return (status.Int());
       
   226         }
       
   227 
       
   228     LOCUTILSDEBUG( "-RContactResolverSession::CreateServerProcess" )
       
   229     
       
   230     return KErrNone;
       
   231     }
       
   232 
       
   233 TVersion RContactResolverSession::Version() const
       
   234     {
       
   235     LOCUTILSDEBUG( "RContactResolverSession::Version" )
       
   236     
       
   237     return TVersion(KLocPrivacyServerMajorVersionNumber,
       
   238             KLocPrivacyServerMinorVersionNumber,
       
   239             KLocPrivacyServerBuildVersionNumber);
       
   240     }
       
   241 
       
   242 EXPORT_C void RContactResolverSession::Close()
       
   243     {
       
   244     LOCUTILSDEBUG( "+RContactResolverSession::Close" )
       
   245     
       
   246     RSessionBase::Close();
       
   247     	
       
   248     LOCUTILSDEBUG( "-RContactResolverSession::Close" )
       
   249     }