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