mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-19 14:15:50 +02:00
[cleanup] rapi compiler warning: fix dbl ;;
This commit is contained in:
parent
84c76ab739
commit
85233305ba
1 changed files with 196 additions and 196 deletions
|
@ -27,200 +27,200 @@ import org.eclipse.tm.rapi.RapiFindData;
|
||||||
*/
|
*/
|
||||||
public class RapiExamples {
|
public class RapiExamples {
|
||||||
|
|
||||||
IRapiDesktop desktop = null;
|
IRapiDesktop desktop = null;
|
||||||
IRapiEnumDevices enumDevices = null;
|
IRapiEnumDevices enumDevices = null;
|
||||||
IRapiDevice device = null;
|
IRapiDevice device = null;
|
||||||
IRapiSession session = null;
|
IRapiSession session = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the underlying natives.
|
* Initialize the underlying natives.
|
||||||
*/
|
*/
|
||||||
public void initRapi() {
|
public void initRapi() {
|
||||||
OS.CoInitializeEx(0, OS.COINIT_MULTITHREADED);
|
OS.CoInitializeEx(0, OS.COINIT_MULTITHREADED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uninitialize the underlying natives.
|
* Uninitialize the underlying natives.
|
||||||
*/
|
*/
|
||||||
public void uninitRapi() {
|
public void uninitRapi() {
|
||||||
if (desktop != null) {
|
if (desktop != null) {
|
||||||
desktop.release();
|
desktop.release();
|
||||||
}
|
}
|
||||||
if (enumDevices != null) {
|
if (enumDevices != null) {
|
||||||
enumDevices.release();
|
enumDevices.release();
|
||||||
}
|
}
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
device.release();
|
device.release();
|
||||||
}
|
}
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
session.release();
|
session.release();
|
||||||
}
|
}
|
||||||
OS.CoUninitialize();
|
OS.CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints various information about the device.
|
* Prints various information about the device.
|
||||||
*/
|
*/
|
||||||
public void printDeviceInfo() throws RapiException {
|
public void printDeviceInfo() throws RapiException {
|
||||||
System.out.println(">>> printDeviceInfo()");
|
System.out.println(">>> printDeviceInfo()");
|
||||||
RapiDeviceInfo deviceInfo = device.getDeviceInfo();
|
RapiDeviceInfo deviceInfo = device.getDeviceInfo();
|
||||||
System.out.println("Device id: " + deviceInfo.id);
|
System.out.println("Device id: " + deviceInfo.id);
|
||||||
System.out.println("Device name: " + deviceInfo.name);
|
System.out.println("Device name: " + deviceInfo.name);
|
||||||
System.out.println("Platform: " + deviceInfo.platform);
|
System.out.println("Platform: " + deviceInfo.platform);
|
||||||
System.out.println("Major version: " + deviceInfo.versionMajor);
|
System.out.println("Major version: " + deviceInfo.versionMajor);
|
||||||
System.out.println("Minor version: " + deviceInfo.versionMinor);
|
System.out.println("Minor version: " + deviceInfo.versionMinor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints information about how the device is connected.
|
* Prints information about how the device is connected.
|
||||||
*/
|
*/
|
||||||
public void printConnectionInfo() throws RapiException {
|
public void printConnectionInfo() throws RapiException {
|
||||||
System.out.println(">>> printConnectionInfo()");
|
System.out.println(">>> printConnectionInfo()");
|
||||||
RapiConnectionInfo connectionInfo = device.getConnectionInfo();
|
RapiConnectionInfo connectionInfo = device.getConnectionInfo();
|
||||||
System.out.println("Connection type: " + connectionInfo);
|
System.out.println("Connection type: " + connectionInfo);
|
||||||
System.out.println("IsConnected: " + device.isConnected());
|
System.out.println("IsConnected: " + device.isConnected());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates file on the device with the specified filename.
|
* Creates file on the device with the specified filename.
|
||||||
*/
|
*/
|
||||||
public void createFile(String fileName) throws RapiException {
|
public void createFile(String fileName) throws RapiException {
|
||||||
System.out.println(">>> createFile()");
|
System.out.println(">>> createFile()");
|
||||||
int handle = session.createFile(fileName, OS.GENERIC_WRITE,
|
int handle = session.createFile(fileName, OS.GENERIC_WRITE,
|
||||||
OS.FILE_SHARE_READ, OS.CREATE_ALWAYS, OS.FILE_ATTRIBUTE_NORMAL);
|
OS.FILE_SHARE_READ, OS.CREATE_ALWAYS, OS.FILE_ATTRIBUTE_NORMAL);
|
||||||
byte[] content = "Hello world!".getBytes();
|
byte[] content = "Hello world!".getBytes();
|
||||||
session.writeFile(handle, content);
|
session.writeFile(handle, content);
|
||||||
session.closeHandle(handle);
|
session.closeHandle(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the specified file on the device and prints its content.
|
* Reads the specified file on the device and prints its content.
|
||||||
*/
|
*/
|
||||||
public void readFile(String fileName) throws RapiException {
|
public void readFile(String fileName) throws RapiException {
|
||||||
System.out.println(">>> readFile()");
|
System.out.println(">>> readFile()");
|
||||||
int handle = session.createFile(fileName, OS.GENERIC_READ,
|
int handle = session.createFile(fileName, OS.GENERIC_READ,
|
||||||
OS.FILE_SHARE_READ, OS.OPEN_EXISTING, OS.FILE_ATTRIBUTE_NORMAL);
|
OS.FILE_SHARE_READ, OS.OPEN_EXISTING, OS.FILE_ATTRIBUTE_NORMAL);
|
||||||
byte[] buf = new byte[256];
|
byte[] buf = new byte[256];
|
||||||
int br = session.readFile(handle, buf);
|
int br = session.readFile(handle, buf);
|
||||||
System.out.println("readFile: " + new String(buf, 0, br));
|
System.out.println("readFile: " + new String(buf, 0, br));
|
||||||
System.out.println("bytesRead: " + br);
|
System.out.println("bytesRead: " + br);
|
||||||
session.closeHandle(handle);
|
session.closeHandle(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method used to determine if the specified <code>RapiFindData</code>
|
* Utility method used to determine if the specified <code>RapiFindData</code>
|
||||||
* describes a directory.
|
* describes a directory.
|
||||||
*/
|
*/
|
||||||
boolean isDirectory(RapiFindData findData) {
|
boolean isDirectory(RapiFindData findData) {
|
||||||
return (findData.fileAttributes & OS.FILE_ATTRIBUTE_DIRECTORY) != 0;
|
return (findData.fileAttributes & OS.FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method used for printing <code>RapiFindData</code> on the console.
|
* Utility method used for printing <code>RapiFindData</code> on the console.
|
||||||
*/
|
*/
|
||||||
void printFindData(RapiFindData findData, int indent) {
|
void printFindData(RapiFindData findData, int indent) {
|
||||||
for (int i = 0 ; i < indent ; i++) {
|
for (int i = 0 ; i < indent ; i++) {
|
||||||
System.out.print(" ");
|
System.out.print(" ");
|
||||||
}
|
}
|
||||||
String fileName = findData.fileName;
|
String fileName = findData.fileName;
|
||||||
if (isDirectory(findData)) {
|
if (isDirectory(findData)) {
|
||||||
System.out.println("[" + fileName + "]");
|
System.out.println("[" + fileName + "]");
|
||||||
} else {
|
} else {
|
||||||
System.out.println(fileName + " (" + findData.fileSize + ")");
|
System.out.println(fileName + " (" + findData.fileSize + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all files in the specified directory using
|
* List all files in the specified directory using
|
||||||
* <code>IRapiSession.findFirstFile</code> and
|
* <code>IRapiSession.findFirstFile</code> and
|
||||||
* <code>IRapiSession.findNextFile</code>
|
* <code>IRapiSession.findNextFile</code>
|
||||||
*/
|
*/
|
||||||
public void listFiles(String dir) throws RapiException {
|
public void listFiles(String dir) throws RapiException {
|
||||||
System.out.println(">>> listFiles()");
|
System.out.println(">>> listFiles()");
|
||||||
RapiFindData findData = new RapiFindData();;
|
RapiFindData findData = new RapiFindData();
|
||||||
int fh = session.findFirstFile(dir + "*", findData);
|
int fh = session.findFirstFile(dir + "*", findData);
|
||||||
while (findData != null) {
|
while (findData != null) {
|
||||||
printFindData(findData, 0);
|
printFindData(findData, 0);
|
||||||
findData = session.findNextFile(fh);
|
findData = session.findNextFile(fh);
|
||||||
}
|
}
|
||||||
session.findClose(fh);
|
session.findClose(fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all files in the specified directory using
|
* List all files in the specified directory using
|
||||||
* <code>IRapiSession.findAllFiles</code>
|
* <code>IRapiSession.findAllFiles</code>
|
||||||
*/
|
*/
|
||||||
public void listFiles2(String dir) throws RapiException {
|
public void listFiles2(String dir) throws RapiException {
|
||||||
System.out.println(">>> listFiles2()");
|
System.out.println(">>> listFiles2()");
|
||||||
RapiFindData[] fdArr = session.findAllFiles(dir + "*",
|
RapiFindData[] fdArr = session.findAllFiles(dir + "*",
|
||||||
OS.FAF_ATTRIBUTES | OS.FAF_NAME | OS.FAF_SIZE_LOW);
|
OS.FAF_ATTRIBUTES | OS.FAF_NAME | OS.FAF_SIZE_LOW);
|
||||||
for (int i = 0 ; i < fdArr.length ; i++) {
|
for (int i = 0 ; i < fdArr.length ; i++) {
|
||||||
printFindData(fdArr[i], 0);
|
printFindData(fdArr[i], 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints various information about the specified file.
|
* Prints various information about the specified file.
|
||||||
*/
|
*/
|
||||||
public void statFile(String fileName) throws RapiException {
|
public void statFile(String fileName) throws RapiException {
|
||||||
System.out.println(">>> statFile()");
|
System.out.println(">>> statFile()");
|
||||||
int handle = session.createFile(fileName, OS.GENERIC_READ,
|
int handle = session.createFile(fileName, OS.GENERIC_READ,
|
||||||
OS.FILE_SHARE_READ, OS.OPEN_EXISTING, OS.FILE_ATTRIBUTE_NORMAL);
|
OS.FILE_SHARE_READ, OS.OPEN_EXISTING, OS.FILE_ATTRIBUTE_NORMAL);
|
||||||
int fileAttributes = session.getFileAttributes(fileName);
|
int fileAttributes = session.getFileAttributes(fileName);
|
||||||
System.out.println("fileAttributes: " + fileAttributes);
|
System.out.println("fileAttributes: " + fileAttributes);
|
||||||
long fileSize = session.getFileSize(handle);
|
long fileSize = session.getFileSize(handle);
|
||||||
System.out.println("fileSize: " + fileSize);
|
System.out.println("fileSize: " + fileSize);
|
||||||
System.out.println("creationTime: " + session.getFileCreationTime(handle));
|
System.out.println("creationTime: " + session.getFileCreationTime(handle));
|
||||||
System.out.println("lastAccessTime: " + session.getFileLastAccessTime(handle));
|
System.out.println("lastAccessTime: " + session.getFileLastAccessTime(handle));
|
||||||
System.out.println("lastWriteTime: " + session.getFileLastWriteTime(handle));
|
System.out.println("lastWriteTime: " + session.getFileLastWriteTime(handle));
|
||||||
session.closeHandle(handle);
|
session.closeHandle(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively print the whole device tree on the console.
|
* Recursively print the whole device tree on the console.
|
||||||
*/
|
*/
|
||||||
void printDeviceTree(String dir, int indent) throws RapiException {
|
void printDeviceTree(String dir, int indent) throws RapiException {
|
||||||
RapiFindData[] fdArr = session.findAllFiles(dir + "*",
|
RapiFindData[] fdArr = session.findAllFiles(dir + "*",
|
||||||
OS.FAF_ATTRIBUTES | OS.FAF_NAME | OS.FAF_SIZE_LOW);
|
OS.FAF_ATTRIBUTES | OS.FAF_NAME | OS.FAF_SIZE_LOW);
|
||||||
if (fdArr == null) {
|
if (fdArr == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0 ; i < fdArr.length ; i++) {
|
for (int i = 0 ; i < fdArr.length ; i++) {
|
||||||
if (isDirectory(fdArr[i])) {
|
if (isDirectory(fdArr[i])) {
|
||||||
printDeviceTree(dir + fdArr[i].fileName + "\\", indent + 1);
|
printDeviceTree(dir + fdArr[i].fileName + "\\", indent + 1);
|
||||||
} else {
|
} else {
|
||||||
printFindData(fdArr[i], indent);
|
printFindData(fdArr[i], indent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void runExamples() {
|
void runExamples() {
|
||||||
try {
|
try {
|
||||||
initRapi();
|
initRapi();
|
||||||
desktop = IRapiDesktop.getInstance();
|
desktop = IRapiDesktop.getInstance();
|
||||||
enumDevices = desktop.enumDevices();
|
enumDevices = desktop.enumDevices();
|
||||||
// get the first device
|
// get the first device
|
||||||
device = enumDevices.next();
|
device = enumDevices.next();
|
||||||
printDeviceInfo();
|
printDeviceInfo();
|
||||||
printConnectionInfo();
|
printConnectionInfo();
|
||||||
// create session
|
// create session
|
||||||
session = device.createSession();
|
session = device.createSession();
|
||||||
session.init();
|
session.init();
|
||||||
createFile("\\foo.txt");
|
createFile("\\foo.txt");
|
||||||
readFile("\\foo.txt");
|
readFile("\\foo.txt");
|
||||||
session.copyFile("\\foo.txt", "\\bar.txt");
|
session.copyFile("\\foo.txt", "\\bar.txt");
|
||||||
listFiles("\\");
|
listFiles("\\");
|
||||||
session.moveFile("\\bar.txt", "\\spam.txt");
|
session.moveFile("\\bar.txt", "\\spam.txt");
|
||||||
listFiles2("\\");
|
listFiles2("\\");
|
||||||
session.deleteFile("\\spam.txt");
|
session.deleteFile("\\spam.txt");
|
||||||
statFile("\\foo.txt");
|
statFile("\\foo.txt");
|
||||||
System.out.println(">>> printDeviceTree()");
|
System.out.println(">>> printDeviceTree()");
|
||||||
printDeviceTree("\\", 0);
|
printDeviceTree("\\", 0);
|
||||||
session.uninit();
|
session.uninit();
|
||||||
} catch (RapiException e) {
|
} catch (RapiException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
uninitRapi();
|
uninitRapi();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue