1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +02:00

[WinCE][api] Implement IRAPISession#CeRapiInvoke

This commit is contained in:
Radoslav Gerganov 2008-06-30 11:12:44 +00:00
parent b01d618a9c
commit dc104853d8
5 changed files with 116 additions and 5 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Radoslav Gerganov
* Copyright (c) 2008 Radoslav Gerganov 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
@ -7,6 +7,7 @@
*
* Contributors:
* Radoslav Gerganov - initial API and implementation
* Radoslav Gerganov - [238773] [WinCE] Implement IRAPISession#CeRapiInvoke
*******************************************************************************/
#include <WinSock2.h>
@ -553,4 +554,58 @@ fail:
if (arg1 && lparg1) env->ReleaseStringChars(arg1, lparg1);
if (arg2 && lparg2) env->ReleaseStringChars(arg2, lparg2);
return rc;
}
}
JNIEXPORT jint JNICALL RAPI_NATIVE(CeRapiInvoke)
(JNIEnv *env, jobject that, jint arg0, jstring arg1, jstring arg2, jbyteArray arg3, jintArray arg4)
{
const jchar *lparg1 = NULL;
const jchar *lparg2 = NULL;
jbyte *lparg3 = NULL;
jint *lparg4 = NULL;
int res = -1;
jsize cbInput = 0;
if (arg0 == 0) return -1;
if (arg1) {
lparg1 = env->GetStringChars(arg1, NULL);
if (lparg1 == NULL) goto fail;
}
if (arg2) {
lparg2 = env->GetStringChars(arg2, NULL);
if (lparg2 == NULL) goto fail;
}
if (arg3) {
lparg3 = env->GetByteArrayElements(arg3, NULL);
if (lparg3 == NULL) goto fail;
cbInput = env->GetArrayLength(arg3);
}
if (arg4) {
lparg4 = env->GetIntArrayElements(arg4, NULL);
if (lparg4 == NULL) goto fail;
}
IRAPISession *pSession = (IRAPISession*) arg0;
res = pSession->CeRapiInvoke((LPCWSTR)lparg1, (LPCWSTR)lparg2, cbInput,
(BYTE*)lparg3, (DWORD*) lparg4, (BYTE**) (lparg4 + 1), NULL, 0);
fail:
if (arg1 && lparg1) env->ReleaseStringChars(arg1, lparg1);
if (arg2 && lparg2) env->ReleaseStringChars(arg2, lparg2);
if (arg3 && lparg3) env->ReleaseByteArrayElements(arg3, lparg3, 0);
if (arg4 && lparg4) env->ReleaseIntArrayElements(arg4, lparg4, 0);
return res;
}
JNIEXPORT void JNICALL RAPI_NATIVE(CeRapiInvokeEx)
(JNIEnv *env, jobject that, jint arg0, jbyteArray arg1)
{
jbyte *lparg1 = NULL;
jsize len = 0;
if (arg1 == 0) return;
lparg1 = env->GetByteArrayElements(arg1, NULL);
if (lparg1 == NULL) return;
len = env->GetArrayLength(arg1);
memcpy(lparg1, (void*)arg0, len);
env->ReleaseByteArrayElements(arg1, lparg1, 0);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Radoslav Gerganov
* Copyright (c) 2008 Radoslav Gerganov 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
@ -7,6 +7,7 @@
*
* Contributors:
* Radoslav Gerganov - initial API and implementation
* Radoslav Gerganov - [238773] [WinCE] Implement IRAPISession#CeRapiInvoke
*******************************************************************************/
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
@ -209,6 +210,22 @@ JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeSetFi
JNIEXPORT jboolean JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeCreateProcess
(JNIEnv *, jobject, jint, jstring, jstring, jint, jobject);
/*
* Class: org_eclipse_tm_internal_rapi_RapiSession
* Method: CeRapiInvoke
* Signature: (ILjava/lang/String;Ljava/lang/String;[B[I)I
*/
JNIEXPORT jint JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeRapiInvoke
(JNIEnv *, jobject, jint, jstring, jstring, jbyteArray, jintArray);
/*
* Class: org_eclipse_tm_internal_rapi_RapiSession
* Method: CeRapiInvokeEx
* Signature: (I[B)V
*/
JNIEXPORT void JNICALL Java_org_eclipse_tm_internal_rapi_RapiSession_CeRapiInvokeEx
(JNIEnv *, jobject, jint, jbyteArray);
#ifdef __cplusplus
}
#endif

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Radoslav Gerganov
* Copyright (c) 2008 Radoslav Gerganov 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
@ -7,6 +7,7 @@
*
* Contributors:
* Radoslav Gerganov - initial API and implementation
* Radoslav Gerganov - [238773] [WinCE] Implement IRAPISession#CeRapiInvoke
*******************************************************************************/
package org.eclipse.tm.internal.rapi;
@ -275,6 +276,19 @@ public class RapiSession extends IRapiSession {
}
return pi;
}
public byte[] invoke(String dllPath, String funcName, byte[] input) throws RapiException {
int[] output = new int[2];
int res = CeRapiInvoke(addr, dllPath, funcName, input, output);
if (res != 0) {
throw new RapiException("CeRapiInvoke failed", res); //$NON-NLS-1$
}
int outputLength = output[0];
int outputPtr = output[1];
byte[] outputArr = new byte[outputLength];
CeRapiInvokeEx(outputPtr, outputArr);
return outputArr;
}
public String toString() {
return "[RapiSession] addr: " + Integer.toHexString(addr); //$NON-NLS-1$
@ -340,4 +354,12 @@ public class RapiSession extends IRapiSession {
private final native boolean CeCreateProcess(int addr, String lpApplicationName,
String lpCommandLine, int dwCreationFlags, ProcessInformation lpProcessInformation);
private final native int CeRapiInvoke(int addr, String dllPath, String funcName,
byte[] input, int[] output);
/**
* Initializes the outputArr with the memory pointed by outputPtr.
*/
private final native void CeRapiInvokeEx(int outputPtr, byte[] outputArr);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Radoslav Gerganov
* Copyright (c) 2008 Radoslav Gerganov 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
@ -7,6 +7,7 @@
*
* Contributors:
* Radoslav Gerganov - initial API and implementation
* Radoslav Gerganov - [238773] [WinCE] Implement IRAPISession#CeRapiInvoke
*******************************************************************************/
package org.eclipse.tm.rapi;
@ -277,4 +278,20 @@ public abstract class IRapiSession extends IUnknown {
*/
public abstract ProcessInformation createProcess(String appName, String commandLine,
int creationFlags) throws RapiException;
/**
* Invokes the specified native function on the remote device passing the specified byte array as argument.
* The native function must have the following signature:<p>
* <code>HRESULT funcName(DWORD inpLen, BYTE *inp, DWORD *outLen, BYTE **out, IRAPIStream *stream)</code><p>
* The native function must return <code>0</code> on success or non-zero value if an error occurs.
* @param dllPath the name of the dll on the remote device which contains the native function
* @param funcName the name of the native function that will be called
* @param input byte array which will be passed to the native function; <code>inpLen</code> is initialized with
* the length of <code>input</code> and <code>inp</code> points to a buffer with the same content as
* <code>input</code>
* @return byte array returned from the native function; the length and the content of the returned array
* corresponds to <code>*outLen</code> and <code>*out</code> respectively
* @throws RapiException if an error occurs.
*/
public abstract byte[] invoke(String dllPath, String funcName, byte[] input) throws RapiException;
}