sdkcreationmw/sdkconnectivityfw/emuconnectmanager/epdt_java/src/com/nokia/epdt/plugins/s60/pan/PanModel.java
changeset 1 ac50fd48361b
parent 0 b26acd06ea60
equal deleted inserted replaced
0:b26acd06ea60 1:ac50fd48361b
     1 /*
     1 /*
     2 * Copyright (c) 2000 - 2006 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2000 - 2006 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 the License "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".
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15  *
     8  *
    16 */
     9  * Initial Contributors:
    17 
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: 
       
    15  *
       
    16  */
    18 
    17 
    19 package com.nokia.epdt.plugins.s60.pan;
    18 package com.nokia.epdt.plugins.s60.pan;
    20 
    19 
    21 import com.nokia.epdt.core.Constants;
       
    22 import org.apache.log4j.Logger;
       
    23 import java.io.FileReader;
    20 import java.io.FileReader;
    24 import java.io.FileWriter;
    21 import java.io.FileWriter;
    25 import java.io.FileNotFoundException;
       
    26 import java.io.IOException;
    22 import java.io.IOException;
    27 import java.util.LinkedList;
    23 import java.util.LinkedList;
    28 
    24 
       
    25 import org.apache.log4j.Logger;
       
    26 
    29 /**
    27 /**
    30  * PanModel
    28  * PanModel
    31  * HCI :
    29  * HCLT :
    32  * [hci] hcidllfilename=
    30  * 
    33  *  hci_h4.dll
    31  * [hctl]
    34  *  hci_bcsp.dll
    32  * port= 1
    35  *  hci_usb.dll
    33  * baud_rate= 115200
       
    34  *
    36  * COM port:
    35  * COM port:
    37  * -1 = disable
    36  * -1 = disable
    38  * 0 - 15 = 1 - 16 enable
    37  * 0 - 15 = 1 - 16 enable
    39  *
    38  *
    40  */
    39  */
    41 class PanModel{
    40 class PanModel {
    42 	static Logger log = Logger.getLogger(PanModel.class);
    41 	static Logger log = Logger.getLogger(PanModel.class);
    43 	public static int BT_HCI_USB_INDEX = 2;
    42 	public static int BT_HCI_USB_INDEX = 2;
    44 	static LinkedList hciList= new LinkedList();
    43 	static LinkedList hciList = new LinkedList();
    45 	{
    44 	{
    46 		hciList.add(0, "hci_bcsp.dll");
    45 		hciList.add(0, "hci_bcsp.dll");
    47 		hciList.add(1, "hci_h4.dll");
    46 		hciList.add(1, "hci_h4.dll");
    48 		hciList.add(BT_HCI_USB_INDEX, "hci_usb.dll");
    47 		hciList.add(BT_HCI_USB_INDEX, "hci_usb.dll");
    49 	}
    48 	}
    50     
       
    51     private PropSets irdaProps = new PropSets();
       
    52     private PropSets btProps = new PropSets();
       
    53     private String epoc32;
       
    54     
       
    55     public PanModel(String epocroot) throws IOException
       
    56     {
       
    57     	this.epoc32 = epocroot;
       
    58     	init();
       
    59     }
       
    60     
       
    61     private static String getResource(String key)
       
    62     {	return PanResourceBundle.getInstance().getValue(key);  }
       
    63     
       
    64     public boolean isBluetoothEnabled(){ return getBluetoothComPort()>=0; }
       
    65     
       
    66     public int getBluetoothHci() {
       
    67     	String hci = btProps.getValue(getResource("bluetooth.esk.sectionName"), 
       
    68 			getResource("bluetooth.esk.dllKey"));
       
    69     	return hciList.indexOf(hci); 
       
    70     }
       
    71     public void setBluetoothHci(int index)
       
    72     { 	btProps.setValue(getResource("bluetooth.esk.sectionName"), 
       
    73     			getResource("bluetooth.esk.dllKey"), (String)hciList.get(index)); }
       
    74     
       
    75     public int getBluetoothComPort()
       
    76     {
       
    77 			String btPort =  btProps.getValue(getResource("bluetooth.esk.sectionName"), 
       
    78 					getResource("bluetooth.esk.portKey"));
       
    79 			return Integer.parseInt(btPort);
       
    80     }
       
    81     
       
    82     public void setBluetoothComPort(int comPort)
       
    83     {btProps.setValue(getResource("bluetooth.esk.sectionName"), 
       
    84 			getResource("bluetooth.esk.portKey"), Integer.toString(comPort));}
       
    85     		
       
    86     public boolean isIrdaEnabled() { return getIrdaComPort() >=0; }
       
    87     
       
    88     public int getIrdaComPort()
       
    89     {return Integer.parseInt(
       
    90 			irdaProps.getValue(getResource("irda.esk.sectionName"), 
       
    91 					getResource("irda.esk.portKey"))); }
       
    92     public void setIrdaComPort(int comPort)
       
    93     {irdaProps.setValue(getResource("irda.esk.sectionName"), 
       
    94 			getResource("irda.esk.portKey"), Integer.toString(comPort));}
       
    95 
    49 
    96     /**
    50 	private PropSets btProps = new PropSets();
    97      * The function reads innitial values from .esk files
    51 	private String epoc32;
    98      *
    52 
    99      */
    53 	public PanModel(String epocroot) throws IOException {
   100     public void init() throws IOException
    54 		this.epoc32 = epocroot;
   101     {	//Initialisation of btProps and irdaProps from .esk files:
    55 		init();
   102     	String btFileName = getBtEskFileName(); 
    56 	}
   103     	String irdaFileName = getIrdaEskFileName();
    57 
   104         
    58 	private static String getResource(String key) {
   105     	FileReader btReader =null;
    59 		return PanResourceBundle.getInstance().getValue(key);
   106     	FileReader irdaReader =null;
    60 	}
   107    		try
    61 
   108    		{
    62 	public boolean isBluetoothEnabled() {
   109    			btReader = new FileReader(btFileName);
    63 		return getBluetoothComPort() >= 0;
   110    			btProps.load(btReader);
    64 	}
   111    			irdaReader = new FileReader(irdaFileName);
    65 
   112    			irdaProps.load(irdaReader);
    66 	public int getBluetoothHci() {
   113    		}
    67 		String hci = btProps.getValue(getResource("bluetooth.esk.sectionName"),
   114    		catch(IOException ex)
    68 				getResource("bluetooth.esk.dllKey"));
   115    		{
    69 		return hciList.indexOf(hci);
   116    			throw(ex);
    70 	}
   117    		}
    71 
   118    		finally
    72 	public void setBluetoothHci(int index) {
   119    		{
    73 		btProps.setValue(getResource("bluetooth.esk.sectionName"),
   120    			try{
    74 				getResource("bluetooth.esk.dllKey"), (String) hciList
   121    				if(btReader != null) btReader.close();
    75 						.get(index));
   122    				if(irdaReader != null)irdaReader.close();
    76 	}
   123    			}catch(IOException ex)
    77 
   124    			{log.error("error closing bt or IrDa .esk configuration files:"
    78 	public int getBluetoothComPort() {
   125    					+ ex.getMessage());}
    79 		String btPort = btProps.getValue(
   126    		}
    80 				getResource("bluetooth.esk.sectionName"),
   127     }
    81 				getResource("bluetooth.esk.portKey"));
   128     public void save()
    82 		return Integer.parseInt(btPort);
   129     {
    83 	}
   130     	String btFileName = getBtEskFileName();
    84 
   131     	String irdaFileName = getIrdaEskFileName();
    85 	public void setBluetoothComPort(int comPort) {
   132         
    86 		btProps
   133     	FileWriter btWriter =null;
    87 				.setValue(getResource("bluetooth.esk.sectionName"),
   134     	FileWriter irdaWriter =null;
    88 						getResource("bluetooth.esk.portKey"), Integer
   135    		try
    89 								.toString(comPort));
   136    		{
    90 	}
   137    			btWriter = new FileWriter(btFileName);
    91 
   138    			btProps.save(btWriter);
    92 	/**
   139    			irdaWriter = new FileWriter(irdaFileName);
    93 	 * The function reads innitial values from .esk files
   140    			irdaProps.save(irdaWriter);
    94 	 *
   141    		}
    95 	 */
   142    		catch(IOException ex)
    96 	public void init() throws IOException { //Initialisation of btProps from .esk file:
   143    		{
    97 		String btFileName = getBtEskFileName();
   144    			log.error("Error saving BT or Irda ESK files:"+ex.getMessage());
    98 
   145    		}
    99 		FileReader btReader = null;
   146    		finally
   100 		try {
   147    		{
   101 			btReader = new FileReader(btFileName);
   148    			try{
   102 			btProps.load(btReader);
   149    				if(btWriter != null) btWriter.close();
   103 		} catch (IOException ex) {
   150    				if(irdaWriter != null)irdaWriter.close();
   104 			throw (ex);
   151    			}catch(IOException ex)
   105 		} finally {
   152    			{log.error("error closing bt or IrDa .esk configuration files:"
   106 			try {
   153    					+ ex.getMessage());}
   107 				if (btReader != null)
   154    		}
   108 					btReader.close();
   155     	
   109 			} catch (IOException ex) {
   156     }
   110 				log.error("Error closing BT ESK configuration files:"
   157     private String getBtEskFileName()
   111 						+ ex.getMessage());
   158     {	return epoc32 + getResource("eskFilePath") 
   112 			}
   159 		+ "\\"+ getResource("bluetooth.eskFileName");
   113 		}
   160     }
   114 	}
   161     private String getIrdaEskFileName()
   115 
   162     {	return epoc32 + getResource("eskFilePath") 
   116 	public void save() {
   163 		+ "\\" + getResource("irda.eskFileName");
   117 		String btFileName = getBtEskFileName();
   164     }
   118 
       
   119 		FileWriter btWriter = null;
       
   120 		try {
       
   121 			btWriter = new FileWriter(btFileName);
       
   122 			btProps.save(btWriter);
       
   123 		} catch (IOException ex) {
       
   124 			log.error("Error saving BT ESK files:" + ex.getMessage());
       
   125 		} finally {
       
   126 			try {
       
   127 				if (btWriter != null)
       
   128 					btWriter.close();
       
   129 			} catch (IOException ex) {
       
   130 				log.error("error closing bt .esk configuration files:"
       
   131 						+ ex.getMessage());
       
   132 			}
       
   133 		}
       
   134 
       
   135 	}
       
   136 
       
   137 	private String getBtEskFileName() {
       
   138 		return epoc32 + getResource("eskFilePath") + "\\"
       
   139 				+ getResource("bluetooth.eskFileName");
       
   140 	}
       
   141 
   165 }
   142 }