javacommons/jvms/nativeportlayer/src.s60/jvmnativeportlayer.cpp
changeset 80 d6dafc5d983f
parent 21 2a9601315dfc
equal deleted inserted replaced
78:71ad690e91f5 80:d6dafc5d983f
     1 /*
     1 /*
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    28 
    28 
    29 MJvmNativePortLayer* CJvmNativePortLayer::NewL(void)
    29 MJvmNativePortLayer* CJvmNativePortLayer::NewL(void)
    30 {
    30 {
    31     JELOG2(EJVM);
    31     JELOG2(EJVM);
    32     CJvmNativePortLayer* portLayer = new(ELeave) CJvmNativePortLayer;
    32     CJvmNativePortLayer* portLayer = new(ELeave) CJvmNativePortLayer;
    33     CleanupStack::PushL(portLayer);
    33     portLayer->Construct();
    34     portLayer->ConstructL();
       
    35     CleanupStack::Pop(portLayer);
       
    36     return portLayer;
    34     return portLayer;
    37 }
    35 }
    38 
    36 
    39 CJvmNativePortLayer::CJvmNativePortLayer():iStdOut(0), iStdErr(0)
    37 CJvmNativePortLayer::CJvmNativePortLayer()
    40 {
    38 {
    41     JELOG2(EJVM);
    39     JELOG2(EJVM);
    42 }
    40 }
    43 
    41 
    44 CJvmNativePortLayer::~CJvmNativePortLayer()
    42 CJvmNativePortLayer::~CJvmNativePortLayer()
    45 {
    43 {
    46     JELOG2(EJVM);
    44     JELOG2(EJVM);
    47     if (iStdOut != 0)
       
    48     {
       
    49         delete iStdOut;
       
    50         iStdOut = 0;
       
    51     }
       
    52     if (iStdErr != 0)
       
    53     {
       
    54         delete iStdErr;
       
    55         iStdErr = 0;
       
    56     }
       
    57     iRedirector.close();
    45     iRedirector.close();
    58 }
    46 }
    59 
    47 
    60 
    48 
    61 _LIT(KOutpuDir,"java");
    49 _LIT(KOutpuDir,"java");
    62 _LIT(KOutpuFullDir,"c:\\logs\\java");
    50 _LIT(KOutpuFullDir,"c:\\logs\\java");
    63 _LIT(KConsole,"vmconsole.txt");
    51 _LIT(KConsole,"vmconsole.txt");
    64 
    52 
    65 void CJvmNativePortLayer::ConstructL(void)
    53 void CJvmNativePortLayer::Construct()
    66 {
    54 {
    67     JELOG2(EJVM);
    55     JELOG2(EJVM);
    68     _LIT(KStdOut,"stdout_%02i%02i_%02i%02i%02i.txt");
       
    69     _LIT(KStdErr,"stderr_%02i%02i_%02i%02i%02i.txt");
       
    70     iStdOut = HBufC::NewL(KDesLength);
       
    71     iStdErr = HBufC::NewL(KDesLength);
       
    72 
    56 
    73     RFs rfs;
    57     RFs rfs;
    74     TUint dummy;
    58     TUint dummy;
    75 
    59 
    76     if (rfs.Connect() != KErrNone)
    60     if (rfs.Connect() != KErrNone)
    83         iLogging = EFalse;
    67         iLogging = EFalse;
    84     }
    68     }
    85     else
    69     else
    86     {
    70     {
    87         iLogging = ETrue;
    71         iLogging = ETrue;
    88         TTime time;
       
    89         time.HomeTime();
       
    90         TDateTime dt = time.DateTime();
       
    91 
       
    92         iStdOut->Des().Format(KStdOut, dt.Month()+1, dt.Day()+1,
       
    93                               dt.Hour(), dt.Minute(), dt.Second());
       
    94         iStdErr->Des().Format(KStdErr, dt.Month()+1, dt.Day()+1,
       
    95                               dt.Hour(), dt.Minute(), dt.Second());
       
    96     }
    72     }
    97     rfs.Close();
    73     rfs.Close();
    98 
    74 
    99     iRedirector.connect();
    75     iRedirector.connect();
   100 }
    76 }
   101 
    77 
   102 MJavaFile* CJvmNativePortLayer::GetJavaFileL()
    78 MJavaFile* CJvmNativePortLayer::GetJavaFileL()
   103 {
    79 {
   104     JELOG2(EJVM);
    80     JELOG2(EJVM);
   105     MJavaFile* javaFile = CJavaFile::NewL();
    81     return new(ELeave) CJavaFile();
   106     return javaFile;
       
   107 }
    82 }
   108 
    83 
   109 void CJvmNativePortLayer::WriteToStdoutL(const TDesC8& aData)
    84 void CJvmNativePortLayer::WriteToStdoutL(const TDesC8& aData)
   110 {
    85 {
   111     if (iLogging)
    86     if (iLogging)
   112     {
    87     {
   113 //              RFileLogger::Write( KOutpuDir, *iStdOut, EFileLoggingModeAppendRaw, aData);
       
   114         RFileLogger::Write(KOutpuDir, KConsole, EFileLoggingModeAppendRaw, aData);
    88         RFileLogger::Write(KOutpuDir, KConsole, EFileLoggingModeAppendRaw, aData);
   115     }
    89     }
   116     iRedirector.systemOut(aData);
    90     iRedirector.systemOut(aData);
   117 }
    91 }
   118 void CJvmNativePortLayer::WriteToStderrL(const TDesC8& aData)
    92 void CJvmNativePortLayer::WriteToStderrL(const TDesC8& aData)
   119 {
    93 {
   120     if (iLogging)
    94     if (iLogging)
   121     {
    95     {
   122 //              RFileLogger::Write( KOutpuDir, *iStdErr, EFileLoggingModeAppendRaw, aData);
       
   123         RFileLogger::Write(KOutpuDir, KConsole, EFileLoggingModeAppendRaw, aData);
    96         RFileLogger::Write(KOutpuDir, KConsole, EFileLoggingModeAppendRaw, aData);
   124     }
    97     }
   125     iRedirector.systemErr(aData);
    98     iRedirector.systemErr(aData);
   126 }
    99 }
   127 
   100 
   128 
   101 
   129 
   102 EXPORT_C MJvmNativePortLayer* javaruntime::GetPortLayerL()
   130 //Obsolite method, but keeping to be in sync with legacy
       
   131 EXPORT_C void CJvmNativePortLayer::SetPointerToCafMethod(TBool(* /*aUseCafForFileOpen*/)(const TDesC&))
       
   132 {
       
   133     JELOG2(EJVM);
       
   134 }
       
   135 EXPORT_C MJvmNativePortLayer* GetPortLayerL()
       
   136 {
   103 {
   137     JELOG2(EJVM);
   104     JELOG2(EJVM);
   138     return CJvmNativePortLayer::NewL();
   105     return CJvmNativePortLayer::NewL();
   139 }
   106 }
       
   107 
   140 const TThreadPriority priorityMapping[] =
   108 const TThreadPriority priorityMapping[] =
   141 {
   109 {
   142     EPriorityMuchLess, //0
   110     EPriorityMuchLess, //0
   143     EPriorityMuchLess, //1
   111     EPriorityMuchLess, //1
   144     EPriorityMuchLess, //2
   112     EPriorityMuchLess, //2
   150     EPriorityLess,     //8
   118     EPriorityLess,     //8
   151     EPriorityNormal,   //9
   119     EPriorityNormal,   //9
   152     EPriorityNormal,   //10
   120     EPriorityNormal,   //10
   153     EPriorityMore,     //11
   121     EPriorityMore,     //11
   154 };
   122 };
   155 EXPORT_C TThreadPriority GetSingleThreadPriority(const TInt& aJavaPriority)
   123 
       
   124 EXPORT_C TThreadPriority javaruntime::GetSingleThreadPriority(const TInt& aJavaPriority)
   156 {
   125 {
   157     JELOG2(EJVM);
   126     JELOG2(EJVM);
   158     TInt index = Max(Min(aJavaPriority,11),0);
   127     TInt index = Max(Min(aJavaPriority,11),0);
   159     return priorityMapping[index];
   128     return priorityMapping[index];
   160 }
   129 }