int main() { printf("============== Before allocating blocks ==============\n"); display_mallinfo(); MbedClient mbed_client; m2mclient = &mbed_client; trace_init(); set_trace_print_function( trace_printer ); set_trace_config(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_DEBUG|TRACE_CARRIAGE_RETURN); signal(SIGINT, (signalhandler_t)ctrl_c_handle_function); bool result = mbed_client.create_interface(); if(true == result) { printf("\nInterface created\n"); } result = mbed_client.create_bootstrap_object(); if(true == result) { printf("Bootstrap object created"); } result = mbed_client.create_register_object(); if(true == result) { printf("Register object created"); } result = mbed_client.create_device_object(); if(true == result) { printf("\nDevice object created !!\n"); } result = mbed_client.create_generic_object(); if(true == result) { printf("\nGeneric object created\n"); } // printf("Bootstrapping endpoint\n"); // mbed_client.test_bootstrap(); printf("Registering endpoint\n"); mbed_client.test_register(); pthread_create(&bootstrap_thread, NULL, &wait_for_bootstrap, (void*) &mbed_client); pthread_create(&observation_thread, NULL, &send_observation, (void*) &mbed_client); pthread_create(&unregister_thread, NULL, &wait_for_unregister, (void*) &mbed_client); pthread_join(bootstrap_thread, NULL); pthread_join(unregister_thread, NULL); pthread_join(observation_thread, NULL); printf("\n============== After freeing blocks ==============\n"); display_mallinfo(); exit(EXIT_SUCCESS); }
void* wait_for_bootstrap(void* arg) { MbedClient *client; client = (MbedClient*) arg; if(client->bootstrap_successful()) { printf("\n============== After Bootstrapping ==============\n"); display_mallinfo(); printf("Registering endpoint\n"); client->test_register(); } return NULL; }
void* send_observation(void* arg) { MbedClient *client; client = (MbedClient*) arg; static uint8_t counter = 0; while(1) { sleep(1); if(counter >= 5 && client->register_successful()) { printf("Sending observation\n"); client->update_resource(); counter = 0; printf("\n============== After Sending Observation ==============\n"); display_mallinfo(); } else counter++; } return NULL; }
int main() { printf("\n============== sizeof(boost::thread) ============== %d\n", sizeof(boost::thread)); printf("\n============== sizeof(boost::detail::thread_data_base) ============== %d\n", sizeof(boost::detail::thread_data_base)); printf("\n============== sizeof(boost::detail::thread_data<>) ============== %d\n", sizeof(boost::detail::thread_data<void(*)()>)); printf("\n============== Before thread creation ==============\n"); display_mallinfo(); { boost::thread thrd1(&count); printf("\n============== After thread creation ==============\n"); display_mallinfo(); boost::thread thrd2(&count); printf("\n============== After thread creation ==============\n"); display_mallinfo(); boost::thread thrd3(&count); printf("\n============== After thread creation ==============\n"); display_mallinfo(); thrd1.join(); printf("\n============== After thread join ==============\n"); display_mallinfo(); thrd2.join(); printf("\n============== After thread join ==============\n"); display_mallinfo(); thrd3.join(); printf("\n============== After thread join ==============\n"); display_mallinfo(); } printf("\n============== After thread destruction ==============\n"); display_mallinfo(); { pthread_attr_t attr; pthread_attr_init(&attr); pthread_t thrd1; pthread_create(&thrd1, &attr, &count2, 0); printf("\n============== After thread creation ==============\n"); display_mallinfo(); pthread_t thrd2; pthread_create(&thrd2, &attr, &count2, 0); printf("\n============== After thread creation ==============\n"); display_mallinfo(); pthread_t thrd3; pthread_create(&thrd3, &attr, &count2, 0); printf("\n============== After thread creation ==============\n"); display_mallinfo(); pthread_attr_destroy(&attr); printf("\n============== After thread attr destroy ==============\n"); display_mallinfo(); void* res; pthread_join(thrd3, &res); printf("\n============== After thread join ==============\n"); display_mallinfo(); pthread_join(thrd2, &res); printf("\n============== After thread join ==============\n"); display_mallinfo(); pthread_join(thrd1, &res); printf("\n============== After thread join ==============\n"); display_mallinfo(); //pthread_destroy(&thrd1); //pthread_destroy(&thrd2); //pthread_destroy(&thrd3); } printf("\n============== After thread destruction ==============\n"); display_mallinfo(); return 1; }
void object_registered(M2MSecurity */*security_object*/, const M2MServer &/*server_object*/) { _registered = true; printf("\nRegistered\n"); printf("\n============== After Registering ==============\n"); display_mallinfo(); }