static void select_click_handler(ClickRecognizerRef recognizer, void *context) { if (!is_connected) { return; } // Start dictation UI #if defined(PBL_MICROPHONE) if (s_dictation_session == NULL) { s_dictation_session = dictation_session_create(sizeof(dictated_message), dictation_session_callback, NULL); if (s_dictation_session != NULL) { dictation_session_enable_confirmation(s_dictation_session, false); } } if (s_state == BEGINNING_STATE) { dictation_session_start(s_dictation_session); } if (s_state == CREATING_FINAL_MESSAGE_STATE) { dictation_session_start(s_dictation_session); } #endif if (s_state == CONFIRMING_FINAL_MESSAGE_STATE) { change_state(SENDING_FINAL_MESSAGE_STATE); send_final_message(); action_bar_layer_set_icon(s_actionbar, BUTTON_ID_UP, NULL); action_bar_layer_set_icon(s_actionbar, BUTTON_ID_SELECT, NULL); action_bar_layer_set_icon(s_actionbar, BUTTON_ID_DOWN, NULL); } }
void *treatment_thr(void * t_args) //Thread de atendimento { int waiting_time = 10, res; char fc_name[MAX_SIZE]; strcpy(fc_name, ((Treatment_args * )t_args)->str); res = pthread_mutex_lock(&((Treatment_args * )t_args)->shm->table_lock); //Vai ler da memoria, por isso nao convem que algum dos processos estejam a alterar memoria checkResult("pthread_mutex_lock()\n", res); if(((Treatment_args * )t_args)->shm->table[(((Treatment_args * )t_args)->desk_number) - 1][IN_RECEPTION] < 10) { waiting_time = ((Treatment_args * )t_args)->shm->table[(((Treatment_args * )t_args)->desk_number) - 1][IN_RECEPTION] + 1; } res = pthread_mutex_unlock(&((Treatment_args * )t_args)->shm->table_lock); //Terminou a leitura da memoria checkResult("pthread_mutex_unlock()\n", res); time_sum += waiting_time; sleep(waiting_time); //Imprimir no log time(&refresh); char time_to_print[20]; strftime(time_to_print, 20, "%Y-%m-%d %H:%M:%S", localtime(&refresh)); char str[MAX_SIZE]; strcpy(str,fc_name); log_file = open(log_file_name, O_WRONLY | O_APPEND); if (log_file < 0) { printf("Nome da mem: %s\n", log_file_name); printf("Error opening log file!\n"); exit(EXIT_FAILURE); } char message[MAX_SIZE]; sprintf(message, "%s\t| Balcao | %d\t\t| fim_atend_cl\t\t| %s\n", time_to_print, ((Treatment_args * )t_args)->desk_number, chopN(str, 5)); write(log_file, message, strlen(message)); close(log_file); send_final_message(fc_name); res = pthread_mutex_lock(&((Treatment_args * )t_args)->shm->table_lock); //Vai escrever em memoria, convem bloquear a memoria checkResult("pthread_mutex_lock()\n", res); ((Treatment_args * )t_args)->shm->table[(((Treatment_args * )t_args)->desk_number) - 1][RECEPTIONED]++; ((Treatment_args * )t_args)->shm->table[(((Treatment_args * )t_args)->desk_number) - 1][IN_RECEPTION]--; res = pthread_mutex_unlock(&((Treatment_args * )t_args)->shm->table_lock); //terminou alteracoes checkResult("pthread_mutex_unlock()\n", res); free(t_args); pthread_exit(NULL); }