void ExampleWorker::do_work(ExampleWindow* caller) { { Glib::Threads::Mutex::Lock lock(m_Mutex); m_has_stopped = false; m_text_done = ""; m_message = ""; } // The mutex is unlocked here by lock's destructor. // Simulate a long calculation. /* Start sign to speech conversion. */ while( true ){ Glib::Threads::Mutex::Lock lock(m_Mutex); /* Check if sensor data is available. */ if( file_exists(fName) ){ /* Collect next set of data and store it as a gesture. */ scrText.SetStatus( "Reading:\t" + string(fName) + "\n" ) ; output_to_display( scrText, true ) ; /* Add delay to make sure file has finished being written to before attempting to read. */ nanosleep( &t1, &t2 ) ; if( rename(fName, intfName) != 0 ){ scrText.SetStatus( "Unable to rename file:\t" + string(fName) + "\n" ) ; } if( get_gesture( nextHand, intfName, scrText, doc, sensorStatus, xmlVersion, convert ) ){ /* Store the next gesture set of data. */ nextGesture = Gesture( nextHand[0], nextHand[1] ) ; /* Update display for the next set of sensor values. */ scrText.SetGestureData( nextGesture.AsString() ) ; /* Indicate file was successfully read. */ scrText.SetStatus( "Successfully read:\t" + string(fName) + "\n" ) ; /* Rename the file so as not to re-read it. */ if( rename(intfName, newfName) != 0 ){ scrText.SetStatus( "Unable to rename file:\t" + string(intfName) + "\n" ) ; } output_to_display( scrText, true ) ; } else{ scrText.SetStatus( "*** Error reading file. Attempting to continue ***\n" ) ; output_to_display( scrText, true ) ; continue ; } /* Convert the gesture to text. */ if( gesture_to_text(nextGesture, db, m_text_done, scrText, motion, added_text) ){ motion = false ; if( motion_gesture( m_text_done, j_motion, invalid_j, completed_j, NUM_J_MOTION, "J" ) || motion_gesture( m_text_done, z_motion, invalid_z, completed_z, NUM_Z_MOTION, "Z" ) ){ motion = true ; } /* Output the text to display */ scrText.SetGestureConv( m_text_done + "\n" ) ; if( added_text ){ nanosleep( &t3, &t4 ) ; } lock.release(); caller->notify(); output_to_display( scrText, true ) ; } else{ /* Gesture to text error. */ scrText.SetStatus( "*** Unable to convert gesture to text. Attempting to continue ***\n" ) ; output_to_display( scrText, true ) ; continue ; } scrText.SetStatus( "Wrote:\t" + string(outfName) + "\n" ) ; /* Update XML file. */ if( !output_xml(outfName, m_text_done, nextGesture, sensorStatus, xmlVersion) ){ scrText.SetStatus( "Error while writing:\t" + string(outfName) + "\n" ) ; } output_to_display( scrText, true ) ; } } Glib::Threads::Mutex::Lock lock(m_Mutex); m_shall_stop = false; m_has_stopped = true; lock.release(); caller->notify(); }
#include "stdafx.h" #include "Gesture.h" #include <iostream> Gesture Gesture::Gestures[] = { Gesture(GESTURE_LEFT, "Looking Left", "LLeft.bmp"), Gesture(GESTURE_CENTER, "Looking Center", "Center.bmp"), Gesture(GESTURE_RIGHT, "Looking Right", "LReft.bmp"), Gesture(GESTURE_LEFT_EYE, "Hiding Left", "HLeft.bmp"), Gesture(GESTURE_RIGHT_EYE, "Hiding Right", "HRight.bmp")}; Gesture::Gesture() { type = GESTURE_CENTER; } Gesture::Gesture(GESTURE type, string name, string imagePath) { this->type = type; this->name = name; this->imagePath = imagePath; } Gesture::~Gesture() { } GESTURE Gesture::getValue() { return type; }