locationsystemui/locationsysui/posindicator/posindhelperclientlib/src/posindicatorhelperserver.cpp
branchRCL_3
changeset 44 2b4ea9893b66
child 50 4c28d569e1fe
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:  Positioning Indicator Helper Client-Server communication
       
    15 *
       
    16 */
       
    17 
       
    18 #include "posindicatorhelperserver.h"
       
    19 #include "posindicatorhelpererrors.h"
       
    20 #include "posindicatorserverconst.h"
       
    21 
       
    22 #include <s32mem.h>
       
    23 #include <e32std.h>
       
    24 
       
    25 const TInt KDefaultMessageSlots = 255; //max
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // RPosIndicatorHelperServer::RPosIndicatorHelperServer()
       
    29 // Default constructor
       
    30 // ---------------------------------------------------------------------------
       
    31 // 
       
    32  RPosIndicatorHelperServer :: RPosIndicatorHelperServer():RSessionBase(),iReserved(NULL)
       
    33     {
       
    34      FUNC("+ RPosIndicatorHelperServer::RPosIndicatorHelperServer");
       
    35      FUNC("- RPosIndicatorHelperServer::RPosIndicatorHelperServer");
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------
       
    39 // RPosIndicatorHelperServer::Connect
       
    40 //
       
    41 // (other items were commented in a header).
       
    42 // ---------------------------------------------------------
       
    43 //
       
    44  TInt RPosIndicatorHelperServer::Connect()
       
    45 	{
       
    46      FUNC("+ RPosIndicatorHelperServer::Connect");
       
    47  	__ASSERT_ALWAYS(Handle() == 0, User::Panic(KPosIndHelperClientPanicCategory, EPosIndicatorHelperServerHandleNotClosed));
       
    48 
       
    49 	TInt ret = CreateSession(KPosIndHelperSrvName, Version(), KDefaultMessageSlots);
       
    50 	
       
    51 	if( ret == KErrNotFound )
       
    52 	    {
       
    53 #if defined(__WINSCW__)
       
    54 	    StartLbsRootProcess();
       
    55 #endif
       
    56 	    RProcess posIndHelperServerProcess;
       
    57 	    ret = posIndHelperServerProcess.Create(KPosIndHelperSrvName, KNullDesC);
       
    58 	    
       
    59 	    if( ret != KErrNone )
       
    60 	        {
       
    61 	        posIndHelperServerProcess.Close();
       
    62 	        return KErrNotFound;
       
    63 	        }
       
    64 	    
       
    65 	    TRequestStatus status;
       
    66 	    posIndHelperServerProcess.Rendezvous(status);
       
    67 	    
       
    68 	    if( status != KRequestPending )
       
    69 	        {
       
    70 	        User::WaitForRequest(status);
       
    71 	        posIndHelperServerProcess.Kill(KErrNone);
       
    72 	        posIndHelperServerProcess.Close();
       
    73 	        return status.Int();
       
    74 	        }
       
    75 	    else
       
    76 	        {
       
    77 	        posIndHelperServerProcess.Resume();		        
       
    78 	        }
       
    79 
       
    80 	    User::WaitForRequest(status);
       
    81 	    posIndHelperServerProcess.Close();
       
    82 
       
    83 	    if( status != KErrNone )
       
    84 	        {
       
    85 	        return (status.Int());
       
    86 	        }
       
    87 	    ret = CreateSession(KPosIndHelperSrvName, Version(), KDefaultMessageSlots);		    
       
    88 	    }
       
    89    
       
    90 	return ret;
       
    91   }
       
    92 	
       
    93 // ---------------------------------------------------------
       
    94 // RPosIndicatorHelperServer::Close
       
    95 //
       
    96 // (other items were commented in a header).
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99  void RPosIndicatorHelperServer::Close()
       
   100 	{
       
   101     FUNC("+ RPosIndicatorHelperServer::Close");
       
   102 	RSessionBase::Close();
       
   103     FUNC("- RPosIndicatorHelperServer::Close");
       
   104 	}
       
   105 	
       
   106 // ---------------------------------------------------------
       
   107 // RPosIndicatorHelperServer::Version
       
   108 //
       
   109 // (other items were commented in a header).
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112  TVersion RPosIndicatorHelperServer::Version() const
       
   113 	{	
       
   114     FUNC("+ RPosIndicatorHelperServer::Version");
       
   115 	return TVersion(KMajorVersionNumber,
       
   116 					KMinorVersionNumber,
       
   117 					KBuildVersionNumber);
       
   118 	}
       
   119 
       
   120 #if defined(__WINSCW__)
       
   121 // ---------------------------------------------------------
       
   122 // RPosIndicatorHelperServer::Version
       
   123 //
       
   124 // (other items were commented in a header).
       
   125 // ---------------------------------------------------------
       
   126 //
       
   127 TInt RPosIndicatorHelperServer::StartLbsRootProcess()
       
   128     {
       
   129     FUNC("+ RPosIndicatorHelperServer::StartLbsRootProcess");
       
   130 
       
   131     RProcess lbsrootProcess;
       
   132     TInt ret = lbsrootProcess.Create(_L("lbsroot"), KNullDesC);
       
   133     
       
   134     if( ret != KErrNone )
       
   135         {
       
   136         lbsrootProcess.Close();
       
   137         return KErrNotFound;
       
   138         }
       
   139     
       
   140     TRequestStatus status;
       
   141     lbsrootProcess.Rendezvous(status);
       
   142     
       
   143     if( status != KRequestPending )
       
   144         {
       
   145         User::WaitForRequest(status);
       
   146         lbsrootProcess.Kill(KErrNone);
       
   147         lbsrootProcess.Close();
       
   148         return KErrNotFound;
       
   149         }
       
   150     else
       
   151         {
       
   152         lbsrootProcess.Resume();             
       
   153         }
       
   154 
       
   155     User::WaitForRequest(status);
       
   156     lbsrootProcess.Close();
       
   157 
       
   158     if( status != KErrNone )
       
   159         {
       
   160         return (status.Int());
       
   161         }
       
   162     return ret;
       
   163     }
       
   164 #endif