void javax_virtualsense_network_Packet_javax_virtualsense_network_Packet_createPacket_byte__(){ uint8_t i = 0; dj_object* ret = NULL; dj_int_array * byteArray = REF_TO_VOIDP(dj_exec_stackPopRef()); // create an object or allocate the chunk as is ? //heap_chunk * chk = (heap_chunk *)byteArray; PRINTF("array size is %d\n", byteArray->array.length); // resolve runtime class dj_global_id refClass = dj_vm_resolveRuntimeClass(dj_exec_getVM(), byteArray->data.bytes[4]); if(refClass.infusion != NULL){ ret = (dj_object*)dj_mem_alloc((byteArray->array.length - sizeof(heap_chunk)), byteArray->data.bytes[4]); heap_chunk * chk = getChunk(ret); PRINTF("BEFORE W Created object id %d s %d\n", chk->id, chk->size); memcpy((char*)ret, (char*)(byteArray->data.bytes+sizeof(heap_chunk)), byteArray->array.length- sizeof(heap_chunk)); chk = getChunk(ret); PRINTF("Created object id %d s %d\n", chk->id, chk->size); for(i = 0; i < byteArray->array.length; i++) PRINTF("%x-", byteArray->data.bytes[i]); PRINTF("\n"); }else { PRINTF("Packet not created\n"); } dj_exec_stackPushRef(VOIDP_TO_REF(ret)); // crete a new object from array }
void javax_wukong_wkpf_WKPF_javax_wukong_wkpf_VirtualWuObject_select() { // Will call update() for native profiles directly, // and return only true for virtual profiles requiring an update. wuobject_t *wuobject = wkpf_mainloop(); dj_exec_stackPushRef(VOIDP_TO_REF(wuobject->java_instance_reference)); DEBUG_LOG(DBG_WKPF, "WKPF: WKPF.select returning wuclass at port %x.\n", wuobject->port_number); return; }
// java.lang.Thread javax.darjeeling.Darjeeling.getThread(short) void javax_darjeeling_Darjeeling_java_lang_Thread_getThread_short() { dj_thread *thread; int index = dj_exec_stackPopShort(); // check for out of bounds if ( (index<0) || (index>=dj_vm_countThreads(dj_exec_getVM())) ) dj_exec_throwHere(dj_vm_createSysLibObject(dj_exec_getVM(), BASE_CDEF_java_lang_IndexOutOfBoundsException)); else { thread = dj_vm_getThread(dj_exec_getVM(), index); dj_exec_stackPushRef(VOIDP_TO_REF(thread)); } }
javax_virtualsense_network_Packet_byte___toByteArray(){ uint8_t i = 0; dj_object *obj = REF_TO_VOIDP(dj_exec_stackPopRef()); heap_chunk * chk = getChunk(obj); dj_int_array * ret; uint16_t length = chk->size; PRINTF("obj id is %d and array size is %d \n", chk->id, chk->size); ret = dj_int_array_create(T_BYTE, length); // data.bytes conatains | chunk struct | chk->size -sizeof(heap_chunk) bytes | memcpy(ret->data.bytes, (char*)chk, length); for(i = 0; i < ret->array.length; i++) PRINTF("%x-", ret->data.bytes[i]); PRINTF("\n"); dj_exec_stackPushRef(VOIDP_TO_REF(ret)); }
// byte[] javax.darjeeling.io.ProgramFlash.read(int) void javax_darjeeling_io_ProgramFlash_byte____read_int() { // Pop arguments. /*uint32_t index = */dj_exec_stackPopInt(); /*ref_t obj = */dj_exec_stackPopRef(); // Allocate byte array. dj_int_array * arr = dj_int_array_create(T_BYTE, PROGFLASH_BLOCKSIZE); // Read data from 'program flash'. // TODO implement ... // Return data. dj_exec_stackPushRef(VOIDP_TO_REF(arr)); }
// byte[] javax.darjeeling.io.ProgramFlash.read(int) void javax_darjeeling_io_ProgramFlash_byte____read_int() { // Pop arguments. // TODO: use when this gets implemented, but for now discard the index to avoid compiler warning // uint32_t index = dj_exec_stackPopInt(); dj_exec_stackPopInt(); // ignore the 'this' argument dj_exec_stackPopRef(); // Allocate byte array. dj_int_array * arr = dj_int_array_create(T_BYTE, PROGFLASH_BLOCKSIZE); // Read data from 'program flash'. // TODO implement ... // Return data. dj_exec_stackPushRef(VOIDP_TO_REF(arr)); }
void javax_wukong_wkpf_WKPF_javax_wukong_wkpf_VirtualWuObject_select() { wuobject_t *wuobject; while(true) { // Process any incoming messages dj_hook_call(dj_vm_pollingHook, NULL); // // TODONR: implement group stuff // #ifdef NVM_USE_GROUP // // Send out a heartbeat message if it's due, and check for failed nodes. // group_heartbeat(); // #endif // NVM_USE_GROUP if (dj_exec_getRunlevel() == RUNLEVEL_RUNNING) { // Propagate any dirty properties wkpf_propagate_dirty_properties(); // Check if any wuobjects need updates if(wkpf_get_next_wuobject_to_update(&wuobject)) { // Will call update() for native profiles directly, and return true for virtual profiles requiring an update. dj_exec_stackPushRef(VOIDP_TO_REF(wuobject->java_instance_reference)); DEBUG_LOG(DBG_WKPF, "WKPF: WKPF.select returning wuclass at port %x.\n", wuobject->port_number); return; } } } }
// byte[] javax.radio.Radio._readBytes() void javax_radio_Radio_byte____readBytes() { int length = tossim_peekMessageLength(); dj_int_array * arr = dj_int_array_create(T_BYTE, length); if (arr==NULL) { dj_exec_createAndThrow(BASE_CDEF_java_lang_OutOfMemoryError); return; } void * data = tossim_popMessageBuffer(); if (data==NULL) { dj_exec_createAndThrow(BASE_CDEF_java_lang_VirtualMachineError); return; } memcpy(arr->data.bytes, data, length); dj_exec_stackPushRef(VOIDP_TO_REF(arr)); //avoid deadlocks }
void java_lang_Object_java_lang_String_toString() { // Don't pop, just peek the object reference off the runtime stack, // because it's cleared by the VM's frame management. dj_object * obj = REF_TO_VOIDP(dj_exec_stackPeekRef()); // Get class definition runtime_id_t classRuntimeId = dj_mem_getChunkId(obj); dj_global_id classGlobalId = dj_vm_getRuntimeClass(dj_exec_getVM(), classRuntimeId); // Get class name dj_di_pointer classDefinition = dj_global_id_getClassDefinition(classGlobalId); dj_local_id classNameLocalId = dj_di_classDefinition_getClassName(classDefinition); dj_global_id classNameGlobalId = dj_global_id_resolve(classGlobalId.infusion, classNameLocalId); dj_object * string = dj_jstring_createFromGlobalId(dj_exec_getVM(), classNameGlobalId); if (string==NULL) dj_exec_createAndThrow(BASE_CDEF_java_lang_OutOfMemoryError); else dj_exec_stackPushRef(VOIDP_TO_REF(string)); }