javaextensions/comm/src.s60/dynamicpropertyhandlerjni.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:  ?Description
       
    15  *
       
    16 */
       
    17 
       
    18 #include <e32def.h>
       
    19 #include <c32comm.h>
       
    20 #include <e32std.h>
       
    21 #include <usbman.h>
       
    22 #include <acminterface.h>
       
    23 #include "com_nokia_mj_impl_properties_comm_DynamicPropertyHandler.h"
       
    24 #include "s60commonutils.h"
       
    25 #include "logger.h"
       
    26 
       
    27 _LIT(KIRCsyName, "IRCOMM"); // IR CSY
       
    28 _LIT(KSerialCsyName, "ECUART"); // Serial CSY
       
    29 _LIT(KBluetoothCsyName, "BTCOMM"); // BT CSY
       
    30 
       
    31 _LIT(KSerialPort, "COM");
       
    32 _LIT(KSymbianSerialPort, "COMM");
       
    33 
       
    34 // USB
       
    35 _LIT(KUSBPort, "USB");
       
    36 _LIT(KSymbianUSBPort, "ACM");
       
    37 
       
    38 _LIT(KIRPort, "IR");
       
    39 _LIT(KSymbianIRPort, "IrCOMM");
       
    40 
       
    41 // BT
       
    42 _LIT(KBTPort, "BT");
       
    43 _LIT(KSymbianBTPort, "BTCOMM");
       
    44 
       
    45 using namespace java::util;
       
    46 
       
    47 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_properties_comm_DynamicPropertyHandler__1getAvailCommPortInfo
       
    48 (JNIEnv* aJni, jobject /*peer*/)
       
    49 {
       
    50     JELOG2(ESOCKET);
       
    51     TBuf<700> names;
       
    52     TBuf<10> javaName;
       
    53     TSerialInfo info;
       
    54     bool validPort = true;
       
    55     RCommServ cserver;
       
    56     TInt r = cserver.Connect();
       
    57 
       
    58     if (r != KErrNone)
       
    59     {
       
    60         return NULL;
       
    61     }
       
    62     r = cserver.LoadCommModule(KSerialCsyName); // Serial
       
    63     r = cserver.LoadCommModule(KIRCsyName); // IR
       
    64     r = cserver.LoadCommModule(KAcmCsyName); // USB
       
    65     r = cserver.LoadCommModule(KBluetoothCsyName); // BT
       
    66 
       
    67     if (r != KErrNone)
       
    68     {
       
    69         return NULL;
       
    70     }
       
    71     TInt numPorts = 0;
       
    72     cserver.NumPorts(numPorts);
       
    73     TInt count;
       
    74     TBuf<10> name;
       
    75     TBuf<40> tempname;
       
    76     TBuf<10> buf;
       
    77     _LIT(KDefaultPort, "USB2");
       
    78     names.Append(KDefaultPort); // first value in the returned string , should be valid one (MIDP spec)
       
    79     for (count = 0; count < numPorts; count++)
       
    80     {
       
    81         r = cserver.GetPortInfo(count, buf, info);
       
    82         validPort = true;
       
    83         name = info.iName; // will be one of these COMM,IrCOMM,BTCOMM,ACM
       
    84 
       
    85         if (info.iName.MatchF(KSymbianSerialPort) != KErrNotFound)
       
    86         {
       
    87             //its a serial port
       
    88             javaName = KSerialPort;
       
    89         }
       
    90         else if (info.iName.MatchF(KSymbianIRPort) != KErrNotFound)
       
    91         {
       
    92             //infrared
       
    93             javaName = KIRPort;
       
    94         }
       
    95         else if (info.iName.MatchF(KSymbianBTPort) != KErrNotFound)
       
    96         {
       
    97             //bluetooth
       
    98             javaName = KBTPort;
       
    99         }
       
   100         else if (info.iName.MatchF(KSymbianUSBPort) != KErrNotFound)
       
   101         {
       
   102             //usb
       
   103             javaName = KUSBPort;
       
   104         }
       
   105         else
       
   106         {
       
   107             validPort = EFalse;
       
   108         }
       
   109         if (!validPort)
       
   110         {
       
   111             continue;
       
   112         }
       
   113         /* for each port, get the start index to end index number */
       
   114         for (int j = info.iLowUnit, k = 1; j <= info.iHighUnit; ++j, k++)
       
   115         {
       
   116             tempname.Format(_L("%S%u"), &javaName, k); // similar to sprintf() function
       
   117             if (tempname.Compare(KDefaultPort) == 0) // skip the default one as it's already added
       
   118             {
       
   119                 continue;
       
   120             }
       
   121             if ((names.MaxLength() - names.Length()) > tempname.Length())
       
   122             { // enough space in the buffer
       
   123                 names.Append(',');
       
   124                 names.Append(tempname);
       
   125             }
       
   126 
       
   127         }
       
   128     }
       
   129     jstring javaString = NULL;
       
   130     javaString = S60CommonUtils::NativeToJavaString(*aJni, names);
       
   131     return javaString;
       
   132 }