upnpharvester/mdhserver/src/client/mdhclientsession.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     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:      Metadata Harvester server's client
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 // INCLUDE FILES
       
    25 
       
    26 #include    "mdhclientsession.h"
       
    27 #include    "mdhcommon.h"
       
    28 #include    "msdebug.h"
       
    29 
       
    30 
       
    31 // CONSTANTS
       
    32 // Number of retries to start server
       
    33 const TInt KServerRetries = 2;
       
    34 
       
    35 // =========================== LOCAL FUNCTIONS ===============================
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // StartServer
       
    39 // Starts the CM Metadata Harvester server.
       
    40 // Returns: TInt error: Error status of the CM Metadata Harvester startup.
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 // ---------------------------------------------------------------------------
       
    44 // StartServer
       
    45 // Creates a new process for the server and starts it up.
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 static TInt StartServer()
       
    49     {
       
    50     LOG(_L("[CmMdh Server]\t StartServer\n"));
       
    51     
       
    52     TInt result( KErrNone );
       
    53     // create server - if one of this name does not already exist
       
    54     TFindServer findServer( KCmMdhServerName );
       
    55     TFullName name;
       
    56     if ( findServer.Next( name ) != KErrNone ) // we don't exist already
       
    57         {
       
    58         
       
    59         TRequestStatus status( KRequestPending );
       
    60         RProcess server;
       
    61         // Create the server process
       
    62         result = server.Create( KCmMdhServerExe, KNullDesC );       
       
    63         if( result != KErrNone )
       
    64             {
       
    65             return result;
       
    66             }
       
    67     
       
    68         // Process created successfully
       
    69         server.Resume(); // start it going
       
    70         server.Rendezvous( status );
       
    71         
       
    72         // Wait until the completion of the server creation
       
    73         // server signals us when it's up
       
    74         User::WaitForRequest( status );
       
    75         
       
    76         
       
    77         if( status != KErrNone )
       
    78             {
       
    79             server.Close();
       
    80             return status.Int();
       
    81             }
       
    82             
       
    83         
       
    84         // Server created successfully
       
    85         server.Close(); // we can close the handle to server process now
       
    86         }
       
    87     return result;
       
    88     }
       
    89 
       
    90 
       
    91 // ========================== MEMBER FUNCTIONS ===============================
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // RCmMdhSession::RCmMdhSession
       
    95 // C++ default constructor can NOT contain any code, that
       
    96 // might leave.
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 RCmMdhSession::RCmMdhSession()
       
   100     {
       
   101     }
       
   102 
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // RCmMdhSession::Connect
       
   106 // Starts and creates a session of CM Metadata Harvester 
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 TInt RCmMdhSession::Connect()
       
   110     {
       
   111     TInt tryLoop = 0;
       
   112     TInt errCode = 0;
       
   113 
       
   114     for ( tryLoop = 0; tryLoop < KServerRetries; tryLoop++ )
       
   115         {
       
   116         errCode = CreateSession(KCmMdhServerName, 
       
   117             TVersion( KCmMdhServerMajor, KCmMdhServerMinor, 
       
   118                     KCmMdhServerBuild ) );
       
   119         //gives MessageSlots of -1
       
   120         //this uses global pool rather than local pool
       
   121 
       
   122         TRACE(Print(_L("[CmMdh Server]\t RCmMdhSession::Connect New Session \
       
   123                             created with status %d\n"), errCode));
       
   124         if( errCode == KErrNotSupported )
       
   125             {
       
   126             TRACE(Print(_L("[CmMdh Server]\t Version not supported!\n") ));
       
   127             return errCode;            
       
   128             }
       
   129         if ( errCode != KErrNotFound &&  errCode != KErrServerTerminated )
       
   130             {
       
   131             return errCode;
       
   132             }
       
   133 
       
   134         errCode = StartServer();
       
   135 
       
   136         if ( errCode != KErrNone && errCode != KErrAlreadyExists )
       
   137             {
       
   138             return errCode;
       
   139             }
       
   140             
       
   141         }
       
   142     return errCode;
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // RCmMdhSession::SearchMediaServers
       
   147 // Searchs for neighborhood media servers
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void RCmMdhSession::SearchMediaservers( TRequestStatus& aStatus )
       
   151     {
       
   152     LOG(_L("[CmMdh Server]\t RCmMdhSession::SearchMediaservers\n"));
       
   153     
       
   154     SendReceive(ECmMdhSearchMediaservers, TIpcArgs(), aStatus);
       
   155     }
       
   156     
       
   157     
       
   158 // ---------------------------------------------------------------------------
       
   159 // RCmMdhSession::Harvest
       
   160 // Harvests and synchronizes metadata from found mediaservers
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void RCmMdhSession::Harvest( TRequestStatus& aStatus )
       
   164     {
       
   165     LOG(_L("[CmMdh Server]\t RCmMdhSession::SearchMediaServers\n"));
       
   166     
       
   167     SendReceive(ECmMdhHarvest, TIpcArgs(), aStatus);
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // RCmMdhSession::Cancel
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void RCmMdhSession::Cancel()
       
   175     {
       
   176     LOG(_L("[CmMdh Server]\t RCmMdhSession::Cancel\n"));
       
   177     
       
   178     SendReceive(ECmMdhCancel, TIpcArgs());
       
   179     }
       
   180 
       
   181 
       
   182