os/mm/mmlibs/mmfw/src/Client/Video/mediaclientpolicyserversession.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "mediaclientpolicyserversession.h"
sl@0
    17
#include <e32std.h>
sl@0
    18
#include "mediaclientvideotrace.h"
sl@0
    19
sl@0
    20
// Policy Server EXE name
sl@0
    21
_LIT( KIvePolicyServerImg, "ivepolicyserver" );
sl@0
    22
sl@0
    23
// Policy Server thread name
sl@0
    24
_LIT( KIvePolicyServerName, "!ivepolicyserver0x10204C27" ); 
sl@0
    25
sl@0
    26
// Number of asynchronous message slots
sl@0
    27
const TInt KIveAsyncMessageSlots = 1;
sl@0
    28
sl@0
    29
static TInt StartServer()
sl@0
    30
    {
sl@0
    31
    DEBUG_PRINTF("medialclientsession StartServer +++");
sl@0
    32
    
sl@0
    33
    RProcess server;
sl@0
    34
    TInt error = server.Create(KIvePolicyServerImg, KNullDesC);
sl@0
    35
    if (error != KErrNone)
sl@0
    36
        {
sl@0
    37
        DEBUG_PRINTF2("medialclientsession StartServer server creation failed %d", error);
sl@0
    38
        return error;
sl@0
    39
        }
sl@0
    40
        
sl@0
    41
    TRequestStatus status;
sl@0
    42
sl@0
    43
    server.Rendezvous(status);
sl@0
    44
    if (status != KRequestPending)
sl@0
    45
        {
sl@0
    46
        server.Kill( 0 );
sl@0
    47
        // abort startup
sl@0
    48
        }
sl@0
    49
    else
sl@0
    50
        {
sl@0
    51
        server.Resume();
sl@0
    52
        // logon OK - start the server
sl@0
    53
        }
sl@0
    54
sl@0
    55
    User::WaitForRequest(status);
sl@0
    56
    // wait for start or death
sl@0
    57
    error = (server.ExitType() == EExitPanic) ? KErrGeneral : status.Int();
sl@0
    58
    server.Close();
sl@0
    59
   
sl@0
    60
    DEBUG_PRINTF(" medialclientsession StartServer ---");
sl@0
    61
    return error;
sl@0
    62
    }
sl@0
    63
sl@0
    64
RMediaClientPolicyServerSession::RMediaClientPolicyServerSession():
sl@0
    65
    RSessionBase()
sl@0
    66
    {
sl@0
    67
    DEBUG_PRINTF(" RMediaClientPolicyServerSession::RMediaClientPolicyServerSession +++");
sl@0
    68
    DEBUG_PRINTF(" RMediaClientPolicyServerSession::RMediaClientPolicyServerSession ---");
sl@0
    69
    }
sl@0
    70
sl@0
    71
TInt RMediaClientPolicyServerSession::Connect()
sl@0
    72
    {
sl@0
    73
    DEBUG_PRINTF(" RMediaClientPolicyServerSession::Connect +++");
sl@0
    74
    
sl@0
    75
    TInt error = KErrNone;
sl@0
    76
    for (TInt i = 0; i < 2; i++)
sl@0
    77
        {
sl@0
    78
        // Try to create session.
sl@0
    79
        error = CreateSession(KIvePolicyServerName, TVersion( 0, 0, 0 ), KIveAsyncMessageSlots);
sl@0
    80
sl@0
    81
        if (error != KErrNotFound && error != KErrServerTerminated) 
sl@0
    82
            {
sl@0
    83
            DEBUG_PRINTF("RMediaClientPolicyServerSession::Connect Server found and session created."); 
sl@0
    84
            DEBUG_PRINTF2("RMediaClientPolicyServerSession::Connect --- returns %d", error);
sl@0
    85
            return error;
sl@0
    86
            }
sl@0
    87
  
sl@0
    88
        // If session failed, try to start server once.
sl@0
    89
        if (i == 0)
sl@0
    90
            {            
sl@0
    91
            DEBUG_PRINTF("RMediaClientPolicyServerSession::Connect StartServer");
sl@0
    92
            // Start server
sl@0
    93
            error = StartServer();                     
sl@0
    94
            if (error != KErrNone && error != KErrAlreadyExists)
sl@0
    95
                {
sl@0
    96
                DEBUG_PRINTF("RMediaClientPolicyServerSession::Connect Server startup failed.");
sl@0
    97
                DEBUG_PRINTF2("RMediaClientPolicyServerSession::Connect --- returns %d", error);
sl@0
    98
                return error;
sl@0
    99
                }
sl@0
   100
            }
sl@0
   101
        else
sl@0
   102
            {
sl@0
   103
            DEBUG_PRINTF2("RMediaClientPolicyServerSession::Connect Session creation failed error %d", error);
sl@0
   104
            }
sl@0
   105
        }
sl@0
   106
    
sl@0
   107
    DEBUG_PRINTF2("RMediaClientPolicyServerSession::Connect --- returns %d", error);
sl@0
   108
    return error;
sl@0
   109
    }
sl@0
   110
sl@0
   111
TInt RMediaClientPolicyServerSession::SendMessage( TInt aFunction, const TIpcArgs &aArgs ) const 
sl@0
   112
    {
sl@0
   113
    DEBUG_PRINTF("RMediaClientPolicyServerSession::SendMessage +++");
sl@0
   114
sl@0
   115
    TInt error = SendReceive( aFunction, aArgs );    
sl@0
   116
    
sl@0
   117
    DEBUG_PRINTF2("RMediaClientPolicyServerSession::SendMessage --- returns %d", error);
sl@0
   118
    return error;
sl@0
   119
    }