本文整理汇总了C++中JNIContext类的典型用法代码示例。如果您正苦于以下问题:C++ JNIContext类的具体用法?C++ JNIContext怎么用?C++ JNIContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JNIContext类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LOGV
void CXXContext::deregisterProxyComponent(long contextAddress)
{
LOGV("deregisterProxyComponent contextAddress %ld", contextAddress);
JNIContext *jniContext = JNIContext::sharedInstance();
pthread_mutex_lock(&proxyComponentMapMutex);
proxyComponentMap[contextAddress] = 0;
std::map<long,jobject>::const_iterator iter;
for (iter = proxyComponentMap.begin(); iter != proxyComponentMap.end(); iter++)
{
if ((*iter).first == contextAddress)
{
jobject externalObject = (jobject) (*iter).second;
LOGV("deregisterProxyComponent erasing contextAddress %ld", contextAddress);
proxyComponentMap.erase(contextAddress);
proxyComponentRefCountMap[externalObject]--;
if (proxyComponentRefCountMap[externalObject] <= 0)
{
proxyComponentRefCountMap.erase(externalObject);
jniContext->deleteGlobalRef(externalObject);
}
break;
}
}
pthread_mutex_unlock(&proxyComponentMapMutex);
}
示例2:
CXXContext::~CXXContext()
{
JNIContext *jniContext = JNIContext::sharedInstance();
ectx_method_createProxiedCallback = 0;
if (ectx_class != 0)
{
jniContext->deleteGlobalRef(ectx_class);
ectx_class = 0;
}
if (ectx_object != 0)
{
jniContext->deleteGlobalRef(ectx_object);
ectx_object = 0;
}
if (actx_object != 0)
{
jniContext->deleteGlobalRef(actx_object);
actx_object = 0;
}
sm_sharedInstance = 0;
}
示例3: createProxiedComponent
jobject createProxiedComponent(long contextAddress, const char *externalClassName, jmethodID methodID, jvalue *args)
{
LOGV("createProxiedComponent contextAddress %ld proxiedClass %s using args %ld", contextAddress, externalClassName, (long) args);
JNIContext *jni = JNIContext::sharedInstance();
jclass clazz = jni->getClassRef(externalClassName);
jobject object = jni->createNewObject(clazz, methodID, args);
jni->deleteLocalRef(clazz);
return object;
}
示例4: pthread_mutex_lock
int CXXContext::createCXXContext(JavaVM *vm, jobject applicationContext)
{
pthread_mutex_lock(&mutex);
if (sm_sharedInstance == 0)
{
JNIEnv* env = 0;
if (vm->GetEnv(reinterpret_cast<void**>(&env), CXX_JNI_VERSION) != JNI_OK)
{
LOGW("Java VM failed to initialize");
pthread_mutex_unlock(&mutex);
return CXX_ERR;
}
JNIContext::createContext(vm);
JNIContext *jni = JNIContext::sharedInstance();
jobject cxxJavaContext = jni->invokeStaticObjectMethod("com/zynga/sdk/cxx/CXXContext", "getInstance", "()Lcom/zynga/sdk/cxx/CXXContext;");
new CXXContext(applicationContext, cxxJavaContext);
}
pthread_mutex_unlock(&mutex);
return CXX_OK;
}
示例5: convert__byte_array
void convert__byte_array(long& java_value, long& cxx_value, const CXXTypeHierarchy cxx_type_hierarchy, const converter_t& converter_type, std::stack<long>& converter_stack)
{
JNIContext *jni = JNIContext::sharedInstance();
if (converter_type == CONVERT_TO_JAVA)
{
jni->pushLocalFrame();
cxx_converter item_converter = get_converter(converter_stack);
std::vector<byte> *cxx_vector = (std::vector<byte> *) cxx_value;
int count = cxx_vector->size();
char java_array[count];
int item_idx = 0;
for(std::vector<byte>::iterator it = cxx_vector->begin(); it != cxx_vector->end(); ++it)
{
byte item = (byte) *it;
java_array[item_idx++] = item;
}
java_value = (long) jni->createByteArray(*java_array, count);
java_value = (long) jni->popLocalFrame((jobject) java_value);
}
else if (converter_type == CONVERT_TO_CXX)
{
jni->pushLocalFrame();
cxx_converter item_converter = get_converter(converter_stack);
std::vector<byte> *cxx_vector = new std::vector<byte>();
int count = (int) jni->getArrayLength((jarray) java_value);
char * java_array = jni->getByteArray((jbyteArray) java_value);
for (int idx = 0 ; idx < count; idx++)
{
char item = (char) java_array[idx];
cxx_vector->push_back((byte) item);
}
cxx_value = (long) cxx_vector;
jni->popLocalFrame();
}
log("convert__byte_array exit");
}
示例6: convert__object_array_type
void convert__object_array_type(long& java_value, long& cxx_value, const CXXTypeHierarchy cxx_type_hierarchy, const converter_t& converter_type, std::stack<long>& converter_stack)
{
JNIContext *jni = JNIContext::sharedInstance();
if (converter_type == CONVERT_TO_JAVA)
{
jni->pushLocalFrame();
cxx_converter item_converter = get_converter(converter_stack);
std::vector<long> *cxx_vector = (std::vector<long> *) cxx_value;
int count = cxx_vector->size();
std::string child_type = jni->getJNIName( std::string("java.lang.Object") );
CXXTypeHierarchy item_type;
item_type.type_name = child_type;
std::vector<CXXTypeHierarchy> child_types = cxx_type_hierarchy.child_types;
if (child_types.size() > 0)
{
item_type = child_types.at(0);
child_type = jni->getJNIName( item_type.type_name );
}
java_value = (long) jni->createObjectArray(count, jni->getClassRef( child_type.c_str() ));
for(std::vector<long>::iterator it = cxx_vector->begin(); it != cxx_vector->end(); ++it)
{
long cxx_item_ptr = (long) *it;
long java_item_ptr = 0;
int item_idx = it - cxx_vector->begin();
item_converter(java_item_ptr, cxx_item_ptr, item_type, converter_type, converter_stack);
jni->setObjectArrayElement((jobjectArray) java_value, item_idx, (jobject) java_item_ptr);
}
java_value = (long) jni->popLocalFrame((jobject) java_value);
}
else if (converter_type == CONVERT_TO_CXX)
{
jni->pushLocalFrame();
std::string child_type = jni->getJNIName( std::string("java.lang.Object") );
CXXTypeHierarchy item_type;
item_type.type_name = child_type;
std::vector<CXXTypeHierarchy> child_types = cxx_type_hierarchy.child_types;
if (child_types.size() > 0)
{
item_type = child_types.at(0);
child_type = jni->getJNIName( item_type.type_name );
}
cxx_converter item_converter = get_converter(converter_stack);
std::vector<long> *cxx_vector = (std::vector<long> *) cxx_value;
int size = (int) jni->getArrayLength((jobjectArray) java_value);
for (int idx = 0 ; idx < size; idx++)
{
long java_item_ptr = (long) jni->getObjectArrayElement((jobjectArray) java_value, idx);
long cxx_item_ptr = 0;
item_converter(java_item_ptr, cxx_item_ptr, item_type, converter_type, converter_stack);
cxx_vector->push_back(cxx_item_ptr);
}
jni->popLocalFrame();
}
}