diff --git a/wince/org.eclipse.rse.subsystems.wince/.classpath b/wince/org.eclipse.rse.subsystems.wince/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/wince/org.eclipse.rse.subsystems.wince/.project b/wince/org.eclipse.rse.subsystems.wince/.project new file mode 100644 index 00000000000..28514fc6a6c --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.subsystems.wince + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/wince/org.eclipse.rse.subsystems.wince/META-INF/MANIFEST.MF b/wince/org.eclipse.rse.subsystems.wince/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..2cf263933ce --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name.0 +Bundle-SymbolicName: org.eclipse.rse.subsystems.wince;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: %Bundle-Vendor.0 +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services, + org.eclipse.rse.core, + org.eclipse.rse.subsystems.files.core, + org.eclipse.rse.ui, + org.eclipse.core.resources +Import-Package: org.eclipse.tm.rapi +Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Eclipse-LazyStart: true +Bundle-Localization: plugin +Bundle-Activator: org.eclipse.rse.internal.subsystems.files.wince.Activator +Export-Package: org.eclipse.rse.subsystems.files.wince diff --git a/wince/org.eclipse.rse.subsystems.wince/build.properties b/wince/org.eclipse.rse.subsystems.wince/build.properties new file mode 100644 index 00000000000..8de80a8e853 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/build.properties @@ -0,0 +1,17 @@ +############################################################################### +# Copyright (c) 2008 Radoslav Gerganov +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Radoslav Gerganov - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties,\ + icons/ diff --git a/wince/org.eclipse.rse.subsystems.wince/icons/systemfiles_obj.gif b/wince/org.eclipse.rse.subsystems.wince/icons/systemfiles_obj.gif new file mode 100644 index 00000000000..874c9926215 Binary files /dev/null and b/wince/org.eclipse.rse.subsystems.wince/icons/systemfiles_obj.gif differ diff --git a/wince/org.eclipse.rse.subsystems.wince/icons/systemfileslive_obj.gif b/wince/org.eclipse.rse.subsystems.wince/icons/systemfileslive_obj.gif new file mode 100644 index 00000000000..885b8a69e39 Binary files /dev/null and b/wince/org.eclipse.rse.subsystems.wince/icons/systemfileslive_obj.gif differ diff --git a/wince/org.eclipse.rse.subsystems.wince/icons/wince.gif b/wince/org.eclipse.rse.subsystems.wince/icons/wince.gif new file mode 100644 index 00000000000..ecbea5e82d9 Binary files /dev/null and b/wince/org.eclipse.rse.subsystems.wince/icons/wince.gif differ diff --git a/wince/org.eclipse.rse.subsystems.wince/icons/wincelive.gif b/wince/org.eclipse.rse.subsystems.wince/icons/wincelive.gif new file mode 100644 index 00000000000..2a550c98bd9 Binary files /dev/null and b/wince/org.eclipse.rse.subsystems.wince/icons/wincelive.gif differ diff --git a/wince/org.eclipse.rse.subsystems.wince/plugin.properties b/wince/org.eclipse.rse.subsystems.wince/plugin.properties new file mode 100644 index 00000000000..e7c4ce7b1d4 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/plugin.properties @@ -0,0 +1,16 @@ +############################################################################### +# Copyright (c) 2008 Radoslav Gerganov +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Radoslav Gerganov - initial API and implementation +############################################################################### +Bundle-Vendor.0 = Eclipse.org +Bundle-Name.0 = RSE WinCE Services +systemType.label.0 = WinCE +configuration.description.0 = This configuration allows you to work with files on remote WinCE-based device using ActiveSync/RAPI2 connection. +configuration.name.0 = WinCE Files +configuration.vendor.0 = Eclipse.org diff --git a/wince/org.eclipse.rse.subsystems.wince/plugin.xml b/wince/org.eclipse.rse.subsystems.wince/plugin.xml new file mode 100644 index 00000000000..a9042996300 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/plugin.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/IWinCESubSystem.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/IWinCESubSystem.java new file mode 100644 index 00000000000..daa0632ce35 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/IWinCESubSystem.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.connectorservice.wince; + +/** + * Markup Interface for subsystems using the WinCEConnectorService. + * + * By implementing this interface, subsystems can be recognized + * as being able to share a single WinCE connector service between + * multiple different subsystems. + */ +public interface IWinCESubSystem { + +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/Messages.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/Messages.java new file mode 100644 index 00000000000..40cd19dff16 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/Messages.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.connectorservice.wince; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.rse.internal.connectorservice.wince.messages"; //$NON-NLS-1$ + public static String WinCEConnectorService_0; + public static String WinCEConnectorService_1; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/WinCEConnectorService.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/WinCEConnectorService.java new file mode 100644 index 00000000000..d824cb33f70 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/WinCEConnectorService.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.connectorservice.wince; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.subsystems.BasicConnectorService; +import org.eclipse.rse.core.subsystems.CommunicationsEvent; +import org.eclipse.rse.internal.services.wince.IRapiSessionProvider; +import org.eclipse.tm.rapi.IRapiDesktop; +import org.eclipse.tm.rapi.IRapiDevice; +import org.eclipse.tm.rapi.IRapiEnumDevices; +import org.eclipse.tm.rapi.IRapiSession; +import org.eclipse.tm.rapi.OS; +import org.eclipse.tm.rapi.RapiException; + + +/** + * Creates ActiveSync/RAPI2 connections to WinCE-based device. + */ +public class WinCEConnectorService extends BasicConnectorService implements IRapiSessionProvider { + + IRapiDesktop desktop = null; + IRapiEnumDevices enumDevices = null; + IRapiDevice device = null; + IRapiSession session = null; + + public WinCEConnectorService(IHost host) { + super(Messages.WinCEConnectorService_0, Messages.WinCEConnectorService_1, host, 0); + } + + protected void internalConnect(IProgressMonitor monitor) throws Exception { + fireCommunicationsEvent(CommunicationsEvent.BEFORE_CONNECT); + OS.CoInitializeEx(0, OS.COINIT_MULTITHREADED); + desktop = IRapiDesktop.getInstance(); + enumDevices = desktop.enumDevices(); + device = enumDevices.next(); + session = device.createSession(); + session.init(); + } + + protected void internalDisconnect(IProgressMonitor monitor) throws Exception { + fireCommunicationsEvent(CommunicationsEvent.BEFORE_DISCONNECT); + if (session != null) { + session.uninit(); + session.release(); + session = null; + } + if (device != null) { + device.release(); + device = null; + } + if (enumDevices != null) { + enumDevices.release(); + enumDevices = null; + } + if (desktop != null) { + desktop.release(); + desktop = null; + } + } + + public boolean isConnected() { + if (device != null) { + try { + return device.isConnected(); + } catch (RapiException e) { + //ignore + } + } + return false; + } + + public IRapiSession getSession() { + return session; + } + +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/WinCEConnectorServiceManager.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/WinCEConnectorServiceManager.java new file mode 100644 index 00000000000..cd4c3e12995 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/WinCEConnectorServiceManager.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.connectorservice.wince; + +import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.subsystems.AbstractConnectorServiceManager; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.ISubSystem; + +public class WinCEConnectorServiceManager extends AbstractConnectorServiceManager { + + private static WinCEConnectorServiceManager inst = null; + + private WinCEConnectorServiceManager() { + super(); + } + + public static WinCEConnectorServiceManager getInstance() { + if (inst == null) { + inst = new WinCEConnectorServiceManager(); + } + return inst; + } + + public IConnectorService createConnectorService(IHost host) { + IConnectorService connectorService = new WinCEConnectorService(host); + return connectorService; + } + + public Class getSubSystemCommonInterface(ISubSystem subsystem) { + return IWinCESubSystem.class; + } + + public boolean sharesSystem(ISubSystem otherSubSystem) { + return (otherSubSystem instanceof IWinCESubSystem); + } + +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/messages.properties b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/messages.properties new file mode 100644 index 00000000000..ea4ff0c151c --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/connectorservice/wince/messages.properties @@ -0,0 +1,2 @@ +WinCEConnectorService_0=WinCE Connector Service +WinCEConnectorService_1=The WinCE Connector Service uses ActiveSync/RAPI2 to connect to the device. diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/IRapiSessionProvider.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/IRapiSessionProvider.java new file mode 100644 index 00000000000..8fec7f8d73e --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/IRapiSessionProvider.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.services.wince; + +import org.eclipse.tm.rapi.IRapiSession; + +public interface IRapiSessionProvider { + + /** + * Returns an active RAPI2 session from a ConnectorService. + */ + public IRapiSession getSession(); + +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/IWinCEService.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/IWinCEService.java new file mode 100644 index 00000000000..6f00956cc70 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/IWinCEService.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.services.wince; + +/** + * Markup Interface for services using the WinCEConnectorService. + * + * By implementing this interface, services can be recognized + * as operating against an WinCEConnectorService. + * The interface is used as the key in a table for looking up the connector + * service when needed. + */ +public interface IWinCEService { + +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/Messages.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/Messages.java new file mode 100644 index 00000000000..bbc8934a6f1 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/Messages.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.services.wince.files; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Messages { + private static final String BUNDLE_NAME = "org.eclipse.rse.internal.services.wince.files.messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle(BUNDLE_NAME); + + private Messages() { + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/WinCEFileService.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/WinCEFileService.java new file mode 100644 index 00000000000..96dcf06e9af --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/WinCEFileService.java @@ -0,0 +1,502 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.services.wince.files; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.internal.services.wince.IRapiSessionProvider; +import org.eclipse.rse.internal.services.wince.IWinCEService; +import org.eclipse.rse.services.clientserver.FileTypeMatcher; +import org.eclipse.rse.services.clientserver.IMatcher; +import org.eclipse.rse.services.clientserver.NamePatternMatcher; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.files.AbstractFileService; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.services.files.RemoteFileException; +import org.eclipse.tm.rapi.IRapiSession; +import org.eclipse.tm.rapi.OS; +import org.eclipse.tm.rapi.RapiException; +import org.eclipse.tm.rapi.RapiFindData; + +public class WinCEFileService extends AbstractFileService implements IWinCEService { + + IRapiSessionProvider sessionProvider; + + public WinCEFileService(IRapiSessionProvider sessionProvider) { + this.sessionProvider = sessionProvider; + } + + String concat(String parentDir, String fileName) { + String result = parentDir; + if (!result.endsWith("\\")) { //$NON-NLS-1$ + result += "\\"; //$NON-NLS-1$ + } + result += fileName; + return result; + } + + protected IHostFile[] internalFetch(String parentPath, String fileFilter, + int fileType, IProgressMonitor monitor) throws SystemMessageException { + if (fileFilter == null) { + fileFilter = "*"; //$NON-NLS-1$ + } + IMatcher fileMatcher = null; + if (fileFilter.endsWith(",")) { //$NON-NLS-1$ + String[] types = fileFilter.split(","); //$NON-NLS-1$ + fileMatcher = new FileTypeMatcher(types, true); + } else { + fileMatcher = new NamePatternMatcher(fileFilter, true, true); + } + List results = new ArrayList(); + try { + IRapiSession session = sessionProvider.getSession(); + RapiFindData[] foundFiles = session.findAllFiles(concat(parentPath,"*"), //$NON-NLS-1$ + OS.FAF_NAME | OS.FAF_ATTRIBUTES | OS.FAF_LASTWRITE_TIME | + OS.FAF_SIZE_HIGH | OS.FAF_SIZE_LOW); + for (int i = 0 ; i < foundFiles.length ; i++) { + String fileName = foundFiles[i].fileName; + if (fileMatcher.matches(fileName)) { + WinCEHostFile hostFile = makeHostFile(parentPath, fileName, foundFiles[i]); + if (isRightType(fileType, hostFile)) { + results.add(hostFile); + } + } + } + } catch (RapiException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } + return (IHostFile[]) results.toArray(new IHostFile[results.size()]); + } + + private WinCEHostFile makeHostFile(String parentPath, String fileName, RapiFindData findData) { + boolean isDirectory = (findData.fileAttributes & OS.FILE_ATTRIBUTE_DIRECTORY) != 0; + boolean isRoot = "\\".equals(parentPath) && "\\".equals(fileName); //$NON-NLS-1$ //$NON-NLS-2$ + long lastModified = (findData.lastWriteTime / 10000) - OS.TIME_DIFF; + long size = findData.fileSize; + return new WinCEHostFile(parentPath, fileName, isDirectory, isRoot, lastModified, size); + } + + private boolean isDirectory(IRapiSession session, String fullPath) { + int attr = session.getFileAttributes(fullPath); + if (attr == -1) { + return false; + } + return (attr & OS.FILE_ATTRIBUTE_DIRECTORY) != 0; + } + + private boolean exist(IRapiSession session, String fileName) { + return session.getFileAttributes(fileName) != -1; + } + + public boolean copy(String srcParent, String srcName, String tgtParent, + String tgtName, IProgressMonitor monitor) throws SystemMessageException { + String srcFullPath = concat(srcParent, srcName); + String tgtFullPath = concat(tgtParent, tgtName); + if (srcFullPath.equals(tgtFullPath)) { + // prevent copying file/folder to itself + return false; + } + IRapiSession session = sessionProvider.getSession(); + try { + if (isDirectory(session, srcFullPath)) { + if (tgtFullPath.startsWith(srcFullPath + "\\")) { //$NON-NLS-1$ + // prevent copying \a to \a\b\c + return false; + } + if (exist(session, tgtFullPath)) { + // we are doing overwrite, + // if the target file or folder already exist - delete it + delete(tgtParent, tgtName, monitor); + } + session.createDirectory(tgtFullPath); + RapiFindData[] allFiles = session.findAllFiles(concat(srcFullPath,"*"), OS.FAF_NAME); //$NON-NLS-1$ + for (int i = 0 ; i < allFiles.length ; i++) { + String fileName = allFiles[i].fileName; + copy(srcFullPath, fileName, tgtFullPath, fileName, monitor); + } + } else { + session.copyFile(srcFullPath, tgtFullPath); + } + } catch (RapiException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } + return true; + } + + public boolean copyBatch(String[] srcParents, String[] srcNames, + String tgtParent, IProgressMonitor monitor) throws SystemMessageException { + boolean ok = true; + for (int i = 0 ; i < srcParents.length ; i++) { + ok = ok && copy(srcParents[i], srcNames[i], tgtParent, srcNames[i], monitor); + } + return ok; + } + + public IHostFile createFile(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException { + String fullPath = concat(remoteParent, fileName); + IRapiSession session = sessionProvider.getSession(); + try { + int handle = session.createFile(fullPath, OS.GENERIC_WRITE, OS.FILE_SHARE_READ, + OS.CREATE_ALWAYS, OS.FILE_ATTRIBUTE_NORMAL); + session.closeHandle(handle); + RapiFindData findData = new RapiFindData(); + handle = session.findFirstFile(fullPath, findData); + session.findClose(handle); + return makeHostFile(remoteParent, fileName, findData); + } catch (RapiException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } + } + + public IHostFile createFolder(String remoteParent, String folderName, IProgressMonitor monitor) throws SystemMessageException { + String fullPath = concat(remoteParent, folderName); + IRapiSession session = sessionProvider.getSession(); + try { + session.createDirectory(fullPath); + RapiFindData findData = new RapiFindData(); + int handle = session.findFirstFile(fullPath, findData); + session.findClose(handle); + return makeHostFile(remoteParent, folderName, findData); + } catch (RapiException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } + } + + public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException { + String fullPath = concat(remoteParent, fileName); + IRapiSession session = sessionProvider.getSession(); + try { + if (isDirectory(session, fullPath)) { + // recursive delete if it is a directory + RapiFindData[] allFiles = session.findAllFiles(concat(fullPath, "*"), OS.FAF_NAME); //$NON-NLS-1$ + for (int i = 0 ; i < allFiles.length ; i++) { + delete(fullPath, allFiles[i].fileName, monitor); + } + session.removeDirectory(fullPath); + } else { + // it is a file + session.deleteFile(fullPath); + } + } catch (RapiException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } + return true; + } + + public boolean download(String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding, + IProgressMonitor monitor) throws SystemMessageException { + + if (!localFile.exists()) { + File localParentFile = localFile.getParentFile(); + if (!localParentFile.exists()) { + localParentFile.mkdirs(); + } + } + String fullPath = concat(remoteParent, remoteFile); + IRapiSession session = sessionProvider.getSession(); + int handle = OS.INVALID_HANDLE_VALUE; + BufferedOutputStream bos = null; + try { + handle = session.createFile(fullPath, OS.GENERIC_READ, + OS.FILE_SHARE_READ, OS.OPEN_EXISTING, OS.FILE_ATTRIBUTE_NORMAL); + bos = new BufferedOutputStream(new FileOutputStream(localFile)); + // TODO: find the optimal buffer size + byte[] buffer = new byte[8 * 1024]; + while (true) { + int bytesRead = session.readFile(handle, buffer); + if (bytesRead == -1) { + break; + } + bos.write(buffer, 0, bytesRead); + } + bos.flush(); + } catch (RapiException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } catch (IOException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } finally { + if (handle != OS.INVALID_HANDLE_VALUE) { + try { + session.closeHandle(handle); + } catch (RapiException e) { + // ignore + } + } + if (bos != null) { + try { + bos.close(); + } catch (IOException e) { + // ignore + } + } + } + return true; + } + + public IHostFile getFile(String remoteParent, String name, IProgressMonitor monitor) throws SystemMessageException { + IRapiSession session = sessionProvider.getSession(); + try { + RapiFindData findData = new RapiFindData(); + int h = session.findFirstFile(concat(remoteParent, name), findData); + session.findClose(h); + return makeHostFile(remoteParent, name, findData); + } catch (RapiException e) { + // ignore the exception and return dummy + } + // return dummy if the file doesn't exist + WinCEHostFile dummy = new WinCEHostFile(remoteParent, name, false, false, 0, 0); + dummy.setExists(false); + return dummy; + } + + public IHostFile[] getRoots(IProgressMonitor monitor) throws SystemMessageException { + return new WinCEHostFile[] { new WinCEHostFile("\\", "\\", true, true, 0, 0) }; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public IHostFile getUserHome() { + return new WinCEHostFile("\\", "My Documents", true, false, 0, 0); //$NON-NLS-1$ //$NON-NLS-2$ + } + + public boolean isCaseSensitive() { + return false; + } + + public boolean move(String srcParent, String srcName, String tgtParent, String tgtName, + IProgressMonitor monitor) throws SystemMessageException { + boolean ok = copy(srcParent, srcName, tgtParent, tgtName, monitor); + ok = ok && delete(srcParent, srcName, monitor); + return ok; + } + + public boolean rename(String remoteParent, String oldName, String newName, + IProgressMonitor monitor) throws SystemMessageException { + String oldFullPath = concat(remoteParent, oldName); + String newFullPath = concat(remoteParent, newName); + IRapiSession session = sessionProvider.getSession(); + try { + session.moveFile(oldFullPath, newFullPath); + } catch (RapiException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } + return true; + } + + public boolean rename(String remoteParent, String oldName, String newName, IHostFile oldFile, + IProgressMonitor monitor) throws SystemMessageException { + boolean retVal = rename(remoteParent, oldName, newName, monitor); + String newFullPath = concat(remoteParent, newName); + oldFile.renameTo(newFullPath); + return retVal; + } + + public boolean setLastModified(String parent, String name, long timestamp, IProgressMonitor monitor) throws SystemMessageException { + return false; + } + + public boolean setReadOnly(String parent, String name, boolean readOnly, IProgressMonitor monitor) throws SystemMessageException { + return false; + } + + public boolean upload(InputStream stream, String remoteParent, String remoteFile, boolean isBinary, + String hostEncoding, IProgressMonitor monitor) throws SystemMessageException { + BufferedInputStream bis = new BufferedInputStream(stream); + IRapiSession session = sessionProvider.getSession(); + String fullPath = concat(remoteParent, remoteFile); + int handle = OS.INVALID_HANDLE_VALUE; + try { + handle = session.createFile(fullPath, OS.GENERIC_WRITE, + OS.FILE_SHARE_READ, OS.CREATE_ALWAYS, OS.FILE_ATTRIBUTE_NORMAL); + // TODO: find the optimal buffer size + byte[] buffer = new byte[8 * 1024]; + while (true) { + int bytesRead = bis.read(buffer); + if (bytesRead == -1) { + break; + } + session.writeFile(handle, buffer, 0, bytesRead); + } + } catch (RapiException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } catch (IOException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } finally { + if (handle != OS.INVALID_HANDLE_VALUE) { + try { + session.closeHandle(handle); + } catch (RapiException e) { + // ignore + } + } + try { + bis.close(); + } catch (IOException e) { + // ignore + } + } + return true; + } + + public boolean upload(File localFile, String remoteParent, String remoteFile, boolean isBinary, + String srcEncoding, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException { + FileInputStream fis = null; + try { + fis = new FileInputStream(localFile); + } catch (FileNotFoundException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } + //FIXME what to do with srcEncoding ? + return upload(fis, remoteParent, remoteFile, isBinary, hostEncoding, monitor); + } + + public InputStream getInputStream(String remoteParent, String remoteFile, + boolean isBinary, IProgressMonitor monitor) throws SystemMessageException { + String fullPath = concat(remoteParent, remoteFile); + IRapiSession session = sessionProvider.getSession(); + try { + int handle = session.createFile(fullPath, OS.GENERIC_READ, + OS.FILE_SHARE_READ, OS.OPEN_EXISTING, OS.FILE_ATTRIBUTE_NORMAL); + return new BufferedInputStream(new WinCEInputStream(session, handle)); + } catch (RapiException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } + } + + public OutputStream getOutputStream(String remoteParent, String remoteFile, + int options, IProgressMonitor monitor) throws SystemMessageException { + String fullPath = concat(remoteParent, remoteFile); + IRapiSession session = sessionProvider.getSession(); + try { + int cd = OS.CREATE_ALWAYS; + if ((options & IFileService.APPEND) == 0) { + cd = OS.CREATE_ALWAYS; + } else { + cd = OS.OPEN_EXISTING; + } + int handle = session.createFile(fullPath, OS.GENERIC_WRITE, + OS.FILE_SHARE_READ, cd, OS.FILE_ATTRIBUTE_NORMAL); + return new BufferedOutputStream(new WinCEOutputStream(session, handle)); + } catch (RapiException e) { + //FIXME error handling + throw new RemoteFileException(e.getMessage()); + } + } + + public String getDescription() { + return Messages.getString("WinCEFileService.12"); //$NON-NLS-1$ + } + + public String getName() { + return Messages.getString("WinCEFileService.13"); //$NON-NLS-1$ + } + + public void initService(IProgressMonitor monitor) { + } + + public void uninitService(IProgressMonitor monitor) { + } + + private static class WinCEInputStream extends InputStream { + + private int handle; + private IRapiSession session; + + public WinCEInputStream(IRapiSession session, int handle) { + this.handle = handle; + this.session = session; + } + + public int read() throws IOException { + byte[] b = new byte[1]; + try { + int br = session.readFile(handle, b); + return (br == -1) ? -1 : b[0]; + } catch (RapiException e) { + throw new IOException(e.getMessage()); + } + } + + public int read(byte[] b, int off, int len) throws IOException { + try { + return session.readFile(handle, b, off, len); + } catch (RapiException e) { + throw new IOException(e.getMessage()); + } + } + + public void close() throws IOException { + try { + session.closeHandle(handle); + } catch (RapiException e) { + throw new IOException(e.getMessage()); + } + } + + } + + private static class WinCEOutputStream extends OutputStream { + + private int handle; + private IRapiSession session; + + public WinCEOutputStream(IRapiSession session, int handle) { + this.session = session; + this.handle = handle; + } + + public void write(int b) throws IOException { + try { + session.writeFile(handle, new byte[] {(byte)b}); + } catch (RapiException e) { + throw new IOException(e.getMessage()); + } + } + + public void write(byte[] b, int off, int len) throws IOException { + try { + session.writeFile(handle, b, off, len); + } catch (RapiException e) { + throw new IOException(e.getMessage()); + } + } + + public void close() throws IOException { + try { + session.closeHandle(handle); + } catch (RapiException e) { + throw new IOException(e.getMessage()); + } + } + } +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/WinCEHostFile.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/WinCEHostFile.java new file mode 100644 index 00000000000..2002310cc6b --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/WinCEHostFile.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.services.wince.files; + +import org.eclipse.rse.services.files.IHostFile; + +public class WinCEHostFile implements IHostFile { + + String name; + String parentPath; + boolean isDirectory; + boolean isRoot; + boolean isArchive = false; + boolean isReadable = true; + boolean isWritable = true; + boolean exists = true; + long lastModified = 0; + long size = 0; + + public WinCEHostFile(String parentPath, String name, boolean isDirectory, boolean isRoot, long lastModified, long size) { + this.parentPath = parentPath; + this.name = name; + this.isDirectory = isDirectory; + this.isRoot = isRoot; + this.lastModified = lastModified; + this.size = size; + } + + public boolean canRead() { + return isReadable; + } + + public boolean canWrite() { + return isWritable; + } + + public boolean exists() { + return exists; + } + + public void setExists(boolean exists) { + this.exists = exists; + } + + public String getAbsolutePath() { + if (isRoot()) { + return getName(); + } + String path = parentPath; + if (!parentPath.endsWith("\\")) { //$NON-NLS-1$ + path += "\\"; //$NON-NLS-1$ + } + path += name; + return path; + } + + public long getModifiedDate() { + return lastModified; + } + + public String getName() { + return name; + } + + public String getParentPath() { + return parentPath; + } + + public long getSize() { + return size; + } + + public boolean isArchive() { + return isArchive; + } + + public boolean isDirectory() { + return isDirectory; + } + + public boolean isFile() { + return !(isDirectory || isRoot); + } + + public boolean isHidden() { + return false; + } + + public boolean isRoot() { + return isRoot; + } + + public void renameTo(String newAbsolutePath) { + int ind = newAbsolutePath.lastIndexOf("\\"); //$NON-NLS-1$ + if (ind == -1) { + name = newAbsolutePath; + } else { + parentPath = newAbsolutePath.substring(0, ind); + name = newAbsolutePath.substring(ind+1); + } + } + +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/messages.properties b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/messages.properties new file mode 100644 index 00000000000..7a9b556b6d9 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/services/wince/files/messages.properties @@ -0,0 +1,2 @@ +WinCEFileService.12=The WinCE File Service uses ActiveSync/RAPI2 to provide service to the Files subsystem on the device. +WinCEFileService.13=WinCE File Service diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/subsystems/files/wince/Activator.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/subsystems/files/wince/Activator.java new file mode 100644 index 00000000000..19bb77a30a4 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/subsystems/files/wince/Activator.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.subsystems.files.wince; + +import org.eclipse.rse.ui.SystemBasePlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends SystemBasePlugin { + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + protected void initializeImageRegistry() { + //TODO + } + +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/subsystems/files/wince/WinCEFileAdapter.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/subsystems/files/wince/WinCEFileAdapter.java new file mode 100644 index 00000000000..8c5518b68a1 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/subsystems/files/wince/WinCEFileAdapter.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.subsystems.files.wince; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.rse.internal.services.wince.files.WinCEHostFile; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; + + +public class WinCEFileAdapter implements IHostFileToRemoteFileAdapter { + + public IRemoteFile convertToRemoteFile(FileServiceSubSystem ss, + IRemoteFileContext context, IRemoteFile parent, IHostFile node) { + + IRemoteFile remoteFile = new WinCERemoteFile(ss, context, parent, (WinCEHostFile)node); + ss.cacheRemoteFile(remoteFile); + return remoteFile; + } + + public IRemoteFile[] convertToRemoteFiles(FileServiceSubSystem ss, + IRemoteFileContext context, IRemoteFile parent, IHostFile[] nodes) { + + List results = new ArrayList(); + if (nodes != null) { + for (int i = 0 ; i < nodes.length ; i++) { + WinCEHostFile node = (WinCEHostFile) nodes[i]; + IRemoteFile remoteFile = new WinCERemoteFile(ss, context, parent, node); + results.add(remoteFile); + ss.cacheRemoteFile(remoteFile); + } + } + return (IRemoteFile[])results.toArray(new IRemoteFile[results.size()]); + } + +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/subsystems/files/wince/WinCERemoteFile.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/subsystems/files/wince/WinCERemoteFile.java new file mode 100644 index 00000000000..54481e70cd6 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/internal/subsystems/files/wince/WinCERemoteFile.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.subsystems.files.wince; + +import org.eclipse.rse.internal.services.wince.files.WinCEHostFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.AbstractRemoteFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; + + +public class WinCERemoteFile extends AbstractRemoteFile { + + public WinCERemoteFile(FileServiceSubSystem subSystem, + IRemoteFileContext context, IRemoteFile parent, WinCEHostFile hostFile) { + super(subSystem, context, parent, hostFile); + } + + public String getCanonicalPath() { + return getAbsolutePath(); + } + + public String getClassification() { + // TODO + return "unknown"; //$NON-NLS-1$ + } + + public String getEncoding() { + // override the default implementation because it causes + // infinite loop on WinCE, see bug #218947 + return getParentRemoteFileSubSystem().getRemoteEncoding(); + } + +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/subsystems/files/wince/WinCEFileServiceSubSystem.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/subsystems/files/wince/WinCEFileServiceSubSystem.java new file mode 100644 index 00000000000..a92f5202342 --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/subsystems/files/wince/WinCEFileServiceSubSystem.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.subsystems.files.wince; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.services.search.ISearchService; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.ui.ISystemMessages; +import org.eclipse.rse.ui.RSEUIPlugin; + +public class WinCEFileServiceSubSystem extends FileServiceSubSystem { + + public WinCEFileServiceSubSystem(IHost host, IConnectorService connectorService, IFileService hostFileService, + IHostFileToRemoteFileAdapter fileAdapter, ISearchService searchService) { + super(host, connectorService, hostFileService, fileAdapter, searchService); + } + + public IRemoteFile getRemoteFileObject(String folderOrFileName, IProgressMonitor monitor) throws SystemMessageException { + String fofName = folderOrFileName.replace('/', '\\'); + IRemoteFile file = getCachedRemoteFile(fofName); + if (file != null && !file.isStale()) { + return file; + } + + // for bug 207095, implicit connect if the connection is not connected + checkIsConnected(monitor); + + if (fofName.equals("\\")) { //$NON-NLS-1$ + try { + return listRoots(null)[0]; + } catch (Exception e) { + } + } + + if (fofName.equals(".")) { //$NON-NLS-1$ + IRemoteFile userHome = getUserHome(); + if (userHome == null){ + // with 207095, it's possible that we could be trying to get user home when not connected + SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_ERROR_UNEXPECTED); + throw new SystemMessageException(msg); + } + return userHome; + } + + if (fofName.endsWith("\\")) { //$NON-NLS-1$ + fofName = fofName.substring(0, fofName.length() - 1); + } + + int lastSep = fofName.lastIndexOf("\\"); //$NON-NLS-1$ + if (lastSep > -1) { + String parentPath = fofName.substring(0, lastSep); + if (parentPath.length() == 0) { + parentPath = "\\"; //$NON-NLS-1$ + } + String name = fofName.substring(lastSep + 1, fofName.length()); + + IHostFile node = getFile(parentPath, name, monitor); + if (node != null) { + IRemoteFile parent = null; + if (!node.isRoot()) { + //parent = getRemoteFileObject(parentPath); + } + return getHostFileToRemoteFileAdapter().convertToRemoteFile(this, getDefaultContext(), parent, node); + } + } + return null; + } + +} diff --git a/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/subsystems/files/wince/WinCEFileSubSystemConfiguration.java b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/subsystems/files/wince/WinCEFileSubSystemConfiguration.java new file mode 100644 index 00000000000..98b8c20828c --- /dev/null +++ b/wince/org.eclipse.rse.subsystems.wince/src/org/eclipse/rse/subsystems/files/wince/WinCEFileSubSystemConfiguration.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.subsystems.files.wince; + +import java.util.Vector; + +import org.eclipse.rse.core.filters.ISystemFilterPool; +import org.eclipse.rse.core.filters.ISystemFilterPoolManager; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.internal.connectorservice.wince.WinCEConnectorService; +import org.eclipse.rse.internal.connectorservice.wince.WinCEConnectorServiceManager; +import org.eclipse.rse.internal.services.wince.IWinCEService; +import org.eclipse.rse.internal.services.wince.files.WinCEFileService; +import org.eclipse.rse.internal.subsystems.files.wince.WinCEFileAdapter; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResultSet; +import org.eclipse.rse.services.search.ISearchService; +import org.eclipse.rse.subsystems.files.core.ILanguageUtilityFactory; +import org.eclipse.rse.subsystems.files.core.model.RemoteFileFilterString; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystemConfiguration; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.ui.SystemBasePlugin; + +public class WinCEFileSubSystemConfiguration extends FileServiceSubSystemConfiguration { + + IHostFileToRemoteFileAdapter hostFileAdapter; + + public IFileService createFileService(IHost host) { + WinCEConnectorService connectorService = (WinCEConnectorService) getConnectorService(host); + return new WinCEFileService(connectorService); + } + + public ISubSystem createSubSystemInternal(IHost host) { + WinCEConnectorService connectorService = (WinCEConnectorService) getConnectorService(host); + return new WinCEFileServiceSubSystem(host, connectorService, getFileService(host), getHostFileAdapter(), getSearchService(host)); + } + + public IHostSearchResultConfiguration createSearchConfiguration(IHost host, + IHostSearchResultSet resultSet, Object searchTarget, + SystemSearchString searchString) { + return null; + } + + public ISearchService createSearchService(IHost host) { + return null; + } + + protected ISystemFilterPool createDefaultFilterPool(ISystemFilterPoolManager mgr) { + ISystemFilterPool pool = null; + try { + pool = mgr.createSystemFilterPool(getDefaultFilterPoolName(mgr.getName(), getId()), true); + Vector filterStrings = new Vector(); + + // "My Home" filter + filterStrings = new Vector(); + RemoteFileFilterString myHomeFilterString = new RemoteFileFilterString(this); + myHomeFilterString.setPath("\\My Documents\\"); //$NON-NLS-1$ + filterStrings.add(myHomeFilterString.toString()); + mgr.createSystemFilter(pool, "My Home", filterStrings); + //filter.setNonChangable(true); + //filter.setSingleFilterStringOnly(true); + + // "Root Files" filter + filterStrings = new Vector(); + RemoteFileFilterString rootFilesFilterString = new RemoteFileFilterString(this); + filterStrings.add(rootFilesFilterString.toString()); + mgr.createSystemFilter(pool, "Root", filterStrings); + } catch (Exception exc) { + SystemBasePlugin.logError("Error creating default filter pool",exc); //$NON-NLS-1$ + } + return pool; + } + + public IHostFileToRemoteFileAdapter getHostFileAdapter() { + if (hostFileAdapter == null) { + hostFileAdapter = new WinCEFileAdapter(); + } + return hostFileAdapter; + } + + public ILanguageUtilityFactory getLanguageUtilityFactory( + IRemoteFileSubSystem ss) { + return null; + } + + public boolean supportsSearch() { + return false; + } + + public boolean supportsArchiveManagement() { + return false; + } + + public IConnectorService getConnectorService(IHost host) { + return WinCEConnectorServiceManager.getInstance().getConnectorService(host, getServiceImplType()); + } + + public Class getServiceImplType() { + return IWinCEService.class; + } + + public void setConnectorService(IHost host, IConnectorService connectorService) { + WinCEConnectorServiceManager.getInstance().setConnectorService(host, getServiceImplType(), connectorService); + } + +} diff --git a/wince/org.eclipse.tm.rapi.examples/.classpath b/wince/org.eclipse.tm.rapi.examples/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.examples/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/wince/org.eclipse.tm.rapi.examples/.project b/wince/org.eclipse.tm.rapi.examples/.project new file mode 100644 index 00000000000..428fa5d15ed --- /dev/null +++ b/wince/org.eclipse.tm.rapi.examples/.project @@ -0,0 +1,28 @@ + + + org.eclipse.tm.rapi.examples + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/wince/org.eclipse.tm.rapi.examples/META-INF/MANIFEST.MF b/wince/org.eclipse.tm.rapi.examples/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..de2eb4f7904 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.examples/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name.0 +Bundle-SymbolicName: org.eclipse.tm.rapi.examples +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.tm.rapi.examples.Activator +Bundle-Vendor: %Bundle-Vendor.0 +Require-Bundle: org.eclipse.core.runtime +Eclipse-LazyStart: true +Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Import-Package: org.eclipse.tm.rapi +Bundle-Localization: plugin diff --git a/wince/org.eclipse.tm.rapi.examples/build.properties b/wince/org.eclipse.tm.rapi.examples/build.properties new file mode 100644 index 00000000000..04397650906 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.examples/build.properties @@ -0,0 +1,15 @@ +############################################################################### +# Copyright (c) 2008 Radoslav Gerganov +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Radoslav Gerganov - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties diff --git a/wince/org.eclipse.tm.rapi.examples/plugin.properties b/wince/org.eclipse.tm.rapi.examples/plugin.properties new file mode 100644 index 00000000000..6012c1b9b25 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.examples/plugin.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2008 Radoslav Gerganov +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Radoslav Gerganov - initial API and implementation +############################################################################### +Bundle-Vendor.0 = Eclipse.org +Bundle-Name.0 = Example usage of RAPI2 \ No newline at end of file diff --git a/wince/org.eclipse.tm.rapi.examples/src/org/eclipse/tm/rapi/examples/Activator.java b/wince/org.eclipse.tm.rapi.examples/src/org/eclipse/tm/rapi/examples/Activator.java new file mode 100644 index 00000000000..8428fb7de3c --- /dev/null +++ b/wince/org.eclipse.tm.rapi.examples/src/org/eclipse/tm/rapi/examples/Activator.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi.examples; + +import org.eclipse.core.runtime.Plugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends Plugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.tm.rapi.examples"; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + + // run the examples when the bundle is started + RapiExamples obj = new RapiExamples(); + obj.runExamples(); + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/wince/org.eclipse.tm.rapi.examples/src/org/eclipse/tm/rapi/examples/RapiExamples.java b/wince/org.eclipse.tm.rapi.examples/src/org/eclipse/tm/rapi/examples/RapiExamples.java new file mode 100644 index 00000000000..f457aaf9fb2 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.examples/src/org/eclipse/tm/rapi/examples/RapiExamples.java @@ -0,0 +1,226 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi.examples; + +import org.eclipse.tm.rapi.IRapiDesktop; +import org.eclipse.tm.rapi.IRapiDevice; +import org.eclipse.tm.rapi.IRapiEnumDevices; +import org.eclipse.tm.rapi.IRapiSession; +import org.eclipse.tm.rapi.OS; +import org.eclipse.tm.rapi.RapiConnectionInfo; +import org.eclipse.tm.rapi.RapiDeviceInfo; +import org.eclipse.tm.rapi.RapiException; +import org.eclipse.tm.rapi.RapiFindData; + +/** + * This class demonstrates example usage of RAPI2. + * + * @author Radoslav Gerganov + */ +public class RapiExamples { + + IRapiDesktop desktop = null; + IRapiEnumDevices enumDevices = null; + IRapiDevice device = null; + IRapiSession session = null; + + /** + * Initialize the underlying natives. + */ + public void initRapi() { + OS.CoInitializeEx(0, OS.COINIT_MULTITHREADED); + } + + /** + * Uninitialize the underlying natives. + */ + public void uninitRapi() { + if (desktop != null) { + desktop.release(); + } + if (enumDevices != null) { + enumDevices.release(); + } + if (device != null) { + device.release(); + } + if (session != null) { + session.release(); + } + OS.CoUninitialize(); + } + + /** + * Prints various information about the device. + */ + public void printDeviceInfo() throws RapiException { + System.out.println(">>> printDeviceInfo()"); + RapiDeviceInfo deviceInfo = device.getDeviceInfo(); + System.out.println("Device id: " + deviceInfo.id); + System.out.println("Device name: " + deviceInfo.name); + System.out.println("Platform: " + deviceInfo.platform); + System.out.println("Major version: " + deviceInfo.versionMajor); + System.out.println("Minor version: " + deviceInfo.versionMinor); + } + + /** + * Prints information about how the device is connected. + */ + public void printConnectionInfo() throws RapiException { + System.out.println(">>> printConnectionInfo()"); + RapiConnectionInfo connectionInfo = device.getConnectionInfo(); + System.out.println("Connection type: " + connectionInfo); + System.out.println("IsConnected: " + device.isConnected()); + } + + /** + * Creates file on the device with the specified filename. + */ + public void createFile(String fileName) throws RapiException { + System.out.println(">>> createFile()"); + int handle = session.createFile(fileName, OS.GENERIC_WRITE, + OS.FILE_SHARE_READ, OS.CREATE_ALWAYS, OS.FILE_ATTRIBUTE_NORMAL); + byte[] content = "Hello world!".getBytes(); + session.writeFile(handle, content); + session.closeHandle(handle); + } + + /** + * Reads the specified file on the device and prints its content. + */ + public void readFile(String fileName) throws RapiException { + System.out.println(">>> readFile()"); + int handle = session.createFile(fileName, OS.GENERIC_READ, + OS.FILE_SHARE_READ, OS.OPEN_EXISTING, OS.FILE_ATTRIBUTE_NORMAL); + byte[] buf = new byte[256]; + int br = session.readFile(handle, buf); + System.out.println("readFile: " + new String(buf, 0, br)); + System.out.println("bytesRead: " + br); + session.closeHandle(handle); + } + + /** + * Utility method used to determine if the specified RapiFindData + * describes a directory. + */ + boolean isDirectory(RapiFindData findData) { + return (findData.fileAttributes & OS.FILE_ATTRIBUTE_DIRECTORY) != 0; + } + + /** + * Utility method used for printing RapiFindData on the console. + */ + void printFindData(RapiFindData findData, int indent) { + for (int i = 0 ; i < indent ; i++) { + System.out.print(" "); + } + String fileName = findData.fileName; + if (isDirectory(findData)) { + System.out.println("[" + fileName + "]"); + } else { + System.out.println(fileName + " (" + findData.fileSize + ")"); + } + } + + /** + * List all files in the specified directory using + * IRapiSession.findFirstFile and + * IRapiSession.findNextFile + */ + public void listFiles(String dir) throws RapiException { + System.out.println(">>> listFiles()"); + RapiFindData findData = new RapiFindData();; + int fh = session.findFirstFile(dir + "*", findData); + while (findData != null) { + printFindData(findData, 0); + findData = session.findNextFile(fh); + } + session.findClose(fh); + } + + /** + * List all files in the specified directory using + * IRapiSession.findAllFiles + */ + public void listFiles2(String dir) throws RapiException { + System.out.println(">>> listFiles2()"); + RapiFindData[] fdArr = session.findAllFiles(dir + "*", + OS.FAF_ATTRIBUTES | OS.FAF_NAME | OS.FAF_SIZE_LOW); + for (int i = 0 ; i < fdArr.length ; i++) { + printFindData(fdArr[i], 0); + } + } + + /** + * Prints various information about the specified file. + */ + public void statFile(String fileName) throws RapiException { + System.out.println(">>> statFile()"); + int handle = session.createFile(fileName, OS.GENERIC_READ, + OS.FILE_SHARE_READ, OS.OPEN_EXISTING, OS.FILE_ATTRIBUTE_NORMAL); + int fileAttributes = session.getFileAttributes(fileName); + System.out.println("fileAttributes: " + fileAttributes); + long fileSize = session.getFileSize(handle); + System.out.println("fileSize: " + fileSize); + System.out.println("creationTime: " + session.getFileCreationTime(handle)); + System.out.println("lastAccessTime: " + session.getFileLastAccessTime(handle)); + System.out.println("lastWriteTime: " + session.getFileLastWriteTime(handle)); + session.closeHandle(handle); + } + + /** + * Recursively print the whole device tree on the console. + */ + void printDeviceTree(String dir, int indent) throws RapiException { + RapiFindData[] fdArr = session.findAllFiles(dir + "*", + OS.FAF_ATTRIBUTES | OS.FAF_NAME | OS.FAF_SIZE_LOW); + if (fdArr == null) { + return; + } + for (int i = 0 ; i < fdArr.length ; i++) { + if (isDirectory(fdArr[i])) { + printDeviceTree(dir + fdArr[i].fileName + "\\", indent + 1); + } else { + printFindData(fdArr[i], indent); + } + } + } + + void runExamples() { + try { + initRapi(); + desktop = IRapiDesktop.getInstance(); + enumDevices = desktop.enumDevices(); + // get the first device + device = enumDevices.next(); + printDeviceInfo(); + printConnectionInfo(); + // create session + session = device.createSession(); + session.init(); + createFile("\\foo.txt"); + readFile("\\foo.txt"); + session.copyFile("\\foo.txt", "\\bar.txt"); + listFiles("\\"); + session.moveFile("\\bar.txt", "\\spam.txt"); + listFiles2("\\"); + session.deleteFile("\\spam.txt"); + statFile("\\foo.txt"); + System.out.println(">>> printDeviceTree()"); + printDeviceTree("\\", 0); + session.uninit(); + } catch (RapiException e) { + e.printStackTrace(); + } finally { + uninitRapi(); + } + } +} diff --git a/wince/org.eclipse.tm.rapi.tests/.classpath b/wince/org.eclipse.tm.rapi.tests/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.tests/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/wince/org.eclipse.tm.rapi.tests/.project b/wince/org.eclipse.tm.rapi.tests/.project new file mode 100644 index 00000000000..c7a68a14314 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.tests/.project @@ -0,0 +1,28 @@ + + + org.eclipse.tm.rapi.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/wince/org.eclipse.tm.rapi.tests/META-INF/MANIFEST.MF b/wince/org.eclipse.tm.rapi.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..f4e39fe596f --- /dev/null +++ b/wince/org.eclipse.tm.rapi.tests/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name.0 +Bundle-SymbolicName: org.eclipse.tm.rapi.tests +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: %Bundle-Vendor.0 +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Require-Bundle: org.junit +Import-Package: org.eclipse.tm.rapi diff --git a/wince/org.eclipse.tm.rapi.tests/build.properties b/wince/org.eclipse.tm.rapi.tests/build.properties new file mode 100644 index 00000000000..04397650906 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.tests/build.properties @@ -0,0 +1,15 @@ +############################################################################### +# Copyright (c) 2008 Radoslav Gerganov +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Radoslav Gerganov - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties diff --git a/wince/org.eclipse.tm.rapi.tests/plugin.properties b/wince/org.eclipse.tm.rapi.tests/plugin.properties new file mode 100644 index 00000000000..ba3977c4400 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.tests/plugin.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2008 Radoslav Gerganov +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Radoslav Gerganov - initial API and implementation +############################################################################### +Bundle-Vendor.0 = Eclipse.org +Bundle-Name.0 = Unit tests for org.eclipse.tm.rapi \ No newline at end of file diff --git a/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/AllTests.java b/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/AllTests.java new file mode 100644 index 00000000000..ff93fa92bf0 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/AllTests.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi.tests; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Unit tests for the Java wrappers of RAPI2. + * + * Establishing an ActiveSync connection with a device or emulator is needed + * before running these tests. + * + * @author Radoslav Gerganov + */ +public class AllTests { + + public static Test suite() { + TestSuite suite = new TestSuite("Test for org.eclipse.tm.rapi"); + //$JUnit-BEGIN$ + suite.addTestSuite(RapiDesktopTest.class); + suite.addTestSuite(RapiEnumDevicesTest.class); + suite.addTestSuite(RapiDeviceTest.class); + suite.addTestSuite(RapiSessionTest.class); + //$JUnit-END$ + return suite; + } + +} diff --git a/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiDesktopTest.java b/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiDesktopTest.java new file mode 100644 index 00000000000..bd0ebb3a5b8 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiDesktopTest.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi.tests; + +import org.eclipse.tm.rapi.IRapiDesktop; +import org.eclipse.tm.rapi.RapiException; + +public class RapiDesktopTest extends RapiTestCase { + + protected void setUp() throws Exception { + super.setUp(); + } + + public void testGetInstance() throws RapiException { + desktop = IRapiDesktop.getInstance(); + assertNotNull("IRapiDesktop.getInstance() returned null", desktop); + } + + public void testEnumDevices() throws RapiException { + desktop = IRapiDesktop.getInstance(); + enumDevices = desktop.enumDevices(); + assertNotNull("IRapiDesktop.enumDevices() returned null", enumDevices); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiDeviceTest.java b/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiDeviceTest.java new file mode 100644 index 00000000000..2c0eaaa58cc --- /dev/null +++ b/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiDeviceTest.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi.tests; + +import org.eclipse.tm.rapi.IRapiDesktop; +import org.eclipse.tm.rapi.IRapiDevice; +import org.eclipse.tm.rapi.RapiConnectionInfo; +import org.eclipse.tm.rapi.RapiDeviceInfo; +import org.eclipse.tm.rapi.RapiException; + +public class RapiDeviceTest extends RapiTestCase { + + protected void setUp() throws Exception { + super.setUp(); + } + + IRapiDevice getDevice() throws RapiException { + desktop = IRapiDesktop.getInstance(); + enumDevices = desktop.enumDevices(); + return enumDevices.next(); + } + + public void testCreateSession() throws RapiException { + device = getDevice(); + session = device.createSession(); + assertNotNull("IRapiDevice.createSession() returned null", session); + } + + public void testGetConnectionInfo() throws RapiException { + device = getDevice(); + RapiConnectionInfo connectionInfo = device.getConnectionInfo(); + int connectionType = connectionInfo.connectionType; + assertTrue("Unknown connectionType: " + connectionType, + connectionType >= 0 && connectionType <= 3); + } + + public void testGetDeviceInfo() throws RapiException { + device = getDevice(); + RapiDeviceInfo deviceInfo = device.getDeviceInfo(); + assertNotNull("deviceInfo.id is null", deviceInfo.id); + assertNotNull("deviceInfo.name is null", deviceInfo.name); + assertNotNull("deviceInfo.platform is null", deviceInfo.platform); + //TODO: make some reasonable checks for the version numbers + } + + public void testIsConnected() throws RapiException { + device = getDevice(); + boolean connected = device.isConnected(); + assertTrue("device should be connected", connected); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiEnumDevicesTest.java b/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiEnumDevicesTest.java new file mode 100644 index 00000000000..84216a356f9 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiEnumDevicesTest.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi.tests; + +import org.eclipse.tm.rapi.IRapiDesktop; +import org.eclipse.tm.rapi.RapiException; + +public class RapiEnumDevicesTest extends RapiTestCase { + + protected void setUp() throws Exception { + super.setUp(); + } + + public void testNext() throws RapiException { + desktop = IRapiDesktop.getInstance(); + enumDevices = desktop.enumDevices(); + device = enumDevices.next(); + assertNotNull("IRapiEnumDevices.next() returned null", device); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiSessionTest.java b/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiSessionTest.java new file mode 100644 index 00000000000..3f58b2c9567 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiSessionTest.java @@ -0,0 +1,253 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi.tests; + +import org.eclipse.tm.rapi.IRapiDesktop; +import org.eclipse.tm.rapi.OS; +import org.eclipse.tm.rapi.RapiException; +import org.eclipse.tm.rapi.RapiFindData; + +public class RapiSessionTest extends RapiTestCase { + + private static final int TEMP_FILES_COUNT = 10; + private static final int TEST_FILE_SIZE = 8 * 1024; + private static final String TEST_FILE_NAME = "\\foo.bin"; + private static final int CHUNK_SIZE = 1024; + + private static final String TEST_DIR_NAME = "bar"; + + protected void setUp() throws Exception { + super.setUp(); + } + + /** + * Creates and initialize RAPI2 session + */ + void createInitSession() throws RapiException { + desktop = IRapiDesktop.getInstance(); + enumDevices = desktop.enumDevices(); + device = enumDevices.next(); + session = device.createSession(); + session.init(); + } + + /** + * Returns true if the first len bytes of the specified arrays + * are equal. + */ + boolean arraysEqual(byte[] arr1, byte[] arr2, int len) { + for (int i = 0 ; i < len ; i++) { + if (arr1[i] != arr2[i]) { + return false; + } + } + return true; + } + + /** + * Returns true if the specified path exists and it is a directory. + */ + boolean isDirectory(String path) { + int attr = session.getFileAttributes(path); + if (attr == -1) { + return false; + } + return (attr & OS.FILE_ATTRIBUTE_DIRECTORY) != 0; + } + + /** + * Returns true if the specified path exists and it is a file. + */ + boolean isFile(String path) { + int attr = session.getFileAttributes(path); + if (attr == -1) { + return false; + } + return (attr & OS.FILE_ATTRIBUTE_DIRECTORY) == 0; + } + + /** + * Tests reading and writing files on the device. + */ + public void testReadWriteFiles() throws RapiException { + createInitSession(); + + // generate random file content + byte[] content = new byte[TEST_FILE_SIZE]; + for (int i = 0 ; i < content.length ; i++) { + content[i] = (byte)(Math.random() * 131); + } + + // write the test file at once + int handle = session.createFile(TEST_FILE_NAME, OS.GENERIC_WRITE, + OS.FILE_SHARE_READ, OS.CREATE_ALWAYS, OS.FILE_ATTRIBUTE_NORMAL); + session.writeFile(handle, content); + session.closeHandle(handle); + + // try to read the whole file + handle = session.createFile(TEST_FILE_NAME, OS.GENERIC_READ, + OS.FILE_SHARE_READ, OS.OPEN_EXISTING, OS.FILE_ATTRIBUTE_NORMAL); + byte[] contentRead = new byte[TEST_FILE_SIZE]; + int br = session.readFile(handle, contentRead); + session.closeHandle(handle); + assertTrue("Different file content", arraysEqual(content, contentRead, br)); + + // write the test file by chunks + handle = session.createFile(TEST_FILE_NAME, OS.GENERIC_WRITE, + OS.FILE_SHARE_READ, OS.CREATE_ALWAYS, OS.FILE_ATTRIBUTE_NORMAL); + int off = 0; + for (int i = 0 ; i < TEST_FILE_SIZE / CHUNK_SIZE ; i++) { + session.writeFile(handle, content, off, CHUNK_SIZE); + off += CHUNK_SIZE; + } + session.closeHandle(handle); + + // read the test file by chunks + handle = session.createFile(TEST_FILE_NAME, OS.GENERIC_READ, + OS.FILE_SHARE_READ, OS.OPEN_EXISTING, OS.FILE_ATTRIBUTE_NORMAL); + byte[] contentRead2 = new byte[TEST_FILE_SIZE]; + off = 0; + int bytesToRead = TEST_FILE_SIZE; + while (bytesToRead > 0) { + int len = CHUNK_SIZE < bytesToRead ? CHUNK_SIZE : bytesToRead; + br = session.readFile(handle, contentRead2, off, len); + off += br; + bytesToRead -= br; + } + session.closeHandle(handle); + assertTrue("Different file content", arraysEqual(content, contentRead2, TEST_FILE_SIZE)); + + // delete the test file + session.deleteFile(TEST_FILE_NAME); + } + + /** + * Tests creating and removing directories on the device. + */ + public void testCreateRemoveDirectories() throws RapiException { + createInitSession(); + try { + session.removeDirectory(TEST_DIR_NAME); + } catch (RapiException re) { + // ignore + } + session.createDirectory(TEST_DIR_NAME); + assertTrue("Failed to create directory", isDirectory(TEST_DIR_NAME)); + session.removeDirectory(TEST_DIR_NAME); + assertFalse("Failed to remove directory", isDirectory(TEST_DIR_NAME)); + } + + /** + * Tests copying, moving and deleting files on the device. + */ + public void testCopyMoveDeleteFiles() throws RapiException { + createInitSession(); + + // create test file + int handle = session.createFile(TEST_FILE_NAME, OS.GENERIC_WRITE, + OS.FILE_SHARE_READ, OS.CREATE_ALWAYS, OS.FILE_ATTRIBUTE_NORMAL); + session.writeFile(handle, "spam".getBytes()); + session.closeHandle(handle); + + // make a copy + String copy = TEST_FILE_NAME + "1"; + session.copyFile(TEST_FILE_NAME, copy); + assertTrue("Failed to copy file", isFile(copy)); + + // delete the test file + session.deleteFile(TEST_FILE_NAME); + assertFalse("Failed to delete file", isFile(TEST_FILE_NAME)); + + // rename the copy + session.moveFile(copy, TEST_FILE_NAME); + assertTrue("Failed to move file", isFile(TEST_FILE_NAME)); + assertFalse("Failed to move file", isFile(copy)); + + // delete test file + session.deleteFile(TEST_FILE_NAME); + } + + /** + * Utility method for creating a bunch of files. + */ + void createTempFiles() throws RapiException { + for (int i = 0 ; i < TEMP_FILES_COUNT ; i++) { + int handle = session.createFile(TEST_FILE_NAME + i, OS.GENERIC_WRITE, + OS.FILE_SHARE_READ, OS.CREATE_ALWAYS, OS.FILE_ATTRIBUTE_NORMAL); + session.writeFile(handle, "spam".getBytes()); + session.closeHandle(handle); + } + } + + /** + * Tests finding files using {@link IRapiSession#findFirstFile(String, RapiFindData)} + */ + public void testFindFiles() throws RapiException { + createInitSession(); + createTempFiles(); + int filesFound = 0; + RapiFindData findData = new RapiFindData(); + int fh = session.findFirstFile(TEST_FILE_NAME + "?", findData); + while (findData != null) { + filesFound++; + findData = session.findNextFile(fh); + } + session.findClose(fh); + assertTrue("Found " + filesFound + " , expected " + TEMP_FILES_COUNT, + filesFound == TEMP_FILES_COUNT); + // clean up + for (int i = 0 ; i < TEMP_FILES_COUNT ; i++) { + session.deleteFile(TEST_FILE_NAME + i); + } + } + + /** + * Tests finding files using {@link IRapiSession#findAllFiles(String, int)} + */ + public void testFindAllFiles() throws RapiException { + createInitSession(); + createTempFiles(); + RapiFindData[] faf = session.findAllFiles(TEST_FILE_NAME + "?", OS.FAF_NAME); + int filesFound = faf.length; + assertTrue("Found " + filesFound + " , expected " + TEMP_FILES_COUNT, + filesFound == TEMP_FILES_COUNT); + // clean up + for (int i = 0 ; i < TEMP_FILES_COUNT ; i++) { + session.deleteFile(TEST_FILE_NAME + i); + } + } + + /** + * Tests getting file attributes, size, etc. + */ + public void testStatFiles() throws RapiException { + createInitSession(); + // create test file + int handle = session.createFile(TEST_FILE_NAME, OS.GENERIC_WRITE, + OS.FILE_SHARE_READ, OS.CREATE_ALWAYS, OS.FILE_ATTRIBUTE_NORMAL); + session.writeFile(handle, "spam".getBytes()); + assertTrue("Wrong file size", 4 == session.getFileSize(handle)); + //TODO: add some checks for file times (creation, last modified, etc) + session.closeHandle(handle); + int attr = session.getFileAttributes(TEST_FILE_NAME); + assertTrue("Wrong file attributes", (attr & OS.FILE_ATTRIBUTE_ARCHIVE) != 0); + //clean up + session.deleteFile(TEST_FILE_NAME); + } + + protected void tearDown() throws Exception { + if (session != null) { + session.uninit(); + } + super.tearDown(); + } + +} diff --git a/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiTestCase.java b/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiTestCase.java new file mode 100644 index 00000000000..d83f2c91852 --- /dev/null +++ b/wince/org.eclipse.tm.rapi.tests/src/org/eclipse/tm/rapi/tests/RapiTestCase.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi.tests; + +import org.eclipse.tm.rapi.IRapiDesktop; +import org.eclipse.tm.rapi.IRapiDevice; +import org.eclipse.tm.rapi.IRapiEnumDevices; +import org.eclipse.tm.rapi.IRapiSession; +import org.eclipse.tm.rapi.OS; + +import junit.framework.TestCase; + +public class RapiTestCase extends TestCase { + + protected IRapiDesktop desktop = null; + protected IRapiEnumDevices enumDevices = null; + protected IRapiDevice device = null; + protected IRapiSession session = null; + + protected void setUp() throws Exception { + super.setUp(); + desktop = null; + enumDevices = null; + device = null; + session = null; + OS.CoInitializeEx(0, OS.COINIT_MULTITHREADED); + } + + protected void tearDown() throws Exception { + super.tearDown(); + if (desktop != null) { + desktop.release(); + } + if (enumDevices != null) { + enumDevices.release(); + } + if (device != null) { + device.release(); + } + if (session != null) { + session.release(); + } + OS.CoUninitialize(); + } + +} diff --git a/wince/org.eclipse.tm.rapi/.classpath b/wince/org.eclipse.tm.rapi/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/wince/org.eclipse.tm.rapi/.project b/wince/org.eclipse.tm.rapi/.project new file mode 100644 index 00000000000..b9116d39117 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/.project @@ -0,0 +1,28 @@ + + + org.eclipse.tm.rapi + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/wince/org.eclipse.tm.rapi/META-INF/MANIFEST.MF b/wince/org.eclipse.tm.rapi/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..0382d6fc69f --- /dev/null +++ b/wince/org.eclipse.tm.rapi/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name.0 +Bundle-SymbolicName: org.eclipse.tm.rapi +Bundle-Version: 1.0.0.qualifier +Export-Package: org.eclipse.tm.internal.rapi;x-internal:=true, + org.eclipse.tm.rapi +Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Bundle-Vendor: %Bundle-Vendor.0 +Eclipse-PlatformFilter: (& (osgi.ws=win32) (osgi.os=win32) (osgi.arch=x86)) +Bundle-Localization: plugin diff --git a/wince/org.eclipse.tm.rapi/build.properties b/wince/org.eclipse.tm.rapi/build.properties new file mode 100644 index 00000000000..85b72c3330d --- /dev/null +++ b/wince/org.eclipse.tm.rapi/build.properties @@ -0,0 +1,16 @@ +############################################################################### +# Copyright (c) 2008 Radoslav Gerganov +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Radoslav Gerganov - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties,\ + lib/os/win32/x86/jrapi.dll diff --git a/wince/org.eclipse.tm.rapi/build/build.xml b/wince/org.eclipse.tm.rapi/build/build.xml new file mode 100644 index 00000000000..a98b4f130b3 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/build/build.xml @@ -0,0 +1,36 @@ + + + + + Java wrappers for RAPI2 + + + + + + + + + + + + + + + + + + + + + + diff --git a/wince/org.eclipse.tm.rapi/build/jrapi.sln b/wince/org.eclipse.tm.rapi/build/jrapi.sln new file mode 100644 index 00000000000..359d1f7b9d8 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/build/jrapi.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jrapi", "jrapi.vcproj", "{7A9CC697-2EEB-40B9-B540-7FFC195B3D4F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7A9CC697-2EEB-40B9-B540-7FFC195B3D4F}.Debug|Win32.ActiveCfg = Debug|Win32 + {7A9CC697-2EEB-40B9-B540-7FFC195B3D4F}.Debug|Win32.Build.0 = Debug|Win32 + {7A9CC697-2EEB-40B9-B540-7FFC195B3D4F}.Release|Win32.ActiveCfg = Release|Win32 + {7A9CC697-2EEB-40B9-B540-7FFC195B3D4F}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/wince/org.eclipse.tm.rapi/build/jrapi.vcproj b/wince/org.eclipse.tm.rapi/build/jrapi.vcproj new file mode 100644 index 00000000000..7c479e350b3 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/build/jrapi.vcproj @@ -0,0 +1,239 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wince/org.eclipse.tm.rapi/lib/os/win32/x86/jrapi.dll b/wince/org.eclipse.tm.rapi/lib/os/win32/x86/jrapi.dll new file mode 100644 index 00000000000..3bf88191959 Binary files /dev/null and b/wince/org.eclipse.tm.rapi/lib/os/win32/x86/jrapi.dll differ diff --git a/wince/org.eclipse.tm.rapi/native/OS.cpp b/wince/org.eclipse.tm.rapi/native/OS.cpp new file mode 100644 index 00000000000..476bc59afea --- /dev/null +++ b/wince/org.eclipse.tm.rapi/native/OS.cpp @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ + +#define _WIN32_DCOM +#include +#include + +#include "org_eclipse_tm_rapi_OS.h" + +#define RAPI_NATIVE(func) Java_org_eclipse_tm_rapi_OS_##func + +JNIEXPORT jint JNICALL RAPI_NATIVE(CoInitializeEx) + (JNIEnv *env, jclass that, jint arg0, jint arg1) +{ + return (jint)CoInitializeEx((LPVOID)arg0, arg1); +} + +JNIEXPORT void JNICALL RAPI_NATIVE(CoUninitialize) + (JNIEnv *env, jclass that) +{ + CoUninitialize(); +} + +JNIEXPORT jint JNICALL RAPI_NATIVE(CreateRapiDesktop) + (JNIEnv *env, jclass that, jintArray arg0) +{ + jint rc = 0; + jint *lparg0 = NULL; + if (arg0) { + lparg0 = env->GetIntArrayElements(arg0, NULL); + if (lparg0 == NULL) goto fail; + } + rc = CoCreateInstance(CLSID_RAPI, NULL, CLSCTX_INPROC_SERVER, + IID_IRAPIDesktop, (void**)lparg0); +fail: + if (arg0 && lparg0) env->ReleaseIntArrayElements(arg0, lparg0, 0); + return rc; +} + +JNIEXPORT void JNICALL RAPI_NATIVE(ReleaseIUnknown) + (JNIEnv *env, jclass that, jint arg0) +{ + if (arg0 == 0) return; + IUnknown *ptr = (IUnknown*) arg0; + ptr->Release(); +} diff --git a/wince/org.eclipse.tm.rapi/native/RapiDesktop.cpp b/wince/org.eclipse.tm.rapi/native/RapiDesktop.cpp new file mode 100644 index 00000000000..f82e8a502bd --- /dev/null +++ b/wince/org.eclipse.tm.rapi/native/RapiDesktop.cpp @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ + +#include +#include + +#include "org_eclipse_tm_internal_rapi_RapiDesktop.h" + +#define RAPI_NATIVE(func) Java_org_eclipse_tm_internal_rapi_RapiDesktop_##func + +JNIEXPORT jint JNICALL RAPI_NATIVE(EnumDevices) + (JNIEnv *env, jobject that, jint arg0, jintArray arg1) +{ + jint rc = E_FAIL; + jint *lparg1 = NULL; + + if (arg0 == 0) return rc; + if (arg1) { + lparg1 = env->GetIntArrayElements(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + IRAPIDesktop *pDesktop = (IRAPIDesktop*) arg0; + rc = pDesktop->EnumDevices((IRAPIEnumDevices**)lparg1); +fail: + if (arg1 && lparg1) env->ReleaseIntArrayElements(arg1, lparg1, 0); + return rc; +} diff --git a/wince/org.eclipse.tm.rapi/native/RapiDevice.cpp b/wince/org.eclipse.tm.rapi/native/RapiDevice.cpp new file mode 100644 index 00000000000..7ce1fc70de8 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/native/RapiDevice.cpp @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ + +#include +#include + +#include "org_eclipse_tm_internal_rapi_RapiDevice.h" + +#define RAPI_NATIVE(func) Java_org_eclipse_tm_internal_rapi_RapiDevice_##func + +struct RAPI_DEVICEINFO_FID_CACHE +{ + int cached; + jclass clazz; + jfieldID id, versionMajor, versionMinor, name, platform; +}; + +struct RAPI_CONNECTIONINFO_FID_CACHE +{ + int cached; + jclass clazz; + jfieldID connectionType; +}; + +RAPI_DEVICEINFO_FID_CACHE RAPI_DEVICEINFOFc; +RAPI_CONNECTIONINFO_FID_CACHE RAPI_CONNECTIONINFOFc; + +JNIEXPORT jint JNICALL RAPI_NATIVE(CreateSession) + (JNIEnv *env, jobject that, jint arg0, jintArray arg1) +{ + jint rc = E_FAIL; + jint *lparg1 = NULL; + + if (arg0 == 0) return rc; + if (arg1) { + lparg1 = env->GetIntArrayElements(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + IRAPIDevice *pDevice = (IRAPIDevice*) arg0; + rc = pDevice->CreateSession((IRAPISession**)lparg1); +fail: + if (arg1 && lparg1) env->ReleaseIntArrayElements(arg1, lparg1, 0); + return rc; +} + +void cacheRAPI_DEVICEINFOFields(JNIEnv *env, jobject lpObject) +{ + if (RAPI_DEVICEINFOFc.cached) return; + RAPI_DEVICEINFOFc.clazz = env->GetObjectClass(lpObject); + RAPI_DEVICEINFOFc.id = env->GetFieldID(RAPI_DEVICEINFOFc.clazz, "id", "Ljava/lang/String;"); + RAPI_DEVICEINFOFc.versionMajor = env->GetFieldID(RAPI_DEVICEINFOFc.clazz, "versionMajor", "I"); + RAPI_DEVICEINFOFc.versionMinor = env->GetFieldID(RAPI_DEVICEINFOFc.clazz, "versionMinor", "I"); + RAPI_DEVICEINFOFc.name = env->GetFieldID(RAPI_DEVICEINFOFc.clazz, "name", "Ljava/lang/String;"); + RAPI_DEVICEINFOFc.platform = env->GetFieldID(RAPI_DEVICEINFOFc.clazz, "platform", "Ljava/lang/String;"); + RAPI_DEVICEINFOFc.cached = 1; +} + +void cacheRAPI_CONNECTIONINFOFields(JNIEnv *env, jobject lpObject) +{ + if (RAPI_CONNECTIONINFOFc.cached) return; + RAPI_CONNECTIONINFOFc.clazz = env->GetObjectClass(lpObject); + RAPI_CONNECTIONINFOFc.connectionType = env->GetFieldID(RAPI_CONNECTIONINFOFc.clazz, "connectionType", "I"); + RAPI_CONNECTIONINFOFc.cached = 1; +} + +void setRAPI_DEVICEINFOFields(JNIEnv *env, jobject lpObject, RAPI_DEVICEINFO *pDeviceInfo) +{ + if (!RAPI_DEVICEINFOFc.cached) cacheRAPI_DEVICEINFOFields(env, lpObject); + WCHAR *pwszGUID = NULL; + if (StringFromCLSID(pDeviceInfo->DeviceId, &pwszGUID) == S_OK) { + int idLen = lstrlen(pwszGUID); + jstring id = env->NewString((const jchar*)pwszGUID, idLen); + env->SetObjectField(lpObject, RAPI_DEVICEINFOFc.id, id); + CoTaskMemFree(pwszGUID); + } + env->SetIntField(lpObject, RAPI_DEVICEINFOFc.versionMajor, (jint)pDeviceInfo->dwOsVersionMajor); + env->SetIntField(lpObject, RAPI_DEVICEINFOFc.versionMinor, (jint)pDeviceInfo->dwOsVersionMinor); + // create new String from the native BSTR + UINT nameLen = SysStringLen(pDeviceInfo->bstrName); + jstring name = env->NewString((const jchar*)pDeviceInfo->bstrName, nameLen); + env->SetObjectField(lpObject, RAPI_DEVICEINFOFc.name, name); + // create new String from the native BSTR + UINT platformLen = SysStringLen(pDeviceInfo->bstrPlatform); + jstring platform = env->NewString((const jchar*)pDeviceInfo->bstrPlatform, platformLen); + env->SetObjectField(lpObject, RAPI_DEVICEINFOFc.platform, platform); +} + +void setRAPI_CONNECTIONINFOFields(JNIEnv *env, jobject lpObject, RAPI_CONNECTIONINFO *pConnectionInfo) +{ + if (!RAPI_CONNECTIONINFOFc.cached) cacheRAPI_CONNECTIONINFOFields(env, lpObject); + env->SetIntField(lpObject, RAPI_CONNECTIONINFOFc.connectionType, (jint)pConnectionInfo->connectionType); +} + +JNIEXPORT jint JNICALL RAPI_NATIVE(GetDeviceInfo) + (JNIEnv *env, jobject that, jint arg0, jobject arg1) +{ + jint rc = E_FAIL; + RAPI_DEVICEINFO deviceInfo = {0}; + + if (arg0 == 0) return rc; + IRAPIDevice *pDevice = (IRAPIDevice*) arg0; + rc = pDevice->GetDeviceInfo(&deviceInfo); + if (rc != NOERROR) goto fail; + if (arg1) setRAPI_DEVICEINFOFields(env, arg1, &deviceInfo); +fail: + FreeDeviceInfoData(&deviceInfo); + return rc; +} + +JNIEXPORT jint JNICALL RAPI_NATIVE(GetConnectionInfo) + (JNIEnv *env, jobject that, jint arg0, jobject arg1) +{ + jint rc = E_FAIL; + RAPI_CONNECTIONINFO connectionInfo = {0}; + + if (arg0 == 0) return rc; + IRAPIDevice *pDevice = (IRAPIDevice*) arg0; + rc = pDevice->GetConnectionInfo(&connectionInfo); + if (rc != NOERROR) goto fail; + if (arg1) setRAPI_CONNECTIONINFOFields(env, arg1, &connectionInfo); +fail: + return rc; +} + +JNIEXPORT jint JNICALL RAPI_NATIVE(GetConnectStat) + (JNIEnv *env, jobject that, jint arg0, jintArray arg1) +{ + jint rc = E_FAIL; + jint *lparg1 = NULL; + RAPI_DEVICESTATUS devStatus; + + if (arg0 == 0) return rc; + if (arg1) { + lparg1 = env->GetIntArrayElements(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + IRAPIDevice *pDevice = (IRAPIDevice*) arg0; + rc = pDevice->GetConnectStat(&devStatus); + lparg1[0] = (int)devStatus; +fail: + if (arg1 && lparg1) env->ReleaseIntArrayElements(arg1, lparg1, 0); + return rc; +} \ No newline at end of file diff --git a/wince/org.eclipse.tm.rapi/native/RapiEnumDevices.cpp b/wince/org.eclipse.tm.rapi/native/RapiEnumDevices.cpp new file mode 100644 index 00000000000..40bdd6fcd9d --- /dev/null +++ b/wince/org.eclipse.tm.rapi/native/RapiEnumDevices.cpp @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ + +#include +#include + +#include "org_eclipse_tm_internal_rapi_RapiEnumDevices.h" + +#define RAPI_NATIVE(func) Java_org_eclipse_tm_internal_rapi_RapiEnumDevices_##func + +JNIEXPORT jint JNICALL RAPI_NATIVE(Next) + (JNIEnv *env, jobject that, jint arg0, jintArray arg1) +{ + jint rc = E_FAIL; + jint *lparg1 = NULL; + + if (arg0 == 0) return rc; + if (arg1) { + lparg1 = env->GetIntArrayElements(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + IRAPIEnumDevices *pEnumDevices = (IRAPIEnumDevices*) arg0; + rc = pEnumDevices->Next((IRAPIDevice**)lparg1); +fail: + if (arg1 && lparg1) env->ReleaseIntArrayElements(arg1, lparg1, 0); + return rc; +} diff --git a/wince/org.eclipse.tm.rapi/native/RapiSession.cpp b/wince/org.eclipse.tm.rapi/native/RapiSession.cpp new file mode 100644 index 00000000000..0d443e1b4c2 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/native/RapiSession.cpp @@ -0,0 +1,438 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ + +#include +#include + +#include "org_eclipse_tm_internal_rapi_RapiSession.h" + +#define RAPI_NATIVE(func) Java_org_eclipse_tm_internal_rapi_RapiSession_##func + +JNIEXPORT jint JNICALL RAPI_NATIVE(CeRapiInit) + (JNIEnv *env, jobject that, jint arg0) +{ + if (arg0 == 0) return E_FAIL; + IRAPISession *pSession = (IRAPISession*) arg0; + return pSession->CeRapiInit(); +} + +JNIEXPORT jint JNICALL RAPI_NATIVE(CeRapiUninit) + (JNIEnv *env, jobject that, jint arg0) +{ + if (arg0 == 0) return E_FAIL; + IRAPISession *pSession = (IRAPISession*) arg0; + return pSession->CeRapiUninit(); +} + +JNIEXPORT jint JNICALL RAPI_NATIVE(CeRapiGetError) + (JNIEnv *env, jobject that, jint arg0) +{ + if (arg0 == 0) return 0; + IRAPISession *pSession = (IRAPISession*) arg0; + return pSession->CeRapiGetError(); +} + +JNIEXPORT jint JNICALL RAPI_NATIVE(CeGetLastError) + (JNIEnv *env, jobject that, jint arg0) +{ + if (arg0 == 0) return 0; + IRAPISession *pSession = (IRAPISession*) arg0; + return pSession->CeGetLastError(); +} + +JNIEXPORT jint JNICALL RAPI_NATIVE(CeCreateFile) + (JNIEnv *env, jobject that, jint arg0, jstring arg1, jint arg2, jint arg3, jint arg4, jint arg5) +{ + HANDLE h = INVALID_HANDLE_VALUE; + const jchar *lparg1 = NULL; + + if (arg0 == 0) goto fail; + if (arg1) { + lparg1 = env->GetStringChars(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + h = pSession->CeCreateFile((LPCWSTR)lparg1, arg2, arg3, NULL, arg4, arg5, 0); +fail: + if (arg1 && lparg1) env->ReleaseStringChars(arg1, lparg1); + return (jint)h; +} + +JNIEXPORT jboolean JNICALL RAPI_NATIVE(CeReadFile) + (JNIEnv *env, jobject that, jint arg0, jint arg1, jbyteArray arg2, jint arg3, jintArray arg4) +{ + jboolean rc = 0; + jbyte *lparg2 = NULL; + jint *lparg4 = NULL; + + if (arg0 == 0) return rc; + if (arg2) { + lparg2 = env->GetByteArrayElements(arg2, NULL); + if (lparg2 == NULL) goto fail; + } + if (arg4) { + lparg4 = env->GetIntArrayElements(arg4, NULL); + if (lparg4 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + rc = pSession->CeReadFile((HANDLE)arg1, lparg2, arg3, (LPDWORD)lparg4, NULL); +fail: + if (arg2 && lparg2) env->ReleaseByteArrayElements(arg2, lparg2, 0); + if (arg4 && lparg4) env->ReleaseIntArrayElements(arg4, lparg4, 0); + return rc; +} + +JNIEXPORT jboolean JNICALL RAPI_NATIVE(CeWriteFile) + (JNIEnv *env, jobject that, jint arg0, jint arg1, jbyteArray arg2, jint arg3, jintArray arg4) +{ + jboolean rc = 0; + jbyte *lparg2 = NULL; + jint *lparg4 = NULL; + + if (arg0 == 0) return rc; + if (arg2) { + lparg2 = env->GetByteArrayElements(arg2, NULL); + if (lparg2 == NULL) goto fail; + } + if (arg4) { + lparg4 = env->GetIntArrayElements(arg4, NULL); + if (lparg4 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + rc = pSession->CeWriteFile((HANDLE)arg1, lparg2, arg3, (LPDWORD)lparg4, NULL); +fail: + if (arg2 && lparg2) env->ReleaseByteArrayElements(arg2, lparg2, 0); + if (arg4 && lparg4) env->ReleaseIntArrayElements(arg4, lparg4, 0); + return rc; +} + +JNIEXPORT jboolean JNICALL RAPI_NATIVE(CeCloseHandle) + (JNIEnv *env, jobject that, jint arg0, jint arg1) +{ + if (arg0 == 0) return 0; + IRAPISession *pSession = (IRAPISession*) arg0; + return pSession->CeCloseHandle((HANDLE)arg1); +} + +JNIEXPORT jboolean JNICALL RAPI_NATIVE(CeCopyFile) + (JNIEnv *env, jobject that, jint arg0, jstring arg1, jstring arg2, jboolean arg3) +{ + jboolean rc = 0; + const jchar *lparg1 = NULL; + const jchar *lparg2 = NULL; + + if (arg0 == 0) return rc; + if (arg1) { + lparg1 = env->GetStringChars(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + if (arg2) { + lparg2 = env->GetStringChars(arg2, NULL); + if (lparg2 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + rc = pSession->CeCopyFile((LPCWSTR)lparg1, (LPCWSTR)lparg2, arg3); +fail: + if (arg1 && lparg1) env->ReleaseStringChars(arg1, lparg1); + if (arg2 && lparg2) env->ReleaseStringChars(arg2, lparg2); + return rc; +} + +JNIEXPORT jboolean JNICALL RAPI_NATIVE(CeDeleteFile) + (JNIEnv *env, jobject that, jint arg0, jstring arg1) +{ + jboolean rc = 0; + const jchar *lparg1 = NULL; + + if (arg0 == 0) return rc; + if (arg1) { + lparg1 = env->GetStringChars(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + rc = pSession->CeDeleteFile((LPCWSTR)lparg1); +fail: + if (arg1 && lparg1) env->ReleaseStringChars(arg1, lparg1); + return rc; +} + +JNIEXPORT jboolean JNICALL RAPI_NATIVE(CeMoveFile) + (JNIEnv *env, jobject that, jint arg0, jstring arg1, jstring arg2) +{ + jboolean rc = 0; + const jchar *lparg1 = NULL; + const jchar *lparg2 = NULL; + + if (arg0 == 0) return rc; + if (arg1) { + lparg1 = env->GetStringChars(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + if (arg2) { + lparg2 = env->GetStringChars(arg2, NULL); + if (lparg2 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + rc = pSession->CeMoveFile((LPCWSTR)lparg1, (LPCWSTR)lparg2); +fail: + if (arg1 && lparg1) env->ReleaseStringChars(arg1, lparg1); + if (arg2 && lparg2) env->ReleaseStringChars(arg2, lparg2); + return rc; +} + +JNIEXPORT jboolean JNICALL RAPI_NATIVE(CeCreateDirectory) + (JNIEnv *env, jobject that, jint arg0, jstring arg1) +{ + jboolean rc = 0; + const jchar *lparg1 = NULL; + + if (arg0 == 0) return rc; + if (arg1) { + lparg1 = env->GetStringChars(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + rc = pSession->CeCreateDirectory((LPCWSTR) lparg1, NULL); +fail: + if (arg1 && lparg1) env->ReleaseStringChars(arg1, lparg1); + return rc; +} + +JNIEXPORT jboolean JNICALL RAPI_NATIVE(CeRemoveDirectory) + (JNIEnv *env, jobject that, jint arg0, jstring arg1) +{ + jboolean rc = 0; + const jchar *lparg1 = NULL; + + if (arg0 == 0) return rc; + if (arg1) { + lparg1 = env->GetStringChars(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + rc = pSession->CeRemoveDirectory((LPCWSTR) lparg1); +fail: + if (arg1 && lparg1) env->ReleaseStringChars(arg1, lparg1); + return rc; +} + +struct FIND_DATA_FID_CACHE +{ + int cached; + jclass clazz; + jfieldID fileAttributes, creationTime, lastAccessTime; + jfieldID lastWriteTime, fileSize, oid, fileName; +}; + +FIND_DATA_FID_CACHE FIND_DATAFc; + +void cacheFIND_DATAFields(JNIEnv *env, jobject lpObject) +{ + if (FIND_DATAFc.cached) return; + FIND_DATAFc.clazz = env->GetObjectClass(lpObject); + FIND_DATAFc.fileAttributes = env->GetFieldID(FIND_DATAFc.clazz, "fileAttributes", "I"); + FIND_DATAFc.creationTime = env->GetFieldID(FIND_DATAFc.clazz, "creationTime", "J"); + FIND_DATAFc.lastAccessTime = env->GetFieldID(FIND_DATAFc.clazz, "lastAccessTime", "J"); + FIND_DATAFc.lastWriteTime = env->GetFieldID(FIND_DATAFc.clazz, "lastWriteTime", "J"); + FIND_DATAFc.fileSize = env->GetFieldID(FIND_DATAFc.clazz, "fileSize", "J"); + FIND_DATAFc.oid = env->GetFieldID(FIND_DATAFc.clazz, "oid", "I"); + FIND_DATAFc.fileName = env->GetFieldID(FIND_DATAFc.clazz, "fileName", "Ljava/lang/String;"); + FIND_DATAFc.cached = 1; +} + +jlong FILETIME2jlong(FILETIME ft) +{ + jlong res = ft.dwHighDateTime; + // well, this is a potential overflow since jlong is signed + // we should take care about this in the java part + res <<= 32; + res |= ft.dwLowDateTime; + return res; +} + +void setFIND_DATAFields(JNIEnv *env, jobject lpObject, CE_FIND_DATA *pFindData) +{ + if (!FIND_DATAFc.cached) cacheFIND_DATAFields(env, lpObject); + env->SetIntField(lpObject, FIND_DATAFc.fileAttributes, (jint)pFindData->dwFileAttributes); + + jlong creationTime = FILETIME2jlong(pFindData->ftCreationTime); + env->SetLongField(lpObject, FIND_DATAFc.creationTime, creationTime); + + jlong lastAccessTime = FILETIME2jlong(pFindData->ftLastAccessTime); + env->SetLongField(lpObject, FIND_DATAFc.lastAccessTime, lastAccessTime); + + jlong lastWriteTime = FILETIME2jlong(pFindData->ftLastWriteTime); + env->SetLongField(lpObject, FIND_DATAFc.lastWriteTime, lastWriteTime); + + jlong fileSize = pFindData->nFileSizeHigh; + fileSize <<= 32; + fileSize |= pFindData->nFileSizeLow; + env->SetLongField(lpObject, FIND_DATAFc.fileSize, fileSize); + + int fileNameLen = lstrlen(pFindData->cFileName); + jstring fileName = env->NewString((const jchar*)pFindData->cFileName, fileNameLen); + env->SetObjectField(lpObject, FIND_DATAFc.fileName, fileName); +} + +JNIEXPORT jint JNICALL RAPI_NATIVE(CeFindFirstFile) + (JNIEnv *env, jobject that, jint arg0, jstring arg1, jobject arg2) +{ + HANDLE h = INVALID_HANDLE_VALUE; + CE_FIND_DATA findData; + const jchar *lparg1 = NULL; + + if (arg0 == 0) goto fail; + if (arg1) { + lparg1 = env->GetStringChars(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + h = pSession->CeFindFirstFile((LPCWSTR)lparg1, &findData); + if (h != INVALID_HANDLE_VALUE && arg2) setFIND_DATAFields(env, arg2, &findData); +fail: + if (arg1 && lparg1) env->ReleaseStringChars(arg1, lparg1); + return (jint)h; +} + +JNIEXPORT jboolean JNICALL RAPI_NATIVE(CeFindNextFile) + (JNIEnv *env, jobject that, jint arg0, jint arg1, jobject arg2) +{ + jboolean rc = 0; + CE_FIND_DATA findData; + + if (arg0 == 0) return 0; + IRAPISession *pSession = (IRAPISession*) arg0; + rc = pSession->CeFindNextFile((HANDLE)arg1, &findData); + if (rc && arg2) setFIND_DATAFields(env, arg2, &findData); + return rc; +} + +JNIEXPORT jboolean JNICALL RAPI_NATIVE(CeFindClose) + (JNIEnv *env, jobject that, jint arg0, jint arg1) +{ + if (arg0 == 0) return 0; + IRAPISession *pSession = (IRAPISession*) arg0; + return pSession->CeFindClose((HANDLE)arg1); +} + +JNIEXPORT jboolean JNICALL RAPI_NATIVE(CeFindAllFiles) + (JNIEnv *env, jobject that, jint arg0, jstring arg1, jint arg2, jintArray arg3, jintArray arg4) +{ + jboolean rc = 0; + const jchar *lparg1 = NULL; + jint *lparg3 = NULL; + jint *lparg4 = NULL; + + if (arg0 == 0) goto fail; + if (arg1) { + lparg1 = env->GetStringChars(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + if (arg3) { + lparg3 = env->GetIntArrayElements(arg3, NULL); + if (lparg3 == NULL) goto fail; + } + if (arg4) { + lparg4 = env->GetIntArrayElements(arg4, NULL); + if (lparg4 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + rc = pSession->CeFindAllFiles((LPCWSTR)lparg1, arg2, (LPDWORD)lparg3, (LPLPCE_FIND_DATA)lparg4); +fail: + if (arg1 && lparg1) env->ReleaseStringChars(arg1, lparg1); + if (arg3 && lparg3) env->ReleaseIntArrayElements(arg3, lparg3, 0); + if (arg4 && lparg4) env->ReleaseIntArrayElements(arg4, lparg4, 0); + return rc; +} + +JNIEXPORT jint JNICALL RAPI_NATIVE(CeFindAllFilesEx) + (JNIEnv *env, jobject that, jint arg0, jint arg1, jint arg2, jobjectArray arg3) +{ + if (arg0 == 0 || arg2 == 0 || arg3 == 0) return E_FAIL; + LPCE_FIND_DATA findDataArray = (LPCE_FIND_DATA) arg2; + for (int i = 0 ; i < arg1 ; i++) { + jobject obj = env->GetObjectArrayElement(arg3, i); + setFIND_DATAFields(env, obj, &findDataArray[i]); + } + IRAPISession *pSession = (IRAPISession*) arg0; + return pSession->CeRapiFreeBuffer(findDataArray); +} + +JNIEXPORT jint JNICALL RAPI_NATIVE(CeGetFileAttributes) + (JNIEnv *env, jobject that, jint arg0, jstring arg1) +{ + jint rc = 0xFFFFFFFF; + const jchar *lparg1 = NULL; + + if (arg0 == 0) return rc; + if (arg1) { + lparg1 = env->GetStringChars(arg1, NULL); + if (lparg1 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + rc = pSession->CeGetFileAttributes((LPCWSTR)lparg1); +fail: + if (arg1 && lparg1) env->ReleaseStringChars(arg1, lparg1); + return rc; +} + +JNIEXPORT jint JNICALL RAPI_NATIVE(CeGetFileSize) + (JNIEnv *env, jobject that, jint arg0, jint arg1, jintArray arg2) +{ + jint rc = INVALID_FILE_SIZE; + jint *lparg2 = NULL; + + if (arg0 == 0) return rc; + if (arg2) { + lparg2 = env->GetIntArrayElements(arg2, NULL); + if (lparg2 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + rc = pSession->CeGetFileSize((HANDLE)arg1, (LPDWORD)lparg2); +fail: + if (arg2 && lparg2) env->ReleaseIntArrayElements(arg2, lparg2, 0); + return rc; +} + +JNIEXPORT jboolean JNICALL RAPI_NATIVE(CeGetFileTime) + (JNIEnv *env, jobject that, jint arg0, jint arg1, jlongArray arg2, jlongArray arg3, jlongArray arg4) +{ + jboolean rc = 0; + jlong *lparg2 = NULL; + jlong *lparg3 = NULL; + jlong *lparg4 = NULL; + FILETIME crTime, laTime, lwTime; + + if (arg0 == 0) return rc; + if (arg2) { + lparg2 = env->GetLongArrayElements(arg2, NULL); + if (lparg2 == NULL) goto fail; + } + if (arg3) { + lparg3 = env->GetLongArrayElements(arg3, NULL); + if (lparg3 == NULL) goto fail; + } + if (arg4) { + lparg4 = env->GetLongArrayElements(arg4, NULL); + if (lparg4 == NULL) goto fail; + } + IRAPISession *pSession = (IRAPISession*) arg0; + rc = pSession->CeGetFileTime((HANDLE)arg1, &crTime, &laTime, &lwTime); + if (!rc) goto fail; + lparg2[0] = FILETIME2jlong(crTime); + lparg3[0] = FILETIME2jlong(laTime); + lparg4[0] = FILETIME2jlong(lwTime); +fail: + if (arg2 && lparg2) env->ReleaseLongArrayElements(arg2, lparg2, 0); + if (arg3 && lparg3) env->ReleaseLongArrayElements(arg3, lparg3, 0); + if (arg4 && lparg4) env->ReleaseLongArrayElements(arg4, lparg4, 0); + return rc; +} \ No newline at end of file diff --git a/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_internal_rapi_RapiDesktop.h b/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_internal_rapi_RapiDesktop.h new file mode 100644 index 00000000000..a9236dfde51 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_internal_rapi_RapiDesktop.h @@ -0,0 +1,21 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_eclipse_tm_internal_rapi_RapiDesktop */ + +#ifndef _Included_org_eclipse_tm_internal_rapi_RapiDesktop +#define _Included_org_eclipse_tm_internal_rapi_RapiDesktop +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_eclipse_tm_internal_rapi_RapiDesktop + * Method: EnumDevices + * Signature: (I[I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiDesktop_EnumDevices + (JNIEnv *, jobject, jint, jintArray); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_internal_rapi_RapiDevice.h b/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_internal_rapi_RapiDevice.h new file mode 100644 index 00000000000..a81190cfed9 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_internal_rapi_RapiDevice.h @@ -0,0 +1,45 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_eclipse_tm_internal_rapi_RapiDevice */ + +#ifndef _Included_org_eclipse_tm_internal_rapi_RapiDevice +#define _Included_org_eclipse_tm_internal_rapi_RapiDevice +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_eclipse_tm_internal_rapi_RapiDevice + * Method: CreateSession + * Signature: (I[I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiDevice_CreateSession + (JNIEnv *, jobject, jint, jintArray); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiDevice + * Method: GetConnectionInfo + * Signature: (ILorg/eclipse/tm/rapi/RapiConnectionInfo;)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiDevice_GetConnectionInfo + (JNIEnv *, jobject, jint, jobject); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiDevice + * Method: GetDeviceInfo + * Signature: (ILorg/eclipse/tm/rapi/RapiDeviceInfo;)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiDevice_GetDeviceInfo + (JNIEnv *, jobject, jint, jobject); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiDevice + * Method: GetConnectStat + * Signature: (I[I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiDevice_GetConnectStat + (JNIEnv *, jobject, jint, jintArray); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_internal_rapi_RapiEnumDevices.h b/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_internal_rapi_RapiEnumDevices.h new file mode 100644 index 00000000000..ede63cb618c --- /dev/null +++ b/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_internal_rapi_RapiEnumDevices.h @@ -0,0 +1,21 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_eclipse_tm_internal_rapi_RapiEnumDevices */ + +#ifndef _Included_org_eclipse_tm_internal_rapi_RapiEnumDevices +#define _Included_org_eclipse_tm_internal_rapi_RapiEnumDevices +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_eclipse_tm_internal_rapi_RapiEnumDevices + * Method: Next + * Signature: (I[I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiEnumDevices_Next + (JNIEnv *, jobject, jint, jintArray); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_internal_rapi_RapiSession.h b/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_internal_rapi_RapiSession.h new file mode 100644 index 00000000000..eba6404ecb7 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_internal_rapi_RapiSession.h @@ -0,0 +1,181 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_eclipse_tm_internal_rapi_RapiSession */ + +#ifndef _Included_org_eclipse_tm_internal_rapi_RapiSession +#define _Included_org_eclipse_tm_internal_rapi_RapiSession +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeRapiInit + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeRapiInit + (JNIEnv *, jobject, jint); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeRapiUninit + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeRapiUninit + (JNIEnv *, jobject, jint); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeRapiGetError + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeRapiGetError + (JNIEnv *, jobject, jint); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeGetLastError + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeGetLastError + (JNIEnv *, jobject, jint); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeCreateFile + * Signature: (ILjava/lang/String;IIII)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeCreateFile + (JNIEnv *, jobject, jint, jstring, jint, jint, jint, jint); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeReadFile + * Signature: (II[BI[I)Z + */ +JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeReadFile + (JNIEnv *, jobject, jint, jint, jbyteArray, jint, jintArray); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeWriteFile + * Signature: (II[BI[I)Z + */ +JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeWriteFile + (JNIEnv *, jobject, jint, jint, jbyteArray, jint, jintArray); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeCloseHandle + * Signature: (II)Z + */ +JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeCloseHandle + (JNIEnv *, jobject, jint, jint); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeCopyFile + * Signature: (ILjava/lang/String;Ljava/lang/String;Z)Z + */ +JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeCopyFile + (JNIEnv *, jobject, jint, jstring, jstring, jboolean); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeDeleteFile + * Signature: (ILjava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeDeleteFile + (JNIEnv *, jobject, jint, jstring); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeMoveFile + * Signature: (ILjava/lang/String;Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeMoveFile + (JNIEnv *, jobject, jint, jstring, jstring); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeCreateDirectory + * Signature: (ILjava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeCreateDirectory + (JNIEnv *, jobject, jint, jstring); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeRemoveDirectory + * Signature: (ILjava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeRemoveDirectory + (JNIEnv *, jobject, jint, jstring); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeFindFirstFile + * Signature: (ILjava/lang/String;Lorg/eclipse/tm/rapi/RapiFindData;)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeFindFirstFile + (JNIEnv *, jobject, jint, jstring, jobject); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeFindNextFile + * Signature: (IILorg/eclipse/tm/rapi/RapiFindData;)Z + */ +JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeFindNextFile + (JNIEnv *, jobject, jint, jint, jobject); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeFindClose + * Signature: (II)Z + */ +JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeFindClose + (JNIEnv *, jobject, jint, jint); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeFindAllFiles + * Signature: (ILjava/lang/String;I[I[I)Z + */ +JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeFindAllFiles + (JNIEnv *, jobject, jint, jstring, jint, jintArray, jintArray); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeFindAllFilesEx + * Signature: (III[Lorg/eclipse/tm/rapi/RapiFindData;)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeFindAllFilesEx + (JNIEnv *, jobject, jint, jint, jint, jobjectArray); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeGetFileAttributes + * Signature: (ILjava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeGetFileAttributes + (JNIEnv *, jobject, jint, jstring); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeGetFileSize + * Signature: (II[I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeGetFileSize + (JNIEnv *, jobject, jint, jint, jintArray); + +/* + * Class: org_eclipse_tm_internal_rapi_RapiSession + * Method: CeGetFileTime + * Signature: (II[J[J[J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeGetFileTime + (JNIEnv *, jobject, jint, jint, jlongArray, jlongArray, jlongArray); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_rapi_OS.h b/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_rapi_OS.h new file mode 100644 index 00000000000..2bb2f10e5c0 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/native/org_eclipse_tm_rapi_OS.h @@ -0,0 +1,137 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_eclipse_tm_rapi_OS */ + +#ifndef _Included_org_eclipse_tm_rapi_OS +#define _Included_org_eclipse_tm_rapi_OS +#ifdef __cplusplus +extern "C" { +#endif +#undef org_eclipse_tm_rapi_OS_NOERROR +#define org_eclipse_tm_rapi_OS_NOERROR 0L +#undef org_eclipse_tm_rapi_OS_GENERIC_READ +#define org_eclipse_tm_rapi_OS_GENERIC_READ -2147483648L +#undef org_eclipse_tm_rapi_OS_GENERIC_WRITE +#define org_eclipse_tm_rapi_OS_GENERIC_WRITE 1073741824L +#undef org_eclipse_tm_rapi_OS_FILE_SHARE_READ +#define org_eclipse_tm_rapi_OS_FILE_SHARE_READ 1L +#undef org_eclipse_tm_rapi_OS_FILE_SHARE_WRITE +#define org_eclipse_tm_rapi_OS_FILE_SHARE_WRITE 2L +#undef org_eclipse_tm_rapi_OS_CREATE_NEW +#define org_eclipse_tm_rapi_OS_CREATE_NEW 1L +#undef org_eclipse_tm_rapi_OS_CREATE_ALWAYS +#define org_eclipse_tm_rapi_OS_CREATE_ALWAYS 2L +#undef org_eclipse_tm_rapi_OS_OPEN_EXISTING +#define org_eclipse_tm_rapi_OS_OPEN_EXISTING 3L +#undef org_eclipse_tm_rapi_OS_OPEN_ALWAYS +#define org_eclipse_tm_rapi_OS_OPEN_ALWAYS 4L +#undef org_eclipse_tm_rapi_OS_TRUNCATE_EXISTING +#define org_eclipse_tm_rapi_OS_TRUNCATE_EXISTING 5L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_ARCHIVE +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_ARCHIVE 32L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_COMPRESSED +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_COMPRESSED 2048L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_DIRECTORY +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_DIRECTORY 16L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_ENCRYPTED +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_ENCRYPTED 16384L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_HIDDEN +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_HIDDEN 2L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_INROM +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_INROM 64L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_NORMAL +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_NORMAL 128L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_READONLY +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_READONLY 1L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_REPARSE_POINT +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_REPARSE_POINT 1024L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_ROMMODULE +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_ROMMODULE 8192L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_SPARSE_FILE +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_SPARSE_FILE 512L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_SYSTEM +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_SYSTEM 4L +#undef org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_TEMPORARY +#define org_eclipse_tm_rapi_OS_FILE_ATTRIBUTE_TEMPORARY 256L +#undef org_eclipse_tm_rapi_OS_FILE_FLAG_WRITE_THROUGH +#define org_eclipse_tm_rapi_OS_FILE_FLAG_WRITE_THROUGH -2147483648L +#undef org_eclipse_tm_rapi_OS_FILE_FLAG_OVERLAPPED +#define org_eclipse_tm_rapi_OS_FILE_FLAG_OVERLAPPED 1073741824L +#undef org_eclipse_tm_rapi_OS_FILE_FLAG_RANDOM_ACCESS +#define org_eclipse_tm_rapi_OS_FILE_FLAG_RANDOM_ACCESS 268435456L +#undef org_eclipse_tm_rapi_OS_FILE_FLAG_SEQUENTIAL_SCAN +#define org_eclipse_tm_rapi_OS_FILE_FLAG_SEQUENTIAL_SCAN 134217728L +#undef org_eclipse_tm_rapi_OS_FAF_ATTRIB_CHILDREN +#define org_eclipse_tm_rapi_OS_FAF_ATTRIB_CHILDREN 4096L +#undef org_eclipse_tm_rapi_OS_FAF_ATTRIB_NO_HIDDEN +#define org_eclipse_tm_rapi_OS_FAF_ATTRIB_NO_HIDDEN 8192L +#undef org_eclipse_tm_rapi_OS_FAF_FOLDERS_ONLY +#define org_eclipse_tm_rapi_OS_FAF_FOLDERS_ONLY 16384L +#undef org_eclipse_tm_rapi_OS_FAF_NO_HIDDEN_SYS_ROMMODULES +#define org_eclipse_tm_rapi_OS_FAF_NO_HIDDEN_SYS_ROMMODULES 32768L +#undef org_eclipse_tm_rapi_OS_FAF_GETTARGET +#define org_eclipse_tm_rapi_OS_FAF_GETTARGET 65536L +#undef org_eclipse_tm_rapi_OS_FAF_ATTRIBUTES +#define org_eclipse_tm_rapi_OS_FAF_ATTRIBUTES 1L +#undef org_eclipse_tm_rapi_OS_FAF_CREATION_TIME +#define org_eclipse_tm_rapi_OS_FAF_CREATION_TIME 2L +#undef org_eclipse_tm_rapi_OS_FAF_LASTACCESS_TIME +#define org_eclipse_tm_rapi_OS_FAF_LASTACCESS_TIME 4L +#undef org_eclipse_tm_rapi_OS_FAF_LASTWRITE_TIME +#define org_eclipse_tm_rapi_OS_FAF_LASTWRITE_TIME 8L +#undef org_eclipse_tm_rapi_OS_FAF_SIZE_HIGH +#define org_eclipse_tm_rapi_OS_FAF_SIZE_HIGH 16L +#undef org_eclipse_tm_rapi_OS_FAF_SIZE_LOW +#define org_eclipse_tm_rapi_OS_FAF_SIZE_LOW 32L +#undef org_eclipse_tm_rapi_OS_FAF_OID +#define org_eclipse_tm_rapi_OS_FAF_OID 64L +#undef org_eclipse_tm_rapi_OS_FAF_NAME +#define org_eclipse_tm_rapi_OS_FAF_NAME 128L +#undef org_eclipse_tm_rapi_OS_INVALID_HANDLE_VALUE +#define org_eclipse_tm_rapi_OS_INVALID_HANDLE_VALUE -1L +#undef org_eclipse_tm_rapi_OS_TIME_DIFF +#define org_eclipse_tm_rapi_OS_TIME_DIFF 11644473600000i64 +#undef org_eclipse_tm_rapi_OS_COINIT_MULTITHREADED +#define org_eclipse_tm_rapi_OS_COINIT_MULTITHREADED 0L +#undef org_eclipse_tm_rapi_OS_COINIT_APARTMENTTHREADED +#define org_eclipse_tm_rapi_OS_COINIT_APARTMENTTHREADED 2L +#undef org_eclipse_tm_rapi_OS_COINIT_DISABLE_OLE1DDE +#define org_eclipse_tm_rapi_OS_COINIT_DISABLE_OLE1DDE 4L +#undef org_eclipse_tm_rapi_OS_COINIT_SPEED_OVER_MEMORY +#define org_eclipse_tm_rapi_OS_COINIT_SPEED_OVER_MEMORY 8L +/* + * Class: org_eclipse_tm_rapi_OS + * Method: CoInitializeEx + * Signature: (II)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_rapi_OS_CoInitializeEx + (JNIEnv *, jclass, jint, jint); + +/* + * Class: org_eclipse_tm_rapi_OS + * Method: CoUninitialize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_eclipse_tm_rapi_OS_CoUninitialize + (JNIEnv *, jclass); + +/* + * Class: org_eclipse_tm_rapi_OS + * Method: CreateRapiDesktop + * Signature: ([I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_tm_rapi_OS_CreateRapiDesktop + (JNIEnv *, jclass, jintArray); + +/* + * Class: org_eclipse_tm_rapi_OS + * Method: ReleaseIUnknown + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_org_eclipse_tm_rapi_OS_ReleaseIUnknown + (JNIEnv *, jclass, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/wince/org.eclipse.tm.rapi/plugin.properties b/wince/org.eclipse.tm.rapi/plugin.properties new file mode 100644 index 00000000000..751c2a744fa --- /dev/null +++ b/wince/org.eclipse.tm.rapi/plugin.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2008 Radoslav Gerganov +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Radoslav Gerganov - initial API and implementation +############################################################################### +Bundle-Vendor.0 = Eclipse.org +Bundle-Name.0 = Java wrappers for RAPI2 \ No newline at end of file diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/internal/rapi/RapiDesktop.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/internal/rapi/RapiDesktop.java new file mode 100644 index 00000000000..0a37d98f646 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/internal/rapi/RapiDesktop.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.internal.rapi; + +import org.eclipse.tm.rapi.IRapiDesktop; +import org.eclipse.tm.rapi.IRapiEnumDevices; +import org.eclipse.tm.rapi.OS; +import org.eclipse.tm.rapi.RapiException; + +/** + * Implementation of IRapiDesktop. + * + * @author Radoslav Gerganov + */ +public class RapiDesktop extends IRapiDesktop { + + public RapiDesktop(int addr) { + super(addr); + } + + public IRapiEnumDevices enumDevices() throws RapiException { + int[] ppIEnum = new int[1]; + int rc = EnumDevices(addr, ppIEnum); + if (rc != OS.NOERROR) { + throw new RapiException("EnumDevices failed", rc); + } + return new RapiEnumDevices(ppIEnum[0]); + } + + public String toString() { + return "[RapiDesktop] addr: " + Integer.toHexString(addr); + } + + private final native int EnumDevices(int addr, int[] ppIEnum); +} diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/internal/rapi/RapiDevice.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/internal/rapi/RapiDevice.java new file mode 100644 index 00000000000..621fda2d2e4 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/internal/rapi/RapiDevice.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.internal.rapi; + +import org.eclipse.tm.rapi.IRapiDevice; +import org.eclipse.tm.rapi.IRapiSession; +import org.eclipse.tm.rapi.OS; +import org.eclipse.tm.rapi.RapiConnectionInfo; +import org.eclipse.tm.rapi.RapiDeviceInfo; +import org.eclipse.tm.rapi.RapiException; + +/** + * Implementation of IRapiDevice. + * + * @author Radoslav Gerganov + */ +public class RapiDevice extends IRapiDevice { + + public RapiDevice(int addr) { + super(addr); + } + + public IRapiSession createSession() throws RapiException { + int[] ppISession = new int[1]; + int rc = CreateSession(addr, ppISession); + if (rc != OS.NOERROR) { + throw new RapiException("CreateSession failed", rc); + } + return new RapiSession(ppISession[0]); + } + + public RapiConnectionInfo getConnectionInfo() throws RapiException { + RapiConnectionInfo connInfo = new RapiConnectionInfo(); + int rc = GetConnectionInfo(addr, connInfo); + if (rc != OS.NOERROR) { + throw new RapiException("GetConnectionInfo failed", rc); + } + return connInfo; + } + + public RapiDeviceInfo getDeviceInfo() throws RapiException { + RapiDeviceInfo devInfo = new RapiDeviceInfo(); + int rc = GetDeviceInfo(addr, devInfo); + if (rc != OS.NOERROR) { + throw new RapiException("GetDeviceInfo failed", rc); + } + return devInfo; + } + + public boolean isConnected() throws RapiException { + int[] status = new int[1]; + int rc = GetConnectStat(addr, status); + if (rc != OS.NOERROR) { + throw new RapiException("GetConnectStat failed", rc); + } + return status[0] == 1; + } + + public String toString() { + return "[RapiDevice] addr: " + Integer.toHexString(addr); + } + + private final native int CreateSession(int addr, int[] ppISession); + private final native int GetConnectionInfo(int addr, RapiConnectionInfo pConnInfo); + private final native int GetDeviceInfo(int addr, RapiDeviceInfo pDevInfo); + private final native int GetConnectStat(int addr, int[] status); +} diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/internal/rapi/RapiEnumDevices.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/internal/rapi/RapiEnumDevices.java new file mode 100644 index 00000000000..8f9c1e26b40 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/internal/rapi/RapiEnumDevices.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.internal.rapi; + +import org.eclipse.tm.rapi.IRapiDevice; +import org.eclipse.tm.rapi.IRapiEnumDevices; +import org.eclipse.tm.rapi.OS; +import org.eclipse.tm.rapi.RapiException; + +/** + * Implementation of IRapiEnumDevices. + * + * @author Radoslav Gerganov + */ +public class RapiEnumDevices extends IRapiEnumDevices { + + public RapiEnumDevices(int addr) { + super(addr); + } + + public IRapiDevice next() throws RapiException { + int[] ppIDevice = new int[1]; + int rc = Next(addr, ppIDevice); + if (rc != OS.NOERROR) { + throw new RapiException("Next failed", rc); + } + return new RapiDevice(ppIDevice[0]); + } + + public String toString() { + return "[RapiEnumDevices] addr: " + Integer.toHexString(addr); + } + + private final native int Next(int addr, int[] ppIDevice); +} diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/internal/rapi/RapiSession.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/internal/rapi/RapiSession.java new file mode 100644 index 00000000000..f8cf86a59ef --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/internal/rapi/RapiSession.java @@ -0,0 +1,310 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.internal.rapi; + +import java.util.Date; + +import org.eclipse.tm.rapi.IRapiSession; +import org.eclipse.tm.rapi.OS; +import org.eclipse.tm.rapi.RapiException; +import org.eclipse.tm.rapi.RapiFindData; + + +/** + * Implementation of IRapiSession. + * + * @author Radoslav Gerganov + */ +public class RapiSession extends IRapiSession { + + private RapiFindData[] EMPTY_FIND_DATA_ARR = new RapiFindData[0]; + + public RapiSession(int addr) { + super(addr); + } + + private int getError() { + int err = CeRapiGetError(addr); + if (err >= 0) { + err = CeGetLastError(addr); + } + return err; + } + + public void init() throws RapiException { + int rc = CeRapiInit(addr); + if (rc != OS.NOERROR) { + throw new RapiException("CeRapiInit failed", rc); + } + } + + public void uninit() throws RapiException { + int rc = CeRapiUninit(addr); + if (rc != OS.NOERROR) { + throw new RapiException("CeRapiUninit failed", rc); + } + } + + public int createFile(String fileName, int desiredAccess, int shareMode, + int creationDisposition, int flagsAndAttributes) throws RapiException { + + int handle = CeCreateFile(addr, fileName, desiredAccess, shareMode, + creationDisposition, flagsAndAttributes); + if (handle == OS.INVALID_HANDLE_VALUE) { + throw new RapiException("CeCreateFile failed", getError()); + } + return handle; + } + + public int readFile(int handle, byte[] b) throws RapiException { + if (b.length == 0) { + return 0; + } + int[] bytesRead = new int[1]; + boolean res = CeReadFile(addr, handle, b, b.length, bytesRead); + if (!res) { + throw new RapiException("CeReadFile failed", getError()); + } + return bytesRead[0] > 0 ? bytesRead[0] : -1; + } + + public int readFile(int handle, byte[] b, int off, int len) + throws RapiException { + if (off < 0 || len < 0 || off + len > b.length) { + throw new IndexOutOfBoundsException("Incorrect offset/length"); + } + if (len == 0) { + return 0; + } + //TODO: add support for setting offset in the native code and remove this tmp array + byte[] tmp = new byte[len]; + int[] bytesRead = new int[1]; + boolean res = CeReadFile(addr, handle, tmp, tmp.length, bytesRead); + if (!res) { + throw new RapiException("CeReadFile failed", getError()); + } + System.arraycopy(tmp, 0, b, off, len); + return bytesRead[0] > 0 ? bytesRead[0] : -1; + } + + public void writeFile(int handle, byte[] b) throws RapiException { + int[] bytesWritten = new int[1]; + boolean res = CeWriteFile(addr, handle, b, b.length, bytesWritten); + if (!res) { + throw new RapiException("CeWriteFile failed", getError()); + } + } + + public void writeFile(int handle, byte[] b, int off, int len) + throws RapiException { + + if (off < 0 || len < 0 || off + len > b.length) { + throw new IndexOutOfBoundsException("Incorrect offset/length"); + } + //TODO: add support for setting offset in the native code and remove this tmp array + byte[] tmp = new byte[len]; + System.arraycopy(b, off, tmp, 0, len); + int[] bytesWritten = new int[1]; + boolean res = CeWriteFile(addr, handle, tmp, tmp.length, bytesWritten); + if (!res) { + throw new RapiException("CeWriteFile failed", getError()); + } + } + + public void closeHandle(int handle) throws RapiException { + boolean res = CeCloseHandle(addr, handle); + if (!res) { + throw new RapiException("CeCloseHandle failed", getError()); + } + } + + public void copyFile(String existingFile, String newFile) throws RapiException { + //overwrite by default + boolean res = CeCopyFile(addr, existingFile, newFile, false); + if (!res) { + throw new RapiException("CeCopyFile failed", getError()); + } + } + + public void deleteFile(String fileName) throws RapiException { + boolean res = CeDeleteFile(addr, fileName); + if (!res) { + throw new RapiException("CeDeleteFile failed", getError()); + } + } + + public void moveFile(String existingFileName, String newFileName) throws RapiException { + boolean res = CeMoveFile(addr, existingFileName, newFileName); + if (!res) { + throw new RapiException("CeMoveFile failed", getError()); + } + } + + public void createDirectory(String pathName) throws RapiException { + boolean res = CeCreateDirectory(addr, pathName); + if (!res) { + throw new RapiException("CeCreateDirectory failed", getError()); + } + } + + public void removeDirectory(String pathName) throws RapiException { + boolean res = CeRemoveDirectory(addr, pathName); + if (!res) { + throw new RapiException("CeRemoveDirectory failed", getError()); + } + } + + public int findFirstFile(String fileName, RapiFindData findData) throws RapiException { + int handle = CeFindFirstFile(addr, fileName, findData); + if (handle == OS.INVALID_HANDLE_VALUE) { + throw new RapiException("CeFindFirstFile failed", getError()); + } + return handle; + } + + public RapiFindData findNextFile(int handle) { + RapiFindData findData = new RapiFindData(); + boolean res = CeFindNextFile(addr, handle, findData); + // just return null if findNext fail + return res ? findData : null; + } + + public void findClose(int handle) throws RapiException { + boolean res = CeFindClose(addr, handle); + if (!res) { + throw new RapiException("CeFindClose failed", getError()); + } + } + + public RapiFindData[] findAllFiles(String path, int flags) throws RapiException { + int[] foundCount = new int[1]; + int[] dataArr = new int[1]; + boolean res = CeFindAllFiles(addr, path, flags, foundCount, dataArr); + int count = foundCount[0]; + if (!res || count == 0) { + // nothing found + return EMPTY_FIND_DATA_ARR; + } + RapiFindData[] findDataArr = new RapiFindData[count]; + for (int i = 0 ; i < count ; i++) { + findDataArr[i] = new RapiFindData(); + } + int hRes = CeFindAllFilesEx(addr, count, dataArr[0], findDataArr); + if (hRes != OS.NOERROR) { + throw new RapiException("CeFindAllFilesEx failed", hRes); + } + return findDataArr; + } + + public int getFileAttributes(String fileName) { + int attributes = CeGetFileAttributes(addr, fileName); +// if (attributes == 0xFFFFFFFF) { +// throw new RapiException("CeGetFileAttributes failed", getError()); +// } + return attributes; + } + + public long getFileSize(int handle) { + int[] sizeHigh = new int[] {1}; + int sizeLow = CeGetFileSize(addr, handle, sizeHigh); + return ( ((long)sizeHigh[0] << 32) | (sizeLow & 0xFFFFFFFF)); + } + + public Date getFileCreationTime(int handle) throws RapiException { + long[] crTime = new long[1]; + long[] laTime = new long[1]; + long[] lwTime = new long[1]; + boolean res = CeGetFileTime(addr, handle, crTime, laTime, lwTime); + if (!res) { + throw new RapiException("CeGetFileTime failed", getError()); + } + return new Date((crTime[0] / 10000) - OS.TIME_DIFF); + } + + public Date getFileLastAccessTime(int handle) throws RapiException { + long[] crTime = new long[1]; + long[] laTime = new long[1]; + long[] lwTime = new long[1]; + boolean res = CeGetFileTime(addr, handle, crTime, laTime, lwTime); + if (!res) { + throw new RapiException("CeGetFileTime failed", getError()); + } + return new Date((laTime[0] / 10000) - OS.TIME_DIFF); + } + + public Date getFileLastWriteTime(int handle) throws RapiException { + long[] crTime = new long[1]; + long[] laTime = new long[1]; + long[] lwTime = new long[1]; + boolean res = CeGetFileTime(addr, handle, crTime, laTime, lwTime); + if (!res) { + throw new RapiException("CeGetFileTime failed", getError()); + } + return new Date((lwTime[0] / 10000) - OS.TIME_DIFF); + } + + public String toString() { + return "[RapiSession] addr: " + Integer.toHexString(addr); + } + + private final native int CeRapiInit(int addr); + + private final native int CeRapiUninit(int addr); + + private final native int CeRapiGetError(int addr); + + private final native int CeGetLastError(int addr); + + private final native int CeCreateFile(int addr, String lpFileName, + int dwDesiredAccess, int dwShareMode, int dwCreationDisposition, + int dwFlagsAndAttributes); + + private final native boolean CeReadFile(int addr, int hFile, byte[] lpBuffer, + int nNumberOfBytesToRead, int[] lpNumberOfBytesRead); + + private final native boolean CeWriteFile(int addr, int hFile, byte[] lpBuffer, + int nNumberOfBytesToWrite, int[] lpNumberOfBytesWritten); + + private final native boolean CeCloseHandle(int addr, int hObject); + + private final native boolean CeCopyFile(int addr, String lpExistingFileName, + String lpNewFileName, boolean bFailIfExists); + + private final native boolean CeDeleteFile(int addr, String lpFileName); + + private final native boolean CeMoveFile(int addr, String lpExistingFileName, + String lpNewFileName); + + private final native boolean CeCreateDirectory(int addr, String lpPathName); + + private final native boolean CeRemoveDirectory(int addr, String lpPathName); + + private final native int CeFindFirstFile(int addr, String lpFileName, + RapiFindData lpFindFileData); + + private final native boolean CeFindNextFile(int addr, int hFindFile, + RapiFindData lpFindFileData); + + private final native boolean CeFindClose(int addr, int hFindFile); + + private final native boolean CeFindAllFiles(int addr, String szPath, + int dwFlags, int[] lpdwFoundCount, int[] ppFindDataArray); + + private final native int CeFindAllFilesEx(int addr, int foundCount, + int dataArr, RapiFindData[] findDataArr); + + private final native int CeGetFileAttributes(int addr, String lpFileName); + + private final native int CeGetFileSize(int addr, int hFile, int[] lpFileSizeHigh); + + private final native boolean CeGetFileTime(int addr, int hFile, + long[] lpCreationTime, long[] lpLastAccessTime, long[] lpLastWriteTime); +} diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IRapiDesktop.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IRapiDesktop.java new file mode 100644 index 00000000000..b79be90f5a9 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IRapiDesktop.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi; + +import org.eclipse.tm.internal.rapi.RapiDesktop; + +/** + * This class is used to find connected WinCE-based remote devices. + *

Use IRapiDesktop.getInstance() to obtain an instance. + * + * @author Radoslav Gerganov + */ +public abstract class IRapiDesktop extends IUnknown { + + public IRapiDesktop(int addr) { + super(addr); + } + + /** + * Returns new instance of IRapiDesktop. + * Use {@link IRapiDesktop#release()} to release this instance when it is + * no longer needed. + * @return new instance of IRapiDesktop + * @throws RapiException if an error occurs. + */ + public synchronized static IRapiDesktop getInstance() throws RapiException { + int[] rapiDesktop = new int[1]; + int rc = OS.CreateRapiDesktop(rapiDesktop); + if (rc != OS.NOERROR) { + throw new RapiException("CreateRapiDesktop failed", rc); + } + return new RapiDesktop(rapiDesktop[0]); + } + + /** + * Returns an instance of IRapiEnumDevices. + * Use {@link IRapiEnumDevices#release()} to release this instance when it is + * no longer needed. + * @return an instance of IRapiEnumDevices + * @throws RapiException if an error occurs. + */ + public abstract IRapiEnumDevices enumDevices() throws RapiException; + +} diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IRapiDevice.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IRapiDevice.java new file mode 100644 index 00000000000..4c5d9be0737 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IRapiDevice.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi; + +/** + * This class represents a connected WinCE-based remote device. + * + * @author Radoslav Gerganov + */ +public abstract class IRapiDevice extends IUnknown { + + public IRapiDevice(int addr) { + super(addr); + } + + /** + * Returns an instance of IRapiSession for this remote device. + * Use {@link IRapiSession#release()} to release this instance when it is + * no longer needed. + * @return an instance of IRapiSession + * @throws RapiException if an error occurs. + */ + public abstract IRapiSession createSession() throws RapiException; + + /** + * Returns information about the connection between this remote device and the desktop. + * @return RapiConnectionInfo object containing information about + * the connection between this remote device and the desktop. + * @throws RapiException if an error occurs. + */ + public abstract RapiConnectionInfo getConnectionInfo() throws RapiException; + + /** + * Returns information about this remote device. + * @return RapiDeviceInfo object containing information about this remote + * device. + * @throws RapiException if an error occurs. + */ + public abstract RapiDeviceInfo getDeviceInfo() throws RapiException; + + /** + * Tests whether this device is connected. + * @return true if this device is connected;false otherwise. + * @throws RapiException if an error occurs. + */ + public abstract boolean isConnected() throws RapiException; + +} \ No newline at end of file diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IRapiEnumDevices.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IRapiEnumDevices.java new file mode 100644 index 00000000000..f3a33704a55 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IRapiEnumDevices.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi; + +/** + * This class is used to enumerate the set of connected WinCE-based + * remote devices which are represented by IRapiDevice + * objects. + * + * @author Radoslav Gerganov + */ +public abstract class IRapiEnumDevices extends IUnknown { + + public IRapiEnumDevices(int addr) { + super(addr); + } + + /** + * Returns an instance of IRapiDevice. + * Use {@link IRapiDevice#release()} to release this instance when it is + * no longer needed. + * @return an instance of IRapiDevice + * @throws RapiException if an error occurs. + */ + public abstract IRapiDevice next() throws RapiException; + +} \ No newline at end of file diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IRapiSession.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IRapiSession.java new file mode 100644 index 00000000000..ee87c7c13ce --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IRapiSession.java @@ -0,0 +1,237 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi; + +import java.util.Date; + +/** + * This class is used to perform Remote API 2 operations on a connected + * WinCE-based remote device. + * + * @author Radoslav Gerganov + */ +public abstract class IRapiSession extends IUnknown { + + public IRapiSession(int addr) { + super(addr); + } + + /** + * Initializes (synchronously) the communication layers between the desktop + * and the target remote device. This method must be called before calling any + * of the other IRapiSession methods. Use {@link IRapiSession#uninit()} + * to uninitialize the session. + * @throws RapiException if an error occurs. + */ + public abstract void init() throws RapiException; + + /** + * Uninitializes the session. This method should be called last. + * @throws RapiException if an error occurs. + */ + public abstract void uninit() throws RapiException; + + /** + * Creates, opens, or truncates a file on the remote device. + * @param fileName file name on the remote device + * @param desiredAccess specifies the type of access to the file + * @param shareMode specifies how the file can be shared + * @param creationDisposition specifies which action to take on + * files that exist, and which action to take when files do not exist + * @param flagsAndAttributes specifies the file attributes and flags + * for the file + * @return integer representing a valid handle that can be used to access the file + * @throws RapiException if an error occurs. + */ + public abstract int createFile(String fileName, int desiredAccess, + int shareMode, int creationDisposition, + int flagsAndAttributes) throws RapiException; + + /** + * Reads up to b.length bytes of data from a remote file + * into an array of bytes. + * @param handle handle to the file to be read + * @param b the buffer into which the data is read + * @return the total number of bytes read into the buffer, or + * -1 if there is no more data because the end of + * the file has been reached + * @throws RapiException if an error occurs. + */ + public abstract int readFile(int handle, byte[] b) throws RapiException; + + /** + * Reads up to len bytes of data from a remote file + * into an array of bytes. + * @param handle handle to the file to be read + * @param b the buffer into which the data is read + * @param off the start offset of the data + * @param len the maximum number of bytes read + * @return the total number of bytes read into the buffer, or + * -1 if there is no more data because the end of + * the file has been reached + * @throws RapiException if an error occurs. + */ + public abstract int readFile(int handle, byte[] b, int off, int len) + throws RapiException; + + /** + * Writes b.length bytes from the specified byte array + * to a remote file. + * @param handle handle to the file to which bytes will be written + * @param b the data + * @throws RapiException if an error occurs. + */ + public abstract void writeFile(int handle, byte[] b) throws RapiException; + + /** + * Writes len bytes from the specified byte array + * starting at offset off to a remote file. + * @param handle handle to the file to which bytes will be written + * @param b the data + * @param off the start offset in the data + * @param len the number of bytes to write + * @throws RapiException if an error occurs. + */ + public abstract void writeFile(int handle, byte[] b, int off, int len) + throws RapiException; + + /** + * Closes an open file handle. + * @param handle handle to an open file + * @throws RapiException if an error occurs. + */ + public abstract void closeHandle(int handle) throws RapiException; + + /** + * Copies an existing file on the remote device to a new file on the + * remote device. + * @param existingFile the file name of the existing file + * @param newFile the file name of the new file + * @throws RapiException if an error occurs. + */ + public abstract void copyFile(String existingFile, String newFile) + throws RapiException; + + /** + * Deletes the specified file on the remote device. + * @param fileName the file to be deleted + * @throws RapiException if an error occurs. + */ + public abstract void deleteFile(String fileName) throws RapiException; + + /** + * Renames existing file or directory on the remote device. + * @param existingFileName the existing name + * @param newFileName the new name + * @throws RapiException if an error occurs. + */ + public abstract void moveFile(String existingFileName, + String newFileName) throws RapiException; + + /** + * Creates a new directory on the remote device. + * @param pathName the path of the directory to be created + * @throws RapiException if an error occurs. + */ + public abstract void createDirectory(String pathName) throws RapiException; + + /** + * Deletes an existing empty directory on the remote device. + * @param pathName the path of the directory to be deleted + * @throws RapiException if an error occurs. + */ + public abstract void removeDirectory(String pathName) throws RapiException; + + /** + * Searches for a file or sub-directory in a directory on the remote device. + * Use {@link IRapiSession#findNextFile(int)} to get the next found file. + * Finally, call {@link IRapiSession#findClose(int)} to close the returned search handle. + * @param fileName string that specifies a valid directory or path and file name. + * This string can contain wildcard characters (* and ?) + * @param findData [out] this object receives information about the found file + * or sub-directory + * @return integer representing valid search handle + * @throws RapiException if an error occurs. + */ + public abstract int findFirstFile(String fileName, + RapiFindData findData) throws RapiException; + + /** + * Retrieves the next file in an enumeration context. + * @param handle search handle obtained with a call to + * {@link IRapiSession#findFirstFile(String, RapiFindData)} + * @return RapiFindData object containing information about the + * next file/sub-directory or null if no matching files can be found + */ + public abstract RapiFindData findNextFile(int handle); + + /** + * Closes the specified search handle on the remote device. + * @param handle the search handle to close + * @throws RapiException if an error occurs. + */ + public abstract void findClose(int handle) throws RapiException; + + /** + * Retrieves information about all files and directories in the given directory on + * the remote device. + * @param path string containing the path in which to search for files + * @param flags combination of filter and retrieval flags + * @return an array of RapiFindData objects containing the information + * about the found items + * @throws RapiException if an error occurs. + */ + public abstract RapiFindData[] findAllFiles(String path, + int flags) throws RapiException; + + /** + * Returns attributes for the specified file or directory on the remote device. + * @param fileName string that specifies the name of a file or directory + * @return attributes for the specified file or -1 + * if an error has occurred + */ + public abstract int getFileAttributes(String fileName); + + /** + * Returns the size, in bytes, of the specified file on the remote device. + * @param handle open handle of the file whose size is being returned + * @return the file size in bytes + */ + public abstract long getFileSize(int handle); + + /** + * Returns when the file was created. + * @param handle handle to the file for which to get dates and times + * @return Date object representing the date and time when + * the file was created + * @throws RapiException if an error occurs. + */ + public abstract Date getFileCreationTime(int handle) throws RapiException; + + /** + * Returns when the file was last accessed. + * @param handle handle to the file for which to get dates and times + * @return Date object representing the date and time when + * the file was last accessed + * @throws RapiException if an error occurs. + */ + public abstract Date getFileLastAccessTime(int handle) throws RapiException; + + /** + * Returns when the file was last written to. + * @param handle handle to the file for which to get dates and times + * @return Date object representing the date and time when + * the file was last written to + * @throws RapiException if an error occurs. + */ + public abstract Date getFileLastWriteTime(int handle) throws RapiException; + +} diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IUnknown.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IUnknown.java new file mode 100644 index 00000000000..1d5b0163436 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/IUnknown.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi; + +/** + * Java wrapper for the native IUnknown interface. + * + * @author Radoslav Gerganov + */ +public abstract class IUnknown { + + /** + * Pointer to the underlying IUnknown object. + */ + protected int addr; + + public IUnknown(int addr) { + this.addr = addr; + } + + /** + * Releases the underlying IUnknown object. + */ + public void release() { + OS.ReleaseIUnknown(addr); + } + +} diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/OS.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/OS.java new file mode 100644 index 00000000000..d0333d44c22 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/OS.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi; + +/** + * This class provides access to some native Win32 APIs and constants. + * + * @author Radoslav Gerganov + */ +public class OS { + + static { + System.loadLibrary("lib/os/win32/x86/jrapi"); + } + + public static final int NOERROR = 0; + //TODO: add more error codes + + public static final int GENERIC_READ = 0x80000000; + public static final int GENERIC_WRITE = 0x40000000; + public static final int FILE_SHARE_READ = 0x00000001; + public static final int FILE_SHARE_WRITE = 0x00000002; + + public static final int CREATE_NEW = 1; + public static final int CREATE_ALWAYS = 2; + public static final int OPEN_EXISTING = 3; + public static final int OPEN_ALWAYS = 4; + public static final int TRUNCATE_EXISTING = 5; + + public static final int FILE_ATTRIBUTE_ARCHIVE = 0x00000020; + public static final int FILE_ATTRIBUTE_COMPRESSED = 0x00000800; + public static final int FILE_ATTRIBUTE_DIRECTORY = 0x00000010; + public static final int FILE_ATTRIBUTE_ENCRYPTED = 0x00004000; + public static final int FILE_ATTRIBUTE_HIDDEN = 0x00000002; + public static final int FILE_ATTRIBUTE_INROM = 0x00000040; + public static final int FILE_ATTRIBUTE_NORMAL = 0x00000080; + public static final int FILE_ATTRIBUTE_READONLY = 0x00000001; + public static final int FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400; + public static final int FILE_ATTRIBUTE_ROMMODULE = 0x00002000; + public static final int FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200; + public static final int FILE_ATTRIBUTE_SYSTEM = 0x00000004; + public static final int FILE_ATTRIBUTE_TEMPORARY = 0x00000100; + + public static final int FILE_FLAG_WRITE_THROUGH = 0x80000000; + public static final int FILE_FLAG_OVERLAPPED = 0x40000000; + public static final int FILE_FLAG_RANDOM_ACCESS = 0x10000000; + public static final int FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000; + + public static final int FAF_ATTRIB_CHILDREN = 0x01000; + public static final int FAF_ATTRIB_NO_HIDDEN = 0x02000; + public static final int FAF_FOLDERS_ONLY = 0x04000; + public static final int FAF_NO_HIDDEN_SYS_ROMMODULES = 0x08000; + public static final int FAF_GETTARGET = 0x10000; + + public static final int FAF_ATTRIBUTES = 0x01; + public static final int FAF_CREATION_TIME = 0x02; + public static final int FAF_LASTACCESS_TIME = 0x04; + public static final int FAF_LASTWRITE_TIME = 0x08; + public static final int FAF_SIZE_HIGH = 0x10; + public static final int FAF_SIZE_LOW = 0x20; + public static final int FAF_OID = 0x40; + public static final int FAF_NAME = 0x80; + + public static final int INVALID_HANDLE_VALUE = -1; + + public static final long TIME_DIFF = 11644473600000L; + + public static final int COINIT_MULTITHREADED = 0x0; + public static final int COINIT_APARTMENTTHREADED = 0x2; + public static final int COINIT_DISABLE_OLE1DDE = 0x4; + public static final int COINIT_SPEED_OVER_MEMORY = 0x8; + + /** + * Initializes the COM library. + */ + public static final native int CoInitializeEx(int pvReserved, int dwCoInit); + + /** + * Closes the COM library on the current thread. + */ + public static final native void CoUninitialize(); + + final static native int CreateRapiDesktop(int[] pIRAPIDesktop); + final static native void ReleaseIUnknown(int addr); +} diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/RapiConnectionInfo.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/RapiConnectionInfo.java new file mode 100644 index 00000000000..e2ecd877678 --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/RapiConnectionInfo.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi; + +/** + * This class contains information that describes the connection between + * a WinCE device and a host computer. + * + * @author Radoslav Gerganov + */ +public class RapiConnectionInfo { + + public static final int RAPI_CONNECTION_USB = 0; + public static final int RAPI_CONNECTION_IR = 1; + public static final int RAPI_CONNECTION_SERIAL = 2; + public static final int RAPI_CONNECTION_NETWORK = 3; + + //FIXME + //SOCKADDR_STORAGE ipaddr; + //SOCKADDR_STORAGE hostIpaddr; + + public int connectionType; + + public String toString() { + switch (connectionType) { + case RAPI_CONNECTION_USB: return "USB"; + case RAPI_CONNECTION_IR: return "IR"; + case RAPI_CONNECTION_SERIAL: return "Serial"; + case RAPI_CONNECTION_NETWORK: return "Network"; + } + return "Unknown"; + } + +} diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/RapiDeviceInfo.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/RapiDeviceInfo.java new file mode 100644 index 00000000000..c280fde386a --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/RapiDeviceInfo.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi; + +/** + * This class contains information that identifies a particular WinCE device. + * + * @author Radoslav Gerganov + */ +public class RapiDeviceInfo { + + public String id; + public int versionMajor; + public int versionMinor; + public String name; + public String platform; +} diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/RapiException.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/RapiException.java new file mode 100644 index 00000000000..fadd9b713cb --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/RapiException.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi; + +/** + * Signals that an error has occurred during execution of RAPI2 call. + * + * @author Radoslav Gerganov + */ +public class RapiException extends Exception { + + private static final long serialVersionUID = -1833456445593343458L; + + private int errorCode; + + public RapiException(String msg) { + super(msg); + } + + public RapiException(String msg, int errCode) { + super(msg + " errorCode: 0x" + Integer.toHexString(errCode)); + this.errorCode = errCode; + } + + /** + * Returns the error code associated with this exception. + */ + public int getErrorCode() { + return errorCode; + } +} diff --git a/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/RapiFindData.java b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/RapiFindData.java new file mode 100644 index 00000000000..390e1968c2f --- /dev/null +++ b/wince/org.eclipse.tm.rapi/src/org/eclipse/tm/rapi/RapiFindData.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2008 Radoslav Gerganov + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Radoslav Gerganov - initial API and implementation + *******************************************************************************/ +package org.eclipse.tm.rapi; + +import java.util.Date; + +/** + * This class describes a file found by CeFindFirstFile + * or CeFindAllFiles + * + * @author Radoslav Gerganov + */ +public class RapiFindData { + public int fileAttributes; + public long creationTime; + public long lastAccessTime; + public long lastWriteTime; + public long fileSize; + public int oid; + public String fileName; + + public Date getCreationTime() { + return new Date((creationTime / 10000) - OS.TIME_DIFF); + } + + public Date getLastAccessTime() { + return new Date((lastAccessTime / 10000) - OS.TIME_DIFF); + } + + public Date getLastWriteTime() { + return new Date((lastWriteTime / 10000) - OS.TIME_DIFF); + } +}