static void init(void) { time_t t = time(NULL); window = window_create(); window_set_background_color(window, GColorBlack); window_stack_push(window, true); rootLayer = window_get_root_layer(window); layer = layer_create(GRect(0, 0, 144, 168)); layer_set_update_proc(layer, updateLayer); layer_add_child(rootLayer, layer); textLayer = text_layer_create(GRect(72-30, 84-10, 60, 20)); text_layer_set_background_color(textLayer, GColorClear); text_layer_set_text_color(textLayer, GColorWhite); text_layer_set_text_alignment(textLayer, GTextAlignmentCenter); layer_add_child(rootLayer, text_layer_get_layer(textLayer)); minuteHandBitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_HAND_MINUTE); minuteHandLayer = rot_bitmap_layer_create(minuteHandBitmap); rot_bitmap_set_compositing_mode(minuteHandLayer, GCompOpOr); layer_add_child(rootLayer, (Layer *)minuteHandLayer); hourHandBitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_HAND_HOUR); hourHandLayer = rot_bitmap_layer_create(hourHandBitmap); rot_bitmap_set_compositing_mode(hourHandLayer, GCompOpOr); layer_add_child(rootLayer, (Layer *)hourHandLayer); // Init rotations handleTick(localtime(&t), SECOND_UNIT|MINUTE_UNIT|HOUR_UNIT); tick_timer_service_subscribe(SECOND_UNIT, handleTick); }
void Timer::clockHandler() { TRACE_BEGIN( LOG_LVL_INFO ); struct timespec start, cur; Condition c; Mutex m; AutoLock l(m); TimeUtils::getCurTime( &start ); while ( !mClockThread->CheckStop() ) { // Wait for the tick to timeout if (not c.Wait(m, mMsPerTick)) { TimeUtils::getCurTime( &cur ); // Check to see if the clock was set back, or jumps // forward by more than 10 seconds. If so, update the // starting time to the current time and wait for the next // tick. if ( TimeUtils::getDifference( &cur, &start ) < 0 or TimeUtils::getDifference( &cur, &start ) > 10000 ) { TimeUtils::getCurTime( &start ); handleTick(); } else { // Get the current time and count ticks until cur time and the // actual tick time are less the mMsPerTick apart. while ( TimeUtils::getDifference( &cur, &start ) > mMsPerTick ) { TimeUtils::addOffset( &start, mMsPerTick ); handleTick(); } } } else { LOG_ERR_FATAL("Signal recieved on timer condition????\n"); } } }
SourceObject::SourceObject (Category cat, QObject *parent) : QObject (parent) #if GST_VERSION_MAJOR < 1 , Dec_ (gst_element_factory_make ("playbin2", "play")) #else , Dec_ (gst_element_factory_make ("playbin", "play")) #endif , Path_ (nullptr) , IsSeeking_ (false) , LastCurrentTime_ (-1) , PrevSoupRank_ (0) , PopThread_ (new MsgPopThread (gst_pipeline_get_bus (GST_PIPELINE (Dec_)), this, cat == Category::Notification ? 0.05 : 1, BusDrainMutex_, BusDrainWC_)) , OldState_ (SourceState::Stopped) { g_signal_connect (Dec_, "about-to-finish", G_CALLBACK (CbAboutToFinish), this); g_signal_connect (Dec_, "notify::source", G_CALLBACK (CbSourceChanged), this); qRegisterMetaType<GstMessage*> ("GstMessage*"); qRegisterMetaType<GstMessage_ptr> ("GstMessage_ptr"); qRegisterMetaType<AudioSource> ("AudioSource"); auto timer = new QTimer (this); connect (timer, SIGNAL (timeout ()), this, SLOT (handleTick ())); timer->start (1000); gst_bus_set_sync_handler (gst_pipeline_get_bus (GST_PIPELINE (Dec_)), [] (GstBus *bus, GstMessage *msg, gpointer udata) { return static_cast<GstBusSyncReply> (static_cast<SourceObject*> (udata)-> HandleSyncMessage (bus, msg)); }, #if GST_VERSION_MAJOR < 1 this); #else this, nullptr); #endif PopThread_->start (QThread::LowestPriority); }