Skip to content

Commit

Permalink
implement wedpr-python-gateway-sdk (#48)
Browse files Browse the repository at this point in the history
* implement wedpr-python-gateway-sdk

* add generated cxx file
  • Loading branch information
cyjseagull authored Sep 29, 2024
1 parent aa82d55 commit acb9355
Show file tree
Hide file tree
Showing 30 changed files with 25,898 additions and 36 deletions.
6 changes: 5 additions & 1 deletion cpp/ppc-framework/front/IFront.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ class IFront : virtual public IFrontClient
long timeout) = 0;

// TODO: optmize here
virtual bcos::Error::Ptr push(uint16_t routeType,
// Note: the python not support function overload, for different interfaces with the same
// functionality, it is best to define methods with different names the 'payload', 'payloadSize'
// should not been changed any more, since the swig has defined by the name to convert python
// bytes to cpp (char*, uint64_t) %pybuffer_binary(char* payload, uint64_t payloadSize)
virtual bcos::Error::Ptr push_msg(uint16_t routeType,
ppc::protocol::MessageOptionalHeader::Ptr const& routeInfo, char* payload,
uint64_t payloadSize, int seq, long timeout)
{
Expand Down
6 changes: 5 additions & 1 deletion cpp/ppc-framework/protocol/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ class MessageOptionalHeader

// !!! Note: the first paramater type(char*) should not been changed, for it's used for pass-in
// java byte[] into c bytes
virtual void setDstNode(char* data, uint64_t length) { m_dstNode.assign(data, data + length); }
// Note: the python not support function override
virtual void setDstNodeBuffer(char* data, uint64_t length)
{
m_dstNode.assign(data, data + length);
}

// the target agency that need receive the message
virtual std::string const& dstInst() const { return m_dstInst; }
Expand Down
1 change: 1 addition & 0 deletions cpp/wedpr-protocol/protocol/src/v1/MessagePayloadImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ int64_t MessagePayloadImpl::decode(bcos::bytesConstRef buffer)
BOOST_THROW_EXCEPTION(
WeDPRException() << errinfo_comment("Malform payload for too small!"));
}
m_length = buffer.size();
auto pointer = buffer.data();
// the version
m_version = boost::asio::detail::socket_ops::network_to_host_short(*((uint16_t*)pointer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void async_send_response(
public Error push(
int routeType, MessageOptionalHeader routeInfo, ubytes payload, int seq, int timeout) {
long cPtr =
wedpr_java_transportJNI.IFront_push__SWIG_0(
wedpr_java_transportJNI.IFront_push(
swigCPtr,
this,
routeType,
Expand All @@ -135,15 +135,15 @@ public Error push(
return (cPtr == 0) ? null : new Error(cPtr, true);
}

public Error push(
public Error push_msg(
int routeType,
MessageOptionalHeader routeInfo,
byte[] payload,
java.math.BigInteger payloadSize,
int seq,
int timeout) {
long cPtr =
wedpr_java_transportJNI.IFront_push__SWIG_1(
wedpr_java_transportJNI.IFront_push_msg(
swigCPtr,
this,
routeType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ public byte[] dstNodeBuffer() {
}

public void setDstNode(ubytes dstNode) {
wedpr_java_transportJNI.MessageOptionalHeader_setDstNode__SWIG_0(
wedpr_java_transportJNI.MessageOptionalHeader_setDstNode(
swigCPtr, this, ubytes.getCPtr(dstNode), dstNode);
}

public void setDstNode(byte[] data, java.math.BigInteger length) {
wedpr_java_transportJNI.MessageOptionalHeader_setDstNode__SWIG_1(
public void setDstNodeBuffer(byte[] data, java.math.BigInteger length) {
wedpr_java_transportJNI.MessageOptionalHeader_setDstNodeBuffer(
swigCPtr, this, data, length);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ public static final native long MessageOptionalHeader_dstNode(
public static final native byte[] MessageOptionalHeader_dstNodeBuffer(
long jarg1, MessageOptionalHeader jarg1_);

public static final native void MessageOptionalHeader_setDstNode__SWIG_0(
public static final native void MessageOptionalHeader_setDstNode(
long jarg1, MessageOptionalHeader jarg1_, long jarg2, ubytes jarg2_);

public static final native void MessageOptionalHeader_setDstNode__SWIG_1(
public static final native void MessageOptionalHeader_setDstNodeBuffer(
long jarg1, MessageOptionalHeader jarg1_, byte[] jarg2, java.math.BigInteger jarg3);

public static final native String MessageOptionalHeader_dstInst(
Expand Down Expand Up @@ -703,7 +703,7 @@ public static final native void IFront_async_send_response(
long jarg8,
ErrorCallback jarg8_);

public static final native long IFront_push__SWIG_0(
public static final native long IFront_push(
long jarg1,
IFront jarg1_,
int jarg2,
Expand All @@ -714,7 +714,7 @@ public static final native long IFront_push__SWIG_0(
int jarg5,
int jarg6);

public static final native long IFront_push__SWIG_1(
public static final native long IFront_push_msg(
long jarg1,
IFront jarg1_,
int jarg2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void asyncSendMessageByNodeID(
MessageCallback msgCallback) {
MessageOptionalHeader routeInfo =
IMessageBuilder.buildRouteInfo(this.transport.routeInfoBuilder(), topic);
routeInfo.setDstNode(dstNode, BigInteger.valueOf(dstNode.length));
routeInfo.setDstNodeBuffer(dstNode, BigInteger.valueOf(dstNode.length));
this.transport
.getFront()
.async_send_message(
Expand Down Expand Up @@ -302,11 +302,11 @@ public void pushByNodeID(String topic, byte[] dstNodeID, int seq, byte[] payload
throws WeDPRSDKException {
MessageOptionalHeader routeInfo =
IMessageBuilder.buildRouteInfo(this.transport.routeInfoBuilder(), topic);
routeInfo.setDstNode(dstNodeID, BigInteger.valueOf(dstNodeID.length));
routeInfo.setDstNodeBuffer(dstNodeID, BigInteger.valueOf(dstNodeID.length));
Error result =
this.transport
.getFront()
.push(
.push_msg(
RouteType.ROUTE_THROUGH_NODEID.ordinal(),
routeInfo,
payload,
Expand All @@ -327,7 +327,7 @@ public void pushByComponent(
Error result =
this.transport
.getFront()
.push(
.push_msg(
RouteType.ROUTE_THROUGH_COMPONENT.ordinal(),
routeInfo,
payload,
Expand All @@ -346,7 +346,7 @@ public void pushByInst(String topic, String dstInst, int seq, byte[] payload, in
Error result =
this.transport
.getFront()
.push(
.push_msg(
RouteType.ROUTE_THROUGH_TOPIC.ordinal(),
routeInfo,
payload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3935,7 +3935,7 @@ SWIGEXPORT jbyteArray JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1jav
}


SWIGEXPORT void JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1transportJNI_MessageOptionalHeader_1setDstNode_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
SWIGEXPORT void JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1transportJNI_MessageOptionalHeader_1setDstNode(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
ppc::protocol::MessageOptionalHeader *arg1 = (ppc::protocol::MessageOptionalHeader *) 0 ;
bcos::bytes *arg2 = 0 ;
std::shared_ptr< ppc::protocol::MessageOptionalHeader > *smartarg1 = 0 ;
Expand All @@ -3957,7 +3957,7 @@ 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_MessageOptionalHeader_1setDstNode_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2, jobject jarg3) {
SWIGEXPORT void JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1transportJNI_MessageOptionalHeader_1setDstNodeBuffer(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2, jobject jarg3) {
ppc::protocol::MessageOptionalHeader *arg1 = (ppc::protocol::MessageOptionalHeader *) 0 ;
char *arg2 = (char *) 0 ;
uint64_t arg3 ;
Expand Down Expand Up @@ -3998,7 +3998,7 @@ SWIGEXPORT void JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1tra
}
jenv->ReleaseByteArrayElements(ba, bae, 0);
}
(arg1)->setDstNode(arg2,arg3);
(arg1)->setDstNodeBuffer(arg2,arg3);
{
jenv->ReleaseByteArrayElements(jarg2, (jbyte *) arg2, 0);
}
Expand Down Expand Up @@ -6393,7 +6393,7 @@ SWIGEXPORT void JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1tra
}


SWIGEXPORT jlong JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1transportJNI_IFront_1push_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2, jlong jarg3, jobject jarg3_, jlong jarg4, jobject jarg4_, jint jarg5, jint jarg6) {
SWIGEXPORT jlong JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1transportJNI_IFront_1push(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2, jlong jarg3, jobject jarg3_, jlong jarg4, jobject jarg4_, jint jarg5, jint jarg6) {
jlong jresult = 0 ;
ppc::front::IFront *arg1 = (ppc::front::IFront *) 0 ;
uint16_t arg2 ;
Expand Down Expand Up @@ -6430,7 +6430,7 @@ SWIGEXPORT jlong JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1tr
}


SWIGEXPORT jlong JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1transportJNI_IFront_1push_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2, jlong jarg3, jobject jarg3_, jbyteArray jarg4, jobject jarg5, jint jarg6, jint jarg7) {
SWIGEXPORT jlong JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1transportJNI_IFront_1push_1msg(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2, jlong jarg3, jobject jarg3_, jbyteArray jarg4, jobject jarg5, jint jarg6, jint jarg7) {
jlong jresult = 0 ;
ppc::front::IFront *arg1 = (ppc::front::IFront *) 0 ;
uint16_t arg2 ;
Expand Down Expand Up @@ -6483,7 +6483,7 @@ SWIGEXPORT jlong JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1tr
}
arg6 = (int)jarg6;
arg7 = (long)jarg7;
result = (arg1)->push(arg2,(ppc::protocol::MessageOptionalHeader::Ptr const &)*arg3,arg4,arg5,arg6,arg7);
result = (arg1)->push_msg(arg2,(ppc::protocol::MessageOptionalHeader::Ptr const &)*arg3,arg4,arg5,arg6,arg7);
*(bcos::Error::Ptr **)&jresult = result ? new bcos::Error::Ptr(result) : 0;
{
jenv->ReleaseByteArrayElements(jarg4, (jbyte *) arg4, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.0.0"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
import shutil
import pkg_resources
from utils.lib_loader import LibLoader


def __bootstrap__():
global __bootstrap__, __loader__, __file__
import sys
import pkg_resources
import imp
__file__ = pkg_resources.resource_filename(
__name__, LibLoader.get_lib_name())
__loader__ = None
del __bootstrap__, __loader__
imp.load_dynamic(__name__, __file__)


__bootstrap__()
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-

from abc import ABC, abstractmethod


class MessageHeaderAPI(ABC):
@abstractmethod
def get_version(self) -> str:
pass

@abstractmethod
def get_trace_id(self) -> str:
pass

@abstractmethod
def get_src_gw_node(self) -> str:
pass

@abstractmethod
def get_dst_gw_node(self) -> str:
pass

@abstractmethod
def get_packet_type(self) -> int:
pass

@abstractmethod
def get_ttl(self) -> int:
pass

@abstractmethod
def get_ext(self) -> int:
pass

@abstractmethod
def is_resp_packet(self) -> bool:
pass

@abstractmethod
def get_route_type(self) -> int:
pass

@abstractmethod
def get_component_type(self) -> str:
pass

@abstractmethod
def get_src_node(self) -> bytes:
pass

@abstractmethod
def get_dst_node(self) -> bytes:
pass

@abstractmethod
def get_dst_inst(self) -> str:
pass

@abstractmethod
def get_src_inst(self) -> str:
pass

@abstractmethod
def get_topic(self) -> str:
pass


class MessageAPI(ABC):

@abstractmethod
def get_header(self) -> MessageHeaderAPI:
pass

@abstractmethod
def get_seq(self) -> int:
pass

@abstractmethod
def get_payload(self) -> bytes:
pass

@abstractmethod
def get_length(self) -> int:
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-

from abc import ABC, abstractmethod
from transport.api.message_api import MessageAPI


class TransportAPI(ABC):
@abstractmethod
def start(self):
pass

@abstractmethod
def stop(self):
pass

@abstractmethod
def push_by_nodeid(topic: str, dstNode: bytes, seq: int, payload: bytes, timeout: int):
pass

@abstractmethod
def push_by_inst(topic: str, dstInst: str, seq: int, payload: bytes, timeout: int):
pass

@abstractmethod
def push_by_component(topic: str, dstInst: str, component: str, seq: int, payload: bytes, timeout: int):
pass

@abstractmethod
def pop(self, topic, timeoutMs) -> MessageAPI:
pass

@abstractmethod
def peek(self, topic) -> MessageAPI:
pass

@abstractmethod
def register_topic(self, topic):
pass

@abstractmethod
def unregister_topic(self, topic):
pass

@abstractmethod
def register_component(self, component):
pass

@abstractmethod
def unregister_component(self, component):
pass
Empty file.
Loading

0 comments on commit acb9355

Please sign in to comment.