javacommons/utils/src.s60/javaredirector.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2009 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: Redirector redirects standard outs and log messages
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "javaredirector.h"
       
    20 
       
    21 #include "javaredirectconsts.h"
       
    22 using namespace java::util;
       
    23 
       
    24 OS_EXPORT Redirector::Redirector() : mStatus(KErrNotReady)
       
    25 {
       
    26 }
       
    27 
       
    28 OS_EXPORT Redirector::~Redirector()
       
    29 {
       
    30 }
       
    31 
       
    32 OS_EXPORT TInt Redirector::systemOut(const TDesC8& aData)
       
    33 {
       
    34     return send(ESystemOut, aData);
       
    35 }
       
    36 
       
    37 OS_EXPORT TInt Redirector::systemErr(const TDesC8& aData)
       
    38 {
       
    39     return send(ESystemErr, aData);
       
    40 }
       
    41 
       
    42 OS_EXPORT TInt Redirector::log(const TDesC8& aData)
       
    43 {
       
    44     Redirector redirector;
       
    45     redirector.connect();
       
    46 
       
    47     TInt rc = redirector.send(ELog, aData);
       
    48     redirector.close();
       
    49 
       
    50     return rc;
       
    51 }
       
    52 
       
    53 TInt Redirector::send(TInt aFunction, const TDesC8& aData)
       
    54 {
       
    55     if (mStatus == KErrNone)
       
    56     {
       
    57         mStatus =  SendReceive(aFunction, TIpcArgs(&aData));
       
    58     }
       
    59     return mStatus;
       
    60 }
       
    61 
       
    62 OS_EXPORT TInt Redirector::connect()
       
    63 {
       
    64     TVersion version(REDIRECT_VERSION_MAJOR, REDIRECT_VERSION_MINOR, REDIRECT_VERSION_BUILD);
       
    65     mStatus = CreateSession(KJavaRedirectServer, version, -1, EIpcSession_Sharable);
       
    66     return mStatus;
       
    67 }
       
    68 
       
    69 OS_EXPORT void Redirector::close()
       
    70 {
       
    71     Close();
       
    72 }