Skip to content

Commit

Permalink
update async_send_response interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Sep 18, 2024
1 parent 24097e7 commit 0f885b3
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 46 deletions.
9 changes: 6 additions & 3 deletions cpp/ppc-framework/front/IFront.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,14 @@ class IFront : virtual public IFrontClient

// !!! Note: the 'payload ' type(char*) should not been changed, since it used to pass-in java
// byte[] data
virtual void async_send_response(bcos::bytes const& dstNode, std::string const& traceID,
bcos::bytes&& payload, int seq, ErrorCallback::Ptr errorCallback)
virtual void async_send_response(char* dstNode, uint64_t dstNodeSize, std::string const& traceID,
char* payload, uint64_t payloadSize, int seq, ErrorCallback::Ptr errorCallback)
{
// TODO: optimize here
bcos::bytes copiedDstNode(dstNode, dstNode + dstNodeSize);
bcos::bytes copyedPayload(payload, payload + payloadSize);
asyncSendResponse(
dstNode, traceID, std::move(payload), seq, populateErrorCallback(errorCallback));
copiedDstNode, traceID, std::move(copyedPayload), seq, populateErrorCallback(errorCallback));
}

// the sync interface for async_send_message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,21 @@ public void async_send_message(
}

public void async_send_response(
ubytes dstNode, String traceID, ubytes payload, int seq, ErrorCallback errorCallback) {
byte[] dstNode,
java.math.BigInteger dstNodeSize,
String traceID,
byte[] payload,
java.math.BigInteger payloadSize,
int seq,
ErrorCallback errorCallback) {
wedpr_java_transportJNI.IFront_async_send_response(
swigCPtr,
this,
ubytes.getCPtr(dstNode),
dstNode,
dstNodeSize,
traceID,
ubytes.swigRelease(payload),
payload,
payloadSize,
seq,
ErrorCallback.getCPtr(errorCallback),
errorCallback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public synchronized void delete() {
/**
* : receive message from gateway, call by gateway<br>
* <br>
*
* @return void
*/
public void onReceiveMessage(
Message _msg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,14 @@ public static final native void IFront_async_send_message(
public static final native void IFront_async_send_response(
long jarg1,
IFront jarg1_,
long jarg2,
ubytes jarg2_,
String jarg3,
long jarg4,
ubytes jarg4_,
int jarg5,
long jarg6,
ErrorCallback jarg6_);
byte[] jarg2,
java.math.BigInteger jarg3,
String jarg4,
byte[] jarg5,
java.math.BigInteger jarg6,
int jarg7,
long jarg8,
ErrorCallback jarg8_);

public static final native long IFront_push__SWIG_0(
long jarg1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ void asyncSendMessageByTopic(
MessageErrorCallback errorCallback,
MessageCallback msgCallback);

/**
* send response to given node
*
* @param dstNode the node that should receive the response
* @param traceID the traceID of the response
* @param payload the payload
* @param seq the seq
* @param errorCallback the error callback
*/
void asyncSendResponse(
byte[] dstNode,
String traceID,
byte[] payload,
int seq,
MessageErrorCallback errorCallback);

/** @param topic the topic to remove */
void removeTopic(String topic) throws WeDPRSDKException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ public void asyncSendMessageByTopic(
msgCallback);
}

@Override
public void asyncSendResponse(
byte[] dstNode,
String traceID,
byte[] payload,
int seq,
MessageErrorCallback errorCallback) {
this.transport
.getFront()
.async_send_response(
dstNode,
dstNode.length,
traceID,
payload,
payload.length,
seq,
errorCallback);
}

/** @param topic the topic to remove */
@Override
public void removeTopic(String topic) throws WeDPRSDKException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6080,51 +6080,104 @@ SWIGEXPORT void JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1tra
}


SWIGEXPORT void JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1transportJNI_IFront_1async_1send_1response(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_, jstring jarg3, jlong jarg4, jobject jarg4_, jint jarg5, jlong jarg6, jobject jarg6_) {
SWIGEXPORT void JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1transportJNI_IFront_1async_1send_1response(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2, jobject jarg3, jstring jarg4, jbyteArray jarg5, jobject jarg6, jint jarg7, jlong jarg8, jobject jarg8_) {
ppc::front::IFront *arg1 = (ppc::front::IFront *) 0 ;
bcos::bytes *arg2 = 0 ;
std::string *arg3 = 0 ;
bcos::bytes *arg4 = 0 ;
int arg5 ;
ppc::front::ErrorCallback::Ptr arg6 ;
char *arg2 = (char *) 0 ;
uint64_t arg3 ;
std::string *arg4 = 0 ;
char *arg5 = (char *) 0 ;
uint64_t arg6 ;
int arg7 ;
ppc::front::ErrorCallback::Ptr arg8 ;
std::shared_ptr< ppc::front::IFront > *smartarg1 = 0 ;
std::unique_ptr< bcos::bytes > rvrdeleter4 ;
ppc::front::ErrorCallback::Ptr *argp6 ;
ppc::front::ErrorCallback::Ptr *argp8 ;

(void)jenv;
(void)jcls;
(void)jarg1_;
(void)jarg2_;
(void)jarg4_;
(void)jarg6_;
(void)jarg8_;

smartarg1 = *(std::shared_ptr< ppc::front::IFront > **)&jarg1;
arg1 = (ppc::front::IFront *)(smartarg1 ? smartarg1->get() : 0);

arg2 = (bcos::bytes *)((*(std::shared_ptr< const bcos::bytes > **)&jarg2) ? (*(std::shared_ptr< const bcos::bytes > **)&jarg2)->get() : 0);
if (!arg2) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "bcos::bytes const & reference is null");
return ;
}
if(!jarg3) {
{
arg2 = (char *) jenv->GetByteArrayElements(jarg2, 0);
}
{
jclass clazz;
jmethodID mid;
jbyteArray ba;
jbyte* bae;
jsize sz;
int i;

if (!jarg3) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
return ;
}
clazz = jenv->GetObjectClass(jarg3);
mid = jenv->GetMethodID(clazz, "toByteArray", "()[B");
ba = (jbyteArray)jenv->CallObjectMethod(jarg3, mid);
bae = jenv->GetByteArrayElements(ba, 0);
sz = jenv->GetArrayLength(ba);
arg3 = 0;
if (sz > 0) {
arg3 = (uint64_t)(signed char)bae[0];
for(i=1; i<sz; i++) {
arg3 = (arg3 << 8) | (uint64_t)(unsigned char)bae[i];
}
}
jenv->ReleaseByteArrayElements(ba, bae, 0);
}
if(!jarg4) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
return ;
}
const char *arg3_pstr = (const char *)jenv->GetStringUTFChars(jarg3, 0);
if (!arg3_pstr) return ;
std::string arg3_str(arg3_pstr);
arg3 = &arg3_str;
jenv->ReleaseStringUTFChars(jarg3, arg3_pstr);
arg4 = *(bcos::bytes **)&jarg4;
if (!arg4) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "bcos::bytes && is null");
return ;
const char *arg4_pstr = (const char *)jenv->GetStringUTFChars(jarg4, 0);
if (!arg4_pstr) return ;
std::string arg4_str(arg4_pstr);
arg4 = &arg4_str;
jenv->ReleaseStringUTFChars(jarg4, arg4_pstr);
{
arg5 = (char *) jenv->GetByteArrayElements(jarg5, 0);
}
rvrdeleter4.reset(arg4);
arg5 = (int)jarg5;
argp6 = *(ppc::front::ErrorCallback::Ptr **)&jarg6;
if (argp6) arg6 = *argp6;
(arg1)->async_send_response((bcos::bytes const &)*arg2,(std::string const &)*arg3,(bcos::bytes &&)*arg4,arg5,arg6);
{
jclass clazz;
jmethodID mid;
jbyteArray ba;
jbyte* bae;
jsize sz;
int i;

if (!jarg6) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
return ;
}
clazz = jenv->GetObjectClass(jarg6);
mid = jenv->GetMethodID(clazz, "toByteArray", "()[B");
ba = (jbyteArray)jenv->CallObjectMethod(jarg6, mid);
bae = jenv->GetByteArrayElements(ba, 0);
sz = jenv->GetArrayLength(ba);
arg6 = 0;
if (sz > 0) {
arg6 = (uint64_t)(signed char)bae[0];
for(i=1; i<sz; i++) {
arg6 = (arg6 << 8) | (uint64_t)(unsigned char)bae[i];
}
}
jenv->ReleaseByteArrayElements(ba, bae, 0);
}
arg7 = (int)jarg7;
argp8 = *(ppc::front::ErrorCallback::Ptr **)&jarg8;
if (argp8) arg8 = *argp8;
(arg1)->async_send_response(arg2,arg3,(std::string const &)*arg4,arg5,arg6,arg7,arg8);
{
jenv->ReleaseByteArrayElements(jarg2, (jbyte *) arg2, 0);
}
{
jenv->ReleaseByteArrayElements(jarg5, (jbyte *) arg5, 0);
}


}


Expand Down

0 comments on commit 0f885b3

Please sign in to comment.