int main(int argc, char **argv) { int rc = 0; int fd, rec_number; struct llog_log_hdr *llog_buf = NULL; struct llog_rec_hdr **recs_buf = NULL; setlinebuf(stdout); if(argc != 2 ){ printf("Usage: llog_reader filename\n"); return -1; } fd = open(argv[1],O_RDONLY); if (fd < 0){ printf("Could not open the file %s\n", argv[1]); goto out; } rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number); if (rc < 0) { printf("Could not pack buffer; rc=%d\n", rc); goto out_fd; } print_llog_header(llog_buf); print_records(recs_buf,rec_number); llog_unpack_buffer(fd,llog_buf,recs_buf); out_fd: close(fd); out: return rc; }
int main(void){ record a[3]; size_t i; for(i = 0; i < 3;i++){ if(input_record(&a[i]) != 1) printf("invalid input.\n"); } printf("-------------------------\n"); print_records(a,3); }
void test_ramdisk(void) { uint8_t user_input = '2'; struct record_t test; struct record_t local_copy; struct record_t test_t; srand(cph_get_millis()); test.wan_msg.tagMac = 1; test.wan_msg.tagBattery = 2; test.wan_msg.tagRssi = 3; struct record_t test_2; local_copy = test; ramdisk_init(); while(true) { test_2.wan_msg.tagMac = rand(); test_2.wan_msg.tagRssi = rand() % 65535; test_2.wan_msg.tagBattery = rand() % 65535; test_2.next = NULL; if(user_input == '2') ramdisk_write(test_2); else if(user_input =='1') ramdisk_write(test); else if(user_input == 'f') local_copy = *ramdisk_next(ramdisk_find(test.wan_msg.tagMac)); else if(user_input == 'p') print_records(); else if(user_input == 'e') ramdisk_erase(local_copy); else if(user_input == 'r') local_copy = test; else user_input = 'q'; // scanf(" %c", &user_input); if(user_input == 'q') break; } }
/**@brief from the (any) module to switch queue a fins frame is read into the * switch. Note that the function init_switch() is needed to initialize the switch, the queues and the semaphores which * control access to these queues. This function reads from the queue as pointed to by the input parameter and sends * a fins frame in response via the fins_switch_out. * @param module_to_switch_bff is the pointer to the queue from (any) module into the switch */ void fins_switch_in(struct queue *module_to_switch_bff){ struct finsFrame fins_in, fins_out; struct destinationList *dstPtr; struct tableRecord *searched_table_ptr; sem_wait(&(module_to_switch_bff->locked));/**lock the queue being read from*/ read_queue(&fins_in, module_to_switch_bff); sem_post(&(module_to_switch_bff->locked));/**lock the queue being read from*/ if (fins_in.dataOrCtrl == CONTROL) //control type fins Frame { if (fins_in.ctrlFrame.opcode == QUERYREQUEST) //if this is a query request generate a query reply { searched_table_ptr = switch_search_query(&(fins_in)); //carries the request fins frame gen_query_reply(&fins_out, &fins_in, searched_table_ptr); print_records(searched_table_ptr); //pointer to linked list of found elements from the table } //for all other opcodes simply copy the frame and send out else if ((fins_in.ctrlFrame.opcode == READREQUEST) &&(fins_in.ctrlFrame.opcode == READREPLY) && (fins_in.ctrlFrame.opcode == WRITEREQUEST) && (fins_in.ctrlFrame.opcode == WRITECONF)) memcpy(&fins_out, &fins_in, sizeof(struct finsFrame)); fins_switch_out(&fins_out); } else if (fins_in.dataOrCtrl == DATA) //data type fins Frame { /**@check the destination ID and send the frame to the module with this ID*/ dstPtr = &(fins_in.destinationID); /**@ The received FINS frame is duplicated and send to each of the modules (i.e. dest list). * However the destination list is pruned for the correct member for this purpose. * For example, if the list has three members each of the three modules will receive exactly * the same frame but without the original destination list (i.e. the destination ID will contain only the module's ID). * */ memcpy(&fins_out, &fins_in, sizeof(struct finsFrame)); while (dstPtr!=NULL){ fins_out.destinationID.id = dstPtr->id; fins_out.destinationID.next = NULL; dstPtr = dstPtr->next; fins_switch_out(&fins_out); //send to the queue for the given module as stored in dstPtr } } }
/* Callback for JVMTI_EVENT_COMPILED_METHOD_LOAD */ void JNICALL compiled_method_load(jvmtiEnv *jvmti, jmethodID method, jint code_size, const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map, const void* compile_info) { jvmtiError err; char* name = NULL; char* signature = NULL; char* generic_ptr = NULL; jvmtiCompiledMethodLoadRecordHeader* pcs; err = (*jvmti)->RawMonitorEnter(jvmti, lock); check_jvmti_error(jvmti, err, "raw monitor enter"); err = (*jvmti)->GetMethodName(jvmti, method, &name, &signature, &generic_ptr); check_jvmti_error(jvmti, err, "get method name"); fprintf(fp, "\nCompiled method load event\n"); fprintf(fp, "Method name %s %s %s\n\n", name, signature, generic_ptr == NULL ? "" : generic_ptr); pcs = (jvmtiCompiledMethodLoadRecordHeader *)compile_info; if (pcs != NULL) { print_records(pcs, jvmti, fp); } if (name != NULL) { err = (*jvmti)->Deallocate(jvmti, (unsigned char*)name); check_jvmti_error(jvmti, err, "deallocate name"); } if (signature != NULL) { err = (*jvmti)->Deallocate(jvmti, (unsigned char*)signature); check_jvmti_error(jvmti, err, "deallocate signature"); } if (generic_ptr != NULL) { err = (*jvmti)->Deallocate(jvmti, (unsigned char*)generic_ptr); check_jvmti_error(jvmti, err, "deallocate generic_ptr"); } err = (*jvmti)->RawMonitorExit(jvmti, lock); check_jvmti_error(jvmti, err, "raw monitor exit"); }