Permalink
Browse files

Update Channels sample to display the 2 dialogs correctly

- the fix is to create and destroy the dialogs on the thread and channel that
  they are reporting information about
  • Loading branch information...
1 parent acb9390 commit 25e8e4c8a4a427296652216cc5d1d8d4964ced3a @jhoffmannrim jhoffmannrim committed Feb 14, 2012
Showing with 38 additions and 11 deletions.
  1. +10 −2 Channels/dialogutil.c
  2. +17 −4 Channels/dialogutil.h
  3. +11 −5 Channels/main.c
View
@@ -129,7 +129,7 @@ void cleanup_screen() {
void
-create_dialogs()
+create_bottom_dialog()
{
if (bottom_dialog == NULL) {
dialog_create_alert(&bottom_dialog);
@@ -141,7 +141,11 @@ create_dialogs()
dialog_set_cancel_required(bottom_dialog, true);
dialog_show(bottom_dialog);
}
+}
+void
+create_top_dialog()
+{
if (top_dialog == NULL) {
dialog_create_alert(&top_dialog);
dialog_set_alert_message_text(top_dialog, "\n");
@@ -156,11 +160,15 @@ create_dialogs()
}
void
-destroy_dialogs() {
+destroy_top_dialog() {
if (top_dialog) {
dialog_destroy(top_dialog);
}
top_dialog = 0;
+}
+
+void
+destroy_bottom_dialog() {
if (bottom_dialog) {
dialog_destroy(bottom_dialog);
View
@@ -32,14 +32,27 @@ int setup_screen();
void cleanup_screen();
/**
- * Show two alert dialogs that will output general data.
+ * Show an alert dialog to display general data along the bottom
+ * of the screen.
*/
-void create_dialogs();
+void create_bottom_dialog();
/**
- * Destroy dialogs that were created by create_dialogs.
+ * Show an alert dialog to display general data along the top
+ * of the screen.
*/
-void destroy_dialogs();
+void create_top_dialog();
+
+/**
+ * Destroy the top dialog that was created by create_top_dialog.
+ */
+void destroy_top_dialog();
+
+/**
+ * Destroy the bottom dialog that was created by create_bottom_dialog.
+ */
+void destroy_bottom_dialog();
+
/**
* Displays a message to the top dialog created by create_dialogs() and
View
@@ -165,6 +165,12 @@ accel_main (void *p) {
pthread_cond_signal(&chidCond);
pthread_mutex_unlock(&chidMutex);
+ /*
+ * Create and display a dialog that will show the data.
+ */
+ create_bottom_dialog();
+ show_bottom_dialog_message("\n\nThis is the Accelerometer Dialog");
+
if (BPS_SUCCESS != sensor_request_events(SENSOR_TYPE_ACCELEROMETER)) {
fprintf(stderr, "Error requesting sensor's accelerometer events: %s", strerror(errno));
bps_shutdown();
@@ -194,6 +200,7 @@ accel_main (void *p) {
}
sensor_stop_events(0);
+ destroy_bottom_dialog();
bps_shutdown();
@@ -266,9 +273,8 @@ main(int argc, char *argv[])
/*
* Create and display the dialogs that will show the data.
*/
- create_dialogs();
+ create_top_dialog();
show_top_dialog_message("Geolocation getting first fix");
- show_bottom_dialog_message("\n\nThis is the Accelerometer Dialog");
/*
* Before initializing the accelerometer service we must ensure the device
@@ -285,7 +291,7 @@ main(int argc, char *argv[])
/*
* Destroy the dialog, if it exists and cleanup screen resources.
*/
- destroy_dialogs();
+ destroy_top_dialog();
cleanup_screen();
bps_shutdown();
return EXIT_FAILURE;
@@ -345,9 +351,9 @@ main(int argc, char *argv[])
pthread_join(accel_thread, NULL);
/*
- * Destroy the dialogs, if they exist.
+ * Destroy the dialog, if it exists.
*/
- destroy_dialogs();
+ destroy_top_dialog();
bps_shutdown();
cleanup_screen();

0 comments on commit 25e8e4c

Please sign in to comment.