AdaptiveCard_DeserializeFromString__SWIG_0对应的jni方法

对AdaptiveCards的分析
在source/android/adaptivecards/src/main/cpp/objectmodel_wrap.cpp

Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_AdaptiveCard_1DeserializeFromString_1_1SWIG_10

AdaptiveCardObjectModelJNI.AdaptiveCard_DeserializeFromString__SWIG_0怎么调用到的SwigDirector_BaseCardElementParser::Deserialize

AdaptiveCardObjectModelJNI.AdaptiveCard_DeserializeFromString__SWIG_0  // AdaptiveCardObjectModelJNI.java
AdaptiveCard_1DeserializeFromString_1_1SWIG_10  // objectmodel_wrap.cpp
result = AdaptiveCards::AdaptiveCard::DeserializeFromString((std::string const &)*arg1,arg2,*arg3);   // objectmodel_wrap.cpp
AdaptiveCard::Deserialize(ParseUtil::GetJsonValueFromString(jsonString), rendererVersion, context);   // SharedAdaptiveCard.cpp
AdaptiveCard::Deserialize   // SharedAdaptiveCard.cpp
ParseUtil::GetElementCollection   // SharedAdaptiveCard.cpp
auto element = parser->Deserialize(context, curJsonValue);  // ParseUtil.cpp

// BaseCardElementParser在构造的时候,jni调用就是生成SwigDirector_BaseCardElementParser
SWIGEXPORT jlong JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_new_1BaseCardElementParser(JNIEnv *jenv, jclass jcls) {
  jlong jresult = 0 ;
  AdaptiveCards::BaseCardElementParser *result = 0 ;
  
  (void)jenv;
  (void)jcls;
  result = (AdaptiveCards::BaseCardElementParser *)new SwigDirector_BaseCardElementParser(jenv);
  
  *(std::shared_ptr<  AdaptiveCards::BaseCardElementParser > **)&jresult = result ? new std::shared_ptr<  AdaptiveCards::BaseCardElementParser >(result SWIG_NO_NULL_DELETER_1) : 0;
  
  return jresult;
}

BaseCardElementParser在构造时会调用director_connect

// BaseCardElementParser.java
    public BaseCardElementParser() {
        this(AdaptiveCardObjectModelJNI.new_BaseCardElementParser(), true);
        AdaptiveCardObjectModelJNI.BaseCardElementParser_director_connect(this, this.swigCPtr, this.swigCMemOwn, true);
    }

// objectmodel_wrap.cpp
SWIGEXPORT void JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_BaseCardElementParser_1director_1connect(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jswig_mem_own, jboolean jweak_global) {
  std::shared_ptr< AdaptiveCards::BaseCardElementParser > *obj = *((std::shared_ptr< AdaptiveCards::BaseCardElementParser > **)&objarg);
  (void)jcls;
  // Keep a local instance of the smart pointer around while we are using the raw pointer
  // Avoids using smart pointer specific API.
  SwigDirector_BaseCardElementParser *director = dynamic_cast(obj->operator->());
  if (director) {
    director->swig_connect_director(jenv, jself, jenv->GetObjectClass(jself), (jswig_mem_own == JNI_TRUE), (jweak_global == JNI_TRUE));
  }
}

void SwigDirector_BaseCardElementParser::swig_connect_director(JNIEnv *jenv, jobject jself, jclass jcls, bool swig_mem_own, bool weak_global) {
  static struct {
    const char *mname;
    const char *mdesc;
    jmethodID base_methid;
  } methods[] = {
    {
      "Deserialize", "(Lio/adaptivecards/objectmodel/ParseContext;Lio/adaptivecards/objectmodel/JsonValue;)Lio/adaptivecards/objectmodel/BaseCardElement;", NULL 
    },
    {
      "DeserializeFromString", "(Lio/adaptivecards/objectmodel/ParseContext;Ljava/lang/String;)Lio/adaptivecards/objectmodel/BaseCardElement;", NULL 
    }
  };
  
  static jclass baseclass = 0 ;
  
  if (swig_set_self(jenv, jself, swig_mem_own, weak_global)) {    // 这里会调用swig_set_self进行connect,swig_self_会被赋值,但是是WeakReference.
    if (!baseclass) {
      baseclass = jenv->FindClass("io/adaptivecards/objectmodel/BaseCardElementParser");
      if (!baseclass) return;
      baseclass = (jclass) jenv->NewGlobalRef(baseclass);
    }
    bool derived = (jenv->IsSameObject(baseclass, jcls) ? false : true);
    for (int i = 0; i < 2; ++i) {
      if (!methods[i].base_methid) {
        methods[i].base_methid = jenv->GetMethodID(baseclass, methods[i].mname, methods[i].mdesc);
        if (!methods[i].base_methid) return;
      }
      swig_override[i] = derived;
    }
  }
}

swig_overrides在SwigDirector_BaseCardElementParser中进行了定义。

调用swigTakeOwnership不知道有没有帮助解决NullPointerExcecption.
BaseCardElementParser.swigTakeOwnership

你可能感兴趣的:(AdaptiveCard_DeserializeFromString__SWIG_0对应的jni方法)