|
1 /* |
|
2 * Copyright (c) 2000 - 2006 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.epdt.plugins.s60.pan; |
|
20 |
|
21 import com.nokia.epdt.core.Constants; |
|
22 import org.apache.log4j.Logger; |
|
23 import java.io.FileReader; |
|
24 import java.io.FileWriter; |
|
25 import java.io.FileNotFoundException; |
|
26 import java.io.IOException; |
|
27 import java.util.LinkedList; |
|
28 |
|
29 /** |
|
30 * PanModel |
|
31 * HCI : |
|
32 * [hci] hcidllfilename= |
|
33 * hci_h4.dll |
|
34 * hci_bcsp.dll |
|
35 * hci_usb.dll |
|
36 * COM port: |
|
37 * -1 = disable |
|
38 * 0 - 15 = 1 - 16 enable |
|
39 * |
|
40 */ |
|
41 class PanModel{ |
|
42 static Logger log = Logger.getLogger(PanModel.class); |
|
43 public static int BT_HCI_USB_INDEX = 2; |
|
44 static LinkedList hciList= new LinkedList(); |
|
45 { |
|
46 hciList.add(0, "hci_bcsp.dll"); |
|
47 hciList.add(1, "hci_h4.dll"); |
|
48 hciList.add(BT_HCI_USB_INDEX, "hci_usb.dll"); |
|
49 } |
|
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 |
|
96 /** |
|
97 * The function reads innitial values from .esk files |
|
98 * |
|
99 */ |
|
100 public void init() throws IOException |
|
101 { //Initialisation of btProps and irdaProps from .esk files: |
|
102 String btFileName = getBtEskFileName(); |
|
103 String irdaFileName = getIrdaEskFileName(); |
|
104 |
|
105 FileReader btReader =null; |
|
106 FileReader irdaReader =null; |
|
107 try |
|
108 { |
|
109 btReader = new FileReader(btFileName); |
|
110 btProps.load(btReader); |
|
111 irdaReader = new FileReader(irdaFileName); |
|
112 irdaProps.load(irdaReader); |
|
113 } |
|
114 catch(IOException ex) |
|
115 { |
|
116 throw(ex); |
|
117 } |
|
118 finally |
|
119 { |
|
120 try{ |
|
121 if(btReader != null) btReader.close(); |
|
122 if(irdaReader != null)irdaReader.close(); |
|
123 }catch(IOException ex) |
|
124 {log.error("error closing bt or IrDa .esk configuration files:" |
|
125 + ex.getMessage());} |
|
126 } |
|
127 } |
|
128 public void save() |
|
129 { |
|
130 String btFileName = getBtEskFileName(); |
|
131 String irdaFileName = getIrdaEskFileName(); |
|
132 |
|
133 FileWriter btWriter =null; |
|
134 FileWriter irdaWriter =null; |
|
135 try |
|
136 { |
|
137 btWriter = new FileWriter(btFileName); |
|
138 btProps.save(btWriter); |
|
139 irdaWriter = new FileWriter(irdaFileName); |
|
140 irdaProps.save(irdaWriter); |
|
141 } |
|
142 catch(IOException ex) |
|
143 { |
|
144 log.error("Error saving BT or Irda ESK files:"+ex.getMessage()); |
|
145 } |
|
146 finally |
|
147 { |
|
148 try{ |
|
149 if(btWriter != null) btWriter.close(); |
|
150 if(irdaWriter != null)irdaWriter.close(); |
|
151 }catch(IOException ex) |
|
152 {log.error("error closing bt or IrDa .esk configuration files:" |
|
153 + ex.getMessage());} |
|
154 } |
|
155 |
|
156 } |
|
157 private String getBtEskFileName() |
|
158 { return epoc32 + getResource("eskFilePath") |
|
159 + "\\"+ getResource("bluetooth.eskFileName"); |
|
160 } |
|
161 private String getIrdaEskFileName() |
|
162 { return epoc32 + getResource("eskFilePath") |
|
163 + "\\" + getResource("irda.eskFileName"); |
|
164 } |
|
165 } |