001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is the Nokia Deployment.
027: * The Initial Developer of the Original Software is Nokia Corporation.
028: * Portions created by Nokia Corporation Copyright 2005, 2007.
029: * All Rights Reserved.
030: *
031: * If you wish your version of this file to be governed by only the CDDL
032: * or only the GPL Version 2, indicate your decision by adding
033: * "[Contributor] elects to include this software in this distribution
034: * under the [CDDL or GPL Version 2] license." If you do not indicate a
035: * single choice of license, a recipient has the option to distribute
036: * your version of this file under either the CDDL, the GPL Version 2 or
037: * to extend the choice of license to its licensees as provided above.
038: * However, if you add GPL Version 2 code and therefore, elected the GPL
039: * Version 2 license, then the option applies only if the new code is
040: * made subject to such option by the copyright holder.
041: */
042: package com.nokia.phone.deploy;
043:
044: /**
045: * This class offers interface for the native methods in CONA API. CONA api
046: * offers Application package deployment to Terminal either by using BT, IrDA,
047: * Serial or USB communication. Native methods declared in this class available
048: * in the ConnJNI.dll. The ConnJNI.dll will itself use methods available in
049: * ConnAPI.dll that has been taken from PC Suite Connectivity API 1.1 which
050: * is freely downloadable from Forum Nokia.
051: *
052: */
053: public class CONA {
054: // Connection Media Types:
055: public static final int CONAPI_MEDIA_ALL = 0x01;
056: public static final int CONAPI_MEDIA_IRDA = 0x02;
057: public static final int CONAPI_MEDIA_SERIAL = 0x04;
058: public static final int CONAPI_MEDIA_BLUETOOTH = 0x08;
059: public static final int CONAPI_MEDIA_USB = 0x10;
060:
061: // The next define values used to define which type of struct is used:
062: public static final int CONA_APPLICATION_TYPE_SIS = 0x00000001; // Use when struct type is CONAPI_APPLICATION_SIS
063: public static final int CONA_APPLICATION_TYPE_JAVA = 0x00000002; // Use when struct type is CONAPI_APPLICATION_JAVA
064:
065: // FSFunction values:
066: public static final int CONARefreshDeviceMemoryValues = 0x00000001;
067: public static final int CONASetCurrentFolder = 0x00000002; // also used for state type
068: public static final int CONAFindBegin = 0x00000004;
069: public static final int CONACreateFolder = 0x00000008; // also used for state type
070: public static final int CONADeleteFolder = 0x00000010;
071: public static final int CONARenameFolder = 0x00000020;
072: public static final int CONAGetFileInfo = 0x00000040;
073: public static final int CONADeleteFile = 0x00000080;
074: public static final int CONAMoveFile = 0x00000100;
075: public static final int CONACopyFile = 0x00000200; // also used for state type
076: public static final int CONARenameFile = 0x00000400;
077: public static final int CONAReadFile = 0x00000800;
078: public static final int CONAWriteFile = 0x00001000;
079: public static final int CONAConnectionLost = 0x00002000;
080: public static final int CONAInstallApplication = 0x00004000; // also used for state type
081:
082: private static CONA instance = null;
083: private static boolean connAPIdllFound = false;
084: private static boolean connJNIdllFound = false;
085:
086: private static boolean OSSupportsDeployment = true;
087:
088: /**
089: * Try to load the native library only if running in a Windows environment.
090: */
091: static {
092: if (!System
093: .getProperty("os.name").toLowerCase().startsWith("windows")) { //$NON-NLS-1$ //$NON-NLS-2$
094: OSSupportsDeployment = false;
095: }
096: }
097:
098: private CONA() {
099: }
100:
101: public static CONA getInstance() {
102: if (instance == null) {
103: instance = new CONA();
104: try {
105: // ConnJNI.dll is linked so that is presumes that ConnAPI.dll is
106: // located
107: // in the start up folder. We must load the ConnAPI.dll to
108: // memory before
109: // loading the ConnJNI.dll.
110: System.loadLibrary("ConnAPI"); // Installed in a system
111: // directory by PC-Suite
112: connAPIdllFound = true;
113: } catch (UnsatisfiedLinkError ulError) {
114: connAPIdllFound = false;
115: } catch (Exception ex) {
116: connAPIdllFound = false;
117: }
118:
119: try {
120:
121: System.loadLibrary("ConnJNI");
122:
123: connJNIdllFound = true;
124: } catch (UnsatisfiedLinkError ulError) {
125: connJNIdllFound = false;
126: } catch (Exception ex) {
127: connJNIdllFound = false;
128: }
129: }
130:
131: return instance;
132: }
133:
134: public boolean isConnAPIDllFound() {
135: return connAPIdllFound;
136: }
137:
138: public boolean isConnJNIDllFound() {
139: return connJNIdllFound;
140: }
141:
142: public boolean isOSSupportsDeployment() {
143: return OSSupportsDeployment;
144: }
145:
146: // Device callback macros
147: public static int getConnapiStatus(int status) {
148: return (0x0000FFFF & status);
149: }
150:
151: public static int getConnapiInfo(int status) {
152: return ((0x00FF0000 & status) >> 16);
153: }
154:
155: public static int getConnapiInfoData(int status) {
156: return ((0xFF000000 & status) >> 24);
157: }
158:
159: /**
160: * This method is called from native code to inform of device operations i.e.
161: * device connect, device disconnect.
162: * Nothing needed to be done in this implementation.
163: */
164: public void fireDeviceNotify(int status, int deviceId) {
165: // do nothing
166: }
167:
168: /**
169: * This method is called from native code to inform of file operations.
170: * Nothing needed to be done in this implementation.
171: */
172: public void fireFileOperationNotify(int function, int state,
173: int transferredBytes, int allBytes) {
174: // do nothing
175: }
176:
177: /*
178: * Native methods available in the ConnJNI.dll. ConnJNI.dll will
179: * itself require ConnAPI.dll that has been taken from PC Suite.
180: */
181: private native String native_getVersion();
182:
183: private native boolean native_connectServiceLayer();
184:
185: private native boolean native_updateDeviceList();
186:
187: private native String native_getDeviceType(int id);
188:
189: private native String native_getDevices(int mediaType);
190:
191: private native boolean native_openConnectionTo(int id);
192:
193: private native boolean native_installFile(String filepath,
194: String filename, String jad, int filetype,
195: boolean defaultfolder);
196:
197: private native boolean native_setCurrentFolder(String folder);
198:
199: private native boolean native_createFolder(String folder);
200:
201: private native boolean native_putFile(String srcPath,
202: String dstPath, String name);
203:
204: private native int native_getStatus(int type);
205:
206: private native boolean native_closeConnection();
207:
208: private native boolean native_disconnectServiceLayer();
209:
210: public String getVersion() {
211: if (connAPIdllFound && connJNIdllFound) {
212: return native_getVersion();
213: }
214:
215: return null;
216: }
217:
218: /**
219: * Returns device media type: one of: {"IRDA", "RS232", "BLUETOOTH", "USB", NULL};
220: * id is device ID.
221: */
222: public String getDeviceType(int id) {
223: if (connAPIdllFound && connJNIdllFound) {
224: return native_getDeviceType(id);
225: }
226:
227: return null;
228: }
229:
230: public boolean connect() {
231: if (connAPIdllFound && connJNIdllFound) {
232: return native_connectServiceLayer();
233: }
234:
235: return false;
236: }
237:
238: public boolean disconnect() {
239: if (connAPIdllFound && connJNIdllFound) {
240: return native_disconnectServiceLayer();
241: }
242:
243: return false;
244: }
245:
246: public boolean updateDeviceList() {
247: if (connAPIdllFound && connJNIdllFound) {
248: return native_updateDeviceList();
249: }
250:
251: return false;
252: }
253:
254: /**
255: * Returns comma-separated list of device names/IDs.
256: * MediaType is one of {CONAPI_MEDIA_ALL, CONAPI_MEDIA_IRDA, CONAPI_MEDIA_SERIAL, CONAPI_MEDIA_BLUETOOTH, CONAPI_MEDIA_USB}
257: * Each device listed with the format: "%s (ID:%i)"
258: */
259: public String getDevices(int mediaType) {
260: if ((mediaType < CONAPI_MEDIA_ALL)
261: || (mediaType > CONAPI_MEDIA_USB)) {
262: return null;
263: }
264:
265: if (connAPIdllFound && connJNIdllFound) {
266: return native_getDevices(mediaType);
267: }
268:
269: return null;
270: }
271:
272: public boolean installApplication(String filepath, String filename,
273: String jad, int filetype, boolean defaultFolder) {
274: if ((filepath == null) || (filename == null))
275: return false;
276:
277: if ((filetype != CONA_APPLICATION_TYPE_JAVA)
278: && (filetype != CONA_APPLICATION_TYPE_SIS))
279: return false;
280:
281: if (connAPIdllFound && connJNIdllFound) {
282: return native_installFile(filepath, filename, jad,
283: filetype, defaultFolder);
284: }
285:
286: return false;
287: }
288:
289: // id is device ID
290: public boolean openFileSystem(int id) {
291: if (connAPIdllFound && connJNIdllFound) {
292: return native_openConnectionTo(id);
293: }
294:
295: return false;
296: }
297:
298: public boolean closeFileSystem() {
299: if (connAPIdllFound && connJNIdllFound) {
300: return native_closeConnection();
301: }
302:
303: return false;
304: }
305: } // End of CONA
|