RHO_GLOBAL VALUE get_camera_info(const char* camera_type) { JNIEnv *env = jnienv(); jclass cls = getJNIClass(RHODES_JAVA_CLASS_CAMERA); if (!cls) return rho_ruby_get_NIL(); jmethodID mid_w = getJNIClassStaticMethod(env, cls, "getMaxCameraWidth", "(Ljava/lang/String;)I"); jmethodID mid_h = getJNIClassStaticMethod(env, cls, "getMaxCameraHeight", "(Ljava/lang/String;)I"); if ((!mid_w) || (!mid_h)) return rho_ruby_get_NIL(); int w = env->CallStaticIntMethod(cls, mid_w, rho_cast<jhstring>(camera_type).get()); int h = env->CallStaticIntMethod(cls, mid_h, rho_cast<jhstring>(camera_type).get()); if ((w <= 0) || (h <= 0)) { return rho_ruby_get_NIL(); } VALUE hash = rho_ruby_createHash(); VALUE hash_max_resolution = rho_ruby_createHash(); rho_ruby_add_to_hash(hash_max_resolution, rho_ruby_create_string("width"), rho_ruby_create_integer(w)); rho_ruby_add_to_hash(hash_max_resolution, rho_ruby_create_string("height"), rho_ruby_create_integer(h)); rho_ruby_add_to_hash(hash, rho_ruby_create_string("max_resolution"), hash_max_resolution); return hash; }
VALUE getallPhonebookRecords(void* pb) { #if defined (_WIN32_WCE)//&& !defined( OS_PLATFORM_MOTCE ) if (RHO_IS_WMDEVICE && pb) { CNativeAddressBook* phonebook = (CNativeAddressBook*)pb; VALUE valGc = rho_ruby_disable_gc(); CHoldRubyValue hash(rho_ruby_createHash()); std::vector<CABRecord*> records; phonebook->getAllRecords(records); while(records.size() > 0) { CABRecord* record = records.back(); const char* rid = record->getValue("id").c_str(); if (rid) { LOGC(TRACE,"Phonebook") + "Adding record " + rid; addHashToHash(hash,rid,_getRecord(record)); } delete record; records.pop_back(); } rho_ruby_enable_gc(valGc); return hash; } #endif return rho_ruby_get_NIL(); }
VALUE rho_cast_helper<VALUE, jobject>::convertJavaMapToRubyHash(jobject objMap) { jhobject objSet = m_env->CallObjectMethod(objMap, midMapKeySet); if(m_env->ExceptionCheck() == JNI_TRUE) { rho::String message = rho::common::clearException(m_env); RAWLOG_ERROR(message.c_str()); return Qnil; } jhobject objIterator = m_env->CallObjectMethod(objSet.get(), midSetIterator); if(m_env->ExceptionCheck() == JNI_TRUE) { rho::String message = rho::common::clearException(m_env); RAWLOG_ERROR(message.c_str()); return Qnil; } CHoldRubyValue retval(rho_ruby_createHash()); while(m_env->CallBooleanMethod(objIterator.get(), midIteratorHasNext)) { jhobject jhKey = m_env->CallObjectMethod(objIterator.get(), midIteratorNext); if (!jhKey) return Qnil; jhobject jhVal = m_env->CallObjectMethod(objMap, midMapGet, jhKey.get()); if (!jhVal) return Qnil; CHoldRubyValue key(rho_cast<VALUE>(m_env, jhKey)); CHoldRubyValue val(rho_cast<VALUE>(m_env, jhVal)); rho_ruby_add_to_hash(retval, key, val); } return retval; }
VALUE rho_ringtone_manager_get_all() { //TODO: rho_ringtone_manager_get_all RAWLOGC_INFO("RingtoneManager", __FUNCTION__); CHoldRubyValue retval(rho_ruby_createHash()); return retval; }
static VALUE createHashFromContact(jobject contactObj) { if (logging_enable) RAWLOG_INFO("createHashFromContact() START"); JNIEnv *env = jnienv(); jclass contactCls = getJNIClass(RHODES_JAVA_CLASS_CONTACT); if (!contactCls) return Qnil; jclass fieldCls = getJNIClass(RHODES_JAVA_CLASS_CONTACT_FIELD); if (!fieldCls) return Qnil; jmethodID contactGetFieldMID = getJNIClassMethod(env, contactCls, "getField", "(I)Ljava/lang/String;"); if (!contactGetFieldMID) return Qnil; CHoldRubyValue contactHash(rho_ruby_createHash()); // contact.moveToBegin(); int i; for (i = 0; i < PB_FIELDS_COUNT; i++) { jstring value = (jstring)env->CallObjectMethod(contactObj, contactGetFieldMID, i); if (value != NULL) { addStrToHash(contactHash, field_names[i], rho_cast<std::string>(value).c_str()); } env->DeleteLocalRef(value); } if (logging_enable) RAWLOG_INFO("createHashFromContact() FINISH"); return contactHash; }
static VALUE _getRecord(CABRecord* record) { if (RHO_IS_WMDEVICE && record) { CHoldRubyValue hash(rho_ruby_createHash()); record->enumValues(_addRecordValue,&(hash.m_value)); return hash; } return rho_ruby_get_NIL(); }
virtual unsigned long getObjectValue() { VALUE b_array = rho_ruby_create_array(); VALUE b_hash = rho_ruby_createHash(); rho_ruby_add_to_hash(b_hash, rho_ruby_create_string("friendlyName"), rho_ruby_create_string("RhoBarcode based on ZXing")); rho_ruby_add_to_hash(b_hash, rho_ruby_create_string("deviceName"), rho_ruby_create_string("RhoBarcode")); rho_ruby_add_to_array(b_array, b_hash); return b_array; }
VALUE convertJavaMapToRubyHash(jobject objMap) { jclass clsMap = getJNIClass(RHODES_JAVA_CLASS_MAP); if (!clsMap) return Qnil; jclass clsSet = getJNIClass(RHODES_JAVA_CLASS_SET); if (!clsSet) return Qnil; jclass clsIterator = getJNIClass(RHODES_JAVA_CLASS_ITERATOR); if (!clsIterator) return Qnil; JNIEnv *env = jnienv(); jmethodID midGet = getJNIClassMethod(env, clsMap, "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); if (!midGet) return Qnil; jmethodID midKeySet = getJNIClassMethod(env, clsMap, "keySet", "()Ljava/util/Set;"); if (!midKeySet) return Qnil; jmethodID midIterator = getJNIClassMethod(env, clsSet, "iterator", "()Ljava/util/Iterator;"); if (!midIterator) return Qnil; jmethodID midHasNext = getJNIClassMethod(env, clsIterator, "hasNext", "()Z"); if (!midHasNext) return Qnil; jmethodID midNext = getJNIClassMethod(env, clsIterator, "next", "()Ljava/lang/Object;"); if (!midNext) return Qnil; jobject objSet = env->CallObjectMethod(objMap, midKeySet); if (!objSet) return Qnil; jobject objIterator = env->CallObjectMethod(objSet, midIterator); if (!objIterator) return Qnil; CHoldRubyValue retval(rho_ruby_createHash()); while(env->CallBooleanMethod(objIterator, midHasNext)) { jstring objKey = (jstring)env->CallObjectMethod(objIterator, midNext); if (!objKey) return Qnil; jstring objValue = (jstring)env->CallObjectMethod(objMap, midGet, objKey); if (!objValue) return Qnil; std::string const &strKey = rho_cast<std::string>(objKey); std::string const &strValue = rho_cast<std::string>(objValue); addStrToHash(retval, strKey.c_str(), strValue.c_str()); env->DeleteLocalRef(objKey); env->DeleteLocalRef(objValue); } return retval; }
VALUE rho_ringtone_manager_get_all() { LOG(INFO) + __FUNCTION__; CHoldRubyValue retval(rho_ruby_createHash()); #if _WIN32_WCE > 0x501 Hashtable<String, String> ringtones; CRingtoneManager::getCRingtoneManager().getAllRingtones(ringtones); for (Hashtable<String, String>::iterator itr = ringtones.begin(); itr != ringtones.end(); ++itr) { addStrToHash( retval, itr->first.c_str(), itr->second.c_str() ); } #endif return retval; }
VALUE rho_cast_helper<VALUE, jobject>::convertJavaMapToRubyHash(JNIEnv *env, jobject objMap) { jhobject objSet = env->CallObjectMethod(objMap, midMapKeySet); if (!objSet) return Qnil; jhobject objIterator = env->CallObjectMethod(objSet.get(), midSetIterator); if (!objIterator) return Qnil; CHoldRubyValue retval(rho_ruby_createHash()); while(env->CallBooleanMethod(objIterator.get(), midIteratorHasNext)) { jhstring objKey = (jstring)env->CallObjectMethod(objIterator.get(), midIteratorNext); if (!objKey) return Qnil; jhstring objValue = (jstring)env->CallObjectMethod(objMap, midMapGet, objKey.get()); if (!objValue) return Qnil; std::string const &strKey = rho_cast<std::string>(objKey); std::string const &strValue = rho_cast<std::string>(objValue); addStrToHash(retval, strKey.c_str(), strValue.c_str()); } return retval; }
VALUE rho_cast_helper<VALUE, jobject>::convertJavaMapToRubyHash(jobject objMap) { jhobject objSet = m_env->CallObjectMethod(objMap, midMapKeySet); if (!objSet) return Qnil; jhobject objIterator = m_env->CallObjectMethod(objSet.get(), midSetIterator); if (!objIterator) return Qnil; CHoldRubyValue retval(rho_ruby_createHash()); while(m_env->CallBooleanMethod(objIterator.get(), midIteratorHasNext)) { jhobject jhKey = m_env->CallObjectMethod(objIterator.get(), midIteratorNext); if (!jhKey) return Qnil; jhobject jhVal = m_env->CallObjectMethod(objMap, midMapGet, jhKey.get()); if (!jhVal) return Qnil; CHoldRubyValue key(rho_cast<VALUE>(m_env, jhKey)); CHoldRubyValue val(rho_cast<VALUE>(m_env, jhVal)); rho_ruby_add_to_hash(retval, key, val); } return retval; }
RHO_GLOBAL VALUE getallPhonebookRecords(void* pb) { if (logging_enable) RAWLOG_INFO("getallPhonebookRecords() START"); jobject phonebookObj = (jobject)pb; JNIEnv *env = jnienv(); jclass phonebookCls = getJNIClass(RHODES_JAVA_CLASS_PHONEBOOK); if (!phonebookCls) return Qnil; jclass contactCls = getJNIClass(RHODES_JAVA_CLASS_CONTACT); if (!contactCls) return Qnil; jmethodID phonebookPrepareFullListMID = getJNIClassMethod(env, phonebookCls, "prepareFullList", "()V"); if (!phonebookPrepareFullListMID) return Qnil; jmethodID phonebookMoveToBeginMID = getJNIClassMethod(env, phonebookCls, "moveToBegin", "()V"); if (!phonebookMoveToBeginMID) return Qnil; jmethodID hasNextMID = getJNIClassMethod(env, phonebookCls, "hasNext", "()Z"); if (!hasNextMID) return Qnil; jmethodID nextMID = getJNIClassMethod(env, phonebookCls, "next", "()Ljava/lang/Object;"); if (!nextMID) return Qnil; jmethodID contactIdMID = getJNIClassMethod(env, contactCls, "id", "()Ljava/lang/String;"); if (!contactIdMID) return Qnil; jmethodID contactGetFieldMID = getJNIClassMethod(env, contactCls, "getField", "(I)Ljava/lang/String;"); if (!contactGetFieldMID) return Qnil; env->CallVoidMethod(phonebookObj, phonebookPrepareFullListMID); // pb.moveToBegin(); env->CallVoidMethod(phonebookObj, phonebookMoveToBeginMID); VALUE valGc = rho_ruby_disable_gc(); CHoldRubyValue hash(rho_ruby_createHash()); // while(pb.hasNext()) while(env->CallBooleanMethod(phonebookObj, hasNextMID)) { // Contact contact = (Contact)pb.next(); jobject contactObj = env->CallObjectMethod(phonebookObj, nextMID); if (!contactObj) return Qnil; // String id = contact.id(); jstring idObj = (jstring)env->CallObjectMethod(contactObj, contactIdMID); if (!idObj) return Qnil; //addHashToHash(hash, rho_cast<std::string>(idObj).c_str(), createHashFromContact(contactObj)); CHoldRubyValue contactHash(rho_ruby_createHash()); // contact.moveToBegin(); int i; for (i = 0; i < PB_FIELDS_COUNT; i++) { jstring value = (jstring)env->CallObjectMethod(contactObj, contactGetFieldMID, i); if (value != NULL) { addStrToHash(contactHash, field_names[i], rho_cast<std::string>(value).c_str()); env->DeleteLocalRef(value); } } addHashToHash(hash, rho_cast<std::string>(idObj).c_str(), contactHash); env->DeleteLocalRef(idObj); env->DeleteLocalRef(contactObj); } rho_ruby_enable_gc(valGc); if (logging_enable) RAWLOG_INFO("getallPhonebookRecords() FINISH"); return hash; }
static VALUE _CreateRequestHash(HttpContextRef context, RouteRef route) { RAWTRACE("Creating Req Hash"); VALUE hash = rho_ruby_createHash(); rho_ruby_holdValue(hash); const char* applicationName = route->_application; addStrToHash(hash, "application", applicationName, strlen(applicationName)); const char* modelName = route->_model; addStrToHash(hash, "model", modelName, strlen(modelName)); if (route->_action!=NULL) { const char* actionName = route->_action; addStrToHash(hash, "action", actionName, strlen(actionName)); } if (route->_id!=NULL) { const char* _id = route->_id; addStrToHash(hash, "id", _id, strlen(_id)); } const char* method = HTTPGetMethod(context->_request->_method); addStrToHash(hash, "request-method", method, strlen(method)); const char* uri = context->_request->_uri; addStrToHash(hash, "request-uri", uri, strlen(uri)); const char* query = context->_request->_query == NULL ? "" : context->_request->_query; addStrToHash(hash, "request-query", query, strlen(query)); VALUE hash_headers = rho_ruby_createHash(); rho_ruby_holdValue(hash_headers); struct parsed_header* h = &context->_request->_cheaders.cl; for (int i = 0; i < sizeof(struct headers)/sizeof(struct parsed_header); i++) { if (h->_name) { char* name = trim(strdup(h->_name)); if (h->_type == HDR_STRING) { addStrToHash(hash_headers,name,h->_v.v_vec.ptr,h->_v.v_vec.len); } else if (h->_type == HDR_INT) { addIntToHash(hash_headers, name, h->_v.v_big_int); } else if (h->_type == HDR_DATE) { addTimeToHash(hash_headers, name, h->_v.v_time); } free(name); } h++; } addHashToHash(hash,"headers",hash_headers); rho_ruby_releaseValue(hash_headers); int buflen = CFDataGetLength(context->_rcvdBytes); if (buflen > 0) { addStrToHash(hash, "request-body", (char*)CFDataGetBytePtr(context->_rcvdBytes), buflen); } rho_ruby_releaseValue(hash); return hash; }